protected void navigate(Execution execution, ExecutionStep currStep) throws InterruptedException { Long position; try { if (currStep.getNavigation() != null) { Map<String, Object> navigationData = new HashMap<>(currStep.getNavigationData()); // We add all the contexts to the step data - so inside of each control action we will have access to all contexts addContextData(navigationData, execution); position = (Long) reflectionAdapter.executeControlAction(currStep.getNavigation(), navigationData); execution.setPosition(position); } else { execution.setPosition(null); // terminate the flow - we got to the last step! } } catch (RuntimeException navEx) { // If Exception occurs in navigation (almost impossible since now we always have Flow Exception Step) we can not continue since we don't know which step is the next step... // terminating... logger.error("Error occurred during navigation execution. Execution id: " + execution.getExecutionId(), navEx); execution.getSystemContext().setStepErrorKey(navEx.getMessage()); // this is done only fo reporting execution.getSystemContext().setFlowTerminationType(ExecutionStatus.SYSTEM_FAILURE); execution.setPosition(null); // this ends the flow!!! try { createErrorEvent(navEx.getMessage(), "Error occurred during navigation execution ", EventConstants.SCORE_STEP_NAV_ERROR, execution.getSystemContext()); } catch (RuntimeException eventEx) { logger.error("Failed to create event: ", eventEx); } } }
private void failFlowIfSplitStepFailed(Execution execution) throws InterruptedException { if (execution.getSystemContext().hasStepErrorKey()) { String exception = execution.getSystemContext().getStepErrorKey(); execution.getSystemContext().setFlowTerminationType(ExecutionStatus.SYSTEM_FAILURE); execution.setPosition(null); // this ends the flow!!! try { createErrorEvent(exception, "Error occurred during split step ", EventConstants.SCORE_STEP_SPLIT_ERROR, execution.getSystemContext()); } catch (RuntimeException eventEx) { logger.error("Failed to create event: ", eventEx); } throw new RuntimeException(exception); } }
private boolean isExecutionCancelled(Execution execution) { if(isCancelledExecution(execution)) { if (logger.isDebugEnabled()) logger.debug("Execution is interrupted by Cancel"); // NOTE: an execution can be cancelled directly from CancelExecutionService, if it's currently paused. // Thus, if you change the code here, please check CancelExecutionService as well. execution.getSystemContext().setFlowTerminationType(ExecutionStatus.CANCELED); execution.setPosition(null); //set current step to finished executionMessage.setStatus(ExecStatus.FINISHED); executionMessage.incMsgSeqId(); executionMessage.setPayload(null); //Flow is finished - does not matter if successfully or not ExecutionMessage terminationMessage = createTerminatedExecutionMessage(execution); ExecutionMessage[] executionMessagesToSend = new ExecutionMessage[]{executionMessage, terminationMessage}; //Messages that we will send to OutBuffer try { outBuffer.put(executionMessagesToSend); } catch (InterruptedException e) { logger.warn("Thread was interrupted While canceling! Exiting the execution... ", e); } return true; } return false; }
protected boolean handleCancelledFlow(Execution execution) { boolean executionIsCancelled = workerConfigurationService.isExecutionCancelled(execution .getExecutionId()); // in this case - just check if need to cancel. It will set as cancelled later on QueueEventListener // Another scenario of getting canceled - it was cancelled from the SplitJoinService (the configuration can still be not updated). Defect #:22060 if (ExecutionStatus.CANCELED.equals(execution.getSystemContext().getFlowTerminationType())) { executionIsCancelled = true; } if (executionIsCancelled) { // NOTE: an execution can be cancelled directly from CancelExecutionService, if it's currently paused. // Thus, if you change the code here, please check CancelExecutionService as well. execution.getSystemContext().setFlowTerminationType(ExecutionStatus.CANCELED); execution.setPosition(null); return true; } return false; }
private void returnCanceledRunToQueue(ExecutionState executionStateToCancel) { // set the context and return the run to the queue. It will be handled on "finishFlow" (QueueEventListener). Execution executionObj = executionSerializationUtil.objFromBytes(executionStateToCancel.getExecutionObject()); if (executionObj == null) { logger.error("Run Object is null. Execution Id = " + executionStateToCancel.getExecutionId() + "; Branch Id = " + executionStateToCancel.getBranchId()); return; } executionObj.getSystemContext().setFlowTerminationType(ExecutionStatus.CANCELED); executionObj.setPosition(null); // just in case - we shouldn't need it, because the Execution is back to the queue as "Terminated" executionStateToCancel.setStatus(ExecutionStatus.PENDING_CANCEL); // clean the DB field executionStateToCancel.setExecutionObject(null); // return execution to queue, as "Terminated" queueDispatcherService.dispatch( String.valueOf(executionObj.getExecutionId()), executionObj.getGroupName(), ExecStatus.TERMINATED, executionMessageConverter.createPayload(executionObj) ); }
private void returnCanceledRunToQueue(ExecutionState executionStateToCancel) { // set the context and return the run to the queue. It will be handled on "finishFlow" (QueueEventListener). Execution executionObj = executionSerializationUtil.objFromBytes(executionStateToCancel.getExecutionObject()); if (executionObj == null) { logger.error("Run Object is null. Execution Id = " + executionStateToCancel.getExecutionId() + "; Branch Id = " + executionStateToCancel.getBranchId()); return; } executionObj.getSystemContext().setFlowTerminationType(ExecutionStatus.CANCELED); executionObj.setPosition(null); // just in case - we shouldn't need it, because the Execution is back to the queue as "Terminated" executionStateToCancel.setStatus(ExecutionStatus.PENDING_CANCEL); // clean the DB field executionStateToCancel.setExecutionObject(null); // return execution to queue, as "Terminated" queueDispatcherService.dispatch( String.valueOf(executionObj.getExecutionId()), executionObj.getGroupName(), ExecStatus.TERMINATED, executionMessageConverter.createPayload(executionObj) ); }
execution.setPosition(null); // this ends the flow!!! return execution;