Search in sources :

Example 1 with Programs

use of io.cdap.cdap.app.program.Programs in project cdap by caskdata.

the class DistributedWorkflowProgramRunner method setupLaunchConfig.

@Override
protected void setupLaunchConfig(ProgramLaunchConfig launchConfig, Program program, ProgramOptions options, CConfiguration cConf, Configuration hConf, File tempDir) throws IOException {
    WorkflowSpecification spec = program.getApplicationSpecification().getWorkflows().get(program.getName());
    List<ClassAcceptor> acceptors = new ArrayList<>();
    acceptors.add(launchConfig.getClassAcceptor());
    // Only interested in MapReduce and Spark nodes.
    // This is because CUSTOM_ACTION types are running inside the driver
    Set<SchedulableProgramType> runnerTypes = EnumSet.of(SchedulableProgramType.MAPREDUCE, SchedulableProgramType.SPARK);
    Iterable<ScheduleProgramInfo> programInfos = spec.getNodeIdMap().values().stream().filter(WorkflowActionNode.class::isInstance).map(WorkflowActionNode.class::cast).map(WorkflowActionNode::getProgram).filter(programInfo -> runnerTypes.contains(programInfo.getProgramType()))::iterator;
    // Can't use Stream.forEach as we want to preserve the IOException being thrown
    for (ScheduleProgramInfo programInfo : programInfos) {
        ProgramType programType = ProgramType.valueOfSchedulableType(programInfo.getProgramType());
        ProgramRunner runner = programRunnerFactory.create(programType);
        try {
            if (runner instanceof DistributedProgramRunner) {
                // Call setupLaunchConfig with the corresponding program.
                // Need to constructs a new ProgramOptions with the scope extracted for the given program
                ProgramId programId = program.getId().getParent().program(programType, programInfo.getProgramName());
                Map<String, String> programUserArgs = RuntimeArguments.extractScope(programId.getType().getScope(), programId.getProgram(), options.getUserArguments().asMap());
                ProgramOptions programOptions = new SimpleProgramOptions(programId, options.getArguments(), new BasicArguments(programUserArgs));
                ((DistributedProgramRunner) runner).setupLaunchConfig(launchConfig, Programs.create(cConf, program, programId, runner), programOptions, cConf, hConf, tempDir);
                acceptors.add(launchConfig.getClassAcceptor());
            }
        } finally {
            if (runner instanceof Closeable) {
                Closeables.closeQuietly((Closeable) runner);
            }
        }
    }
    // Set the class acceptor
    launchConfig.setClassAcceptor(new AndClassAcceptor(acceptors));
    // Find out the default resources requirements based on the programs inside the workflow
    // At least gives the Workflow driver 768 mb of container memory
    Map<String, Resources> runnablesResources = Maps.transformValues(launchConfig.getRunnables(), this::getResources);
    Resources defaultResources = maxResources(new Resources(768), findDriverResources(spec.getNodes(), runnablesResources));
    // Clear and set the runnable for the workflow driver.
    launchConfig.clearRunnables();
    // Extract scoped runtime arguments that only meant for the workflow but not for child nodes
    Map<String, String> runtimeArgs = RuntimeArguments.extractScope("task", "workflow", options.getUserArguments().asMap());
    launchConfig.addRunnable(spec.getName(), new WorkflowTwillRunnable(spec.getName()), 1, runtimeArgs, defaultResources, 0);
}
Also used : URL(java.net.URL) Inject(com.google.inject.Inject) LoggerFactory(org.slf4j.LoggerFactory) ClusterMode(io.cdap.cdap.app.guice.ClusterMode) ProgramRunnerFactory(io.cdap.cdap.app.runtime.ProgramRunnerFactory) Resources(io.cdap.cdap.api.Resources) WorkflowNode(io.cdap.cdap.api.workflow.WorkflowNode) SimpleProgramOptions(io.cdap.cdap.internal.app.runtime.SimpleProgramOptions) Configuration(org.apache.hadoop.conf.Configuration) Map(java.util.Map) Closeables(com.google.common.io.Closeables) ProgramRunner(io.cdap.cdap.app.runtime.ProgramRunner) EnumSet(java.util.EnumSet) TwillController(org.apache.twill.api.TwillController) Collection(java.util.Collection) ApplicationSpecification(io.cdap.cdap.api.app.ApplicationSpecification) WorkflowNodeType(io.cdap.cdap.api.workflow.WorkflowNodeType) ResourceSpecification(org.apache.twill.api.ResourceSpecification) Set(java.util.Set) SchedulableProgramType(io.cdap.cdap.api.schedule.SchedulableProgramType) ScheduleProgramInfo(io.cdap.cdap.api.workflow.ScheduleProgramInfo) List(java.util.List) Constants(io.cdap.cdap.common.conf.Constants) Workflow(io.cdap.cdap.api.workflow.Workflow) WorkflowForkNode(io.cdap.cdap.api.workflow.WorkflowForkNode) WorkflowSpecification(io.cdap.cdap.api.workflow.WorkflowSpecification) Program(io.cdap.cdap.app.program.Program) Programs(io.cdap.cdap.app.program.Programs) ProgramType(io.cdap.cdap.proto.ProgramType) ArrayList(java.util.ArrayList) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) ProgramRunId(io.cdap.cdap.proto.id.ProgramRunId) ProgramOptions(io.cdap.cdap.app.runtime.ProgramOptions) TwillRunner(org.apache.twill.api.TwillRunner) SystemArguments(io.cdap.cdap.internal.app.runtime.SystemArguments) WorkflowActionNode(io.cdap.cdap.api.workflow.WorkflowActionNode) ClassAcceptor(org.apache.twill.api.ClassAcceptor) ProgramController(io.cdap.cdap.app.runtime.ProgramController) Logger(org.slf4j.Logger) RuntimeArguments(io.cdap.cdap.api.common.RuntimeArguments) ProgramId(io.cdap.cdap.proto.id.ProgramId) Impersonator(io.cdap.cdap.security.impersonation.Impersonator) IOException(java.io.IOException) Maps(com.google.common.collect.Maps) File(java.io.File) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) Closeable(java.io.Closeable) Preconditions(com.google.common.base.Preconditions) WorkflowConditionNode(io.cdap.cdap.api.workflow.WorkflowConditionNode) Collections(java.util.Collections) BasicArguments(io.cdap.cdap.internal.app.runtime.BasicArguments) WorkflowActionNode(io.cdap.cdap.api.workflow.WorkflowActionNode) Closeable(java.io.Closeable) ArrayList(java.util.ArrayList) ClassAcceptor(org.apache.twill.api.ClassAcceptor) ProgramId(io.cdap.cdap.proto.id.ProgramId) SimpleProgramOptions(io.cdap.cdap.internal.app.runtime.SimpleProgramOptions) ProgramOptions(io.cdap.cdap.app.runtime.ProgramOptions) WorkflowSpecification(io.cdap.cdap.api.workflow.WorkflowSpecification) SchedulableProgramType(io.cdap.cdap.api.schedule.SchedulableProgramType) SchedulableProgramType(io.cdap.cdap.api.schedule.SchedulableProgramType) ProgramType(io.cdap.cdap.proto.ProgramType) SimpleProgramOptions(io.cdap.cdap.internal.app.runtime.SimpleProgramOptions) BasicArguments(io.cdap.cdap.internal.app.runtime.BasicArguments) Resources(io.cdap.cdap.api.Resources) ScheduleProgramInfo(io.cdap.cdap.api.workflow.ScheduleProgramInfo) ProgramRunner(io.cdap.cdap.app.runtime.ProgramRunner)

