Search in sources :

Example 1 with RemoteExecutionDiscoveryModule

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

the class DefaultRuntimeJob method createModules.

/**
 * Returns list of guice modules used to start the program run.
 */
@VisibleForTesting
List<Module> createModules(RuntimeJobEnvironment runtimeJobEnv, CConfiguration cConf, ProgramRunId programRunId, ProgramOptions programOpts) {
    List<Module> modules = new ArrayList<>();
    modules.add(new ConfigModule(cConf));
    RuntimeMonitorType runtimeMonitorType = SystemArguments.getRuntimeMonitorType(cConf, programOpts);
    modules.add(RuntimeMonitors.getRemoteAuthenticatorModule(runtimeMonitorType, programOpts));
    modules.add(new IOModule());
    modules.add(new TMSLogAppenderModule());
    modules.add(new RemoteExecutionDiscoveryModule());
    modules.add(new AuthenticationContextModules().getProgramContainerModule(cConf));
    modules.add(new MetricsClientRuntimeModule().getDistributedModules());
    modules.add(new MessagingServerRuntimeModule().getStandaloneModules());
    modules.add(new AbstractModule() {

        @Override
        protected void configure() {
            bind(ClusterMode.class).toInstance(ClusterMode.ISOLATED);
            bind(UGIProvider.class).to(CurrentUGIProvider.class).in(Scopes.SINGLETON);
            // Bindings from the environment
            bind(TwillRunner.class).annotatedWith(Constants.AppFabric.ProgramRunner.class).toInstance(runtimeJobEnv.getTwillRunner());
            bind(LocationFactory.class).toInstance(runtimeJobEnv.getLocationFactory());
            MapBinder<ProgramType, ProgramRunner> defaultProgramRunnerBinder = MapBinder.newMapBinder(binder(), ProgramType.class, ProgramRunner.class);
            bind(ProgramRuntimeProvider.Mode.class).toInstance(ProgramRuntimeProvider.Mode.DISTRIBUTED);
            bind(ProgramRunnerFactory.class).annotatedWith(Constants.AppFabric.ProgramRunner.class).to(DefaultProgramRunnerFactory.class).in(Scopes.SINGLETON);
            bind(ProgramStateWriter.class).to(MessagingProgramStateWriter.class).in(Scopes.SINGLETON);
            defaultProgramRunnerBinder.addBinding(ProgramType.MAPREDUCE).to(DistributedMapReduceProgramRunner.class);
            defaultProgramRunnerBinder.addBinding(ProgramType.WORKFLOW).to(DistributedWorkflowProgramRunner.class);
            defaultProgramRunnerBinder.addBinding(ProgramType.WORKER).to(DistributedWorkerProgramRunner.class);
            bind(ProgramRunnerFactory.class).to(DefaultProgramRunnerFactory.class).in(Scopes.SINGLETON);
            bind(ProgramRunId.class).toInstance(programRunId);
            bind(RuntimeMonitorType.class).toInstance(runtimeMonitorType);
            install(new FactoryModuleBuilder().implement(Configurator.class, InMemoryConfigurator.class).build(ConfiguratorFactory.class));
            bind(String.class).annotatedWith(Names.named(RemoteIsolatedPluginFinder.ISOLATED_PLUGIN_DIR)).toInstance(programOpts.getArguments().getOption(ProgramOptionConstants.PLUGIN_DIR, DistributedProgramRunner.PLUGIN_DIR));
            bind(PluginFinder.class).to(RemoteIsolatedPluginFinder.class);
            bind(ArtifactRepositoryReader.class).to(RemoteArtifactRepositoryReader.class).in(Scopes.SINGLETON);
            bind(ArtifactRepository.class).to(RemoteArtifactRepository.class);
        }
    });
    return modules;
}
Also used : IOModule(io.cdap.cdap.common.guice.IOModule) RuntimeMonitorType(io.cdap.cdap.runtime.spi.RuntimeMonitorType) ConfigModule(io.cdap.cdap.common.guice.ConfigModule) FactoryModuleBuilder(com.google.inject.assistedinject.FactoryModuleBuilder) InMemoryConfigurator(io.cdap.cdap.internal.app.deploy.InMemoryConfigurator) Configurator(io.cdap.cdap.app.deploy.Configurator) UGIProvider(io.cdap.cdap.security.impersonation.UGIProvider) CurrentUGIProvider(io.cdap.cdap.security.impersonation.CurrentUGIProvider) TwillRunner(org.apache.twill.api.TwillRunner) ArrayList(java.util.ArrayList) MessagingServerRuntimeModule(io.cdap.cdap.messaging.guice.MessagingServerRuntimeModule) MetricsClientRuntimeModule(io.cdap.cdap.metrics.guice.MetricsClientRuntimeModule) RemoteExecutionDiscoveryModule(io.cdap.cdap.app.guice.RemoteExecutionDiscoveryModule) ProgramRunnerFactory(io.cdap.cdap.app.runtime.ProgramRunnerFactory) DefaultProgramRunnerFactory(io.cdap.cdap.app.guice.DefaultProgramRunnerFactory) ArtifactRepositoryReader(io.cdap.cdap.internal.app.runtime.artifact.ArtifactRepositoryReader) RemoteArtifactRepositoryReader(io.cdap.cdap.internal.app.runtime.artifact.RemoteArtifactRepositoryReader) TMSLogAppenderModule(io.cdap.cdap.logging.guice.TMSLogAppenderModule) ProgramStateWriter(io.cdap.cdap.app.runtime.ProgramStateWriter) MessagingProgramStateWriter(io.cdap.cdap.internal.app.program.MessagingProgramStateWriter) RemoteArtifactRepository(io.cdap.cdap.internal.app.runtime.artifact.RemoteArtifactRepository) ProgramType(io.cdap.cdap.proto.ProgramType) DistributedWorkflowProgramRunner(io.cdap.cdap.internal.app.runtime.distributed.DistributedWorkflowProgramRunner) DistributedProgramRunner(io.cdap.cdap.internal.app.runtime.distributed.DistributedProgramRunner) DistributedMapReduceProgramRunner(io.cdap.cdap.internal.app.runtime.distributed.DistributedMapReduceProgramRunner) DistributedWorkerProgramRunner(io.cdap.cdap.internal.app.runtime.distributed.DistributedWorkerProgramRunner) ProgramRunner(io.cdap.cdap.app.runtime.ProgramRunner) DistributedWorkflowProgramRunner(io.cdap.cdap.internal.app.runtime.distributed.DistributedWorkflowProgramRunner) AuthenticationContextModules(io.cdap.cdap.security.auth.context.AuthenticationContextModules) Constants(io.cdap.cdap.common.conf.Constants) ProgramOptionConstants(io.cdap.cdap.internal.app.runtime.ProgramOptionConstants) RemoteIsolatedPluginFinder(io.cdap.cdap.internal.app.runtime.artifact.RemoteIsolatedPluginFinder) DistributedMapReduceProgramRunner(io.cdap.cdap.internal.app.runtime.distributed.DistributedMapReduceProgramRunner) AbstractModule(com.google.inject.AbstractModule) ProgramRuntimeProvider(io.cdap.cdap.app.runtime.ProgramRuntimeProvider) MapBinder(com.google.inject.multibindings.MapBinder) DistributedWorkerProgramRunner(io.cdap.cdap.internal.app.runtime.distributed.DistributedWorkerProgramRunner) MessagingServerRuntimeModule(io.cdap.cdap.messaging.guice.MessagingServerRuntimeModule) TMSLogAppenderModule(io.cdap.cdap.logging.guice.TMSLogAppenderModule) IOModule(io.cdap.cdap.common.guice.IOModule) AbstractModule(com.google.inject.AbstractModule) Module(com.google.inject.Module) ConfigModule(io.cdap.cdap.common.guice.ConfigModule) RemoteExecutionDiscoveryModule(io.cdap.cdap.app.guice.RemoteExecutionDiscoveryModule) MetricsClientRuntimeModule(io.cdap.cdap.metrics.guice.MetricsClientRuntimeModule) InMemoryConfigurator(io.cdap.cdap.internal.app.deploy.InMemoryConfigurator) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with RemoteExecutionDiscoveryModule

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

