/** * Gives the appropriate instance of {@link ProgramWorkflowRunner} depending upon the passed programType * * @param programType the programType * @param token the {@link WorkflowToken} * @param nodeStates the map of node ids to node states * @return the appropriate concrete implementation of {@link ProgramWorkflowRunner} for the program */ ProgramWorkflowRunner getProgramWorkflowRunner(SchedulableProgramType programType, WorkflowToken token, String nodeId, Map<String, WorkflowNodeState> nodeStates) { switch (programType) { case MAPREDUCE: return new DefaultProgramWorkflowRunner(cConf, workflowProgram, workflowProgramOptions, programRunnerFactory, workflowSpec, token, nodeId, nodeStates, ProgramType.MAPREDUCE, programStateWriter); case SPARK: return new DefaultProgramWorkflowRunner(cConf, workflowProgram, workflowProgramOptions, programRunnerFactory, workflowSpec, token, nodeId, nodeStates, ProgramType.SPARK, programStateWriter); default: LOG.debug("No workflow program runner found for this program"); } return null; // if no workflow program runner was found for this program } }
private void runAndWait(ProgramRunner programRunner, Program program, ProgramOptions options) throws Exception { Closeable closeable = createCloseable(programRunner, program); // Publish the program's starting state RunId runId = ProgramRunners.getRunId(options); String twillRunId = options.getArguments().getOption(ProgramOptionConstants.TWILL_RUN_ID); ProgramDescriptor programDescriptor = new ProgramDescriptor(program.getId(), program.getApplicationSpecification()); programStateWriter.start(program.getId().run(runId), options, twillRunId, programDescriptor); ProgramController controller; try { controller = programRunner.run(program, options); } catch (Throwable t) { // If there is any exception when running the program, close the program to release resources. // Otherwise it will be released when the execution completed. programStateWriter.error(program.getId().run(runId), t); Closeables.closeQuietly(closeable); throw t; } blockForCompletion(closeable, controller); if (controller instanceof WorkflowDataProvider) { updateWorkflowToken(((WorkflowDataProvider) controller).getWorkflowToken()); } else { // This shouldn't happen throw new IllegalStateException("No WorkflowToken available after program completed: " + program.getId()); } }
@Override public Runnable create(String name) { ProgramRunner programRunner = programRunnerFactory.create(programType); try { ProgramId programId = workflowProgram.getId().getParent().program(programType, name); Program program = Programs.create(cConf, workflowProgram, programId, programRunner); return getProgramRunnable(name, programRunner, program); } catch (Exception e) { closeProgramRunner(programRunner); throw Throwables.propagate(e); } }
private void runAndWait(ProgramRunner programRunner, Program program, ProgramOptions options) throws Exception { Closeable closeable = createCloseable(programRunner, program); // Publish the program's starting state RunId runId = ProgramRunners.getRunId(options); String twillRunId = options.getArguments().getOption(ProgramOptionConstants.TWILL_RUN_ID); ProgramDescriptor programDescriptor = new ProgramDescriptor(program.getId(), program.getApplicationSpecification()); programStateWriter.start(program.getId().run(runId), options, twillRunId, programDescriptor); ProgramController controller; try { controller = programRunner.run(program, options); } catch (Throwable t) { // If there is any exception when running the program, close the program to release resources. // Otherwise it will be released when the execution completed. programStateWriter.error(program.getId().run(runId), t); Closeables.closeQuietly(closeable); throw t; } blockForCompletion(closeable, controller); if (controller instanceof WorkflowDataProvider) { updateWorkflowToken(((WorkflowDataProvider) controller).getWorkflowToken()); } else { // This shouldn't happen throw new IllegalStateException("No WorkflowToken available after program completed: " + program.getId()); } }
@Override public Runnable create(String name) { ProgramRunner programRunner = programRunnerFactory.create(programType); try { ProgramId programId = workflowProgram.getId().getParent().program(programType, name); Program program = Programs.create(cConf, workflowProgram, programId, programRunner); return getProgramRunnable(name, programRunner, program); } catch (Exception e) { closeProgramRunner(programRunner); throw Throwables.propagate(e); } }
/** * Gives the appropriate instance of {@link ProgramWorkflowRunner} depending upon the passed programType * * @param programType the programType * @param token the {@link WorkflowToken} * @param nodeStates the map of node ids to node states * @return the appropriate concrete implementation of {@link ProgramWorkflowRunner} for the program */ ProgramWorkflowRunner getProgramWorkflowRunner(SchedulableProgramType programType, WorkflowToken token, String nodeId, Map<String, WorkflowNodeState> nodeStates) { switch (programType) { case MAPREDUCE: return new DefaultProgramWorkflowRunner(cConf, workflowProgram, workflowProgramOptions, programRunnerFactory, workflowSpec, token, nodeId, nodeStates, ProgramType.MAPREDUCE, programStateWriter); case SPARK: return new DefaultProgramWorkflowRunner(cConf, workflowProgram, workflowProgramOptions, programRunnerFactory, workflowSpec, token, nodeId, nodeStates, ProgramType.SPARK, programStateWriter); default: LOG.debug("No workflow program runner found for this program"); } return null; // if no workflow program runner was found for this program } }