RA: Support for using allocated number in the entity id
[ccsdk/sli.git] / northbound / 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.ccsdk.sli.core.utils.common.EnvProperties;
34 import org.onap.sdc.api.consumer.IConfiguration;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
37
38 public class SdncUebConfiguration implements IConfiguration{
39
40         private static final String SDNC_CONFIG_DIR = "SDNC_CONFIG_DIR";
41         private static final Logger LOG = LoggerFactory
42                         .getLogger(SdncUebConfiguration.class);
43
44         private String asdcAddress = null;
45         private String consumerGroup = null;
46         private String consumerID = null;
47         private String environmentName = null;
48         private String password = null;
49         private int pollingInterval = 30;
50         private int pollingTimeout = 15;
51         private int clientStartupTimeout = 900;
52         private List<String> relevantArtifactTypes = null;
53         private String user = null;
54
55         private String sdncUser = null;
56         private String sdncPasswd = null;
57         private String asdcApiBaseUrl = null;
58         private String asdcApiNamespace = null;
59         private List<String> msgBusAddress = null;
60
61         private SdncArtifactMap artifactMap = SdncArtifactMap.getInstance();
62
63         private String incomingDir = null;
64
65         private String archiveDir = null;
66
67         private String overrideFile = null;
68
69         private boolean activateServerTLSAuth;
70         private String keyStorePassword;
71         private String keyStorePath;
72
73         private String xsltPathList;
74
75         public SdncUebConfiguration() {
76                 String propDir = System.getenv(SDNC_CONFIG_DIR);
77                 if (propDir == null) {
78
79                         propDir = "/opt/sdnc/data/properties";
80                 }
81                 try {
82                         init(propDir);
83                 } catch (Exception e) {
84                         LOG.error("Cannot initialize SdncUebConfiguration", e);
85                 }
86         }
87
88         public SdncUebConfiguration(String propDir) {
89                 try {
90                         init(propDir);
91                 } catch (Exception e) {
92                         LOG.error("Cannot initialize SdncUebConfiguration", e);
93                 }
94         }
95
96         public String getAsdcApiNamespace() {
97                 return asdcApiNamespace;
98         }
99
100         public String getXsltPathList() {
101                 return xsltPathList;
102         }
103
104         public String getOverrideFile() {
105                 return overrideFile;
106         }
107
108         public void init(String propDir) throws IOException {
109                 String propPath;
110
111
112                 propPath = propDir + "/ueb-listener.properties";
113                 File propFile = new File(propPath);
114
115
116                 if (!propFile.exists()) {
117
118                         throw new FileNotFoundException(
119                                         "Missing configuration properties file : "
120                                                         + propFile);
121                 }
122
123                 Properties props = new EnvProperties();
124                 props.load(new FileInputStream(propFile));
125
126                 asdcAddress = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.asdc-address");
127                 consumerGroup = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.consumer-group");
128                 consumerID = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.consumer-id");
129                 environmentName = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.environment-name");
130                 password = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.password");
131                 user = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.user");
132
133                 sdncUser = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.sdnc-user");
134                 sdncPasswd = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.sdnc-passwd");
135                 asdcApiBaseUrl = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.asdc-api-base-url");
136                 asdcApiNamespace = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.asdc-api-namespace");
137
138                 incomingDir = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.spool.incoming");
139                 archiveDir = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.spool.archive");
140                 overrideFile = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.override-file");
141
142                 String curval = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.polling-interval");
143                 if ((curval != null) && (curval.length() > 0)) {
144                         try {
145                                 pollingInterval = Integer.parseInt(curval);
146                         } catch (Exception e) {
147                                 LOG.warn("Illegal value for org.onap.ccsdk.sli.northbound.uebclient.polling-interval ({}) ", curval, e);
148                         }
149                 }
150
151                 curval = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.polling-timeout");
152                 if ((curval != null) && (curval.length() > 0)) {
153                         try {
154                                 pollingTimeout = Integer.parseInt(curval);
155                         } catch (Exception e) {
156                                 LOG.warn("Illegal value for org.onap.ccsdk.sli.northbound.uebclient.polling-timeout ({}) ", curval, e);
157                         }
158                 }
159
160                 curval = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.client-startup-timeout");
161                 if ((curval != null) && (curval.length() > 0)) {
162                         try {
163                                 clientStartupTimeout = Integer.parseInt(curval);
164                         } catch (Exception e) {
165                                 LOG.warn("Illegal value for org.onap.ccsdk.sli.northbound.uebclient.polling-timeout ({}) ", curval, e);
166                         }
167                 }
168                 curval = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.relevant-artifact-types");
169                 if ((curval != null) && (curval.length() > 0)) {
170                         String[] artifactTypes = curval.split(",");
171
172                         relevantArtifactTypes = new LinkedList<>();
173
174                         for (String artifactType : artifactTypes) {
175
176                                 relevantArtifactTypes.add(artifactType);
177
178                         }
179
180                 }
181
182                 curval = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.activate-server-tls-auth", "false");
183                 activateServerTLSAuth = "true".equalsIgnoreCase(curval);
184                 keyStorePath = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.keystore-path");
185                 keyStorePassword = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.keystore-password");
186                 xsltPathList = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.xslt-path-list");
187
188
189                 String artifactMapFile = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.artifact-map");
190                 if (artifactMapFile != null) {
191                         LOG.info("Loading artifactMapFile {}", artifactMapFile);
192                         artifactMap.load(artifactMapFile);
193                 } else {
194                         LOG.warn("artifact-map is unset");
195                 }
196
197                 msgBusAddress = new LinkedList<>();
198                 String msgBusAddressStr = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.msg-bus-address");
199                 if (msgBusAddressStr != null) {
200                     String[] msgBusAddressArray = msgBusAddressStr.split(",");
201                     for (int i = 0 ; i < msgBusAddressArray.length ; i++) {
202                         msgBusAddress.add(msgBusAddressArray[i]);
203                     }
204                 }
205
206
207         }
208
209         @Override
210         public String getAsdcAddress() {
211                 return asdcAddress;
212         }
213
214         @Override
215         public String getConsumerGroup() {
216                 return consumerGroup;
217         }
218
219         @Override
220         public String getConsumerID() {
221                 return consumerID;
222         }
223
224         @Override
225         public String getEnvironmentName() {
226                 return environmentName;
227         }
228
229         @Override
230         public String getPassword() {
231                 return password;
232         }
233
234         @Override
235         public int getPollingInterval() {
236                 return pollingInterval;
237         }
238
239         @Override
240         public int getPollingTimeout() {
241                 return pollingTimeout;
242         }
243
244         @Override
245         public List<String> getRelevantArtifactTypes() {
246                 return relevantArtifactTypes;
247         }
248
249         public int getClientStartupTimeout() {
250                 return clientStartupTimeout;
251         }
252
253         @Override
254         public String getUser() {
255                 return user;
256         }
257
258
259         public String getSdncUser() {
260                 return sdncUser;
261         }
262
263         public String getSdncPasswd() {
264                 return sdncPasswd;
265         }
266
267         public String getAsdcApiBaseUrl() {
268                 return asdcApiBaseUrl;
269         }
270
271         @Override
272         public boolean activateServerTLSAuth() {
273                 return activateServerTLSAuth;
274         }
275
276         @Override
277         public String getKeyStorePassword() {
278                 return keyStorePassword;
279         }
280
281         @Override
282         public String getKeyStorePath() {
283                 return keyStorePath;
284         }
285
286         public String getIncomingDir() {
287                 return incomingDir;
288         }
289
290         public String getArchiveDir() {
291                 return archiveDir;
292         }
293
294         public int getMaxPasses() {
295                 return artifactMap.getNumPasses();
296         }
297
298         public SdncArtifactMap.SdncArtifactType getMapping(String tag) {
299                 return artifactMap.getMapping(tag);
300         }
301
302         @Override
303         public boolean isFilterInEmptyResources() {
304                 return false;
305         }
306
307         @Override
308         public Boolean isUseHttpsWithDmaap() {
309                 return false;
310         }
311
312     @Override
313     public List<String> getMsgBusAddress() {
314         return msgBusAddress;
315     }
316
317
318 }