diff options
author | waqas.ikram <waqas.ikram@est.tech> | 2019-09-25 12:27:06 +0100 |
---|---|---|
committer | waqas.ikram <waqas.ikram@est.tech> | 2019-09-25 12:27:08 +0100 |
commit | a1f84a15cf98925a334062bfd912c9097c1b5be5 (patch) | |
tree | bf1e60edf10e9638fb3edcf9c4ad45da2cb8b7fb /plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main | |
parent | 2fd2236b7db11e5ff8592ca982557546af4b3fad (diff) |
Fixing service delete in sdnc simulator
Change-Id: I76a52aaa102e08b27d20e1bc908f145b4256595e
Issue-ID: SO-2342
Signed-off-by: waqas.ikram <waqas.ikram@est.tech>
Diffstat (limited to 'plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main')
2 files changed, 59 insertions, 14 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; + + } + } |