Search in sources :

Example 6 with ClusterMode

use of io.cdap.cdap.app.guice.ClusterMode in project cdap by caskdata.

the class AbstractProgramRuntimeService method run.

@Override
public final RuntimeInfo run(ProgramDescriptor programDescriptor, ProgramOptions options, RunId runId) {
    ProgramId programId = programDescriptor.getProgramId();
    ProgramRunId programRunId = programId.run(runId);
    ClusterMode clusterMode = ProgramRunners.getClusterMode(options);
    // Creates the ProgramRunner based on the cluster mode
    ProgramRunner runner = (clusterMode == ClusterMode.ON_PREMISE ? programRunnerFactory : Optional.ofNullable(remoteProgramRunnerFactory).orElseThrow(UnsupportedOperationException::new)).create(programId.getType());
    File tempDir = createTempDirectory(programId, runId);
    AtomicReference<Runnable> cleanUpTaskRef = new AtomicReference<>(createCleanupTask(tempDir, runner));
    DelayedProgramController controller = new DelayedProgramController(programRunId);
    RuntimeInfo runtimeInfo = createRuntimeInfo(controller, programId, () -> cleanUpTaskRef.get().run());
    updateRuntimeInfo(runtimeInfo);
    executor.execute(() -> {
        try {
            // Get the artifact details and save it into the program options.
            ArtifactId artifactId = programDescriptor.getArtifactId();
            ArtifactDetail artifactDetail = getArtifactDetail(artifactId);
            ApplicationSpecification appSpec = programDescriptor.getApplicationSpecification();
            ProgramDescriptor newProgramDescriptor = programDescriptor;
            boolean isPreview = Boolean.valueOf(options.getArguments().getOption(ProgramOptionConstants.IS_PREVIEW, "false"));
            // for preview we already have a resolved app spec, so no need to regenerate the app spec again
            if (!isPreview && appSpec != null && ClusterMode.ON_PREMISE.equals(clusterMode)) {
                try {
                    ApplicationSpecification generatedAppSpec = regenerateAppSpec(artifactDetail, programId, artifactId, appSpec, options);
                    appSpec = generatedAppSpec != null ? generatedAppSpec : appSpec;
                    newProgramDescriptor = new ProgramDescriptor(programDescriptor.getProgramId(), appSpec);
                } catch (Exception e) {
                    LOG.warn("Failed to regenerate the app spec for program {}, using the existing app spec", programId);
                }
            }
            ProgramOptions runtimeProgramOptions = updateProgramOptions(artifactId, programId, options, runId, clusterMode, Iterables.getFirst(artifactDetail.getMeta().getClasses().getApps(), null));
            // Take a snapshot of all the plugin artifacts used by the program
            ProgramOptions optionsWithPlugins = createPluginSnapshot(runtimeProgramOptions, programId, tempDir, newProgramDescriptor.getApplicationSpecification());
            // Create and run the program
            Program executableProgram = createProgram(cConf, runner, newProgramDescriptor, artifactDetail, tempDir);
            cleanUpTaskRef.set(createCleanupTask(cleanUpTaskRef.get(), executableProgram));
            controller.setProgramController(runner.run(executableProgram, optionsWithPlugins));
        } catch (Exception e) {
            controller.failed(e);
            programStateWriter.error(programRunId, e);
            LOG.error("Exception while trying to run program", e);
        }
    });
    return runtimeInfo;
}
Also used : ApplicationSpecification(io.cdap.cdap.api.app.ApplicationSpecification) Program(io.cdap.cdap.app.program.Program) AppDeploymentRuntimeInfo(io.cdap.cdap.internal.app.deploy.pipeline.AppDeploymentRuntimeInfo) SimpleRuntimeInfo(io.cdap.cdap.internal.app.runtime.service.SimpleRuntimeInfo) ArtifactId(io.cdap.cdap.proto.id.ArtifactId) ClusterMode(io.cdap.cdap.app.guice.ClusterMode) AtomicReference(java.util.concurrent.atomic.AtomicReference) ProgramId(io.cdap.cdap.proto.id.ProgramId) TimeoutException(java.util.concurrent.TimeoutException) IOException(java.io.IOException) FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException) ExecutionException(java.util.concurrent.ExecutionException) ArtifactNotFoundException(io.cdap.cdap.common.ArtifactNotFoundException) SimpleProgramOptions(io.cdap.cdap.internal.app.runtime.SimpleProgramOptions) ProgramRunId(io.cdap.cdap.proto.id.ProgramRunId) ProgramDescriptor(io.cdap.cdap.app.program.ProgramDescriptor) File(java.io.File) ArtifactDetail(io.cdap.cdap.internal.app.runtime.artifact.ArtifactDetail)

Example 7 with ClusterMode

use of io.cdap.cdap.app.guice.ClusterMode in project cdap by cdapio.

the class SparkTwillRunnableModuleTest method testSpark.

