Search in sources :

Example 16 with ProgramOptions

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

the class ProgramStateWriterWithHeartBeatTest method testHeartBeatThread.

private void testHeartBeatThread(ProgramRunStatus terminalState) throws Exception {
    // configure program state writer to emit heart beat every second
    MockProgramStatePublisher programStatePublisher = new MockProgramStatePublisher();
    AtomicReference<ProgramRunStatus> completionState = new AtomicReference<>();
    ProgramStateWriter programStateWriter = new NoOpProgramStateWriter() {

        @Override
        public void completed(ProgramRunId programRunId) {
            super.completed(programRunId);
            completionState.set(ProgramRunStatus.COMPLETED);
        }

        @Override
        public void killed(ProgramRunId programRunId) {
            super.killed(programRunId);
            completionState.set(ProgramRunStatus.KILLED);
        }

        @Override
        public void error(ProgramRunId programRunId, Throwable failureCause) {
            super.error(programRunId, failureCause);
            completionState.set(ProgramRunStatus.FAILED);
        }
    };
    // mock program configurations
    ProgramId programId = NamespaceId.DEFAULT.app("someapp").program(ProgramType.SERVICE, "s");
    Map<String, String> systemArguments = new HashMap<>();
    systemArguments.put(ProgramOptionConstants.SKIP_PROVISIONING, Boolean.TRUE.toString());
    ProgramOptions programOptions = new SimpleProgramOptions(programId, new BasicArguments(systemArguments), new BasicArguments());
    ProgramRunId runId = programId.run(RunIds.generate());
    ArtifactId artifactId = NamespaceId.DEFAULT.artifact("testArtifact", "1.0").toApiArtifactId();
    ProgramStateWriterWithHeartBeat programStateWriterWithHeartBeat = new ProgramStateWriterWithHeartBeat(runId, programStateWriter, 1, programStatePublisher);
    ApplicationSpecification appSpec = new DefaultApplicationSpecification("name", "1.0.0", ProjectInfo.getVersion().toString(), "desc", null, artifactId, Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap());
    ProgramDescriptor programDescriptor = new ProgramDescriptor(programId, appSpec);
    // start the program and ensure heart beat is 0 before we call running
    programStateWriter.start(runId, programOptions, null, programDescriptor);
    Assert.assertEquals(0, programStatePublisher.getHeartBeatCount());
    programStateWriterWithHeartBeat.running(null);
    // on running, we start receiving heart beat messages, verify if the heartbeat count goes to 2.
    Tasks.waitFor(true, () -> programStatePublisher.getHeartBeatCount() > 1, 10, TimeUnit.SECONDS, "Didn't receive expected heartbeat after 10 seconds");
    // Terminate the program and make sure the heart beat thread also gets stopped
    switch(terminalState) {
        case COMPLETED:
            programStateWriterWithHeartBeat.completed();
            break;
        case FAILED:
            programStateWriterWithHeartBeat.error(new RuntimeException());
            break;
        case KILLED:
            programStateWriterWithHeartBeat.killed();
            break;
        default:
            throw new IllegalStateException("The terminal state must one of COMPLETED, FAILED, or KILLED");
    }
    Tasks.waitFor(false, programStateWriterWithHeartBeat::isHeartBeatThreadAlive, 5, TimeUnit.SECONDS, "Heartbeat thread did not stop after 5 seconds");
    Assert.assertEquals(terminalState, completionState.get());
}
Also used : NoOpProgramStateWriter(io.cdap.cdap.app.runtime.NoOpProgramStateWriter) DefaultApplicationSpecification(io.cdap.cdap.internal.app.DefaultApplicationSpecification) ApplicationSpecification(io.cdap.cdap.api.app.ApplicationSpecification) ArtifactId(io.cdap.cdap.api.artifact.ArtifactId) HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) ProgramId(io.cdap.cdap.proto.id.ProgramId) SimpleProgramOptions(io.cdap.cdap.internal.app.runtime.SimpleProgramOptions) ProgramOptions(io.cdap.cdap.app.runtime.ProgramOptions) ProgramRunStatus(io.cdap.cdap.proto.ProgramRunStatus) NoOpProgramStateWriter(io.cdap.cdap.app.runtime.NoOpProgramStateWriter) ProgramStateWriter(io.cdap.cdap.app.runtime.ProgramStateWriter) ProgramRunId(io.cdap.cdap.proto.id.ProgramRunId) SimpleProgramOptions(io.cdap.cdap.internal.app.runtime.SimpleProgramOptions) BasicArguments(io.cdap.cdap.internal.app.runtime.BasicArguments) DefaultApplicationSpecification(io.cdap.cdap.internal.app.DefaultApplicationSpecification) ProgramDescriptor(io.cdap.cdap.app.program.ProgramDescriptor)

