diff options
author | Kai <lukai@chinamobile.com> | 2020-02-05 13:09:23 +0800 |
---|---|---|
committer | LUKAI <lukai@chinamobile.com> | 2020-02-10 06:48:50 +0000 |
commit | a6b11ee264c2e3f4d20632b006f281025448507f (patch) | |
tree | 08c40aa1bc391adea25ee0cda0bd539ba15372d2 /dcae-analytics/dcae-analytics-tca-web/src/main | |
parent | 5cfa2de9371778236c1548a1961413d47abd4eb2 (diff) |
new config not reflected in TCA processing
Issue-ID: DCAEGEN2-2043
Signed-off-by: Kai Lu <lukai@chinamobile.com>
Change-Id: I9f757ce8931f725dd1c7c5398c0d40453d52e0d8
Diffstat (limited to 'dcae-analytics/dcae-analytics-tca-web/src/main')
4 files changed, 147 insertions, 79 deletions
diff --git a/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/TcaAppProperties.java b/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/TcaAppProperties.java index 9ee625a..63fd2f6 100644 --- a/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/TcaAppProperties.java +++ b/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/TcaAppProperties.java @@ -1,6 +1,6 @@ /* * ================================================================================ - * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved. + * Copyright (c) 2019-2020 China Mobile. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,55 +19,49 @@ package org.onap.dcae.analytics.tca.web; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.stream.Stream; +import org.onap.dcae.analytics.model.AnalyticsProfile; import org.onap.dcae.analytics.model.TcaModelConstants; import org.onap.dcae.analytics.model.configbindingservice.BaseConfigBindingServiceProperties; import org.onap.dcae.analytics.model.configbindingservice.ConfigBindingServiceConstants; -import org.onap.dcae.analytics.model.configbindingservice.ConfigBindingServiceModel; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.validation.annotation.Validated; +import org.springframework.core.env.Environment; + +import lombok.Data; +import lombok.ToString; /** - * @author Rajiv Singla + * @author Kai Lu */ -@Data -@EqualsAndHashCode(callSuper = true) -@ConfigurationProperties(ConfigBindingServiceConstants.CONFIG_BINDING_SERVICE_PROPERTIES_KEY) -@Validated -public class TcaAppProperties extends BaseConfigBindingServiceProperties { - private static final long serialVersionUID = 1L; +public class TcaAppProperties extends BaseConfigBindingServiceProperties { - private Tca tca; + private final Environment environment; + public TcaAppProperties(final Environment environment) { + this.environment = environment; + } /** * TCA Application properties */ @Data - public static class Tca implements ConfigBindingServiceModel { - - private static final long serialVersionUID = 1L; - + public static class Tca { private String policy; private Integer processingBatchSize = TcaModelConstants.DEFAULT_TCA_PROCESSING_BATCH_SIZE; private Boolean enableAbatement = TcaModelConstants.DEFAULT_ABATEMENT_ENABLED; private Boolean enableEcompLogging = TcaModelConstants.DEFAULT_ECOMP_LOGGING_ENABLED; private Aai aai = new Aai(); - } - /** * A&AI properties */ @Data @ToString(exclude = "password") - public static class Aai implements ConfigBindingServiceModel { - - private static final long serialVersionUID = 1L; + public static class Aai { private Boolean enableEnrichment = TcaModelConstants.DEFAULT_AAI_ENRICHMENT_ENABLED; private String url; @@ -82,5 +76,73 @@ public class TcaAppProperties extends BaseConfigBindingServiceProperties { } + public Tca getTca() { + Tca tca = new Tca(); + tca.setPolicy(environment.getProperty(ConfigBindingServiceConstants.POLICY)); + tca.setProcessingBatchSize(environment.getProperty(ConfigBindingServiceConstants.PROCESSINGBATCHSIZE, Integer.class)); + tca.setEnableAbatement(environment.getProperty(ConfigBindingServiceConstants.ENABLEABATEMENT, Boolean.class)); + tca.setEnableEcompLogging(environment.getProperty(ConfigBindingServiceConstants.EnableEcompLogging, Boolean.class)); + + Aai aai = tca.getAai(); + aai.setEnableEnrichment(environment.getProperty(ConfigBindingServiceConstants.EnableEnrichment, Boolean.class)); + aai.setUrl(environment.getProperty(ConfigBindingServiceConstants.AAIURL)); + aai.setUsername(environment.getProperty(ConfigBindingServiceConstants.AAIUSERNAME)); + aai.setPassword(environment.getProperty(ConfigBindingServiceConstants.AAIPASSWORD)); + aai.setGenericVnfPath(ConfigBindingServiceConstants.AAIGENERICVNFPATH); + aai.setNodeQueryPath(environment.getProperty(ConfigBindingServiceConstants.AAINODEQUERYPATH)); + tca.setAai(aai); + + return tca; + } + + @Override + public Map<String, PublisherDetails> getStreamsPublishes() { + DmaapInfo dmaapInfo = new DmaapInfo(); + dmaapInfo.setTopicUrl(environment.getProperty(ConfigBindingServiceConstants.PUBTOPICURL)); + + PublisherDetails detail = new PublisherDetails(); + detail.setType(environment.getProperty(ConfigBindingServiceConstants.PUBTYPE)); + detail.setDmaapInfo(dmaapInfo); + streamsPublishes.put(ConfigBindingServiceConstants.PUBKEY, detail); + return streamsPublishes; + } + + @Override + public Map<String, SubscriberDetails> getStreamsSubscribes() { + DmaapInfo dmaapInfo = new DmaapInfo(); + dmaapInfo.setTopicUrl(environment.getProperty(ConfigBindingServiceConstants.SUBTOPICURL)); + + AutoAdjusting autoAdjust = new AutoAdjusting(); + autoAdjust.setStepUp(environment.getProperty(ConfigBindingServiceConstants.SUBAUTOADJUSTINGSTEPUP, Integer.class)); + autoAdjust.setStepDown(environment.getProperty(ConfigBindingServiceConstants.SUBAUTOADJUSTINGSTEPDOWN, Integer.class)); + autoAdjust.setMax(environment.getProperty(ConfigBindingServiceConstants.SUBAUTOADJUSTINGMAX, Integer.class)); + autoAdjust.setMin(environment.getProperty(ConfigBindingServiceConstants.SUBAUTOADJUSTINGMIN, Integer.class)); + + Polling poll = new Polling(); + poll.setAutoAdjusting(autoAdjust); + poll.setFixedRate(environment.getProperty(ConfigBindingServiceConstants.SUBFIXEDRATE, Integer.class)); + + SubscriberDetails detail = new SubscriberDetails(); + detail.setType(environment.getProperty(ConfigBindingServiceConstants.SUBTYPE)); + detail.setDmaapInfo(dmaapInfo); + detail.setPolling(poll); + + detail.setConsumerGroup(environment.getProperty(ConfigBindingServiceConstants.SUBCONSUMERGROUP)); + detail.setMessageLimit(environment.getProperty(ConfigBindingServiceConstants.SUBMESSAGELIMIT, Integer.class)); + detail.setTimeout(environment.getProperty(ConfigBindingServiceConstants.SUBTIMEOUT, Integer.class)); + List<String> consumerIds = new ArrayList<>(); + consumerIds.add(environment.getProperty(ConfigBindingServiceConstants.SUBCONSUMERIDS0)); + consumerIds.add(environment.getProperty(ConfigBindingServiceConstants.SUBCONSUMERIDS1)); + detail.setConsumerIds(consumerIds); + + streamsSubscribes.put(ConfigBindingServiceConstants.SUBKEY, detail); + return streamsSubscribes; + } -} + public boolean isConfigBindingServiceProfileActive() { + return Stream.of(environment.getActiveProfiles()) + .anyMatch(profile -> + profile.equalsIgnoreCase(AnalyticsProfile.CONFIG_BINDING_SERVICE_PROFILE_NAME)); + + } +}
\ No newline at end of file diff --git a/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/config/TcaMrConfig.java b/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/config/TcaMrConfig.java index 64cb6eb..e330914 100644 --- a/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/config/TcaMrConfig.java +++ b/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/config/TcaMrConfig.java @@ -73,7 +73,6 @@ public class TcaMrConfig { return new TcaAlertTransformer(tcaAppProperties); } - @Bean public IntegrationFlow tcaMrFlow(final TcaPolicyWrapper tcaPolicyWrapper, final QueueChannel mrSubscriberOutputChannel, diff --git a/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/config/TcaWebConfig.java b/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/config/TcaWebConfig.java index 7be20cc..a3ca7a8 100644 --- a/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/config/TcaWebConfig.java +++ b/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/config/TcaWebConfig.java @@ -19,12 +19,6 @@ package org.onap.dcae.analytics.tca.web.config; -import com.fasterxml.jackson.databind.ObjectMapper; - -import java.util.stream.Stream; - -import org.onap.dcae.analytics.model.AnalyticsProfile; -import org.onap.dcae.analytics.model.common.ConfigSource; import org.onap.dcae.analytics.tca.core.service.TcaAaiEnrichmentContext; import org.onap.dcae.analytics.tca.core.service.TcaAbatementContext; import org.onap.dcae.analytics.tca.model.util.json.TcaModelJsonConversion; @@ -34,23 +28,28 @@ import org.onap.dcae.analytics.tca.web.service.TcaProcessingService; import org.onap.dcae.analytics.tca.web.service.TcaProcessingServiceImpl; import org.onap.dcae.analytics.tca.web.validation.TcaAppPropertiesValidator; import org.onap.dcae.analytics.web.config.AnalyticsWebConfig; -import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.core.env.Environment; import org.springframework.validation.Validator; +import com.fasterxml.jackson.databind.ObjectMapper; + /** * @author Rajiv Singla */ @Configuration -@EnableConfigurationProperties(value = TcaAppProperties.class) @Import(value = {AnalyticsWebConfig.class, TcaMrConfig.class, TcaAaiConfig.class, TcaMongoAbatementConfig.class, TcaSimpleAbatementConfig.class, SwaggerConfig.class, ControllerConfig.class}) public class TcaWebConfig { @Bean + public TcaAppProperties tcaAppProperties(final Environment environment) { + return new TcaAppProperties(environment); + } + + @Bean public static Validator configurationPropertiesValidator() { return new TcaAppPropertiesValidator(); } @@ -61,18 +60,8 @@ public class TcaWebConfig { } @Bean - public TcaPolicyWrapper tcaPolicyWrapper(final TcaAppProperties tcaAppProperties, - final Environment environment) { - final String policy = tcaAppProperties.getTca().getPolicy(); - final boolean isConfigBindingServiceProfileActive = - Stream.of(environment.getActiveProfiles()) - .anyMatch(profile -> - profile.equalsIgnoreCase(AnalyticsProfile.CONFIG_BINDING_SERVICE_PROFILE_NAME)); - if (isConfigBindingServiceProfileActive) { - return new TcaPolicyWrapper(policy, ConfigSource.CONFIG_BINDING_SERVICE); - } else { - return new TcaPolicyWrapper(policy, ConfigSource.CLASSPATH); - } + public TcaPolicyWrapper tcaPolicyWrapper(final TcaAppProperties tcaAppProperties) { + return new TcaPolicyWrapper(tcaAppProperties); } @Bean diff --git a/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/domain/TcaPolicyWrapper.java b/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/domain/TcaPolicyWrapper.java index e85932a..c54d27c 100644 --- a/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/domain/TcaPolicyWrapper.java +++ b/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/domain/TcaPolicyWrapper.java @@ -21,78 +21,96 @@ package org.onap.dcae.analytics.tca.web.domain; import static org.onap.dcae.analytics.tca.model.util.json.TcaModelJsonConversion.TCA_POLICY_JSON_FUNCTION; -import lombok.Getter; -import lombok.ToString; - import java.time.ZonedDateTime; import java.util.concurrent.atomic.AtomicInteger; import org.onap.dcae.analytics.model.common.ConfigSource; import org.onap.dcae.analytics.tca.model.policy.TcaPolicy; import org.onap.dcae.analytics.tca.model.policy.TcaPolicyModel; -import org.onap.dcae.analytics.tca.web.validation.TcaPolicyValidator; +import org.onap.dcae.analytics.tca.web.TcaAppProperties; import org.onap.dcae.analytics.web.exception.AnalyticsParsingException; -import org.onap.dcae.analytics.web.util.ValidationUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * @author Rajiv Singla */ -@Getter -@ToString public class TcaPolicyWrapper implements TcaPolicyModel { - private static final long serialVersionUID = 1L; - private static final Logger logger = LoggerFactory.getLogger(TcaPolicyWrapper.class); private final ZonedDateTime creationTime; private ZonedDateTime updateDateTime; - private TcaPolicy tcaPolicy; + private String tcaPolicy; private ConfigSource configSource; private AtomicInteger policyUpdateSequence; private String policyVersion; - public TcaPolicyWrapper(final String tcaPolicyString, final ConfigSource configSource) { - createOrUpdatePolicy(getTcaPolicy(tcaPolicyString), configSource); - this.creationTime = ZonedDateTime.now(); - } + private final TcaAppProperties tcaAppProperties; - public void setTcaPolicy(final String tcaPolicyString, final ConfigSource configSource) { - createOrUpdatePolicy(getTcaPolicy(tcaPolicyString), configSource); - } - - public void setTcaPolicy(final TcaPolicy tcaPolicy, final ConfigSource configSource) { - createOrUpdatePolicy(tcaPolicy, configSource); + public TcaPolicyWrapper(final TcaAppProperties tcaAppProperties) { + this.tcaAppProperties = tcaAppProperties; + this.creationTime = ZonedDateTime.now(); + this.tcaPolicy = tcaAppProperties.getTca().getPolicy(); + policyUpdateSequence = new AtomicInteger(0); + this.updateDateTime = ZonedDateTime.now(); + this.policyVersion = getPolicyVersion(new AtomicInteger(0)); } - private void createOrUpdatePolicy(final TcaPolicy tcaPolicy, final ConfigSource configSource) { - ValidationUtils.validate(tcaPolicy, new TcaPolicyValidator()); - this.tcaPolicy = tcaPolicy; - this.configSource = configSource; - this.updateDateTime = ZonedDateTime.now(); - if (policyUpdateSequence == null) { - policyUpdateSequence = new AtomicInteger(0); + public TcaPolicy getTcaPolicy() { + String tcaPolicyString = tcaAppProperties.getTca().getPolicy(); + boolean isConfigBindingServiceProfileActive = tcaAppProperties.isConfigBindingServiceProfileActive(); + if (isConfigBindingServiceProfileActive) { + this.configSource = ConfigSource.CONFIG_BINDING_SERVICE; } else { + this.configSource = ConfigSource.CLASSPATH; + } + + if (!tcaPolicyString.equals(tcaPolicy)) { + this.tcaPolicy = tcaPolicyString; + this.updateDateTime = ZonedDateTime.now(); policyUpdateSequence.getAndUpdate(sequence -> sequence + 1); + this.policyVersion = getPolicyVersion(policyUpdateSequence); + logger.info("Updated Tca Policy Wrapper with policy: {}, from Source: {}, policy Version: {}", + tcaPolicy, configSource.name(), policyVersion); } - this.policyVersion = getPolicyVersion(policyUpdateSequence); - final String configSourceName = configSource.name(); - logger.info("Updated Tca Policy Wrapper with policy: {}, from Source: {}, policy Version: {}", - tcaPolicy, configSourceName, policyVersion); + + return convertTcaPolicy(tcaPolicyString); } + public void setTcaPolicy(TcaPolicy tcaPolicy, ConfigSource configSource) { + this.tcaPolicy = tcaPolicy.toString(); + this.configSource = configSource; + } - private TcaPolicy getTcaPolicy(final String tcaPolicyString) { + public TcaPolicy convertTcaPolicy(String tcaPolicyString) { return TCA_POLICY_JSON_FUNCTION.apply(tcaPolicyString).orElseThrow( () -> new AnalyticsParsingException("Unable to parse Tca Policy String: " + tcaPolicyString, new IllegalArgumentException())); } - private static String getPolicyVersion(final AtomicInteger policyUpdateSequence) { return "version-" + policyUpdateSequence.intValue(); } + public ZonedDateTime getCreationTime() { + return creationTime; + } + + public ZonedDateTime getUpdateDateTime() { + return updateDateTime; + } + + public ConfigSource getConfigSource() { + return configSource; + } + + public AtomicInteger getPolicyUpdateSequence() { + return policyUpdateSequence; + } + + public String getPolicyVersion() { + return policyVersion; + } + } |