Merge "DG changes for the closed loop and async support in MDONS"
[sdnc/oam.git] / data-migrator / src / main / java / org / onap / sdnc / oam / datamigrator / common / MigratorConfiguration.java
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP : SDNC
4  * ================================================================================
5  * Copyright 2019 AMDOCS
6  *=================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20 package org.onap.sdnc.oam.datamigrator.common;
21
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
24
25 import java.io.File;
26 import java.io.FileInputStream;
27 import java.io.FileNotFoundException;
28 import java.io.IOException;
29 import java.net.URL;
30 import java.util.Properties;
31
32 public class MigratorConfiguration {
33
34     private String sourceHost ;
35     private String sourceUser ;
36     private String sourcePassword ;
37     private String targetHost ;
38     private String targetUser ;
39     private String targetPassword ;
40     private String dataPath;
41
42     private static final String SDNC_CONFIG_DIR = "SDNC_CONFIG_DIR";
43     private static final Logger LOG = LoggerFactory
44             .getLogger(MigratorConfiguration.class);
45
46     public MigratorConfiguration (){
47         String propDir = System.getenv(SDNC_CONFIG_DIR);
48         if (propDir == null) {
49             propDir = "/opt/sdnc/data/properties";
50         }
51         try {
52             init(propDir);
53         } catch (Exception e) {
54             LOG.error("Cannot initialize MigratorConfiguration", e);
55         }
56     }
57
58     public MigratorConfiguration (String propDir){
59         try {
60             init(propDir);
61         } catch (Exception e) {
62             LOG.error("Cannot initialize MigratorConfiguration", e);
63         }
64     }
65
66     public void init(String propDir) throws IOException {
67         String propPath = propDir + "/data-migrator.properties";
68         URL propPathUrl= getClass().getClassLoader().getResource(propPath);
69         File propFile = (propPathUrl != null) ? new File(propPathUrl.getFile()) : new File(propPath); 
70         if (!propFile.exists()) {
71             throw new FileNotFoundException(
72                     "Missing configuration properties file : "
73                             + propFile);
74         }
75
76         Properties props = new Properties();
77         props.load(new FileInputStream(propFile));
78         this.sourceHost = props.getProperty("org.onap.sdnc.datamigrator.source.host");
79         this.sourceUser = props.getProperty("org.onap.sdnc.datamigrator.source.user");
80         this.sourcePassword = props.getProperty("org.onap.sdnc.datamigrator.source.password");
81         this.targetHost = props.getProperty("org.onap.sdnc.datamigrator.target.host");
82         this.targetUser = props.getProperty("org.onap.sdnc.datamigrator.target.user");
83         this.targetPassword = props.getProperty("org.onap.sdnc.datamigrator.target.password");
84         this.dataPath = props.getProperty("org.onap.sdnc.datamigrator.data.path");
85     }
86
87     public String getSourceHost() {
88         return sourceHost;
89     }
90
91     public String getSourceUser() {
92         return sourceUser;
93     }
94
95     public String getSourcePassword() {
96         return sourcePassword;
97     }
98
99     public String getTargetHost() {
100         return targetHost;
101     }
102
103     public String getTargetUser() {
104         return targetUser;
105     }
106
107     public String getTargetPassword() {
108         return targetPassword;
109     }
110
111     public String getDataPath() {
112         return dataPath;
113     }
114
115     public void setDataPath(String dataPath) {
116         this.dataPath = dataPath;
117     }
118 }