summaryrefslogtreecommitdiffstats
path: root/dcae-analytics/dcae-analytics-tca-web
diff options
context:
space:
mode:
authorKai <lukai@chinamobile.com>2020-05-18 09:59:28 +0800
committerKai <lukai@chinamobile.com>2020-05-18 10:03:49 +0800
commitddb9b0f7e578aefd06ee9e3f01d810b0b9034f3a (patch)
treeb4612d9976e3348b09029961560e7ceb36c90baa /dcae-analytics/dcae-analytics-tca-web
parent13bb744669580623fd779f287ca9ce647d6182b6 (diff)
for policy update work
Issue-ID: DCAEGEN2-2198 Signed-off-by: Kai Lu <lukai@chinamobile.com> Change-Id: I8e1fec6f180ea3f44fa6df707048b5396b8d5a39
Diffstat (limited to 'dcae-analytics/dcae-analytics-tca-web')
-rw-r--r--dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/config/TcaMrConfig.java2
-rw-r--r--dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/controller/TcaRestController.java3
-rw-r--r--dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/service/TcaProcessingService.java6
-rw-r--r--dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/service/TcaProcessingServiceImpl.java5
-rw-r--r--dcae-analytics/dcae-analytics-tca-web/src/test/java/org/onap/dcae/analytics/tca/web/controller/TcaRestControllerTest.java3
-rw-r--r--dcae-analytics/dcae-analytics-tca-web/src/test/java/org/onap/dcae/analytics/tca/web/service/TcaProcessingServiceImplTest.java6
6 files changed, 15 insertions, 10 deletions
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 e330914..3579d3e 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
@@ -86,7 +86,7 @@ public class TcaMrConfig {
tcaProcessingService.getTcaExecutionResults(
headers.getOrDefault(REQUEST_ID_HEADER_KEY, headers.get(MessageHeaders.ID)).toString(),
headers.getOrDefault(REQUEST_TRANSACTION_ID_HEADER_KEY, "").toString(),
- tcaPolicyWrapper.getTcaPolicy(), cefMessages))
+ tcaPolicyWrapper, cefMessages))
// transform tca execution results to alerts - if not alerts are detected terminate further processing
.transform(tcaAlertTransformer, c -> c.requiresReply(false))
// post messages to dmaap publisher input channel
diff --git a/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/controller/TcaRestController.java b/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/controller/TcaRestController.java
index 0d34f90..402d475 100644
--- a/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/controller/TcaRestController.java
+++ b/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/controller/TcaRestController.java
@@ -82,10 +82,11 @@ public class TcaRestController {
@ApiOperation(value = "Applies TCA to provided execution request and generated TCA execution response")
public ResponseEntity<List<TcaExecutionResponse>> execute(@RequestBody final TcaExecutionRequest
tcaExecutionRequest) {
+
// process tca execution request
final List<TcaExecutionContext> executionContexts = tcaProcessingService.getTcaExecutionResults(
tcaExecutionRequest.getRequestId(), tcaExecutionRequest.getTransactionId(),
- tcaExecutionRequest.getTcaPolicy(), TcaUtils.getCefMessagesFromEventListeners
+ tcaPolicyWrapper, TcaUtils.getCefMessagesFromEventListeners
(tcaExecutionRequest.getEventListeners()));
// create execution response
final List<TcaExecutionResponse> tcaExecutionResponses = executionContexts.stream().map(tcaExecutionContext -> {
diff --git a/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/service/TcaProcessingService.java b/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/service/TcaProcessingService.java
index 39a985c..5b9f5a8 100644
--- a/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/service/TcaProcessingService.java
+++ b/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/service/TcaProcessingService.java
@@ -22,7 +22,7 @@ package org.onap.dcae.analytics.tca.web.service;
import java.util.List;
import org.onap.dcae.analytics.tca.core.service.TcaExecutionContext;
-import org.onap.dcae.analytics.tca.model.policy.TcaPolicy;
+import org.onap.dcae.analytics.tca.web.domain.TcaPolicyWrapper;
/**
* Provides TCA functionality
@@ -36,13 +36,13 @@ public interface TcaProcessingService {
*
* @param requestId request id associated with tca execution request
* @param transactionId transaction id associated with the tca execution request
- * @param tcaPolicy tca policy that needs to be applied to CEF messages
+ * @param tcaPolicyWrapper tca policy that needs to be applied to CEF messages
* @param cefMessages list of CEF messages that needs to be processed by TCA
*
* @return results of TCA Processing
*/
List<TcaExecutionContext> getTcaExecutionResults(String requestId, String transactionId,
- TcaPolicy tcaPolicy,
+ TcaPolicyWrapper tcaPolicyWrapper,
List<String> cefMessages);
diff --git a/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/service/TcaProcessingServiceImpl.java b/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/service/TcaProcessingServiceImpl.java
index f5aec0b..e05026c 100644
--- a/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/service/TcaProcessingServiceImpl.java
+++ b/dcae-analytics/dcae-analytics-tca-web/src/main/java/org/onap/dcae/analytics/tca/web/service/TcaProcessingServiceImpl.java
@@ -37,6 +37,7 @@ import org.onap.dcae.analytics.tca.core.service.TcaExecutionContext;
import org.onap.dcae.analytics.tca.core.util.TcaUtils;
import org.onap.dcae.analytics.tca.core.util.function.calculation.TcaCalculator;
import org.onap.dcae.analytics.tca.model.policy.TcaPolicy;
+import org.onap.dcae.analytics.tca.web.domain.TcaPolicyWrapper;
/**
* @author Rajiv Singla
@@ -56,10 +57,10 @@ public class TcaProcessingServiceImpl implements TcaProcessingService {
@Override
public List<TcaExecutionContext> getTcaExecutionResults(final String requestId,
final String transactionId,
- final TcaPolicy tcaPolicy,
+ final TcaPolicyWrapper tcaPolicyWrapper,
final List<String> cefMessages) {
// create tca policy deep copy as it should be same for current execution
- final TcaPolicy tcaPolicyDeepCopy = TcaUtils.getTcaPolicyDeepCopy(tcaPolicy);
+ final TcaPolicy tcaPolicyDeepCopy = TcaUtils.getTcaPolicyDeepCopy(tcaPolicyWrapper.getTcaPolicy());
// create new request id if not present
final String executionRequestId = isPresent(requestId) ? requestId : REQUEST_ID_SUPPLIER.get();
// create transaction id if not present
diff --git a/dcae-analytics/dcae-analytics-tca-web/src/test/java/org/onap/dcae/analytics/tca/web/controller/TcaRestControllerTest.java b/dcae-analytics/dcae-analytics-tca-web/src/test/java/org/onap/dcae/analytics/tca/web/controller/TcaRestControllerTest.java
index 04146a3..001af0f 100644
--- a/dcae-analytics/dcae-analytics-tca-web/src/test/java/org/onap/dcae/analytics/tca/web/controller/TcaRestControllerTest.java
+++ b/dcae-analytics/dcae-analytics-tca-web/src/test/java/org/onap/dcae/analytics/tca/web/controller/TcaRestControllerTest.java
@@ -54,9 +54,8 @@ public class TcaRestControllerTest {
TcaProcessingService tcaProcessingService = Mockito.mock(TcaProcessingService.class);
TcaExecutionContext tcaExecutionContext = Mockito.mock(TcaExecutionContext.class);
List<String> cefMessages = Arrays.asList("Test1", "Test2");
- TcaPolicy tcaPolicy = Mockito.mock(TcaPolicy.class);
List<TcaExecutionContext> executionContexts = Arrays.asList(tcaExecutionContext, tcaExecutionContext);
- Mockito.when(tcaProcessingService.getTcaExecutionResults("requestId", "transactioId", tcaPolicy, cefMessages))
+ Mockito.when(tcaProcessingService.getTcaExecutionResults("requestId", "transactioId", tcaPolicyWrapper, cefMessages))
.thenReturn(executionContexts);
TcaRestController restcontroller = new TcaRestController(tcaProcessingService, tcaPolicyWrapper);
restcontroller.execute(tcaExecutionRequest);
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 9347d53..5e9957e 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
@@ -25,12 +25,14 @@ import java.util.Arrays;
import java.util.List;
import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
import org.onap.dcae.analytics.tca.core.exception.AnalyticsParsingException;
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.model.policy.TcaPolicy;
+import org.onap.dcae.analytics.tca.web.domain.TcaPolicyWrapper;
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -53,10 +55,12 @@ class TcaProcessingServiceImplTest {
TcaAbatementContext tcaAbatementContext = new TestTcaAbatementContext();
TcaAaiEnrichmentContext tcaAaiEnrichmentContext = new TestTcaAaiEnrichmentContext();
+ TcaPolicyWrapper tcaPolicyWrapper = Mockito.mock(TcaPolicyWrapper.class);
// 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);
+ Mockito.when(tcaPolicyWrapper.getTcaPolicy()).thenReturn(tcaPolicy);
TcaProcessingService tcaProcessingService = new TcaProcessingServiceImpl(tcaAbatementContext, tcaAaiEnrichmentContext);
String cefMessage = "{\r\n" +
@@ -373,7 +377,7 @@ class TcaProcessingServiceImplTest {
ObjectMapper objectMapper = new ObjectMapper();
final List<TcaExecutionContext> tcaExecutionResults = tcaProcessingService.getTcaExecutionResults(
- "testRequestId", "testTransactionId", tcaPolicy,
+ "testRequestId", "testTransactionId", tcaPolicyWrapper,
Arrays.asList(cefMessage, cefViolationMessage,
cefAbatementMessage,
cefInapplicableMessage));