diff options
Diffstat (limited to 'mso-api-handlers')
17 files changed, 220 insertions, 193 deletions
diff --git a/mso-api-handlers/mso-api-handler-infra/pom.xml b/mso-api-handlers/mso-api-handler-infra/pom.xml index afb734d46e..eb7b73caab 100644 --- a/mso-api-handlers/mso-api-handler-infra/pom.xml +++ b/mso-api-handlers/mso-api-handler-infra/pom.xml @@ -244,6 +244,10 @@ <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> </exclusion> + <exclusion> + <groupId>log4j</groupId> + <artifactId>log4j</artifactId> + </exclusion> </exclusions> </dependency> <dependency> 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<String, String> instanceIdMap = new HashMap<>(); + final String requestId = requestHandlerUtils.getRequestId(requestContext); + final Map<String, String> 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<String, String> instanceIdMap = new HashMap<>(); + final String requestId = requestHandlerUtils.getRequestId(requestContext); + final Map<String, String> 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<String, String> 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<String, String> 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<String, String> 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<String, String> instanceIdMap, String requestScope, + private void checkDuplicateAndBuildError(Actions action, Map<String, String> instanceIdMap, String requestScope, InfraActiveRequests currentActiveReq) throws ApiException { InfraActiveRequests dup = @@ -248,74 +252,6 @@ public class InstanceManagement { } } - private Response processPNFCustomWorkflowRequest(String requestJSON, Actions action, - HashMap<String, String> 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<String, String> instanceIdMap, Actions action, - String version, String originalRequestJSON, int reqVersion, Boolean aLaCarteFlag) - throws ValidationException, IOException { + public void parse(ServiceInstancesRequest sir, Map<String, String> instanceIdMap, Actions action, String version, + String originalRequestJSON, int reqVersion, Boolean aLaCarteFlag) throws ValidationException, IOException { logger.debug("Validating the Service Instance request"); List<ValidationRule> 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<String, String> instanceIdMap, - String instanceName, String requestScope, InfraActiveRequests currentActiveReq) throws ApiException { + public InfraActiveRequests duplicateCheck(Actions action, Map<String, String> 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<String, String> instanceIdMap, Actions action, + public void parseRequest(ServiceInstancesRequest sir, Map<String, String> 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<String, String> instanceIdMap, String instanceName, String requestScope, InfraActiveRequests dup) + Map<String, String> 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/infra/rest/handler/AbstractRestHandler.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/handler/AbstractRestHandler.java index c806e9fc1b..fec512ac44 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/handler/AbstractRestHandler.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/handler/AbstractRestHandler.java @@ -163,12 +163,14 @@ public abstract class AbstractRestHandler { try { URL aUrl = new URL(url); String aPath = aUrl.getPath(); - if (aPath.indexOf("/v") == -1) { - version = aPath.substring(aPath.indexOf("/V"), aPath.indexOf("/V") + 4); - } else { - version = aPath.substring(aPath.indexOf("/v"), aPath.indexOf("/v") + 4); - } - String selfLinkPath = Constants.ORCHESTRATION_REQUESTS_PATH.concat(version).concat(requestId); + int indexOfVersion = Math.max(aPath.indexOf("/V"), aPath.indexOf("/v")); + version = aPath.substring(indexOfVersion, indexOfVersion + 4); + + String pathWithSOAction = aPath.substring(0, indexOfVersion); + String pathWithoutSOAction = pathWithSOAction.substring(0, pathWithSOAction.lastIndexOf("/")); + + String selfLinkPath = + pathWithoutSOAction.concat(Constants.ORCHESTRATION_REQUESTS_PATH).concat(version).concat(requestId); selfLinkUrl = Optional.of(new URL(aUrl.getProtocol(), aUrl.getHost(), aUrl.getPort(), selfLinkPath)); } catch (Exception e) { selfLinkUrl = Optional.empty(); // ignore 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<String, String> instanceIdMap = info.getInstanceIdMap(); + Map<String, String> 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<String, String> instanceIdMap; + Map<String, String> instanceIdMap; Actions action; int reqVersion; String requestScope; @@ -53,7 +53,7 @@ public class ValidationInformation { OwningEntity owningEntity; Service userParams; - public ValidationInformation(ServiceInstancesRequest sir, HashMap<String, String> instanceIdMap, Actions action, + public ValidationInformation(ServiceInstancesRequest sir, Map<String, String> 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<String, String> getInstanceIdMap() { + public Map<String, String> getInstanceIdMap() { return this.instanceIdMap; } - public void setInstanceIdMap(HashMap<String, String> value) { + public void setInstanceIdMap(Map<String, String> value) { this.instanceIdMap = value; } diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/BaseTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/BaseTest.java index 5da16f4326..0ca98883c9 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/BaseTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/BaseTest.java @@ -70,6 +70,10 @@ public abstract class BaseTest { return "http://localhost:" + port + uri; } + protected String createURLWithPort(String uri, String orchestrationPath) { + return "http://localhost:" + port + orchestrationPath + uri; + } + protected String createURLWithPort(String uri, int iPort) { return "http://localhost:" + iPort + uri; } 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..7b2e502892 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 { @@ -72,6 +71,7 @@ public class InstanceManagementTest extends BaseTest { private String wiremockPort; private final String instanceManagementUri = "/onap/so/infra/instanceManagement/"; + private final String orchestration_path = "/onap/so/infra"; private String uri; private URL selfLink; @@ -93,7 +93,7 @@ public class InstanceManagementTest extends BaseTest { headers.set(ONAP_PARTNER_NAME, "VID"); headers.set(REQUESTOR_ID, "xxxxxx"); try { // generate one-time port number to avoid RANDOM port number later. - initialUrl = new URL(createURLWithPort(Constants.ORCHESTRATION_REQUESTS_PATH)); + initialUrl = new URL(createURLWithPort(Constants.ORCHESTRATION_REQUESTS_PATH, orchestration_path)); initialPort = initialUrl.getPort(); } catch (MalformedURLException e) { e.printStackTrace(); @@ -208,6 +208,35 @@ public class InstanceManagementTest extends BaseTest { } @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<String> 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( ".*/workflow/search/findByArtifactUUID[?]artifactUUID=71526781-e55c-4cb7-adb3-97e09d9c76be")) diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/OrchestrationRequestsTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/OrchestrationRequestsTest.java index 9b892af869..7711608288 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/OrchestrationRequestsTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/OrchestrationRequestsTest.java @@ -133,7 +133,6 @@ public class OrchestrationRequestsTest extends BaseTest { testResponse.getRequest().setRequestProcessingData(new ArrayList<RequestProcessingData>()); RequestProcessingData e = new RequestProcessingData(); e.setGroupingId("7d2e8c07-4d10-456d-bddc-37abf38ca714"); - e.setTag("pincFabricConfigRequest"); List<HashMap<String, String>> data = new ArrayList<HashMap<String, String>>(); HashMap<String, String> data1 = new HashMap<String, String>(); data1.put("requestAction", "assign"); @@ -210,7 +209,6 @@ public class OrchestrationRequestsTest extends BaseTest { testResponse.getRequest().setRequestProcessingData(new ArrayList<RequestProcessingData>()); RequestProcessingData e = new RequestProcessingData(); e.setGroupingId("7d2e8c07-4d10-456d-bddc-37abf38ca714"); - e.setTag("pincFabricConfigRequest"); List<HashMap<String, String>> data = new ArrayList<HashMap<String, String>>(); HashMap<String, String> data1 = new HashMap<String, String>(); data1.put("requestAction", "assign"); @@ -256,7 +254,6 @@ public class OrchestrationRequestsTest extends BaseTest { testResponse.getRequest().setRequestProcessingData(new ArrayList<RequestProcessingData>()); RequestProcessingData e = new RequestProcessingData(); e.setGroupingId("7d2e8c07-4d10-456d-bddc-37abf38ca714"); - e.setTag("pincFabricConfigRequest"); List<HashMap<String, String>> data = new ArrayList<HashMap<String, String>>(); HashMap<String, String> data1 = new HashMap<String, String>(); data1.put("requestAction", "assign"); @@ -463,13 +460,11 @@ public class OrchestrationRequestsTest extends BaseTest { HashMap<String, String> secondExpectedMap = new HashMap<>(); List<RequestProcessingData> expectedDataList = new ArrayList<>(); entry.setGroupingId("7d2e8c07-4d10-456d-bddc-37abf38ca714"); - entry.setTag("pincFabricConfigRequest"); expectedMap.put("requestAction", "assign"); - expectedMap.put("pincFabricId", "testId"); + expectedMap.put("fabricId", "testId"); expectedList.add(expectedMap); entry.setDataPairs(expectedList); secondEntry.setGroupingId("7d2e8c07-4d10-456d-bddc-37abf38ca715"); - secondEntry.setTag("pincFabricConfig"); secondExpectedMap.put("requestAction", "unassign"); secondExpectedList.add(secondExpectedMap); secondEntry.setDataPairs(secondExpectedList); diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/ServiceInstancesTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/ServiceInstancesTest.java index ef90b22b01..33d86a2cc6 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/ServiceInstancesTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/ServiceInstancesTest.java @@ -1,8 +1,6 @@ /*- * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,6 +13,8 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ @@ -97,6 +97,8 @@ public class ServiceInstancesTest extends BaseTest { private final String servInstanceuri = "/onap/so/infra/serviceInstantiation/"; private final String servInstanceUriPrev7 = "/onap/so/infra/serviceInstances/"; + private final String orchestration_path = "/onap/so/infra"; + private String uri; private URL selfLink; private URL initialUrl; @@ -115,7 +117,7 @@ public class ServiceInstancesTest extends BaseTest { headers.set(ONAP_PARTNER_NAME, "VID"); headers.set(REQUESTOR_ID, "xxxxxx"); try { // generate one-time port number to avoid RANDOM port number later. - initialUrl = new URL(createURLWithPort(Constants.ORCHESTRATION_REQUESTS_PATH)); + initialUrl = new URL(createURLWithPort(Constants.ORCHESTRATION_REQUESTS_PATH, orchestration_path)); initialPort = initialUrl.getPort(); } catch (MalformedURLException e) { e.printStackTrace(); diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/infra/rest/handler/AbstractRestHandlerTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/infra/rest/handler/AbstractRestHandlerTest.java index d39192cdf0..6c643c77d7 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/infra/rest/handler/AbstractRestHandlerTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/infra/rest/handler/AbstractRestHandlerTest.java @@ -61,4 +61,15 @@ public class AbstractRestHandlerTest { restHandler.createResponse("instanceId", "requestId", mockRequestContext); assertThat(actualResponse, sameBeanAs(expectedResponse)); } + + @Test + public void test_buildSelfLinkUrl() throws MalformedURLException { + String initialLink = "http://some.domain.com:30277/onap/so/infra/serviceInstantiation/v7/serviceInstances"; + String requestId = "4d0437c3-ee48-4361-a4f7-e1613c82493a"; + Optional<URL> expectedLink = Optional.of(new URL( + "http://some.domain.com:30277/onap/so/infra/orchestrationRequests/v7/4d0437c3-ee48-4361-a4f7-e1613c82493a")); + Optional<URL> resultURL = restHandler.buildSelfLinkUrl(initialLink, requestId); + + assertThat(resultURL, sameBeanAs(expectedLink)); + } } diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/resources/OrchestrationRequest/RequestProcessingData.json b/mso-api-handlers/mso-api-handler-infra/src/test/resources/OrchestrationRequest/RequestProcessingData.json index 79caa33419..a84b2dbe11 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/resources/OrchestrationRequest/RequestProcessingData.json +++ b/mso-api-handlers/mso-api-handler-infra/src/test/resources/OrchestrationRequest/RequestProcessingData.json @@ -4,21 +4,18 @@ "soRequestId": "00032ab7-na18-42e5-965d-8ea592502018", "groupingId": "7d2e8c07-4d10-456d-bddc-37abf38ca714", "name": "requestAction", - "value": "assign", - "tag": "pincFabricConfigRequest" + "value": "assign" },{ "id": 2, "soRequestId": "00032ab7-na18-42e5-965d-8ea592502018", "groupingId": "7d2e8c07-4d10-456d-bddc-37abf38ca714", - "name": "pincFabricId", - "value": "testId", - "tag": "pincFabricConfigRequest" + "name": "fabricId", + "value": "testId" },{ "id": 3, "soRequestId": "00032ab7-na18-42e5-965d-8ea592502018", "groupingId": "7d2e8c07-4d10-456d-bddc-37abf38ca715", "name": "requestAction", - "value": "unassign", - "tag": "pincFabricConfig" + "value": "unassign" } ]
\ No newline at end of file diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/resources/OrchestrationRequest/getRequestProcessingData.json b/mso-api-handlers/mso-api-handler-infra/src/test/resources/OrchestrationRequest/getRequestProcessingData.json index af28007900..6ebe55201a 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/resources/OrchestrationRequest/getRequestProcessingData.json +++ b/mso-api-handlers/mso-api-handler-infra/src/test/resources/OrchestrationRequest/getRequestProcessingData.json @@ -3,6 +3,5 @@ "soRequestId": "00032ab7-na18-42e5-965d-8ea592502018", "groupingId": "7d2e8c07-4d10-456d-bddc-37abf38ca714", "name": "requestAction", - "value": "assign", - "tag": "pincFabricConfigRequest" + "value": "assign" } diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/resources/OrchestrationRequest/getRequestProcessingDataArray.json b/mso-api-handlers/mso-api-handler-infra/src/test/resources/OrchestrationRequest/getRequestProcessingDataArray.json index c746020e7f..c3554c86a5 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/resources/OrchestrationRequest/getRequestProcessingDataArray.json +++ b/mso-api-handlers/mso-api-handler-infra/src/test/resources/OrchestrationRequest/getRequestProcessingDataArray.json @@ -3,6 +3,5 @@ "soRequestId": "00032ab7-na18-42e5-965d-8ea592502018", "groupingId": "7d2e8c07-4d10-456d-bddc-37abf38ca714", "name": "requestAction", - "value": "assign", - "tag": "pincFabricConfigRequest" + "value": "assign" }] 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" +} |