Search in sources :

Example 6 with ProgramRunner

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

the class ConfiguratorTaskModule method configure.

@Override
protected void configure() {
    MasterEnvironment masterEnv = MasterEnvironments.getMasterEnvironment();
    bind(DiscoveryService.class).toProvider(new SupplierProviderBridge<>(masterEnv.getDiscoveryServiceSupplier()));
    bind(DiscoveryServiceClient.class).toProvider(new SupplierProviderBridge<>(masterEnv.getDiscoveryServiceClientSupplier()));
    // Bind ProgramRunner
    MapBinder<ProgramType, ProgramRunner> runnerFactoryBinder = MapBinder.newMapBinder(binder(), ProgramType.class, ProgramRunner.class);
    bind(ProgramStateWriter.class).to(NoOpProgramStateWriter.class);
    bind(ProgramRuntimeProvider.Mode.class).toInstance(ProgramRuntimeProvider.Mode.LOCAL);
    bind(ProgramRunnerFactory.class).to(DefaultProgramRunnerFactory.class).in(Scopes.SINGLETON);
    bind(PluginFinder.class).to(RemoteWorkerPluginFinder.class);
    bind(UGIProvider.class).to(CurrentUGIProvider.class);
    bind(ArtifactRepositoryReader.class).to(RemoteArtifactRepositoryReader.class).in(Scopes.SINGLETON);
    bind(NamespaceQueryAdmin.class).to(RemoteNamespaceQueryClient.class);
    bind(MetadataServiceClient.class).to(DefaultMetadataServiceClient.class);
    bind(ArtifactRepository.class).to(RemoteArtifactRepository.class);
}
Also used : DiscoveryServiceClient(org.apache.twill.discovery.DiscoveryServiceClient) UGIProvider(io.cdap.cdap.security.impersonation.UGIProvider) CurrentUGIProvider(io.cdap.cdap.security.impersonation.CurrentUGIProvider) RemoteArtifactRepository(io.cdap.cdap.internal.app.runtime.artifact.RemoteArtifactRepository) ArtifactRepository(io.cdap.cdap.internal.app.runtime.artifact.ArtifactRepository) DefaultProgramRunnerFactory(io.cdap.cdap.app.guice.DefaultProgramRunnerFactory) DefaultMetadataServiceClient(io.cdap.cdap.data2.metadata.writer.DefaultMetadataServiceClient) MetadataServiceClient(io.cdap.cdap.data2.metadata.writer.MetadataServiceClient) MasterEnvironment(io.cdap.cdap.master.spi.environment.MasterEnvironment) NoOpProgramStateWriter(io.cdap.cdap.app.runtime.NoOpProgramStateWriter) ProgramStateWriter(io.cdap.cdap.app.runtime.ProgramStateWriter) PluginFinder(io.cdap.cdap.internal.app.runtime.artifact.PluginFinder) RemoteArtifactRepositoryReader(io.cdap.cdap.internal.app.runtime.artifact.RemoteArtifactRepositoryReader) NamespaceQueryAdmin(io.cdap.cdap.common.namespace.NamespaceQueryAdmin) ProgramType(io.cdap.cdap.proto.ProgramType) DiscoveryService(org.apache.twill.discovery.DiscoveryService) ProgramRunner(io.cdap.cdap.app.runtime.ProgramRunner)

Example 7 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 8 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)

Example 9 with ProgramRunner

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

the class ConfiguratorTaskModule method configure.

@Override
protected void configure() {
    MasterEnvironment masterEnv = MasterEnvironments.getMasterEnvironment();
    bind(DiscoveryService.class).toProvider(new SupplierProviderBridge<>(masterEnv.getDiscoveryServiceSupplier()));
    bind(DiscoveryServiceClient.class).toProvider(new SupplierProviderBridge<>(masterEnv.getDiscoveryServiceClientSupplier()));
    // Bind ProgramRunner
    MapBinder<ProgramType, ProgramRunner> runnerFactoryBinder = MapBinder.newMapBinder(binder(), ProgramType.class, ProgramRunner.class);
    bind(ProgramStateWriter.class).to(NoOpProgramStateWriter.class);
    bind(ProgramRuntimeProvider.Mode.class).toInstance(ProgramRuntimeProvider.Mode.LOCAL);
    bind(ProgramRunnerFactory.class).to(DefaultProgramRunnerFactory.class).in(Scopes.SINGLETON);
    bind(PluginFinder.class).to(RemoteWorkerPluginFinder.class);
    bind(UGIProvider.class).to(CurrentUGIProvider.class);
    bind(ArtifactRepositoryReader.class).to(RemoteArtifactRepositoryReader.class).in(Scopes.SINGLETON);
    bind(NamespaceQueryAdmin.class).to(RemoteNamespaceQueryClient.class);
    bind(MetadataServiceClient.class).to(DefaultMetadataServiceClient.class);
    bind(ArtifactRepository.class).to(RemoteArtifactRepository.class);
}
Also used : DiscoveryServiceClient(org.apache.twill.discovery.DiscoveryServiceClient) UGIProvider(io.cdap.cdap.security.impersonation.UGIProvider) CurrentUGIProvider(io.cdap.cdap.security.impersonation.CurrentUGIProvider) RemoteArtifactRepository(io.cdap.cdap.internal.app.runtime.artifact.RemoteArtifactRepository) ArtifactRepository(io.cdap.cdap.internal.app.runtime.artifact.ArtifactRepository) DefaultProgramRunnerFactory(io.cdap.cdap.app.guice.DefaultProgramRunnerFactory) DefaultMetadataServiceClient(io.cdap.cdap.data2.metadata.writer.DefaultMetadataServiceClient) MetadataServiceClient(io.cdap.cdap.data2.metadata.writer.MetadataServiceClient) MasterEnvironment(io.cdap.cdap.master.spi.environment.MasterEnvironment) NoOpProgramStateWriter(io.cdap.cdap.app.runtime.NoOpProgramStateWriter) ProgramStateWriter(io.cdap.cdap.app.runtime.ProgramStateWriter) PluginFinder(io.cdap.cdap.internal.app.runtime.artifact.PluginFinder) RemoteArtifactRepositoryReader(io.cdap.cdap.internal.app.runtime.artifact.RemoteArtifactRepositoryReader) NamespaceQueryAdmin(io.cdap.cdap.common.namespace.NamespaceQueryAdmin) ProgramType(io.cdap.cdap.proto.ProgramType) DiscoveryService(org.apache.twill.discovery.DiscoveryService) ProgramRunner(io.cdap.cdap.app.runtime.ProgramRunner)

