use of co.cask.cdap.app.runtime.ProgramOptions in project cdap by caskdata.
the class DefaultProgramWorkflowRunner method getProgramRunnable.
/**
* Gets a {@link Runnable} for the {@link Program}.
*
* @param name name of the {@link Program}
* @param program the {@link Program}
* @return a {@link Runnable} for this {@link Program}
*/
private Runnable getProgramRunnable(String name, final ProgramRunner programRunner, final Program program) {
Map<String, String> systemArgumentsMap = new HashMap<>(workflowProgramOptions.getArguments().asMap());
// Generate the new RunId here for the program running under Workflow
systemArgumentsMap.put(ProgramOptionConstants.RUN_ID, RunIds.generate().getId());
// Add Workflow specific system arguments to be passed to the underlying program
systemArgumentsMap.put(ProgramOptionConstants.WORKFLOW_NAME, workflowSpec.getName());
systemArgumentsMap.put(ProgramOptionConstants.WORKFLOW_RUN_ID, ProgramRunners.getRunId(workflowProgramOptions).getId());
systemArgumentsMap.put(ProgramOptionConstants.WORKFLOW_NODE_ID, nodeId);
systemArgumentsMap.put(ProgramOptionConstants.PROGRAM_NAME_IN_WORKFLOW, name);
systemArgumentsMap.put(ProgramOptionConstants.WORKFLOW_TOKEN, GSON.toJson(token));
final ProgramOptions options = new SimpleProgramOptions(program.getId(), new BasicArguments(Collections.unmodifiableMap(systemArgumentsMap)), new BasicArguments(RuntimeArguments.extractScope(program.getType().getScope(), name, workflowProgramOptions.getUserArguments().asMap())));
return new Runnable() {
@Override
public void run() {
try {
runAndWait(programRunner, program, options);
} catch (Exception e) {
throw Throwables.propagate(e);
}
}
};
}
Aggregations