Search in sources :

Example 1 with ProgramRunner

use of io.cdap.cdap.app.runtime.ProgramRunner in project cdap by caskdata.

the class WorkflowTwillRunnable method createModule.

@Override
protected Module createModule(CConfiguration cConf, Configuration hConf, ProgramOptions programOptions, ProgramRunId programRunId) {
    List<Module> modules = new ArrayList<>();
    modules.add(super.createModule(cConf, hConf, programOptions, programRunId));
    if (ProgramRunners.getClusterMode(programOptions) == ClusterMode.ON_PREMISE) {
        modules.add(new DistributedArtifactManagerModule());
    } else {
        modules.add(new AbstractModule() {

            @Override
            protected void configure() {
                bind(PluginFinder.class).to(UnsupportedPluginFinder.class);
            }
        });
    }
    modules.add(new PrivateModule() {

        @Override
        protected void configure() {
            // Bind ProgramRunner for MR, which is used by Workflow.
            // The ProgramRunner for Spark is provided by the DefaultProgramRunnerFactory through the extension mechanism
            MapBinder<ProgramType, ProgramRunner> runnerFactoryBinder = MapBinder.newMapBinder(binder(), ProgramType.class, ProgramRunner.class);
            runnerFactoryBinder.addBinding(ProgramType.MAPREDUCE).to(MapReduceProgramRunner.class);
            // It uses local mode factory because for Workflow we launch the job from the Workflow container directly.
            // The actual execution mode of the job is governed by the framework configuration
            // For mapreduce, it's in the mapred-site.xml
            // for spark, it's in the hConf we shipped from DistributedWorkflowProgramRunner
            bind(ProgramRuntimeProvider.Mode.class).toInstance(ProgramRuntimeProvider.Mode.LOCAL);
            bind(ProgramRunnerFactory.class).to(DefaultProgramRunnerFactory.class).in(Scopes.SINGLETON);
            expose(ProgramRunnerFactory.class);
        }
    });
    return Modules.combine(modules);
}
Also used : ArrayList(java.util.ArrayList) UnsupportedPluginFinder(io.cdap.cdap.app.guice.UnsupportedPluginFinder) DefaultProgramRunnerFactory(io.cdap.cdap.app.guice.DefaultProgramRunnerFactory) ProgramRunnerFactory(io.cdap.cdap.app.runtime.ProgramRunnerFactory) AbstractModule(com.google.inject.AbstractModule) ProgramRuntimeProvider(io.cdap.cdap.app.runtime.ProgramRuntimeProvider) DistributedArtifactManagerModule(io.cdap.cdap.app.guice.DistributedArtifactManagerModule) MapReduceProgramRunner(io.cdap.cdap.internal.app.runtime.batch.MapReduceProgramRunner) MapBinder(com.google.inject.multibindings.MapBinder) ProgramType(io.cdap.cdap.proto.ProgramType) Module(com.google.inject.Module) PrivateModule(com.google.inject.PrivateModule) DistributedArtifactManagerModule(io.cdap.cdap.app.guice.DistributedArtifactManagerModule) AbstractModule(com.google.inject.AbstractModule) WorkflowProgramRunner(io.cdap.cdap.internal.app.runtime.workflow.WorkflowProgramRunner) ProgramRunner(io.cdap.cdap.app.runtime.ProgramRunner) MapReduceProgramRunner(io.cdap.cdap.internal.app.runtime.batch.MapReduceProgramRunner) PrivateModule(com.google.inject.PrivateModule)

Example 2 with ProgramRunner

use of io.cdap.cdap.app.runtime.ProgramRunner in project cdap by caskdata.

the class DefaultRuntimeJob method createModules.

/**
 * Returns list of guice modules used to start the program run.
 */