Example 10 with ProgramRunner

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

the class AppFabricTestHelper method submit.

/**
 * Submits a program execution.
 *
 * @param app the application containing the program
 * @param programClassName name of the program class
 * @param userArgs runtime arguments
 * @param folderSupplier a Supplier of temporary folder
 * @return a {@link ProgramController} for controlling the program execution.
 */
public static ProgramController submit(ApplicationWithPrograms app, String programClassName, Arguments userArgs, Supplier<File> folderSupplier) throws Exception {
    ProgramRunnerFactory runnerFactory = injector.getInstance(ProgramRunnerFactory.class);
    ProgramRunner runner = null;
    Program program = null;
    for (ProgramDescriptor programDescriptor : app.getPrograms()) {
        if (programDescriptor.getSpecification().getClassName().equals(programClassName)) {
            runner = runnerFactory.create(programDescriptor.getProgramId().getType());
            program = createProgram(programDescriptor, app.getArtifactLocation(), runner, folderSupplier);
            break;
        }
    }
    Assert.assertNotNull(program);
    BasicArguments systemArgs = new BasicArguments(ImmutableMap.of(ProgramOptionConstants.RUN_ID, RunIds.generate().getId(), ProgramOptionConstants.HOST, InetAddress.getLoopbackAddress().getCanonicalHostName(), ProgramOptionConstants.ARTIFACT_ID, Joiner.on(":").join(app.getArtifactId().toIdParts())));
    return runner.run(program, new SimpleProgramOptions(program.getId(), systemArgs, userArgs));
}
Also used : Program(io.cdap.cdap.app.program.Program) ProgramDescriptor(io.cdap.cdap.app.program.ProgramDescriptor) BasicArguments(io.cdap.cdap.internal.app.runtime.BasicArguments) SimpleProgramOptions(io.cdap.cdap.internal.app.runtime.SimpleProgramOptions) ProgramRunner(io.cdap.cdap.app.runtime.ProgramRunner) ProgramRunnerFactory(io.cdap.cdap.app.runtime.ProgramRunnerFactory)

Aggregations

ProgramRunner (io.cdap.cdap.app.runtime.ProgramRunner)22 Program (io.cdap.cdap.app.program.Program)10 ProgramRunnerFactory (io.cdap.cdap.app.runtime.ProgramRunnerFactory)10 ProgramType (io.cdap.cdap.proto.ProgramType)10 DefaultProgramRunnerFactory (io.cdap.cdap.app.guice.DefaultProgramRunnerFactory)8 BasicArguments (io.cdap.cdap.internal.app.runtime.BasicArguments)8 SimpleProgramOptions (io.cdap.cdap.internal.app.runtime.SimpleProgramOptions)8 ProgramOptions (io.cdap.cdap.app.runtime.ProgramOptions)6 ProgramRuntimeProvider (io.cdap.cdap.app.runtime.ProgramRuntimeProvider)6 ProgramStateWriter (io.cdap.cdap.app.runtime.ProgramStateWriter)6 CConfiguration (io.cdap.cdap.common.conf.CConfiguration)6 Closeable (java.io.Closeable)6 ArrayList (java.util.ArrayList)6 ProgramId (io.cdap.cdap.proto.id.ProgramId)5 IOException (java.io.IOException)5 AbstractModule (com.google.inject.AbstractModule)4 FactoryModuleBuilder (com.google.inject.assistedinject.FactoryModuleBuilder)4 ApplicationSpecification (io.cdap.cdap.api.app.ApplicationSpecification)4 ProgramDescriptor (io.cdap.cdap.app.program.ProgramDescriptor)4 ProgramController (io.cdap.cdap.app.runtime.ProgramController)4