diff options
Diffstat (limited to 'plans')
4 files changed, 150 insertions, 4 deletions
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 2281d0ab..d5e991a8 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 @@ -153,8 +153,10 @@ public class ServiceOperationsCacheServiceProviderimpl extends AbstractCacheServ final GenericResourceApiServicedataServiceData serviceData = service.getServiceData(); if (serviceData != null) { final List<GenericResourceApiServicedataServicedataVnfsVnf> vnfsList = getVnfs(serviceData); - if (ifVnfNotExists(vnfId, vnfsList)) { + final GenericResourceApiLastRpcActionEnumeration svcAction = + GenericResourceApiLastRpcActionEnumeration.fromValue(getSvcAction(requestHeader)); + if (ifVnfNotExists(vnfId, svcAction, vnfsList)) { vnfsList.add(getGenericResourceApiServicedataVnf(serviceInstanceId, vnfId, input)); final GenericResourceApiServicestatusServiceStatus serviceStatus = service.getServiceStatus(); @@ -167,7 +169,7 @@ public class ServiceOperationsCacheServiceProviderimpl extends AbstractCacheServ .vnfResponseInformation(new GenericResourceApiInstanceReference().instanceId(vnfId) .objectPath(getObjectPath(serviceInstanceId, vnfId))); } - LOGGER.error("vnfId: {} already exists", vnfId); + LOGGER.error("vnfId: {} already exists with SVC Action: {}", vnfId, svcAction); return new Output().ackFinalIndicator(YES).responseCode(HttpStatus.BAD_REQUEST.toString()) .responseMessage("vnfId: " + vnfId + " already exists").svcRequestId(svcRequestId); } @@ -198,11 +200,37 @@ public class ServiceOperationsCacheServiceProviderimpl extends AbstractCacheServ } - private boolean ifVnfNotExists(final String vnfId, + private boolean ifVnfNotExists(final String vnfId, final GenericResourceApiLastRpcActionEnumeration svcAction, + final List<GenericResourceApiServicedataServicedataVnfsVnf> vnfsList) { + final Optional<GenericResourceApiServicedataServicedataVnfsVnf> optional = getExistingVnf(vnfId, vnfsList); + if (optional.isPresent()) { + final GenericResourceApiServicedataServicedataVnfsVnf existingVnf = optional.get(); + final GenericResourceApiServicedataServicedataVnfsVnfVnfData vnfData = existingVnf.getVnfData(); + + if (vnfData != null && vnfData.getVnfLevelOperStatus() != null + && vnfData.getVnfLevelOperStatus().getLastRpcAction() != null) { + final GenericResourceApiLastRpcActionEnumeration existingVnflastRpcAction = + vnfData.getVnfLevelOperStatus().getLastRpcAction(); + if (existingVnflastRpcAction.equals(svcAction)) { + LOGGER.error("Found vnf with id: {} and LastRpcAction: {} same as SvcAction: {}", vnfId, + existingVnflastRpcAction, svcAction); + return false; + } + LOGGER.warn("Will remove and replace existing vnf with id: {} as SvcAction is changed from {} to {}", + vnfId, existingVnflastRpcAction, svcAction); + vnfsList.removeIf(vnf -> vnf.getVnfId() != null && vnf.getVnfId().equals(vnfId)); + + } + } + + return true; + } + + private Optional<GenericResourceApiServicedataServicedataVnfsVnf> getExistingVnf(final String vnfId, final List<GenericResourceApiServicedataServicedataVnfsVnf> vnfsList) { final Optional<GenericResourceApiServicedataServicedataVnfsVnf> optional = vnfsList.stream().filter(vnf -> vnf.getVnfId() != null && vnf.getVnfId().equals(vnfId)).findFirst(); - return !optional.isPresent(); + return optional; } private List<GenericResourceApiServicedataServicedataVnfsVnf> getVnfs( 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 18d478eb..b1ede082 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 @@ -25,11 +25,14 @@ import static org.junit.Assert.assertTrue; 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.getVnfRequestInput; +import static org.onap.so.sdncsimulator.controller.TestUtils.getVnfRequestWithSvcActionActivateInput; import java.util.Optional; import org.junit.After; import org.junit.Test; import org.junit.runner.RunWith; import org.onap.sdnc.northbound.client.model.GenericResourceApiInstanceReference; +import org.onap.sdnc.northbound.client.model.GenericResourceApiLastRpcActionEnumeration; +import org.onap.sdnc.northbound.client.model.GenericResourceApiOperStatusData; import org.onap.sdnc.northbound.client.model.GenericResourceApiServicedataServicedataVnfsVnf; import org.onap.sdnc.northbound.client.model.GenericResourceApiServicemodelinfrastructureService; import org.onap.so.sdncsimulator.models.InputRequest; @@ -239,6 +242,71 @@ public class OperationsControllerTest { } + @Test + public void test_postVnfOperationInformationWithSvcActionChanged_successfullyAddToExistingServiceInCache() + 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()); + + final HttpEntity<?> httpVnfWithSvcActionAssignEntity = new HttpEntity<>(getVnfRequestInput(), getHttpHeaders()); + final ResponseEntity<OutputRequest> response = restTemplate.exchange(getVnfUrl(), HttpMethod.POST, + httpVnfWithSvcActionAssignEntity, OutputRequest.class); + assertEquals(HttpStatus.OK, response.getStatusCode()); + assertTrue(response.hasBody()); + + final HttpEntity<?> httpVnfEntity = + new HttpEntity<>(getVnfRequestWithSvcActionActivateInput(), getHttpHeaders()); + final ResponseEntity<OutputRequest> responseVnfEntity = + restTemplate.exchange(getVnfUrl(), HttpMethod.POST, httpVnfEntity, OutputRequest.class); + assertEquals(HttpStatus.OK, responseVnfEntity.getStatusCode()); + assertTrue(responseVnfEntity.hasBody()); + + final OutputRequest actualOutputRequest = responseVnfEntity.getBody(); + assertNotNull(actualOutputRequest); + assertNotNull(actualOutputRequest.getOutput()); + + final Output actualObject = actualOutputRequest.getOutput(); + + assertEquals(HttpStatus.OK.toString(), actualObject.getResponseCode()); + assertEquals(Constants.YES, actualObject.getAckFinalIndicator()); + assertEquals(VNF_SVC_REQUEST_ID, actualObject.getSvcRequestId()); + assertNotNull(actualObject.getServiceResponseInformation()); + + final GenericResourceApiInstanceReference acutalReference = actualObject.getServiceResponseInformation(); + assertEquals(Constants.RESTCONF_CONFIG_END_POINT + SERVICE_INSTANCE_ID, acutalReference.getObjectPath()); + assertEquals(SERVICE_INSTANCE_ID, acutalReference.getInstanceId()); + final Optional<GenericResourceApiServicemodelinfrastructureService> optional = + cacheServiceProvider.getGenericResourceApiServicemodelinfrastructureService(SERVICE_INSTANCE_ID); + assertTrue(optional.isPresent()); + + final GenericResourceApiInstanceReference actualvnfInformation = actualObject.getVnfResponseInformation(); + assertEquals(VNF_INSTANCE_ID, actualvnfInformation.getInstanceId()); + + final Optional<GenericResourceApiServicemodelinfrastructureService> serviceOptional = + cacheServiceProvider.getGenericResourceApiServicemodelinfrastructureService(SERVICE_INSTANCE_ID); + assertTrue(serviceOptional.isPresent()); + + final GenericResourceApiServicemodelinfrastructureService service = serviceOptional.get(); + assertNotNull(service.getServiceInstanceId()); + assertNotNull(service.getServiceData().getVnfs().getVnf()); + assertNotNull(service.getServiceData()); + assertNotNull(service.getServiceData().getVnfs()); + assertNotNull(service.getServiceData().getVnfs().getVnf()); + assertEquals(1, service.getServiceData().getVnfs().getVnf().size()); + final GenericResourceApiServicedataServicedataVnfsVnf vnf = service.getServiceData().getVnfs().getVnf().get(0); + assertNotNull(vnf.getVnfId()); + assertEquals(VNF_INSTANCE_ID, vnf.getVnfId()); + assertNotNull(vnf.getVnfData()); + GenericResourceApiOperStatusData vnfLevelOperStatus = vnf.getVnfData().getVnfLevelOperStatus(); + assertNotNull(vnfLevelOperStatus); + assertEquals(GenericResourceApiLastRpcActionEnumeration.ACTIVATE, vnfLevelOperStatus.getLastRpcAction()); + + } + + 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 a6814b69..220ec7d3 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 @@ -45,6 +45,10 @@ public class TestUtils { public static String getVnfRequestInput() throws IOException { return getFileAsString(getFile("test-data/vnfInput.json").toPath()); } + + public static String getVnfRequestWithSvcActionActivateInput() throws IOException { + return getFileAsString(getFile("test-data/activateVnfInput.json").toPath()); + } public static String getInvalidRequestInput() throws IOException { return getFileAsString(getFile("test-data/InvalidInput.json").toPath()); diff --git a/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/test/resources/test-data/activateVnfInput.json b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/test/resources/test-data/activateVnfInput.json new file mode 100644 index 00000000..a3adf0bf --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/test/resources/test-data/activateVnfInput.json @@ -0,0 +1,46 @@ +{ + "input": { + "request-information": { + "request-action": "CreateVnfInstance", + "source": "MSO", + "request-id": "1a545ea9-2a5e-4df9-9c73-529b1d0b2012" + }, + "sdnc-request-header": { + "svc-request-id": "8fd2622b-01fc-424d-bfc8-f48bcd64e546", + "svc-notification-url": "http://so-bpmn-infra.onap:8081/mso/WorkflowMessage/SDNCCallback/fd40ea09-3245-476a-b6ff-58cb042edb9d", + "svc-action": "activate" + }, + "service-information": { + "onap-model-information": { + "model-name": "Sol004Zip4Service", + "model-version": "1.0", + "model-uuid": "99d59273-4450-4034-9141-027f0c1a807a", + "model-invariant-uuid": "51672777-9b8d-4e5e-b488-5f9092e03a82" + }, + "subscription-service-type": "vCPE", + "service-id": "ccece8fe-13da-456a-baf6-41b3a4a2bc2b", + "global-customer-id": "NordixDemoCustomer", + "service-instance-id": "ccece8fe-13da-456a-baf6-41b3a4a2bc2b" + }, + "vnf-information": { + "onap-model-information": { + "model-name": "Sol004Zip3VSP", + "model-version": "1.0", + "model-customization-uuid": "50a90cd7-a84e-4ee1-b5ba-bfa5a26f5e15", + "model-uuid": "84b9649a-4eb9-4967-9abe-e8702f55518b", + "model-invariant-uuid": "b0f14066-2b65-40d2-b5a4-c8f2116fb5fc" + }, + "vnf-id": "dfd02fb5-d7fb-4aac-b3c4-cd6b60058701", + "vnf-name": "EsyVnfInstantiationTest2", + "vnf-type": "Sol004Zip4Service/Sol004Zip3VSP 0" + }, + "vnf-request-input": { + "aic-cloud-region": "nordixcloud", + "cloud-owner": "CloudOwner", + "tenant": "693c7729b2364a26a3ca602e6f66187d", + "vnf-network-instance-group-ids": [], + "vnf-input-parameters": {}, + "vnf-name": "EsyVnfInstantiationTest2" + } + } +}
\ No newline at end of file |