Example 17 with ProgramOptions

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

the class RuntimeServiceMainTest method testRuntimeService.

@Test
public void testRuntimeService() throws Exception {
    ArtifactId artifactId = NamespaceId.DEFAULT.artifact("test", "1.0");
    ProgramRunId programRunId = NamespaceId.DEFAULT.app("app").worker("worker").run(RunIds.generate());
    Map<String, String> systemArgs = ImmutableMap.of(SystemArguments.PROFILE_PROVISIONER, NativeProvisioner.SPEC.getName(), SystemArguments.PROFILE_NAME, "default");
    ProgramOptions programOptions = new SimpleProgramOptions(programRunId.getParent(), new BasicArguments(systemArgs), new BasicArguments());
    ProgramDescriptor programDescriptor = new ProgramDescriptor(programRunId.getParent(), null, artifactId);
    // Write out program state events to simulate program start
    Injector appFabricInjector = getServiceMainInstance(AppFabricServiceMain.class).getInjector();
    CConfiguration cConf = appFabricInjector.getInstance(CConfiguration.class);
    ProgramStatePublisher programStatePublisher = new MessagingProgramStatePublisher(appFabricInjector.getInstance(MessagingService.class), NamespaceId.SYSTEM.topic(cConf.get(Constants.AppFabric.PROGRAM_STATUS_RECORD_EVENT_TOPIC)), RetryStrategies.fromConfiguration(cConf, "system.program.state."));
    new MessagingProgramStateWriter(programStatePublisher).start(programRunId, programOptions, null, programDescriptor);
    Injector injector = getServiceMainInstance(RuntimeServiceMain.class).getInjector();
    TransactionRunner txRunner = injector.getInstance(TransactionRunner.class);
    // Should see a STARTING record in the runtime store
    Tasks.waitFor(ProgramRunStatus.STARTING, () -> {
        RunRecordDetail detail = TransactionRunners.run(txRunner, context -> {
            return AppMetadataStore.create(context).getRun(programRunId);
        });
        return detail == null ? null : detail.getStatus();
    }, 5, TimeUnit.SECONDS);
    ProgramStateWriter programStateWriter = createProgramStateWriter(injector, programRunId);
    // Write a running state. We should see a RUNNING record in the runtime store
    programStateWriter.running(programRunId, null);
    Tasks.waitFor(ProgramRunStatus.RUNNING, () -> {
        RunRecordDetail detail = TransactionRunners.run(txRunner, context -> {
            return AppMetadataStore.create(context).getRun(programRunId);
        });
        return detail == null ? null : detail.getStatus();
    }, 5, TimeUnit.SECONDS);
    // Write a complete state. The run record should be removed in the runtime store
    programStateWriter.completed(programRunId);
    Tasks.waitFor(true, () -> TransactionRunners.run(txRunner, context -> AppMetadataStore.create(context).getRun(programRunId) == null), 5, TimeUnit.SECONDS);
}
Also used : Retries(io.cdap.cdap.common.service.Retries) RetryStrategy(io.cdap.cdap.common.service.RetryStrategy) RunRecordDetail(io.cdap.cdap.internal.app.store.RunRecordDetail) TransactionRunners(io.cdap.cdap.spi.data.transaction.TransactionRunners) BeforeClass(org.junit.BeforeClass) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) MessagingProgramStateWriter(io.cdap.cdap.internal.app.program.MessagingProgramStateWriter) Notification(io.cdap.cdap.proto.Notification) Bytes(io.cdap.cdap.api.common.Bytes) RetryStrategies(io.cdap.cdap.common.service.RetryStrategies) TopicId(io.cdap.cdap.proto.id.TopicId) ProgramRunId(io.cdap.cdap.proto.id.ProgramRunId) ProgramStateWriter(io.cdap.cdap.app.runtime.ProgramStateWriter) SimpleProgramOptions(io.cdap.cdap.internal.app.runtime.SimpleProgramOptions) Gson(com.google.gson.Gson) ProgramOptions(io.cdap.cdap.app.runtime.ProgramOptions) Map(java.util.Map) SystemArguments(io.cdap.cdap.internal.app.runtime.SystemArguments) NativeProvisioner(io.cdap.cdap.internal.provision.NativeProvisioner) ArtifactId(io.cdap.cdap.proto.id.ArtifactId) AppMetadataStore(io.cdap.cdap.internal.app.store.AppMetadataStore) Tasks(io.cdap.cdap.common.utils.Tasks) Message(io.cdap.cdap.api.messaging.Message) ImmutableMap(com.google.common.collect.ImmutableMap) RunIds(io.cdap.cdap.common.app.RunIds) ProgramStatePublisher(io.cdap.cdap.internal.app.program.ProgramStatePublisher) RetryableException(io.cdap.cdap.api.retry.RetryableException) MessagingService(io.cdap.cdap.messaging.MessagingService) ProgramDescriptor(io.cdap.cdap.app.program.ProgramDescriptor) MessagingProgramStatePublisher(io.cdap.cdap.internal.app.program.MessagingProgramStatePublisher) RuntimeClient(io.cdap.cdap.internal.app.runtime.monitor.RuntimeClient) Test(org.junit.Test) IOException(java.io.IOException) ProgramRunStatus(io.cdap.cdap.proto.ProgramRunStatus) StandardCharsets(java.nio.charset.StandardCharsets) MessageId(io.cdap.cdap.messaging.data.MessageId) Injector(com.google.inject.Injector) TimeUnit(java.util.concurrent.TimeUnit) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) TransactionRunner(io.cdap.cdap.spi.data.transaction.TransactionRunner) Constants(io.cdap.cdap.common.conf.Constants) Collections(java.util.Collections) BasicArguments(io.cdap.cdap.internal.app.runtime.BasicArguments) ArtifactId(io.cdap.cdap.proto.id.ArtifactId) RunRecordDetail(io.cdap.cdap.internal.app.store.RunRecordDetail) MessagingProgramStateWriter(io.cdap.cdap.internal.app.program.MessagingProgramStateWriter) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) SimpleProgramOptions(io.cdap.cdap.internal.app.runtime.SimpleProgramOptions) ProgramOptions(io.cdap.cdap.app.runtime.ProgramOptions) MessagingService(io.cdap.cdap.messaging.MessagingService) MessagingProgramStatePublisher(io.cdap.cdap.internal.app.program.MessagingProgramStatePublisher) MessagingProgramStateWriter(io.cdap.cdap.internal.app.program.MessagingProgramStateWriter) ProgramStateWriter(io.cdap.cdap.app.runtime.ProgramStateWriter) Injector(com.google.inject.Injector) TransactionRunner(io.cdap.cdap.spi.data.transaction.TransactionRunner) ProgramRunId(io.cdap.cdap.proto.id.ProgramRunId) SimpleProgramOptions(io.cdap.cdap.internal.app.runtime.SimpleProgramOptions) BasicArguments(io.cdap.cdap.internal.app.runtime.BasicArguments) ProgramDescriptor(io.cdap.cdap.app.program.ProgramDescriptor) ProgramStatePublisher(io.cdap.cdap.internal.app.program.ProgramStatePublisher) MessagingProgramStatePublisher(io.cdap.cdap.internal.app.program.MessagingProgramStatePublisher) Test(org.junit.Test)

