Search in sources :

Example 11 with ClusterMode

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

the class RemoteExecutionTwillRunnerService method createControllerIfNeeded.

/**
 * Creates a {@link TwillController} based on the given {@link RunRecordDetail} if it should be monitored by this
 * service.
 */
private boolean createControllerIfNeeded(RunRecordDetail runRecordDetail) {
    // Program runs in PENDING and STARTING state will eventually start and controller will be created later.
    if (runRecordDetail.getStatus() != ProgramRunStatus.RUNNING && runRecordDetail.getStatus() != ProgramRunStatus.SUSPENDED) {
        LOG.debug("Skip creating controller for run {} with status {}", runRecordDetail.getProgramRunId(), runRecordDetail.getStatus());
        return false;
    }
    Map<String, String> systemArgs = runRecordDetail.getSystemArgs();
    try {
        ClusterMode clusterMode = ClusterMode.valueOf(systemArgs.getOrDefault(ProgramOptionConstants.CLUSTER_MODE, ClusterMode.ON_PREMISE.name()));
        if (clusterMode != ClusterMode.ISOLATED) {
            LOG.debug("Ignore run {} of non supported cluster mode {}", runRecordDetail.getProgramRunId(), clusterMode);
            return false;
        }
    } catch (IllegalArgumentException e) {
        LOG.warn("Ignore run record with an invalid cluster mode", e);
        return false;
    }
    ProgramOptions programOpts = new SimpleProgramOptions(runRecordDetail.getProgramRunId().getParent(), new BasicArguments(runRecordDetail.getSystemArgs()), new BasicArguments(runRecordDetail.getUserArgs()));
    // Creates a controller via the controller factory.
    // Since there is no startup start needed, the timeout is arbitrarily short
    new ControllerFactory(runRecordDetail.getProgramRunId(), programOpts).create(null, 5, TimeUnit.SECONDS);
    return true;
}
Also used : ClusterMode(io.cdap.cdap.app.guice.ClusterMode) 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)

Aggregations

ClusterMode (io.cdap.cdap.app.guice.ClusterMode)11 CConfiguration (io.cdap.cdap.common.conf.CConfiguration)8 Configuration (org.apache.hadoop.conf.Configuration)8 Injector (com.google.inject.Injector)7 ProgramRunId (io.cdap.cdap.proto.id.ProgramRunId)7 Module (com.google.inject.Module)6 Test (org.junit.Test)4 ApplicationSpecification (io.cdap.cdap.api.app.ApplicationSpecification)3 Service (com.google.common.util.concurrent.Service)2 MetricsCollectionService (io.cdap.cdap.api.metrics.MetricsCollectionService)2 Program (io.cdap.cdap.app.program.Program)2 ProgramDescriptor (io.cdap.cdap.app.program.ProgramDescriptor)2 Arguments (io.cdap.cdap.app.runtime.Arguments)2 ProgramOptions (io.cdap.cdap.app.runtime.ProgramOptions)2 MockTwillContext (io.cdap.cdap.common.test.MockTwillContext)2 ProgramContextAware (io.cdap.cdap.data.ProgramContextAware)2 DatasetFramework (io.cdap.cdap.data2.dataset2.DatasetFramework)2 BasicArguments (io.cdap.cdap.internal.app.runtime.BasicArguments)2 BasicProgramContext (io.cdap.cdap.internal.app.runtime.BasicProgramContext)2 SimpleProgramOptions (io.cdap.cdap.internal.app.runtime.SimpleProgramOptions)2