2 * ================================================================================
3 * Copyright (c) 2019-2020 China Mobile. All rights reserved.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 * ============LICENSE_END=========================================================
20 package org.onap.dcae.analytics.tca.web;
22 import java.util.ArrayList;
23 import java.util.List;
25 import java.util.stream.Stream;
27 import org.onap.dcae.analytics.model.AnalyticsProfile;
28 import org.onap.dcae.analytics.model.TcaModelConstants;
29 import org.onap.dcae.analytics.model.configbindingservice.BaseConfigBindingServiceProperties;
30 import org.onap.dcae.analytics.model.configbindingservice.ConfigBindingServiceConstants;
31 import org.springframework.core.env.Environment;
34 import lombok.ToString;
40 public class TcaAppProperties extends BaseConfigBindingServiceProperties {
42 private final Environment environment;
44 public TcaAppProperties(final Environment environment) {
45 this.environment = environment;
48 * TCA Application properties
51 public static class Tca {
52 private String policy;
53 private Integer processingBatchSize = TcaModelConstants.DEFAULT_TCA_PROCESSING_BATCH_SIZE;
54 private Boolean enableAbatement = TcaModelConstants.DEFAULT_ABATEMENT_ENABLED;
55 private Boolean enableEcompLogging = TcaModelConstants.DEFAULT_ECOMP_LOGGING_ENABLED;
56 private Aai aai = new Aai();
63 @ToString(exclude = "password")
64 public static class Aai {
66 private Boolean enableEnrichment = TcaModelConstants.DEFAULT_AAI_ENRICHMENT_ENABLED;
68 private String username;
69 private String password;
71 private String proxyUrl = null;
72 private Boolean ignoreSSLValidation = TcaModelConstants.DEFAULT_TCA_AAI_IGNORE_SSL_VALIDATION;
74 private String genericVnfPath = TcaModelConstants.DEFAULT_TCA_AAI_GENERIC_VNF_PATH;
75 private String nodeQueryPath = TcaModelConstants.DEFAULT_TCA_AAI_NODE_QUERY_PATH;
81 tca.setPolicy(environment.getProperty(ConfigBindingServiceConstants.POLICY));
82 tca.setProcessingBatchSize(environment.getProperty(ConfigBindingServiceConstants.PROCESSINGBATCHSIZE, Integer.class));
83 tca.setEnableAbatement(environment.getProperty(ConfigBindingServiceConstants.ENABLEABATEMENT, Boolean.class));
84 tca.setEnableEcompLogging(environment.getProperty(ConfigBindingServiceConstants.ENABLEECOMPLOGGING, Boolean.class));
86 Aai aai = tca.getAai();
87 aai.setEnableEnrichment(environment.getProperty(ConfigBindingServiceConstants.ENABLEENRICHMENT, Boolean.class));
88 aai.setUrl(environment.getProperty(ConfigBindingServiceConstants.AAIURL));
89 aai.setUsername(environment.getProperty(ConfigBindingServiceConstants.AAIUSERNAME));
90 aai.setPassword(environment.getProperty(ConfigBindingServiceConstants.AAIPASSWORD));
91 aai.setGenericVnfPath(ConfigBindingServiceConstants.AAIGENERICVNFPATH);
92 aai.setNodeQueryPath(environment.getProperty(ConfigBindingServiceConstants.AAINODEQUERYPATH));
99 public Map<String, PublisherDetails> getStreamsPublishes() {
100 DmaapInfo dmaapInfo = new DmaapInfo();
101 dmaapInfo.setTopicUrl(environment.getProperty(ConfigBindingServiceConstants.PUBTOPICURL));
103 PublisherDetails detail = new PublisherDetails();
104 detail.setType(environment.getProperty(ConfigBindingServiceConstants.PUBTYPE));
105 detail.setDmaapInfo(dmaapInfo);
106 streamsPublishes.put(ConfigBindingServiceConstants.PUBKEY, detail);
107 return streamsPublishes;
111 public Map<String, SubscriberDetails> getStreamsSubscribes() {
112 DmaapInfo dmaapInfo = new DmaapInfo();
113 dmaapInfo.setTopicUrl(environment.getProperty(ConfigBindingServiceConstants.SUBTOPICURL));
115 AutoAdjusting autoAdjust = new AutoAdjusting();
116 autoAdjust.setStepUp(environment.getProperty(ConfigBindingServiceConstants.SUBAUTOADJUSTINGSTEPUP, Integer.class));
117 autoAdjust.setStepDown(environment.getProperty(ConfigBindingServiceConstants.SUBAUTOADJUSTINGSTEPDOWN, Integer.class));
118 autoAdjust.setMax(environment.getProperty(ConfigBindingServiceConstants.SUBAUTOADJUSTINGMAX, Integer.class));
119 autoAdjust.setMin(environment.getProperty(ConfigBindingServiceConstants.SUBAUTOADJUSTINGMIN, Integer.class));
121 Polling poll = new Polling();
122 poll.setAutoAdjusting(autoAdjust);
123 poll.setFixedRate(environment.getProperty(ConfigBindingServiceConstants.SUBFIXEDRATE, Integer.class));
125 SubscriberDetails detail = new SubscriberDetails();
126 detail.setType(environment.getProperty(ConfigBindingServiceConstants.SUBTYPE));
127 detail.setDmaapInfo(dmaapInfo);
128 detail.setPolling(poll);
130 detail.setConsumerGroup(environment.getProperty(ConfigBindingServiceConstants.SUBCONSUMERGROUP));
131 detail.setMessageLimit(environment.getProperty(ConfigBindingServiceConstants.SUBMESSAGELIMIT, Integer.class));
132 detail.setTimeout(environment.getProperty(ConfigBindingServiceConstants.SUBTIMEOUT, Integer.class));
133 List<String> consumerIds = new ArrayList<>();
134 consumerIds.add(environment.getProperty(ConfigBindingServiceConstants.SUBCONSUMERIDS0));
135 consumerIds.add(environment.getProperty(ConfigBindingServiceConstants.SUBCONSUMERIDS1));
136 detail.setConsumerIds(consumerIds);
138 streamsSubscribes.put(ConfigBindingServiceConstants.SUBKEY, detail);
139 return streamsSubscribes;
142 public boolean isConfigBindingServiceProfileActive() {
143 return Stream.of(environment.getActiveProfiles())
145 profile.equalsIgnoreCase(AnalyticsProfile.CONFIG_BINDING_SERVICE_PROFILE_NAME));