diff options
21 files changed, 482 insertions, 71 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()); } } diff --git a/adapters/mso-adapter-utils/pom.xml b/adapters/mso-adapter-utils/pom.xml index b8dec73f80..a121d2d89b 100644 --- a/adapters/mso-adapter-utils/pom.xml +++ b/adapters/mso-adapter-utils/pom.xml @@ -152,5 +152,13 @@ <artifactId>mso-requests-db</artifactId> <version>${project.version}</version> </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-cache</artifactId> + </dependency> + <dependency> + <groupId>com.github.ben-manes.caffeine</groupId> + <artifactId>caffeine</artifactId> + </dependency> </dependencies> </project> diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/NovaCacheConfig.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/NovaCacheConfig.java new file mode 100644 index 0000000000..2f7d19ff1d --- /dev/null +++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/NovaCacheConfig.java @@ -0,0 +1,42 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 AT&T Intellectual Property. 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.openstack.utils; + +import java.util.concurrent.TimeUnit; +import org.springframework.cache.CacheManager; +import org.springframework.cache.caffeine.CaffeineCacheManager; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import com.github.benmanes.caffeine.cache.Caffeine; + +@Configuration +public class NovaCacheConfig { + + @Bean + public CacheManager cacheManager() { + CaffeineCacheManager cacheManager = new CaffeineCacheManager("novaClient"); + cacheManager.setCaffeine(caffeineCacheBuilder()); + return cacheManager; + } + + private Caffeine<Object, Object> caffeineCacheBuilder() { + return Caffeine.newBuilder().initialCapacity(100).maximumSize(500).expireAfterWrite(90, TimeUnit.MINUTES); + } +} diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/NovaClient.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/NovaClient.java new file mode 100644 index 0000000000..c5eeb34157 --- /dev/null +++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/NovaClient.java @@ -0,0 +1,52 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 AT&T Intellectual Property. 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.openstack.utils; + +import org.onap.so.cloud.authentication.KeystoneAuthHolder; +import org.onap.so.openstack.exceptions.MsoException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.cache.annotation.Cacheable; +import org.springframework.stereotype.Component; +import com.woorea.openstack.nova.Nova; + + +@Component +public class NovaClient extends MsoCommonUtils { + + private static final Logger logger = LoggerFactory.getLogger(NovaClient.class); + + /** + * Gets the Nova client + * + * @param cloudSiteId id of the cloud site + * @param tenantId the tenant id + * @return the Nova client + * @throws MsoException the mso exception + */ + @Cacheable(value = "novaClient") + public Nova getNovaClient(String cloudSiteId, String tenantId) throws MsoException { + KeystoneAuthHolder keystone = getKeystoneAuthHolder(cloudSiteId, tenantId, "compute"); + Nova novaClient = new Nova(keystone.getServiceUrl()); + novaClient.token(keystone.getId()); + return novaClient; + } +} diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/NovaClientImpl.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/NovaClientImpl.java index 5d28eaaf71..dc276d9b8f 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/NovaClientImpl.java +++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/NovaClientImpl.java @@ -21,11 +21,11 @@ package org.onap.so.openstack.utils; import java.io.IOException; -import org.onap.so.cloud.authentication.KeystoneAuthHolder; import org.onap.so.openstack.exceptions.MsoCloudSiteNotFound; import org.onap.so.openstack.exceptions.MsoException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; @@ -50,21 +50,8 @@ public class NovaClientImpl extends MsoCommonUtils { /** The logger. */ private static final Logger logger = LoggerFactory.getLogger(NovaClientImpl.class); - /** - * Gets the Nova client - * - * @param cloudSiteId id of the cloud site - * @param tenantId the tenant id - * @return the Nova client - * @throws MsoException the mso exception - */ - private Nova getNovaClient(String cloudSiteId, String tenantId) throws MsoException { - KeystoneAuthHolder keystone = getKeystoneAuthHolder(cloudSiteId, tenantId, "compute"); - Nova novaClient = new Nova(keystone.getServiceUrl()); - novaClient.token(keystone.getId()); - return novaClient; - } - + @Autowired + private NovaClient client; /** * Query Networks @@ -83,7 +70,7 @@ public class NovaClientImpl extends MsoCommonUtils { public Flavors queryFlavors(String cloudSiteId, String tenantId, int limit, String marker) throws MsoCloudSiteNotFound, NovaClientException { try { - Nova novaClient = getNovaClient(cloudSiteId, tenantId); + Nova novaClient = client.getNovaClient(cloudSiteId, tenantId); OpenStackRequest<Flavors> request = novaClient.flavors().list(false).queryParam("limit", limit).queryParam("marker", marker); return executeAndRecordOpenstackRequest(request, false); @@ -108,8 +95,7 @@ public class NovaClientImpl extends MsoCommonUtils { public Flavor queryFlavorById(String cloudSiteId, String tenantId, String id) throws MsoCloudSiteNotFound, NovaClientException { try { - Nova novaClient = getNovaClient(cloudSiteId, tenantId); - novaClient = getNovaClient(cloudSiteId, tenantId); + Nova novaClient = client.getNovaClient(cloudSiteId, tenantId); OpenStackRequest<Flavor> request = novaClient.flavors().show(id); return executeAndRecordOpenstackRequest(request, false); } catch (MsoException e) { @@ -133,7 +119,7 @@ public class NovaClientImpl extends MsoCommonUtils { public HostAggregates queryHostAggregates(String cloudSiteId, String tenantId, int limit, String marker) throws MsoCloudSiteNotFound, NovaClientException { try { - Nova novaClient = getNovaClient(cloudSiteId, tenantId); + Nova novaClient = client.getNovaClient(cloudSiteId, tenantId); OpenStackRequest<HostAggregates> request = novaClient.aggregates().list().queryParam("limit", limit).queryParam("marker", marker); return executeAndRecordOpenstackRequest(request, false); @@ -158,7 +144,7 @@ public class NovaClientImpl extends MsoCommonUtils { public HostAggregate queryHostAggregateById(String cloudSiteId, String tenantId, String id) throws MsoCloudSiteNotFound, NovaClientException { try { - Nova novaClient = getNovaClient(cloudSiteId, tenantId); + Nova novaClient = client.getNovaClient(cloudSiteId, tenantId); OpenStackRequest<HostAggregate> request = novaClient.aggregates().showAggregate(id); return executeAndRecordOpenstackRequest(request, false); } catch (MsoException e) { @@ -182,7 +168,7 @@ public class NovaClientImpl extends MsoCommonUtils { public QuotaSet queryOSQuotaSet(String cloudSiteId, String tenantId) throws MsoCloudSiteNotFound, NovaClientException { try { - Nova novaClient = getNovaClient(cloudSiteId, tenantId); + Nova novaClient = client.getNovaClient(cloudSiteId, tenantId); OpenStackRequest<QuotaSet> request = novaClient.quotaSets().showQuota(tenantId); return executeAndRecordOpenstackRequest(request, false); } catch (MsoException e) { @@ -204,7 +190,7 @@ public class NovaClientImpl extends MsoCommonUtils { public void deleteKeyPair(String cloudSiteId, String tenantId, String keyPairName) throws MsoCloudSiteNotFound, NovaClientException { try { - Nova novaClient = getNovaClient(cloudSiteId, tenantId); + Nova novaClient = client.getNovaClient(cloudSiteId, tenantId); OpenStackRequest<Void> request = novaClient.keyPairs().delete(keyPairName); executeAndRecordOpenstackRequest(request, false); } catch (MsoException e) { @@ -215,7 +201,7 @@ public class NovaClientImpl extends MsoCommonUtils { public Server queryServerById(String cloudSiteId, String tenantId, String id) throws NovaClientException { try { - Nova novaClient = getNovaClient(cloudSiteId, tenantId); + Nova novaClient = client.getNovaClient(cloudSiteId, tenantId); OpenStackRequest<Server> request = novaClient.servers().show(id); return executeAndRecordOpenstackRequest(request, false); } catch (MsoException e) { @@ -230,7 +216,7 @@ public class NovaClientImpl extends MsoCommonUtils { JsonNode actualObj = mapper.readTree(request); Entity<JsonNode> openstackEntity = new Entity<>(actualObj, "application/json"); CharSequence actionPath = "/servers/" + id + "/action"; - Nova novaClient = getNovaClient(cloudSiteId, tenantId); + Nova novaClient = client.getNovaClient(cloudSiteId, tenantId); OpenStackRequest<Void> OSRequest = new OpenStackRequest<>(novaClient, HttpMethod.POST, actionPath, openstackEntity, Void.class); executeAndRecordOpenstackRequest(OSRequest, false); @@ -240,7 +226,7 @@ public class NovaClientImpl extends MsoCommonUtils { throws NovaClientException { Nova novaClient; try { - novaClient = getNovaClient(cloudSiteId, tenantId); + novaClient = client.getNovaClient(cloudSiteId, tenantId); OpenStackRequest<Void> request = novaClient.servers().attachVolume(serverId, volumeAttachment.getVolumeId(), volumeAttachment.getDevice()); executeAndRecordOpenstackRequest(request, false); @@ -254,7 +240,7 @@ public class NovaClientImpl extends MsoCommonUtils { throws NovaClientException { Nova novaClient; try { - novaClient = getNovaClient(cloudSiteId, tenantId); + novaClient = client.getNovaClient(cloudSiteId, tenantId); OpenStackRequest<Void> request = novaClient.servers().detachVolume(serverId, volumeId); executeAndRecordOpenstackRequest(request, false); } catch (MsoException e) { @@ -266,7 +252,7 @@ public class NovaClientImpl extends MsoCommonUtils { public Hypervisors getHypervisorDetails(String cloudSiteId, String tenantId) throws NovaClientException { Nova novaClient; try { - novaClient = getNovaClient(cloudSiteId, tenantId); + novaClient = client.getNovaClient(cloudSiteId, tenantId); OpenStackRequest<Hypervisors> request = novaClient.hypervisors().listDetail(); return executeAndRecordOpenstackRequest(request, false); } catch (MsoException e) { diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/CreateCommunicationService.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/CreateCommunicationService.groovy index 89c3ab7c8b..12cd0dde0b 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/CreateCommunicationService.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/CreateCommunicationService.groovy @@ -293,11 +293,11 @@ class CreateCommunicationService extends AbstractServiceTaskProcessor { //2. profile info - Integer expDataRateDL = jsonUtil.getJsonIntValue(uuiRequest, "service.parameters.requestInputs.expDataRateDL") - Integer expDataRateUL = jsonUtil.getJsonIntValue(uuiRequest, "service.parameters.requestInputs.expDataRateUL") - Integer latency = jsonUtil.getJsonIntValue(uuiRequest, "service.parameters.requestInputs.latency") - Integer maxNumberOfUEs = jsonUtil.getJsonIntValue(uuiRequest, "service.parameters.requestInputs.maxNumberofUEs") - String uEMobilityLevel = jsonUtil.getJsonValue(uuiRequest, "service.parameters.requestInputs.uemobilityLevel") + Integer expDataRateDL = jsonUtil.getJsonValue(uuiRequest, "service.parameters.requestInputs.expDataRateDL") as Integer + Integer expDataRateUL = jsonUtil.getJsonValue(uuiRequest, "service.parameters.requestInputs.expDataRateUL") as Integer + Integer latency = jsonUtil.getJsonValue(uuiRequest, "service.parameters.requestInputs.latency") as Integer + Integer maxNumberOfUEs = jsonUtil.getJsonValue(uuiRequest, "service.parameters.requestInputs.maxNumberofUEs") as Integer + String uEMobilityLevel = jsonUtil.getJsonValue(uuiRequest, "service.parameters.requestInputs.uEMobilityLevel") String resourceSharingLevel = jsonUtil.getJsonValue(uuiRequest, "service.parameters.requestInputs.resourceSharingLevel") String coverageArea = jsonUtil.getJsonValue(uuiRequest, "service.parameters.requestInputs.coverageAreaList") diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIPnfResources.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIPnfResources.java index b8562ba6b5..7184bba377 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIPnfResources.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIPnfResources.java @@ -22,6 +22,9 @@ package org.onap.so.client.orchestration; import com.google.common.base.Strings; import java.util.Optional; +import org.onap.aai.domain.yang.RelatedToProperty; +import org.onap.aai.domain.yang.Relationship; +import org.onap.aai.domain.yang.RelationshipData; import org.onap.so.bpmn.common.InjectionHelper; import org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf; import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; @@ -68,8 +71,15 @@ public class AAIPnfResources { public void checkIfPnfExistsInAaiAndCanBeUsed(String pnfName) throws Exception { Optional<org.onap.aai.domain.yang.Pnf> pnfFromAai = injectionHelper.getAaiClient() .get(org.onap.aai.domain.yang.Pnf.class, AAIUriFactory.createResourceUri(AAIObjectType.PNF, pnfName)); - if (pnfFromAai.isPresent() && isOrchestrationStatusSet(pnfFromAai.get())) { - checkOrchestrationStatusOfExistingPnf(pnfFromAai.get()); + if (pnfFromAai.isPresent()) { + checkIfPnfCanBeUsed(pnfFromAai.get()); + } + } + + private void checkIfPnfCanBeUsed(org.onap.aai.domain.yang.Pnf pnfFromAai) throws Exception { + isRelatedToService(pnfFromAai); + if (isOrchestrationStatusSet(pnfFromAai)) { + checkOrchestrationStatusOfExistingPnf(pnfFromAai); } } @@ -92,7 +102,39 @@ public class AAIPnfResources { pnfFromAai.getPnfName(), pnfFromAai.getOrchestrationStatus()); logger.error(errorMessage); throw new Exception(errorMessage); + } + } + private void isRelatedToService(org.onap.aai.domain.yang.Pnf pnfFromAai) throws Exception { + if (pnfFromAai.getRelationshipList() != null) { + for (Relationship relationship : pnfFromAai.getRelationshipList().getRelationship()) { + if (relationship.getRelatedTo().equals("service-instance")) { + String errorMessage = prepareRelationErrorMessage(pnfFromAai, relationship); + logger.error(errorMessage); + throw new Exception(errorMessage); + } + } + } + } + + private String prepareRelationErrorMessage(org.onap.aai.domain.yang.Pnf pnfFromAai, Relationship relationship) { + String serviceInstanceName = ""; + String serviceInstanceId = ""; + + for (RelationshipData relationshipData : relationship.getRelationshipData()) { + if (relationshipData.getRelationshipKey().equals("service-instance.service-instance-id")) { + serviceInstanceId = relationshipData.getRelationshipValue(); + break; + } + } + for (RelatedToProperty relatedToProperty : relationship.getRelatedToProperty()) { + if (relatedToProperty.getPropertyKey().equals("service-instance.service-instance-name")) { + serviceInstanceName = relatedToProperty.getPropertyValue(); + break; + } } + return String.format( + "Pnf with name %s exist with orchestration status %s and is related to %s service with certain service-instance-id: %s", + pnfFromAai.getPnfName(), pnfFromAai.getOrchestrationStatus(), serviceInstanceName, serviceInstanceId); } } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIPnfResourcesTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIPnfResourcesTest.java index 15c4b48d66..5e9b4c7592 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIPnfResourcesTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIPnfResourcesTest.java @@ -29,7 +29,10 @@ import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import java.io.File; +import java.io.IOException; import java.util.Optional; +import com.fasterxml.jackson.databind.ObjectMapper; import joptsimple.internal.Strings; import org.junit.Before; import org.junit.Test; @@ -151,6 +154,27 @@ public class AAIPnfResourcesTest extends TestDataSetup { } } + @Test + public void existingPnfInAaiIsRelatedToService() throws IOException { + // given + final String relatedTo = "service-instance"; + final String serviceInstanceId = "service-instance-id"; + final String path = "src/test/resources/__files/BuildingBlocks/aaiPnf.json"; + org.onap.aai.domain.yang.Pnf pnfFromAai = + new ObjectMapper().readValue(new File(path), org.onap.aai.domain.yang.Pnf.class); + when(injectionHelperMock.getAaiClient().get(org.onap.aai.domain.yang.Pnf.class, + AAIUriFactory.createResourceUri(AAIObjectType.PNF, PNF_NAME))).thenReturn(Optional.of(pnfFromAai)); + // when + try { + testedObject.checkIfPnfExistsInAaiAndCanBeUsed(PNF_NAME); + } catch (Exception e) { + // then + assertThat(e.getMessage()).isEqualTo(String.format( + "Pnf with name %s exist with orchestration status %s and is related to %s service with certain service-instance-id: %s", + PNF_NAME, OrchestrationStatus.ACTIVE, relatedTo, serviceInstanceId)); + } + } + private org.onap.aai.domain.yang.Pnf createPnf(String orchestrationStatus) { org.onap.aai.domain.yang.Pnf pnfFromAai = new org.onap.aai.domain.yang.Pnf(); pnfFromAai.setPnfName(PNF_NAME); diff --git a/bpmn/so-bpmn-tasks/src/test/resources/__files/BuildingBlocks/aaiPnf.json b/bpmn/so-bpmn-tasks/src/test/resources/__files/BuildingBlocks/aaiPnf.json new file mode 100644 index 0000000000..c4600d94a0 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/resources/__files/BuildingBlocks/aaiPnf.json @@ -0,0 +1,31 @@ +{ + "pnfName": "pnfTest", + "pnfId": "pnfId", + "orchestrationStatus": "Active", + "resourceVersion": "resourceVersion", + "relationshipList": { + "relationship": [ + { + "relatedTo": "service-instance", + "relationshipLabel": "org.onap.relationships.inventory.ComposedOf", + "relatedLink": "relatedLink", + "relationshipData": [ + { + "relationshipKey": "relationshipKey", + "relationshipValue": "relationshipValue" + }, + { + "relationshipKey": "service-instance.service-instance-id", + "relationshipValue": "service-instance-id" + } + ], + "relatedToProperty": [ + { + "propertyKey": "service-instance.service-instance-name", + "propertyValue": "service-instance" + } + ] + } + ] + } +} diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/NetworkDeleteValidator.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/NetworkDeleteValidator.java index f75897dda1..89c5cbed9b 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/NetworkDeleteValidator.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/NetworkDeleteValidator.java @@ -8,8 +8,9 @@ import org.onap.so.apihandlerinfra.Actions; import org.onap.so.apihandlerinfra.infra.rest.AAIDataRetrieval; import org.onap.so.serviceinstancebeans.ServiceInstancesRequest; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; - +@Component public class NetworkDeleteValidator implements RequestValidator { @Autowired diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/RequestValidator.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/RequestValidator.java index 1dea57ad9c..50938e6826 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/RequestValidator.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/RequestValidator.java @@ -24,7 +24,9 @@ import java.util.Map; import java.util.Optional; import org.onap.so.apihandlerinfra.Actions; import org.onap.so.serviceinstancebeans.ServiceInstancesRequest; +import org.springframework.stereotype.Component; +@Component public interface RequestValidator { diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/ServiceInstanceDeleteValidator.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/ServiceInstanceDeleteValidator.java index 61f757ba64..843d94ce6c 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/ServiceInstanceDeleteValidator.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/ServiceInstanceDeleteValidator.java @@ -8,8 +8,10 @@ import org.onap.so.apihandlerinfra.Actions; import org.onap.so.apihandlerinfra.infra.rest.AAIDataRetrieval; import org.onap.so.serviceinstancebeans.ServiceInstancesRequest; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +@Component public class ServiceInstanceDeleteValidator implements RequestValidator { @Autowired @@ -17,8 +19,17 @@ public class ServiceInstanceDeleteValidator implements RequestValidator { @Override public boolean shouldRunFor(String requestUri, ServiceInstancesRequest request, Actions action) { + boolean isALaCarte = false; + if (request.getRequestDetails() != null && request.getRequestDetails().getRequestParameters() != null) { + if (request.getRequestDetails().getRequestParameters().getALaCarte() == null) { + isALaCarte = false; + } else { + isALaCarte = request.getRequestDetails().getRequestParameters().getALaCarte(); + } + + } return Pattern.compile("[Vv][5-8]/serviceInstances/[^/]+").matcher(requestUri).matches() - && action.equals(Action.deleteInstance); + && action.equals(Action.deleteInstance) && isALaCarte; } @Override diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/VnfDeleteValidator.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/VnfDeleteValidator.java index d54e60d153..37e3f0cb2e 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/VnfDeleteValidator.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/VnfDeleteValidator.java @@ -8,8 +8,9 @@ import org.onap.so.apihandlerinfra.Actions; import org.onap.so.apihandlerinfra.infra.rest.AAIDataRetrieval; import org.onap.so.serviceinstancebeans.ServiceInstancesRequest; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; - +@Component public class VnfDeleteValidator implements RequestValidator { @Autowired diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/VolumeGroupDeleteValidator.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/VolumeGroupDeleteValidator.java index f010d47f70..e3598af31d 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/VolumeGroupDeleteValidator.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/VolumeGroupDeleteValidator.java @@ -8,7 +8,9 @@ import org.onap.so.apihandlerinfra.Actions; import org.onap.so.apihandlerinfra.infra.rest.AAIDataRetrieval; import org.onap.so.serviceinstancebeans.ServiceInstancesRequest; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +@Component public class VolumeGroupDeleteValidator implements RequestValidator { @Autowired diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/infra/rest/validator/ServiceInstanceDeleteValidatorTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/infra/rest/validator/ServiceInstanceDeleteValidatorTest.java index c334d522b6..f461df3720 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/infra/rest/validator/ServiceInstanceDeleteValidatorTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/infra/rest/validator/ServiceInstanceDeleteValidatorTest.java @@ -5,6 +5,7 @@ import static org.mockito.Mockito.when; import java.util.HashMap; import java.util.Map; import java.util.Optional; +import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; @@ -14,6 +15,8 @@ import org.mockito.junit.MockitoJUnitRunner; import org.onap.so.apihandlerinfra.Action; import org.onap.so.apihandlerinfra.infra.rest.AAIDataRetrieval; import org.onap.so.apihandlerinfra.infra.rest.validators.ServiceInstanceDeleteValidator; +import org.onap.so.serviceinstancebeans.RequestDetails; +import org.onap.so.serviceinstancebeans.RequestParameters; import org.onap.so.serviceinstancebeans.ServiceInstancesRequest; @@ -30,22 +33,41 @@ public class ServiceInstanceDeleteValidatorTest { private Map<String, String> instanceIdMap = new HashMap<>(); + private ServiceInstancesRequest serviceInstancesRequest; + + @Before + public void before() { + serviceInstancesRequest = new ServiceInstancesRequest(); + RequestDetails requestDetails = new RequestDetails(); + RequestParameters requestParameters = new RequestParameters(); + requestParameters.setaLaCarte(true); + requestDetails.setRequestParameters(requestParameters); + serviceInstancesRequest.setRequestDetails(requestDetails); + } + @Test public void validateURIMatchTest() { - assertEquals(true, serviceValidator.shouldRunFor("v8/serviceInstances/uasdfasdf", new ServiceInstancesRequest(), + assertEquals(true, serviceValidator.shouldRunFor("v8/serviceInstances/uasdfasdf", serviceInstancesRequest, Action.deleteInstance)); } @Test public void validateURINotMatchTest() { assertEquals(false, serviceValidator.shouldRunFor("v8/serviceInstances/uasdfasdf/vnfs/asdfasdf", - new ServiceInstancesRequest(), Action.deleteInstance)); + serviceInstancesRequest, Action.deleteInstance)); } @Test public void validateURINotMatch2Test() { assertEquals(false, serviceValidator.shouldRunFor("v8/serviceInstances/uasdfasdf/update", - new ServiceInstancesRequest(), Action.deleteInstance)); + serviceInstancesRequest, Action.deleteInstance)); + } + + @Test + public void validateNotALaCarteTest() { + serviceInstancesRequest.getRequestDetails().getRequestParameters().setaLaCarte(false); + assertEquals(false, serviceValidator.shouldRunFor("v8/serviceInstances/uasdfasdf", serviceInstancesRequest, + Action.deleteInstance)); } @Test |