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.onap.ccsdk.sli.core.utils.common.EnvProperties;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
27 import java.io.FileInputStream;
28 import java.io.FileNotFoundException;
29 import java.io.IOException;
31 import java.util.Properties;
33 public class MigratorConfiguration {
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;
43 private static final String SDNC_CONFIG_DIR = "SDNC_CONFIG_DIR";
44 private static final Logger LOG = LoggerFactory
45 .getLogger(MigratorConfiguration.class);
47 public MigratorConfiguration (){
48 String propDir = System.getenv(SDNC_CONFIG_DIR);
49 if (propDir == null) {
50 propDir = "/opt/sdnc/data/properties";
54 } catch (Exception e) {
55 LOG.error("Cannot initialize MigratorConfiguration", e);
59 public MigratorConfiguration (String propDir){
62 } catch (Exception e) {
63 LOG.error("Cannot initialize MigratorConfiguration", e);
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 : "
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");
88 public String getSourceHost() {
92 public String getSourceUser() {
96 public String getSourcePassword() {
97 return sourcePassword;
100 public String getTargetHost() {
104 public String getTargetUser() {
108 public String getTargetPassword() {
109 return targetPassword;
112 public String getDataPath() {
116 public void setDataPath(String dataPath) {
117 this.dataPath = dataPath;