/** * Returns true when the execution is a branch with the new branch mechanism * It will return true for executions of parallel, multi-instance, sub-flows and non blocking */ private boolean isBranch(Execution execution) { return execution != null && !StringUtils.isEmpty(execution.getSystemContext().getBranchId()); }
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); } }
public StartBranchDataContainer(Long startPosition, Long executionPlanId, Map<String, Serializable> contexts, SystemContext systemContext) { Validate.notNull(startPosition); Validate.notNull(executionPlanId); Validate.notNull(contexts); Validate.notNull(systemContext); this.startPosition = startPosition; this.executionPlanId = executionPlanId; this.systemContext = new SystemContext(systemContext); this.contexts = new HashMap<>(); for (String name : contexts.keySet()) { this.contexts.put(name, contexts.get(name)); } }
public ScoreEvent createFinishedEvent(Execution execution) { String eventType = EventConstants.SCORE_FINISHED_EVENT; Serializable eventData = createFinishedEventData(execution); SystemContext systemContext = execution.getSystemContext(); return new ScoreEvent(eventType, systemContext.getLanguageName(), eventData, systemContext.getMetaData()); }
@Override public FinishedBranch convert(Execution execution) { boolean isBranchCancelled = ExecutionStatus.CANCELED.equals(execution.getSystemContext().getFlowTerminationType()); return new FinishedBranch(execution.getExecutionId().toString(), execution.getSystemContext().getBranchId(), execution.getSystemContext().getSplitId(), execution.getSystemContext().getStepErrorKey(), new BranchContexts(isBranchCancelled, execution.getContexts(), execution.getSystemContext())); } };
logger.debug("finishing branch " + execution.getSystemContext().getBranchId() + " for execution " + execution.getExecutionId()); List<String> splitIds = extract(executions, on(Execution.class).getSystemContext().getSplitId());
private Long pauseExecution(Execution execution) { String branchId = execution.getSystemContext().getBranchId(); ExecutionSummary pe = pauseResumeService.readPausedExecution(execution.getExecutionId(), branchId); //Check if this execution is not paused already (by user) Long pauseId; if (pe == null) { // When cancel execution and no worker in group it should return to be paused without any termination type execution.getSystemContext().setFlowTerminationType(null); pauseId = pauseResumeService.pauseExecution(execution.getExecutionId(), branchId, PauseReason.NO_WORKERS_IN_GROUP); pauseResumeService.writeExecutionObject(execution.getExecutionId(), branchId, execution); } else { pauseId = null; //If yes - just write the object pauseResumeService.writeExecutionObject(execution.getExecutionId(), branchId, execution); } return pauseId; }
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; }
@Override public Long trigger(Long executionId, TriggeringProperties triggeringProperties) { SystemContext scoreSystemContext = new SystemContext(triggeringProperties.getRuntimeValues()); Long runningExecutionPlanId = saveRunningExecutionPlans(triggeringProperties.getExecutionPlan(), triggeringProperties.getDependencies(), scoreSystemContext, String.valueOf(executionId)); scoreSystemContext.setExecutionId(executionId); Map<String,Serializable> executionMetadata = createMetadata(triggeringProperties); scoreSystemContext.putMetaData(executionMetadata); Execution execution = new Execution(executionId, runningExecutionPlanId, triggeringProperties.getStartStep(), triggeringProperties.getContext(), scoreSystemContext); // create execution record in ExecutionSummary table executionStateService.createParentExecution(execution.getExecutionId()); // create execution message ExecutionMessage message = createExecutionMessage(execution); enqueue(message); return executionId; }
exec.getSystemContext().setFinishedChildBranchesData(finishedContexts); exec.getSystemContext().setFlowTerminationType(ExecutionStatus.CANCELED);
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; }
} catch (TimeoutException timeout) { logger.error("Timed out waiting for cancel for execution id " + execution.getExecutionId()); execution.getSystemContext().setStepErrorKey(timeoutMessage); if (execution.getSystemContext().isPaused()) { if (handlePausedFlowAfterStep(execution)) { return null; } catch (Exception ex) { logger.error("Error during execution: ", ex); execution.getSystemContext().setStepErrorKey(ex.getMessage()); // this is done only fo reporting execution.getSystemContext().setFlowTerminationType(ExecutionStatus.SYSTEM_FAILURE);
@Override public Long reTrigger(SystemContext newSystemContext, byte[] executionObj) { Execution execution = executionMessageConverter.extractExecution(new Payload(executionObj)); //We must refresh the system context with the new one in order to re-trigger execution.getSystemContext().clear(); execution.getSystemContext().putAll(newSystemContext); //generate new execution id Long newExecutionId = idGenerator.next(); execution.getSystemContext().setExecutionId(newExecutionId); execution.setExecutionId(newExecutionId); // create execution record in ExecutionSummary table executionStateService.createParentExecution(execution.getExecutionId()); // create execution message ExecutionMessage message = createExecutionMessage(execution); queueDispatcher.dispatch(Collections.singletonList(message)); return newExecutionId; }
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 String getSplitId(List<Execution> newExecutions) { if (newExecutions != null && newExecutions.size() > 0) { return newExecutions.get(0).getSystemContext().getSplitId(); } throw new RuntimeException("Split executions list is null or empty!!!"); } }
private boolean isCancelledExecution(Execution execution) { if(execution==null) return false; 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; } return executionIsCancelled; }
public Execution(Long executionId, Long runningExecutionPlanId, Long position, Map<String, ? extends Serializable> contexts, Map<String, Serializable> systemContext) { this(runningExecutionPlanId, position, contexts); if(systemContext != null) { this.systemContext.putAll(systemContext); } this.executionId = executionId; }
private void updateMetadata(Execution execution, RunningExecutionPlan runningExecutionPlan) { Map<String, Serializable> executionMetadata = (Map<String, Serializable>) execution.getSystemContext() .getMetaData(); ExecutionPlan executionPlan = runningExecutionPlan.getExecutionPlan(); executionMetadata.put(ExecutionMetadataConsts.EXECUTION_PLAN_ID, executionPlan.getFlowUuid()); executionMetadata.put(ExecutionMetadataConsts.EXECUTION_PLAN_NAME, executionPlan.getName()); }
@Override public FinishedBranch convert(Execution execution) { boolean isBranchCancelled = ExecutionStatus.CANCELED.equals(execution.getSystemContext().getFlowTerminationType()); return new FinishedBranch(execution.getExecutionId().toString(), execution.getSystemContext().getBranchId(), execution.getSystemContext().getSplitId(), execution.getSystemContext().getStepErrorKey(), new BranchContexts(isBranchCancelled, execution.getContexts(), execution.getSystemContext())); } };
logger.debug("finishing branch " + execution.getSystemContext().getBranchId() + " for execution " + execution.getExecutionId()); List<String> splitIds = extract(executions, on(Execution.class).getSystemContext().getSplitId());