private void executeAll(Iterator<WorkflowNode> iterator, ApplicationSpecification appSpec, InstantiatorFactory instantiator, ClassLoader classLoader, WorkflowToken token) { while (iterator.hasNext() && runningThread != null) { try { blockIfSuspended(); WorkflowNode node = iterator.next(); executeNode(appSpec, node, instantiator, classLoader, token); } catch (Throwable t) { Throwable rootCause = Throwables.getRootCause(t); if (rootCause instanceof InterruptedException) { LOG.debug("Workflow '{}' with run id '{}' aborted", workflowSpec.getName(), workflowRunId.getRun()); workflowContext.setState(new ProgramState(ProgramStatus.KILLED, rootCause.getMessage())); break; } workflowContext.setState(new ProgramState(ProgramStatus.FAILED, rootCause.getMessage())); throw Throwables.propagate(rootCause); } } }
private void executeAll(Iterator<WorkflowNode> iterator, ApplicationSpecification appSpec, InstantiatorFactory instantiator, ClassLoader classLoader, WorkflowToken token) { while (iterator.hasNext() && runningThread != null) { try { blockIfSuspended(); WorkflowNode node = iterator.next(); executeNode(appSpec, node, instantiator, classLoader, token); } catch (Throwable t) { Throwable rootCause = Throwables.getRootCause(t); if (rootCause instanceof InterruptedException) { LOG.debug("Workflow '{}' with run id '{}' aborted", workflowSpec.getName(), workflowRunId.getRun()); workflowContext.setState(new ProgramState(ProgramStatus.KILLED, rootCause.getMessage())); break; } workflowContext.setState(new ProgramState(ProgramStatus.FAILED, rootCause.getMessage())); throw Throwables.propagate(rootCause); } } }
@Override protected void run() throws Exception { LOG.info("Starting workflow execution for '{}' with Run id '{}'", workflowSpec.getName(), workflowRunId.getRun()); LOG.trace("Workflow specification is {}", workflowSpec); workflowContext.setState(new ProgramState(ProgramStatus.RUNNING, null)); executeAll(workflowSpec.getNodes().iterator(), program.getApplicationSpecification(), new InstantiatorFactory(false), program.getClassLoader(), basicWorkflowToken); if (runningThread != null) { workflowContext.setState(new ProgramState(ProgramStatus.COMPLETED, null)); } LOG.info("Workflow '{}' with run id '{}' completed", workflowSpec.getName(), workflowRunId.getRun()); }
@Override protected void run() throws Exception { LOG.info("Starting workflow execution for '{}' with Run id '{}'", workflowSpec.getName(), workflowRunId.getRun()); LOG.trace("Workflow specification is {}", workflowSpec); workflowContext.setState(new ProgramState(ProgramStatus.RUNNING, null)); executeAll(workflowSpec.getNodes().iterator(), program.getApplicationSpecification(), new InstantiatorFactory(false), program.getClassLoader(), basicWorkflowToken); if (runningThread != null) { workflowContext.setState(new ProgramState(ProgramStatus.COMPLETED, null)); } LOG.info("Workflow '{}' with run id '{}' completed", workflowSpec.getName(), workflowRunId.getRun()); }
@SuppressWarnings("unchecked") private Workflow initializeWorkflow() throws Exception { Class<?> clz = Class.forName(workflowSpec.getClassName(), true, program.getClassLoader()); if (!Workflow.class.isAssignableFrom(clz)) { throw new IllegalStateException(String.format("%s is not Workflow.", clz)); } Class<? extends Workflow> workflowClass = (Class<? extends Workflow>) clz; final Workflow workflow = new InstantiatorFactory(false).get(TypeToken.of(workflowClass)).create(); // set metrics Reflections.visit(workflow, workflow.getClass(), new MetricsFieldSetter(workflowContext.getMetrics())); if (!(workflow instanceof ProgramLifecycle)) { return workflow; } final TransactionControl txControl = Transactions.getTransactionControl(workflowContext.getDefaultTxControl(), Workflow.class, workflow, "initialize", WorkflowContext.class); basicWorkflowToken.setCurrentNode(workflowSpec.getName()); workflowContext.setState(new ProgramState(ProgramStatus.INITIALIZING, null)); workflowContext.initializeProgram((ProgramLifecycle) workflow, txControl, false); workflowStateWriter.setWorkflowToken(workflowRunId, basicWorkflowToken); return workflow; }
@SuppressWarnings("unchecked") private Workflow initializeWorkflow() throws Exception { Class<?> clz = Class.forName(workflowSpec.getClassName(), true, program.getClassLoader()); if (!Workflow.class.isAssignableFrom(clz)) { throw new IllegalStateException(String.format("%s is not Workflow.", clz)); } Class<? extends Workflow> workflowClass = (Class<? extends Workflow>) clz; final Workflow workflow = new InstantiatorFactory(false).get(TypeToken.of(workflowClass)).create(); // set metrics Reflections.visit(workflow, workflow.getClass(), new MetricsFieldSetter(workflowContext.getMetrics())); if (!(workflow instanceof ProgramLifecycle)) { return workflow; } final TransactionControl txControl = Transactions.getTransactionControl(workflowContext.getDefaultTxControl(), Workflow.class, workflow, "initialize", WorkflowContext.class); basicWorkflowToken.setCurrentNode(workflowSpec.getName()); workflowContext.setState(new ProgramState(ProgramStatus.INITIALIZING, null)); workflowContext.initializeProgram((ProgramLifecycle) workflow, txControl, false); workflowStateWriter.setWorkflowToken(workflowRunId, basicWorkflowToken); return workflow; }