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()); } }
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()); } }