public String getWorkflowState(WorkflowExecution execution) throws WorkflowException { String workflowId = execution.getWorkflowId(); if (workflowId == null) { throw new IllegalArgumentException("null workflowId"); } final ChildWorkflowTryCatchFinally childTryCatch = workflowExecutions.get(workflowId); if (childTryCatch == null) { throw new UnknownResourceException(execution.toString()); } String openExecutionRunId = childTryCatch.getWorkflowExecution().getRunId(); if (execution.getRunId() != null && !openExecutionRunId.equals(execution.getRunId())) { throw new UnknownResourceException("Unknown Execution (runId doesn't match)"); } return childTryCatch.getWorkflowState(); }
public void requestCancelWorkflowExecution(WorkflowExecution execution) { String workflowId = execution.getWorkflowId(); if (workflowId == null) { throw new IllegalArgumentException("null workflowId"); } final ChildWorkflowTryCatchFinally childTryCatch = workflowExecutions.get(workflowId); if (childTryCatch == null) { throw new UnknownResourceException("Unknown excution: " + execution.toString()); } String openExecutionRunId = childTryCatch.getWorkflowExecution().getRunId(); if (execution.getRunId() != null && !openExecutionRunId.equals(execution.getRunId())) { throw new UnknownResourceException("Unknown Execution (runId doesn't match)"); } childTryCatch.cancel(new CancellationException()); }
public Promise<Void> signalWorkflowExecution( final SignalExternalWorkflowParameters signalParameters) { WorkflowExecution signaledExecution = new WorkflowExecution(); signaledExecution.setWorkflowId(signalParameters.getWorkflowId()); signaledExecution.setRunId(signalParameters.getRunId()); final ChildWorkflowTryCatchFinally childTryCatch = workflowExecutions.get(signalParameters.getWorkflowId()); if (childTryCatch == null) { throw new SignalExternalWorkflowException( 0, signaledExecution, "UNKNOWN_EXTERNAL_WORKFLOW_EXECUTION"); } String openExecutionRunId = childTryCatch.getWorkflowExecution().getRunId(); if (signalParameters.getRunId() != null && !openExecutionRunId.equals(signalParameters.getRunId())) { throw new SignalExternalWorkflowException( 0, signaledExecution, "Unknown Execution (runId doesn't match)"); } childTryCatch.signalRecieved(signalParameters.getSignalName(), signalParameters.getInput()); return Promise.Void(); }
private void continueAsNewWorkflowExecution( final ChildWorkflowTryCatchFinally tryCatch, final Settable<String> result) { // It is always set to ready with null if no continuation is necessary final Promise<ContinueAsNewWorkflowExecutionParameters> continueAsNew = tryCatch.getContinueAsNew(); new Task(continueAsNew) { @Override protected void doExecute() throws Throwable { ContinueAsNewWorkflowExecutionParameters cp = continueAsNew.get(); if (cp == null) { return; } StartChildWorkflowExecutionParameters nextParameters = new StartChildWorkflowExecutionParameters(); nextParameters.setInput(cp.getInput()); WorkflowExecution previousWorkflowExecution = tryCatch.getWorkflowExecution(); String workflowId = previousWorkflowExecution.getWorkflowId(); nextParameters.setWorkflowId(workflowId); StartChildWorkflowExecutionParameters previousParameters = tryCatch.getParameters(); nextParameters.setWorkflowType(previousParameters.getWorkflowType()); long startToClose = cp.getExecutionStartToCloseTimeoutSeconds(); if (startToClose == FlowConstants.NONE) { startToClose = previousParameters.getExecutionStartToCloseTimeoutSeconds(); } nextParameters.setExecutionStartToCloseTimeoutSeconds(startToClose); long taskStartToClose = cp.getTaskStartToCloseTimeoutSeconds(); if (taskStartToClose == FlowConstants.NONE) { taskStartToClose = previousParameters.getTaskStartToCloseTimeoutSeconds(); } nextParameters.setTaskStartToCloseTimeoutSeconds(taskStartToClose); Settable<StartChildWorkflowReply> reply = new Settable<StartChildWorkflowReply>(); startChildWorkflow(nextParameters, reply, result); } }; }