Add unit test for ueb-listener
[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  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.ccsdk.sli.northbound.uebclient;
23
24 import java.io.File;
25 import java.io.FileInputStream;
26 import java.io.FileNotFoundException;
27 import java.io.IOException;
28 import java.util.LinkedList;
29 import java.util.List;
30 import java.util.Properties;
31
32 import org.openecomp.sdc.api.consumer.IConfiguration;
33 import org.openecomp.sdc.utils.ArtifactTypeEnum;
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 List<String> relevantArtifactTypes = null;
51         private String user = null;
52
53         private String sdncUser = null;
54         private String sdncPasswd = null;
55         private String asdcApiBaseUrl = null;
56         private String asdcApiNamespace = null;
57
58         private SdncArtifactMap artifactMap = SdncArtifactMap.getInstance();
59
60         public String getAsdcApiNamespace() {
61                 return asdcApiNamespace;
62         }
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 String getXsltPathList() {
77                 return xsltPathList;
78         }
79
80         public String getOverrideFile() {
81                 return overrideFile;
82         }
83
84         public SdncUebConfiguration() {
85                 String propDir = System.getenv(SDNC_CONFIG_DIR);
86                 if (propDir == null) {
87
88                         propDir = "/opt/sdnc/data/properties";
89                 }
90                 try {
91                         init(propDir);
92                 } catch (Exception e) {
93                         LOG.error("Cannot initialize SdncUebConfiguration", e);
94                 }
95         }
96
97         public SdncUebConfiguration(String propDir) {
98                 try {
99                         init(propDir);
100                 } catch (Exception e) {
101                         LOG.error("Cannot initialize SdncUebConfiguration", e);
102                 }
103         }
104
105
106         public void init(String propDir) throws IOException {
107                 String propPath;
108
109
110                 propPath = propDir + "/ueb-listener.properties";
111                 File propFile = new File(propPath);
112
113
114                 if (!propFile.exists()) {
115
116                         throw new FileNotFoundException(
117                                         "Missing configuration properties file : "
118                                                         + propFile);
119                 }
120
121                 Properties props = new Properties();
122                 props.load(new FileInputStream(propFile));
123
124                 asdcAddress = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.asdc-address");
125                 consumerGroup = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.consumer-group");
126                 consumerID = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.consumer-id");
127                 environmentName = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.environment-name");
128                 password = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.password");
129                 user = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.user");
130
131                 sdncUser = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.sdnc-user");
132                 sdncPasswd = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.sdnc-passwd");
133                 asdcApiBaseUrl = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.asdc-api-base-url");
134                 asdcApiNamespace = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.asdc-api-namespace");
135
136                 incomingDir = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.spool.incoming");
137                 archiveDir = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.spool.archive");
138                 overrideFile = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.override-file");
139
140                 String curval = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.polling-interval");
141                 if ((curval != null) && (curval.length() > 0)) {
142                         try {
143                                 pollingInterval = Integer.parseInt(curval);
144                         } catch (Exception e) {
145                                 LOG.warn("Illegal value for org.onap.ccsdk.sli.northbound.uebclient.polling-interval ({}) ", curval, e);
146                         }
147                 }
148
149                 curval = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.polling-timeout");
150                 if ((curval != null) && (curval.length() > 0)) {
151                         try {
152                                 pollingTimeout = Integer.parseInt(curval);
153                         } catch (Exception e) {
154                                 LOG.warn("Illegal value for org.onap.ccsdk.sli.northbound.uebclient.polling-timeout ({}) ", curval, e);
155                         }
156                 }
157
158                 curval = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.relevant-artifact-types");
159                 if ((curval != null) && (curval.length() > 0)) {
160                         String[] artifactTypes = curval.split(",");
161
162                         relevantArtifactTypes = new LinkedList<>();
163
164                         for (String artifactType : artifactTypes) {
165                                 try {
166                                         if (ArtifactTypeEnum.valueOf(artifactType) != null) {
167                                                         relevantArtifactTypes.add(artifactType);
168                                         } else {
169                                                 LOG.warn("Skipping unrecognized artifact type {}", artifactType);
170                                         }
171                                 } catch (Exception e) {
172
173                                         LOG.warn("Caught exception validating artifact type {}", artifactType, e);
174                                 }
175
176                         }
177
178                 }
179
180                 curval = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.activate-server-tls-auth", "false");
181                 activateServerTLSAuth = "true".equalsIgnoreCase(curval);
182                 keyStorePath = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.keystore-path");
183                 keyStorePassword = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.keystore-password");
184                 xsltPathList = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.xslt-path-list");
185
186
187                 String artifactMapFile = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.artifact-map");
188                 if (artifactMapFile != null) {
189                         artifactMap.load(artifactMapFile);
190                 }
191
192         }
193
194         @Override
195         public String getAsdcAddress() {
196                 return asdcAddress;
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         @Override
235         public String getUser() {
236                 return user;
237         }
238
239
240         public String getSdncUser() {
241                 return sdncUser;
242         }
243
244         public String getSdncPasswd() {
245                 return sdncPasswd;
246         }
247
248         public String getAsdcApiBaseUrl() {
249                 return asdcApiBaseUrl;
250         }
251
252         @Override
253         public boolean activateServerTLSAuth() {
254                 return activateServerTLSAuth;
255         }
256
257         @Override
258         public String getKeyStorePassword() {
259                 return keyStorePassword;
260         }
261
262         @Override
263         public String getKeyStorePath() {
264                 return keyStorePath;
265         }
266
267         public String getIncomingDir() {
268                 return incomingDir;
269         }
270
271         public String getArchiveDir() {
272                 return archiveDir;
273         }
274
275         public int getMaxPasses() {
276                 return artifactMap.getNumPasses();
277         }
278
279         public SdncArtifactMap.SdncArtifactType getMapping(String tag) {
280                 return artifactMap.getMapping(tag);
281         }
282
283         @Override
284         public boolean isFilterInEmptyResources() {
285                 // TODO Auto-generated method stub
286                 return false;
287         }
288
289
290 }