Aggregations

Preconditions (com.google.common.base.Preconditions)1 Maps (com.google.common.collect.Maps)1 Closeables (com.google.common.io.Closeables)1 Inject (com.google.inject.Inject)1 Resources (io.cdap.cdap.api.Resources)1 ApplicationSpecification (io.cdap.cdap.api.app.ApplicationSpecification)1 RuntimeArguments (io.cdap.cdap.api.common.RuntimeArguments)1 SchedulableProgramType (io.cdap.cdap.api.schedule.SchedulableProgramType)1 ScheduleProgramInfo (io.cdap.cdap.api.workflow.ScheduleProgramInfo)1 Workflow (io.cdap.cdap.api.workflow.Workflow)1 WorkflowActionNode (io.cdap.cdap.api.workflow.WorkflowActionNode)1 WorkflowConditionNode (io.cdap.cdap.api.workflow.WorkflowConditionNode)1 WorkflowForkNode (io.cdap.cdap.api.workflow.WorkflowForkNode)1 WorkflowNode (io.cdap.cdap.api.workflow.WorkflowNode)1 WorkflowNodeType (io.cdap.cdap.api.workflow.WorkflowNodeType)1 WorkflowSpecification (io.cdap.cdap.api.workflow.WorkflowSpecification)1 ClusterMode (io.cdap.cdap.app.guice.ClusterMode)1 Program (io.cdap.cdap.app.program.Program)1 Programs (io.cdap.cdap.app.program.Programs)1 ProgramController (io.cdap.cdap.app.runtime.ProgramController)1