/** * Executes a target flow. If execution is failed except on {@link ExecutionPhase#SETUP setup}, * {@link ExecutionPhase#FINALIZE finalize}, or {@link ExecutionPhase#CLEANUP cleanup}, then the * {@code finalize} phase will be executed for recovery before execution is aborted. * * @param batchId target batch ID * @param flowId target flow ID * @param executionId target execution ID * @throws InterruptedException if interrupted during this execution * @throws IOException if failed to execute target flow * @throws IllegalArgumentException if some parameters were {@code null} */ public void executeFlow(String batchId, String flowId, String executionId) throws InterruptedException, IOException { if (batchId == null) { throw new IllegalArgumentException("batchId must not be null"); // $NON-NLS-1$ } if (flowId == null) { throw new IllegalArgumentException("flowId must not be null"); // $NON-NLS-1$ } if (executionId == null) { throw new IllegalArgumentException("executionId must not be null"); // $NON-NLS-1$ } FlowScript flow = script.findFlow(flowId); if (flow == null) { throw new IllegalArgumentException( MessageFormat.format( "Flow is undefined: batchId={0}, flowId={1}, executionId={2}", batchId, flowId, executionId)); } ExecutionLock lock = acquireExecutionLock(batchId); try { lock.beginFlow(flowId, executionId); executeFlow(batchId, flow, executionId); lock.endFlow(flowId, executionId); } finally { lock.close(); } }
/** * Executes a target phase. * * @param context the current context * @throws InterruptedException if interrupted during this execution * @throws IOException if failed to execute target phase * @throws IllegalArgumentException if some parameters were {@code null} * @since 0.2.5 */ public void executePhase(ExecutionContext context) throws InterruptedException, IOException { if (context == null) { throw new IllegalArgumentException("context must not be null"); // $NON-NLS-1$ } FlowScript flow = script.findFlow(context.getFlowId()); if (flow == null) { throw new IllegalArgumentException( MessageFormat.format( "Flow is undefined: batchId={0}, flowId={1}, executionId={2}", context.getBatchId(), context.getFlowId(), context.getExecutionId())); } Set<ExecutionScript> executions = flow.getScripts().get(context.getPhase()); ExecutionLock lock = acquireExecutionLock(context.getBatchId()); try { lock.beginFlow(context.getFlowId(), context.getExecutionId()); executePhase(context, executions); lock.endFlow(context.getFlowId(), context.getExecutionId()); } finally { lock.close(); } }