diff options
Diffstat (limited to 'adapters/etsi-sol002-adapter/src/main/java')
5 files changed, 127 insertions, 21 deletions
diff --git a/adapters/etsi-sol002-adapter/src/main/java/org/onap/so/adapters/vevnfm/aai/AaiConnection.java b/adapters/etsi-sol002-adapter/src/main/java/org/onap/so/adapters/vevnfm/aai/AaiConnection.java index 038b0e44d3..3995185f23 100644 --- a/adapters/etsi-sol002-adapter/src/main/java/org/onap/so/adapters/vevnfm/aai/AaiConnection.java +++ b/adapters/etsi-sol002-adapter/src/main/java/org/onap/so/adapters/vevnfm/aai/AaiConnection.java @@ -26,12 +26,12 @@ import java.util.List; import java.util.Optional; import org.apache.logging.log4j.util.Strings; import org.onap.aai.domain.yang.*; -import org.onap.so.adapters.vevnfm.exception.VeVnfmException; import org.onap.aaiclient.client.aai.AAIObjectType; import org.onap.aaiclient.client.aai.AAIResourcesClient; import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri; import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory; import org.onap.aaiclient.client.graphinventory.entities.uri.Depth; +import org.onap.so.adapters.vevnfm.exception.VeVnfmException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; @@ -40,7 +40,12 @@ import org.springframework.stereotype.Service; public class AaiConnection { private static final Logger logger = LoggerFactory.getLogger(AaiConnection.class); - + private static final String VSERVER = "vserver"; + private static final String CLOUD_OWNER = "cloud-region.cloud-owner"; + private static final String CLOUD_REGION_ID = "cloud-region.cloud-region-id"; + private static final String TENANT_ID = "tenant.tenant-id"; + private static final String VSERVER_ID = "vserver.vserver-id"; + private static final String VSERVER_NAME = "vserver.vserver-name"; private static final String SELFLINK = "selflink"; private static final int FIRST_INDEX = 0; @@ -52,6 +57,30 @@ public class AaiConnection { } } + static String getRelationshipData(final Relationship relationship, final String relationshipDataKey) { + if (relationship != null && relationship.getRelationshipData() != null) { + for (final RelationshipData relationshipData : relationship.getRelationshipData()) { + if (relationshipDataKey.equals(relationshipData.getRelationshipKey())) { + return relationshipData.getRelationshipValue(); + } + } + } + + return null; + } + + static String getRelatedToProperty(final Relationship relationship, final String propertyKey) { + if (relationship != null && relationship.getRelatedToProperty() != null) { + for (final RelatedToProperty relatedToProperty : relationship.getRelatedToProperty()) { + if (propertyKey.equals(relatedToProperty.getPropertyKey())) { + return relatedToProperty.getPropertyValue(); + } + } + } + + return null; + } + private AAIResourcesClient getResourcesClient() { if (resourcesClient == null) { resourcesClient = new AAIResourcesClient(); @@ -125,7 +154,8 @@ public class AaiConnection { final int size = genericVnfList.size(); if (size == 1) { - return genericVnfList.get(FIRST_INDEX).getVnfId(); + final GenericVnf genericVnf = genericVnfList.get(FIRST_INDEX); + return genericVnf.getVnfId(); } else if (size > 1) { logger.warn("more generic vnfs available"); } @@ -133,4 +163,50 @@ public class AaiConnection { return null; } + + public String receiveVserverName(final String genericId) { + final AAIResourceUri resourceUri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, genericId); + final Optional<GenericVnf> response = getResourcesClient().get(GenericVnf.class, resourceUri); + + if (response.isPresent()) { + final GenericVnf genericVnf = response.get(); + final RelationshipList relationshipList = genericVnf.getRelationshipList(); + + if (relationshipList == null || relationshipList.getRelationship() == null) { + return null; + } + + for (final Relationship relationship : relationshipList.getRelationship()) { + if (VSERVER.equals(relationship.getRelatedTo())) { + final String vserverName = getRelatedToProperty(relationship, VSERVER_NAME); + + if (vserverName == null) { + final String cloudOwner = getRelationshipData(relationship, CLOUD_OWNER); + final String cloudId = getRelationshipData(relationship, CLOUD_REGION_ID); + final String tenantId = getRelationshipData(relationship, TENANT_ID); + final String vserverId = getRelationshipData(relationship, VSERVER_ID); + return receiveVserverNameFromParams(cloudOwner, cloudId, tenantId, vserverId); + } + + return vserverName; + } + } + } + + return null; + } + + private String receiveVserverNameFromParams(final String cloudOwner, final String cloudId, final String tenantId, + final String vserverId) { + final AAIResourceUri resourceUri = + AAIUriFactory.createResourceUri(AAIObjectType.VSERVER, cloudOwner, cloudId, tenantId, vserverId); + final Optional<Vserver> response = getResourcesClient().get(Vserver.class, resourceUri); + + if (response.isPresent()) { + final Vserver vserver = response.get(); + return vserver.getVserverName(); + } + + return null; + } } diff --git a/adapters/etsi-sol002-adapter/src/main/java/org/onap/so/adapters/vevnfm/event/AaiEvent.java b/adapters/etsi-sol002-adapter/src/main/java/org/onap/so/adapters/vevnfm/event/AaiEvent.java index ceabb8a020..6c7aaf8f5c 100644 --- a/adapters/etsi-sol002-adapter/src/main/java/org/onap/so/adapters/vevnfm/event/AaiEvent.java +++ b/adapters/etsi-sol002-adapter/src/main/java/org/onap/so/adapters/vevnfm/event/AaiEvent.java @@ -25,11 +25,13 @@ import com.fasterxml.jackson.annotation.JsonProperty; public class AaiEvent { private final boolean vserverIsClosedLoopDisabled; + private final String vserverName; private final String genericVnfVnfId; - public AaiEvent(final boolean cld, final String id) { - this.vserverIsClosedLoopDisabled = cld; - this.genericVnfVnfId = id; + public AaiEvent(final boolean vserverIsClosedLoopDisabled, final String vserverName, final String genericVnfVnfId) { + this.vserverIsClosedLoopDisabled = vserverIsClosedLoopDisabled; + this.vserverName = vserverName; + this.genericVnfVnfId = genericVnfVnfId; } @JsonProperty("vserver.is-closed-loop-disabled") @@ -37,6 +39,11 @@ public class AaiEvent { return vserverIsClosedLoopDisabled; } + @JsonProperty("vserver.vserver-name") + public String getVserverName() { + return vserverName; + } + @JsonProperty("generic-vnf.vnf-id") public String getGenericVnfVnfId() { return genericVnfVnfId; diff --git a/adapters/etsi-sol002-adapter/src/main/java/org/onap/so/adapters/vevnfm/event/DmaapEvent.java b/adapters/etsi-sol002-adapter/src/main/java/org/onap/so/adapters/vevnfm/event/DmaapEvent.java index 142c6b0399..55a36a5d85 100644 --- a/adapters/etsi-sol002-adapter/src/main/java/org/onap/so/adapters/vevnfm/event/DmaapEvent.java +++ b/adapters/etsi-sol002-adapter/src/main/java/org/onap/so/adapters/vevnfm/event/DmaapEvent.java @@ -21,10 +21,10 @@ package org.onap.so.adapters.vevnfm.event; import static java.time.temporal.ChronoField.INSTANT_SECONDS; +import com.fasterxml.jackson.annotation.JsonProperty; import java.time.Instant; import java.util.UUID; import org.onap.so.adapters.etsisol003adapter.lcm.lcn.model.VnfLcmOperationOccurrenceNotification; -import com.fasterxml.jackson.annotation.JsonProperty; public class DmaapEvent { @@ -47,7 +47,8 @@ public class DmaapEvent { private final VnfLcmOperationOccurrenceNotification etsiLcmEvent; public DmaapEvent(final String closedLoopControlName, final String version, - final VnfLcmOperationOccurrenceNotification etsiLcmEvent, final String genericId) { + final VnfLcmOperationOccurrenceNotification etsiLcmEvent, final String vserverName, + final String genericId) { this.closedLoopControlName = closedLoopControlName; this.closedLoopAlarmStart = Instant.now().getLong(INSTANT_SECONDS); this.closedLoopEventClient = MSERVICE; @@ -55,7 +56,7 @@ public class DmaapEvent { this.requestId = UUID.randomUUID().toString(); this.targetType = VNF; this.target = VNFID; - this.aaiEvent = (genericId == null) ? null : new AaiEvent(false, genericId); + this.aaiEvent = (genericId == null) ? null : new AaiEvent(false, vserverName, genericId); this.from = ETSI; this.version = version; this.etsiLcmEvent = etsiLcmEvent; diff --git a/adapters/etsi-sol002-adapter/src/main/java/org/onap/so/adapters/vevnfm/service/DmaapConditionalSender.java b/adapters/etsi-sol002-adapter/src/main/java/org/onap/so/adapters/vevnfm/service/DmaapConditionalSender.java index bb1d26f523..13cc5d3a1e 100644 --- a/adapters/etsi-sol002-adapter/src/main/java/org/onap/so/adapters/vevnfm/service/DmaapConditionalSender.java +++ b/adapters/etsi-sol002-adapter/src/main/java/org/onap/so/adapters/vevnfm/service/DmaapConditionalSender.java @@ -25,6 +25,7 @@ import org.onap.so.adapters.etsisol003adapter.lcm.lcn.model.VnfLcmOperationOccur import org.onap.so.adapters.vevnfm.aai.AaiConnection; import org.onap.so.adapters.vevnfm.configuration.ConfigProperties; import org.onap.so.adapters.vevnfm.constant.NotificationVnfFilterType; +import org.onap.so.adapters.vevnfm.event.DmaapEvent; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; @@ -47,19 +48,14 @@ public class DmaapConditionalSender { public void send(final VnfLcmOperationOccurrenceNotification notification) { final String href = notification.getLinks().getVnfInstance().getHref(); - boolean logSent = false; + DmaapEvent dmaapEvent = null; switch (notificationVnfFilterType) { case ALL: - dmaapService.send(notification, aaiConnection.receiveGenericVnfId(href)); - logSent = true; + dmaapEvent = conditionalSend(true, notification, href); break; case AAI_CHECKED: - final String genericId = aaiConnection.receiveGenericVnfId(href); - if (Strings.isNotBlank(genericId)) { - dmaapService.send(notification, genericId); - logSent = true; - } + dmaapEvent = conditionalSend(false, notification, href); break; case NONE: break; @@ -69,7 +65,29 @@ public class DmaapConditionalSender { } final String vnfInstanceId = notification.getVnfInstanceId(); - final String not = logSent ? "" : "not "; - logger.info("The info with the VNF id '{}' is " + not + "sent to DMaaP", vnfInstanceId); + + if (dmaapEvent == null) { + logger.info("The info with the VNF id '{}' is not sent to DMaaP", vnfInstanceId); + } else { + dmaapService.send(dmaapEvent); + logger.info("The info with the VNF id '{}' is sent to DMaaP", vnfInstanceId); + } + } + + private DmaapEvent conditionalSend(final boolean allowAll, final VnfLcmOperationOccurrenceNotification notification, + final String href) { + final String genericId = aaiConnection.receiveGenericVnfId(href); + final boolean idNotBlank = Strings.isNotBlank(genericId); + String vserverName = null; + + if (idNotBlank) { + vserverName = aaiConnection.receiveVserverName(genericId); + } + + if (allowAll || idNotBlank) { + return dmaapService.createDmaapEvent(notification, vserverName, genericId); + } + + return null; } } diff --git a/adapters/etsi-sol002-adapter/src/main/java/org/onap/so/adapters/vevnfm/service/DmaapService.java b/adapters/etsi-sol002-adapter/src/main/java/org/onap/so/adapters/vevnfm/service/DmaapService.java index 4319d78d39..435e8e0593 100644 --- a/adapters/etsi-sol002-adapter/src/main/java/org/onap/so/adapters/vevnfm/service/DmaapService.java +++ b/adapters/etsi-sol002-adapter/src/main/java/org/onap/so/adapters/vevnfm/service/DmaapService.java @@ -51,9 +51,13 @@ public class DmaapService { this.restProvider = restProvider; } - public void send(final VnfLcmOperationOccurrenceNotification notification, final String genericId) { + public DmaapEvent createDmaapEvent(final VnfLcmOperationOccurrenceNotification notification, + final String vserverName, final String genericId) { + return new DmaapEvent(closedLoopControlName, version, notification, vserverName, genericId); + } + + public void send(final DmaapEvent event) { try { - final DmaapEvent event = new DmaapEvent(closedLoopControlName, version, notification, genericId); final ResponseEntity<String> response = restProvider.postHttpRequest(event, getUrl(), String.class); final HttpStatus statusCode = response.getStatusCode(); final String body = response.getBody(); |