Search in sources :

Example 1 with ProgramStateWriterWithHeartBeat

use of io.cdap.cdap.internal.app.program.ProgramStateWriterWithHeartBeat 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)

Example 2 with ProgramStateWriterWithHeartBeat

use of io.cdap.cdap.internal.app.program.ProgramStateWriterWithHeartBeat in project cdap by cdapio.

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 Injector (com.google.inject.Injector)2 Module (com.google.inject.Module)2 RemoteExecutionDiscoveryModule (io.cdap.cdap.app.guice.RemoteExecutionDiscoveryModule)2 ProgramStateWriter (io.cdap.cdap.app.runtime.ProgramStateWriter)2 CConfiguration (io.cdap.cdap.common.conf.CConfiguration)2 ConfigModule (io.cdap.cdap.common.guice.ConfigModule)2 KafkaClientModule (io.cdap.cdap.common.guice.KafkaClientModule)2 ZKClientModule (io.cdap.cdap.common.guice.ZKClientModule)2 ZKDiscoveryModule (io.cdap.cdap.common.guice.ZKDiscoveryModule)2 MessagingProgramStateWriter (io.cdap.cdap.internal.app.program.MessagingProgramStateWriter)2 ProgramStateWriterWithHeartBeat (io.cdap.cdap.internal.app.program.ProgramStateWriterWithHeartBeat)2 MessagingService (io.cdap.cdap.messaging.MessagingService)2 MessagingClientModule (io.cdap.cdap.messaging.guice.MessagingClientModule)2 ProgramRunId (io.cdap.cdap.proto.id.ProgramRunId)2 AuthenticationContextModules (io.cdap.cdap.security.auth.context.AuthenticationContextModules)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 Configuration (org.apache.hadoop.conf.Configuration)2