diff options
author | Shiwei Tian <tian.shiwei@zte.com.cn> | 2017-10-20 16:20:05 +0800 |
---|---|---|
committer | Shiwei Tian <tian.shiwei@zte.com.cn> | 2017-10-21 11:02:28 +0800 |
commit | ece7abcfdf6d68a8f41732883435822ceb745c11 (patch) | |
tree | 9fbf4fd69e1ba1cde1531bfb9ac322184ff79ddb | |
parent | c3a783d2ed1e9e19525b7a88a0ef29aab419a436 (diff) |
modify bug
Issue-ID: HOLMES-71
Change-Id: I4af999e2061e66f4323b8b7657c4d713e4a4ae00
Signed-off-by: Shiwei Tian <tian.shiwei@zte.com.cn>
5 files changed, 54 insertions, 36 deletions
diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiQuery.java b/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiQuery.java index 40390b8..df4e4ac 100644 --- a/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiQuery.java +++ b/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiQuery.java @@ -83,7 +83,7 @@ public class AaiQuery { } private String getVnfDataResponse(String vnfId, String vnfName) throws CorrelationException { - String url = getBaseUrl(getMsbSuffixAddr(AaiConfig.AAI_VNF_ADDR)+ "vnf-id=" + vnfId); + String url = getBaseUrl(getMsbSuffixAddr(AaiConfig.AAI_VNF_ADDR)+ "/" + vnfId); String response = getResponse(url); if ("".equals(response) || "{}".equals(response)) { url = getBaseUrl(AaiConfig.AAI_VNF_ADDR + "vnf-name=" + vnfName); diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/aai/config/AaiConfig.java b/holmes-actions/src/main/java/org/onap/holmes/common/aai/config/AaiConfig.java index 1d02c78..d0ddf85 100644 --- a/holmes-actions/src/main/java/org/onap/holmes/common/aai/config/AaiConfig.java +++ b/holmes-actions/src/main/java/org/onap/holmes/common/aai/config/AaiConfig.java @@ -15,7 +15,7 @@ package org.onap.holmes.common.aai.config; public class AaiConfig { - public static final String AAI_VNF_ADDR = "/aai/v11/network/generic-vnfs/generic-vnf?"; + public static final String AAI_VNF_ADDR = "/aai/v11/network/generic-vnfs/generic-vnf"; public static final String AAI_VM_ADDR = "/aai/v11/search/nodes-query?search-node-type=vserver&filter="; 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 f414341..4dfc392 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 @@ -18,6 +18,7 @@ package org.onap.holmes.common.dmaap; import com.fasterxml.jackson.core.JsonProcessingException; import java.util.List; import java.util.Optional; +import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; import javax.inject.Inject; import lombok.extern.slf4j.Slf4j; @@ -44,6 +45,8 @@ public class DmaapService { public static ConcurrentHashMap<String, String> loopControlNames = new ConcurrentHashMap<>(); + public static ConcurrentHashMap<String, String> alarmUniqueRequestID = new ConcurrentHashMap<>(); + public void publishPolicyMsg(PolicyMsg policyMsg, String dmaapConfigKey) { try { Publisher publisher = new Publisher(); @@ -59,10 +62,10 @@ public class DmaapService { } } - public PolicyMsg getPolicyMsg(VesAlarm vesAlarm, String packgeName) { - return Optional.ofNullable(getVmEntity(vesAlarm.getSourceId(), vesAlarm.getSourceName())) - .map(vmEntity -> getEnrichedPolicyMsg(vmEntity, vesAlarm, packgeName)) - .orElse(getDefaultPolicyMsg(vesAlarm.getSourceName())); + 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())); } private String getVserverInstanceId(VnfEntity vnfEntity) { @@ -74,41 +77,29 @@ public class DmaapService { .limit(1).findFirst().get().getRelationshipDataList(); vserverInstanceId = relationshipDataList.stream() - .filter(relationshipData -> relationshipData.getRelationshipKey().equals("service-instance.service-instance-id")) + .filter(relationshipData -> relationshipData.getRelationshipKey() + .equals("service-instance.service-instance-id")) .findFirst() .map(relationshipData -> relationshipData.getRelationshipValue()).get(); } return vserverInstanceId; } - private VnfEntity getVnfEntity(String vnfId, String vnfName) { - VnfEntity vnfEntity = null; - try { - vnfEntity = aaiQuery.getAaiVnfData(vnfId, vnfName); - } catch (CorrelationException e) { - log.error("Failed to get vnf data", e.getMessage()); - } - return vnfEntity; - } - - private VmEntity getVmEntity(String sourceId, String sourceName) { - VmEntity vmEntity = null; - try { - vmEntity = aaiQuery.getAaiVmData(sourceId, sourceName); - } catch (CorrelationException e) { - log.error("Failed to get vm data", e.getMessage()); - } - return vmEntity; - } - - private PolicyMsg getEnrichedPolicyMsg(VmEntity vmEntity, VesAlarm vesAlarm, String packageName) { - VnfEntity vnfEntity = getVnfEntity(vesAlarm.getEventId(), vesAlarm.getEventName()); - String vserverInstatnceId = getVserverInstanceId(vnfEntity); + private PolicyMsg getEnrichedPolicyMsg(VmEntity vmEntity, VesAlarm rootAlarm, VesAlarm childAlarm, + String packageName) { PolicyMsg policyMsg = new PolicyMsg(); - if (vesAlarm.getAlarmIsCleared() == POLICY_MESSAGE_ABATED) { + if (rootAlarm.getAlarmIsCleared() == POLICY_MESSAGE_ABATED) { policyMsg.setClosedLoopEventStatus(EVENT_STATUS.ABATED); } else { policyMsg.setClosedLoopEventStatus(EVENT_STATUS.ONSET); + enrichVnfInfo(childAlarm, policyMsg); + } + if (alarmUniqueRequestID.containsKey(rootAlarm.getSourceId())) { + policyMsg.setRequestID(alarmUniqueRequestID.get(rootAlarm.getSourceId())); + } else { + String requestID = UUID.randomUUID().toString(); + policyMsg.setRequestID(requestID); + alarmUniqueRequestID.put(rootAlarm.getSourceId(), requestID); } policyMsg.setClosedLoopControlName(loopControlNames.get(packageName)); policyMsg.getAai().put("vserver.in-maint", String.valueOf(vmEntity.getInMaint())); @@ -120,9 +111,6 @@ public class DmaapService { 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("generic-vnf.vnf-id", vesAlarm.getEventId()); - policyMsg.getAai().put("generic-vnf.vnf-name", vesAlarm.getEventName()); - policyMsg.getAai().put("generic-vnf.service-instance-id", vserverInstatnceId); return policyMsg; } @@ -133,4 +121,32 @@ public class DmaapService { 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); + } + + private VnfEntity getVnfEntity(String vnfId, String vnfName) { + VnfEntity vnfEntity = null; + try { + vnfEntity = aaiQuery.getAaiVnfData(vnfId, vnfName); + } catch (CorrelationException e) { + log.error("Failed to get vnf data", e.getMessage()); + } + return vnfEntity; + } + + private VmEntity getVmEntity(String sourceId, String sourceName) { + VmEntity vmEntity = null; + try { + vmEntity = aaiQuery.getAaiVmData(sourceId, sourceName); + } catch (CorrelationException e) { + log.error("Failed to get vm data", e.getMessage()); + } + return vmEntity; + } } diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/aai/config/AaiConfigTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/aai/config/AaiConfigTest.java index bc91f43..6cbc56e 100644 --- a/holmes-actions/src/test/java/org/onap/holmes/common/aai/config/AaiConfigTest.java +++ b/holmes-actions/src/test/java/org/onap/holmes/common/aai/config/AaiConfigTest.java @@ -24,7 +24,7 @@ public class AaiConfigTest { @Test public void testAaiConfig_get_static_fields() { - String aaiVnfAddr = "/aai/v11/network/generic-vnfs/generic-vnf?"; + String aaiVnfAddr = "/aai/v11/network/generic-vnfs/generic-vnf"; String aaiVmAddr = "/aai/v11/search/nodes-query?search-node-type=vserver&filter="; String xTransactionId = "9999"; String xFromAppId = "jimmy-postman"; 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 15b6b80..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 @@ -21,6 +21,7 @@ import static org.junit.Assert.assertThat; import java.util.ArrayList; import java.util.List; +import org.easymock.EasyMock; import org.junit.runner.RunWith; import org.omg.CORBA.Any; import org.onap.holmes.common.aai.AaiQuery; @@ -177,13 +178,14 @@ public class DmaapServiceTest { VesAlarm vesAlarm = new VesAlarm(); vesAlarm.setEventId("11111"); vesAlarm.setEventName("3333"); + vesAlarm.setSourceId("111"); PowerMock.expectPrivate(dmaapService, "getVnfEntity", anyObject(String.class), anyObject(String.class)).andReturn(null).anyTimes(); PowerMock.replayAll(); PolicyMsg actual = Whitebox - .invokeMethod(dmaapService, "getEnrichedPolicyMsg", vmEntity, vesAlarm, "loopName"); + .invokeMethod(dmaapService, "getEnrichedPolicyMsg", vmEntity, vesAlarm, vesAlarm, "loopName"); PowerMock.verifyAll(); assertThat(actual.getClosedLoopControlName(), equalTo(null)); |