Merge "Supporting 3 or more network domains for Transport Slicing use case. Issue...
[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.onap.ccsdk.sli.core.utils.common.EnvProperties;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
25
26 import java.io.File;
27 import java.io.FileInputStream;
28 import java.io.FileNotFoundException;
29 import java.io.IOException;
30 import java.net.URL;
31 import java.util.Properties;
32
33 public class MigratorConfiguration {
34
35     private String sourceHost ;
36     private String sourceUser ;
37     private String sourcePassword ;
38     private String targetHost ;
39     private String targetUser ;
40     private String targetPassword ;
41     private String dataPath;
42
43     private static final String SDNC_CONFIG_DIR = "SDNC_CONFIG_DIR";
44     private static final Logger LOG = LoggerFactory
45             .getLogger(MigratorConfiguration.class);
46
47     public MigratorConfiguration (){
48         String propDir = System.getenv(SDNC_CONFIG_DIR);
49         if (propDir == null) {
50             propDir = "/opt/sdnc/data/properties";
51         }
52         try {
53             init(propDir);
54         } catch (Exception e) {
55             LOG.error("Cannot initialize MigratorConfiguration", e);
56         }
57     }
58
59     public MigratorConfiguration (String propDir){
60         try {
61             init(propDir);
62         } catch (Exception e) {
63             LOG.error("Cannot initialize MigratorConfiguration", e);
64         }
65     }
66
67     public void init(String propDir) throws IOException {
68         String propPath = propDir + "/data-migrator.properties";
69         URL propPathUrl= getClass().getClassLoader().getResource(propPath);
70         File propFile = (propPathUrl != null) ? new File(propPathUrl.getFile()) : new File(propPath); 
71         if (!propFile.exists()) {
72             throw new FileNotFoundException(
73                     "Missing configuration properties file : "
74                             + propFile);
75         }
76
77         Properties props = new EnvProperties();
78         props.load(new FileInputStream(propFile));
79         this.sourceHost = props.getProperty("org.onap.sdnc.datamigrator.source.host");
80         this.sourceUser = props.getProperty("org.onap.sdnc.datamigrator.source.user");
81         this.sourcePassword = props.getProperty("org.onap.sdnc.datamigrator.source.password");
82         this.targetHost = props.getProperty("org.onap.sdnc.datamigrator.target.host");
83         this.targetUser = props.getProperty("org.onap.sdnc.datamigrator.target.user");
84         this.targetPassword = props.getProperty("org.onap.sdnc.datamigrator.target.password");
85         this.dataPath = props.getProperty("org.onap.sdnc.datamigrator.data.path");
86     }
87
88     public String getSourceHost() {
89         return sourceHost;
90     }
91
92     public String getSourceUser() {
93         return sourceUser;
94     }
95
96     public String getSourcePassword() {
97         return sourcePassword;
98     }
99
100     public String getTargetHost() {
101         return targetHost;
102     }
103
104     public String getTargetUser() {
105         return targetUser;
106     }
107
108     public String getTargetPassword() {
109         return targetPassword;
110     }
111
112     public String getDataPath() {
113         return dataPath;
114     }
115
116     public void setDataPath(String dataPath) {
117         this.dataPath = dataPath;
118     }
119 }