Change nexus values to properties
[appc.git] / app-c / appc / appc-asdc-listener / appc-asdc-listener-bundle / src / main / java / org / openecomp / appc / sdc / listener / AsdcConfig.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * openECOMP : APP-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.appc.sdc.listener;
23
24 import java.net.URI;
25 import java.util.ArrayList;
26 import java.util.HashMap;
27 import java.util.List;
28 import java.util.Map;
29 import java.util.Properties;
30
31 import org.openecomp.sdc.api.consumer.IConfiguration;
32 import org.openecomp.sdc.utils.ArtifactTypeEnum;
33 import com.att.eelf.configuration.EELFLogger;
34 import com.att.eelf.configuration.EELFManager;
35
36 public class AsdcConfig implements IConfiguration {
37
38         private String host;
39         private String consumer;
40         private String consumerId;
41         private String env;
42         private String keystorePath;
43         private String keystorePass;
44         private int pollingInterval; // Time between listening sessions
45         private int pollingTimeout; // Time to listen for (dmaap timeout url param)/1000
46         private List<String> types = new ArrayList<>(1);
47         private String user;
48         private String pass;
49
50         private URI storeOp;
51
52         Properties props;
53
54         private final EELFLogger logger = EELFManager.getInstance().getLogger(AsdcConfig.class);
55
56         public AsdcConfig(Properties props) throws Exception {
57                 this.props = props;
58                 init();
59         }
60
61         private void init() throws Exception {
62                 if (props != null) {
63                         // Keystore for ca cert
64                         keystorePath = props.getProperty("appc.asdc.keystore.path");
65                         keystorePass = props.getProperty("appc.asdc.keystore.pass");
66
67                         // ASDC host
68                         host = props.getProperty("appc.asdc.host");
69                         env = props.getProperty("appc.asdc.env");
70                         user = props.getProperty("appc.asdc.user");
71                         pass = props.getProperty("appc.asdc.pass");
72
73                         // DMaaP properties
74                         consumer = props.getProperty("appc.asdc.consumer");
75                         consumerId = props.getProperty("appc.asdc.consumer.id");
76
77                         pollingInterval = Integer.valueOf(props.getProperty("interval", "60"));
78
79                         // Client uses cambriaClient-0.2.4 which throws non relevant (wrong)
80                         // exceptions with times > 30s
81                         pollingTimeout = Integer.valueOf(props.getProperty("timeout", "25"));
82
83                         // Anything less than 60 and we risk 429 Too Many Requests
84                         if (pollingInterval < 60) {
85                                 pollingInterval = 60;
86                         }
87
88                         if (pollingInterval > pollingInterval) {
89                                 logger.warn(String.format(
90                                                 "Message acknowledgement may be delayed by %ds in the ADSC listener. [Listening Time: %s, Poll Period: %s]",
91                                                 pollingInterval - pollingTimeout, pollingTimeout, pollingInterval));
92                         }
93
94                         logParams();
95
96                         // Download type
97                         types.add("APPC_CONFIG");
98                         types.add("VF_LICENSE");
99
100                         storeOp = new URI(props.getProperty("appc.asdc.provider.url"));
101                 }
102         }
103
104         @Override
105         public boolean activateServerTLSAuth() {
106                 return false;
107         }
108
109         @Override
110         public String getAsdcAddress() {
111                 return host;
112         }
113
114         @Override
115         public String getConsumerGroup() {
116                 return consumer;
117         }
118
119         @Override
120         public String getConsumerID() {
121                 return consumerId;
122         }
123
124         @Override
125         public String getEnvironmentName() {
126                 return env;
127         }
128
129         @Override
130         public String getKeyStorePassword() {
131                 return keystorePass;
132         }
133
134         @Override
135         public String getKeyStorePath() {
136                 return keystorePath;
137         }
138
139         @Override
140         public String getPassword() {
141                 return pass;
142         }
143
144         @Override
145         public int getPollingInterval() {
146                 return pollingInterval;
147         }
148
149         @Override
150         public int getPollingTimeout() {
151                 return pollingTimeout;
152         }
153
154         @Override
155         public List<String> getRelevantArtifactTypes() {
156                 return types;
157         }
158
159         @Override
160         public String getUser() {
161                 return user;
162         }
163
164         public URI getStoreOpURI() {
165                 return storeOp;
166         }
167
168         /**
169          * Logs the relevant parameters
170          */
171         public void logParams() {
172                 Map<String, String> params = new HashMap<String, String>();
173                 params.put("ASDC Host", getAsdcAddress());
174                 params.put("ASDC Environment", getEnvironmentName());
175                 params.put("Consumer Name", getConsumerGroup());
176                 params.put("Consumer ID", getConsumerID());
177                 params.put("Poll Active Wait", String.valueOf(getPollingInterval()));
178                 params.put("Poll Timeout", String.valueOf(getPollingTimeout()));
179
180                 logger.info(String.format("ASDC Params: %s", params));
181         }
182 }