private ExecutionMessage createPendingExecutionMessage(Execution nextStepExecution) { //take care of worker group String groupName = nextStepExecution.getGroupName(); if (groupName == null) { groupName = WorkerNode.DEFAULT_WORKER_GROUPS[0]; } return new ExecutionMessage(ExecutionMessage.EMPTY_EXEC_STATE_ID, ExecutionMessage.EMPTY_WORKER, groupName, executionMessage.getMsgId(), ExecStatus.PENDING, converter.createPayload(nextStepExecution), 0).setWorkerKey(executionMessage.getWorkerKey()); }
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 ExecutionMessage createInProgressExecutionMessage(Execution nextStepExecution) { //take care of worker group String groupName = nextStepExecution.getGroupName(); if (groupName == null) { groupName = WorkerNode.DEFAULT_WORKER_GROUPS[0]; } Long id = queueStateIdGeneratorService.generateStateId(); // stay in the same worker in the next step return new ExecutionMessage(id, executionMessage.getWorkerId(), groupName, executionMessage.getMsgId(), ExecStatus.IN_PROGRESS, nextStepExecution, converter.createPayload(nextStepExecution), 0).setWorkerKey(executionMessage.getWorkerKey()); }
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 boolean shouldChangeWorkerGroup(Execution nextStepExecution) { //Here we check if we can continue to run in current thread - depends on the group if (nextStepExecution.getSystemContext().containsKey(TempConstants.SHOULD_CHECK_GROUP)) { //take care of worker group id String groupName = nextStepExecution.getGroupName(); //clean key nextStepExecution.getSystemContext().remove(TempConstants.SHOULD_CHECK_GROUP); boolean canRunInThisWorker = groupName== null || //does not really matter on what worker to run workerConfigurationService.isMemberOf(groupName) || //this worker is member of the group isStickyToThisWorker(groupName); //next step should run in this worker because of "sticky worker" feature if(!canRunInThisWorker){ //set current step to finished executionMessage.setStatus(ExecStatus.FINISHED); executionMessage.incMsgSeqId(); executionMessage.setPayload(null); ExecutionMessage pendingMessage = createPendingExecutionMessage(nextStepExecution); ExecutionMessage[] executionMessagesToSend = new ExecutionMessage[]{executionMessage, pendingMessage};//Messages that we will send to OutBuffer try { outBuffer.put(executionMessagesToSend); } catch (InterruptedException e) { logger.warn("Thread was interrupted! Exiting the execution... ", e); return true; } return true; } } return false; }