From d866e3f2d0044b92a12bd7832168d6f037be93ec Mon Sep 17 00:00:00 2001 From: "waqas.ikram" Date: Thu, 19 Sep 2019 14:55:31 +0100 Subject: Adding vserver delete endpoints Change-Id: If866e63b2b6725a5c8141c6764189654f9be75b3 Issue-ID: SO-2342 Signed-off-by: waqas.ikram --- .../controller/CloudRegionsController.java | 27 +++++++++++++++++ .../so/aaisimulator/models/CloudRegionKey.java | 6 ++++ .../providers/CloudRegionCacheServiceProvider.java | 3 ++ .../CloudRegionCacheServiceProviderImpl.java | 34 +++++++++++++++++++++- .../controller/CloudRegionsControllerTest.java | 29 ++++++++++++++++++ .../controller/GenericVnfsControllerTest.java | 1 + 6 files changed, 99 insertions(+), 1 deletion(-) diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/CloudRegionsController.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/CloudRegionsController.java index f5b411d1..29701ed4 100644 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/CloudRegionsController.java +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/CloudRegionsController.java @@ -45,6 +45,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpHeaders; 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.PutMapping; @@ -292,4 +293,30 @@ public class CloudRegionsController { tenantId, vServerId); return getRequestErrorResponseEntity(request, CLOUD_REGION); } + + + @DeleteMapping(value = "{cloud-owner}/{cloud-region-id}/tenants/tenant/{tenant-id}/vservers/vserver/{vserver-id}", + produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + public ResponseEntity deleteVserver(@PathVariable("cloud-owner") final String cloudOwner, + @PathVariable("cloud-region-id") final String cloudRegionId, + @PathVariable("tenant-id") final String tenantId, @PathVariable("vserver-id") final String vServerId, + @RequestParam(name = "resource-version") final String resourceVersion, final HttpServletRequest request) { + + final CloudRegionKey key = new CloudRegionKey(cloudOwner, cloudRegionId); + LOGGER.info("Will delete Vserver using key: {}, tenant-id: {}, vserver-id: {} and resource-version: {}...", key, + tenantId, vServerId, resourceVersion); + + + if (cacheServiceProvider.deleteVserver(key, tenantId, vServerId, resourceVersion)) { + LOGGER.info( + "Successfully delete Vserver from cache for key: {}, tenant-id: {}, vserver-id: {} and resource-version: {}", + key, tenantId, vServerId, resourceVersion); + return ResponseEntity.noContent().build(); + } + + LOGGER.error( + "Unable to delete Vserver from cache using key: {}, tenant-id: {}, vserver-id: {} and resource-version: {} ...", + key, tenantId, vServerId, resourceVersion); + return getRequestErrorResponseEntity(request, CLOUD_REGION); + } } diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/models/CloudRegionKey.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/models/CloudRegionKey.java index d49a1a37..3c45c196 100644 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/models/CloudRegionKey.java +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/models/CloudRegionKey.java @@ -76,4 +76,10 @@ public class CloudRegionKey implements Serializable { } return false; } + + @Override + public String toString() { + return "CloudRegionKey [cloudOwner=" + cloudOwner + ", cloudRegionId=" + cloudRegionId + "]"; + } + } diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CloudRegionCacheServiceProvider.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CloudRegionCacheServiceProvider.java index 082130b7..412da1c6 100644 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CloudRegionCacheServiceProvider.java +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CloudRegionCacheServiceProvider.java @@ -56,4 +56,7 @@ public interface CloudRegionCacheServiceProvider extends Clearable { boolean putVserver(final CloudRegionKey key, final String tenantId, final String vServerId, Vserver vServer); Optional getVserver(final CloudRegionKey key, final String tenantId, final String vServerId); + + boolean deleteVserver(final CloudRegionKey key, final String tenantId, final String vServerId, + final String resourceVersion); } diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CloudRegionCacheServiceProviderImpl.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CloudRegionCacheServiceProviderImpl.java index 5024cc79..6fb1eb0f 100644 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CloudRegionCacheServiceProviderImpl.java +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CloudRegionCacheServiceProviderImpl.java @@ -282,7 +282,7 @@ public class CloudRegionCacheServiceProviderImpl extends AbstractCacheServicePro final Optional optional = getTenant(key, tenantId); if (optional.isPresent()) { final Tenant tenant = optional.get(); - Vservers vServers = tenant.getVservers(); + final Vservers vServers = tenant.getVservers(); if (vServers != null) { return vServers.getVserver().stream() .filter(vServer -> vServer.getVserverId() != null && vServer.getVserverId().equals(vServerId)) @@ -293,6 +293,38 @@ public class CloudRegionCacheServiceProviderImpl extends AbstractCacheServicePro return Optional.empty(); } + @Override + public boolean deleteVserver(final CloudRegionKey key, final String tenantId, final String vServerId, + final String resourceVersion) { + final Optional optional = getVserver(key, tenantId, vServerId); + if (optional.isPresent()) { + final Optional tenantOptional = getTenant(key, tenantId); + if (tenantOptional.isPresent()) { + final Tenant tenant = tenantOptional.get(); + final Vservers vServers = tenant.getVservers(); + if (vServers != null) { + return vServers.getVserver().removeIf(vServer -> { + if (vServer.getVserverId() != null && vServer.getVserverId().equals(vServerId) + && vServer.getResourceVersion() != null + && vServer.getResourceVersion().equals(resourceVersion)) { + LOGGER.info("Will remove Vserver from cache with vServerId: {} and resource-version: {} ", + vServerId, vServer.getResourceVersion()); + return true; + } + return false; + }); + } + + } + + } + LOGGER.error( + "Unable to find Vserver for using key: {}, tenant-id: {}, vserver-id: {} and resource-version: {} ...", + key, tenantId, vServerId, resourceVersion); + + return false; + } + private List getEsrSystemInfoList(final CloudRegion cloudRegion) { EsrSystemInfoList esrSystemInfoList = cloudRegion.getEsrSystemInfoList(); if (esrSystemInfoList == null) { diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/CloudRegionsControllerTest.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/CloudRegionsControllerTest.java index 584e28cf..0ed9d4ea 100644 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/CloudRegionsControllerTest.java +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/CloudRegionsControllerTest.java @@ -320,6 +320,35 @@ public class CloudRegionsControllerTest extends AbstractSpringBootTest { assertEquals("active", actualVserver.getProvStatus()); } + @Test + public void test_deleteVServer_successfullyRemoveFromCache() throws Exception { + final String url = getUrl(Constants.CLOUD_REGIONS, CLOUD_OWNER_NAME, "/" + CLOUD_REGION_NAME); + + invokeCloudRegionHttpPutEndPointAndAssertResponse(url); + + final String tenantUrl = url + TENANTS_TENANT + TENANT_ID; + addTenantAndAssertResponse(tenantUrl); + + final String vServerAddUrl = tenantUrl + VSERVER_URL + VSERVER_ID; + + final ResponseEntity vServerAddResponse = + testRestTemplateService.invokeHttpPut(vServerAddUrl, TestUtils.getVserver(), Void.class); + assertEquals(HttpStatus.ACCEPTED, vServerAddResponse.getStatusCode()); + + final Optional optional = + cloudRegionCacheServiceProvider.getVserver(CLOUD_REGION_KEY, TENANT_ID, VSERVER_ID); + assertTrue(optional.isPresent()); + final Vserver vserver = optional.get(); + + final String vServerRemoveUrl = vServerAddUrl + "?resource-version=" + vserver.getResourceVersion(); + + final ResponseEntity responseEntity = + testRestTemplateService.invokeHttpDelete(vServerRemoveUrl, Void.class); + assertEquals(HttpStatus.NO_CONTENT, responseEntity.getStatusCode()); + assertFalse(cloudRegionCacheServiceProvider.getVserver(CLOUD_REGION_KEY, TENANT_ID, VSERVER_ID).isPresent()); + + + } private void addTenantAndAssertResponse(final String tenantUrl) throws IOException { final ResponseEntity responseEntity = diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/GenericVnfsControllerTest.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/GenericVnfsControllerTest.java index 711dcd11..dca7f669 100644 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/GenericVnfsControllerTest.java +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/GenericVnfsControllerTest.java @@ -404,6 +404,7 @@ public class GenericVnfsControllerTest extends AbstractSpringBootTest { final ResponseEntity responseEntity = testRestTemplateService.invokeHttpDelete(genericVnfDeleteUrl, Void.class); assertEquals(HttpStatus.NO_CONTENT, responseEntity.getStatusCode()); + assertFalse(genericVnfCacheServiceProvider.getGenericVnf(VNF_ID).isPresent()); } -- cgit 1.2.3-korg