From 00a017801130973f0da0fdb11c0a513259eed124 Mon Sep 17 00:00:00 2001 From: ajay_dp001 Date: Wed, 15 Jul 2020 14:35:53 +0530 Subject: [SO] Service Level Workflow Execution API This commit implements - New SO Service level workflow execution API - Code refactoring on class InstanceManagement.java Issue-ID: SO-2930 Signed-off-by: ajay_dp001 Change-Id: Iabeeddab3ac47d257e25af0f3e43d8e857c70037 --- .../so/apihandlerinfra/InstanceManagement.java | 228 ++++++++------------- .../org/onap/so/apihandlerinfra/MsoRequest.java | 5 +- .../so/apihandlerinfra/RequestHandlerUtils.java | 8 +- .../validation/InstanceIdMapValidation.java | 9 +- .../validation/ValidationInformation.java | 10 +- .../so/apihandlerinfra/InstanceManagementTest.java | 38 +++- .../ExecuteServiceLevelCustomWorkflow.json | 39 ++++ .../catalogdb/workflow_ServiceLevel_Response.json | 6 + 8 files changed, 178 insertions(+), 165 deletions(-) create mode 100644 mso-api-handlers/mso-api-handler-infra/src/test/resources/ServiceInstanceTest/ExecuteServiceLevelCustomWorkflow.json create mode 100644 mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/catalogdb/workflow_ServiceLevel_Response.json (limited to 'mso-api-handlers/mso-api-handler-infra') diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/InstanceManagement.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/InstanceManagement.java index f39a95e92c..b59f298022 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/InstanceManagement.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/InstanceManagement.java @@ -9,6 +9,8 @@ * ================================================================================ * Modifications Copyright (c) 2020 Nokia * ================================================================================ + * Modifications Copyright (c) 2020 Nordix + * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -25,7 +27,28 @@ package org.onap.so.apihandlerinfra; +import io.swagger.v3.oas.annotations.OpenAPIDefinition; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.info.Info; +import io.swagger.v3.oas.annotations.media.ArraySchema; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import javax.transaction.Transactional; +import javax.ws.rs.Consumes; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.container.ContainerRequestContext; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; import org.apache.http.HttpStatus; +import org.onap.logging.filter.base.ErrorCode; import org.onap.so.apihandler.common.ErrorNumbers; import org.onap.so.apihandler.common.RequestClientParameter; import org.onap.so.apihandlerinfra.exceptions.ApiException; @@ -39,35 +62,13 @@ import org.onap.so.db.catalog.client.CatalogDbClient; import org.onap.so.db.request.beans.InfraActiveRequests; import org.onap.so.db.request.client.RequestsDbClient; import org.onap.so.exceptions.ValidationException; -import org.onap.logging.filter.base.ErrorCode; import org.onap.so.logger.MessageEnum; import org.onap.so.serviceinstancebeans.ModelType; -import org.onap.so.serviceinstancebeans.RequestReferences; import org.onap.so.serviceinstancebeans.ServiceInstancesRequest; -import org.onap.so.serviceinstancebeans.ServiceInstancesResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -import javax.transaction.Transactional; -import javax.ws.rs.Consumes; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.container.ContainerRequestContext; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import java.io.IOException; -import java.util.HashMap; -import io.swagger.v3.oas.annotations.OpenAPIDefinition; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.info.Info; -import io.swagger.v3.oas.annotations.media.ArraySchema; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.responses.ApiResponse; @Component @Path("/onap/so/infra/instanceManagement") @@ -75,8 +76,8 @@ import io.swagger.v3.oas.annotations.responses.ApiResponse; description = "Infrastructure API Requests for Instance Management")) public class InstanceManagement { - private static Logger logger = LoggerFactory.getLogger(InstanceManagement.class); - private static String uriPrefix = "/instanceManagement/"; + private static final Logger LOG = LoggerFactory.getLogger(InstanceManagement.class); + private static final String URI_PREFIX = "/instanceManagement/"; private static final String SAVE_TO_DB = "save instance to db"; @Autowired @@ -102,13 +103,13 @@ public class InstanceManagement { @PathParam("serviceInstanceId") String serviceInstanceId, @PathParam("vnfInstanceId") String vnfInstanceId, @PathParam("workflowUuid") String workflowUuid, @Context ContainerRequestContext requestContext) throws ApiException { - String requestId = requestHandlerUtils.getRequestId(requestContext); - HashMap instanceIdMap = new HashMap<>(); + final String requestId = requestHandlerUtils.getRequestId(requestContext); + final Map instanceIdMap = new HashMap<>(); instanceIdMap.put("serviceInstanceId", serviceInstanceId); instanceIdMap.put("vnfInstanceId", vnfInstanceId); instanceIdMap.put("workflowUuid", workflowUuid); return processCustomWorkflowRequest(request, Action.inPlaceSoftwareUpdate, instanceIdMap, version, requestId, - requestContext); + requestContext, true); } @POST @@ -122,34 +123,61 @@ public class InstanceManagement { @PathParam("serviceInstanceId") String serviceInstanceId, @PathParam("pnfName") String pnfName, @PathParam("workflowUuid") String workflowUuid, @Context ContainerRequestContext requestContext) throws ApiException { - String requestId = requestHandlerUtils.getRequestId(requestContext); - HashMap instanceIdMap = new HashMap<>(); + final String requestId = requestHandlerUtils.getRequestId(requestContext); + final Map instanceIdMap = new HashMap<>(); instanceIdMap.put("serviceInstanceId", serviceInstanceId); instanceIdMap.put("pnfName", pnfName); instanceIdMap.put("workflowUuid", workflowUuid); - return processPNFCustomWorkflowRequest(request, Action.forCustomWorkflow, instanceIdMap, version, requestId, - requestContext); + return processCustomWorkflowRequest(request, Action.forCustomWorkflow, instanceIdMap, version, requestId, + requestContext, false); + } + + @POST + @Path("/{version:[vV][1]}/serviceInstances/{serviceInstanceId}/workflows/{workflowUuid}") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @Operation(description = "Execute custom Service Level workflow", responses = @ApiResponse( + content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class))))) + @Transactional + public Response executeServiceLevelCustomWorkflow(String request, @PathParam("version") String version, + @PathParam("serviceInstanceId") String serviceInstanceId, @PathParam("workflowUuid") String workflowUuid, + @Context ContainerRequestContext requestContext) throws ApiException { + final String requestId = requestHandlerUtils.getRequestId(requestContext); + final Map instanceIdMap = new HashMap<>(); + instanceIdMap.put("serviceInstanceId", serviceInstanceId); + instanceIdMap.put("workflowUuid", workflowUuid); + return processCustomWorkflowRequest(request, Action.forCustomWorkflow, instanceIdMap, version, requestId, + requestContext, false); } - private Response processCustomWorkflowRequest(String requestJSON, Actions action, - HashMap instanceIdMap, String version, String requestId, - ContainerRequestContext requestContext) throws ApiException { - String serviceInstanceId; - boolean aLaCarte = true; - ServiceInstancesRequest sir; - String apiVersion = version.substring(1); + private Response processCustomWorkflowRequest(final String requestJSON, final Actions action, + final Map instanceIdMap, final String version, final String requestId, + final ContainerRequestContext requestContext, final boolean aLaCarte) throws ApiException { + String pnfName = null; + String vnfType = null; + String workflowUuid = null; + String vnfInstanceId = null; + String svcInstanceId = null; + final String apiVersion = version.substring(1); - String requestUri = requestHandlerUtils.getRequestUri(requestContext, uriPrefix); + if (instanceIdMap != null && !instanceIdMap.isEmpty()) { + pnfName = instanceIdMap.get("pnfName"); + workflowUuid = instanceIdMap.get("workflowUuid"); + vnfInstanceId = instanceIdMap.get("vnfInstanceId"); + svcInstanceId = instanceIdMap.get("serviceInstanceId"); + } - sir = requestHandlerUtils.convertJsonToServiceInstanceRequest(requestJSON, action, requestId, requestUri); - String requestScope = requestHandlerUtils.deriveRequestScope(action, sir, requestUri); - InfraActiveRequests currentActiveReq = - msoRequest.createRequestObject(sir, action, requestId, Status.IN_PROGRESS, requestJSON, requestScope); + final String requestUri = requestHandlerUtils.getRequestUri(requestContext, URI_PREFIX); + final ServiceInstancesRequest svcInsReq = + requestHandlerUtils.convertJsonToServiceInstanceRequest(requestJSON, action, requestId, requestUri); + final String requestScope = requestHandlerUtils.deriveRequestScope(action, svcInsReq, requestUri); + InfraActiveRequests currentActiveReq = msoRequest.createRequestObject(svcInsReq, action, requestId, + Status.IN_PROGRESS, requestJSON, requestScope); try { requestHandlerUtils.validateHeaders(requestContext); } catch (ValidationException e) { - logger.error("Exception occurred", e); + LOG.error("Exception occurred", e); ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_VALIDATION_ERROR, ErrorCode.SchemaError) .errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build(); @@ -160,42 +188,18 @@ public class InstanceManagement { throw validateException; } - requestHandlerUtils.parseRequest(sir, instanceIdMap, action, version, requestJSON, aLaCarte, requestId, + requestHandlerUtils.parseRequest(svcInsReq, instanceIdMap, action, version, requestJSON, aLaCarte, requestId, currentActiveReq); requestHandlerUtils.setInstanceId(currentActiveReq, requestScope, null, instanceIdMap); - String vnfType = msoRequest.getVnfType(sir, requestScope); - - if (requestScope.equalsIgnoreCase(ModelType.vnf.name()) && vnfType != null) { + if (requestScope.equalsIgnoreCase(ModelType.vnf.name())) { + vnfType = msoRequest.getVnfType(svcInsReq, requestScope); currentActiveReq.setVnfType(vnfType); } checkDuplicateAndBuildError(action, instanceIdMap, requestScope, currentActiveReq); - - ServiceInstancesResponse serviceResponse = new ServiceInstancesResponse(); - - RequestReferences referencesResponse = new RequestReferences(); - - referencesResponse.setRequestId(requestId); - - serviceResponse.setRequestReferences(referencesResponse); - boolean isBaseVfModule = false; - - String workflowUuid = null; - if (instanceIdMap != null) { - workflowUuid = instanceIdMap.get("workflowUuid"); - } - - RecipeLookupResult recipeLookupResult = getInstanceManagementWorkflowRecipe(currentActiveReq, workflowUuid); - - String serviceInstanceType = requestHandlerUtils.getServiceType(requestScope, sir, true); - - serviceInstanceId = requestHandlerUtils.setServiceInstanceId(requestScope, sir); - String vnfId = ""; - - if (sir.getVnfInstanceId() != null) { - vnfId = sir.getVnfInstanceId(); - } + final RecipeLookupResult recipeLookupResult = + getInstanceManagementWorkflowRecipe(currentActiveReq, workflowUuid); currentActiveReq = setWorkflowNameAndOperationName(currentActiveReq, workflowUuid); saveCurrentActiveRequest(currentActiveReq); @@ -203,11 +207,11 @@ public class InstanceManagement { RequestClientParameter requestClientParameter; try { requestClientParameter = new RequestClientParameter.Builder().setRequestId(requestId) - .setBaseVfModule(isBaseVfModule).setRecipeTimeout(recipeLookupResult.getRecipeTimeout()) - .setRequestAction(action.toString()).setServiceInstanceId(serviceInstanceId).setVnfId(vnfId) - .setServiceType(serviceInstanceType).setVnfType(vnfType) + .setRecipeTimeout(recipeLookupResult.getRecipeTimeout()).setRequestAction(action.toString()) + .setServiceInstanceId(svcInstanceId).setVnfId(vnfInstanceId).setVnfType(vnfType) + .setPnfCorrelationId(pnfName).setApiVersion(apiVersion) .setRequestDetails(requestHandlerUtils.mapJSONtoMSOStyle(requestJSON, null, aLaCarte, action)) - .setApiVersion(apiVersion).setALaCarte(aLaCarte).setRequestUri(requestUri).build(); + .setALaCarte(aLaCarte).setRequestUri(requestUri).build(); } catch (IOException e) { ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_BPEL_RESPONSE_ERROR, ErrorCode.SchemaError) @@ -232,7 +236,7 @@ public class InstanceManagement { } } - private void checkDuplicateAndBuildError(Actions action, HashMap instanceIdMap, String requestScope, + private void checkDuplicateAndBuildError(Actions action, Map instanceIdMap, String requestScope, InfraActiveRequests currentActiveReq) throws ApiException { InfraActiveRequests dup = @@ -248,74 +252,6 @@ public class InstanceManagement { } } - private Response processPNFCustomWorkflowRequest(String requestJSON, Actions action, - HashMap instanceIdMap, String version, String requestId, - ContainerRequestContext requestContext) throws ApiException { - boolean aLaCarte = false; - ServiceInstancesRequest sir; - String apiVersion = version.substring(1); - - String serviceInstanceId = ""; - String pnfName = ""; - String workflowUuid = ""; - if (instanceIdMap != null) { - serviceInstanceId = instanceIdMap.get("serviceInstanceId"); - pnfName = instanceIdMap.get("pnfName"); - workflowUuid = instanceIdMap.get("workflowUuid"); - } - - String requestUri = requestHandlerUtils.getRequestUri(requestContext, uriPrefix); - sir = requestHandlerUtils.convertJsonToServiceInstanceRequest(requestJSON, action, requestId, requestUri); - sir.setServiceInstanceId(serviceInstanceId); - sir.setPnfName(pnfName); - String requestScope = ModelType.pnf.name(); - InfraActiveRequests currentActiveReq = - msoRequest.createRequestObject(sir, action, requestId, Status.IN_PROGRESS, requestJSON, requestScope); - - try { - requestHandlerUtils.validateHeaders(requestContext); - } catch (ValidationException e) { - logger.error("Exception occurred", e); - ErrorLoggerInfo errorLoggerInfo = - new ErrorLoggerInfo.Builder(MessageEnum.APIH_VALIDATION_ERROR, ErrorCode.SchemaError) - .errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build(); - ValidateException validateException = - new ValidateException.Builder(e.getMessage(), HttpStatus.SC_BAD_REQUEST, - ErrorNumbers.SVC_BAD_PARAMETER).cause(e).errorInfo(errorLoggerInfo).build(); - requestHandlerUtils.updateStatus(currentActiveReq, Status.FAILED, validateException.getMessage()); - throw validateException; - } - - requestHandlerUtils.parseRequest(sir, instanceIdMap, action, version, requestJSON, aLaCarte, requestId, - currentActiveReq); - requestHandlerUtils.setInstanceId(currentActiveReq, requestScope, null, instanceIdMap); - - checkDuplicateAndBuildError(action, instanceIdMap, requestScope, currentActiveReq); - - RecipeLookupResult recipeLookupResult = getInstanceManagementWorkflowRecipe(currentActiveReq, workflowUuid); - - currentActiveReq = setWorkflowNameAndOperationName(currentActiveReq, workflowUuid); - saveCurrentActiveRequest(currentActiveReq); - - RequestClientParameter requestClientParameter; - try { - requestClientParameter = new RequestClientParameter.Builder().setRequestId(requestId) - .setRecipeTimeout(recipeLookupResult.getRecipeTimeout()).setRequestAction(action.toString()) - .setServiceInstanceId(serviceInstanceId).setPnfCorrelationId(pnfName) - .setRequestDetails(requestHandlerUtils.mapJSONtoMSOStyle(requestJSON, null, aLaCarte, action)) - .setApiVersion(apiVersion).setRequestUri(requestUri).build(); - } catch (IOException e) { - ErrorLoggerInfo errorLoggerInfo = - new ErrorLoggerInfo.Builder(MessageEnum.APIH_BPEL_RESPONSE_ERROR, ErrorCode.SchemaError) - .errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build(); - throw new ValidateException.Builder("Unable to generate RequestClientParamter object" + e.getMessage(), - HttpStatus.SC_INTERNAL_SERVER_ERROR, ErrorNumbers.SVC_BAD_PARAMETER).errorInfo(errorLoggerInfo) - .build(); - } - return requestHandlerUtils.postBPELRequest(currentActiveReq, requestClientParameter, - recipeLookupResult.getOrchestrationURI(), requestScope); - } - private RecipeLookupResult getInstanceManagementWorkflowRecipe(InfraActiveRequests currentActiveReq, String workflowUuid) throws ApiException { RecipeLookupResult recipeLookupResult; diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/MsoRequest.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/MsoRequest.java index f3c3ec5ff1..4ac8b73698 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/MsoRequest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/MsoRequest.java @@ -154,9 +154,8 @@ public class MsoRequest { // Parse request JSON - public void parse(ServiceInstancesRequest sir, HashMap instanceIdMap, Actions action, - String version, String originalRequestJSON, int reqVersion, Boolean aLaCarteFlag) - throws ValidationException, IOException { + public void parse(ServiceInstancesRequest sir, Map instanceIdMap, Actions action, String version, + String originalRequestJSON, int reqVersion, Boolean aLaCarteFlag) throws ValidationException, IOException { logger.debug("Validating the Service Instance request"); List rules = new ArrayList<>(); diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/RequestHandlerUtils.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/RequestHandlerUtils.java index a61975f529..a68309f199 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/RequestHandlerUtils.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/RequestHandlerUtils.java @@ -261,8 +261,8 @@ public class RequestHandlerUtils extends AbstractRestHandler { } } - public InfraActiveRequests duplicateCheck(Actions action, HashMap instanceIdMap, - String instanceName, String requestScope, InfraActiveRequests currentActiveReq) throws ApiException { + public InfraActiveRequests duplicateCheck(Actions action, Map instanceIdMap, String instanceName, + String requestScope, InfraActiveRequests currentActiveReq) throws ApiException { InfraActiveRequests dup = null; try { if (!(instanceName == null && "service".equals(requestScope) && (action == Action.createInstance @@ -332,7 +332,7 @@ public class RequestHandlerUtils extends AbstractRestHandler { } } - public void parseRequest(ServiceInstancesRequest sir, HashMap instanceIdMap, Actions action, + public void parseRequest(ServiceInstancesRequest sir, Map instanceIdMap, Actions action, String version, String requestJSON, Boolean aLaCarte, String requestId, InfraActiveRequests currentActiveReq) throws ValidateException, RequestDbFailureException { int reqVersion = Integer.parseInt(version.substring(1)); @@ -354,7 +354,7 @@ public class RequestHandlerUtils extends AbstractRestHandler { } public void buildErrorOnDuplicateRecord(InfraActiveRequests currentActiveReq, Actions action, - HashMap instanceIdMap, String instanceName, String requestScope, InfraActiveRequests dup) + Map instanceIdMap, String instanceName, String requestScope, InfraActiveRequests dup) throws ApiException { String instance = null; diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/validation/InstanceIdMapValidation.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/validation/InstanceIdMapValidation.java index 2cf01f9390..55a68ff7df 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/validation/InstanceIdMapValidation.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/validation/InstanceIdMapValidation.java @@ -21,7 +21,7 @@ package org.onap.so.apihandlerinfra.validation; -import java.util.HashMap; +import java.util.Map; import org.onap.so.apihandler.common.CommonConstants; import org.onap.so.exceptions.ValidationException; import org.onap.so.serviceinstancebeans.ServiceInstancesRequest; @@ -31,6 +31,7 @@ public class InstanceIdMapValidation implements ValidationRule { private static final String Service_InstanceId = "serviceInstanceId"; private static final String Vnf_InstanceId = "vnfInstanceId"; + private static final String PNF_NAME = "pnfName"; private static final String vfModule_InstanceId = "vfModuleInstanceId"; private static final String volume_Group_InstanceId = "volumeGroupInstanceId"; @@ -39,7 +40,7 @@ public class InstanceIdMapValidation implements ValidationRule { @Override public ValidationInformation validate(ValidationInformation info) throws ValidationException { - HashMap instanceIdMap = info.getInstanceIdMap(); + Map instanceIdMap = info.getInstanceIdMap(); ServiceInstancesRequest sir = info.getSir(); if (instanceIdMap != null) { if (instanceIdMap.get(Service_InstanceId) != null) { @@ -90,6 +91,10 @@ public class InstanceIdMapValidation implements ValidationRule { } sir.setInstanceGroupId(instanceIdMap.get(CommonConstants.INSTANCE_GROUP_INSTANCE_ID)); } + + if (instanceIdMap.get(PNF_NAME) != null) { + sir.setPnfName(instanceIdMap.get(PNF_NAME)); + } } return info; } diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/validation/ValidationInformation.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/validation/ValidationInformation.java index 68b2a78a85..ee4fde02eb 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/validation/ValidationInformation.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/validation/ValidationInformation.java @@ -21,7 +21,7 @@ package org.onap.so.apihandlerinfra.validation; -import java.util.HashMap; +import java.util.Map; import org.onap.so.apihandlerinfra.Actions; import org.onap.so.serviceinstancebeans.LineOfBusiness; import org.onap.so.serviceinstancebeans.OwningEntity; @@ -34,7 +34,7 @@ import org.onap.so.serviceinstancebeans.ServiceInstancesRequest; public class ValidationInformation { ServiceInstancesRequest sir; - HashMap instanceIdMap; + Map instanceIdMap; Actions action; int reqVersion; String requestScope; @@ -53,7 +53,7 @@ public class ValidationInformation { OwningEntity owningEntity; Service userParams; - public ValidationInformation(ServiceInstancesRequest sir, HashMap instanceIdMap, Actions action, + public ValidationInformation(ServiceInstancesRequest sir, Map instanceIdMap, Actions action, int reqVersion, Boolean aLaCarteFlag, RequestParameters requestParameters) { this.sir = sir; this.instanceIdMap = instanceIdMap; @@ -71,11 +71,11 @@ public class ValidationInformation { this.sir = value; } - public HashMap getInstanceIdMap() { + public Map getInstanceIdMap() { return this.instanceIdMap; } - public void setInstanceIdMap(HashMap value) { + public void setInstanceIdMap(Map value) { this.instanceIdMap = value; } diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/InstanceManagementTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/InstanceManagementTest.java index 081f235db1..33ed5fa700 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/InstanceManagementTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/InstanceManagementTest.java @@ -29,10 +29,12 @@ import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThat; -import static org.onap.logging.filter.base.Constants.HttpHeaders.ONAP_REQUEST_ID; -import static org.onap.so.logger.HttpHeadersConstants.REQUESTOR_ID; import static org.onap.logging.filter.base.Constants.HttpHeaders.ONAP_PARTNER_NAME; +import static org.onap.logging.filter.base.Constants.HttpHeaders.ONAP_REQUEST_ID; import static org.onap.logging.filter.base.Constants.HttpHeaders.TRANSACTION_ID; +import static org.onap.so.logger.HttpHeadersConstants.REQUESTOR_ID; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; import java.io.File; import java.io.IOException; import java.net.MalformedURLException; @@ -46,7 +48,6 @@ import org.junit.Before; import org.junit.Test; import org.onap.logging.ref.slf4j.ONAPLogConstants; import org.onap.so.db.request.beans.InfraActiveRequests; -import org.onap.so.logger.HttpHeadersConstants; import org.onap.so.serviceinstancebeans.RequestReferences; import org.onap.so.serviceinstancebeans.ServiceInstancesResponse; import org.springframework.beans.factory.annotation.Autowired; @@ -57,8 +58,6 @@ import org.springframework.http.HttpMethod; import org.springframework.http.ResponseEntity; import org.springframework.util.ResourceUtils; import org.springframework.web.util.UriComponentsBuilder; -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.ObjectMapper; public class InstanceManagementTest extends BaseTest { @@ -207,6 +206,35 @@ public class InstanceManagementTest extends BaseTest { assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); } + @Test + public void executeServiceLevelCustomWorkflow() throws IOException { + wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/testingServiceLevelWorkflow")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK))); + + wireMockServer.stubFor(get(urlMatching( + ".*/workflow/search/findByArtifactUUID[?]artifactUUID=81526781-e55c-4cb7-adb3-97e09d9c76bf")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("workflow_ServiceLevel_Response.json")) + .withStatus(org.apache.http.HttpStatus.SC_OK))); + + // expected response + ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); + RequestReferences requestReferences = new RequestReferences(); + requestReferences.setInstanceId("1882939"); + requestReferences.setRequestSelfLink(createExpectedSelfLink("v1", "32807a28-1a14-4b88-b7b3-2950918aa76d")); + expectedResponse.setRequestReferences(requestReferences); + uri = instanceManagementUri + "v1" + + "/serviceInstances/5df8b6de-2083-11e7-93ae-92361f002676/workflows/81526781-e55c-4cb7-adb3-97e09d9c76bf"; + ResponseEntity response = + sendRequest(inputStream("/ExecuteServiceLevelCustomWorkflow.json"), uri, HttpMethod.POST, headers); + + assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); + + ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class); + assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); + } + @Test public void workflowAndOperationNameTest() { wireMockServer.stubFor(get(urlMatching( diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/resources/ServiceInstanceTest/ExecuteServiceLevelCustomWorkflow.json b/mso-api-handlers/mso-api-handler-infra/src/test/resources/ServiceInstanceTest/ExecuteServiceLevelCustomWorkflow.json new file mode 100644 index 0000000000..e466ac08a3 --- /dev/null +++ b/mso-api-handlers/mso-api-handler-infra/src/test/resources/ServiceInstanceTest/ExecuteServiceLevelCustomWorkflow.json @@ -0,0 +1,39 @@ +{ + "requestDetails":{ + "subscriberInfo":{ + "globalSubscriberId":"Test" + }, + "requestInfo":{ + "suppressRollback": false, + "productFamilyId": "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb", + "requestorId": "demo", + "instanceName":"testInstanceName", + "source":"VID" + }, + "cloudConfiguration":{ + "lcpCloudRegionId": "RegionOne", + "tenantId": "7320ec4a5b9d4589ba7c4412ccfd290f", + "cloudOwner": "CloudOwner" + }, + "requestParameters":{ + "subscriptionServiceType": "test", + "userParams":[], + "aLaCarte": false, + "payload": "{\"k1\": \"v1\"}" + }, + "project":{ + "projectName": "PNFSWUProject" + }, + "owningEntity":{ + "owningEntityId":"67f2e84c-734d-4e90-a1e4-d2ffa2e75849", + "owningEntityName":"OE-Test" + }, + "modelInfo":{ + "modelVersion": "2.0", + "modelVersionId": "d88da85c-d9e8-4f73-b837-3a72a431622b", + "modelInvariantId": "fe41489e-1563-46a3-b90a-1db629e4375b", + "modelName": "Demo_svc", + "modelType": "service" + } + } +} diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/catalogdb/workflow_ServiceLevel_Response.json b/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/catalogdb/workflow_ServiceLevel_Response.json new file mode 100644 index 0000000000..133c724b43 --- /dev/null +++ b/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/catalogdb/workflow_ServiceLevel_Response.json @@ -0,0 +1,6 @@ +{ + "artifactUUID": "81526781-e55c-4cb7-adb3-97e09d9c76bf", + "artifactName": "testingServiceLevelWorkflow.bpmn", + "name": "testingServiceLevelWorkflow", + "operationName": "testServiceLevelOperation" +} -- cgit 1.2.3-korg