Search in sources :

Example 1 with WorkflowProcessorException

use of org.openecomp.mso.bpmn.common.workflow.service.WorkflowProcessorException in project so by onap.

the class WorkflowAsyncResource method startProcessInstanceByKey.

/**
 * Asynchronous JAX-RS method that starts a process instance.
 *
 * @param processKey the process key
 * @param variableMap input variables to the process
 * @return
 */
@POST
@Path("/services/{processKey}")
@Operation(description = "Starts a new process with the appropriate process Key. Aysnc fall outs are only logged")
@Produces("application/json")
@Consumes("application/json")
public Response startProcessInstanceByKey(@PathParam("processKey") String processKey, VariableMapImpl variableMap) {
    Map<String, Object> inputVariables = getInputVariables(variableMap);
    try {
        MDC.put(ONAPLogConstants.MDCs.REQUEST_ID, getRequestId(inputVariables));
        processor.startProcess(processKey, variableMap);
        WorkflowResponse response = waitForResponse(inputVariables);
        if (response.getMessageCode() == 500) {
            return Response.status(500).entity(response).build();
        } else {
            return Response.status(202).entity(response).build();
        }
    } catch (WorkflowProcessorException e) {
        WorkflowResponse response = e.getWorkflowResponse();
        return Response.status(500).entity(response).build();
    } catch (Exception e) {
        WorkflowResponse response = buildUnkownError(getRequestId(inputVariables), e.getMessage());
        return Response.status(500).entity(response).build();
    }
}
Also used : WorkflowResponse(org.onap.so.bpmn.common.workflow.context.WorkflowResponse) WorkflowProcessorException(org.openecomp.mso.bpmn.common.workflow.service.WorkflowProcessorException) WorkflowProcessorException(org.openecomp.mso.bpmn.common.workflow.service.WorkflowProcessorException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) Operation(io.swagger.v3.oas.annotations.Operation)

Example 2 with WorkflowProcessorException

use of org.openecomp.mso.bpmn.common.workflow.service.WorkflowProcessorException in project so by onap.

the class WorkflowProcessor method startProcess.

@Async
public void startProcess(String processKey, VariableMapImpl variableMap) {
    Map<String, Object> inputVariables;
    String processInstanceId = null;
    try {
        inputVariables = getInputVariables(variableMap);
        // This variable indicates that the flow was invoked asynchronously
        inputVariables.put("isAsyncProcess", "true");
        // Note: this creates a random businessKey if it wasn't specified.
        String businessKey = getBusinessKey(inputVariables);
        logger.debug("***Received MSO startProcessInstanceByKey with processKey: {} and variables: {}", processKey, inputVariables);
        RuntimeService runtimeService = getProcessEngineServices().getRuntimeService();
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(processKey, businessKey, inputVariables);
        processInstanceId = processInstance.getId();
        logger.debug(logMarker + "Process " + processKey + ":" + processInstanceId + " " + (processInstance.isEnded() ? "ENDED" : "RUNNING"));
    } catch (Exception e) {
        WorkflowResponse workflowResponse = new WorkflowResponse();
        workflowResponse.setResponse("Error occurred while executing the process: " + e);
        workflowResponse.setProcessInstanceID(processInstanceId);
        workflowResponse.setMessageCode(500);
        workflowResponse.setMessage("Fail");
        throw new WorkflowProcessorException(workflowResponse);
    }
}
Also used : RuntimeService(org.camunda.bpm.engine.RuntimeService) WorkflowResponse(org.onap.so.bpmn.common.workflow.context.WorkflowResponse) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) WorkflowProcessorException(org.openecomp.mso.bpmn.common.workflow.service.WorkflowProcessorException) WorkflowProcessorException(org.openecomp.mso.bpmn.common.workflow.service.WorkflowProcessorException) Async(org.springframework.scheduling.annotation.Async)

Aggregations

WorkflowResponse (org.onap.so.bpmn.common.workflow.context.WorkflowResponse)2 WorkflowProcessorException (org.openecomp.mso.bpmn.common.workflow.service.WorkflowProcessorException)2 Operation (io.swagger.v3.oas.annotations.Operation)1 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 RuntimeService (org.camunda.bpm.engine.RuntimeService)1 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)1 Async (org.springframework.scheduling.annotation.Async)1