Search in sources :

Example 11 with ProgramOptions

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);
            }
        }
    };
}
Also used : HashMap(java.util.HashMap) SimpleProgramOptions(co.cask.cdap.internal.app.runtime.SimpleProgramOptions) BasicArguments(co.cask.cdap.internal.app.runtime.BasicArguments) SimpleProgramOptions(co.cask.cdap.internal.app.runtime.SimpleProgramOptions) ProgramOptions(co.cask.cdap.app.runtime.ProgramOptions) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

ProgramOptions (co.cask.cdap.app.runtime.ProgramOptions)11 SimpleProgramOptions (co.cask.cdap.internal.app.runtime.SimpleProgramOptions)10 ProgramController (co.cask.cdap.app.runtime.ProgramController)5 AbstractProgramController (co.cask.cdap.internal.app.runtime.AbstractProgramController)4 BasicArguments (co.cask.cdap.internal.app.runtime.BasicArguments)4 Function (com.google.common.base.Function)4 HashMap (java.util.HashMap)4 CConfiguration (co.cask.cdap.common.conf.CConfiguration)3 Map (java.util.Map)3 ExecutionException (java.util.concurrent.ExecutionException)3 FlowletDefinition (co.cask.cdap.api.flow.FlowletDefinition)2 DatasetFramework (co.cask.cdap.data2.dataset2.DatasetFramework)2 ProgramId (co.cask.cdap.proto.id.ProgramId)2 ProgramRunId (co.cask.cdap.proto.id.ProgramRunId)2 IOException (java.io.IOException)2 Table (co.cask.cdap.api.dataset.table.Table)1 MapReduceSpecification (co.cask.cdap.api.mapreduce.MapReduceSpecification)1 MetricsCollectionService (co.cask.cdap.api.metrics.MetricsCollectionService)1 SecureStore (co.cask.cdap.api.security.store.SecureStore)1 SecureStoreManager (co.cask.cdap.api.security.store.SecureStoreManager)1