From c56c4a5e36d97cb22c97d9acc29d057760b0ec0f Mon Sep 17 00:00:00 2001 From: malar Date: Thu, 28 Jul 2022 09:52:22 +0000 Subject: Support 7.2.1 VES in TCAGEN2 - Includes modifications for processing Tca Policy as a List to support both v5 and v7 policies Issue-ID: DCAEGEN2-2976 Signed-off-by: Malarvizhi Paramasivam Change-Id: I29f56048d825710d268e4588f4b5779d5fdb6020 --- dcae-analytics/dcae-analytics-tca-core/pom.xml | 3 +- .../core/service/GenericTcaExecutionContext.java | 6 ++- .../tca/core/service/TcaExecutionContext.java | 6 ++- .../dcae/analytics/tca/core/util/TcaUtils.java | 19 ++++++--- .../util/function/calculation/TcaDomainFilter.java | 33 +++++++++------ .../function/calculation/TcaEventNameFilter.java | 28 ++++++++----- .../TcaThresholdViolationCalculator.java | 49 +++++++++++++++------- .../dcae/analytics/tca/core/BaseTcaCoreTest.java | 9 ++-- 8 files changed, 101 insertions(+), 52 deletions(-) (limited to 'dcae-analytics/dcae-analytics-tca-core') diff --git a/dcae-analytics/dcae-analytics-tca-core/pom.xml b/dcae-analytics/dcae-analytics-tca-core/pom.xml index d21a86c..4921f84 100644 --- a/dcae-analytics/dcae-analytics-tca-core/pom.xml +++ b/dcae-analytics/dcae-analytics-tca-core/pom.xml @@ -42,7 +42,8 @@ Contins Core functionality for TCA - ${project.parent.basedir} + ${project.parent.basedir} + -changelog-missing diff --git a/dcae-analytics/dcae-analytics-tca-core/src/main/java/org/onap/dcae/analytics/tca/core/service/GenericTcaExecutionContext.java b/dcae-analytics/dcae-analytics-tca-core/src/main/java/org/onap/dcae/analytics/tca/core/service/GenericTcaExecutionContext.java index 6a208d2..715ed53 100644 --- a/dcae-analytics/dcae-analytics-tca-core/src/main/java/org/onap/dcae/analytics/tca/core/service/GenericTcaExecutionContext.java +++ b/dcae-analytics/dcae-analytics-tca-core/src/main/java/org/onap/dcae/analytics/tca/core/service/GenericTcaExecutionContext.java @@ -1,6 +1,7 @@ /* - * ================================================================================ + * ============LICENSE_START======================================================= * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved. + * Copyright (c) 2022 Wipro Limited 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. @@ -23,6 +24,7 @@ import lombok.Builder; import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.ToString; +import java.util.List; import org.onap.dcae.analytics.tca.model.policy.TcaPolicy; @@ -39,7 +41,7 @@ public class GenericTcaExecutionContext implements TcaExecutionContext { private final String transactionId; private final int messageIndex; private final String cefMessage; - private final TcaPolicy tcaPolicy; + private final List tcaPolicy; private final TcaProcessingContext tcaProcessingContext; private final TcaResultContext tcaResultContext; private final TcaAbatementContext tcaAbatementContext; diff --git a/dcae-analytics/dcae-analytics-tca-core/src/main/java/org/onap/dcae/analytics/tca/core/service/TcaExecutionContext.java b/dcae-analytics/dcae-analytics-tca-core/src/main/java/org/onap/dcae/analytics/tca/core/service/TcaExecutionContext.java index 9a55151..7a0ac51 100644 --- a/dcae-analytics/dcae-analytics-tca-core/src/main/java/org/onap/dcae/analytics/tca/core/service/TcaExecutionContext.java +++ b/dcae-analytics/dcae-analytics-tca-core/src/main/java/org/onap/dcae/analytics/tca/core/service/TcaExecutionContext.java @@ -1,6 +1,7 @@ /* - * ================================================================================ + * ============LICENSE_START======================================================= * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved. + * Copyright (c) 2022 Wipro Limited 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. @@ -19,6 +20,7 @@ package org.onap.dcae.analytics.tca.core.service; +import java.util.List; import org.onap.dcae.analytics.tca.model.policy.TcaPolicy; /** @@ -65,7 +67,7 @@ public interface TcaExecutionContext { * * @return TCA Policy associated with processing context */ - TcaPolicy getTcaPolicy(); + List getTcaPolicy(); /** diff --git a/dcae-analytics/dcae-analytics-tca-core/src/main/java/org/onap/dcae/analytics/tca/core/util/TcaUtils.java b/dcae-analytics/dcae-analytics-tca-core/src/main/java/org/onap/dcae/analytics/tca/core/util/TcaUtils.java index bbadcac..5f581f6 100644 --- a/dcae-analytics/dcae-analytics-tca-core/src/main/java/org/onap/dcae/analytics/tca/core/util/TcaUtils.java +++ b/dcae-analytics/dcae-analytics-tca-core/src/main/java/org/onap/dcae/analytics/tca/core/util/TcaUtils.java @@ -1,6 +1,7 @@ /* - * ================================================================================ + * ==========LICENSE_START========================================================= * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved. + * Copyright (c) 2022 Wipro Limited 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. @@ -23,6 +24,7 @@ import static org.onap.dcae.analytics.tca.model.util.json.TcaModelJsonConversion import com.fasterxml.jackson.core.JsonProcessingException; +import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Optional; @@ -52,14 +54,19 @@ public abstract class TcaUtils { * * @return deep copy of provided tca policy */ - public static TcaPolicy getTcaPolicyDeepCopy(final TcaPolicy tcaPolicy) { + public static List getTcaPolicyDeepCopy(final List tcaPolicy) { if (tcaPolicy != null) { - try { - return TCA_OBJECT_MAPPER.treeToValue(TCA_OBJECT_MAPPER.valueToTree(tcaPolicy), TcaPolicy.class); + List tcaList = new ArrayList(); + for( TcaPolicy tcaPol : tcaPolicy) { + try { + tcaList.add(TCA_OBJECT_MAPPER.treeToValue(TCA_OBJECT_MAPPER.valueToTree(tcaPol), TcaPolicy.class)); } catch (JsonProcessingException e) { - throw new AnalyticsParsingException("Unable to create deep copy of TCA Policy: " + tcaPolicy, e); + throw new AnalyticsParsingException("Unable to create deep copy of TCA Policy: " + tcaPol, e); } - } else { + } + return tcaList; + } + else { final String errorMessage = "Invalid application state. TCA Policy must not be null"; throw new AnalyticsParsingException(errorMessage, new IllegalStateException(errorMessage)); } diff --git a/dcae-analytics/dcae-analytics-tca-core/src/main/java/org/onap/dcae/analytics/tca/core/util/function/calculation/TcaDomainFilter.java b/dcae-analytics/dcae-analytics-tca-core/src/main/java/org/onap/dcae/analytics/tca/core/util/function/calculation/TcaDomainFilter.java index a54b615..2e3a1f5 100644 --- a/dcae-analytics/dcae-analytics-tca-core/src/main/java/org/onap/dcae/analytics/tca/core/util/function/calculation/TcaDomainFilter.java +++ b/dcae-analytics/dcae-analytics-tca-core/src/main/java/org/onap/dcae/analytics/tca/core/util/function/calculation/TcaDomainFilter.java @@ -1,6 +1,7 @@ /* - * ================================================================================ + * ===========LICENSE_START======================================================== * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved. + * Copyright (c) 2022 Wipro Limited 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. @@ -19,12 +20,14 @@ package org.onap.dcae.analytics.tca.core.util.function.calculation; +import java.util.List; import java.util.Optional; import org.onap.dcae.analytics.model.cef.CommonEventHeader; import org.onap.dcae.analytics.model.cef.Domain; import org.onap.dcae.analytics.model.cef.Event; import org.onap.dcae.analytics.model.cef.EventListener; +import org.onap.dcae.analytics.tca.model.policy.TcaPolicy; import org.onap.dcae.analytics.tca.core.service.TcaExecutionContext; import org.onap.dcae.analytics.tca.core.service.TcaProcessingContext; @@ -54,19 +57,25 @@ public class TcaDomainFilter implements TcaCalculationFunction { } // Get Policy and CEF Message Domain - final String policyDomain = tcaExecutionContext.getTcaPolicy().getDomain(); + final List tcaPolList = tcaExecutionContext.getTcaPolicy(); final String cefMessageDomain = domainOptional.get().name(); - - // Check Policy domain matches CEF message domain - if (!policyDomain.equalsIgnoreCase(cefMessageDomain)) { - final String earlyTerminationMessage = String.format( - "Policy Domain does not match CEF Message Domain. Policy Domain: %s, CEF Message Domain: %s", - policyDomain, cefMessageDomain); - setTerminatingMessage(earlyTerminationMessage, tcaExecutionContext, false); - return tcaExecutionContext; + + for( TcaPolicy tcaPol : tcaPolList){ + String policyDomain = tcaPol.getDomain(); + int size = tcaPolList.size(); + int count = 0; + // Check Policy domain matches CEF message domain + if (!policyDomain.equalsIgnoreCase(cefMessageDomain)) { + count++; + if (count >= size){ + final String earlyTerminationMessage = String.format( + "Policy Domain does not match CEF Message Domain. Policy Domain: %s, CEF Message Domain: %s", + policyDomain, cefMessageDomain); + setTerminatingMessage(earlyTerminationMessage, tcaExecutionContext, false); + return tcaExecutionContext; + } + } } - - // Policy Domain and CEF Message Domain match successful // do nothing diff --git a/dcae-analytics/dcae-analytics-tca-core/src/main/java/org/onap/dcae/analytics/tca/core/util/function/calculation/TcaEventNameFilter.java b/dcae-analytics/dcae-analytics-tca-core/src/main/java/org/onap/dcae/analytics/tca/core/util/function/calculation/TcaEventNameFilter.java index 574e9ba..e5f501e 100644 --- a/dcae-analytics/dcae-analytics-tca-core/src/main/java/org/onap/dcae/analytics/tca/core/util/function/calculation/TcaEventNameFilter.java +++ b/dcae-analytics/dcae-analytics-tca-core/src/main/java/org/onap/dcae/analytics/tca/core/util/function/calculation/TcaEventNameFilter.java @@ -1,6 +1,7 @@ /* - * ================================================================================ + * ==========LICENSE_START========================================================= * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved. + * Copyright (c) 2022 Wipro Limited 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. @@ -21,6 +22,7 @@ package org.onap.dcae.analytics.tca.core.util.function.calculation; import java.util.Optional; import java.util.Set; +import java.util.List; import java.util.stream.Collectors; import org.onap.dcae.analytics.model.cef.CommonEventHeader; @@ -56,17 +58,23 @@ public class TcaEventNameFilter implements TcaCalculationFunction { // Get CEF Message Event name and Event names in tca policy final String cefMessageEventName = eventNameOptional.get(); - final TcaPolicy tcaPolicy = tcaExecutionContext.getTcaPolicy(); - final Set policyEventNames = tcaPolicy.getMetricsPerEventName().stream() + final List tcaPolList = tcaExecutionContext.getTcaPolicy(); + int count = 0; + int size = tcaPolList.size(); + for( TcaPolicy tcaPol : tcaPolList){ + final Set policyEventNames = tcaPol.getMetricsPerEventName().stream() .map(MetricsPerEventName::getEventName).collect(Collectors.toSet()); - - // Check CEF Message Event name matches any Policy Event names - if (!policyEventNames.contains(cefMessageEventName)) { - final String earlyTerminationMessage = String.format( - "CEF Message Event name does not match any Policy Event Names. " + + // Check CEF Message Event name matches any Policy Event names + if (!policyEventNames.contains(cefMessageEventName)) { + count++; + if(count >= size) { + final String earlyTerminationMessage = String.format( + "CEF Message Event name does not match any Policy Event Names. " + "Message EventName: %s, Policy Event Names: %s", cefMessageEventName, policyEventNames); - setTerminatingMessage(earlyTerminationMessage, tcaExecutionContext, false); - return tcaExecutionContext; + setTerminatingMessage(earlyTerminationMessage, tcaExecutionContext, false); + return tcaExecutionContext; + } + } } // CEF Messages one of the the Policy Event names diff --git a/dcae-analytics/dcae-analytics-tca-core/src/main/java/org/onap/dcae/analytics/tca/core/util/function/calculation/TcaThresholdViolationCalculator.java b/dcae-analytics/dcae-analytics-tca-core/src/main/java/org/onap/dcae/analytics/tca/core/util/function/calculation/TcaThresholdViolationCalculator.java index 053fcab..afa35ee 100644 --- a/dcae-analytics/dcae-analytics-tca-core/src/main/java/org/onap/dcae/analytics/tca/core/util/function/calculation/TcaThresholdViolationCalculator.java +++ b/dcae-analytics/dcae-analytics-tca-core/src/main/java/org/onap/dcae/analytics/tca/core/util/function/calculation/TcaThresholdViolationCalculator.java @@ -1,6 +1,7 @@ /* - * ================================================================================ + * ============LICENSE_START======================================================= * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved. + * Copyright (c) 2022 Wipro Limited 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. @@ -39,6 +40,7 @@ import java.util.stream.Collectors; import javax.annotation.Nonnull; import org.onap.dcae.analytics.model.cef.CommonEventHeader; +import org.onap.dcae.analytics.model.cef.Domain; import org.onap.dcae.analytics.model.cef.Event; import org.onap.dcae.analytics.model.cef.EventListener; import org.onap.dcae.analytics.tca.core.exception.TcaProcessingException; @@ -52,13 +54,14 @@ import org.onap.dcae.analytics.tca.model.policy.Threshold; * @author Rajiv Singla */ public class TcaThresholdViolationCalculator implements TcaCalculationFunction { - + @Override public TcaExecutionContext calculate(final TcaExecutionContext tcaExecutionContext) { final String cefMessage = tcaExecutionContext.getCefMessage(); final EventListener eventListener = tcaExecutionContext.getTcaProcessingContext().getEventListener(); - final TcaPolicy tcaPolicy = tcaExecutionContext.getTcaPolicy(); + final List tcaPolicy = tcaExecutionContext.getTcaPolicy(); + TcaPolicy tcaPolicyFinal = null; // Get CEF Event Name final String cefEventName = Optional.ofNullable(eventListener) @@ -66,18 +69,33 @@ public class TcaThresholdViolationCalculator implements TcaCalculationFunction { .map(Event::getCommonEventHeader) .map(CommonEventHeader::getEventName) .orElseThrow(() -> new TcaProcessingException("Required Field: EventName not present")); + + final Optional domainName = Optional.ofNullable(eventListener) + .map(EventListener::getEvent) + .map(Event::getCommonEventHeader) + .map(CommonEventHeader::getDomain); - // Get Policy's metrics per event name matching CEF message event name - final MetricsPerEventName policyMetricsPerEventName = - tcaPolicy.getMetricsPerEventName().stream() - .filter(m -> m.getEventName().equalsIgnoreCase(cefEventName)) - .findFirst().orElseThrow(() -> - new TcaProcessingException("Required Field: MetricsPerEventName not present")); - + final String cefMessageDomain = domainName.get().name(); + for(TcaPolicy tca : tcaPolicy){ + if (tca.getDomain().equalsIgnoreCase(cefMessageDomain)){ + tcaPolicyFinal = tca; + break; + } + else + continue; + } + + // Get Policy's metrics per event name matching CEF message event name + final MetricsPerEventName policyMetricsPerEventName = + tcaPolicyFinal.getMetricsPerEventName().stream() + .filter(m -> m.getEventName().equalsIgnoreCase(cefEventName)) + .findFirst().orElseThrow(() -> + new TcaProcessingException("Required Field: MetricsPerEventName not present")); + // get violated policy threshold for cef event name sorted by severity final Optional thresholdOptional = - getViolatedThreshold(policyMetricsPerEventName.getThresholds(), cefMessage); + getViolatedThreshold(policyMetricsPerEventName.getThresholds(), cefMessage); // Check if threshold violation is present @@ -85,17 +103,17 @@ public class TcaThresholdViolationCalculator implements TcaCalculationFunction { final String earlyTerminationMessage = "No Policy Threshold violation detected in CEF Message"; setTerminatingMessage(earlyTerminationMessage, tcaExecutionContext, false); return tcaExecutionContext; - } - + } + // Threshold violations are present - update tca processing result context final MetricsPerEventName violatedMetricsPerEventName = copyMetricsPerEventName(policyMetricsPerEventName); final Threshold violatedThreshold = thresholdOptional.get(); violatedMetricsPerEventName.setThresholds(Collections.singletonList(violatedThreshold)); final TcaResultContext tcaResultContext = - tcaExecutionContext.getTcaResultContext(); + tcaExecutionContext.getTcaResultContext(); tcaResultContext.setViolatedMetricsPerEventName(violatedMetricsPerEventName); - + return tcaExecutionContext; } @@ -226,7 +244,6 @@ public class TcaThresholdViolationCalculator implements TcaCalculationFunction { } } } - return jsonFieldPathMap; } diff --git a/dcae-analytics/dcae-analytics-tca-core/src/test/java/org/onap/dcae/analytics/tca/core/BaseTcaCoreTest.java b/dcae-analytics/dcae-analytics-tca-core/src/test/java/org/onap/dcae/analytics/tca/core/BaseTcaCoreTest.java index 0d32190..23ff4e3 100644 --- a/dcae-analytics/dcae-analytics-tca-core/src/test/java/org/onap/dcae/analytics/tca/core/BaseTcaCoreTest.java +++ b/dcae-analytics/dcae-analytics-tca-core/src/test/java/org/onap/dcae/analytics/tca/core/BaseTcaCoreTest.java @@ -1,6 +1,7 @@ /* - * ================================================================================ + * ==========LICENSE_START========================================================= * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved. + * Copyright (c) 2022 Wipro Limited 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. @@ -19,6 +20,8 @@ package org.onap.dcae.analytics.tca.core; +import java.util.List; + import org.onap.dcae.analytics.model.cef.EventListener; import org.onap.dcae.analytics.model.util.json.AnalyticsModelJsonConversion; import org.onap.dcae.analytics.tca.core.domain.TestTcaAaiEnrichmentContext; @@ -47,7 +50,7 @@ public abstract class BaseTcaCoreTest extends BaseAnalyticsUnitTest { protected static final String TEST_CEF_JSON_MESSAGE_WITH_ABATEMENT_STRING; protected static final String TEST_CEF_JSON_MESSAGE_WITH_INAPPLICABLE_EVENT_NAME; protected static final String TEST_REQUEST_ID = "testRequestId"; - protected static final TcaPolicy TEST_TCA_POLICY; + protected static final List TEST_TCA_POLICY; static { @@ -102,7 +105,7 @@ public abstract class BaseTcaCoreTest extends BaseAnalyticsUnitTest { } protected GenericTcaExecutionContextBuilder getTestExecutionContextBuilder( - final String cefMessage, final TcaPolicy tcaPolicy, final TcaAbatementContext tcaAbatementContext) { + final String cefMessage, final List tcaPolicy, final TcaAbatementContext tcaAbatementContext) { final TcaProcessingContext tcaProcessingContext = new GenericTcaProcessingContext(); final TcaResultContext tcaResultContext = new GenericTcaResultContext(); -- cgit 1.2.3-korg