X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=plans%2Fso%2Fintegration-etsi-testing%2Fso-simulators%2Fsdnc-simulator%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fso%2Fsdncsimulator%2Fcontroller%2FOperationsController.java;h=58f903828a3ee2e0d5da5046e7ab24b920e51a4b;hb=refs%2Fheads%2Fguilin;hp=2d901c42398128f7c16c69d403cc5d784c17bf2b;hpb=413bbe636e82c268d588c08185422f94ab4f75f3;p=integration%2Fcsit.git 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 2d901c42..58f90382 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,11 +19,19 @@ */ 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.sdnc.northbound.client.model.GenericResourceApiVfModuleOperationInformation; import org.onap.so.sdncsimulator.models.InputRequest; import org.onap.so.sdncsimulator.models.Output; import org.onap.so.sdncsimulator.models.OutputRequest; @@ -45,6 +53,7 @@ import org.springframework.web.bind.annotation.RequestMapping; @Controller @RequestMapping(path = OPERATIONS_URL) public class OperationsController { + private static final String HTTP_STATUS_OK = HttpStatus.OK.value() + ""; private static final Logger LOGGER = LoggerFactory.getLogger(OperationsController.class); @@ -70,14 +79,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); + if (output.getResponseCode().equals(HTTP_STATUS_OK)) { + 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); } @@ -96,17 +105,79 @@ public class OperationsController { return ResponseEntity.badRequest().build(); } - final Output output = cacheServiceProvider.putVnfOperationInformation(apiVnfOperationInformation); + 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); + if (output.getResponseCode().equals(HTTP_STATUS_OK)) { + 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(); + final GenericResourceApiSdncrequestheaderSdncRequestHeader sdncRequestHeader = + serviceOperationInformation.getSdncRequestHeader(); + if (requestInformation != null && sdncRequestHeader != null) { + final GenericResourceApiRequestActionEnumeration requestAction = requestInformation.getRequestAction(); + 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); + } + } + return cacheServiceProvider.putServiceOperationInformation(serviceOperationInformation); + } + + private Output getOutput(final GenericResourceApiVnfOperationInformation apiVnfOperationInformation) { + final GenericResourceApiRequestinformationRequestInformation requestInformation = + apiVnfOperationInformation.getRequestInformation(); + if (requestInformation != null) { + final GenericResourceApiRequestActionEnumeration requestAction = requestInformation.getRequestAction(); + if (DELETEVNFINSTANCE.equals(requestAction)) { + LOGGER.info("RequestAction: {} will delete vnf instance from cache ...", requestAction); + return cacheServiceProvider.deleteVnfOperationInformation(apiVnfOperationInformation); + } + } + return cacheServiceProvider.putVnfOperationInformation(apiVnfOperationInformation); + } + + @PostMapping(value = "/GENERIC-RESOURCE-API:vf-module-topology-operation/", + consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}, + produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + public ResponseEntity postVfModuleOperationInformation( + @RequestBody final InputRequest inputRequest, + final HttpServletRequest request) { + LOGGER.info("Request Received for VfModule : {} ...", inputRequest); + + final GenericResourceApiVfModuleOperationInformation apiVfModuleOperationInformation = inputRequest.getInput(); + if (apiVfModuleOperationInformation == null) { + LOGGER.error("Invalid input request: {}", inputRequest); + return ResponseEntity.badRequest().build(); + } + + final Output output = getOutput(apiVfModuleOperationInformation); + final OutputRequest outputRequest = new OutputRequest(output); + + if (output.getResponseCode().equals(HTTP_STATUS_OK)) { + LOGGER.info("Sucessfully executed request vnf sending response: {}", outputRequest); + return ResponseEntity.ok(outputRequest); + } + + LOGGER.error("Unable to execute input request: {}, will send OutputRequest: {}", inputRequest, outputRequest); + return ResponseEntity.badRequest().body(outputRequest); + + } + + private Output getOutput(final GenericResourceApiVfModuleOperationInformation apiVfModuleOperationInformation) { + + return cacheServiceProvider.putVfModuleOperationInformation(apiVfModuleOperationInformation); + } + }