diff options
author | Shiwei Tian <tian.shiwei@zte.com.cn> | 2017-10-26 16:24:17 +0800 |
---|---|---|
committer | Shiwei Tian <tian.shiwei@zte.com.cn> | 2017-10-26 21:42:08 +0800 |
commit | 3e52d0c33f6a7db4e81ebecc50623cd449c624ba (patch) | |
tree | 963fa40f2fe2816d30c3d38ea14488e14379660a /holmes-actions/src | |
parent | 80aa5b49e5e3fb696231ce66acf198ff50d74731 (diff) |
modify vnf enriched
Issue-ID: HOLMES-71
Change-Id: I3f451df7e95c1ed9d72e9680f16255bc78c8fa36
Signed-off-by: Shiwei Tian <tian.shiwei@zte.com.cn>
Diffstat (limited to 'holmes-actions/src')
4 files changed, 133 insertions, 57 deletions
diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/aai/entity/RelationshipList.java b/holmes-actions/src/main/java/org/onap/holmes/common/aai/entity/RelationshipList.java index 8711e2c..533760c 100644 --- a/holmes-actions/src/main/java/org/onap/holmes/common/aai/entity/RelationshipList.java +++ b/holmes-actions/src/main/java/org/onap/holmes/common/aai/entity/RelationshipList.java @@ -26,6 +26,19 @@ public class RelationshipList { private List<Relationship> relationships; + public Relationship getRelationship(String relatedTo) { + Relationship relationship = null; + if(null == relationships || relationships.size() == 0) + return relationship; + for(int i = 0; i < relationships.size(); i++) { + if (relatedTo.equals(relationships.get(i).getRelatedTo())) { + relationship = relationships.get(i); + break; + } + } + return relationship; + } + @Setter @Getter public static class Relationship { @@ -33,6 +46,34 @@ public class RelationshipList { private String relatedTo; private List<RelatedToProperty> relatedToPropertyList; private List<RelationshipData> relationshipDataList; + + public String getRelatedToPropertyValue(String key) { + String value = ""; + if (null == relatedToPropertyList || relatedToPropertyList.size() == 0) { + return ""; + } + for(int i = 0; i < relatedToPropertyList.size(); i++) { + if (key.equals(relatedToPropertyList.get(i).getPropertyKey())) { + value = relatedToPropertyList.get(i).getPropertyValue(); + break; + } + } + return value; + } + + public String getRelationshipDataValue(String key) { + String value = ""; + if (null == relationshipDataList || relationshipDataList.size() == 0) { + return ""; + } + for(int i = 0; i < relationshipDataList.size(); i++) { + if (key.equals(relationshipDataList.get(i).getRelationshipKey())) { + value = relationshipDataList.get(i).getRelationshipValue(); + break; + } + } + return value; + } } @Setter 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 fc79539..300201f 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 @@ -16,7 +16,6 @@ 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; @@ -25,7 +24,6 @@ import lombok.extern.slf4j.Slf4j; import org.jvnet.hk2.annotations.Service; 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; @@ -38,9 +36,7 @@ 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<>(); @@ -49,7 +45,8 @@ public class DmaapService { public void publishPolicyMsg(PolicyMsg policyMsg, String dmaapConfigKey) { try { Publisher publisher = new Publisher(); - publisher.setUrl(DcaeConfigurationsCache.getPubSecInfo(dmaapConfigKey).getDmaapInfo().getTopicUrl()); + publisher.setUrl(DcaeConfigurationsCache.getPubSecInfo(dmaapConfigKey).getDmaapInfo() + .getTopicUrl()); publisher.publish(policyMsg); log.info("send policyMsg: " + JacksonUtil.beanToJson(policyMsg)); } catch (CorrelationException e) { @@ -67,58 +64,25 @@ public class DmaapService { .orElse(getDefaultPolicyMsg(rootAlarm.getSourceName())); } - private String getVserverInstanceId(VnfEntity vnfEntity) { - String vserverInstanceId = ""; - if (vnfEntity != null) { - 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())) { - relationship = relationshipList.get(i); - break; - } - } - if (relationship != null) { - List<RelationshipData> relationshipDataList = relationship.getRelationshipDataList(); - for(int i = 0; i < relationshipDataList.size(); i++) { - if (SERVICE_INSTANCE_ID - .equals(relationshipDataList.get(i).getRelationshipKey())) { - vserverInstanceId = relationshipDataList.get(i).getRelationshipValue(); - break; - } - } - } - } - return vserverInstanceId; - } - 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.setRequestID(getUniqueRequestId(rootAlarm, policyMsg)); + if (rootAlarm.getAlarmIsCleared() == PolicyMassgeConstant.POLICY_MESSAGE_ONSET) { + enrichVnfInfo(vmEntity, childAlarm, policyMsg); policyMsg.setClosedLoopEventStatus(EVENT_STATUS.ONSET); - enrichVnfInfo(childAlarm, policyMsg); - alarmUniqueKey = rootAlarm.getSourceId() + ":" + rootAlarm.getEventName(); - } - if (alarmUniqueRequestID.containsKey(alarmUniqueKey)) { - policyMsg.setRequestID(alarmUniqueRequestID.get(alarmUniqueKey)); + policyMsg.setTarget("vserver.vserver-id"); + 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()); } else { - String requestID = UUID.randomUUID().toString(); - policyMsg.setRequestID(requestID); - alarmUniqueRequestID.put(alarmUniqueKey, requestID); + policyMsg.setClosedLoopAlarmEnd(rootAlarm.getLastEpochMicrosec()); + policyMsg.setClosedLoopEventStatus(EVENT_STATUS.ABATED); } 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", - String.valueOf(vmEntity.getClosedLoopDisable())); - policyMsg.getAai().put("vserver.prov-status", vmEntity.getProvStatus()); - policyMsg.getAai().put("vserver.resource-version", vmEntity.getResourceVersion()); + policyMsg.setClosedLoopAlarmStart(rootAlarm.getStartEpochMicrosec()); policyMsg.getAai().put("vserver.vserver-id", vmEntity.getVserverId()); policyMsg.getAai().put("vserver.vserver-name", vmEntity.getVserverName()); policyMsg.getAai().put("vserver.vserver-name2", vmEntity.getVserverName2()); @@ -128,20 +92,64 @@ public class DmaapService { private PolicyMsg getDefaultPolicyMsg(String sourceName) { PolicyMsg policyMsg = new PolicyMsg(); - policyMsg.setTarget("vserver.vserver-name"); + policyMsg.setTarget("vserver.vserver-id"); policyMsg.setTargetType("VM"); policyMsg.getAai().put("vserver.vserver-name", sourceName); return policyMsg; } - private void enrichVnfInfo(VesAlarm childAlarm, PolicyMsg policyMsg) { - VnfEntity vnfEntity = getVnfEntity(childAlarm.getSourceId(), childAlarm.getSourceName()); + private String getUniqueRequestId(VesAlarm rootAlarm, PolicyMsg policyMsg) { + String alarmUniqueKey = ""; + if (rootAlarm.getAlarmIsCleared() == PolicyMassgeConstant.POLICY_MESSAGE_ABATED) { + alarmUniqueKey = + rootAlarm.getSourceId() + ":" + rootAlarm.getEventName().replace("Cleared", ""); + } else { + alarmUniqueKey = rootAlarm.getSourceId() + ":" + rootAlarm.getEventName(); + } + if (alarmUniqueRequestID.containsKey(alarmUniqueKey)) { + return alarmUniqueRequestID.get(alarmUniqueKey); + } else { + String requestID = UUID.randomUUID().toString(); + alarmUniqueRequestID.put(alarmUniqueKey, requestID); + return requestID; + } + } + + private void enrichVnfInfo(VmEntity vmEntity, VesAlarm childAlarm, PolicyMsg policyMsg) { + String vnfId = ""; + String vnfName = ""; + if (null != childAlarm) { + vnfId = childAlarm.getSourceId(); + vnfName = childAlarm.getSourceName(); + } else { + Relationship relationship = vmEntity.getRelationshipList() + .getRelationship(PolicyMassgeConstant.GENERIC_VNF); + if (null != relationship) { + vnfId = relationship.getRelationshipDataValue(PolicyMassgeConstant.GENERIC_VNF_VNF_ID); + vnfName = relationship.getRelatedToPropertyValue(PolicyMassgeConstant.GENERIC_VNF_VNF_NAME); + } + } + VnfEntity vnfEntity = getVnfEntity(vnfId, vnfName); 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.vnf-id", vnfId); policyMsg.getAai().put("generic-vnf.service-instance-id", vserverInstatnceId); } + + private String getVserverInstanceId(VnfEntity vnfEntity) { + String vserverInstanceId = ""; + if (vnfEntity != null) { + Relationship relationship = vnfEntity.getRelationshipList() + .getRelationship(PolicyMassgeConstant.SERVICE_INSTANCE); + if (relationship == null) { + return vserverInstanceId; + } + vserverInstanceId = relationship + .getRelationshipDataValue(PolicyMassgeConstant.SERVICE_INSTANCE_ID); + } + return vserverInstanceId; + } + private VnfEntity getVnfEntity(String vnfId, String vnfName) { VnfEntity vnfEntity = null; try { diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/PolicyMassgeConstant.java b/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/PolicyMassgeConstant.java new file mode 100644 index 0000000..f67336e --- /dev/null +++ b/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/PolicyMassgeConstant.java @@ -0,0 +1,26 @@ +/* + * Copyright 2017 ZTE Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.holmes.common.dmaap; + +public class PolicyMassgeConstant { + public static final int POLICY_MESSAGE_ONSET = 0; + 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"; + public static final String GENERIC_VNF = "generic-vnf"; + public static final String GENERIC_VNF_VNF_ID = "generic-vnf.vnf-id"; + public static final String GENERIC_VNF_VNF_NAME = "generic-vnf.vnf-name"; +} 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 3f61813..5099fba 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 @@ -70,7 +70,7 @@ public class DmaapServiceTest { .invokeMethod(dmaapService, "getDefaultPolicyMsg", "tetss"); PowerMock.verifyAll(); - assertThat(policyMsg.getTarget(), equalTo("vserver.vserver-name")); + assertThat(policyMsg.getTarget(), equalTo("vserver.vserver-id")); assertThat(policyMsg.getTargetType(), equalTo("VM")); assertThat(policyMsg.getAai().get("vserver.vserver-name"), equalTo("tetss")); } @@ -179,6 +179,7 @@ public class DmaapServiceTest { vesAlarm.setEventId("11111"); vesAlarm.setEventName("3333"); vesAlarm.setSourceId("111"); + vesAlarm.setStartEpochMicrosec(11111L); PowerMock.expectPrivate(dmaapService, "getVnfEntity", anyObject(String.class), anyObject(String.class)).andReturn(null).anyTimes(); |