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