2 * ============LICENSE_START=======================================================
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
25 package org.onap.appc.sdc.listener;
27 import com.att.eelf.configuration.EELFLogger;
28 import com.att.eelf.configuration.EELFManager;
29 import com.google.common.collect.Lists;
31 import java.net.URISyntaxException;
32 import java.util.ArrayList;
33 import java.util.Collections;
34 import java.util.HashMap;
35 import java.util.List;
37 import java.util.Properties;
38 import org.apache.commons.lang.StringUtils;
39 import org.openecomp.sdc.api.consumer.IConfiguration;
41 public class SdcConfig implements IConfiguration {
44 private String consumer;
45 private String consumerId;
47 private String keystorePath;
48 private String keystorePass;
50 * Polling internal is time between listening sessions
52 private int pollingInterval;
54 * Polling timeout is the time to listen for (dmaap timeout url param)/1000
56 private int pollingTimeout;
57 private List<String> types = new ArrayList<>();
61 private Properties props;
62 private final EELFLogger logger = EELFManager.getInstance().getLogger(SdcConfig.class);
64 SdcConfig(Properties props) throws URISyntaxException {
69 private void init() throws URISyntaxException {
71 logger.error("SdcConfig init is skipped due to properties is null");
74 // Keystore for ca cert
75 keystorePath = props.getProperty("appc.sdc.keystore.path");
76 keystorePass = props.getProperty("appc.sdc.keystore.pass");
79 host = props.getProperty("appc.sdc.host");
80 env = props.getProperty("appc.sdc.env");
81 user = props.getProperty("appc.sdc.user");
82 pass = props.getProperty("appc.sdc.pass");
85 consumer = props.getProperty("appc.sdc.consumer");
86 consumerId = props.getProperty("appc.sdc.consumer.id");
88 pollingInterval = Integer.valueOf(props.getProperty("interval", "60"));
90 // Client uses cambriaClient-0.2.4 which throws non relevant (wrong)
91 // exceptions with times > 30s
92 pollingTimeout = Integer.valueOf(props.getProperty("timeout", "25"));
94 // Anything less than 60 and we risk 429 Too Many Requests
95 if (pollingInterval < 60) {
99 if (pollingInterval > pollingTimeout) {
100 logger.warn(String.format(
101 "Message acknowledgement may be delayed by %ds in the ADSC listener. [Listening Time: %s, Poll Period: %s]",
102 pollingInterval - pollingTimeout, pollingTimeout, pollingInterval));
109 This types seems redundant, as it looks from the code that they are not being used anywhere
111 types.add("APPC_CONFIG");
112 types.add("VF_LICENSE");
113 // types.add("TOSCA_CSAR"); commenting it out as we are not listening to TOSCA_CSAR
115 storeOp = new URI(props.getProperty("appc.sdc.provider.url"));
119 public boolean activateServerTLSAuth() {
124 public boolean isFilterInEmptyResources() {
129 public String getAsdcAddress() {
134 public String getConsumerGroup() {
139 public String getConsumerID() {
144 public String getEnvironmentName() {
149 public String getKeyStorePassword() {
154 public String getKeyStorePath() {
159 public String getPassword() {
164 public int getPollingInterval() {
165 return pollingInterval;
169 public int getPollingTimeout() {
170 return pollingTimeout;
174 public List<String> getRelevantArtifactTypes() {
179 public String getUser() {
184 public Boolean isUseHttpsWithDmaap() {
189 public List<String> getMsgBusAddress() {
190 return getMsgBusProperties();
193 public List<String> getMsgBusProperties() {
194 List<String> uebAddresses;
195 String uebAddressesList;
196 if (null != this.props) {
197 uebAddressesList = this.props.getProperty("appc.ClosedLoop.poolMembers");
199 logger.info("SdcConfig:SdcConfig:getMsgBusProperties()::props is null for SdcConfig");
200 return Collections.emptyList();
202 if (null == uebAddressesList) {
203 logger.info("SdcConfig:SdcConfig:getMsgBusProperties()::uebAddressesList is null for SdcConfig");
204 return Collections.emptyList();
206 logger.debug("SdcConfig:SdcConfig:getMsgBusProperties()::uebAddressesList is=" + uebAddressesList);
207 String[] sList = uebAddressesList.split(",");
208 uebAddresses = formatAddresses(sList);
209 logger.debug("SdcConfig:getMsgBusProperties:::Returning addresses as " + uebAddresses.toString());
213 URI getStoreOpURI() {
218 * Logs the relevant parameters
220 private void logParams() {
221 Map<String, String> params = new HashMap<>();
222 params.put("SDC Host", getAsdcAddress());
223 params.put("SDC Environment", getEnvironmentName());
224 params.put("Consumer Name", getConsumerGroup());
225 params.put("Consumer ID", getConsumerID());
226 params.put("Poll Active Wait", String.valueOf(getPollingInterval()));
227 params.put("Poll Timeout", String.valueOf(getPollingTimeout()));
229 logger.info(String.format("SDC Params: %s", params));
232 private List<String> formatAddresses(String[] sList) {
233 List<String> uebAddresses = new ArrayList<>();
234 for (String fqdnPort : sList) {
235 if (fqdnPort.startsWith("http")) {
236 fqdnPort = StringUtils.substringAfter(fqdnPort, "://");
238 if (fqdnPort.contains(":")) {
239 fqdnPort = StringUtils.substringBefore(fqdnPort, ":");
241 logger.debug("SdcConfig:formatAddresses:: " + fqdnPort);
242 uebAddresses.add(fqdnPort);