private void fillPayload(ExecutionMessage msg) { if (msg.getPayload() == null){ Map<Long, Payload> payloadMap = executionQueueService.readPayloadByExecutionIds(msg.getExecStateId()); Payload payload = payloadMap.get(msg.getExecStateId()); msg.setPayload(payload); } }
private boolean isExecutionPaused(Execution nextStepExecution) { //If execution was paused if(nextStepExecution == null){ //set current step to finished executionMessage.setStatus(ExecStatus.FINISHED); executionMessage.incMsgSeqId(); executionMessage.setPayload(null); //execution was paused - send only the FINISHED message! try { outBuffer.put(executionMessage); } catch (InterruptedException e) { logger.warn("Thread was interrupted! Exiting the execution... ", e); } return true; } else { return false; } }
private boolean isRunningTooLong(Long startTime, Execution nextStepExecution) { Long currentTime = System.currentTimeMillis(); //Return true if running more than 60 seconds. //We want to exit after 60 seconds from this thread in order to prevent starvation of other tasks. if ((currentTime - startTime) > 60 * 1000) { //set current step to finished executionMessage.setStatus(ExecStatus.FINISHED); executionMessage.incMsgSeqId(); executionMessage.setPayload(null); ExecutionMessage inProgressMessage = createInProgressExecutionMessage(nextStepExecution); ExecutionMessage[] executionMessagesToSend = new ExecutionMessage[]{executionMessage, inProgressMessage}; //for the outBuffer ExecutionMessage inProgressMessageForInBuffer = (ExecutionMessage) inProgressMessage.clone(); inProgressMessageForInBuffer.setPayload(null); //we do not need the payload for the inBuffer shortcut try { //The order is important!!!!! outBuffer.put(executionMessagesToSend); inBuffer.addExecutionMessage(inProgressMessageForInBuffer); } catch (InterruptedException e) { logger.warn("Thread was interrupted! Exiting the execution... ", e); return true; //exiting... in shutdown... } return true; } else { return false; } }
private ExecutionMessage createTerminatedExecutionMessage(Execution nextStepExecution) { Payload payload = converter.createPayload(nextStepExecution); //we need the payload ExecutionMessage finalMessage = (ExecutionMessage) executionMessage.clone(); finalMessage.setStatus(ExecStatus.TERMINATED); //in queue it is checked and finish flow is called finalMessage.incMsgSeqId(); finalMessage.setPayload(payload); return finalMessage; }
private void executeSplitStep(Execution execution) throws InterruptedException { //If execution is paused or cancelled it will return false List<Execution> newExecutions = executionService.executeSplit(execution); //set current step to finished executionMessage.setStatus(ExecStatus.FINISHED); executionMessage.incMsgSeqId(); executionMessage.setPayload(null); String splitId = getSplitId(newExecutions); SplitMessage splitMessage = new SplitMessage(splitId, execution, newExecutions); try { outBuffer.put(executionMessage, splitMessage); } catch (InterruptedException e) { logger.warn("Thread was interrupted! Exiting the execution... ", e); } }
private boolean isExecutionTerminating(Execution nextStepExecution) { if(nextStepExecution.getPosition() == 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(nextStepExecution); 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! Exiting the execution... ", e); return true; } return true; } else { return false; } }
private boolean isSplitStep(Execution nextStepExecution){ if(executionService.isSplitStep(nextStepExecution)){ //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; } else { return false; } }
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; }
executionMessage.setPayload(converter.createPayload(execution)); //this is done since we could get here from InBuffer shortcut - so no payload... and for FAILED message we need to set the payload
private void addErrorMessage(ExecutionMessage message) { String group = message.getWorkerGroup(); Execution execution = converter.extractExecution(message.getPayload()); execution.getSystemContext().setNoWorkerInGroup(group); Payload payload = converter.createPayload(execution); message.setPayload(payload); }
private boolean isRecoveryCheckpoint(Execution nextStepExecution) { //Here we check if we need to go to queue to persist - we can do it with shortcut to InBuffer!!!!!!!! if (!isRecoveryDisabled && nextStepExecution.getSystemContext().containsKey(TempConstants.IS_RECOVERY_CHECKPOINT)) { //clean key nextStepExecution.getSystemContext().remove(TempConstants.IS_RECOVERY_CHECKPOINT); //set current step to finished executionMessage.setStatus(ExecStatus.FINISHED); executionMessage.incMsgSeqId(); executionMessage.setPayload(null); ExecutionMessage inProgressMessage = createInProgressExecutionMessage(nextStepExecution); ExecutionMessage[] executionMessagesToSend = new ExecutionMessage[]{executionMessage, inProgressMessage}; //for the outBuffer ExecutionMessage inProgressMessageForInBuffer = (ExecutionMessage) inProgressMessage.clone(); inProgressMessageForInBuffer.setPayload(null); //we do not need the payload for the inBuffer shortcut try { //The order is important!!!!! outBuffer.put(executionMessagesToSend); inBuffer.addExecutionMessage(inProgressMessageForInBuffer); } catch (InterruptedException e) { logger.warn("Thread was interrupted! Exiting the execution... ", e); return true; //exiting... in shutdown... } return true; } else { return false; } }
private void ackMessages(List<ExecutionMessage> newMessages) throws InterruptedException { ExecutionMessage cloned; for (ExecutionMessage message : newMessages) { // create a unique id for this lane in this specific worker to be used in out buffer optimization //logger.error("ACK FOR MESSAGE: " + message.getMsgId() + " : " + message.getExecStateId()); message.setWorkerKey(message.getMsgId() + " : " + message.getExecStateId()); cloned = (ExecutionMessage) message.clone(); cloned.setStatus(ExecStatus.IN_PROGRESS); cloned.incMsgSeqId(); message.incMsgSeqId(); // increment the original message seq too in order to preserve the order of all messages of entire step cloned.setPayload(null); //payload is not needed in ack - make it null in order to minimize the data that is being sent outBuffer.put(cloned); } }
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; }
executionMessage.setPayload(converter.createPayload(nextStepExecution)); inProgressMessageForInBuffer.setPayload(null); //we do not need the payload for the inBuffer shortcut, we have execution there