summaryrefslogtreecommitdiffstats
path: root/dcae-analytics-cdap-common/src/test
diff options
context:
space:
mode:
authoran4828 <nekrassov@att.com>2017-09-15 15:28:53 -0400
committeran4828 <nekrassov@att.com>2017-09-18 09:24:04 -0400
commit4edf0fa48892bf38d0e3838d125e9bf2324b38e0 (patch)
tree7216dae042828ec2cf38cb9300af1a32a17b3b91 /dcae-analytics-cdap-common/src/test
parent82aaf956855507e5a72d5ef5b45e398430d04a7a (diff)
Add support for ABATED alerts within CDAP TCA
Change-Id: Iae560a2d0a47b30b41cd31206dc481a08e4930f7 Signed-off-by: an4828 <nekrassov@att.com> Issue-ID: DCAEGEN2-107 Signed-off-by: an4828 <nekrassov@att.com>
Diffstat (limited to 'dcae-analytics-cdap-common/src/test')
-rw-r--r--dcae-analytics-cdap-common/src/test/java/org/openecomp/dcae/apod/analytics/cdap/common/BaseAnalyticsCDAPCommonUnitTest.java4
-rw-r--r--dcae-analytics-cdap-common/src/test/java/org/openecomp/dcae/apod/analytics/cdap/common/persistance/tca/TCAAlertsAbatementPersisterTest.java103
-rw-r--r--dcae-analytics-cdap-common/src/test/java/org/openecomp/dcae/apod/analytics/cdap/common/persistance/tca/TCAMessageStatusPersisterTest.java15
-rw-r--r--dcae-analytics-cdap-common/src/test/resources/data/json/cef_message.json37
-rw-r--r--dcae-analytics-cdap-common/src/test/resources/data/json/tca_policy.json53
5 files changed, 113 insertions, 99 deletions
diff --git a/dcae-analytics-cdap-common/src/test/java/org/openecomp/dcae/apod/analytics/cdap/common/BaseAnalyticsCDAPCommonUnitTest.java b/dcae-analytics-cdap-common/src/test/java/org/openecomp/dcae/apod/analytics/cdap/common/BaseAnalyticsCDAPCommonUnitTest.java
index 825cdf0..55a2198 100644
--- a/dcae-analytics-cdap-common/src/test/java/org/openecomp/dcae/apod/analytics/cdap/common/BaseAnalyticsCDAPCommonUnitTest.java
+++ b/dcae-analytics-cdap-common/src/test/java/org/openecomp/dcae/apod/analytics/cdap/common/BaseAnalyticsCDAPCommonUnitTest.java
@@ -35,8 +35,8 @@ import org.openecomp.dcae.apod.analytics.test.BaseDCAEAnalyticsUnitTest;
*/
public abstract class BaseAnalyticsCDAPCommonUnitTest extends BaseDCAEAnalyticsUnitTest {
- protected static final String CEF_MESSAGE_FILE_LOCATION = "data/json/cef_message.json";
- protected static final String TCA_POLICY_FILE_LOCATION = "data/json/tca_policy.json";
+ protected static final String CEF_MESSAGE_FILE_LOCATION = "data/json/cef/cef_message.json";
+ protected static final String TCA_POLICY_FILE_LOCATION = "data/json/policy/tca_policy.json";
protected static final ObjectMapper ANALYTICS_MODEL_OBJECT_MAPPER =
Suppliers.memoize(new AnalyticsModelObjectMapperSupplier()).get();
diff --git a/dcae-analytics-cdap-common/src/test/java/org/openecomp/dcae/apod/analytics/cdap/common/persistance/tca/TCAAlertsAbatementPersisterTest.java b/dcae-analytics-cdap-common/src/test/java/org/openecomp/dcae/apod/analytics/cdap/common/persistance/tca/TCAAlertsAbatementPersisterTest.java
new file mode 100644
index 0000000..36d72fa
--- /dev/null
+++ b/dcae-analytics-cdap-common/src/test/java/org/openecomp/dcae/apod/analytics/cdap/common/persistance/tca/TCAAlertsAbatementPersisterTest.java
@@ -0,0 +1,103 @@
+package org.openecomp.dcae.apod.analytics.cdap.common.persistance.tca;
+
+import co.cask.cdap.api.dataset.DatasetProperties;
+import co.cask.cdap.api.dataset.lib.ObjectMappedTable;
+import com.google.common.base.Joiner;
+import com.google.common.collect.ImmutableList;
+import org.junit.Before;
+import org.junit.Test;
+import org.openecomp.dcae.apod.analytics.cdap.common.BaseAnalyticsCDAPCommonUnitTest;
+import org.openecomp.dcae.apod.analytics.common.utils.PersistenceUtils;
+import org.openecomp.dcae.apod.analytics.model.domain.cef.CommonEventHeader;
+import org.openecomp.dcae.apod.analytics.model.domain.cef.Event;
+import org.openecomp.dcae.apod.analytics.model.domain.cef.EventListener;
+import org.openecomp.dcae.apod.analytics.model.domain.policy.tca.MetricsPerEventName;
+import org.openecomp.dcae.apod.analytics.model.domain.policy.tca.Threshold;
+import org.openecomp.dcae.apod.analytics.model.facade.tca.TCAVESResponse;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+/**
+ * Author: rs153v (Rajiv Singla) . Creation Date: 9/13/2017.
+ */
+public class TCAAlertsAbatementPersisterTest extends BaseAnalyticsCDAPCommonUnitTest {
+
+ private static final String EVENT_NAME = "testEventName";
+ private static final String SOURCE_NAME = "testSourceName";
+ private static final String REPORTING_ENTITY_NAME = "testReportingEntityName";
+ private static final String THRESHOLD_CLOSED_LOOP_CONTROL_NAME = "testControlLoopName";
+ private static final String THRESHOLD_FIELD_PATH = "testFieldPath";
+ private static final String EXPECTED_LOOKUP_KEY = Joiner.on(PersistenceUtils.ROW_KEY_DELIMITER).join(
+ ImmutableList.of(EVENT_NAME, SOURCE_NAME, REPORTING_ENTITY_NAME,
+ THRESHOLD_CLOSED_LOOP_CONTROL_NAME, THRESHOLD_FIELD_PATH));
+
+ private ObjectMappedTable<TCAAlertsAbatementEntity> alertsAbatementTable;
+ private EventListener eventListener;
+ private MetricsPerEventName violatedMetricsPerEventName;
+ private TCAVESResponse tcavesResponse;
+ private String abatementTS;
+ private Event event;
+ private CommonEventHeader commonEventHeader;
+ private Threshold violatedThreshold;
+
+ @Before
+ public void before() throws Exception {
+ alertsAbatementTable = mock(ObjectMappedTable.class);
+ eventListener = mock(EventListener.class);
+ event = mock(Event.class);
+ commonEventHeader = mock(CommonEventHeader.class);
+
+ when(eventListener.getEvent()).thenReturn(event);
+ when(event.getCommonEventHeader()).thenReturn(commonEventHeader);
+ when(commonEventHeader.getEventName()).thenReturn(EVENT_NAME);
+ when(commonEventHeader.getSourceName()).thenReturn(SOURCE_NAME);
+ when(commonEventHeader.getReportingEntityName()).thenReturn(REPORTING_ENTITY_NAME);
+
+ violatedMetricsPerEventName = mock(MetricsPerEventName.class);
+ when(violatedMetricsPerEventName.getEventName()).thenReturn(EVENT_NAME);
+ violatedThreshold = mock(Threshold.class);
+ when(violatedMetricsPerEventName.getThresholds()).thenReturn(ImmutableList.of(violatedThreshold));
+ when(violatedThreshold.getClosedLoopControlName()).thenReturn(THRESHOLD_CLOSED_LOOP_CONTROL_NAME);
+ when(violatedThreshold.getFieldPath()).thenReturn(THRESHOLD_FIELD_PATH);
+ tcavesResponse = mock(TCAVESResponse.class);
+ abatementTS = "1234";
+ }
+
+ @Test
+ public void testGetDatasetProperties() throws Exception {
+ final DatasetProperties datasetProperties = TCAAlertsAbatementPersister.getDatasetProperties(20000);
+ assertNotNull(datasetProperties);
+ }
+
+ @Test
+ public void testPersist() throws Exception {
+
+ TCAAlertsAbatementPersister.persist(eventListener, violatedMetricsPerEventName, tcavesResponse,
+ abatementTS, alertsAbatementTable);
+ verify(alertsAbatementTable, times(1)).write(anyString(),
+ any(TCAAlertsAbatementEntity.class));
+
+ }
+
+ @Test
+ public void testLookUpByKey() throws Exception {
+ TCAAlertsAbatementPersister.lookUpByKey(eventListener, violatedMetricsPerEventName, alertsAbatementTable);
+ verify(alertsAbatementTable, times(1)).read(eq(EXPECTED_LOOKUP_KEY));
+ }
+
+ @Test
+ public void testCreateKey() throws Exception {
+ final String createdKey = TCAAlertsAbatementPersister.createKey(eventListener, violatedMetricsPerEventName);
+ assertEquals(createdKey, EXPECTED_LOOKUP_KEY);
+
+ }
+
+}
diff --git a/dcae-analytics-cdap-common/src/test/java/org/openecomp/dcae/apod/analytics/cdap/common/persistance/tca/TCAMessageStatusPersisterTest.java b/dcae-analytics-cdap-common/src/test/java/org/openecomp/dcae/apod/analytics/cdap/common/persistance/tca/TCAMessageStatusPersisterTest.java
index a062b37..7dfd74d 100644
--- a/dcae-analytics-cdap-common/src/test/java/org/openecomp/dcae/apod/analytics/cdap/common/persistance/tca/TCAMessageStatusPersisterTest.java
+++ b/dcae-analytics-cdap-common/src/test/java/org/openecomp/dcae/apod/analytics/cdap/common/persistance/tca/TCAMessageStatusPersisterTest.java
@@ -28,11 +28,12 @@ import org.junit.Before;
import org.junit.Test;
import org.openecomp.dcae.apod.analytics.cdap.common.BaseAnalyticsCDAPCommonUnitTest;
import org.openecomp.dcae.apod.analytics.model.domain.cef.CommonEventHeader;
+import org.openecomp.dcae.apod.analytics.model.domain.cef.Domain;
import org.openecomp.dcae.apod.analytics.model.domain.cef.Event;
import org.openecomp.dcae.apod.analytics.model.domain.cef.EventListener;
import org.openecomp.dcae.apod.analytics.model.domain.cef.EventSeverity;
import org.openecomp.dcae.apod.analytics.model.domain.policy.tca.Direction;
-import org.openecomp.dcae.apod.analytics.model.domain.policy.tca.MetricsPerFunctionalRole;
+import org.openecomp.dcae.apod.analytics.model.domain.policy.tca.MetricsPerEventName;
import org.openecomp.dcae.apod.analytics.model.domain.policy.tca.TCAPolicy;
import org.openecomp.dcae.apod.analytics.model.domain.policy.tca.Threshold;
import org.openecomp.dcae.apod.analytics.tca.processor.TCACEFProcessorContext;
@@ -51,8 +52,8 @@ import static org.mockito.Mockito.when;
public class TCAMessageStatusPersisterTest extends BaseAnalyticsCDAPCommonUnitTest {
private static final int TEST_INSTANCE_ID = 0;
- private static final String TEST_DOMAIN = "TEST_DOMAIN";
- private static final String TEST_FUNCTIONAL_ROLE = "TEST_FUNCIONAL_ROLE";
+ private static final Domain TEST_DOMAIN = Domain.other;
+ private static final String TEST_EVENT_NAME = "TEST_EVENT_NAME";
private ObjectMappedTable<TCAMessageStatusEntity> vesMessageStatusTable;
private TCACEFProcessorContext processorContext;
@@ -73,7 +74,7 @@ public class TCAMessageStatusPersisterTest extends BaseAnalyticsCDAPCommonUnitTe
when(processorContext.getCEFEventListener()).thenReturn(eventListener);
when(eventListener.getEvent()).thenReturn(event);
when(event.getCommonEventHeader()).thenReturn(commonEventHeader);
- when(commonEventHeader.getFunctionalRole()).thenReturn(TEST_FUNCTIONAL_ROLE);
+ when(commonEventHeader.getEventName()).thenReturn(TEST_EVENT_NAME);
when(commonEventHeader.getDomain()).thenReturn(TEST_DOMAIN);
}
@@ -88,10 +89,10 @@ public class TCAMessageStatusPersisterTest extends BaseAnalyticsCDAPCommonUnitTe
@Test
public void testPersistWithNonCompliantMessage() throws Exception {
- final MetricsPerFunctionalRole metricsPerFunctionalRole = mock(MetricsPerFunctionalRole.class);
+ final MetricsPerEventName metricsPerEventName = mock(MetricsPerEventName.class);
final Threshold threshold = mock(Threshold.class);
- when(processorContext.getMetricsPerFunctionalRole()).thenReturn(metricsPerFunctionalRole);
- when((metricsPerFunctionalRole.getThresholds())).thenReturn(ImmutableList.of(threshold));
+ when(processorContext.getMetricsPerEventName()).thenReturn(metricsPerEventName);
+ when((metricsPerEventName.getThresholds())).thenReturn(ImmutableList.of(threshold));
when(threshold.getDirection()).thenReturn(Direction.GREATER);
when(threshold.getSeverity()).thenReturn(EventSeverity.CRITICAL);
TCAMessageStatusPersister.persist(
diff --git a/dcae-analytics-cdap-common/src/test/resources/data/json/cef_message.json b/dcae-analytics-cdap-common/src/test/resources/data/json/cef_message.json
deleted file mode 100644
index 52cf53b..0000000
--- a/dcae-analytics-cdap-common/src/test/resources/data/json/cef_message.json
+++ /dev/null
@@ -1,37 +0,0 @@
-{
- "event": {
- "measurementsForVfScalingFields": {
- "measurementInterval": 10,
- "measurementsForVfScalingVersion": 1.1,
- "vNicUsageArray": [
- {
- "bytesIn": 6086,
- "multicastPacketsIn": 0,
- "multicastPacketsOut": 0,
- "unicastPacketsIn": 0,
- "broadcastPacketsOut": 0,
- "packetsOut": 42,
- "bytesOut": 7156,
- "packetsIn": 93,
- "broadcastPacketsIn": 0,
- "vNicIdentifier": "eth0",
- "unicastPacketsOut": 0
- }
- ]
- },
- "commonEventHeader": {
- "reportingEntityName": "vpp-test",
- "startEpochMicrosec": 1477070210290442,
- "eventId": "375",
- "lastEpochMicrosec": 1477070220290442,
- "priority": "Normal",
- "sequence": 375,
- "sourceName": "Dummy VM name - No Metadata available",
- "domain": "measurementsForVfScaling",
- "functionalRole": "vFirewall",
- "reportingEntityId": "No UUID available",
- "version": 1.1,
- "sourceId": "Dummy VM UUID - No Metadata available"
- }
- }
-}
diff --git a/dcae-analytics-cdap-common/src/test/resources/data/json/tca_policy.json b/dcae-analytics-cdap-common/src/test/resources/data/json/tca_policy.json
deleted file mode 100644
index 1bf9e83..0000000
--- a/dcae-analytics-cdap-common/src/test/resources/data/json/tca_policy.json
+++ /dev/null
@@ -1,53 +0,0 @@
-{
- "domain": "measurementsForVfScaling",
- "metricsPerFunctionalRole": [
- {
- "functionalRole": "vFirewall",
- "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",
- "version": "1.0.2",
- "fieldPath": "$.event.measurementsForVfScalingFields.vNicUsageArray[*].bytesIn",
- "thresholdValue": 4000,
- "direction": "LESS_OR_EQUAL",
- "severity": "MAJOR"
- },
- {
- "closedLoopControlName": "CL-FRWL-HIGH-TRAFFIC-SIG-EA36FE84-9342-5E13-A656-EC5F21309A09",
- "version": "1.0.2",
- "fieldPath": "$.event.measurementsForVfScalingFields.vNicUsageArray[*].bytesIn",
- "thresholdValue": 20000,
- "direction": "GREATER_OR_EQUAL",
- "severity": "CRITICAL"
- }
- ]
- },
- {
- "functionalRole": "vLoadBalancer",
- "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",
- "version": "1.0.2",
- "fieldPath": "$.event.measurementsForVfScalingFields.vNicUsageArray[*].packetsIn",
- "thresholdValue": 500,
- "direction": "LESS_OR_EQUAL",
- "severity": "MAJOR"
- },
- {
- "closedLoopControlName": "CL-LBAL-LOW-TRAFFIC-SIG-0C5920A6-B564-8035-C878-0E814352BC2B",
- "version": "1.0.2",
- "fieldPath": "$.event.measurementsForVfScalingFields.vNicUsageArray[*].packetsIn",
- "thresholdValue": 5000,
- "direction": "GREATER_OR_EQUAL",
- "severity": "CRITICAL"
- }
- ]
- }
- ]
-}