2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 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.
20 * ============LICENSE_END=========================================================
23 package org.onap.appc.sdc.listener;
25 import com.att.eelf.configuration.EELFLogger;
26 import com.att.eelf.configuration.EELFManager;
27 import com.google.common.collect.Lists;
29 import java.net.URISyntaxException;
30 import java.util.ArrayList;
31 import java.util.Collections;
32 import java.util.HashMap;
33 import java.util.List;
35 import java.util.Properties;
36 import org.apache.commons.lang.StringUtils;
37 import org.onap.sdc.api.consumer.IConfiguration;
39 public class SdcConfig implements IConfiguration {
42 private String consumer;
43 private String consumerId;
45 private String keystorePath;
46 private String keystorePass;
48 * Polling internal is time between listening sessions
50 private int pollingInterval;
52 * Polling timeout is the time to listen for (dmaap timeout url param)/1000
54 private int pollingTimeout;
55 private List<String> types = new ArrayList<>();
59 private Properties props;
60 private final EELFLogger logger = EELFManager.getInstance().getLogger(SdcConfig.class);
62 SdcConfig(Properties props) throws URISyntaxException {
67 private void init() throws URISyntaxException {
69 logger.error("SdcConfig init is skipped due to properties is null");
72 // Keystore for ca cert
73 keystorePath = props.getProperty("appc.sdc.keystore.path");
74 keystorePass = props.getProperty("appc.sdc.keystore.pass");
77 host = props.getProperty("appc.sdc.host");
78 env = props.getProperty("appc.sdc.env");
79 user = props.getProperty("appc.sdc.user");
80 pass = props.getProperty("appc.sdc.pass");
83 consumer = props.getProperty("appc.sdc.consumer");
84 consumerId = props.getProperty("appc.sdc.consumer.id");
86 pollingInterval = Integer.valueOf(props.getProperty("interval", "60"));
88 // Client uses cambriaClient-0.2.4 which throws non relevant (wrong)
89 // exceptions with times > 30s
90 pollingTimeout = Integer.valueOf(props.getProperty("timeout", "25"));
92 // Anything less than 60 and we risk 429 Too Many Requests
93 if (pollingInterval < 60) {
97 if (pollingInterval > pollingTimeout) {
98 logger.warn(String.format(
99 "Message acknowledgement may be delayed by %ds in the ADSC listener. [Listening Time: %s, Poll Period: %s]",
100 pollingInterval - pollingTimeout, pollingTimeout, pollingInterval));
107 This types seems redundant, as it looks from the code that they are not being used anywhere
109 types.add("APPC_CONFIG");
110 types.add("VF_LICENSE");
111 // types.add("TOSCA_CSAR"); commenting it out as we are not listening to TOSCA_CSAR
113 storeOp = new URI(props.getProperty("appc.sdc.provider.url"));
117 public boolean activateServerTLSAuth() {
122 public boolean isFilterInEmptyResources() {
127 public String getAsdcAddress() {
132 public String getConsumerGroup() {
137 public String getConsumerID() {
142 public String getEnvironmentName() {
147 public String getKeyStorePassword() {
152 public String getKeyStorePath() {
157 public String getPassword() {
162 public int getPollingInterval() {
163 return pollingInterval;
167 public int getPollingTimeout() {
168 return pollingTimeout;
172 public List<String> getRelevantArtifactTypes() {
177 public String getUser() {
182 public Boolean isUseHttpsWithDmaap() {
187 public List<String> getMsgBusAddress() {
188 return getMsgBusProperties();
191 public List<String> getMsgBusProperties() {
192 List<String> uebAddresses;
193 String uebAddressesList;
194 if (null != this.props) {
195 uebAddressesList = this.props.getProperty("appc.ClosedLoop.poolMembers");
197 logger.info("SdcConfig:SdcConfig:getMsgBusProperties()::props is null for SdcConfig");
198 return Collections.emptyList();
200 if (null == uebAddressesList) {
201 logger.info("SdcConfig:SdcConfig:getMsgBusProperties()::uebAddressesList is null for SdcConfig");
202 return Collections.emptyList();
204 logger.debug("SdcConfig:SdcConfig:getMsgBusProperties()::uebAddressesList is=" + uebAddressesList);
205 String[] sList = uebAddressesList.split(",");
206 uebAddresses = formatAddresses(sList);
207 logger.debug("SdcConfig:getMsgBusProperties:::Returning addresses as " + uebAddresses.toString());
211 URI getStoreOpURI() {
216 * Logs the relevant parameters
218 private void logParams() {
219 Map<String, String> params = new HashMap<>();
220 params.put("SDC Host", getAsdcAddress());
221 params.put("SDC Environment", getEnvironmentName());
222 params.put("Consumer Name", getConsumerGroup());
223 params.put("Consumer ID", getConsumerID());
224 params.put("Poll Active Wait", String.valueOf(getPollingInterval()));
225 params.put("Poll Timeout", String.valueOf(getPollingTimeout()));
227 logger.info(String.format("SDC Params: %s", params));
230 private List<String> formatAddresses(String[] sList) {
231 List<String> uebAddresses = new ArrayList<>();
232 for (String fqdnPort : sList) {
233 if (fqdnPort.startsWith("http")) {
234 fqdnPort = StringUtils.substringAfter(fqdnPort, "://");
236 if (fqdnPort.contains(":")) {
237 fqdnPort = StringUtils.substringBefore(fqdnPort, ":");
239 logger.debug("SdcConfig:formatAddresses:: " + fqdnPort);
240 uebAddresses.add(fqdnPort);