@VisibleForTesting
List<Module> createModules(RuntimeJobEnvironment runtimeJobEnv, CConfiguration cConf, ProgramRunId programRunId, ProgramOptions programOpts) {
    List<Module> modules = new ArrayList<>();
    modules.add(new ConfigModule(cConf));
    RuntimeMonitorType runtimeMonitorType = SystemArguments.getRuntimeMonitorType(cConf, programOpts);
    modules.add(RuntimeMonitors.getRemoteAuthenticatorModule(runtimeMonitorType, programOpts));
    modules.add(new IOModule());
    modules.add(new TMSLogAppenderModule());
    modules.add(new RemoteExecutionDiscoveryModule());
    modules.add(new AuthenticationContextModules().getProgramContainerModule(cConf));
    modules.add(new MetricsClientRuntimeModule().getDistributedModules());
    modules.add(new MessagingServerRuntimeModule().getStandaloneModules());
    modules.add(new AbstractModule() {

        @Override
        protected void configure() {
            bind(ClusterMode.class).toInstance(ClusterMode.ISOLATED);
            bind(UGIProvider.class).to(CurrentUGIProvider.class).in(Scopes.SINGLETON);
            // Bindings from the environment
            bind(TwillRunner.class).annotatedWith(Constants.AppFabric.ProgramRunner.class).toInstance(runtimeJobEnv.getTwillRunner());
            bind(LocationFactory.class).toInstance(runtimeJobEnv.getLocationFactory());
            MapBinder<ProgramType, ProgramRunner> defaultProgramRunnerBinder = MapBinder.newMapBinder(binder(), ProgramType.class, ProgramRunner.class);
            bind(ProgramRuntimeProvider.Mode.class).toInstance(ProgramRuntimeProvider.Mode.DISTRIBUTED);
            bind(ProgramRunnerFactory.class).annotatedWith(Constants.AppFabric.ProgramRunner.class).to(DefaultProgramRunnerFactory.class).in(Scopes.SINGLETON);
            bind(ProgramStateWriter.class).to(MessagingProgramStateWriter.class).in(Scopes.SINGLETON);
            defaultProgramRunnerBinder.addBinding(ProgramType.MAPREDUCE).to(DistributedMapReduceProgramRunner.class);
            defaultProgramRunnerBinder.addBinding(ProgramType.WORKFLOW).to(DistributedWorkflowProgramRunner.class);
            defaultProgramRunnerBinder.addBinding(ProgramType.WORKER).to(DistributedWorkerProgramRunner.class);
            bind(ProgramRunnerFactory.class).to(DefaultProgramRunnerFactory.class).in(Scopes.SINGLETON);
            bind(ProgramRunId.class).toInstance(programRunId);
            bind(RuntimeMonitorType.class).toInstance(runtimeMonitorType);
            install(new FactoryModuleBuilder().implement(Configurator.class, InMemoryConfigurator.class).build(ConfiguratorFactory.class));
            bind(String.class).annotatedWith(Names.named(RemoteIsolatedPluginFinder.ISOLATED_PLUGIN_DIR)).toInstance(programOpts.getArguments().getOption(ProgramOptionConstants.PLUGIN_DIR, DistributedProgramRunner.PLUGIN_DIR));
            bind(PluginFinder.class).to(RemoteIsolatedPluginFinder.class);
            bind(ArtifactRepositoryReader.class).to(RemoteArtifactRepositoryReader.class).in(Scopes.SINGLETON);
            bind(ArtifactRepository.class).to(RemoteArtifactRepository.class);
        }
    });
    return modules;
}
Also used : IOModule(io.cdap.cdap.common.guice.IOModule) RuntimeMonitorType(io.cdap.cdap.runtime.spi.RuntimeMonitorType) ConfigModule(io.cdap.cdap.common.guice.ConfigModule) FactoryModuleBuilder(com.google.inject.assistedinject.FactoryModuleBuilder) InMemoryConfigurator(io.cdap.cdap.internal.app.deploy.InMemoryConfigurator) Configurator(io.cdap.cdap.app.deploy.Configurator) UGIProvider(io.cdap.cdap.security.impersonation.UGIProvider) CurrentUGIProvider(io.cdap.cdap.security.impersonation.CurrentUGIProvider) TwillRunner(org.apache.twill.api.TwillRunner) ArrayList(java.util.ArrayList) MessagingServerRuntimeModule(io.cdap.cdap.messaging.guice.MessagingServerRuntimeModule) MetricsClientRuntimeModule(io.cdap.cdap.metrics.guice.MetricsClientRuntimeModule) RemoteExecutionDiscoveryModule(io.cdap.cdap.app.guice.RemoteExecutionDiscoveryModule) ProgramRunnerFactory(io.cdap.cdap.app.runtime.ProgramRunnerFactory) DefaultProgramRunnerFactory(io.cdap.cdap.app.guice.DefaultProgramRunnerFactory) ArtifactRepositoryReader(io.cdap.cdap.internal.app.runtime.artifact.ArtifactRepositoryReader) RemoteArtifactRepositoryReader(io.cdap.cdap.internal.app.runtime.artifact.RemoteArtifactRepositoryReader) TMSLogAppenderModule(io.cdap.cdap.logging.guice.TMSLogAppenderModule) ProgramStateWriter(io.cdap.cdap.app.runtime.ProgramStateWriter) MessagingProgramStateWriter(io.cdap.cdap.internal.app.program.MessagingProgramStateWriter) RemoteArtifactRepository(io.cdap.cdap.internal.app.runtime.artifact.RemoteArtifactRepository) ProgramType(io.cdap.cdap.proto.ProgramType) DistributedWorkflowProgramRunner(io.cdap.cdap.internal.app.runtime.distributed.DistributedWorkflowProgramRunner) DistributedProgramRunner(io.cdap.cdap.internal.app.runtime.distributed.DistributedProgramRunner) DistributedMapReduceProgramRunner(io.cdap.cdap.internal.app.runtime.distributed.DistributedMapReduceProgramRunner) DistributedWorkerProgramRunner(io.cdap.cdap.internal.app.runtime.distributed.DistributedWorkerProgramRunner) ProgramRunner(io.cdap.cdap.app.runtime.ProgramRunner) DistributedWorkflowProgramRunner(io.cdap.cdap.internal.app.runtime.distributed.DistributedWorkflowProgramRunner) AuthenticationContextModules(io.cdap.cdap.security.auth.context.AuthenticationContextModules) Constants(io.cdap.cdap.common.conf.Constants) ProgramOptionConstants(io.cdap.cdap.internal.app.runtime.ProgramOptionConstants) RemoteIsolatedPluginFinder(io.cdap.cdap.internal.app.runtime.artifact.RemoteIsolatedPluginFinder) DistributedMapReduceProgramRunner(io.cdap.cdap.internal.app.runtime.distributed.DistributedMapReduceProgramRunner) AbstractModule(com.google.inject.AbstractModule) ProgramRuntimeProvider(io.cdap.cdap.app.runtime.ProgramRuntimeProvider) MapBinder(com.google.inject.multibindings.MapBinder) DistributedWorkerProgramRunner(io.cdap.cdap.internal.app.runtime.distributed.DistributedWorkerProgramRunner) MessagingServerRuntimeModule(io.cdap.cdap.messaging.guice.MessagingServerRuntimeModule) TMSLogAppenderModule(io.cdap.cdap.logging.guice.TMSLogAppenderModule) IOModule(io.cdap.cdap.common.guice.IOModule) AbstractModule(com.google.inject.AbstractModule) Module(com.google.inject.Module) ConfigModule(io.cdap.cdap.common.guice.ConfigModule) RemoteExecutionDiscoveryModule(io.cdap.cdap.app.guice.RemoteExecutionDiscoveryModule) MetricsClientRuntimeModule(io.cdap.cdap.metrics.guice.MetricsClientRuntimeModule) InMemoryConfigurator(io.cdap.cdap.internal.app.deploy.InMemoryConfigurator) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 3 with ProgramRunner

