summaryrefslogtreecommitdiffstats
path: root/holmes-actions
diff options
context:
space:
mode:
Diffstat (limited to 'holmes-actions')
-rw-r--r--holmes-actions/src/main/java/org/onap/holmes/common/api/stat/VesAlarm.java6
-rw-r--r--holmes-actions/src/main/java/org/onap/holmes/common/dmaap/DmaapService.java44
-rw-r--r--holmes-actions/src/main/java/org/onap/holmes/common/dmaap/entity/PolicyMsg.java5
-rw-r--r--holmes-actions/src/test/java/org/onap/holmes/common/api/stat/VesAlarmTest.java9
-rw-r--r--holmes-actions/src/test/java/org/onap/holmes/common/dmaap/DmaapServiceTest.java8
5 files changed, 40 insertions, 32 deletions
diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/api/stat/VesAlarm.java b/holmes-actions/src/main/java/org/onap/holmes/common/api/stat/VesAlarm.java
index f43d3bd..ead8464 100644
--- a/holmes-actions/src/main/java/org/onap/holmes/common/api/stat/VesAlarm.java
+++ b/holmes-actions/src/main/java/org/onap/holmes/common/api/stat/VesAlarm.java
@@ -57,7 +57,7 @@ public class VesAlarm implements Cloneable, Serializable{
@Override
public int hashCode() {
- return this.version.hashCode();
+ return (this.getSourceId() + this.eventName.replace("Cleared", "")).hashCode();
}
@Override
@@ -65,7 +65,9 @@ public class VesAlarm implements Cloneable, Serializable{
if (object == null || !(object instanceof VesAlarm)) {
return false;
}
- return this.version.equals(((VesAlarm) object).getVersion());
+ return this.eventName.replace("Cleared", "")
+ .equals(((VesAlarm) object).getEventName().replace("Cleared", ""))
+ && this.getSourceId().equals(((VesAlarm) object).getSourceId());
}
@Override
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 3ddf126..fc79539 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
@@ -38,14 +38,12 @@ import org.onap.holmes.common.utils.JacksonUtil;
@Slf4j
@Service
public class DmaapService {
-
public static final int POLICY_MESSAGE_ABATED = 1;
-
+ public static final String SERVICE_INSTANCE = "service-instance";
+ public static final String SERVICE_INSTANCE_ID = "service-instance.service-instance-id";
@Inject
private AaiQuery aaiQuery;
-
public static ConcurrentHashMap<String, String> loopControlNames = new ConcurrentHashMap<>();
-
public static ConcurrentHashMap<String, String> alarmUniqueRequestID = new ConcurrentHashMap<>();
public void publishPolicyMsg(PolicyMsg policyMsg, String dmaapConfigKey) {
@@ -75,7 +73,7 @@ public class DmaapService {
List<Relationship> relationshipList = vnfEntity.getRelationshipList().getRelationships();
Relationship relationship = null;
for(int i = 0; i < relationshipList.size(); i++) {
- if ("service-instance".equals(relationshipList.get(i).getRelatedTo())) {
+ if (SERVICE_INSTANCE.equals(relationshipList.get(i).getRelatedTo())) {
relationship = relationshipList.get(i);
break;
}
@@ -83,7 +81,7 @@ public class DmaapService {
if (relationship != null) {
List<RelationshipData> relationshipDataList = relationship.getRelationshipDataList();
for(int i = 0; i < relationshipDataList.size(); i++) {
- if ("service-instance.service-instance-id"
+ if (SERVICE_INSTANCE_ID
.equals(relationshipDataList.get(i).getRelationshipKey())) {
vserverInstanceId = relationshipDataList.get(i).getRelationshipValue();
break;
@@ -97,30 +95,34 @@ public class DmaapService {
private PolicyMsg getEnrichedPolicyMsg(VmEntity vmEntity, VesAlarm rootAlarm, VesAlarm childAlarm,
String packageName) {
PolicyMsg policyMsg = new PolicyMsg();
+ String alarmUniqueKey = "";
if (rootAlarm.getAlarmIsCleared() == POLICY_MESSAGE_ABATED) {
policyMsg.setClosedLoopEventStatus(EVENT_STATUS.ABATED);
+ alarmUniqueKey =
+ rootAlarm.getSourceId() + ":" + rootAlarm.getEventName().replace("Cleared", "");
} else {
policyMsg.setClosedLoopEventStatus(EVENT_STATUS.ONSET);
enrichVnfInfo(childAlarm, policyMsg);
+ alarmUniqueKey = rootAlarm.getSourceId() + ":" + rootAlarm.getEventName();
}
- if (alarmUniqueRequestID.containsKey(rootAlarm.getSourceId())) {
- policyMsg.setRequestID(alarmUniqueRequestID.get(rootAlarm.getSourceId()));
+ if (alarmUniqueRequestID.containsKey(alarmUniqueKey)) {
+ policyMsg.setRequestID(alarmUniqueRequestID.get(alarmUniqueKey));
} else {
String requestID = UUID.randomUUID().toString();
policyMsg.setRequestID(requestID);
- alarmUniqueRequestID.put(rootAlarm.getSourceId(), requestID);
+ alarmUniqueRequestID.put(alarmUniqueKey, requestID);
}
policyMsg.setClosedLoopControlName(loopControlNames.get(packageName));
policyMsg.setTarget(vmEntity.getVserverName());
- policyMsg.getAAI().put("vserver.in-maint", String.valueOf(vmEntity.getInMaint()));
- policyMsg.getAAI().put("vserver.is-closed-loop-disabled",
+ policyMsg.getAai().put("vserver.in-maint", String.valueOf(vmEntity.getInMaint()));
+ policyMsg.getAai().put("vserver.is-closed-loop-disabled",
String.valueOf(vmEntity.getClosedLoopDisable()));
- policyMsg.getAAI().put("vserver.prov-status", vmEntity.getProvStatus());
- policyMsg.getAAI().put("vserver.resource-version", vmEntity.getResourceVersion());
- policyMsg.getAAI().put("vserver.vserver-id", vmEntity.getVserverId());
- policyMsg.getAAI().put("vserver.vserver-name", vmEntity.getVserverName());
- policyMsg.getAAI().put("vserver.vserver-name2", vmEntity.getVserverName2());
- policyMsg.getAAI().put("vserver.vserver-selflink", vmEntity.getVserverSelflink());
+ policyMsg.getAai().put("vserver.prov-status", vmEntity.getProvStatus());
+ policyMsg.getAai().put("vserver.resource-version", vmEntity.getResourceVersion());
+ policyMsg.getAai().put("vserver.vserver-id", vmEntity.getVserverId());
+ policyMsg.getAai().put("vserver.vserver-name", vmEntity.getVserverName());
+ policyMsg.getAai().put("vserver.vserver-name2", vmEntity.getVserverName2());
+ policyMsg.getAai().put("vserver.vserver-selflink", vmEntity.getVserverSelflink());
return policyMsg;
}
@@ -128,16 +130,16 @@ public class DmaapService {
PolicyMsg policyMsg = new PolicyMsg();
policyMsg.setTarget("vserver.vserver-name");
policyMsg.setTargetType("VM");
- policyMsg.getAAI().put("vserver.vserver-name", sourceName);
+ policyMsg.getAai().put("vserver.vserver-name", sourceName);
return policyMsg;
}
private void enrichVnfInfo(VesAlarm childAlarm, PolicyMsg policyMsg) {
VnfEntity vnfEntity = getVnfEntity(childAlarm.getSourceId(), childAlarm.getSourceName());
String vserverInstatnceId = getVserverInstanceId(vnfEntity);
- policyMsg.getAAI().put("generic-vnf.vnf-id", childAlarm.getSourceId());
- policyMsg.getAAI().put("generic-vnf.vnf-name", childAlarm.getSourceName());
- policyMsg.getAAI().put("generic-vnf.service-instance-id", vserverInstatnceId);
+ policyMsg.getAai().put("generic-vnf.vnf-id", childAlarm.getSourceId());
+ policyMsg.getAai().put("generic-vnf.vnf-name", childAlarm.getSourceName());
+ policyMsg.getAai().put("generic-vnf.service-instance-id", vserverInstatnceId);
}
private VnfEntity getVnfEntity(String vnfId, String vnfName) {
diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/entity/PolicyMsg.java b/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/entity/PolicyMsg.java
index 4462474..37713b4 100644
--- a/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/entity/PolicyMsg.java
+++ b/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/entity/PolicyMsg.java
@@ -36,11 +36,12 @@ public class PolicyMsg {
private String policyVersion;
private String policyName;
private String policyScope;
- private String from = "HOLMES";
+ private String from = "DCAE";
@JsonProperty(value = "target_type")
private String targetType = "VM";
private String target;
- private Map<String, String> AAI = new HashMap<>();
+ @JsonProperty(value = "AAI")
+ private Map<String, String> aai = new HashMap<>();
public static enum EVENT_STATUS {
ONSET, ABATED;
diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/api/stat/VesAlarmTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/api/stat/VesAlarmTest.java
index c2772e8..f046517 100644
--- a/holmes-actions/src/test/java/org/onap/holmes/common/api/stat/VesAlarmTest.java
+++ b/holmes-actions/src/test/java/org/onap/holmes/common/api/stat/VesAlarmTest.java
@@ -27,7 +27,8 @@ public class VesAlarmTest {
@Test
public void hashCodeTest() throws Exception {
VesAlarm alarm = new VesAlarm();
- alarm.setVersion(0L);
+ alarm.setEventName("unique");
+ alarm.setSourceId("123");
VesAlarm alarmClone = (VesAlarm)alarm.clone();
assertTrue(alarm.hashCode() == alarmClone.hashCode());
}
@@ -35,7 +36,8 @@ public class VesAlarmTest {
@Test
public void equalsTest() throws Exception {
VesAlarm alarm = new VesAlarm();
- alarm.setVersion(0L);
+ alarm.setEventName("unique");
+ alarm.setSourceId("123");
VesAlarm alarmClone = (VesAlarm)alarm.clone();
assertTrue(alarm.equals(alarmClone));
}
@@ -44,7 +46,8 @@ public class VesAlarmTest {
public void cloneTest() throws Exception {
VesAlarm alarm = new VesAlarm();
alarm.setDomain("Test");
- alarm.setVersion(0L);
+ alarm.setEventName("unique");
+ alarm.setSourceId("123");
assertThat(alarm, equalTo(alarm.clone()));
}
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 c9f892b..3f61813 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
@@ -72,7 +72,7 @@ public class DmaapServiceTest {
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("tetss"));
}
@Test
@@ -189,8 +189,8 @@ public class DmaapServiceTest {
PowerMock.verifyAll();
assertThat(actual.getClosedLoopControlName(), equalTo(null));
- assertThat(actual.getAAI().get("vserver.prov-status"), equalTo("prov"));
- assertThat(actual.getAAI().get("vserver.vserver-name2") == null, equalTo(true));
- assertThat(actual.getAAI().get("generic-vnf.service-instance-id"), equalTo(""));
+ assertThat(actual.getAai().get("vserver.prov-status"), equalTo("prov"));
+ assertThat(actual.getAai().get("vserver.vserver-name2") == null, equalTo(true));
+ assertThat(actual.getAai().get("generic-vnf.service-instance-id"), equalTo(""));
}
} \ No newline at end of file