the class TwillAppLifecycleEventHandler method initialize.

@Override
public void initialize(EventHandlerContext context) {
    super.initialize(context);
    this.runningPublished = new AtomicBoolean();
    this.twillRunId = context.getRunId();
    Map<String, String> configs = context.getSpecification().getConfigs();
    this.programRunId = GSON.fromJson(configs.get("programRunId"), ProgramRunId.class);
    this.clusterMode = ClusterMode.valueOf(configs.get("clusterMode"));
    this.runtimeMonitorType = RuntimeMonitorType.valueOf(configs.get("monitorType"));
    // Fetch cConf and hConf from resources jar
    File cConfFile = new File("resources.jar/resources/" + CDAP_CONF_FILE_NAME);
    File hConfFile = new File("resources.jar/resources/" + HADOOP_CONF_FILE_NAME);
    if (!cConfFile.exists()) {
        // This shouldn't happen, unless CDAP is misconfigured
        throw new IllegalArgumentException("Missing cConf file " + cConfFile.getAbsolutePath());
    }
    try {
        // Load the configuration from the XML files serialized from the cdap master.
        CConfiguration cConf = CConfiguration.create();
        cConf.clear();
        cConf.addResource(cConfFile.toURI().toURL());
        Configuration hConf = new Configuration();
        if (hConfFile.exists()) {
            hConf.clear();
            hConf.addResource(hConfFile.toURI().toURL());
        }
        // Create the injector to create a program state writer
        List<Module> modules = new ArrayList<>(Arrays.asList(new ConfigModule(cConf, hConf), RemoteAuthenticatorModules.getDefaultModule(), new MessagingClientModule(), new AbstractModule() {

            @Override
            protected void configure() {
                bind(ProgramStateWriter.class).to(MessagingProgramStateWriter.class);
            }
        }));
        switch(clusterMode) {
            case ON_PREMISE:
                modules.add(new AuthenticationContextModules().getProgramContainerModule(cConf));
                modules.add(new ZKClientModule());
                modules.add(new ZKDiscoveryModule());
                modules.add(new KafkaClientModule());
                break;
            case ISOLATED:
                modules.add(new AuthenticationContextModules().getProgramContainerModule(cConf));
                modules.add(new RemoteExecutionDiscoveryModule());
                modules.add(new AbstractModule() {

                    @Override
                    protected void configure() {
                        bind(RuntimeMonitorType.class).toInstance(runtimeMonitorType);
                    }
                });
                break;
        }
        Injector injector = Guice.createInjector(modules);
        if (clusterMode == ClusterMode.ON_PREMISE) {
            zkClientService = injector.getInstance(ZKClientService.class);
            zkClientService.startAndWait();
        }
        ProgramStateWriter programStateWriter = injector.getInstance(ProgramStateWriter.class);
        MessagingService messagingService = injector.getInstance(MessagingService.class);
        programStateWriterWithHeartBeat = new ProgramStateWriterWithHeartBeat(programRunId, programStateWriter, messagingService, cConf);
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
}
Also used : MessagingClientModule(io.cdap.cdap.messaging.guice.MessagingClientModule) Configuration(org.apache.hadoop.conf.Configuration) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) ZKDiscoveryModule(io.cdap.cdap.common.guice.ZKDiscoveryModule) ConfigModule(io.cdap.cdap.common.guice.ConfigModule) ArrayList(java.util.ArrayList) RemoteExecutionDiscoveryModule(io.cdap.cdap.app.guice.RemoteExecutionDiscoveryModule) ZKClientModule(io.cdap.cdap.common.guice.ZKClientModule) ProgramStateWriterWithHeartBeat(io.cdap.cdap.internal.app.program.ProgramStateWriterWithHeartBeat) MessagingProgramStateWriter(io.cdap.cdap.internal.app.program.MessagingProgramStateWriter) ProgramStateWriter(io.cdap.cdap.app.runtime.ProgramStateWriter) KafkaClientModule(io.cdap.cdap.common.guice.KafkaClientModule) Injector(com.google.inject.Injector) AuthenticationContextModules(io.cdap.cdap.security.auth.context.AuthenticationContextModules) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) AbstractModule(com.google.inject.AbstractModule) MessagingService(io.cdap.cdap.messaging.MessagingService) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ZKClientService(org.apache.twill.zookeeper.ZKClientService) ProgramRunId(io.cdap.cdap.proto.id.ProgramRunId) Module(com.google.inject.Module) ConfigModule(io.cdap.cdap.common.guice.ConfigModule) KafkaClientModule(io.cdap.cdap.common.guice.KafkaClientModule) ZKClientModule(io.cdap.cdap.common.guice.ZKClientModule) RemoteExecutionDiscoveryModule(io.cdap.cdap.app.guice.RemoteExecutionDiscoveryModule) ZKDiscoveryModule(io.cdap.cdap.common.guice.ZKDiscoveryModule) MessagingClientModule(io.cdap.cdap.messaging.guice.MessagingClientModule) AbstractModule(com.google.inject.AbstractModule) File(java.io.File)

