summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuangrong Fu <fu.guangrong@zte.com.cn>2017-11-10 14:25:16 +0800
committerGuangrong Fu <fu.guangrong@zte.com.cn>2017-11-10 14:25:16 +0800
commit449744265f24a4d3337115240ae4e834594c50a2 (patch)
tree02a18a72206e297eea8ccd68b29d428815ec70fd
parentee62cd0ae490e27d461d50258805dc37c5de0d3b (diff)
Fix Some Bug
Add more info to the CL event even the AAI info is partly unavailable. Change-Id: I61a6ee8e0e1a5c9e7b3416646140d61a948f5424 Issue-ID: HOLMES-85 Signed-off-by: Guangrong Fu <fu.guangrong@zte.com.cn>
-rw-r--r--holmes-actions/src/main/java/org/onap/holmes/common/dmaap/DmaapService.java19
-rw-r--r--holmes-actions/src/test/java/org/onap/holmes/common/dmaap/DmaapServiceTest.java41
2 files changed, 41 insertions, 19 deletions
diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/DmaapService.java b/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/DmaapService.java
index 2651c97..5fb1176 100644
--- a/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/DmaapService.java
+++ b/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/DmaapService.java
@@ -61,13 +61,13 @@ public class DmaapService {
public PolicyMsg getPolicyMsg(VesAlarm rootAlarm, VesAlarm childAlarm, String packgeName) {
return Optional.ofNullable(getVmEntity(rootAlarm.getSourceId(), rootAlarm.getSourceName()))
.map(vmEntity -> getEnrichedPolicyMsg(vmEntity, rootAlarm, childAlarm, packgeName))
- .orElse(getDefaultPolicyMsg(rootAlarm.getSourceName()));
+ .orElse(getDefaultPolicyMsg(rootAlarm, packgeName));
}
private PolicyMsg getEnrichedPolicyMsg(VmEntity vmEntity, VesAlarm rootAlarm, VesAlarm childAlarm,
String packageName) {
PolicyMsg policyMsg = new PolicyMsg();
- policyMsg.setRequestID(getUniqueRequestId(rootAlarm, policyMsg));
+ policyMsg.setRequestID(getUniqueRequestId(rootAlarm));
if (rootAlarm.getAlarmIsCleared() == PolicyMassgeConstant.POLICY_MESSAGE_ONSET) {
enrichVnfInfo(vmEntity, childAlarm, policyMsg);
policyMsg.setClosedLoopEventStatus(EVENT_STATUS.ONSET);
@@ -95,15 +95,22 @@ public class DmaapService {
return policyMsg;
}
- private PolicyMsg getDefaultPolicyMsg(String sourceName) {
+ private PolicyMsg getDefaultPolicyMsg(VesAlarm rootAlarm, String packageName) {
PolicyMsg policyMsg = new PolicyMsg();
- policyMsg.setTarget("vserver.vserver-id");
+ policyMsg.setRequestID(getUniqueRequestId(rootAlarm));
+ policyMsg.setClosedLoopControlName(loopControlNames.get(packageName));
+ policyMsg.setClosedLoopAlarmStart(rootAlarm.getStartEpochMicrosec());
+ policyMsg.setTarget("vserver.vserver-name");
policyMsg.setTargetType("VM");
- policyMsg.getAai().put("vserver.vserver-name", sourceName);
+ policyMsg.getAai().put("vserver.vserver-name", rootAlarm.getSourceName());
+ if (rootAlarm.getAlarmIsCleared() == PolicyMassgeConstant.POLICY_MESSAGE_ABATED) {
+ policyMsg.setClosedLoopAlarmEnd(rootAlarm.getLastEpochMicrosec());
+ policyMsg.setClosedLoopEventStatus(EVENT_STATUS.ABATED);
+ }
return policyMsg;
}
- private String getUniqueRequestId(VesAlarm rootAlarm, PolicyMsg policyMsg) {
+ private String getUniqueRequestId(VesAlarm rootAlarm) {
String alarmUniqueKey = "";
if (rootAlarm.getAlarmIsCleared() == PolicyMassgeConstant.POLICY_MESSAGE_ABATED) {
alarmUniqueKey =
diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/dmaap/DmaapServiceTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/dmaap/DmaapServiceTest.java
index 5099fba..b47a16f 100644
--- a/holmes-actions/src/test/java/org/onap/holmes/common/dmaap/DmaapServiceTest.java
+++ b/holmes-actions/src/test/java/org/onap/holmes/common/dmaap/DmaapServiceTest.java
@@ -17,29 +17,28 @@ package org.onap.holmes.common.dmaap;
import static org.easymock.EasyMock.anyObject;
import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
import java.util.ArrayList;
import java.util.List;
-import org.easymock.EasyMock;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
-import org.omg.CORBA.Any;
import org.onap.holmes.common.aai.AaiQuery;
import org.onap.holmes.common.aai.entity.RelationshipList.Relationship;
import org.onap.holmes.common.aai.entity.RelationshipList.RelationshipData;
import org.onap.holmes.common.aai.entity.VmEntity;
import org.onap.holmes.common.aai.entity.VnfEntity;
import org.onap.holmes.common.api.stat.VesAlarm;
-import org.onap.holmes.common.exception.CorrelationException;
-import org.powermock.api.mockito.PowerMockito;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
import org.onap.holmes.common.dmaap.entity.PolicyMsg;
+import org.onap.holmes.common.dmaap.entity.PolicyMsg.EVENT_STATUS;
+import org.onap.holmes.common.exception.CorrelationException;
import org.powermock.api.easymock.PowerMock;
+import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.reflect.Whitebox;
@@ -63,16 +62,32 @@ public class DmaapServiceTest {
@Test
public void testDmaapService_getDefaultPolicyMsg_ok() throws Exception {
+ String packageName = "org.onap.holmes.rule";
+ DmaapService.loopControlNames.put(packageName, "Control-loop-VoLTE");
+ long startTime = System.currentTimeMillis();
+ long endTime = System.currentTimeMillis() + 1000000;
+ VesAlarm vesAlarm = new VesAlarm();
+ vesAlarm.setStartEpochMicrosec(startTime);
+ vesAlarm.setLastEpochMicrosec(endTime);
+ vesAlarm.setAlarmIsCleared(1);
+ vesAlarm.setSourceName("test");
+ vesAlarm.setSourceId("782d-4dfa-88ef");
+ vesAlarm.setEventName("alarmCleared");
PowerMock.resetAll();
PowerMock.replayAll();
PolicyMsg policyMsg = Whitebox
- .invokeMethod(dmaapService, "getDefaultPolicyMsg", "tetss");
+ .invokeMethod(dmaapService, "getDefaultPolicyMsg", vesAlarm, packageName);
PowerMock.verifyAll();
- assertThat(policyMsg.getTarget(), equalTo("vserver.vserver-id"));
+ assertThat(policyMsg.getTarget(), equalTo("vserver.vserver-name"));
assertThat(policyMsg.getTargetType(), equalTo("VM"));
- assertThat(policyMsg.getAai().get("vserver.vserver-name"), equalTo("tetss"));
+ assertThat(policyMsg.getAai().get("vserver.vserver-name"), equalTo("test"));
+ assertThat(policyMsg.getClosedLoopEventStatus(), is(EVENT_STATUS.ABATED));
+ assertThat(policyMsg.getClosedLoopControlName(), equalTo("Control-loop-VoLTE"));
+ assertThat(policyMsg.getClosedLoopAlarmStart(), is(startTime));
+ assertThat(policyMsg.getClosedLoopAlarmEnd(), is(endTime));
+ assertThat(policyMsg.getRequestID(), notNullValue());
}
@Test