2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 AT&T Intellectual Property. All rights
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
24 package org.onap.clamp.clds.config.sdc;
26 import com.att.eelf.configuration.EELFLogger;
27 import com.att.eelf.configuration.EELFManager;
28 import com.fasterxml.jackson.databind.JsonNode;
30 import java.security.GeneralSecurityException;
31 import java.util.Arrays;
32 import java.util.Collections;
33 import java.util.List;
35 import org.apache.commons.codec.DecoderException;
36 import org.onap.clamp.clds.exception.sdc.controller.SdcParametersException;
37 import org.onap.clamp.clds.util.CryptoUtils;
38 import org.openecomp.sdc.api.consumer.IConfiguration;
41 * This class maps the SDC config JSON for one controller.
43 public class SdcSingleControllerConfiguration implements IConfiguration {
45 private static final EELFLogger logger = EELFManager.getInstance()
46 .getLogger(SdcSingleControllerConfiguration.class);
48 * The sdc Controller name corresponding.
50 private String sdcControllerName;
52 * The root of the JSON.
54 private JsonNode jsonRootNode;
55 // All keys that can be present in the JSON
56 public static final String CONSUMER_GROUP_ATTRIBUTE_NAME = "consumerGroup";
57 public static final String CONSUMER_ID_ATTRIBUTE_NAME = "consumerId";
58 public static final String ENVIRONMENT_NAME_ATTRIBUTE_NAME = "environmentName";
59 public static final String SDC_KEY_ATTRIBUTE_NAME = "password";
60 public static final String POLLING_INTERVAL_ATTRIBUTE_NAME = "pollingInterval";
61 public static final String RELEVANT_ARTIFACT_TYPES_ATTRIBUTE_NAME = "relevantArtifactTypes";
62 public static final String USER_ATTRIBUTE_NAME = "user";
63 public static final String SDC_ADDRESS_ATTRIBUTE_NAME = "sdcAddress";
64 public static final String POLLING_TIMEOUT_ATTRIBUTE_NAME = "pollingTimeout";
65 public static final String ACTIVATE_SERVER_TLS_AUTH = "activateServerTLSAuth";
66 public static final String KEY_STORE_KEY = "keyStorePassword";
67 public static final String KEY_STORE_PATH = "keyStorePath";
68 private String errorMessageKeyNotFound;
70 * Supported artifact types.
72 public static final String HEAT = "HEAT";
73 public static final String HEAT_ARTIFACT = "HEAT_ARTIFACT";
74 public static final String HEAT_ENV = "HEAT_ENV";
75 public static final String HEAT_NESTED = "HEAT_NESTED";
76 public static final String HEAT_NET = "HEAT_NET";
77 public static final String HEAT_VOL = "HEAT_VOL";
78 public static final String OTHER = "OTHER";
79 public static final String TOSCA_CSAR = "TOSCA_CSAR";
80 public static final String VF_MODULES_METADATA = "VF_MODULES_METADATA";
81 private static final String[] SUPPORTED_ARTIFACT_TYPES = {
82 HEAT, HEAT_ARTIFACT, HEAT_ENV, HEAT_NESTED, HEAT_NET, HEAT_VOL, OTHER, TOSCA_CSAR, VF_MODULES_METADATA
84 public static final List<String> SUPPORTED_ARTIFACT_TYPES_LIST = Collections
85 .unmodifiableList(Arrays.asList(SUPPORTED_ARTIFACT_TYPES));
88 * This constructor builds a SdcSingleControllerConfiguration from the
93 * @param controllerName
94 * The controller name that must appear in the JSON
96 public SdcSingleControllerConfiguration(JsonNode jsonNode, String controllerName) {
97 jsonRootNode = jsonNode;
98 setSdcControllerName(controllerName);
99 testAllRequiredParameters();
102 public String getSdcControllerName() {
103 return sdcControllerName;
106 public void setSdcControllerName(String controllerName) {
107 this.sdcControllerName = controllerName;
108 errorMessageKeyNotFound = " parameter cannot be found in config file for controller name" + sdcControllerName;
109 testAllRequiredParameters();
112 private String getStringConfig(String key) {
113 if (jsonRootNode != null && jsonRootNode.get(key) != null) {
114 String config = jsonRootNode.get(key).asText();
115 return config.isEmpty() ? null : config;
120 private Integer getIntConfig(String key) {
121 if (jsonRootNode != null && jsonRootNode.get(key) != null) {
122 return jsonRootNode.get(key).asInt();
128 private String getEncryptedStringConfig(String key) throws GeneralSecurityException, DecoderException {
129 if (jsonRootNode != null && jsonRootNode.get(key) != null) {
130 String config = CryptoUtils.decrypt(jsonRootNode.get(key).asText());
131 return config.isEmpty() ? null : config;
137 public java.lang.Boolean isUseHttpsWithDmaap() {
142 public String getConsumerGroup() {
143 if (jsonRootNode != null && jsonRootNode.get(CONSUMER_GROUP_ATTRIBUTE_NAME) != null) {
144 String config = jsonRootNode.get(CONSUMER_GROUP_ATTRIBUTE_NAME).asText();
145 return "NULL".equals(config) || config.isEmpty() ? null : config;
151 public String getConsumerID() {
152 return getStringConfig(CONSUMER_ID_ATTRIBUTE_NAME);
156 public String getEnvironmentName() {
157 return getStringConfig(ENVIRONMENT_NAME_ATTRIBUTE_NAME);
161 public String getPassword() {
163 return getEncryptedStringConfig(SDC_KEY_ATTRIBUTE_NAME);
164 } catch (GeneralSecurityException | DecoderException e) {
165 logger.error("Unable to decrypt the SDC password", e);
171 public int getPollingInterval() {
172 return getIntConfig(POLLING_INTERVAL_ATTRIBUTE_NAME);
176 public List<String> getRelevantArtifactTypes() {
177 // DO not return the Static List SUPPORTED_ARTIFACT_TYPES_LIST because
178 // the ASDC Client could try to modify it !!!
179 return Arrays.asList(SUPPORTED_ARTIFACT_TYPES);
183 public String getUser() {
184 return getStringConfig(USER_ATTRIBUTE_NAME);
188 public String getAsdcAddress() {
189 return getStringConfig(SDC_ADDRESS_ATTRIBUTE_NAME);
193 public int getPollingTimeout() {
194 return getIntConfig(POLLING_TIMEOUT_ATTRIBUTE_NAME);
198 public boolean activateServerTLSAuth() {
199 if (jsonRootNode != null && jsonRootNode.get(ACTIVATE_SERVER_TLS_AUTH) != null) {
200 return jsonRootNode.get(ACTIVATE_SERVER_TLS_AUTH).asBoolean(false);
207 public String getKeyStorePassword() {
209 return getEncryptedStringConfig(KEY_STORE_KEY);
210 } catch (GeneralSecurityException | DecoderException e) {
211 logger.error("Unable to decrypt the SDC password", e);
217 public String getKeyStorePath() {
218 return getStringConfig(KEY_STORE_PATH);
222 * This method can be used to validate all required parameters are well
225 public void testAllRequiredParameters() {
226 // Special case for this attribute that can be null from
228 if (jsonRootNode == null) {
229 throw new SdcParametersException("Json is null for controller " + this.getSdcControllerName());
231 if (this.getConsumerGroup() == null && (jsonRootNode.get(CONSUMER_GROUP_ATTRIBUTE_NAME) == null
232 || !"NULL".equals(jsonRootNode.get(CONSUMER_GROUP_ATTRIBUTE_NAME).asText()))) {
233 throw new SdcParametersException(CONSUMER_GROUP_ATTRIBUTE_NAME + errorMessageKeyNotFound);
235 if (this.getConsumerID() == null || this.getConsumerID().isEmpty()) {
236 throw new SdcParametersException(CONSUMER_ID_ATTRIBUTE_NAME + errorMessageKeyNotFound);
238 if (this.getEnvironmentName() == null || this.getEnvironmentName().isEmpty()) {
239 throw new SdcParametersException(ENVIRONMENT_NAME_ATTRIBUTE_NAME + errorMessageKeyNotFound);
241 if (this.getAsdcAddress() == null || this.getAsdcAddress().isEmpty()) {
242 throw new SdcParametersException(SDC_ADDRESS_ATTRIBUTE_NAME + errorMessageKeyNotFound);
244 if (this.getPassword() == null || this.getPassword().isEmpty()) {
245 throw new SdcParametersException(SDC_KEY_ATTRIBUTE_NAME + errorMessageKeyNotFound);
247 if (this.getPollingInterval() == 0) {
248 throw new SdcParametersException(POLLING_INTERVAL_ATTRIBUTE_NAME + errorMessageKeyNotFound);
250 if (this.getPollingTimeout() == 0) {
251 throw new SdcParametersException(POLLING_TIMEOUT_ATTRIBUTE_NAME + errorMessageKeyNotFound);
253 if (this.getRelevantArtifactTypes() == null || this.getRelevantArtifactTypes().isEmpty()) {
254 throw new SdcParametersException(RELEVANT_ARTIFACT_TYPES_ATTRIBUTE_NAME + errorMessageKeyNotFound);
256 if (this.getUser() == null || this.getUser().isEmpty()) {
257 throw new SdcParametersException(USER_ATTRIBUTE_NAME + errorMessageKeyNotFound);
262 * The flag allows the client to receive metadata for all resources of the
263 * service regardless of the artifacts associated to them. Setting the flag
264 * to false will preserve legacy behavior.
267 public boolean isFilterInEmptyResources() {
272 public List<String> getMsgBusAddress() {