aboutsummaryrefslogtreecommitdiffstats
path: root/plans/so/integration-etsi-testing/so-simulators
diff options
context:
space:
mode:
authorDaniel Rose <dr695h@att.com>2019-09-24 14:46:39 +0000
committerGerrit Code Review <gerrit@onap.org>2019-09-24 14:46:39 +0000
commit2fd2236b7db11e5ff8592ca982557546af4b3fad (patch)
tree2a2574d3364c446fc3178cd6f6fc56c418f9832e /plans/so/integration-etsi-testing/so-simulators
parent7b66a4b2ba1b6f092adff4198bda6ec055ee7118 (diff)
parent8343ef4ffe4280310d26c32fc6d172cc32e7aff4 (diff)
Merge "Adding service delete endpoint in aai simulator"
Diffstat (limited to 'plans/so/integration-etsi-testing/so-simulators')
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/BusinessController.java29
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CustomerCacheServiceProvider.java3
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CustomerCacheServiceProviderImpl.java39
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/BusinessControllerTest.java24
4 files changed, 93 insertions, 2 deletions
diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/BusinessController.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/BusinessController.java
index 347743bd..4a0ed1b9 100644
--- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/BusinessController.java
+++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/BusinessController.java
@@ -50,6 +50,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
@@ -324,4 +325,32 @@ public class BusinessController {
return getRequestErrorResponseEntity(request);
}
+
+ @DeleteMapping(
+ value = "/{global-customer-id}/service-subscriptions/service-subscription/{service-type}/service-instances/service-instance/{service-instance-id}",
+ produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
+ public ResponseEntity<?> deleteSericeInstance(@PathVariable("global-customer-id") final String globalCustomerId,
+ @PathVariable("service-type") final String serviceType,
+ @PathVariable(name = "service-instance-id") final String serviceInstanceId,
+ @RequestParam(name = "resource-version") final String resourceVersion, final HttpServletRequest request) {
+
+ LOGGER.info(
+ "Will delete SericeInstance for 'global-customer-id': {}, 'service-type': {}, 'service-instance-id': {} and 'resource-version': {}",
+ globalCustomerId, serviceType, serviceInstanceId, resourceVersion);
+
+ if (cacheServiceProvider.deleteSericeInstance(globalCustomerId, serviceType, serviceInstanceId,
+ resourceVersion)) {
+ LOGGER.info(
+ "Successfully deleted SericeInstance from cache for 'global-customer-id': {}, 'service-type': {}, 'service-instance-id': {} and 'resource-version': {}",
+ globalCustomerId, serviceType, serviceInstanceId, resourceVersion);
+ return ResponseEntity.noContent().build();
+ }
+
+ LOGGER.error(
+ "Unable to delete SericeInstance from cache for 'global-customer-id': {}, 'service-type': {}, 'service-instance-id': {} and 'resource-version': {}",
+ globalCustomerId, serviceType, serviceInstanceId, resourceVersion);
+
+ return getRequestErrorResponseEntity(request);
+
+ }
}
diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CustomerCacheServiceProvider.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CustomerCacheServiceProvider.java
index 268a6bc3..7000fb3f 100644
--- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CustomerCacheServiceProvider.java
+++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CustomerCacheServiceProvider.java
@@ -59,4 +59,7 @@ public interface CustomerCacheServiceProvider extends Clearable {
Optional<Relationship> addRelationShip(final String globalCustomerId, final String serviceType,
final String serviceInstanceId, final Relationship relationship, final String requestUri);
+ boolean deleteSericeInstance(final String globalCustomerId, final String serviceType,
+ final String serviceInstanceId, final String resourceVersion);
+
}
diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CustomerCacheServiceProviderImpl.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CustomerCacheServiceProviderImpl.java
index 4d42c243..7193ade1 100644
--- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CustomerCacheServiceProviderImpl.java
+++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CustomerCacheServiceProviderImpl.java
@@ -152,6 +152,9 @@ public class CustomerCacheServiceProviderImpl extends AbstractCacheServiceProvid
}
}
+ LOGGER.error(
+ "Unable to find ServiceInstance using globalCustomerId: {}, serviceType: {} and serviceInstanceId: {} ...",
+ globalCustomerId, serviceType, serviceInstanceId);
return Optional.empty();
}
@@ -228,6 +231,42 @@ public class CustomerCacheServiceProviderImpl extends AbstractCacheServiceProvid
return false;
}
+ @Override
+ public boolean deleteSericeInstance(final String globalCustomerId, final String serviceType,
+ final String serviceInstanceId, final String resourceVersion) {
+ final Cache cache = getCache(CUSTOMER_CACHE.getName());
+ final Customer value = cache.get(globalCustomerId, Customer.class);
+
+ if (value != null) {
+ final Optional<ServiceSubscription> serviceSubscription = value.getServiceSubscriptions()
+ .getServiceSubscription().stream().filter(s -> serviceType.equals(s.getServiceType())).findFirst();
+
+ if (serviceSubscription.isPresent()) {
+ LOGGER.info("Found service subscription ...");
+ final ServiceInstances serviceInstances = serviceSubscription.get().getServiceInstances();
+ if (serviceInstances != null) {
+
+ serviceInstances.getServiceInstance().removeIf(serviceInstance -> {
+ final String existingServiceInstanceId = serviceInstance.getServiceInstanceId();
+ final String existingResourceVersion = serviceInstance.getResourceVersion();
+ if (existingServiceInstanceId != null && existingServiceInstanceId.equals(serviceInstanceId)
+ && existingResourceVersion != null && existingResourceVersion.equals(resourceVersion)) {
+ LOGGER.info("Removing ServiceInstance with serviceInstanceId: {} and resourceVersion: {}",
+ existingServiceInstanceId, existingResourceVersion);
+ return true;
+ }
+ return false;
+ });
+
+
+ return true;
+ }
+
+ }
+ }
+ return false;
+ }
+
private ServiceInstances getServiceInstances(final Optional<ServiceSubscription> optional) {
final ServiceSubscription serviceSubscription = optional.get();
final ServiceInstances serviceInstances = serviceSubscription.getServiceInstances();
diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/BusinessControllerTest.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/BusinessControllerTest.java
index 8c57db58..c08c51ec 100644
--- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/BusinessControllerTest.java
+++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/BusinessControllerTest.java
@@ -335,8 +335,8 @@ public class BusinessControllerTest extends AbstractSpringBootTest {
invokeServiceInstanceEndPointAndAssertResponse();
- final String relationShipUrl =
- getUrl(CUSTOMERS_URL, SERVICE_SUBSCRIPTIONS_URL, SERVICE_INSTANCE_URL, BI_DIRECTIONAL_RELATIONSHIP_LIST_URL);
+ final String relationShipUrl = getUrl(CUSTOMERS_URL, SERVICE_SUBSCRIPTIONS_URL, SERVICE_INSTANCE_URL,
+ BI_DIRECTIONAL_RELATIONSHIP_LIST_URL);
final ResponseEntity<Relationship> responseEntity2 = testRestTemplateService.invokeHttpPut(relationShipUrl,
TestUtils.getRelationShipJsonObject(), Relationship.class);
@@ -360,6 +360,26 @@ public class BusinessControllerTest extends AbstractSpringBootTest {
assertEquals(GENERIC_VNF_NAME, genericVnf.getVnfName());
}
+ @Test
+ public void test_DeleteSericeInstance_ServiceInstanceRemovedFromCache() throws Exception {
+ final String url = getUrl(CUSTOMERS_URL, SERVICE_SUBSCRIPTIONS_URL, SERVICE_INSTANCE_URL);
+
+ invokeCustomerEndPointAndAssertResponse();
+
+ invokeServiceInstanceEndPointAndAssertResponse();
+
+ final Optional<ServiceInstance> optional =
+ cacheServiceProvider.getServiceInstance(GLOBAL_CUSTOMER_ID, SERVICE_TYPE, SERVICE_INSTANCE_ID);
+ assertTrue(optional.isPresent());
+ final ServiceInstance serviceInstance = optional.get();
+
+ final ResponseEntity<Void> responseEntity = testRestTemplateService
+ .invokeHttpDelete(url + "?resource-version=" + serviceInstance.getResourceVersion(), Void.class);
+ assertEquals(HttpStatus.NO_CONTENT, responseEntity.getStatusCode());
+ assertFalse(cacheServiceProvider.getServiceInstance(GLOBAL_CUSTOMER_ID, SERVICE_TYPE, SERVICE_INSTANCE_ID)
+ .isPresent());
+ }
+
private void invokeServiceInstanceEndPointAndAssertResponse() throws IOException {
final String url = getUrl(CUSTOMERS_URL, SERVICE_SUBSCRIPTIONS_URL, SERVICE_INSTANCE_URL);
final ResponseEntity<Void> responseEntity =