2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
20 package org.onap.sdnc.oam.datamigrator.common;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
26 import java.io.FileInputStream;
27 import java.io.FileNotFoundException;
28 import java.io.IOException;
30 import java.util.Properties;
32 public class MigratorConfiguration {
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;
42 private static final String SDNC_CONFIG_DIR = "SDNC_CONFIG_DIR";
43 private static final Logger LOG = LoggerFactory
44 .getLogger(MigratorConfiguration.class);
46 public MigratorConfiguration (){
47 String propDir = System.getenv(SDNC_CONFIG_DIR);
48 if (propDir == null) {
49 propDir = "/opt/sdnc/data/properties";
53 } catch (Exception e) {
54 LOG.error("Cannot initialize MigratorConfiguration", e);
58 public MigratorConfiguration (String propDir){
61 } catch (Exception e) {
62 LOG.error("Cannot initialize MigratorConfiguration", e);
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 : "
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");
87 public String getSourceHost() {
91 public String getSourceUser() {
95 public String getSourcePassword() {
96 return sourcePassword;
99 public String getTargetHost() {
103 public String getTargetUser() {
107 public String getTargetPassword() {
108 return targetPassword;
111 public String getDataPath() {
115 public void setDataPath(String dataPath) {
116 this.dataPath = dataPath;