Example 18 with ProgramOptions

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

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 19 with ProgramOptions

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

the class AbstractProgramTwillRunnable method createProgramOptions.

/**
 * Creates a {@link ProgramOptions} by deserializing the given json file.
 */
private ProgramOptions createProgramOptions(File programOptionsFile) throws IOException {
    ProgramOptions original = readJsonFile(programOptionsFile, ProgramOptions.class);
    // Overwrite them with environmental information
    Map<String, String> arguments = new HashMap<>(original.getArguments().asMap());
    arguments.putAll(getExtraSystemArguments());
    // Use the name passed in by the constructor as the program name to construct the ProgramId
    return new SimpleProgramOptions(original.getProgramId(), new BasicArguments(arguments), original.getUserArguments(), original.isDebug());
}
Also used : HashMap(java.util.HashMap) SimpleProgramOptions(io.cdap.cdap.internal.app.runtime.SimpleProgramOptions) BasicArguments(io.cdap.cdap.internal.app.runtime.BasicArguments) SimpleProgramOptions(io.cdap.cdap.internal.app.runtime.SimpleProgramOptions) ProgramOptions(io.cdap.cdap.app.runtime.ProgramOptions)

Example 20 with ProgramOptions

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

the class DistributedProgramRunner method run.

@Override
public final ProgramController run(final Program program, ProgramOptions oldOptions) {
    validateOptions(program, oldOptions);
    CConfiguration cConf = CConfiguration.copy(this.cConf);
    // Reload config for log extension jar update (CDAP-15091)
    cConf.reloadConfiguration();
    File tempDir = DirUtils.createTempDir(new File(cConf.get(Constants.CFG_LOCAL_DATA_DIR), cConf.get(Constants.AppFabric.TEMP_DIR)).getAbsoluteFile());
    try {
        // For runs from a tethered instance, load additional resources
        if (oldOptions.getArguments().hasOption(ProgramOptionConstants.PEER_NAME)) {
            loadAdditionalResources(oldOptions.getArguments(), cConf, tempDir);
        }
        ProgramLaunchConfig launchConfig = new ProgramLaunchConfig();
        if (clusterMode == ClusterMode.ISOLATED) {
            // For isolated mode, the hadoop classes comes from the hadoop classpath in the target cluster directly
            launchConfig.addExtraClasspath(Collections.singletonList("$HADOOP_CLASSPATH"));
        }
        setupLaunchConfig(launchConfig, program, oldOptions, cConf, hConf, tempDir);
        // Add extra localize resources needed by the program runner
        final Map<String, LocalizeResource> localizeResources = new HashMap<>(launchConfig.getExtraResources());
        final List<String> additionalClassPaths = new ArrayList<>();
        addContainerJars(cConf, localizeResources, additionalClassPaths);
        addAdditionalLogAppenderJars(cConf, tempDir, localizeResources, SystemArguments.getProfileProvisioner(oldOptions.getArguments().asMap()));
        prepareHBaseDDLExecutorResources(tempDir, cConf, localizeResources);
        List<URI> configResources = localizeConfigs(createContainerCConf(cConf), createContainerHConf(this.hConf), tempDir, localizeResources);
        // Localize the program jar
        Location programJarLocation = program.getJarLocation();
        final String programJarName = programJarLocation.getName();
        localizeResources.put(programJarName, new LocalizeResource(programJarLocation.toURI(), false));
        // Localize the app spec
        localizeResources.put(APP_SPEC_FILE_NAME, new LocalizeResource(saveJsonFile(program.getApplicationSpecification(), ApplicationSpecification.class, File.createTempFile("appSpec", ".json", tempDir))));
        URI logbackURI = getLogBackURI(program, oldOptions.getArguments(), tempDir);
        if (logbackURI != null) {
            // Localize the logback xml
            localizeResources.put(LOGBACK_FILE_NAME, new LocalizeResource(logbackURI, false));
        }
        // Update the ProgramOptions to carry program and runtime information necessary to reconstruct the program
        // and runs it in the remote container
        Map<String, String> extraSystemArgs = new HashMap<>(launchConfig.getExtraSystemArguments());
        extraSystemArgs.put(ProgramOptionConstants.PROGRAM_JAR, programJarName);
        extraSystemArgs.put(ProgramOptionConstants.HADOOP_CONF_FILE, HADOOP_CONF_FILE_NAME);
        extraSystemArgs.put(ProgramOptionConstants.CDAP_CONF_FILE, CDAP_CONF_FILE_NAME);
        extraSystemArgs.put(ProgramOptionConstants.APP_SPEC_FILE, APP_SPEC_FILE_NAME);
        ProgramOptions options = updateProgramOptions(oldOptions, localizeResources, DirUtils.createTempDir(tempDir), extraSystemArgs);
        ProgramRunId programRunId = program.getId().run(ProgramRunners.getRunId(options));
        // Localize the serialized program options
        localizeResources.put(PROGRAM_OPTIONS_FILE_NAME, new LocalizeResource(saveJsonFile(options, ProgramOptions.class, File.createTempFile("program.options", ".json", tempDir))));
        Callable<ProgramController> callable = () -> {
            ProgramTwillApplication twillApplication = new ProgramTwillApplication(programRunId, options, launchConfig.getRunnables(), launchConfig.getLaunchOrder(), localizeResources, createEventHandler(cConf, programRunId, options));
            TwillPreparer twillPreparer = twillRunner.prepare(twillApplication);
            // Also add the configuration files to container classpath so that the
            // TwillAppLifecycleEventHandler can get it. This can be removed when TWILL-246 is fixed.
            // Only ON_PREMISE mode will be using EventHandler
            twillPreparer.withResources(configResources);
            Map<String, String> userArgs = options.getUserArguments().asMap();
            // Setup log level
            twillPreparer.setLogLevels(transformLogLevels(SystemArguments.getLogLevels(userArgs)));
            // Set the configuration for the twill application
            Map<String, String> twillConfigs = new HashMap<>();
            if (DistributedProgramRunner.this instanceof LongRunningDistributedProgramRunner) {
                twillConfigs.put(Configs.Keys.YARN_ATTEMPT_FAILURES_VALIDITY_INTERVAL, cConf.get(Constants.AppFabric.YARN_ATTEMPT_FAILURES_VALIDITY_INTERVAL));
            } else {
                // For non long running program type, set the max attempts to 1 to avoid YARN retry.
                // If the AM container dies, the program execution will be marked as failure.
                // Note that this setting is only applicable to the Twill YARN application
                // (e.g. workflow, Spark client, MR client, etc), but not to the actual Spark / MR job.
                twillConfigs.put(Configs.Keys.YARN_MAX_APP_ATTEMPTS, Integer.toString(1));
            }
            // Add twill configurations coming from the runtime arguments
            twillConfigs.putAll(SystemArguments.getNamespaceConfigs(options.getArguments().asMap()));
            twillConfigs.putAll(SystemArguments.getTwillApplicationConfigs(userArgs));
            twillPreparer.withConfiguration(twillConfigs);
            // Setup per runnable configurations
            Set<String> runnables = new HashSet<>();
            for (Map.Entry<String, RunnableDefinition> entry : launchConfig.getRunnables().entrySet()) {
                String runnable = entry.getKey();
                runnables.add(runnable);
                RunnableDefinition runnableDefinition = entry.getValue();
                if (runnableDefinition.getMaxRetries() != null) {
                    twillPreparer.withMaxRetries(runnable, runnableDefinition.getMaxRetries());
                }
                twillPreparer.setLogLevels(runnable, transformLogLevels(runnableDefinition.getLogLevels()));
                twillPreparer.withConfiguration(runnable, runnableDefinition.getTwillRunnableConfigs());
                // Add cdap-security.xml if using secrets, and set the runnable identity.
                if (twillPreparer instanceof SecureTwillPreparer) {
                    String twillSystemIdentity = cConf.get(Constants.Twill.Security.IDENTITY_SYSTEM);
                    if (twillSystemIdentity != null) {
                        SecurityContext securityContext = new SecurityContext.Builder().withIdentity(twillSystemIdentity).build();
                        twillPreparer = ((SecureTwillPreparer) twillPreparer).withSecurityContext(runnable, securityContext);
                    }
                    String securityName = cConf.get(Constants.Twill.Security.MASTER_SECRET_DISK_NAME);
                    String securityPath = cConf.get(Constants.Twill.Security.MASTER_SECRET_DISK_PATH);
                    twillPreparer = ((SecureTwillPreparer) twillPreparer).withSecretDisk(runnable, new SecretDisk(securityName, securityPath));
                }
            }
            if (options.isDebug()) {
                twillPreparer.enableDebugging();
            }
            logProgramStart(program, options);
            // Add scheduler queue name if defined
            String schedulerQueueName = options.getArguments().getOption(Constants.AppFabric.APP_SCHEDULER_QUEUE);
            if (schedulerQueueName != null && !schedulerQueueName.isEmpty()) {
                LOG.info("Setting scheduler queue for app {} as {}", program.getId(), schedulerQueueName);
                twillPreparer.setSchedulerQueue(schedulerQueueName);
            }
            // Set JVM options based on configuration
            String jvmOpts = cConf.get(Constants.AppFabric.PROGRAM_JVM_OPTS);
            if (!Strings.isNullOrEmpty(jvmOpts)) {
                twillPreparer.addJVMOptions(jvmOpts);
            }
            // Overwrite JVM options if specified
            LauncherUtils.overrideJVMOpts(cConf, twillPreparer, runnables);
            if (logbackURI != null) {
                twillPreparer.addJVMOptions("-Dlogback.configurationFile=" + LOGBACK_FILE_NAME);
            }
            addLogHandler(twillPreparer, cConf);
            // Setup the environment for the container logback.xml
            twillPreparer.withEnv(Collections.singletonMap("CDAP_LOG_DIR", ApplicationConstants.LOG_DIR_EXPANSION_VAR));
            // Add dependencies
            Set<Class<?>> extraDependencies = addExtraDependencies(cConf, new HashSet<>(launchConfig.getExtraDependencies()));
            twillPreparer.withDependencies(extraDependencies);
            // Add the additional classes to the classpath that comes from the container jar setting
            twillPreparer.withClassPaths(additionalClassPaths);
            twillPreparer.withClassPaths(launchConfig.getExtraClasspath());
            twillPreparer.withEnv(launchConfig.getExtraEnv());
            // Add the YARN_APPLICATION_CLASSPATH so that yarn classpath are included in the twill container.
            // The Yarn app classpath goes last
            List<String> yarnAppClassPath = Arrays.asList(hConf.getTrimmedStrings(YarnConfiguration.YARN_APPLICATION_CLASSPATH, YarnConfiguration.DEFAULT_YARN_APPLICATION_CLASSPATH));
            twillPreparer.withApplicationClassPaths(yarnAppClassPath).withClassPaths(yarnAppClassPath);
            twillPreparer.withBundlerClassAcceptor(launchConfig.getClassAcceptor()).withApplicationArguments(PROGRAM_OPTIONS_FILE_NAME).setClassLoader(MainClassLoader.class.getName());
            TwillController twillController;
            // Change the context classloader to the combine classloader of this ProgramRunner and
            // all the classloaders of the dependencies classes so that Twill can trace classes.
            ClassLoader oldClassLoader = ClassLoaders.setContextClassLoader(new CombineClassLoader(DistributedProgramRunner.this.getClass().getClassLoader(), extraDependencies.stream().map(Class::getClassLoader)::iterator));
            try {
                twillController = twillPreparer.start(cConf.getLong(Constants.AppFabric.PROGRAM_MAX_START_SECONDS), TimeUnit.SECONDS);
                // Block on the twill controller until it is in running state or terminated (due to failure)
                CountDownLatch latch = new CountDownLatch(1);
                twillController.onRunning(latch::countDown, Threads.SAME_THREAD_EXECUTOR);
                twillController.onTerminated(latch::countDown, Threads.SAME_THREAD_EXECUTOR);
                latch.await(cConf.getLong(Constants.AppFabric.PROGRAM_MAX_START_SECONDS), TimeUnit.SECONDS);
            } finally {
                ClassLoaders.setContextClassLoader(oldClassLoader);
            }
            return createProgramController(programRunId, addCleanupListener(twillController, program, tempDir));
        };
        return impersonator.doAs(programRunId, callable);
    } catch (Exception e) {
        deleteDirectory(tempDir);
        throw Throwables.propagate(e);
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SecretDisk(io.cdap.cdap.master.spi.twill.SecretDisk) URI(java.net.URI) CombineClassLoader(io.cdap.cdap.common.lang.CombineClassLoader) LogEntry(org.apache.twill.api.logging.LogEntry) CombineClassLoader(io.cdap.cdap.common.lang.CombineClassLoader) MainClassLoader(io.cdap.cdap.common.app.MainClassLoader) List(java.util.List) ArrayList(java.util.ArrayList) TwillPreparer(org.apache.twill.api.TwillPreparer) SecureTwillPreparer(io.cdap.cdap.master.spi.twill.SecureTwillPreparer) HashSet(java.util.HashSet) ProgramController(io.cdap.cdap.app.runtime.ProgramController) CountDownLatch(java.util.concurrent.CountDownLatch) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) SimpleProgramOptions(io.cdap.cdap.internal.app.runtime.SimpleProgramOptions) ProgramOptions(io.cdap.cdap.app.runtime.ProgramOptions) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) TwillController(org.apache.twill.api.TwillController) SecureTwillPreparer(io.cdap.cdap.master.spi.twill.SecureTwillPreparer) SecurityContext(io.cdap.cdap.master.spi.twill.SecurityContext) ProgramRunId(io.cdap.cdap.proto.id.ProgramRunId) File(java.io.File) Map(java.util.Map) HashMap(java.util.HashMap) Location(org.apache.twill.filesystem.Location)

