Release version 1.1.0 of sli/northbound
[ccsdk/sli/northbound.git] / ueb-listener / src / main / java / org / onap / ccsdk / sli / northbound / uebclient / SdncUebConfiguration.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * openECOMP : SDN-C
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
6  *                      reserved.
7  * Modifications Copyright © 2018 IBM.
8  * ================================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.ccsdk.sli.northbound.uebclient;
24
25 import java.io.File;
26 import java.io.FileInputStream;
27 import java.io.FileNotFoundException;
28 import java.io.IOException;
29 import java.util.LinkedList;
30 import java.util.List;
31 import java.util.Properties;
32
33 import org.onap.sdc.api.consumer.IConfiguration;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
36
37 public class SdncUebConfiguration implements IConfiguration{
38
39         private static final String SDNC_CONFIG_DIR = "SDNC_CONFIG_DIR";
40         private static final Logger LOG = LoggerFactory
41                         .getLogger(SdncUebConfiguration.class);
42
43         private String asdcAddress = null;
44         private String consumerGroup = null;
45         private String consumerID = null;
46         private String environmentName = null;
47         private String password = null;
48         private int pollingInterval = 30;
49         private int pollingTimeout = 15;
50         private int clientStartupTimeout = 900;
51         private List<String> relevantArtifactTypes = null;
52         private String user = null;
53
54         private String sdncUser = null;
55         private String sdncPasswd = null;
56         private String asdcApiBaseUrl = null;
57         private String asdcApiNamespace = null;
58         private List<String> msgBusAddress = null;
59
60         private SdncArtifactMap artifactMap = SdncArtifactMap.getInstance();
61
62         private String incomingDir = null;
63
64         private String archiveDir = null;
65
66         private String overrideFile = null;
67
68         private boolean activateServerTLSAuth;
69         private String keyStorePassword;
70         private String keyStorePath;
71
72         private String xsltPathList;
73
74         public SdncUebConfiguration() {
75                 String propDir = System.getenv(SDNC_CONFIG_DIR);
76                 if (propDir == null) {
77
78                         propDir = "/opt/sdnc/data/properties";
79                 }
80                 try {
81                         init(propDir);
82                 } catch (Exception e) {
83                         LOG.error("Cannot initialize SdncUebConfiguration", e);
84                 }
85         }
86
87         public SdncUebConfiguration(String propDir) {
88                 try {
89                         init(propDir);
90                 } catch (Exception e) {
91                         LOG.error("Cannot initialize SdncUebConfiguration", e);
92                 }
93         }
94
95         public String getAsdcApiNamespace() {
96                 return asdcApiNamespace;
97         }
98
99         public String getXsltPathList() {
100                 return xsltPathList;
101         }
102
103         public String getOverrideFile() {
104                 return overrideFile;
105         }
106
107         public void init(String propDir) throws IOException {
108                 String propPath;
109
110
111                 propPath = propDir + "/ueb-listener.properties";
112                 File propFile = new File(propPath);
113
114
115                 if (!propFile.exists()) {
116
117                         throw new FileNotFoundException(
118                                         "Missing configuration properties file : "
119                                                         + propFile);
120                 }
121
122                 Properties props = new Properties();
123                 props.load(new FileInputStream(propFile));
124
125                 asdcAddress = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.asdc-address");
126                 consumerGroup = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.consumer-group");
127                 consumerID = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.consumer-id");
128                 environmentName = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.environment-name");
129                 password = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.password");
130                 user = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.user");
131
132                 sdncUser = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.sdnc-user");
133                 sdncPasswd = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.sdnc-passwd");
134                 asdcApiBaseUrl = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.asdc-api-base-url");
135                 asdcApiNamespace = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.asdc-api-namespace");
136
137                 incomingDir = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.spool.incoming");
138                 archiveDir = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.spool.archive");
139                 overrideFile = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.override-file");
140
141                 String curval = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.polling-interval");
142                 if ((curval != null) && (curval.length() > 0)) {
143                         try {
144                                 pollingInterval = Integer.parseInt(curval);
145                         } catch (Exception e) {
146                                 LOG.warn("Illegal value for org.onap.ccsdk.sli.northbound.uebclient.polling-interval ({}) ", curval, e);
147                         }
148                 }
149
150                 curval = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.polling-timeout");
151                 if ((curval != null) && (curval.length() > 0)) {
152                         try {
153                                 pollingTimeout = Integer.parseInt(curval);
154                         } catch (Exception e) {
155                                 LOG.warn("Illegal value for org.onap.ccsdk.sli.northbound.uebclient.polling-timeout ({}) ", curval, e);
156                         }
157                 }
158
159                 curval = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.client-startup-timeout");
160                 if ((curval != null) && (curval.length() > 0)) {
161                         try {
162                                 clientStartupTimeout = Integer.parseInt(curval);
163                         } catch (Exception e) {
164                                 LOG.warn("Illegal value for org.onap.ccsdk.sli.northbound.uebclient.polling-timeout ({}) ", curval, e);
165                         }
166                 }
167                 curval = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.relevant-artifact-types");
168                 if ((curval != null) && (curval.length() > 0)) {
169                         String[] artifactTypes = curval.split(",");
170
171                         relevantArtifactTypes = new LinkedList<>();
172
173                         for (String artifactType : artifactTypes) {
174
175                                 relevantArtifactTypes.add(artifactType);
176
177                         }
178
179                 }
180
181                 curval = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.activate-server-tls-auth", "false");
182                 activateServerTLSAuth = "true".equalsIgnoreCase(curval);
183                 keyStorePath = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.keystore-path");
184                 keyStorePassword = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.keystore-password");
185                 xsltPathList = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.xslt-path-list");
186
187
188                 String artifactMapFile = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.artifact-map");
189                 if (artifactMapFile != null) {
190                         LOG.info("Loading artifactMapFile {}", artifactMapFile);
191                         artifactMap.load(artifactMapFile);
192                 } else {
193                         LOG.warn("artifact-map is unset");
194                 }
195
196                 msgBusAddress = new LinkedList<>();
197                 String msgBusAddressStr = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.msg-bus-address");
198                 if (msgBusAddressStr != null) {
199                     String[] msgBusAddressArray = msgBusAddressStr.split(",");
200                     for (int i = 0 ; i < msgBusAddressArray.length ; i++) {
201                         msgBusAddress.add(msgBusAddressArray[i]);
202                     }
203                 }
204
205
206         }
207
208         @Override
209         public String getAsdcAddress() {
210                 return asdcAddress;
211         }
212
213         @Override
214         public String getConsumerGroup() {
215                 return consumerGroup;
216         }
217
218         @Override
219         public String getConsumerID() {
220                 return consumerID;
221         }
222
223         @Override
224         public String getEnvironmentName() {
225                 return environmentName;
226         }
227
228         @Override
229         public String getPassword() {
230                 return password;
231         }
232
233         @Override
234         public int getPollingInterval() {
235                 return pollingInterval;
236         }
237
238         @Override
239         public int getPollingTimeout() {
240                 return pollingTimeout;
241         }
242
243         @Override
244         public List<String> getRelevantArtifactTypes() {
245                 return relevantArtifactTypes;
246         }
247
248         public int getClientStartupTimeout() {
249                 return clientStartupTimeout;
250         }
251
252         @Override
253         public String getUser() {
254                 return user;
255         }
256
257
258         public String getSdncUser() {
259                 return sdncUser;
260         }
261
262         public String getSdncPasswd() {
263                 return sdncPasswd;
264         }
265
266         public String getAsdcApiBaseUrl() {
267                 return asdcApiBaseUrl;
268         }
269
270         @Override
271         public boolean activateServerTLSAuth() {
272                 return activateServerTLSAuth;
273         }
274
275         @Override
276         public String getKeyStorePassword() {
277                 return keyStorePassword;
278         }
279
280         @Override
281         public String getKeyStorePath() {
282                 return keyStorePath;
283         }
284
285         public String getIncomingDir() {
286                 return incomingDir;
287         }
288
289         public String getArchiveDir() {
290                 return archiveDir;
291         }
292
293         public int getMaxPasses() {
294                 return artifactMap.getNumPasses();
295         }
296
297         public SdncArtifactMap.SdncArtifactType getMapping(String tag) {
298                 return artifactMap.getMapping(tag);
299         }
300
301         @Override
302         public boolean isFilterInEmptyResources() {
303                 return false;
304         }
305
306         @Override
307         public Boolean isUseHttpsWithDmaap() {
308                 return false;
309         }
310
311     @Override
312     public List<String> getMsgBusAddress() {
313         return msgBusAddress;
314     }
315
316
317 }