use of io.cdap.cdap.app.runtime.ProgramRunner in project cdap by caskdata.

the class DefaultProgramWorkflowRunner method create.

@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);
    }
}
Also used : Program(io.cdap.cdap.app.program.Program) ProgramRunner(io.cdap.cdap.app.runtime.ProgramRunner) ProgramId(io.cdap.cdap.proto.id.ProgramId) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

Example 4 with ProgramRunner

use of io.cdap.cdap.app.runtime.ProgramRunner in project cdap by caskdata.

the class DistributedWorkflowProgramRunnerTest method setupWorkflowRuntime.

/**
 * Setup the {@link ProgramLaunchConfig} for the given workflow.
 */
private ProgramLaunchConfig setupWorkflowRuntime(String workflowName, Map<String, String> runtimeArgs) throws IOException {
    // Create the distributed workflow program runner
    ProgramRunner programRunner = programRunnerFactory.create(ProgramType.WORKFLOW);
    Assert.assertTrue(programRunner instanceof DistributedWorkflowProgramRunner);
    DistributedWorkflowProgramRunner workflowRunner = (DistributedWorkflowProgramRunner) programRunner;
    // Create the Workflow Program
    Program workflowProgram = createWorkflowProgram(cConf, programRunner, workflowName);
    ProgramLaunchConfig launchConfig = new ProgramLaunchConfig();
    ProgramOptions programOpts = new SimpleProgramOptions(workflowProgram.getId(), new BasicArguments(), new BasicArguments(runtimeArgs));
    // Setup the launching config
    workflowRunner.setupLaunchConfig(launchConfig, workflowProgram, programOpts, cConf, new Configuration(), TEMP_FOLDER.newFolder());
    return launchConfig;
}
Also used : Program(io.cdap.cdap.app.program.Program) Configuration(org.apache.hadoop.conf.Configuration) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) SimpleProgramOptions(io.cdap.cdap.internal.app.runtime.SimpleProgramOptions) BasicArguments(io.cdap.cdap.internal.app.runtime.BasicArguments) ProgramRunner(io.cdap.cdap.app.runtime.ProgramRunner) SimpleProgramOptions(io.cdap.cdap.internal.app.runtime.SimpleProgramOptions) ProgramOptions(io.cdap.cdap.app.runtime.ProgramOptions)

