diff options
6 files changed, 140 insertions, 15 deletions
diff --git a/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/controller/OperationsController.java b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/controller/OperationsController.java index 9696beb6..f96224d3 100644 --- a/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/controller/OperationsController.java +++ b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/controller/OperationsController.java @@ -21,12 +21,15 @@ package org.onap.so.sdncsimulator.controller; import static org.onap.sdnc.northbound.client.model.GenericResourceApiRequestActionEnumeration.DELETESERVICEINSTANCE; import static org.onap.sdnc.northbound.client.model.GenericResourceApiRequestActionEnumeration.DELETEVNFINSTANCE; +import static org.onap.sdnc.northbound.client.model.GenericResourceApiSvcActionEnumeration.DELETE; import static org.onap.so.sdncsimulator.utils.Constants.OPERATIONS_URL; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.core.MediaType; import org.onap.sdnc.northbound.client.model.GenericResourceApiRequestActionEnumeration; import org.onap.sdnc.northbound.client.model.GenericResourceApiRequestinformationRequestInformation; +import org.onap.sdnc.northbound.client.model.GenericResourceApiSdncrequestheaderSdncRequestHeader; import org.onap.sdnc.northbound.client.model.GenericResourceApiServiceOperationInformation; +import org.onap.sdnc.northbound.client.model.GenericResourceApiSvcActionEnumeration; import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfOperationInformation; import org.onap.so.sdncsimulator.models.InputRequest; import org.onap.so.sdncsimulator.models.Output; @@ -116,10 +119,14 @@ public class OperationsController { private Output getOutput(final GenericResourceApiServiceOperationInformation serviceOperationInformation) { final GenericResourceApiRequestinformationRequestInformation requestInformation = serviceOperationInformation.getRequestInformation(); - if (requestInformation != null) { + final GenericResourceApiSdncrequestheaderSdncRequestHeader sdncRequestHeader = + serviceOperationInformation.getSdncRequestHeader(); + if (requestInformation != null && sdncRequestHeader != null) { final GenericResourceApiRequestActionEnumeration requestAction = requestInformation.getRequestAction(); - if (DELETESERVICEINSTANCE.equals(requestAction)) { - LOGGER.info("RequestAction: {} will delete service instance from cache ...", requestAction); + final GenericResourceApiSvcActionEnumeration svcAction = sdncRequestHeader.getSvcAction(); + if (DELETESERVICEINSTANCE.equals(requestAction) && DELETE.equals(svcAction)) { + LOGGER.info("RequestAction: {} and SvcAction: {} will delete service instance from cache ...", + requestAction, svcAction); return cacheServiceProvider.deleteServiceOperationInformation(serviceOperationInformation); } } diff --git a/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/providers/ServiceOperationsCacheServiceProviderimpl.java b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/providers/ServiceOperationsCacheServiceProviderimpl.java index 180e636b..dae8b7f4 100644 --- a/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/providers/ServiceOperationsCacheServiceProviderimpl.java +++ b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/providers/ServiceOperationsCacheServiceProviderimpl.java @@ -94,28 +94,37 @@ public class ServiceOperationsCacheServiceProviderimpl extends AbstractCacheServ final GenericResourceApiServiceinformationServiceInformation serviceInformation = input.getServiceInformation(); if (serviceInformation != null && isValid(serviceInformation.getServiceInstanceId())) { - final Cache cache = getCache(SERVICE_TOPOLOGY_OPERATION_CACHE); final String serviceInstanceId = serviceInformation.getServiceInstanceId(); - LOGGER.info("Adding GenericResourceApiServiceOperationInformation to cache with key: {}", - serviceInstanceId); - final GenericResourceApiServicemodelinfrastructureService service = - getServiceItem(input, serviceInstanceId); - cache.put(serviceInstanceId, service); + if (isServiceOperationInformationNotExists(serviceInstanceId, input)) { + final Cache cache = getCache(SERVICE_TOPOLOGY_OPERATION_CACHE); + LOGGER.info("Adding GenericResourceApiServiceOperationInformation to cache with key: {}", + serviceInstanceId); - final GenericResourceApiServicestatusServiceStatus serviceStatus = service.getServiceStatus(); + final GenericResourceApiServicemodelinfrastructureService service = + getServiceItem(input, serviceInstanceId); + cache.put(serviceInstanceId, service); - return new Output().ackFinalIndicator(serviceStatus.getFinalIndicator()) - .responseCode(serviceStatus.getResponseCode()).responseMessage(serviceStatus.getResponseMessage()) - .svcRequestId(svcRequestId).serviceResponseInformation(new GenericResourceApiInstanceReference() - .instanceId(serviceInstanceId).objectPath(getObjectPath(serviceInstanceId))); + final GenericResourceApiServicestatusServiceStatus serviceStatus = service.getServiceStatus(); + return new Output().ackFinalIndicator(serviceStatus.getFinalIndicator()) + .responseCode(serviceStatus.getResponseCode()) + .responseMessage(serviceStatus.getResponseMessage()).svcRequestId(svcRequestId) + .serviceResponseInformation(new GenericResourceApiInstanceReference() + .instanceId(serviceInstanceId).objectPath(getObjectPath(serviceInstanceId))); + } + LOGGER.error("serviceInstanceId: {} already exists", serviceInstanceId); + return new Output().ackFinalIndicator(YES).responseCode(HttpStatus.BAD_REQUEST.toString()) + .responseMessage("serviceInstanceId: " + serviceInstanceId + " already exists") + .svcRequestId(svcRequestId); } + LOGGER.error( "Unable to add GenericResourceApiServiceOperationInformation in cache due to invalid input: {}... ", input); return new Output().ackFinalIndicator(YES).responseCode(HttpStatus.BAD_REQUEST.toString()) .responseMessage("Service instance not found").svcRequestId(svcRequestId); + } @Override @@ -467,4 +476,33 @@ public class ServiceOperationsCacheServiceProviderimpl extends AbstractCacheServ } + private boolean isServiceOperationInformationNotExists(final String serviceInstanceId, + final GenericResourceApiServiceOperationInformation input) { + final GenericResourceApiSdncrequestheaderSdncRequestHeader requestHeader = input.getSdncRequestHeader(); + final Optional<GenericResourceApiServicemodelinfrastructureService> optional = + getGenericResourceApiServicemodelinfrastructureService(serviceInstanceId); + + if (optional.isPresent()) { + final GenericResourceApiServicemodelinfrastructureService existingService = optional.get(); + final GenericResourceApiServicestatusServiceStatus serviceStatus = existingService.getServiceStatus(); + if (serviceStatus != null) { + final GenericResourceApiRpcActionEnumeration rpcAction = serviceStatus.getRpcAction(); + final String svcAction = getSvcAction(requestHeader); + if (rpcAction != null && rpcAction.toString().equals(svcAction)) { + LOGGER.error("Found Service with id: {} and RpcAction: {} same as SvcAction: {}", + serviceInstanceId, rpcAction, svcAction); + return false; + } + + final Cache cache = getCache(SERVICE_TOPOLOGY_OPERATION_CACHE); + LOGGER.info( + "Deleting existing GenericResourceApiServiceOperationInformation from cache using key: {} as SvcAction is changed from {} to {}", + serviceInstanceId, rpcAction, svcAction); + cache.evict(serviceInstanceId); + } + } + return true; + + } + } diff --git a/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/test/java/org/onap/so/sdncsimulator/controller/OperationsControllerTest.java b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/test/java/org/onap/so/sdncsimulator/controller/OperationsControllerTest.java index 3c17a376..b498bd6e 100644 --- a/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/test/java/org/onap/so/sdncsimulator/controller/OperationsControllerTest.java +++ b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/test/java/org/onap/so/sdncsimulator/controller/OperationsControllerTest.java @@ -23,8 +23,11 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import static org.onap.sdnc.northbound.client.model.GenericResourceApiRpcActionEnumeration.ASSIGN; +import static org.onap.sdnc.northbound.client.model.GenericResourceApiRpcActionEnumeration.DEACTIVATE; import static org.onap.so.sdncsimulator.controller.TestUtils.getInvalidRequestInput; import static org.onap.so.sdncsimulator.controller.TestUtils.getRequestInput; +import static org.onap.so.sdncsimulator.controller.TestUtils.getServiceRequestWithRequestActionDeleteServiceAndSvcActionDeactivateInput; import static org.onap.so.sdncsimulator.controller.TestUtils.getServiceRequestWithRequestActionDeleteServiceInput; import static org.onap.so.sdncsimulator.controller.TestUtils.getVnfRequestInput; import static org.onap.so.sdncsimulator.controller.TestUtils.getVnfRequestWithRequestActionDeleteVnfInput; @@ -402,6 +405,49 @@ public class OperationsControllerTest { } + @Test + public void test_postServiceOperationInformation_withActionDeleteServiceInstanceAndSvcActionDeactivate_successfullyUpdateExistingServiceInCache() + throws Exception { + + final HttpEntity<?> httpEntity = new HttpEntity<>(getRequestInput(), getHttpHeaders()); + final ResponseEntity<OutputRequest> responseEntity = + restTemplate.exchange(getUrl(), HttpMethod.POST, httpEntity, OutputRequest.class); + + assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); + Optional<GenericResourceApiServicemodelinfrastructureService> serviceOptional = + cacheServiceProvider.getGenericResourceApiServicemodelinfrastructureService(SERVICE_INSTANCE_ID); + assertTrue(serviceOptional.isPresent()); + + GenericResourceApiServicemodelinfrastructureService service = serviceOptional.get(); + assertNotNull(service.getServiceInstanceId()); + assertNotNull(service.getServiceStatus()); + assertEquals(ASSIGN, service.getServiceStatus().getRpcAction()); + + final HttpEntity<?> entity = new HttpEntity<>( + getServiceRequestWithRequestActionDeleteServiceAndSvcActionDeactivateInput(), getHttpHeaders()); + final ResponseEntity<OutputRequest> deactivateResponseEntity = + restTemplate.exchange(getUrl(), HttpMethod.POST, entity, OutputRequest.class); + assertEquals(HttpStatus.OK, deactivateResponseEntity.getStatusCode()); + + final OutputRequest actualOutputRequest = deactivateResponseEntity.getBody(); + assertNotNull(actualOutputRequest); + assertNotNull(actualOutputRequest.getOutput()); + + final Output actualObject = actualOutputRequest.getOutput(); + + assertEquals(HttpStatus.OK.toString(), actualObject.getResponseCode()); + assertEquals(Constants.YES, actualObject.getAckFinalIndicator()); + assertEquals(SVC_REQUEST_ID, actualObject.getSvcRequestId()); + + serviceOptional = + cacheServiceProvider.getGenericResourceApiServicemodelinfrastructureService(SERVICE_INSTANCE_ID); + assertTrue(serviceOptional.isPresent()); + service = serviceOptional.get(); + assertNotNull(service.getServiceStatus()); + assertEquals(DEACTIVATE, service.getServiceStatus().getRpcAction()); + + } + private HttpHeaders getHttpHeaders() { return TestUtils.getHttpHeaders(userCredentials.getUsers().iterator().next().getUsername()); } diff --git a/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/test/java/org/onap/so/sdncsimulator/controller/TestUtils.java b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/test/java/org/onap/so/sdncsimulator/controller/TestUtils.java index 8e0e9b43..52901b27 100644 --- a/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/test/java/org/onap/so/sdncsimulator/controller/TestUtils.java +++ b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/test/java/org/onap/so/sdncsimulator/controller/TestUtils.java @@ -62,6 +62,12 @@ public class TestUtils { return getFileAsString(getFile("test-data/deleteServiceInput.json").toPath()); } + public static String getServiceRequestWithRequestActionDeleteServiceAndSvcActionDeactivateInput() + throws IOException { + return getFileAsString(getFile("test-data/deactivateServiceInput.json").toPath()); + } + + public static String getFileAsString(final Path path) throws IOException { return new String(Files.readAllBytes(path)); } diff --git a/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/test/resources/test-data/deactivateServiceInput.json b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/test/resources/test-data/deactivateServiceInput.json new file mode 100644 index 00000000..1040209f --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/test/resources/test-data/deactivateServiceInput.json @@ -0,0 +1,28 @@ +{ + "input": { + "request-information": { + "request-action": "DeleteServiceInstance", + "source": "MSO", + "request-id": "33ebd358-a189-4664-90f5-cf9e23658e0a" + }, + "sdnc-request-header": { + "svc-request-id": "04fc9f50-87b8-430d-a232-ef24bd6c4150", + "svc-action": "deactivate" + }, + "service-information": { + "onap-model-information": { + "model-name": "Sol004Zip3Service", + "model-version": "2.0", + "model-uuid": "c112a499-6148-488b-ba82-3f5938cf26d2", + "model-invariant-uuid": "e9acd081-9c89-4b4d-bcb3-e0e2b9715b2a" + }, + "subscription-service-type": "vCPE", + "service-id": "ccece8fe-13da-456a-baf6-41b3a4a2bc2b", + "global-customer-id": "NordixDemoCustomer", + "service-instance-id": "ccece8fe-13da-456a-baf6-41b3a4a2bc2b" + }, + "service-request-input": { + "service-instance-name": "ServiceTest_24_07_2019" + } + } +} diff --git a/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/test/resources/test-data/deleteServiceInput.json b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/test/resources/test-data/deleteServiceInput.json index 1040209f..71a51b84 100644 --- a/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/test/resources/test-data/deleteServiceInput.json +++ b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/test/resources/test-data/deleteServiceInput.json @@ -7,7 +7,7 @@ }, "sdnc-request-header": { "svc-request-id": "04fc9f50-87b8-430d-a232-ef24bd6c4150", - "svc-action": "deactivate" + "svc-action": "delete" }, "service-information": { "onap-model-information": { |