Aggregations

AbstractModule (com.google.inject.AbstractModule)2 Module (com.google.inject.Module)2 RemoteExecutionDiscoveryModule (io.cdap.cdap.app.guice.RemoteExecutionDiscoveryModule)2 ProgramStateWriter (io.cdap.cdap.app.runtime.ProgramStateWriter)2 ConfigModule (io.cdap.cdap.common.guice.ConfigModule)2 MessagingProgramStateWriter (io.cdap.cdap.internal.app.program.MessagingProgramStateWriter)2 AuthenticationContextModules (io.cdap.cdap.security.auth.context.AuthenticationContextModules)2 ArrayList (java.util.ArrayList)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Injector (com.google.inject.Injector)1 FactoryModuleBuilder (com.google.inject.assistedinject.FactoryModuleBuilder)1 MapBinder (com.google.inject.multibindings.MapBinder)1 Configurator (io.cdap.cdap.app.deploy.Configurator)1 DefaultProgramRunnerFactory (io.cdap.cdap.app.guice.DefaultProgramRunnerFactory)1 ProgramRunner (io.cdap.cdap.app.runtime.ProgramRunner)1 ProgramRunnerFactory (io.cdap.cdap.app.runtime.ProgramRunnerFactory)1 ProgramRuntimeProvider (io.cdap.cdap.app.runtime.ProgramRuntimeProvider)1 CConfiguration (io.cdap.cdap.common.conf.CConfiguration)1 Constants (io.cdap.cdap.common.conf.Constants)1 IOModule (io.cdap.cdap.common.guice.IOModule)1