d28f7cd4000c8b8974648330d3e7250aa312eead
[sdnc/northbound.git] / ueb-listener / src / main / java / org / openecomp / sdnc / 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.openecomp.sdnc.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
86                 try {
87                         init();
88                 } catch (Exception e) {
89                         LOG.error("Cannot initialize SdncUebConfiguration", e);
90                 }
91         }
92
93         public void init() throws IOException {
94                 String propPath = null;
95                 String propDir = System.getenv(SDNC_CONFIG_DIR);
96                 if (propDir == null) {
97
98                         propDir = "/opt/sdnc/data/properties";
99                 }
100                 propPath = propDir + "/ueb-listener.properties";
101                 File propFile = new File(propPath);
102
103
104                 if (!propFile.exists()) {
105
106                         throw new FileNotFoundException(
107                                         "Missing configuration properties file : "
108                                                         + propFile);
109                 }
110
111                 Properties props = new Properties();
112                 props.load(new FileInputStream(propFile));
113
114                 asdcAddress = props.getProperty("org.openecomp.sdnc.uebclient.asdc-address");
115                 consumerGroup = props.getProperty("org.openecomp.sdnc.uebclient.consumer-group");
116                 consumerID = props.getProperty("org.openecomp.sdnc.uebclient.consumer-id");
117                 environmentName = props.getProperty("org.openecomp.sdnc.uebclient.environment-name");
118                 password = props.getProperty("org.openecomp.sdnc.uebclient.password");
119                 user = props.getProperty("org.openecomp.sdnc.uebclient.user");
120
121                 sdncUser = props.getProperty("org.openecomp.sdnc.uebclient.sdnc-user");
122                 sdncPasswd = props.getProperty("org.openecomp.sdnc.uebclient.sdnc-passwd");
123                 asdcApiBaseUrl = props.getProperty("org.openecomp.sdnc.uebclient.asdc-api-base-url");
124                 asdcApiNamespace = props.getProperty("org.openecomp.sdnc.uebclient.asdc-api-namespace");
125
126                 incomingDir = props.getProperty("org.openecomp.sdnc.uebclient.spool.incoming");
127                 archiveDir = props.getProperty("org.openecomp.sdnc.uebclient.spool.archive");
128                 overrideFile = props.getProperty("org.openecomp.sdnc.uebclient.override-file");
129
130                 String curval = props.getProperty("org.openecomp.sdnc.uebclient.polling-interval");
131                 if ((curval != null) && (curval.length() > 0)) {
132                         try {
133                                 pollingInterval = Integer.parseInt(curval);
134                         } catch (Exception e) {
135                                 LOG.warn("Illegal value for org.openecomp.sdnc.uebclient.polling-interval ("+curval+")");
136                         }
137                 }
138
139                 curval = props.getProperty("org.openecomp.sdnc.uebclient.polling-timeout");
140                 if ((curval != null) && (curval.length() > 0)) {
141                         try {
142                                 pollingTimeout = Integer.parseInt(curval);
143                         } catch (Exception e) {
144                                 LOG.warn("Illegal value for org.openecomp.sdnc.uebclient.polling-timeout ("+curval+")");
145                         }
146                 }
147
148                 curval = props.getProperty("org.openecomp.sdnc.uebclient.relevant-artifact-types");
149                 if ((curval != null) && (curval.length() > 0)) {
150                         String[] artifactTypes = curval.split(",");
151
152                         relevantArtifactTypes = new LinkedList<String>();
153
154                         for (int i = 0 ; i < artifactTypes.length ; i++) {
155                                 try {
156                                         if (ArtifactTypeEnum.valueOf(artifactTypes[i]) != null) {
157                                                         relevantArtifactTypes.add(artifactTypes[i]);
158                                         } else {
159                                                 LOG.warn("Skipping unrecognized artifact type "+artifactTypes[i]);
160                                         }
161                                 } catch (Exception e) {
162
163                                         LOG.warn("Caught exception validating artifact type "+artifactTypes[i], e);
164                                 }
165
166                         }
167
168                 }
169
170                 curval = props.getProperty("org.openecomp.sdnc.uebclient.activate-server-tls-auth", "false");
171                 activateServerTLSAuth = "true".equalsIgnoreCase(curval);
172                 keyStorePath = props.getProperty("org.openecomp.sdnc.uebclient.keystore-path");
173                 keyStorePassword = props.getProperty("org.openecomp.sdnc.uebclient.keystore-password");
174                 xsltPathList = props.getProperty("org.openecomp.sdnc.uebclient.xslt-path-list");
175
176
177                 String artifactMapFile = props.getProperty("org.openecomp.sdnc.uebclient.artifact-map");
178                 if (artifactMapFile != null) {
179                         artifactMap.load(artifactMapFile);
180                 }
181
182         }
183
184         @Override
185         public String getAsdcAddress() {
186                 return asdcAddress;
187         }
188
189         @Override
190         public String getConsumerGroup() {
191                 return consumerGroup;
192         }
193
194         @Override
195         public String getConsumerID() {
196                 return consumerID;
197         }
198
199         @Override
200         public String getEnvironmentName() {
201                 return environmentName;
202         }
203
204         @Override
205         public String getPassword() {
206                 return password;
207         }
208
209         @Override
210         public int getPollingInterval() {
211                 return pollingInterval;
212         }
213
214         @Override
215         public int getPollingTimeout() {
216                 return pollingTimeout;
217         }
218
219         @Override
220         public List<String> getRelevantArtifactTypes() {
221                 return relevantArtifactTypes;
222         }
223
224         @Override
225         public String getUser() {
226                 return user;
227         }
228
229
230         public String getSdncUser() {
231                 return sdncUser;
232         }
233
234         public String getSdncPasswd() {
235                 return sdncPasswd;
236         }
237
238         public String getAsdcApiBaseUrl() {
239                 return asdcApiBaseUrl;
240         }
241
242         @Override
243         public boolean activateServerTLSAuth() {
244                 return activateServerTLSAuth;
245         }
246
247         @Override
248         public String getKeyStorePassword() {
249                 return keyStorePassword;
250         }
251
252         @Override
253         public String getKeyStorePath() {
254                 return keyStorePath;
255         }
256
257         public String getIncomingDir() {
258                 return incomingDir;
259         }
260
261         public String getArchiveDir() {
262                 return archiveDir;
263         }
264
265         public int getMaxPasses() {
266                 return(artifactMap.getNumPasses());
267         }
268
269         public SdncArtifactMap.SdncArtifactType getMapping(String tag) {
270                 return(artifactMap.getMapping(tag));
271         }
272
273         @Override
274         public boolean isFilterInEmptyResources() {
275                 // TODO Auto-generated method stub
276                 return false;
277         }
278
279
280 }