aboutsummaryrefslogtreecommitdiffstats
path: root/adapters
diff options
context:
space:
mode:
authorSteve Smokowski <ss835w@att.com>2020-05-21 13:21:57 +0000
committerGerrit Code Review <gerrit@onap.org>2020-05-21 13:21:57 +0000
commita90f0e766ce933d0473d4148269e1caf80a53149 (patch)
tree502d3c7fc3b9cacd0500d98c341b24961cafb948 /adapters
parent49ac4a666b59114844e90117c225e08994c9a94e (diff)
parentb69bec9d271ecffd2b3b172219d53ffab417e253 (diff)
Merge "etsi-sol002-adapter's support for vserver"
Diffstat (limited to 'adapters')
-rw-r--r--adapters/etsi-sol002-adapter/src/main/java/org/onap/so/adapters/vevnfm/aai/AaiConnection.java82
-rw-r--r--adapters/etsi-sol002-adapter/src/main/java/org/onap/so/adapters/vevnfm/event/AaiEvent.java13
-rw-r--r--adapters/etsi-sol002-adapter/src/main/java/org/onap/so/adapters/vevnfm/event/DmaapEvent.java7
-rw-r--r--adapters/etsi-sol002-adapter/src/main/java/org/onap/so/adapters/vevnfm/service/DmaapConditionalSender.java38
-rw-r--r--adapters/etsi-sol002-adapter/src/main/java/org/onap/so/adapters/vevnfm/service/DmaapService.java8
-rw-r--r--adapters/etsi-sol002-adapter/src/test/java/org/onap/so/adapters/vevnfm/aai/AaiConnectionTest.java65
-rw-r--r--adapters/etsi-sol002-adapter/src/test/java/org/onap/so/adapters/vevnfm/service/DmaapConditionalSenderTest.java34
7 files changed, 217 insertions, 30 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();
diff --git a/adapters/etsi-sol002-adapter/src/test/java/org/onap/so/adapters/vevnfm/aai/AaiConnectionTest.java b/adapters/etsi-sol002-adapter/src/test/java/org/onap/so/adapters/vevnfm/aai/AaiConnectionTest.java
new file mode 100644
index 0000000000..12928ae9ed
--- /dev/null
+++ b/adapters/etsi-sol002-adapter/src/test/java/org/onap/so/adapters/vevnfm/aai/AaiConnectionTest.java
@@ -0,0 +1,65 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SO
+ * ================================================================================
+ * Copyright (C) 2020 Samsung. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.adapters.vevnfm.aai;
+
+import static org.junit.Assert.assertEquals;
+import org.junit.Test;
+import org.onap.aai.domain.yang.RelatedToProperty;
+import org.onap.aai.domain.yang.Relationship;
+import org.onap.aai.domain.yang.RelationshipData;
+
+public class AaiConnectionTest {
+
+ private static final String KEY = "key";
+ private static final String VALUE = "value";
+
+ @Test
+ public void testRelationshipData() {
+ // given
+ final Relationship relationship = new Relationship();
+ final RelationshipData data = new RelationshipData();
+ data.setRelationshipKey(KEY);
+ data.setRelationshipValue(VALUE);
+ relationship.getRelationshipData().add(data);
+
+ // when
+ final String value = AaiConnection.getRelationshipData(relationship, KEY);
+
+ // then
+ assertEquals(VALUE, value);
+ }
+
+ @Test
+ public void testRelatedToProperty() {
+ // given
+ final Relationship relationship = new Relationship();
+ final RelatedToProperty property = new RelatedToProperty();
+ property.setPropertyKey(KEY);
+ property.setPropertyValue(VALUE);
+ relationship.getRelatedToProperty().add(property);
+
+ // when
+ final String value = AaiConnection.getRelatedToProperty(relationship, KEY);
+
+ // then
+ assertEquals(VALUE, value);
+ }
+}
diff --git a/adapters/etsi-sol002-adapter/src/test/java/org/onap/so/adapters/vevnfm/service/DmaapConditionalSenderTest.java b/adapters/etsi-sol002-adapter/src/test/java/org/onap/so/adapters/vevnfm/service/DmaapConditionalSenderTest.java
index b430c2bb7a..428ccad054 100644
--- a/adapters/etsi-sol002-adapter/src/test/java/org/onap/so/adapters/vevnfm/service/DmaapConditionalSenderTest.java
+++ b/adapters/etsi-sol002-adapter/src/test/java/org/onap/so/adapters/vevnfm/service/DmaapConditionalSenderTest.java
@@ -22,9 +22,7 @@ package org.onap.so.adapters.vevnfm.service;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.*;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@@ -35,10 +33,12 @@ 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;
@RunWith(MockitoJUnitRunner.class)
public class DmaapConditionalSenderTest {
+ private static final String VSERVER_NAME = "vsn";
private static final String GENERIC_ID = "gener77";
private static final String INSTANCE_ID = "insta44";
private static final String HREF = "/href";
@@ -66,6 +66,10 @@ public class DmaapConditionalSenderTest {
return notification;
}
+ private static DmaapEvent createDmaapEvent() {
+ return new DmaapEvent(null, null, null, null, null);
+ }
+
@Test
public void testSendNone() {
// given
@@ -79,41 +83,52 @@ public class DmaapConditionalSenderTest {
// then
verify(aaiConnection, never()).receiveGenericVnfId(any());
- verify(dmaapService, never()).send(any(), any());
+ verify(dmaapService, never()).createDmaapEvent(any(), any(), any());
+ verify(dmaapService, never()).send(any());
}
@Test
public void testSendAll() {
// given
+ final VnfLcmOperationOccurrenceNotification notification = createNotification();
+ final DmaapEvent dmaapEvent = createDmaapEvent();
+
when(configProperties.getNotificationVnfFilterType()).thenReturn(NotificationVnfFilterType.ALL);
when(aaiConnection.receiveGenericVnfId(eq(HREF))).thenReturn(GENERIC_ID);
+ when(aaiConnection.receiveVserverName(eq(GENERIC_ID))).thenReturn(VSERVER_NAME);
+ when(dmaapService.createDmaapEvent(eq(notification), eq(VSERVER_NAME), eq(GENERIC_ID))).thenReturn(dmaapEvent);
final DmaapConditionalSender sender = new DmaapConditionalSender(configProperties, aaiConnection, dmaapService);
- final VnfLcmOperationOccurrenceNotification notification = createNotification();
// when
sender.send(notification);
// then
verify(aaiConnection).receiveGenericVnfId(eq(HREF));
- verify(dmaapService).send(eq(notification), eq(GENERIC_ID));
+ verify(dmaapService).createDmaapEvent(eq(notification), eq(VSERVER_NAME), eq(GENERIC_ID));
+ verify(dmaapService).send(eq(dmaapEvent));
}
@Test
public void testSendAaiCheckedPresent() {
// given
+ final DmaapEvent dmaapEvent = createDmaapEvent();
+ final VnfLcmOperationOccurrenceNotification notification = createNotification();
+
when(configProperties.getNotificationVnfFilterType()).thenReturn(NotificationVnfFilterType.AAI_CHECKED);
when(aaiConnection.receiveGenericVnfId(eq(HREF))).thenReturn(GENERIC_ID);
+ when(aaiConnection.receiveVserverName(eq(GENERIC_ID))).thenReturn(VSERVER_NAME);
+ when(dmaapService.createDmaapEvent(eq(notification), eq(VSERVER_NAME), eq(GENERIC_ID))).thenReturn(dmaapEvent);
final DmaapConditionalSender sender = new DmaapConditionalSender(configProperties, aaiConnection, dmaapService);
- final VnfLcmOperationOccurrenceNotification notification = createNotification();
// when
sender.send(notification);
// then
verify(aaiConnection).receiveGenericVnfId(eq(HREF));
- verify(dmaapService).send(eq(notification), eq(GENERIC_ID));
+ verify(dmaapService).createDmaapEvent(eq(notification), eq(VSERVER_NAME), eq(GENERIC_ID));
+ verify(dmaapService).send(eq(dmaapEvent));
}
@Test
@@ -130,6 +145,7 @@ public class DmaapConditionalSenderTest {
// then
verify(aaiConnection).receiveGenericVnfId(eq(HREF));
- verify(dmaapService, never()).send(any(), any());
+ verify(dmaapService, never()).createDmaapEvent(any(), any(), any());
+ verify(dmaapService, never()).send(any());
}
}