diff options
author | Chuanyu Chen <chenchuanyu@huawei.com> | 2020-02-27 01:05:54 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2020-02-27 01:05:54 +0000 |
commit | 5e18e8dfb30778f1dd2d6bba2644f58c6b8315ec (patch) | |
tree | af8603182c66171f633ccf267511d7e9747a5d0a /mso-api-handlers/mso-api-handler-infra/src | |
parent | 3d6d255441d913e28639a74c52b057878c6a3b94 (diff) | |
parent | 5b19af9fc6416273b0ac02278f1f8b96ac8d1978 (diff) |
Merge "Add API for commit and abort OrchestrationTask"
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/OrchestrationTasks.java | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/OrchestrationTasks.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/OrchestrationTasks.java index 21129d7c2d..90cf50262b 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/OrchestrationTasks.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/OrchestrationTasks.java @@ -206,4 +206,95 @@ public class OrchestrationTasks { } } + @POST + @Path("/{version:[vV][4-7]}/{taskId}/commit") + @Operation(description = "Commit an Orchestrated Task", responses = @ApiResponse( + content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class))))) + @Produces(MediaType.APPLICATION_JSON) + @Transactional + public Response CommitOrchestrationTask(@PathParam("taskId") String taskId, @PathParam("version") String version) { + OrchestrationTask orchestrationTask; + try { + orchestrationTask = requestsDbClient.getOrchestrationTask(taskId); + } catch (Exception e) { + logger.error(LoggingAnchor.FOUR, MessageEnum.APIH_DB_ACCESS_EXC.toString(), MSO_PROP_APIHANDLER_INFRA, + ErrorCode.AvailabilityError.getValue(), + "Exception while communciate with Request DB - Orchestration Task Commit", e); + Response response = + msoRequest.buildServiceErrorResponse(HttpStatus.SC_NOT_FOUND, MsoException.ServiceException, + e.getMessage(), ErrorNumbers.NO_COMMUNICATION_TO_REQUESTS_DB, null, version); + return response; + } + try { + String taskName = orchestrationTask.getName(); + Map<String, String> commitVar = new HashMap<>(); + commitVar.put("taskAction", "commit"); + JSONObject msgJson = createMessageBody(taskId, taskName, commitVar); + camundaRequestHandler.sendCamundaMessages(msgJson); + return builder.buildResponse(HttpStatus.SC_OK, null, orchestrationTask, version); + } catch (Exception e) { + logger.error(LoggingAnchor.FOUR, MessageEnum.APIH_DB_ACCESS_EXC.toString(), MSO_PROP_APIHANDLER_INFRA, + ErrorCode.AvailabilityError.getValue(), + "Exception while communciate with Request DB - Orchestration Task Delete", e); + Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_INTERNAL_SERVER_ERROR, + MsoException.ServiceException, e.getMessage(), ErrorNumbers.ERROR_FROM_BPEL, null, version); + return response; + } + + } + + @POST + @Path("/{version:[vV][4-7]}/{taskId}/abort") + @Operation(description = "Commit an Orchestrated Task", responses = @ApiResponse( + content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class))))) + @Produces(MediaType.APPLICATION_JSON) + @Transactional + public Response AbortOrchestrationTask(@PathParam("taskId") String taskId, @PathParam("version") String version) { + OrchestrationTask orchestrationTask; + try { + orchestrationTask = requestsDbClient.getOrchestrationTask(taskId); + } catch (Exception e) { + logger.error(LoggingAnchor.FOUR, MessageEnum.APIH_DB_ACCESS_EXC.toString(), MSO_PROP_APIHANDLER_INFRA, + ErrorCode.AvailabilityError.getValue(), + "Exception while communciate with Request DB - Orchestration Task Commit", e); + Response response = + msoRequest.buildServiceErrorResponse(HttpStatus.SC_NOT_FOUND, MsoException.ServiceException, + e.getMessage(), ErrorNumbers.NO_COMMUNICATION_TO_REQUESTS_DB, null, version); + return response; + } + try { + String taskName = orchestrationTask.getName(); + Map<String, String> commitVar = new HashMap<>(); + commitVar.put("taskAction", "abort"); + JSONObject msgJson = createMessageBody(taskId, taskName, commitVar); + camundaRequestHandler.sendCamundaMessages(msgJson); + return builder.buildResponse(HttpStatus.SC_OK, null, orchestrationTask, version); + } catch (Exception e) { + logger.error(LoggingAnchor.FOUR, MessageEnum.APIH_DB_ACCESS_EXC.toString(), MSO_PROP_APIHANDLER_INFRA, + ErrorCode.AvailabilityError.getValue(), + "Exception while communciate with Request DB - Orchestration Task Delete", e); + Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_INTERNAL_SERVER_ERROR, + MsoException.ServiceException, e.getMessage(), ErrorNumbers.ERROR_FROM_BPEL, null, version); + return response; + } + + } + + private JSONObject createMessageBody(String taskId, String taskName, Map<String, ?> variables) { + JSONObject msgJson = new JSONObject(); + msgJson.put("messageName", taskName); + msgJson.put("businessKey", taskId); + JSONObject processVariables = new JSONObject(); + for (Map.Entry<String, ?> entry : variables.entrySet()) { + JSONObject valueInfo = new JSONObject(); + String key = entry.getKey(); + Object value = entry.getValue(); + valueInfo.put("value", value.toString()); + valueInfo.put("type", value.getClass().getSimpleName()); + processVariables.put(key, valueInfo); + } + msgJson.put("processVariables", processVariables); + return msgJson; + } + } |