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