Aggregations

ProgramOptions (io.cdap.cdap.app.runtime.ProgramOptions)68 SimpleProgramOptions (io.cdap.cdap.internal.app.runtime.SimpleProgramOptions)52 BasicArguments (io.cdap.cdap.internal.app.runtime.BasicArguments)40 ProgramRunId (io.cdap.cdap.proto.id.ProgramRunId)40 ProgramDescriptor (io.cdap.cdap.app.program.ProgramDescriptor)32 HashMap (java.util.HashMap)26 CConfiguration (io.cdap.cdap.common.conf.CConfiguration)24 IOException (java.io.IOException)24 ProgramId (io.cdap.cdap.proto.id.ProgramId)22 ApplicationSpecification (io.cdap.cdap.api.app.ApplicationSpecification)20 Test (org.junit.Test)14 ArtifactId (io.cdap.cdap.api.artifact.ArtifactId)12 Program (io.cdap.cdap.app.program.Program)12 ProgramStateWriter (io.cdap.cdap.app.runtime.ProgramStateWriter)12 SystemArguments (io.cdap.cdap.internal.app.runtime.SystemArguments)12 Map (java.util.Map)12 Injector (com.google.inject.Injector)10 MetricsCollectionService (io.cdap.cdap.api.metrics.MetricsCollectionService)10 ClusterMode (io.cdap.cdap.app.guice.ClusterMode)10 MessagingService (io.cdap.cdap.messaging.MessagingService)10