diff options
author | Vijay Venkatesh Kumar <vv770d@att.com> | 2020-02-11 15:18:57 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2020-02-11 15:18:57 +0000 |
commit | c57f0d90087776d1fb4422bd6c3b85db54f642e3 (patch) | |
tree | 0ab0df4a1187f0fea5d3c218273c9011fe41df28 | |
parent | 4ae4c72f031755212369c116396fcb8b2c993b64 (diff) | |
parent | a6b11ee264c2e3f4d20632b006f281025448507f (diff) |
Merge "new config not reflected in TCA processing"
13 files changed, 735 insertions, 122 deletions
diff --git a/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/AnalyticsModel.java b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/AnalyticsModel.java index bb13ed6..b4139b0 100644 --- a/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/AnalyticsModel.java +++ b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/AnalyticsModel.java @@ -19,12 +19,10 @@ package org.onap.dcae.analytics.model; -import java.io.Serializable; - /** * Marker Interface for all DCAE Analytics Model implementations * * @author Rajiv Singla */ -public interface AnalyticsModel extends Serializable { +public interface AnalyticsModel { } diff --git a/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/configbindingservice/BaseConfigBindingServiceProperties.java b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/configbindingservice/BaseConfigBindingServiceProperties.java index 7158b2e..7da418d 100644 --- a/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/configbindingservice/BaseConfigBindingServiceProperties.java +++ b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/configbindingservice/BaseConfigBindingServiceProperties.java @@ -40,8 +40,6 @@ import java.util.Map; @Data public abstract class BaseConfigBindingServiceProperties implements ConfigBindingServiceModel { - private static final long serialVersionUID = 1L; - protected Map<String, List<String>> servicesCalls = new LinkedHashMap<>(); protected Map<String, PublisherDetails> streamsPublishes = new LinkedHashMap<>(); protected Map<String, SubscriberDetails> streamsSubscribes = new LinkedHashMap<>(); @@ -51,9 +49,7 @@ public abstract class BaseConfigBindingServiceProperties implements ConfigBindin */ @Data @ToString(exclude = "aafPassword") - public static class PubSubCommonDetails implements ConfigBindingServiceModel { - - private static final long serialVersionUID = 1L; + public static class PubSubCommonDetails { private String type; private String aafUsername; @@ -76,8 +72,6 @@ public abstract class BaseConfigBindingServiceProperties implements ConfigBindin @EqualsAndHashCode(callSuper = true) public static class PublisherDetails extends PubSubCommonDetails { - private static final long serialVersionUID = 1L; - } @@ -91,8 +85,6 @@ public abstract class BaseConfigBindingServiceProperties implements ConfigBindin @EqualsAndHashCode(callSuper = true) public static class SubscriberDetails extends PubSubCommonDetails { - private static final long serialVersionUID = 1L; - // custom subscriber properties private String consumerGroup; private List<String> consumerIds; @@ -107,9 +99,7 @@ public abstract class BaseConfigBindingServiceProperties implements ConfigBindin * DMaaP Info */ @Data - public static class DmaapInfo implements ConfigBindingServiceModel { - - private static final long serialVersionUID = 1L; + public static class DmaapInfo { private String clientRole; private String clientId; @@ -123,9 +113,7 @@ public abstract class BaseConfigBindingServiceProperties implements ConfigBindin * Polling Details */ @Data - public static class Polling implements ConfigBindingServiceModel { - - private static final long serialVersionUID = 1L; + public static class Polling { private Integer fixedRate; private AutoAdjusting autoAdjusting; @@ -137,9 +125,7 @@ public abstract class BaseConfigBindingServiceProperties implements ConfigBindin * Auto Adjusting Polling Details */ @Data - public static class AutoAdjusting implements ConfigBindingServiceModel { - - private static final long serialVersionUID = 1L; + public static class AutoAdjusting { private Integer min; private Integer stepUp; diff --git a/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/configbindingservice/ConfigBindingServiceConstants.java b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/configbindingservice/ConfigBindingServiceConstants.java index 9776d70..619c417 100644 --- a/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/configbindingservice/ConfigBindingServiceConstants.java +++ b/dcae-analytics/dcae-analytics-model/src/main/java/org/onap/dcae/analytics/model/configbindingservice/ConfigBindingServiceConstants.java @@ -45,7 +45,6 @@ public abstract class ConfigBindingServiceConstants { CONSUL_HOST_ENV_VARIABLE_VALUE, CONFIG_BINDING_SERVICE_ENV_VARIABLE_VALUE); public static final String CONFIG_SERVICE_QUERY_URL_STRING = "http://%s:%s/service_component/%s"; - public static final String CONFIG_BINDING_SERVICE_PROPERTIES_KEY = "config-binding-service"; public static final Set<String> SPRING_RESERVED_PROPERTIES_KEY_PREFIXES = @@ -56,6 +55,33 @@ public abstract class ConfigBindingServiceConstants { public static final String CONFIG = "config"; public static final int CONFIG_SERVICE_REFRESHPERIOD = 1; + public static final String POLICY = "config-binding-service.tca.policy"; + public static final String PROCESSINGBATCHSIZE = "config-binding-service.tca.processing_batch_size"; + public static final String ENABLEABATEMENT = "config-binding-service.tca.enable_abatement"; + public static final String EnableEcompLogging = "config-binding-service.tca.enable_ecomp_logging"; + public static final String EnableEnrichment = "config-binding-service.tca.aai.enable_enrichment"; + public static final String AAIURL = "config-binding-service.tca.aai.url"; + public static final String AAIUSERNAME = "config-binding-service.tca.aai.username"; + public static final String AAIPASSWORD = "config-binding-service.tca.aai.password"; + public static final String AAIGENERICVNFPATH = "config-binding-service.tca.aai.generic_vnf_path"; + public static final String AAINODEQUERYPATH = "config-binding-service.tca.aai.node_query_path"; + public static final String PUBTOPICURL = "config-binding-service.streams_publishes.tca_handle_out.dmaap_info.topic_url"; + public static final String PUBTYPE = "config-binding-service.streams_publishes.tca_handle_out.type"; + public static final String PUBKEY = "tca_handle_out"; + public static final String SUBAUTOADJUSTINGSTEPUP = "config-binding-service.streams_subscribes.tca_handle_in.polling.auto_adjusting.step_up"; + public static final String SUBAUTOADJUSTINGSTEPDOWN = "config-binding-service.streams_subscribes.tca_handle_in.polling.auto_adjusting.step_down"; + public static final String SUBAUTOADJUSTINGMAX = "config-binding-service.streams_subscribes.tca_handle_in.polling.auto_adjusting.max"; + public static final String SUBAUTOADJUSTINGMIN = "config-binding-service.streams_subscribes.tca_handle_in.polling.auto_adjusting.min"; + public static final String SUBTOPICURL = "config-binding-service.streams_subscribes.tca_handle_in.dmaap_info.topic_url"; + public static final String SUBFIXEDRATE = "config-binding-service.streams_subscribes.tca_handle_in.polling.fixed_rate"; + public static final String SUBTYPE = "config-binding-service.streams_subscribes.tca_handle_in.type"; + public static final String SUBCONSUMERGROUP = "config-binding-service.streams_subscribes.tca_handle_in.consumer_group"; + public static final String SUBMESSAGELIMIT = "config-binding-service.streams_subscribes.tca_handle_in.message_limit"; + public static final String SUBTIMEOUT = "config-binding-service.streams_subscribes.tca_handle_in.timeout"; + public static final String SUBCONSUMERIDS0 = "config-binding-service.streams_subscribes.tca_handle_in.consumer_ids[0]"; + public static final String SUBCONSUMERIDS1 = "config-binding-service.streams_subscribes.tca_handle_in.consumer_ids[1]"; + public static final String SUBKEY = "tca_handle_in"; + // ============== CONFIG BINDING SERVICE UTILS ========================= // /** * Predicate which can be used to filter message router publisher or subscriber details 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; + } + } diff --git a/dcae-analytics/dcae-analytics-tca-web/src/test/java/org/onap/dcae/analytics/tca/web/service/TcaProcessingServiceImplTest.java b/dcae-analytics/dcae-analytics-tca-web/src/test/java/org/onap/dcae/analytics/tca/web/service/TcaProcessingServiceImplTest.java index 5723160..426ae46 100644 --- a/dcae-analytics/dcae-analytics-tca-web/src/test/java/org/onap/dcae/analytics/tca/web/service/TcaProcessingServiceImplTest.java +++ b/dcae-analytics/dcae-analytics-tca-web/src/test/java/org/onap/dcae/analytics/tca/web/service/TcaProcessingServiceImplTest.java @@ -19,43 +19,368 @@ package org.onap.dcae.analytics.tca.web.service; -import com.fasterxml.jackson.databind.ObjectMapper; +import static org.onap.dcae.analytics.tca.model.util.json.TcaModelJsonConversion.TCA_POLICY_JSON_FUNCTION; import java.util.Arrays; import java.util.List; import org.junit.jupiter.api.Test; +import org.onap.dcae.analytics.tca.core.service.TcaAaiEnrichmentContext; +import org.onap.dcae.analytics.tca.core.service.TcaAbatementContext; import org.onap.dcae.analytics.tca.core.service.TcaExecutionContext; import org.onap.dcae.analytics.tca.model.facade.TcaAlert; -import org.onap.dcae.analytics.tca.web.BaseTcaWebSpringBootIT; +import org.onap.dcae.analytics.tca.model.policy.TcaPolicy; +import org.onap.dcae.analytics.tca.web.TcaAppProperties; import org.onap.dcae.analytics.tca.web.domain.TcaPolicyWrapper; +import org.onap.dcae.analytics.web.exception.AnalyticsParsingException; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.env.Environment; + +import com.fasterxml.jackson.databind.ObjectMapper; /** * @author Rajiv Singla */ -class TcaProcessingServiceImplTest extends BaseTcaWebSpringBootIT { - - @Autowired - private TcaProcessingService tcaProcessingService; +class TcaProcessingServiceImplTest { - @Autowired - private TcaPolicyWrapper tcaPolicyWrapper; +// @Autowired +// Environment environment; - @Autowired - private ObjectMapper objectMapper; + public TcaPolicy convertTcaPolicy(String tcaPolicyString) { + return TCA_POLICY_JSON_FUNCTION.apply(tcaPolicyString).orElseThrow( + () -> new AnalyticsParsingException("Unable to parse Tca Policy String: " + tcaPolicyString, + new IllegalArgumentException())); + } @Test void getTcaExecutionResults() throws Exception { + TcaAbatementContext tcaAbatementContext = new TestTcaAbatementContext(); + TcaAaiEnrichmentContext tcaAaiEnrichmentContext = new TestTcaAaiEnrichmentContext(); + +// TcaAppProperties tcaAppProperties = new TcaAppProperties(environment); + String policy = "{\"domain\":\"measurementsForVfScaling\",\"metricsPerEventName\":[{\"eventName\":\"Mfvs_eNodeB_RANKPI\",\"controlLoopSchemaType\":\"VNF\",\"policyScope\":\"resource=vFirewall;type=configuration\",\"policyName\":\"configuration.dcae.microservice.tca.xml\",\"policyVersion\":\"v0.0.1\",\"thresholds\":[{\"closedLoopControlName\":\"CL-FRWL-LOW-TRAFFIC-SIG-d925ed73-8231-4d02-9545-db4e101f88f8\",\"closedLoopEventStatus\":\"ONSET\",\"version\":\"1.0.2\",\"fieldPath\":\"$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedBroadcastPacketsAccumulated\",\"thresholdValue\":4000,\"direction\":\"LESS_OR_EQUAL\",\"severity\":\"MAJOR\"},{\"closedLoopControlName\":\"CL-FRWL-HIGH-TRAFFIC-SIG-EA36FE84-9342-5E13-A656-EC5F21309A09\",\"closedLoopEventStatus\":\"ONSET\",\"version\":\"1.0.2\",\"fieldPath\":\"$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedBroadcastPacketsAccumulated\",\"thresholdValue\":20000,\"direction\":\"GREATER_OR_EQUAL\",\"severity\":\"CRITICAL\"},{\"closedLoopControlName\":\"CL-FRWL-HIGH-TRAFFIC-SIG-EA36FE84-9342-5E13-A656-EC5F21309A09\",\"closedLoopEventStatus\":\"ABATED\",\"version\":\"1.0.2\",\"fieldPath\":\"$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedBroadcastPacketsAccumulated\",\"thresholdValue\":0,\"direction\":\"EQUAL\",\"severity\":\"CRITICAL\"}]},{\"eventName\":\"vLoadBalancer\",\"controlLoopSchemaType\":\"VNF\",\"policyScope\":\"resource=vLoadBalancer;type=configuration\",\"policyName\":\"configuration.dcae.microservice.tca.xml\",\"policyVersion\":\"v0.0.1\",\"thresholds\":[{\"closedLoopControlName\":\"CL-LBAL-LOW-TRAFFIC-SIG-FB480F95-A453-6F24-B767-FD703241AB1A\",\"closedLoopEventStatus\":\"ONSET\",\"version\":\"1.0.2\",\"fieldPath\":\"$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedBroadcastPacketsAccumulated\",\"thresholdValue\":500,\"direction\":\"LESS_OR_EQUAL\",\"severity\":\"MAJOR\"},{\"closedLoopControlName\":\"CL-LBAL-LOW-TRAFFIC-SIG-0C5920A6-B564-8035-C878-0E814352BC2B\",\"closedLoopEventStatus\":\"ONSET\",\"version\":\"1.0.2\",\"fieldPath\":\"$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedBroadcastPacketsAccumulated\",\"thresholdValue\":5000,\"direction\":\"GREATER_OR_EQUAL\",\"severity\":\"CRITICAL\"}]},{\"eventName\":\"virtualVMEventName\",\"controlLoopSchemaType\":\"VM\",\"policyScope\":\"resource=virtualVM;type=configuration\",\"policyName\":\"configuration.dcae.microservice.tca.xml\",\"policyVersion\":\"v0.0.1\",\"thresholds\":[{\"closedLoopControlName\":\"CL-LBAL-LOW-TRAFFIC-SIG-FB480F95-A453-6F24-B767-FD703241AB1A\",\"closedLoopEventStatus\":\"ONSET\",\"version\":\"1.0.2\",\"fieldPath\":\"$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedBroadcastPacketsAccumulated\",\"thresholdValue\":500,\"direction\":\"LESS_OR_EQUAL\",\"severity\":\"MAJOR\"}]}]}"; +// TcaPolicyWrapper tcaPolicyWrapper = new TcaPolicyWrapper(tcaAppProperties); + TcaPolicy tcaPolicy = convertTcaPolicy(policy); + TcaProcessingService tcaProcessingService = new TcaProcessingServiceImpl(tcaAbatementContext, tcaAaiEnrichmentContext); + + String cefMessage = "{\r\n" + + " \"event\": {\r\n" + + " \"commonEventHeader\": {\r\n" + + " \"domain\": \"measurementsForVfScaling\",\r\n" + + " \"eventId\": \"UC1-SCL01081-1492639920787\",\r\n" + + " \"eventName\": \"Mfvs_eNodeB_RANKPI\",\r\n" + + " \"lastEpochMicrosec\": 1492639920787,\r\n" + + " \"nfNamingCode\": \"ENBE\",\r\n" + + " \"priority\": \"Normal\",\r\n" + + " \"reportingEntityId\": \"\",\r\n" + + " \"reportingEntityName\": \"vtc2e7admn2\",\r\n" + + " \"sequence\": 0,\r\n" + + " \"sourceId\": \"SCL01081_9B_1\",\r\n" + + " \"sourceName\": \"SCL01081\",\r\n" + + " \"startEpochMicrosec\": 1492639920787,\r\n" + + " \"version\": 3.0\r\n" + + " },\r\n" + + " \"measurementsForVfScalingFields\": {\r\n" + + " \"additionalFields\": [\r\n" + + " {\r\n" + + " \"name\": \"software_version \",\r\n" + + " \"value\": \"version1\"\r\n" + + " },\r\n" + + " {\r\n" + + " \"name\": \"vendor \",\r\n" + + " \"value\": \"Ericsson \"\r\n" + + " }\r\n" + + " ],\r\n" + + " \"additionalMeasurements\": [\r\n" + + " {\r\n" + + " \"name\": \"OaaS_UC1_EricssonSleepingCell\",\r\n" + + " \"arrayOfFields\": [\r\n" + + " {\r\n" + + " \"name\": \"PMRAATTCBRA\",\r\n" + + " \"value\": \"1353\"\r\n" + + " },\r\n" + + " {\r\n" + + " \"name\": \"PMRASUCCCBRA\",\r\n" + + " \"value\": \"1351\"\r\n" + + " },\r\n" + + " {\r\n" + + " \"name\": \"PMCELLDOWNTIMEAUTO\",\r\n" + + " \"value\": \"0\"\r\n" + + " },\r\n" + + " {\r\n" + + " \"name\": \"PMCELLDOWNTIMEMAN\",\r\n" + + " \"value\": \"0\"\r\n" + + " },\r\n" + + " {\r\n" + + " \"name\": \"PMRRCCONNESTABATT\",\r\n" + + " \"value\": \"297\"\r\n" + + " },\r\n" + + " {\r\n" + + " \"name\": \"PMRRCCONNESTABSUCC\",\r\n" + + " \"value\": \"297\"\r\n" + + " }\r\n" + + " ]\r\n" + + " }\r\n" + + " ],\r\n" + + " \"vNicPerformanceArray\": [\r\n" + + " {\r\n" + + " \"receivedBroadcastPacketsAccumulated\": 5000,\r\n" + + " \"receivedBroadcastPacketsDelta\": 5,\r\n" + + " \"receivedDiscardedPacketsAccumulated\": 12,\r\n" + + " \"receivedDiscardedPacketsDelta\": 2,\r\n" + + " \"receivedErrorPacketsAccumulated\": 2,\r\n" + + " \"receivedErrorPacketsDelta\": 1,\r\n" + + " \"valuesAreSuspect\": false,\r\n" + + " \"vNicIdentifier\": \"someVNicIdentifier\"\r\n" + + " }\r\n" + + " ],\r\n" + + " \"measurementInterval\": 900,\r\n" + + " \"measurementsForVfScalingVersion\": 2.0\r\n" + + " }\r\n" + + " }\r\n" + + "}\r\n" + + ""; - final List<TcaExecutionContext> tcaExecutionResults = - tcaProcessingService.getTcaExecutionResults - (TEST_REQUEST_ID, TEST_TRANSACTION_ID, tcaPolicyWrapper.getTcaPolicy(), - Arrays.asList(TEST_CEF_EVENT_LISTENER_STRING, - TEST_CEF_JSON_MESSAGE_WITH_VIOLATION_STRING, - TEST_CEF_JSON_MESSAGE_WITH_ABATEMENT_STRING, - TEST_CEF_JSON_MESSAGE_WITH_INAPPLICABLE_EVENT_NAME)); + String cefViolationMessage = "{\r\n" + + " \"event\": {\r\n" + + " \"commonEventHeader\": {\r\n" + + " \"domain\": \"measurementsForVfScaling\",\r\n" + + " \"eventId\": \"UC1-SCL01081-1492639920787\",\r\n" + + " \"eventName\": \"Mfvs_eNodeB_RANKPI\",\r\n" + + " \"lastEpochMicrosec\": 1492639920787,\r\n" + + " \"nfNamingCode\": \"ENBE\",\r\n" + + " \"priority\": \"Normal\",\r\n" + + " \"reportingEntityId\": \"\",\r\n" + + " \"reportingEntityName\": \"vtc2e7admn2\",\r\n" + + " \"sequence\": 0,\r\n" + + " \"sourceId\": \"SCL01081_9B_1\",\r\n" + + " \"sourceName\": \"SCL01081\",\r\n" + + " \"startEpochMicrosec\": 1492639920787,\r\n" + + " \"version\": 3.0\r\n" + + " },\r\n" + + " \"measurementsForVfScalingFields\": {\r\n" + + " \"additionalFields\": [\r\n" + + " {\r\n" + + " \"name\": \"software_version \",\r\n" + + " \"value\": \"version1\"\r\n" + + " },\r\n" + + " {\r\n" + + " \"name\": \"vendor \",\r\n" + + " \"value\": \"Ericsson \"\r\n" + + " }\r\n" + + " ],\r\n" + + " \"additionalMeasurements\": [\r\n" + + " {\r\n" + + " \"name\": \"OaaS_UC1_EricssonSleepingCell\",\r\n" + + " \"arrayOfFields\": [\r\n" + + " {\r\n" + + " \"name\": \"PMRAATTCBRA\",\r\n" + + " \"value\": \"1353\"\r\n" + + " },\r\n" + + " {\r\n" + + " \"name\": \"PMRASUCCCBRA\",\r\n" + + " \"value\": \"1351\"\r\n" + + " },\r\n" + + " {\r\n" + + " \"name\": \"PMCELLDOWNTIMEAUTO\",\r\n" + + " \"value\": \"0\"\r\n" + + " },\r\n" + + " {\r\n" + + " \"name\": \"PMCELLDOWNTIMEMAN\",\r\n" + + " \"value\": \"0\"\r\n" + + " },\r\n" + + " {\r\n" + + " \"name\": \"PMRRCCONNESTABATT\",\r\n" + + " \"value\": \"297\"\r\n" + + " },\r\n" + + " {\r\n" + + " \"name\": \"PMRRCCONNESTABSUCC\",\r\n" + + " \"value\": \"297\"\r\n" + + " }\r\n" + + " ]\r\n" + + " }\r\n" + + " ],\r\n" + + " \"vNicPerformanceArray\": [\r\n" + + " {\r\n" + + " \"receivedBroadcastPacketsAccumulated\": 21000,\r\n" + + " \"receivedBroadcastPacketsDelta\": 5,\r\n" + + " \"receivedDiscardedPacketsAccumulated\": 12,\r\n" + + " \"receivedDiscardedPacketsDelta\": 2,\r\n" + + " \"receivedErrorPacketsAccumulated\": 2,\r\n" + + " \"receivedErrorPacketsDelta\": 1,\r\n" + + " \"valuesAreSuspect\": false,\r\n" + + " \"vNicIdentifier\": \"someVNicIdentifier\"\r\n" + + " }\r\n" + + " ],\r\n" + + " \"measurementInterval\": 900,\r\n" + + " \"measurementsForVfScalingVersion\": 2.0\r\n" + + " }\r\n" + + " }\r\n" + + "}\r\n" + + ""; + String cefAbatementMessage = "{\r\n" + + " \"event\": {\r\n" + + " \"commonEventHeader\": {\r\n" + + " \"domain\": \"measurementsForVfScaling\",\r\n" + + " \"eventId\": \"UC1-SCL01081-1492639920787\",\r\n" + + " \"eventName\": \"Mfvs_eNodeB_RANKPI\",\r\n" + + " \"lastEpochMicrosec\": 1492639920787,\r\n" + + " \"nfNamingCode\": \"ENBE\",\r\n" + + " \"priority\": \"Normal\",\r\n" + + " \"reportingEntityId\": \"\",\r\n" + + " \"reportingEntityName\": \"vtc2e7admn2\",\r\n" + + " \"sequence\": 0,\r\n" + + " \"sourceId\": \"SCL01081_9B_1\",\r\n" + + " \"sourceName\": \"SCL01081\",\r\n" + + " \"startEpochMicrosec\": 1492639920787,\r\n" + + " \"version\": 3.0\r\n" + + " },\r\n" + + " \"measurementsForVfScalingFields\": {\r\n" + + " \"additionalFields\": [\r\n" + + " {\r\n" + + " \"name\": \"software_version \",\r\n" + + " \"value\": \"version1\"\r\n" + + " },\r\n" + + " {\r\n" + + " \"name\": \"vendor \",\r\n" + + " \"value\": \"Ericsson \"\r\n" + + " }\r\n" + + " ],\r\n" + + " \"additionalMeasurements\": [\r\n" + + " {\r\n" + + " \"name\": \"OaaS_UC1_EricssonSleepingCell\",\r\n" + + " \"arrayOfFields\": [\r\n" + + " {\r\n" + + " \"name\": \"PMRAATTCBRA\",\r\n" + + " \"value\": \"1353\"\r\n" + + " },\r\n" + + " {\r\n" + + " \"name\": \"PMRASUCCCBRA\",\r\n" + + " \"value\": \"1351\"\r\n" + + " },\r\n" + + " {\r\n" + + " \"name\": \"PMCELLDOWNTIMEAUTO\",\r\n" + + " \"value\": \"0\"\r\n" + + " },\r\n" + + " {\r\n" + + " \"name\": \"PMCELLDOWNTIMEMAN\",\r\n" + + " \"value\": \"0\"\r\n" + + " },\r\n" + + " {\r\n" + + " \"name\": \"PMRRCCONNESTABATT\",\r\n" + + " \"value\": \"297\"\r\n" + + " },\r\n" + + " {\r\n" + + " \"name\": \"PMRRCCONNESTABSUCC\",\r\n" + + " \"value\": \"297\"\r\n" + + " }\r\n" + + " ]\r\n" + + " }\r\n" + + " ],\r\n" + + " \"vNicPerformanceArray\": [\r\n" + + " {\r\n" + + " \"receivedBroadcastPacketsAccumulated\": 0,\r\n" + + " \"receivedBroadcastPacketsDelta\": 5,\r\n" + + " \"receivedDiscardedPacketsAccumulated\": 12,\r\n" + + " \"receivedDiscardedPacketsDelta\": 2,\r\n" + + " \"receivedErrorPacketsAccumulated\": 2,\r\n" + + " \"receivedErrorPacketsDelta\": 1,\r\n" + + " \"valuesAreSuspect\": false,\r\n" + + " \"vNicIdentifier\": \"someVNicIdentifier\"\r\n" + + " }\r\n" + + " ],\r\n" + + " \"measurementInterval\": 900,\r\n" + + " \"measurementsForVfScalingVersion\": 2.0\r\n" + + " }\r\n" + + " }\r\n" + + "}\r\n" + + ""; + + String cefInapplicableMessage = "{\r\n" + + " \"event\": {\r\n" + + " \"commonEventHeader\": {\r\n" + + " \"domain\": \"measurementsForVfScaling\",\r\n" + + " \"eventId\": \"UC1-SCL01081-1492639920787\",\r\n" + + " \"eventName\": \"testEventName\",\r\n" + + " \"lastEpochMicrosec\": 1492639920787,\r\n" + + " \"nfNamingCode\": \"ENBE\",\r\n" + + " \"priority\": \"Normal\",\r\n" + + " \"reportingEntityId\": \"\",\r\n" + + " \"reportingEntityName\": \"vtc2e7admn2\",\r\n" + + " \"sequence\": 0,\r\n" + + " \"sourceId\": \"SCL01081_9B_1\",\r\n" + + " \"sourceName\": \"SCL01081\",\r\n" + + " \"startEpochMicrosec\": 1492639920787,\r\n" + + " \"version\": 3.0\r\n" + + " },\r\n" + + " \"measurementsForVfScalingFields\": {\r\n" + + " \"additionalFields\": [\r\n" + + " {\r\n" + + " \"name\": \"software_version \",\r\n" + + " \"value\": \"version1\"\r\n" + + " },\r\n" + + " {\r\n" + + " \"name\": \"vendor \",\r\n" + + " \"value\": \"Ericsson \"\r\n" + + " }\r\n" + + " ],\r\n" + + " \"additionalMeasurements\": [\r\n" + + " {\r\n" + + " \"name\": \"OaaS_UC1_EricssonSleepingCell\",\r\n" + + " \"arrayOfFields\": [\r\n" + + " {\r\n" + + " \"name\": \"PMRAATTCBRA\",\r\n" + + " \"value\": \"1353\"\r\n" + + " },\r\n" + + " {\r\n" + + " \"name\": \"PMRASUCCCBRA\",\r\n" + + " \"value\": \"1351\"\r\n" + + " },\r\n" + + " {\r\n" + + " \"name\": \"PMCELLDOWNTIMEAUTO\",\r\n" + + " \"value\": \"0\"\r\n" + + " },\r\n" + + " {\r\n" + + " \"name\": \"PMCELLDOWNTIMEMAN\",\r\n" + + " \"value\": \"0\"\r\n" + + " },\r\n" + + " {\r\n" + + " \"name\": \"PMRRCCONNESTABATT\",\r\n" + + " \"value\": \"297\"\r\n" + + " },\r\n" + + " {\r\n" + + " \"name\": \"PMRRCCONNESTABSUCC\",\r\n" + + " \"value\": \"297\"\r\n" + + " }\r\n" + + " ]\r\n" + + " }\r\n" + + " ],\r\n" + + " \"vNicPerformanceArray\": [\r\n" + + " {\r\n" + + " \"receivedBroadcastPacketsAccumulated\": 5000,\r\n" + + " \"receivedBroadcastPacketsDelta\": 5,\r\n" + + " \"receivedDiscardedPacketsAccumulated\": 12,\r\n" + + " \"receivedDiscardedPacketsDelta\": 2,\r\n" + + " \"receivedErrorPacketsAccumulated\": 2,\r\n" + + " \"receivedErrorPacketsDelta\": 1,\r\n" + + " \"valuesAreSuspect\": false,\r\n" + + " \"vNicIdentifier\": \"someVNicIdentifier\"\r\n" + + " }\r\n" + + " ],\r\n" + + " \"measurementInterval\": 900,\r\n" + + " \"measurementsForVfScalingVersion\": 2.0\r\n" + + " }\r\n" + + " }\r\n" + + "}\r\n" + + ""; + + ObjectMapper objectMapper = new ObjectMapper(); + final List<TcaExecutionContext> tcaExecutionResults = tcaProcessingService.getTcaExecutionResults( + "testRequestId", "testTransactionId", tcaPolicy, + Arrays.asList(cefMessage, cefViolationMessage, + cefAbatementMessage, + cefInapplicableMessage)); for (TcaExecutionContext tcaExecutionResult : tcaExecutionResults) { final TcaAlert tcaAlert = tcaExecutionResult.getTcaResultContext().getTcaAlert(); @@ -63,10 +388,8 @@ class TcaProcessingServiceImplTest extends BaseTcaWebSpringBootIT { if (tcaAlert != null) { tcaAlertString = objectMapper.writeValueAsString(tcaAlert); } - logger.debug("{} -> {}", tcaExecutionResult.getRequestId(), tcaAlertString); - } - } - } + + diff --git a/dcae-analytics/dcae-analytics-tca-web/src/test/java/org/onap/dcae/analytics/tca/web/service/TestTcaAaiEnrichmentContext.java b/dcae-analytics/dcae-analytics-tca-web/src/test/java/org/onap/dcae/analytics/tca/web/service/TestTcaAaiEnrichmentContext.java new file mode 100644 index 0000000..d8779a6 --- /dev/null +++ b/dcae-analytics/dcae-analytics-tca-web/src/test/java/org/onap/dcae/analytics/tca/web/service/TestTcaAaiEnrichmentContext.java @@ -0,0 +1,36 @@ +/* + * ================================================================================ + * Copyright (c) 2018 AT&T Intellectual Property. 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + */ + +package org.onap.dcae.analytics.tca.web.service; + +import lombok.Data; + +import org.onap.dcae.analytics.tca.core.service.TcaAaiEnrichmentContext; +import org.onap.dcae.analytics.tca.core.service.TcaAaiEnrichmentService; + +/** + * @author Rajiv Singla + */ +@Data +public class TestTcaAaiEnrichmentContext implements TcaAaiEnrichmentContext { + + private boolean isAaiEnrichmentEnabled = true; + private TcaAaiEnrichmentService aaiEnrichmentService = new TestTcaAaiEnrichmentService(); + +} diff --git a/dcae-analytics/dcae-analytics-tca-web/src/test/java/org/onap/dcae/analytics/tca/web/service/TestTcaAaiEnrichmentService.java b/dcae-analytics/dcae-analytics-tca-web/src/test/java/org/onap/dcae/analytics/tca/web/service/TestTcaAaiEnrichmentService.java new file mode 100644 index 0000000..0f8c7ed --- /dev/null +++ b/dcae-analytics/dcae-analytics-tca-web/src/test/java/org/onap/dcae/analytics/tca/web/service/TestTcaAaiEnrichmentService.java @@ -0,0 +1,41 @@ +/* + * ================================================================================ + * Copyright (c) 2018 AT&T Intellectual Property. 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + */ + +package org.onap.dcae.analytics.tca.web.service; + +import lombok.Data; + +import org.onap.dcae.analytics.tca.core.service.TcaAaiEnrichmentService; +import org.onap.dcae.analytics.tca.core.service.TcaExecutionContext; +import org.onap.dcae.analytics.tca.model.facade.TcaAlert; + +/** + * @author Rajiv Singla + */ +@Data +public class TestTcaAaiEnrichmentService implements TcaAaiEnrichmentService { + + private TcaAlert enrichedTcaAlert; + + @Override + public TcaAlert doAaiEnrichment(final TcaExecutionContext tcaExecutionContext) { + final TcaAlert tcaAlert = tcaExecutionContext.getTcaResultContext().getTcaAlert(); + return enrichedTcaAlert == null ? tcaAlert : enrichedTcaAlert; + } +} diff --git a/dcae-analytics/dcae-analytics-tca-web/src/test/java/org/onap/dcae/analytics/tca/web/service/TestTcaAbatementContext.java b/dcae-analytics/dcae-analytics-tca-web/src/test/java/org/onap/dcae/analytics/tca/web/service/TestTcaAbatementContext.java new file mode 100644 index 0000000..42f8c1c --- /dev/null +++ b/dcae-analytics/dcae-analytics-tca-web/src/test/java/org/onap/dcae/analytics/tca/web/service/TestTcaAbatementContext.java @@ -0,0 +1,46 @@ +/* + * ================================================================================ + * Copyright (c) 2018 AT&T Intellectual Property. 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + */ + +package org.onap.dcae.analytics.tca.web.service; + +import lombok.Data; + +import java.util.Date; + +import org.onap.dcae.analytics.tca.core.service.TcaAbatementContext; +import org.onap.dcae.analytics.tca.core.service.TcaAbatementEntity; +import org.onap.dcae.analytics.tca.core.service.TcaAbatementRepository; + +/** + * @author Rajiv Singla + */ +@Data +public class TestTcaAbatementContext implements TcaAbatementContext { + + private boolean isAbatementEnabled = true; + private TcaAbatementRepository tcaAbatementRepository = new TestTcaAbatementRepository(); + + + @Override + public TcaAbatementEntity create( + final String lookupKey, final String requestId, final boolean isAbatementAlertSent) { + return new TestTcaAbatementEntity(new Date(), lookupKey, requestId, isAbatementAlertSent); + } + +} diff --git a/dcae-analytics/dcae-analytics-tca-web/src/test/java/org/onap/dcae/analytics/tca/web/service/TestTcaAbatementEntity.java b/dcae-analytics/dcae-analytics-tca-web/src/test/java/org/onap/dcae/analytics/tca/web/service/TestTcaAbatementEntity.java new file mode 100644 index 0000000..e1e8418 --- /dev/null +++ b/dcae-analytics/dcae-analytics-tca-web/src/test/java/org/onap/dcae/analytics/tca/web/service/TestTcaAbatementEntity.java @@ -0,0 +1,41 @@ +/* + * ================================================================================ + * Copyright (c) 2018 AT&T Intellectual Property. 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + */ + +package org.onap.dcae.analytics.tca.web.service; + +import lombok.AllArgsConstructor; +import lombok.Data; + +import java.util.Date; + +import org.onap.dcae.analytics.tca.core.service.TcaAbatementEntity; + +/** + * @author Rajiv Singla + */ +@Data +@AllArgsConstructor +public class TestTcaAbatementEntity implements TcaAbatementEntity { + + private Date lastModificationDate; + private String lookupKey; + private String requestId; + private boolean isAbatementAlertSent; + +} diff --git a/dcae-analytics/dcae-analytics-tca-web/src/test/java/org/onap/dcae/analytics/tca/web/service/TestTcaAbatementRepository.java b/dcae-analytics/dcae-analytics-tca-web/src/test/java/org/onap/dcae/analytics/tca/web/service/TestTcaAbatementRepository.java new file mode 100644 index 0000000..bc32ad8 --- /dev/null +++ b/dcae-analytics/dcae-analytics-tca-web/src/test/java/org/onap/dcae/analytics/tca/web/service/TestTcaAbatementRepository.java @@ -0,0 +1,48 @@ +/* + * ================================================================================ + * Copyright (c) 2018 AT&T Intellectual Property. 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + */ + +package org.onap.dcae.analytics.tca.web.service; + +import lombok.Data; + +import java.util.LinkedList; +import java.util.List; + +import org.onap.dcae.analytics.tca.core.service.TcaAbatementEntity; +import org.onap.dcae.analytics.tca.core.service.TcaAbatementRepository; + +/** + * @author Rajiv Singla + */ +@Data +public class TestTcaAbatementRepository implements TcaAbatementRepository { + + private List<TcaAbatementEntity> testLookupAbatementEntities = new LinkedList<>(); + + @Override + public void save(final TcaAbatementEntity tcaAbatementEntity) { + // do nothing + } + + @Override + public List<TcaAbatementEntity> findByLookupKey(final String lookUpKey) { + return testLookupAbatementEntities; + } + +} |