Search in sources :

Example 1 with RuntimeJobEnvironment

use of io.cdap.cdap.runtime.spi.runtimejob.RuntimeJobEnvironment in project cdap by caskdata.

the class RemoteExecutionJobMainTest method testJobEnvironment.

@Test
public void testJobEnvironment() throws Exception {
    CConfiguration cConf = CConfiguration.create();
    cConf.set(Constants.CFG_LOCAL_DATA_DIR, TEMP_FOLDER.newFolder().getAbsolutePath());
    cConf.set(Constants.CFG_HDFS_NAMESPACE, TEMP_FOLDER.newFolder().getAbsolutePath());
    RemoteExecutionJobMain runner = new RemoteExecutionJobMain();
    RuntimeJobEnvironment jobEnv = runner.initialize(cConf);
    try {
        Assert.assertNotNull(jobEnv.getLocationFactory());
        Assert.assertNotNull(jobEnv.getTwillRunner());
        Map<String, String> properties = jobEnv.getProperties();
        ZKClientService zkClient = ZKClientService.Builder.of(properties.get(Constants.Zookeeper.QUORUM)).build();
        zkClient.startAndWait();
        try {
            Assert.assertNotNull(zkClient.exists("/").get());
        } finally {
            zkClient.stopAndWait();
        }
    } finally {
        runner.destroy();
    }
}
Also used : ZKClientService(org.apache.twill.zookeeper.ZKClientService) RuntimeJobEnvironment(io.cdap.cdap.runtime.spi.runtimejob.RuntimeJobEnvironment) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) Test(org.junit.Test)

Example 2 with RuntimeJobEnvironment

use of io.cdap.cdap.runtime.spi.runtimejob.RuntimeJobEnvironment in project cdap by caskdata.

the class DefaultRuntimeJobTest method testInjector.

@Test
public void testInjector() throws Exception {
    CConfiguration cConf = CConfiguration.create();
    cConf.set(Constants.CFG_LOCAL_DATA_DIR, TEMP_FOLDER.newFolder().toString());
    LocationFactory locationFactory = new LocalLocationFactory(TEMP_FOLDER.newFile());
    DefaultRuntimeJob defaultRuntimeJob = new DefaultRuntimeJob();
    Arguments systemArgs = new BasicArguments(Collections.singletonMap(SystemArguments.PROFILE_NAME, "test"));
    Node node = new Node("test", Node.Type.MASTER, "127.0.0.1", System.currentTimeMillis(), Collections.emptyMap());
    Cluster cluster = new Cluster("test", ClusterStatus.RUNNING, Collections.singleton(node), Collections.emptyMap());
    ProgramRunId programRunId = NamespaceId.DEFAULT.app("app").workflow("workflow").run(RunIds.generate());
    SimpleProgramOptions programOpts = new SimpleProgramOptions(programRunId.getParent(), systemArgs, new BasicArguments());
    Injector injector = Guice.createInjector(defaultRuntimeJob.createModules(new RuntimeJobEnvironment() {

        @Override
        public LocationFactory getLocationFactory() {
            return locationFactory;
        }

        @Override
        public TwillRunner getTwillRunner() {
            return new NoopTwillRunnerService();
        }

        @Override
        public Map<String, String> getProperties() {
            return Collections.emptyMap();
        }
    }, cConf, programRunId, programOpts));
    injector.getInstance(LogAppenderInitializer.class);
    defaultRuntimeJob.createCoreServices(injector, systemArgs, cluster);
}
Also used : Node(io.cdap.cdap.runtime.spi.provisioner.Node) Arguments(io.cdap.cdap.app.runtime.Arguments) SystemArguments(io.cdap.cdap.internal.app.runtime.SystemArguments) BasicArguments(io.cdap.cdap.internal.app.runtime.BasicArguments) Cluster(io.cdap.cdap.runtime.spi.provisioner.Cluster) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) LocalLocationFactory(org.apache.twill.filesystem.LocalLocationFactory) LocationFactory(org.apache.twill.filesystem.LocationFactory) NoopTwillRunnerService(io.cdap.cdap.common.twill.NoopTwillRunnerService) Injector(com.google.inject.Injector) RuntimeJobEnvironment(io.cdap.cdap.runtime.spi.runtimejob.RuntimeJobEnvironment) BasicArguments(io.cdap.cdap.internal.app.runtime.BasicArguments) ProgramRunId(io.cdap.cdap.proto.id.ProgramRunId) SimpleProgramOptions(io.cdap.cdap.internal.app.runtime.SimpleProgramOptions) LocalLocationFactory(org.apache.twill.filesystem.LocalLocationFactory) Test(org.junit.Test)

Aggregations

CConfiguration (io.cdap.cdap.common.conf.CConfiguration)2 RuntimeJobEnvironment (io.cdap.cdap.runtime.spi.runtimejob.RuntimeJobEnvironment)2 Test (org.junit.Test)2 Injector (com.google.inject.Injector)1 Arguments (io.cdap.cdap.app.runtime.Arguments)1 NoopTwillRunnerService (io.cdap.cdap.common.twill.NoopTwillRunnerService)1 BasicArguments (io.cdap.cdap.internal.app.runtime.BasicArguments)1 SimpleProgramOptions (io.cdap.cdap.internal.app.runtime.SimpleProgramOptions)1 SystemArguments (io.cdap.cdap.internal.app.runtime.SystemArguments)1 ProgramRunId (io.cdap.cdap.proto.id.ProgramRunId)1 Cluster (io.cdap.cdap.runtime.spi.provisioner.Cluster)1 Node (io.cdap.cdap.runtime.spi.provisioner.Node)1 LocalLocationFactory (org.apache.twill.filesystem.LocalLocationFactory)1 LocationFactory (org.apache.twill.filesystem.LocationFactory)1 ZKClientService (org.apache.twill.zookeeper.ZKClientService)1