aboutsummaryrefslogtreecommitdiffstats
path: root/mso-api-handlers/mso-api-handler-infra/src/main
diff options
context:
space:
mode:
authorYulian Han <elaine.hanyulian@huawei.com>2020-01-02 00:31:28 +0800
committerYulian Han <elaine.hanyulian@huawei.com>2020-01-02 00:31:28 +0800
commitcd30f0cb0f6fe465d13a97e55359bd6bea158f08 (patch)
tree64ee6035397fceb3cb7b14138137d2cfd69e011e /mso-api-handlers/mso-api-handler-infra/src/main
parent6416fa05f3a54c0a95e9ab41927b74cb8e0e68f8 (diff)
SO API to support custom PNF workflow
Change-Id: Idaa55084f5ecb0dd3636c232cebc14fa5f064418 Issue-ID: SO-2071 Signed-off-by: Yulian Han <elaine.hanyulian@huawei.com>
Diffstat (limited to 'mso-api-handlers/mso-api-handler-infra/src/main')
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/Action.java3
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/InstanceManagement.java109
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/MsoRequest.java11
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/RequestHandlerUtils.java19
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/validation/CustomWorkflowValidation.java8
5 files changed, 138 insertions, 12 deletions
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/Action.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/Action.java
index d0302f2e59..88c4bc3b04 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/Action.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/Action.java
@@ -45,5 +45,6 @@ public enum Action implements Actions {
scaleOut,
recreateInstance,
addMembers,
- removeMembers
+ removeMembers,
+ forCustomWorkflow
}
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 d3bd769386..dbdc274bc6 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
@@ -96,7 +96,7 @@ public class InstanceManagement {
@Operation(description = "Execute custom workflow", responses = @ApiResponse(
content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
@Transactional
- public Response executeCustomWorkflow(String request, @PathParam("version") String version,
+ public Response executeVNFCustomWorkflow(String request, @PathParam("version") String version,
@PathParam("serviceInstanceId") String serviceInstanceId, @PathParam("vnfInstanceId") String vnfInstanceId,
@PathParam("workflowUuid") String workflowUuid, @Context ContainerRequestContext requestContext)
throws ApiException {
@@ -109,6 +109,26 @@ public class InstanceManagement {
requestContext);
}
+ @POST
+ @Path("/{version:[vV][1]}/serviceInstances/{serviceInstanceId}/pnfs/{pnfId}/workflows/{workflowUuid}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Execute custom workflow", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @Transactional
+ public Response executePNFCustomWorkflow(String request, @PathParam("version") String version,
+ @PathParam("serviceInstanceId") String serviceInstanceId, @PathParam("pnfId") String pnfId,
+ @PathParam("workflowUuid") String workflowUuid, @Context ContainerRequestContext requestContext)
+ throws ApiException {
+ String requestId = requestHandlerUtils.getRequestId(requestContext);
+ HashMap<String, String> instanceIdMap = new HashMap<>();
+ instanceIdMap.put("serviceInstanceId", serviceInstanceId);
+ instanceIdMap.put("pnfId", pnfId);
+ instanceIdMap.put("workflowUuid", workflowUuid);
+ return processPNFCustomWorkflowRequest(request, Action.forCustomWorkflow, instanceIdMap, version, requestId,
+ requestContext);
+ }
+
private Response processCustomWorkflowRequest(String requestJSON, Actions action,
HashMap<String, String> instanceIdMap, String version, String requestId,
ContainerRequestContext requestContext) throws ApiException {
@@ -217,6 +237,93 @@ public class InstanceManagement {
recipeLookupResult.getOrchestrationURI(), requestScope);
}
+ 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 pnfId = "";
+ String workflowUuid = "";
+ if (instanceIdMap != null) {
+ serviceInstanceId = instanceIdMap.get("serviceInstanceId");
+ pnfId = instanceIdMap.get("pnfId");
+ workflowUuid = instanceIdMap.get("workflowUuid");
+ }
+
+ String requestUri = requestHandlerUtils.getRequestUri(requestContext, uriPrefix);
+ sir = requestHandlerUtils.convertJsonToServiceInstanceRequest(requestJSON, action, requestId, requestUri);
+ sir.setServiceInstanceId(serviceInstanceId);
+ sir.setPnfId(pnfId);
+ 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);
+
+ InfraActiveRequests dup = null;
+ boolean inProgress = false;
+
+ dup = requestHandlerUtils.duplicateCheck(action, instanceIdMap, null, requestScope, currentActiveReq);
+
+ if (dup != null) {
+ inProgress = requestHandlerUtils.camundaHistoryCheck(dup, currentActiveReq);
+ }
+
+ if (dup != null && inProgress) {
+ requestHandlerUtils.buildErrorOnDuplicateRecord(currentActiveReq, action, instanceIdMap, null, requestScope,
+ dup);
+ }
+
+ RecipeLookupResult recipeLookupResult = getInstanceManagementWorkflowRecipe(currentActiveReq, workflowUuid);
+
+ try {
+ infraActiveRequestsClient.save(currentActiveReq);
+ } catch (Exception e) {
+ ErrorLoggerInfo errorLoggerInfo =
+ new ErrorLoggerInfo.Builder(MessageEnum.APIH_DB_ACCESS_EXC, ErrorCode.DataError)
+ .errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build();
+ throw new RequestDbFailureException.Builder(SAVE_TO_DB, e.toString(), HttpStatus.SC_INTERNAL_SERVER_ERROR,
+ ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).cause(e).errorInfo(errorLoggerInfo).build();
+ }
+
+ RequestClientParameter requestClientParameter = null;
+ try {
+ requestClientParameter = new RequestClientParameter.Builder().setRequestId(requestId)
+ .setRecipeTimeout(recipeLookupResult.getRecipeTimeout()).setRequestAction(action.toString())
+ .setServiceInstanceId(serviceInstanceId).setPnfCorrelationId(pnfId)
+ .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 = null;
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 2307a18c1a..0e9ed78eac 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
@@ -318,9 +318,16 @@ public class MsoRequest {
aq.setVnfId(servInsReq.getVnfInstanceId());
}
+ if (servInsReq.getPnfId() != null) {
+ aq.setRequestScope(requestScope);
+ aq.setPnfId(servInsReq.getPnfId());
+ }
+
if (ModelType.service.name().equalsIgnoreCase(requestScope)) {
- if (servInsReq.getRequestDetails().getRequestInfo().getInstanceName() != null) {
- aq.setServiceInstanceName(requestInfo.getInstanceName());
+ if (servInsReq.getRequestDetails().getRequestInfo() != null) {
+ if (servInsReq.getRequestDetails().getRequestInfo().getInstanceName() != null) {
+ aq.setServiceInstanceName(requestInfo.getInstanceName());
+ }
}
}
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 b078aed6ac..a7c03f9070 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
@@ -275,12 +275,18 @@ public class RequestHandlerUtils extends AbstractRestHandler {
} else if (action == Action.addMembers || action == Action.removeMembers) {
return (ModelType.instanceGroup.toString());
} else {
- String requestScope;
+ String requestScope = requestScopeFromUri(requestUri);;
+
+ if (sir.getRequestDetails() == null) {
+ return requestScope;
+ }
+ if (sir.getRequestDetails().getModelInfo() == null) {
+ return requestScope;
+ }
if (sir.getRequestDetails().getModelInfo().getModelType() == null) {
- requestScope = requestScopeFromUri(requestUri);
- } else {
- requestScope = sir.getRequestDetails().getModelInfo().getModelType().name();
+ return requestScope;
}
+ requestScope = sir.getRequestDetails().getModelInfo().getModelType().name();
return requestScope;
}
}
@@ -505,6 +511,9 @@ public class RequestHandlerUtils extends AbstractRestHandler {
if (instanceIdMap.get(CommonConstants.INSTANCE_GROUP_INSTANCE_ID) != null) {
currentActiveReq.setInstanceGroupId(instanceIdMap.get(CommonConstants.INSTANCE_GROUP_INSTANCE_ID));
}
+ if (instanceIdMap.get("PnfId") != null) {
+ currentActiveReq.setPnfId(instanceIdMap.get("PnfId"));
+ }
}
}
@@ -610,6 +619,8 @@ public class RequestHandlerUtils extends AbstractRestHandler {
requestScope = ModelType.configuration.name();
} else if (requestUri.contains(ModelType.vnf.name())) {
requestScope = ModelType.vnf.name();
+ } else if (requestUri.contains(ModelType.pnf.name())) {
+ requestScope = ModelType.pnf.name();
} else {
requestScope = ModelType.service.name();
}
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/validation/CustomWorkflowValidation.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/validation/CustomWorkflowValidation.java
index 01e3de99ec..c05ef98fbb 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/validation/CustomWorkflowValidation.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/validation/CustomWorkflowValidation.java
@@ -35,13 +35,13 @@ public class CustomWorkflowValidation implements ValidationRule {
CloudConfiguration cloudConfiguration = info.getSir().getRequestDetails().getCloudConfiguration();
if (cloudConfiguration == null) {
- throw new ValidationException("cloudConfiguration");
+ // throw new ValidationException("cloudConfiguration");
} else if (Strings.isNullOrEmpty((cloudConfiguration.getCloudOwner()))) {
- throw new ValidationException("cloudOwner");
+ // throw new ValidationException("cloudOwner");
} else if (Strings.isNullOrEmpty((cloudConfiguration.getLcpCloudRegionId()))) {
- throw new ValidationException("lcpCloudRegionId");
+ // throw new ValidationException("lcpCloudRegionId");
} else if (Strings.isNullOrEmpty((cloudConfiguration.getTenantId()))) {
- throw new ValidationException("tenantId");
+ // throw new ValidationException("tenantId");
}
if (requestParameters == null) {
throw new ValidationException("requestParameters");