summaryrefslogtreecommitdiffstats
path: root/mso-api-handlers/mso-api-handler-infra/src
diff options
context:
space:
mode:
Diffstat (limited to 'mso-api-handlers/mso-api-handler-infra/src')
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/InstanceManagement.java228
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/MsoRequest.java5
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/RequestHandlerUtils.java8
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/WorkflowSpecificationsHandler.java29
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/validation/InstanceIdMapValidation.java9
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/validation/ValidationInformation.java10
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/InstanceManagementTest.java38
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/WorkflowSpecificationsHandlerTest.java53
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/test/resources/ServiceInstanceTest/ExecuteServiceLevelCustomWorkflow.json39
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/catalogdb/WorkflowSpecificationsForService.json20
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/catalogdb/WorkflowSpecificationsForServiceWorkflows_Response.json41
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/catalogdb/workflow_ServiceLevel_Response.json6
12 files changed, 314 insertions, 172 deletions
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/WorkflowSpecificationsHandler.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/WorkflowSpecificationsHandler.java
index 357497591d..0f7cf5fc6a 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/WorkflowSpecificationsHandler.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/WorkflowSpecificationsHandler.java
@@ -81,12 +81,13 @@ public class WorkflowSpecificationsHandler {
@Transactional
public Response queryWorkflowSpecifications(@QueryParam("vnfModelVersionId") String vnfModelVersionId,
- @QueryParam("pnfModelVersionId") String pnfModelVersionId, @PathParam("version") String version)
+ @QueryParam("pnfModelVersionId") String pnfModelVersionId,
+ @QueryParam("resourceTarget") String resourceTarget, @PathParam("version") String version)
throws Exception {
String apiVersion = version.substring(1);
List<Workflow> workflows = new ArrayList<>();
- if (vnfModelVersionId == null && pnfModelVersionId == null) {
+ if (vnfModelVersionId == null && pnfModelVersionId == null && resourceTarget == null) {
workflows.addAll(queryWorkflowSpecificationsForAll());
} else {
// 1. query workflow specifications for given vnfModelVersionId if need.
@@ -106,6 +107,16 @@ public class WorkflowSpecificationsHandler {
workflows.addAll(pnfWorkflows);
}
}
+
+ // 3. query workflow specifications for given resourceTarget
+ if (resourceTarget != null) {
+ List<Workflow> workflowsForResourceTarget = queryWorkflowsForResourceTarget(resourceTarget);
+ logger.debug(
+ "Retrieved " + workflowsForResourceTarget.size() + " workflows for given resource target.");
+ if (workflowsForResourceTarget.size() > 0) {
+ workflows.addAll(workflowsForResourceTarget);
+ }
+ }
}
// Deduplication
@@ -119,11 +130,16 @@ public class WorkflowSpecificationsHandler {
apiVersion);
}
+ /**
+ * @deprecated As of G release, workflows for all resource types (pnf,vnf,service) can be fetched using
+ * /workflowSpecifications/{version:[vV]1}/workflows?resourceTarget={resourceType} API
+ */
@Path("/{version:[vV]1}/pnfWorkflows")
@GET
@Operation(description = "Finds pnf workflow specifications", responses = @ApiResponse(
content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
@Transactional
+ @Deprecated
public Response getWorkflowsSpecForPnf(@PathParam("version") String version) throws Exception {
final String pnf_resource = "pnf";
@@ -132,7 +148,7 @@ public class WorkflowSpecificationsHandler {
ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
- List<Workflow> workflows = catalogDbClient.findWorkflowByResourceTarget(pnf_resource);
+ List<Workflow> workflows = queryWorkflowsForResourceTarget(pnf_resource);
Optional<String> optional = getResponseByWorkflowSpec(workflows);
return builder.buildResponse(HttpStatus.SC_OK, "", optional.isPresent() ? optional.get() : EMPTY_BODY,
@@ -296,4 +312,11 @@ public class WorkflowSpecificationsHandler {
List<Workflow> workflows = catalogDbClient.findWorkflowByPnfModelUUID(pnfModelVersionId);
return workflows;
}
+
+ private List<Workflow> queryWorkflowsForResourceTarget(String resourceTarget) {
+ List<Workflow> workflows = catalogDbClient.findWorkflowByResourceTarget(resourceTarget);
+ return workflows;
+ }
+
+
}
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/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 {
@@ -208,6 +207,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/WorkflowSpecificationsHandlerTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/WorkflowSpecificationsHandlerTest.java
index 4ab88f40f6..1fa71cefc2 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/WorkflowSpecificationsHandlerTest.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/WorkflowSpecificationsHandlerTest.java
@@ -58,6 +58,9 @@ public class WorkflowSpecificationsHandlerTest extends BaseTest {
@Autowired
WorkflowSpecificationsHandler workflowSpecificationsHandler;
+ @Autowired
+ ObjectMapper mapper;
+
@Value("${wiremock.server.port}")
private String wiremockPort;
@@ -152,7 +155,6 @@ public class WorkflowSpecificationsHandlerTest extends BaseTest {
assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
- ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
WorkflowSpecifications expectedResponse = mapper.readValue(
@@ -306,7 +308,6 @@ public class WorkflowSpecificationsHandlerTest extends BaseTest {
WorkflowSpecifications workflowSpecifications =
workflowSpecificationsHandler.mapWorkflowsToWorkflowSpecifications(workflows);
- ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
String workflowSpecificationsJson = mapper.writeValueAsString(workflowSpecifications);
@@ -349,7 +350,6 @@ public class WorkflowSpecificationsHandlerTest extends BaseTest {
assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
- ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
WorkflowSpecifications expectedResponse = mapper.readValue(
@@ -367,6 +367,52 @@ public class WorkflowSpecificationsHandlerTest extends BaseTest {
}
@Test
+ public void queryWorkflowSpecificationsByResourceTarget_Test_Success() throws JSONException, IOException {
+
+ String URL_PATH = basePath + "/v1/workflows";
+ HttpHeaders headers = new HttpHeaders();
+ headers.set("Accept", MediaType.APPLICATION_JSON);
+ headers.set("Content-Type", MediaType.APPLICATION_JSON);
+ HttpEntity<String> entity = new HttpEntity<String>(null, headers);
+ String WORKFLOW_QUERY = "/workflow/search/findByResourceTarget[?]resourceTarget=service";
+ String WORKFLOW_SPEC_QUERY = "/workflow/5/workflowActivitySpecSequence";
+ String JSON_FILE_PATH = "src/test/resources/__files/catalogdb/WorkflowSpecificationsForService.json";
+ String MOCK_RESP_FILE = "WorkflowSpecificationsForServiceWorkflows_Response.json";
+ String MOCK_RESP_SPEC_FILE = "Empty_workflowActivitySpecSequence_Response.json";
+
+ wireMockServer.stubFor(get(urlMatching(WORKFLOW_QUERY))
+ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .withBody(getWiremockResponseForCatalogdb(MOCK_RESP_FILE))
+ .withStatus(org.apache.http.HttpStatus.SC_OK)));
+
+ wireMockServer.stubFor(get(urlMatching(WORKFLOW_SPEC_QUERY))
+ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .withBody(getWiremockResponseForCatalogdb(MOCK_RESP_SPEC_FILE))
+ .withStatus(org.apache.http.HttpStatus.SC_OK)));
+
+ UriComponentsBuilder builder =
+ UriComponentsBuilder.fromHttpUrl(createURLWithPort(URL_PATH)).queryParam("resourceTarget", "service");
+
+ ResponseEntity<String> response =
+ restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, String.class);
+
+ assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
+
+ mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+
+ WorkflowSpecifications expectedResponse = mapper
+ .readValue(new String(Files.readAllBytes(Paths.get(JSON_FILE_PATH))), WorkflowSpecifications.class);
+ WorkflowSpecifications realResponse = mapper.readValue(response.getBody(), WorkflowSpecifications.class);
+
+ assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
+ assertThat(expectedResponse, sameBeanAs(realResponse));
+ assertEquals("application/json", response.getHeaders().get(HttpHeaders.CONTENT_TYPE).get(0));
+ assertEquals("0", response.getHeaders().get("X-MinorVersion").get(0));
+ assertEquals("0", response.getHeaders().get("X-PatchVersion").get(0));
+ assertEquals("1.0.0", response.getHeaders().get("X-LatestVersion").get(0));
+ }
+
+ @Test
public void testWorkflowSpecificationsForPnf_Success() throws JSONException, IOException {
final String urlPath = basePath + "/v1/pnfWorkflows";
@@ -397,7 +443,6 @@ public class WorkflowSpecificationsHandlerTest extends BaseTest {
assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
- ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
WorkflowSpecifications expectedResponse = mapper.readValue(
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/WorkflowSpecificationsForService.json b/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/catalogdb/WorkflowSpecificationsForService.json
new file mode 100644
index 0000000000..aaaad17470
--- /dev/null
+++ b/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/catalogdb/WorkflowSpecificationsForService.json
@@ -0,0 +1,20 @@
+{
+ "workflowSpecificationList": [
+ {
+ "workflowSpecification": {
+ "artifactInfo": {
+ "artifactType": "workflow",
+ "artifactUuid": "a1fe8726-66d5-3e7f-2212-7e5h662e9255",
+ "artifactName": "DummyServiceWorkflow",
+ "artifactVersion": "1.0",
+ "artifactDescription": "Dummy Service Workflow to test custom Service workflow",
+ "workflowName": "Dummy Service Workflow",
+ "operationName": "DummyServiceWorkflow",
+ "workflowSource": "native",
+ "workflowResourceTarget": "service"
+ },
+ "workflowInputParameters": []
+ }
+ }
+ ]
+} \ No newline at end of file
diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/catalogdb/WorkflowSpecificationsForServiceWorkflows_Response.json b/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/catalogdb/WorkflowSpecificationsForServiceWorkflows_Response.json
new file mode 100644
index 0000000000..9a836e033b
--- /dev/null
+++ b/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/catalogdb/WorkflowSpecificationsForServiceWorkflows_Response.json
@@ -0,0 +1,41 @@
+{
+ "_embedded": {
+ "workflow": [
+ {
+ "artifactChecksum": "MANUAL RECORD",
+ "artifactName": "DummyServiceWorkflow",
+ "artifactUUID": "a1fe8726-66d5-3e7f-2212-7e5h662e9255",
+ "body": null,
+ "created": "2020-06-29T08:28:15.000+0000",
+ "description": "Dummy Service Workflow to test custom Service workflow",
+ "id": 4,
+ "name": "Dummy Service Workflow",
+ "operationName": "DummyServiceWorkflow",
+ "pnfResourceWorkflow": null,
+ "resourceTarget": "service",
+ "source": "native",
+ "timeoutMinutes": null,
+ "version": 1.0,
+ "_links": {
+ "self": {
+ "href": "http://localhost:8090/workflow/search/findByResourceTarget?resourceTarget=service"
+ },
+ "workflow": {
+ "href": "http://localhost:8090/workflow/5"
+ },
+ "workflowActivitySpecSequence": {
+ "href": "http://localhost:8090/workflow/5/workflowActivitySpecSequence"
+ }
+ }
+ }
+ ]
+ },
+ "_links": {
+ "self": {
+ "href": "http://localhost:8090/workflow/search/findByResourceTarget?resourceTarget=service"
+ },
+ "workflowActivitySpecSequence": {
+ "href": "http://localhost:8090/workflow/5/workflowActivitySpecSequence"
+ }
+ }
+} \ No newline at end of file
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"
+}