@Test
public void testSpark() {
    ProgramRunId programRunId = NamespaceId.DEFAULT.app("test").spark("spark").run(RunIds.generate());
    for (ClusterMode mode : ClusterMode.values()) {
        Module module = new SparkTwillRunnable("spark") {

            @Override
            protected ServiceAnnouncer getServiceAnnouncer() {
                return new MockTwillContext();
            }
        }.createModule(CConfiguration.create(), new Configuration(), createProgramOptions(programRunId, mode), programRunId);
        Injector injector = Guice.createInjector(module);
        injector.getInstance(SparkProgramRunner.class);
        injector.getInstance(ExploreClient.class);
        Injector contextInjector = SparkRuntimeContextProvider.createInjector(CConfiguration.create(), new Configuration(), programRunId.getParent(), createProgramOptions(programRunId, mode));
        contextInjector.getInstance(PluginFinder.class);
        contextInjector.getInstance(ExploreClient.class);
    }
}
Also used : MockTwillContext(io.cdap.cdap.common.test.MockTwillContext) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) Configuration(org.apache.hadoop.conf.Configuration) ClusterMode(io.cdap.cdap.app.guice.ClusterMode) Injector(com.google.inject.Injector) ProgramRunId(io.cdap.cdap.proto.id.ProgramRunId) Module(com.google.inject.Module) ServiceAnnouncer(org.apache.twill.api.ServiceAnnouncer) Test(org.junit.Test)

Example 8 with ClusterMode

use of io.cdap.cdap.app.guice.ClusterMode in project cdap by cdapio.

the class ProgramTwillRunnableModuleTest method testWorkflow.

@Test
public void testWorkflow() {
    ProgramRunId programRunId = NamespaceId.DEFAULT.app("test").workflow("workflow").run(RunIds.generate());
    for (ClusterMode mode : ClusterMode.values()) {
        Module module = new WorkflowTwillRunnable("workflow").createModule(CConfiguration.create(), new Configuration(), createProgramOptions(programRunId, mode), programRunId);
        Injector injector = Guice.createInjector(module);
        injector.getInstance(WorkflowProgramRunner.class);
        // Workflow supports spark, which supports PluginFinder
        injector.getInstance(PluginFinder.class);
        injector.getInstance(ExploreClient.class);
    }
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) ClusterMode(io.cdap.cdap.app.guice.ClusterMode) Injector(com.google.inject.Injector) ProgramRunId(io.cdap.cdap.proto.id.ProgramRunId) Module(com.google.inject.Module) Test(org.junit.Test)

Example 9 with ClusterMode

use of io.cdap.cdap.app.guice.ClusterMode in project cdap by cdapio.

the class ProgramTwillRunnableModuleTest method testWorker.

@Test
public void testWorker() {
    ProgramRunId programRunId = NamespaceId.DEFAULT.app("test").worker("worker").run(RunIds.generate());
    for (ClusterMode mode : ClusterMode.values()) {
        Module module = new WorkerTwillRunnable("worker").createModule(CConfiguration.create(), new Configuration(), createProgramOptions(programRunId, mode), programRunId);
        Injector injector = Guice.createInjector(module);
        injector.getInstance(WorkerProgramRunner.class);
        injector.getInstance(ExploreClient.class);
    }
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) ClusterMode(io.cdap.cdap.app.guice.ClusterMode) Injector(com.google.inject.Injector) ProgramRunId(io.cdap.cdap.proto.id.ProgramRunId) Module(com.google.inject.Module) Test(org.junit.Test)

Example 10 with ClusterMode

use of io.cdap.cdap.app.guice.ClusterMode in project cdap by cdapio.

the class ProgramTwillRunnableModuleTest method testMapReduce.

@Test
public void testMapReduce() {
    ProgramRunId programRunId = NamespaceId.DEFAULT.app("test").mr("mapreduce").run(RunIds.generate());
    for (ClusterMode mode : ClusterMode.values()) {
        Module module = new MapReduceTwillRunnable("mapreduce").createModule(CConfiguration.create(), new Configuration(), createProgramOptions(programRunId, mode), programRunId);
        Injector injector = Guice.createInjector(module);
        injector.getInstance(MapReduceProgramRunner.class);
        injector.getInstance(ExploreClient.class);
    }
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) ClusterMode(io.cdap.cdap.app.guice.ClusterMode) Injector(com.google.inject.Injector) ProgramRunId(io.cdap.cdap.proto.id.ProgramRunId) Module(com.google.inject.Module) Test(org.junit.Test)

Aggregations

ClusterMode (io.cdap.cdap.app.guice.ClusterMode)22 CConfiguration (io.cdap.cdap.common.conf.CConfiguration)16 Configuration (org.apache.hadoop.conf.Configuration)16 Injector (com.google.inject.Injector)14 ProgramRunId (io.cdap.cdap.proto.id.ProgramRunId)14 Module (com.google.inject.Module)12 Test (org.junit.Test)9 ApplicationSpecification (io.cdap.cdap.api.app.ApplicationSpecification)6 Service (com.google.common.util.concurrent.Service)4 MetricsCollectionService (io.cdap.cdap.api.metrics.MetricsCollectionService)4 Program (io.cdap.cdap.app.program.Program)4 ProgramDescriptor (io.cdap.cdap.app.program.ProgramDescriptor)4 Arguments (io.cdap.cdap.app.runtime.Arguments)4 ProgramOptions (io.cdap.cdap.app.runtime.ProgramOptions)4 MockTwillContext (io.cdap.cdap.common.test.MockTwillContext)4 ProgramContextAware (io.cdap.cdap.data.ProgramContextAware)4 DatasetFramework (io.cdap.cdap.data2.dataset2.DatasetFramework)4 BasicArguments (io.cdap.cdap.internal.app.runtime.BasicArguments)4 BasicProgramContext (io.cdap.cdap.internal.app.runtime.BasicProgramContext)4 PluginInstantiator (io.cdap.cdap.internal.app.runtime.plugin.PluginInstantiator)4