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