Example 5 with ProgramRunner

use of io.cdap.cdap.app.runtime.ProgramRunner in project cdap by caskdata.

the class ArtifactClassLoaderFactory method createClassLoader.

/**
 * Create a classloader that loads classes from a directory where an artifact jar has been expanded, with access to
 * packages that all program type has access to. The classloader created is only for artifact inspection purpose
 * and shouldn't be used for program execution as it doesn't have the proper class filtering for the specific
 * program type for the program being executed.
 *
 * @param unpackDir the directory where the artifact jar has been expanded
 * @return a closeable classloader based off the specified artifact; on closing the returned {@link ClassLoader},
 *         all temporary resources created for the classloader will be removed
 */
CloseableClassLoader createClassLoader(File unpackDir) {
    ProgramRunner programRunner = null;
    try {
        // Try to create a ProgramClassLoader from the Spark runtime system if it is available.
        // It is needed because we don't know what program types that an artifact might have.
        // TODO: CDAP-5613. We shouldn't always expose the Spark classes.
        programRunner = programRunnerFactory.create(ProgramType.SPARK);
    } catch (Exception e) {
        // If Spark is not supported, exception is expected. We'll use the default filter.
        LOG.trace("Spark is not supported. Not using ProgramClassLoader from Spark", e);
    }
    ProgramClassLoader programClassLoader = null;
    if (programRunner instanceof ProgramClassLoaderProvider) {
        programClassLoader = new ProgramClassLoader(cConf, unpackDir, ((ProgramClassLoaderProvider) programRunner).createProgramClassLoaderParent());
    }
    if (programClassLoader == null) {
        programClassLoader = new ProgramClassLoader(cConf, unpackDir, FilterClassLoader.create(getClass().getClassLoader()));
    }
    final ClassLoader finalProgramClassLoader = programClassLoader;
    final ProgramRunner finalProgramRunner = programRunner;
    return new CloseableClassLoader(programClassLoader, () -> {
        Closeables.closeQuietly((Closeable) finalProgramClassLoader);
        if (finalProgramRunner instanceof Closeable) {
            Closeables.closeQuietly((Closeable) finalProgramRunner);
        }
    });
}
Also used : ProgramClassLoader(io.cdap.cdap.internal.app.runtime.ProgramClassLoader) ProgramClassLoaderProvider(io.cdap.cdap.app.runtime.ProgramClassLoaderProvider) Closeable(java.io.Closeable) ProgramClassLoader(io.cdap.cdap.internal.app.runtime.ProgramClassLoader) FilterClassLoader(io.cdap.cdap.common.lang.FilterClassLoader) DirectoryClassLoader(io.cdap.cdap.common.lang.DirectoryClassLoader) CloseableClassLoader(io.cdap.cdap.api.artifact.CloseableClassLoader) CloseableClassLoader(io.cdap.cdap.api.artifact.CloseableClassLoader) ProgramRunner(io.cdap.cdap.app.runtime.ProgramRunner)

Aggregations

ProgramRunner (io.cdap.cdap.app.runtime.ProgramRunner)11 Program (io.cdap.cdap.app.program.Program)5 ProgramRunnerFactory (io.cdap.cdap.app.runtime.ProgramRunnerFactory)5 ProgramType (io.cdap.cdap.proto.ProgramType)5 DefaultProgramRunnerFactory (io.cdap.cdap.app.guice.DefaultProgramRunnerFactory)4 BasicArguments (io.cdap.cdap.internal.app.runtime.BasicArguments)4 SimpleProgramOptions (io.cdap.cdap.internal.app.runtime.SimpleProgramOptions)4 ProgramOptions (io.cdap.cdap.app.runtime.ProgramOptions)3 ProgramStateWriter (io.cdap.cdap.app.runtime.ProgramStateWriter)3 CConfiguration (io.cdap.cdap.common.conf.CConfiguration)3 ProgramId (io.cdap.cdap.proto.id.ProgramId)3 Closeable (java.io.Closeable)3 AbstractModule (com.google.inject.AbstractModule)2 Module (com.google.inject.Module)2 FactoryModuleBuilder (com.google.inject.assistedinject.FactoryModuleBuilder)2 MapBinder (com.google.inject.multibindings.MapBinder)2 ApplicationSpecification (io.cdap.cdap.api.app.ApplicationSpecification)2 ProgramDescriptor (io.cdap.cdap.app.program.ProgramDescriptor)2 ProgramController (io.cdap.cdap.app.runtime.ProgramController)2 ProgramRuntimeProvider (io.cdap.cdap.app.runtime.ProgramRuntimeProvider)2