82b86e2175317a9a29256416eae7994a25b8b5c2
[ccsdk/sli.git] /
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 String asdcUseHttps = null;
60         private List<String> msgBusAddress = null;
61
62         private SdncArtifactMap artifactMap = SdncArtifactMap.getInstance();
63
64         private String incomingDir = null;
65
66         private String archiveDir = null;
67
68         private String overrideFile = null;
69
70         private boolean activateServerTLSAuth;
71         private String keyStorePassword;
72         private String keyStorePath;
73
74         private String xsltPathList;
75
76         public SdncUebConfiguration() {
77                 String propDir = System.getenv(SDNC_CONFIG_DIR);
78                 if (propDir == null) {
79
80                         propDir = "/opt/sdnc/data/properties";
81                 }
82                 try {
83                         init(propDir);
84                 } catch (Exception e) {
85                         LOG.error("Cannot initialize SdncUebConfiguration", e);
86                 }
87         }
88
89         public SdncUebConfiguration(String propDir) {
90                 try {
91                         init(propDir);
92                 } catch (Exception e) {
93                         LOG.error("Cannot initialize SdncUebConfiguration", e);
94                 }
95         }
96
97         public String getAsdcApiNamespace() {
98                 return asdcApiNamespace;
99         }
100
101         public String getXsltPathList() {
102                 return xsltPathList;
103         }
104
105         public String getOverrideFile() {
106                 return overrideFile;
107         }
108
109         public void init(String propDir) throws IOException {
110                 String propPath;
111
112
113                 propPath = propDir + "/ueb-listener.properties";
114                 File propFile = new File(propPath);
115
116
117                 if (!propFile.exists()) {
118
119                         throw new FileNotFoundException(
120                                         "Missing configuration properties file : "
121                                                         + propFile);
122                 }
123
124                 Properties props = new EnvProperties();
125                 props.load(new FileInputStream(propFile));
126
127                 asdcAddress = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.asdc-address");
128                 consumerGroup = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.consumer-group");
129                 consumerID = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.consumer-id");
130                 environmentName = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.environment-name");
131                 password = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.password");
132                 user = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.user");
133                 asdcUseHttps = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.use-https", "true");
134
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                 curval = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.relevant-artifact-types");
172                 if ((curval != null) && (curval.length() > 0)) {
173                         String[] artifactTypes = curval.split(",");
174
175                         relevantArtifactTypes = new LinkedList<>();
176
177                         for (String artifactType : artifactTypes) {
178
179                                 relevantArtifactTypes.add(artifactType);
180
181                         }
182
183                 }
184
185                 curval = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.activate-server-tls-auth", "false");
186                 activateServerTLSAuth = "true".equalsIgnoreCase(curval);
187                 keyStorePath = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.keystore-path");
188                 keyStorePassword = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.keystore-password");
189                 xsltPathList = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.xslt-path-list");
190
191
192                 String artifactMapFile = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.artifact-map");
193                 if (artifactMapFile != null) {
194                         LOG.info("Loading artifactMapFile {}", artifactMapFile);
195                         artifactMap.load(artifactMapFile);
196                 } else {
197                         LOG.warn("artifact-map is unset");
198                 }
199
200                 msgBusAddress = new LinkedList<>();
201                 String msgBusAddressStr = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.msg-bus-address");
202                 if (msgBusAddressStr != null) {
203                     String[] msgBusAddressArray = msgBusAddressStr.split(",");
204                     for (int i = 0 ; i < msgBusAddressArray.length ; i++) {
205                         msgBusAddress.add(msgBusAddressArray[i]);
206                     }
207                 }
208
209
210         }
211
212         @Override
213         public String getAsdcAddress() {
214                 return asdcAddress;
215         }
216
217         @Override
218         public String getConsumerGroup() {
219                 return consumerGroup;
220         }
221
222         @Override
223         public String getConsumerID() {
224                 return consumerID;
225         }
226
227         @Override
228         public String getEnvironmentName() {
229                 return environmentName;
230         }
231
232         @Override
233         public String getPassword() {
234                 return password;
235         }
236
237         @Override
238         public int getPollingInterval() {
239                 return pollingInterval;
240         }
241
242         @Override
243         public int getPollingTimeout() {
244                 return pollingTimeout;
245         }
246
247         @Override
248         public List<String> getRelevantArtifactTypes() {
249                 return relevantArtifactTypes;
250         }
251
252         public int getClientStartupTimeout() {
253                 return clientStartupTimeout;
254         }
255
256         @Override
257         public String getUser() {
258                 return user;
259         }
260
261
262         public String getSdncUser() {
263                 return sdncUser;
264         }
265
266         public String getSdncPasswd() {
267                 return sdncPasswd;
268         }
269
270         public String getAsdcApiBaseUrl() {
271                 return asdcApiBaseUrl;
272         }
273
274         @Override
275         public boolean activateServerTLSAuth() {
276                 return activateServerTLSAuth;
277         }
278
279         @Override
280         public String getKeyStorePassword() {
281                 return keyStorePassword;
282         }
283
284         @Override
285         public String getKeyStorePath() {
286                 return keyStorePath;
287         }
288
289         public String getIncomingDir() {
290                 return incomingDir;
291         }
292
293         public String getArchiveDir() {
294                 return archiveDir;
295         }
296
297         public int getMaxPasses() {
298                 return artifactMap.getNumPasses();
299         }
300
301         public SdncArtifactMap.SdncArtifactType getMapping(String tag) {
302                 return artifactMap.getMapping(tag);
303         }
304
305         @Override
306         public boolean isFilterInEmptyResources() {
307                 return false;
308         }
309
310         @Override
311         public Boolean isUseHttpsWithDmaap() {
312                 return false;
313         }
314
315         @Override
316     public Boolean isUseHttpsWithSDC() {
317         return Boolean.parseBoolean(asdcUseHttps);
318     }
319
320     @Override
321     public List<String> getMsgBusAddress() {
322         return msgBusAddress;
323     }
324
325
326 }