aboutsummaryrefslogtreecommitdiffstats
path: root/plans/so/integration-etsi-testing
diff options
context:
space:
mode:
authorwaqas.ikram <waqas.ikram@est.tech>2019-09-23 15:11:20 +0100
committerwaqas.ikram <waqas.ikram@est.tech>2019-09-23 16:37:11 +0100
commit07593362ee3550b94cdf734a14e22c9f848185e1 (patch)
treeed1046c36109b9c118e8580be23895b16f4f586c /plans/so/integration-etsi-testing
parent0713941d88dadd5689fefe514c8f45c9b7f5752f (diff)
Adding service delete endpoint in sdnc simulator
Change-Id: I7c849b32a7b920becd6b7f9622e5f5bbe01eebe0 Issue-ID: SO-2342 Signed-off-by: waqas.ikram <waqas.ikram@est.tech>
Diffstat (limited to 'plans/so/integration-etsi-testing')
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/controller/OperationsController.java25
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/providers/ServiceOperationsCacheServiceProvider.java3
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/providers/ServiceOperationsCacheServiceProviderimpl.java37
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/test/java/org/onap/so/sdncsimulator/controller/OperationsControllerTest.java40
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/test/java/org/onap/so/sdncsimulator/controller/TestUtils.java4
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/test/resources/test-data/deleteServiceInput.json28
6 files changed, 129 insertions, 8 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 88970e74..9696beb6 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
@@ -19,6 +19,7 @@
*/
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.so.sdncsimulator.utils.Constants.OPERATIONS_URL;
import javax.servlet.http.HttpServletRequest;
@@ -73,14 +74,14 @@ public class OperationsController {
return ResponseEntity.badRequest().build();
}
- final Output output = cacheServiceProvider.putServiceOperationInformation(apiServiceOperationInformation);
+ final Output output = getOutput(apiServiceOperationInformation);
final OutputRequest outputRequest = new OutputRequest(output);
if (output.getResponseCode().equals(HttpStatus.OK.toString())) {
- LOGGER.info("Sucessfully added service in cache sending response: {}", outputRequest);
+ LOGGER.info("Sucessfully executed service request sending response: {}", outputRequest);
return ResponseEntity.ok(outputRequest);
}
- LOGGER.error("Unable to add input request: {}, will send OutputRequest: {}", inputRequest, outputRequest);
+ LOGGER.error("Unable to execute input request: {}, will send OutputRequest: {}", inputRequest, outputRequest);
return ResponseEntity.badRequest().body(outputRequest);
}
@@ -100,19 +101,31 @@ public class OperationsController {
}
final Output output = getOutput(apiVnfOperationInformation);
-
final OutputRequest outputRequest = new OutputRequest(output);
if (output.getResponseCode().equals(HttpStatus.OK.toString())) {
- LOGGER.info("Sucessfully added vnf in cache sending response: {}", outputRequest);
+ LOGGER.info("Sucessfully executed request vnf sending response: {}", outputRequest);
return ResponseEntity.ok(outputRequest);
}
- LOGGER.error("Unable to add input request: {}, will send OutputRequest: {}", inputRequest, outputRequest);
+ LOGGER.error("Unable to execute input request: {}, will send OutputRequest: {}", inputRequest, outputRequest);
return ResponseEntity.badRequest().body(outputRequest);
}
+ private Output getOutput(final GenericResourceApiServiceOperationInformation serviceOperationInformation) {
+ final GenericResourceApiRequestinformationRequestInformation requestInformation =
+ serviceOperationInformation.getRequestInformation();
+ if (requestInformation != null) {
+ final GenericResourceApiRequestActionEnumeration requestAction = requestInformation.getRequestAction();
+ if (DELETESERVICEINSTANCE.equals(requestAction)) {
+ LOGGER.info("RequestAction: {} will delete service instance from cache ...", requestAction);
+ return cacheServiceProvider.deleteServiceOperationInformation(serviceOperationInformation);
+ }
+ }
+ return cacheServiceProvider.putServiceOperationInformation(serviceOperationInformation);
+ }
+
private Output getOutput(final GenericResourceApiVnfOperationInformation apiVnfOperationInformation) {
final GenericResourceApiRequestinformationRequestInformation requestInformation =
apiVnfOperationInformation.getRequestInformation();
diff --git a/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/providers/ServiceOperationsCacheServiceProvider.java b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/providers/ServiceOperationsCacheServiceProvider.java
index 5b32b91f..c3a80ec3 100644
--- a/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/providers/ServiceOperationsCacheServiceProvider.java
+++ b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/providers/ServiceOperationsCacheServiceProvider.java
@@ -34,6 +34,9 @@ public interface ServiceOperationsCacheServiceProvider {
Output putServiceOperationInformation(
final GenericResourceApiServiceOperationInformation apiServiceOperationInformation);
+ Output deleteServiceOperationInformation(
+ final GenericResourceApiServiceOperationInformation serviceOperationInformation);
+
Optional<GenericResourceApiServicemodelinfrastructureService> getGenericResourceApiServicemodelinfrastructureService(
final String serviceInstanceId);
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 616a56c4..180e636b 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
@@ -119,6 +119,34 @@ public class ServiceOperationsCacheServiceProviderimpl extends AbstractCacheServ
}
@Override
+ public Output deleteServiceOperationInformation(final GenericResourceApiServiceOperationInformation input) {
+ final GenericResourceApiServiceinformationServiceInformation serviceInformation = input.getServiceInformation();
+ final String svcRequestId = getSvcRequestId(input.getSdncRequestHeader());
+
+ if (serviceInformation != null && isValid(serviceInformation.getServiceInstanceId())) {
+ final String serviceInstanceId = serviceInformation.getServiceInstanceId();
+ final Optional<GenericResourceApiServicemodelinfrastructureService> optional =
+ getGenericResourceApiServicemodelinfrastructureService(serviceInstanceId);
+ if (optional.isPresent()) {
+ final Cache cache = getCache(SERVICE_TOPOLOGY_OPERATION_CACHE);
+ LOGGER.info("Deleting GenericResourceApiServiceOperationInformation from cache using key: {}",
+ serviceInstanceId);
+ cache.evict(serviceInstanceId);
+ return new Output().ackFinalIndicator(YES).responseCode(HttpStatus.OK.toString())
+ .responseMessage(EMPTY_STRING).svcRequestId(svcRequestId).serviceResponseInformation(
+ new GenericResourceApiInstanceReference().instanceId(serviceInstanceId));
+ }
+ LOGGER.error(
+ "Unable to find existing GenericResourceApiServiceModelInfrastructure in cache using service instance id: {}",
+ serviceInstanceId);
+
+ }
+ LOGGER.error("Unable to remove service instance from cache due to invalid input: {}... ", input);
+ return new Output().ackFinalIndicator(YES).responseCode(HttpStatus.BAD_REQUEST.toString())
+ .responseMessage("Unable to remove service").svcRequestId(svcRequestId);
+ }
+
+ @Override
public Optional<GenericResourceApiServicemodelinfrastructureService> getGenericResourceApiServicemodelinfrastructureService(
final String serviceInstanceId) {
final Cache cache = getCache(SERVICE_TOPOLOGY_OPERATION_CACHE);
@@ -210,7 +238,14 @@ public class ServiceOperationsCacheServiceProviderimpl extends AbstractCacheServ
getExistingVnf(vnfId, vnfsList);
if (vnfInstanceOptional.isPresent()) {
- vnfsList.removeIf(vnf -> vnf.getVnfId() != null && vnf.getVnfId().equals(vnfId));
+ vnfsList.removeIf(vnf -> {
+ final String existingVnfId = vnf.getVnfId();
+ if (existingVnfId != null && existingVnfId.equals(vnfId)) {
+ LOGGER.info("Remove vnf with id: {} ... ", existingVnfId);
+ return true;
+ }
+ return false;
+ });
return new Output().ackFinalIndicator(YES).responseCode(HttpStatus.OK.toString())
.responseMessage(EMPTY_STRING).svcRequestId(svcRequestId)
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 a338283c..3c17a376 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,6 +25,7 @@ import static org.junit.Assert.assertNotNull;
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.getServiceRequestWithRequestActionDeleteServiceInput;
import static org.onap.so.sdncsimulator.controller.TestUtils.getVnfRequestInput;
import static org.onap.so.sdncsimulator.controller.TestUtils.getVnfRequestWithRequestActionDeleteVnfInput;
import static org.onap.so.sdncsimulator.controller.TestUtils.getVnfRequestWithSvcActionActivateInput;
@@ -302,7 +303,7 @@ public class OperationsControllerTest {
assertNotNull(vnf.getVnfId());
assertEquals(VNF_INSTANCE_ID, vnf.getVnfId());
assertNotNull(vnf.getVnfData());
- GenericResourceApiOperStatusData vnfLevelOperStatus = vnf.getVnfData().getVnfLevelOperStatus();
+ final GenericResourceApiOperStatusData vnfLevelOperStatus = vnf.getVnfData().getVnfLevelOperStatus();
assertNotNull(vnfLevelOperStatus);
assertEquals(GenericResourceApiLastRpcActionEnumeration.ACTIVATE, vnfLevelOperStatus.getLastRpcAction());
@@ -364,6 +365,43 @@ public class OperationsControllerTest {
}
+ @Test
+ public void test_postServiceOperationInformation_withActionDeleteServiceInstance_successfullyRemoveServiceFromExistingServiceInCache()
+ 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());
+
+ final GenericResourceApiServicemodelinfrastructureService service = serviceOptional.get();
+ assertNotNull(service.getServiceInstanceId());
+
+ final HttpEntity<?> httpRemoveServiceEntity =
+ new HttpEntity<>(getServiceRequestWithRequestActionDeleteServiceInput(), getHttpHeaders());
+ final ResponseEntity<OutputRequest> responseRemoveServiceEntity =
+ restTemplate.exchange(getUrl(), HttpMethod.POST, httpRemoveServiceEntity, OutputRequest.class);
+ assertEquals(HttpStatus.OK, responseRemoveServiceEntity.getStatusCode());
+
+ final OutputRequest actualOutputRequest = responseRemoveServiceEntity.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);
+ assertFalse(serviceOptional.isPresent());
+
+ }
+
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 b43ecf4c..8e0e9b43 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
@@ -58,6 +58,10 @@ public class TestUtils {
return getFileAsString(getFile("test-data/deleteVnfInput.json").toPath());
}
+ public static String getServiceRequestWithRequestActionDeleteServiceInput() throws IOException {
+ return getFileAsString(getFile("test-data/deleteServiceInput.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/deleteServiceInput.json b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/test/resources/test-data/deleteServiceInput.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/deleteServiceInput.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"
+ }
+ }
+}