Search in sources :

Example 1 with ClusterMode

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

the class AbstractProgramTwillRunnable method doInitialize.

/**
 * Prepares this instance to execute a program.
 *
 * @param programOptionFile a json file containing the serialized {@link ProgramOptions}
 * @throws Exception if failed to initialize
 */
private void doInitialize(File programOptionFile) throws Exception {
    controllerFuture = new CompletableFuture<>();
    programCompletion = new CompletableFuture<>();
    // Setup process wide settings
    Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler());
    System.setSecurityManager(new ProgramContainerSecurityManager(System.getSecurityManager()));
    SLF4JBridgeHandler.removeHandlersForRootLogger();
    SLF4JBridgeHandler.install();
    // Create the ProgramOptions
    programOptions = createProgramOptions(programOptionFile);
    programRunId = programOptions.getProgramId().run(ProgramRunners.getRunId(programOptions));
    Arguments systemArgs = programOptions.getArguments();
    LoggingContextAccessor.setLoggingContext(LoggingContextHelper.getLoggingContextWithRunId(programRunId, systemArgs.asMap()));
    ClusterMode clusterMode = ProgramRunners.getClusterMode(programOptions);
    // Loads configurations
    Configuration hConf = new Configuration();
    if (clusterMode == ClusterMode.ON_PREMISE) {
        hConf.clear();
        hConf.addResource(new File(systemArgs.getOption(ProgramOptionConstants.HADOOP_CONF_FILE)).toURI().toURL());
    }
    UserGroupInformation.setConfiguration(hConf);
    CConfiguration cConf = CConfiguration.create();
    cConf.clear();
    cConf.addResource(new File(systemArgs.getOption(ProgramOptionConstants.CDAP_CONF_FILE)).toURI().toURL());
    maxStopSeconds = cConf.getLong(io.cdap.cdap.common.conf.Constants.AppFabric.PROGRAM_MAX_STOP_SECONDS);
    Injector injector = Guice.createInjector(createModule(cConf, hConf, programOptions, programRunId));
    // Initialize log appender
    logAppenderInitializer = injector.getInstance(LogAppenderInitializer.class);
    logAppenderInitializer.initialize();
    SystemArguments.setLogLevel(programOptions.getUserArguments(), logAppenderInitializer);
    // Setup the proxy selector for in active monitoring mode
    oldProxySelector = ProxySelector.getDefault();
    if (clusterMode == ClusterMode.ISOLATED) {
        RuntimeMonitors.setupMonitoring(injector, programOptions);
    }
    // Create list of core services. They'll will be started in the run method and shutdown when the run
    // method completed
    coreServices = createCoreServices(injector, programOptions);
    // Create the ProgramRunner
    programRunner = createProgramRunner(injector);
    // Create the Program instance
    Location programJarLocation = Locations.toLocation(new File(systemArgs.getOption(ProgramOptionConstants.PROGRAM_JAR)));
    ApplicationSpecification appSpec = readJsonFile(new File(systemArgs.getOption(ProgramOptionConstants.APP_SPEC_FILE)), ApplicationSpecification.class);
    // Expand the program jar for creating classloader
    ClassLoaderFolder classLoaderFolder = BundleJarUtil.prepareClassLoaderFolder(programJarLocation, () -> new File("expanded." + System.currentTimeMillis() + programJarLocation.getName()));
    program = Programs.create(cConf, programRunner, new ProgramDescriptor(programOptions.getProgramId(), appSpec), programJarLocation, classLoaderFolder.getDir());
}
Also used : ApplicationSpecification(io.cdap.cdap.api.app.ApplicationSpecification) Configuration(org.apache.hadoop.conf.Configuration) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) ClusterMode(io.cdap.cdap.app.guice.ClusterMode) Arguments(io.cdap.cdap.app.runtime.Arguments) SystemArguments(io.cdap.cdap.internal.app.runtime.SystemArguments) BasicArguments(io.cdap.cdap.internal.app.runtime.BasicArguments) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) ClassLoaderFolder(io.cdap.cdap.common.lang.jar.ClassLoaderFolder) LogAppenderInitializer(io.cdap.cdap.logging.appender.LogAppenderInitializer) Injector(com.google.inject.Injector) ProgramDescriptor(io.cdap.cdap.app.program.ProgramDescriptor) UncaughtExceptionHandler(io.cdap.cdap.common.logging.common.UncaughtExceptionHandler) File(java.io.File) Location(org.apache.twill.filesystem.Location)

Example 2 with ClusterMode

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

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 3 with ClusterMode

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

the class ProgramTwillRunnableModuleTest method testService.

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

            @Override
            protected ServiceAnnouncer getServiceAnnouncer() {
                return new MockTwillContext();
            }
        }.createModule(CConfiguration.create(), new Configuration(), createProgramOptions(programRunId, mode), programRunId);
        Injector injector = Guice.createInjector(module);
        injector.getInstance(ServiceProgramRunner.class);
        injector.getInstance(ExploreClient.class);
    }
}
Also used : MockTwillContext(io.cdap.cdap.common.test.MockTwillContext) 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) ServiceAnnouncer(org.apache.twill.api.ServiceAnnouncer) Test(org.junit.Test)

Example 4 with ClusterMode

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

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 5 with ClusterMode

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

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