Search in sources :

Example 1 with GobblinInstanceDriver

use of org.apache.gobblin.runtime.api.GobblinInstanceDriver in project incubator-gobblin by apache.

the class TestHadoopKerberosKeytabAuthenticationPlugin method testMissingOptions.

@Test
public void testMissingOptions() {
    final Config testConfig1 = ConfigFactory.parseMap(ImmutableMap.<String, Object>builder().put("hadoop-inject.hadoop.security.authentication", "simple").put("hadoop.loginUser", "foo").put("gobblin.instance.hadoop.loginUserKeytabFile", "/tmp/bar").build());
    final GobblinInstanceDriver instance1 = Mockito.mock(GobblinInstanceDriver.class);
    Mockito.when(instance1.getSysConfig()).thenReturn(DefaultConfigurableImpl.createFromConfig(testConfig1));
    Assert.assertThrows(new ThrowingRunnable() {

        @Override
        public void run() throws Throwable {
            (new HadoopKerberosKeytabAuthenticationPlugin.ConfigBasedFactory()).createPlugin(instance1);
        }
    });
    final Config testConfig2 = ConfigFactory.parseMap(ImmutableMap.<String, Object>builder().put("hadoop-inject.hadoop.security.authentication", "simple").put("gobblin.instance.hadoop.loginUser", "foo").put("hadoop.loginUserKeytabFile", "/tmp/bar").build());
    final GobblinInstanceDriver instance2 = Mockito.mock(GobblinInstanceDriver.class);
    Mockito.when(instance1.getSysConfig()).thenReturn(DefaultConfigurableImpl.createFromConfig(testConfig2));
    Assert.assertThrows(new ThrowingRunnable() {

        @Override
        public void run() throws Throwable {
            (new HadoopKerberosKeytabAuthenticationPlugin.ConfigBasedFactory()).createPlugin(instance2);
        }
    });
}
Also used : Config(com.typesafe.config.Config) GobblinInstanceDriver(org.apache.gobblin.runtime.api.GobblinInstanceDriver) ThrowingRunnable(org.testng.Assert.ThrowingRunnable) Test(org.testng.annotations.Test)

Example 2 with GobblinInstanceDriver

use of org.apache.gobblin.runtime.api.GobblinInstanceDriver in project incubator-gobblin by apache.

the class EmbeddedGobblin method runAsync.

/**
 * Launch the Gobblin job asynchronously. This method will return when the Gobblin job has started.
 * @return a {@link JobExecutionDriver}. This object is a future that will resolve when the Gobblin job finishes.
 * @throws TimeoutException if the Gobblin job does not start within the launch timeout.
 */
@NotOnCli
public JobExecutionDriver runAsync() throws TimeoutException, InterruptedException {
    // Run function to distribute jars to workers in distributed mode
    this.distributeJarsFunction.run();
    Config sysProps = ConfigFactory.parseMap(this.builtConfigMap).withFallback(this.defaultSysConfig);
    Config userConfig = ConfigFactory.parseMap(this.userConfigMap);
    JobSpec jobSpec;
    if (this.jobFile.isPresent()) {
        try {
            Path jobFilePath = this.jobFile.get();
            PullFileLoader loader = new PullFileLoader(jobFilePath.getParent(), jobFilePath.getFileSystem(new Configuration()), PullFileLoader.DEFAULT_JAVA_PROPS_PULL_FILE_EXTENSIONS, PullFileLoader.DEFAULT_HOCON_PULL_FILE_EXTENSIONS);
            Config jobConfig = userConfig.withFallback(loader.loadPullFile(jobFilePath, sysProps, false));
            ImmutableFSJobCatalog.JobSpecConverter converter = new ImmutableFSJobCatalog.JobSpecConverter(jobFilePath.getParent(), Optional.<String>absent());
            jobSpec = converter.apply(jobConfig);
        } catch (IOException ioe) {
            throw new RuntimeException("Failed to run embedded Gobblin.", ioe);
        }
    } else {
        Config finalConfig = userConfig.withFallback(sysProps);
        if (this.template != null) {
            try {
                finalConfig = this.template.getResolvedConfig(finalConfig);
            } catch (SpecNotFoundException | JobTemplate.TemplateException exc) {
                throw new RuntimeException(exc);
            }
        }
        jobSpec = this.specBuilder.withConfig(finalConfig).build();
    }
    ResolvedJobSpec resolvedJobSpec;
    try {
        resolvedJobSpec = new ResolvedJobSpec(jobSpec);
    } catch (SpecNotFoundException | JobTemplate.TemplateException exc) {
        throw new RuntimeException("Failed to resolved template.", exc);
    }
    final JobCatalog jobCatalog = new StaticJobCatalog(Optional.of(this.useLog), Lists.<JobSpec>newArrayList(resolvedJobSpec));
    SimpleGobblinInstanceEnvironment instanceEnvironment = new SimpleGobblinInstanceEnvironment("EmbeddedGobblinInstance", this.useLog, getSysConfig());
    StandardGobblinInstanceDriver.Builder builder = new StandardGobblinInstanceDriver.Builder(Optional.<GobblinInstanceEnvironment>of(instanceEnvironment)).withLog(this.useLog).withJobCatalog(jobCatalog).withImmediateJobScheduler();
    for (GobblinInstancePluginFactory plugin : this.plugins) {
        builder.addPlugin(plugin);
    }
    final GobblinInstanceDriver driver = builder.build();
    EmbeddedJobLifecycleListener listener = new EmbeddedJobLifecycleListener(this.useLog);
    driver.registerJobLifecycleListener(listener);
    driver.startAsync();
    boolean started = listener.awaitStarted(this.launchTimeout.getTimeout(), this.launchTimeout.getTimeUnit());
    if (!started) {
        log.warn("Timeout waiting for job to start. Aborting.");
        driver.stopAsync();
        driver.awaitTerminated(this.shutdownTimeout.getTimeout(), this.shutdownTimeout.getTimeUnit());
        throw new TimeoutException("Timeout waiting for job to start.");
    }
    final JobExecutionDriver jobDriver = listener.getJobDriver();
    // Stop the Gobblin instance driver when the job finishes.
    Futures.addCallback(jobDriver, new FutureCallback<JobExecutionResult>() {

        @Override
        public void onSuccess(@Nullable JobExecutionResult result) {
            stopGobblinInstanceDriver();
        }

        @Override
        public void onFailure(Throwable t) {
            stopGobblinInstanceDriver();
        }

        private void stopGobblinInstanceDriver() {
            try {
                driver.stopAsync();
                driver.awaitTerminated(EmbeddedGobblin.this.shutdownTimeout.getTimeout(), EmbeddedGobblin.this.shutdownTimeout.getTimeUnit());
            } catch (TimeoutException te) {
                log.error("Failed to shutdown Gobblin instance driver.");
            }
        }
    });
    return listener.getJobDriver();
}
Also used : ImmutableFSJobCatalog(org.apache.gobblin.runtime.job_catalog.ImmutableFSJobCatalog) Configuration(org.apache.hadoop.conf.Configuration) Config(com.typesafe.config.Config) StandardGobblinInstanceDriver(org.apache.gobblin.runtime.instance.StandardGobblinInstanceDriver) GobblinInstanceDriver(org.apache.gobblin.runtime.api.GobblinInstanceDriver) StandardGobblinInstanceDriver(org.apache.gobblin.runtime.instance.StandardGobblinInstanceDriver) StaticJobCatalog(org.apache.gobblin.runtime.job_catalog.StaticJobCatalog) JobCatalog(org.apache.gobblin.runtime.api.JobCatalog) ImmutableFSJobCatalog(org.apache.gobblin.runtime.job_catalog.ImmutableFSJobCatalog) GobblinInstanceEnvironment(org.apache.gobblin.runtime.api.GobblinInstanceEnvironment) SimpleGobblinInstanceEnvironment(org.apache.gobblin.runtime.instance.SimpleGobblinInstanceEnvironment) SpecNotFoundException(org.apache.gobblin.runtime.api.SpecNotFoundException) StaticJobCatalog(org.apache.gobblin.runtime.job_catalog.StaticJobCatalog) ResolvedJobSpec(org.apache.gobblin.runtime.job_spec.ResolvedJobSpec) GobblinInstancePluginFactory(org.apache.gobblin.runtime.api.GobblinInstancePluginFactory) JobExecutionDriver(org.apache.gobblin.runtime.api.JobExecutionDriver) TimeoutException(java.util.concurrent.TimeoutException) Path(org.apache.hadoop.fs.Path) PullFileLoader(org.apache.gobblin.util.PullFileLoader) IOException(java.io.IOException) SimpleGobblinInstanceEnvironment(org.apache.gobblin.runtime.instance.SimpleGobblinInstanceEnvironment) JobExecutionResult(org.apache.gobblin.runtime.api.JobExecutionResult) ResolvedJobSpec(org.apache.gobblin.runtime.job_spec.ResolvedJobSpec) JobSpec(org.apache.gobblin.runtime.api.JobSpec) NotOnCli(org.apache.gobblin.runtime.cli.NotOnCli)

Example 3 with GobblinInstanceDriver

use of org.apache.gobblin.runtime.api.GobblinInstanceDriver in project incubator-gobblin by apache.

the class TestStandardGobblinInstanceLauncher method testDirectToExecutionDriver.

@Test
public /**
 * Test running of a job when submitted directly to the execution driver
 */
void testDirectToExecutionDriver() throws Exception {
    StandardGobblinInstanceLauncher.Builder instanceLauncherBuilder = StandardGobblinInstanceLauncher.builder().withInstanceName("testDirectToExecutionDriver");
    instanceLauncherBuilder.driver();
    StandardGobblinInstanceLauncher instanceLauncher = instanceLauncherBuilder.build();
    instanceLauncher.startAsync();
    instanceLauncher.awaitRunning(5, TimeUnit.SECONDS);
    JobSpec js1 = JobSpec.builder().withConfig(ConfigFactory.parseResources("gobblin/runtime/instance/SimpleHelloWorldJob.jobconf")).build();
    GobblinInstanceDriver instance = instanceLauncher.getDriver();
    final JobExecutionLauncher.StandardMetrics launcherMetrics = instance.getJobLauncher().getMetrics();
    AssertWithBackoff asb = new AssertWithBackoff().timeoutMs(100);
    checkLaunchJob(instanceLauncher, js1, instance);
    Assert.assertEquals(launcherMetrics.getNumJobsLaunched().getCount(), 1);
    Assert.assertEquals(launcherMetrics.getNumJobsCompleted().getCount(), 1);
    // Need to use assert with backoff because of race conditions with the callback that updates the
    // metrics
    asb.assertEquals(new Function<Void, Long>() {

        @Override
        public Long apply(Void input) {
            return launcherMetrics.getNumJobsCommitted().getCount();
        }
    }, 1l, "numJobsCommitted==1");
    Assert.assertEquals(launcherMetrics.getNumJobsFailed().getCount(), 0);
    Assert.assertEquals(launcherMetrics.getNumJobsRunning().getValue().intValue(), 0);
    checkLaunchJob(instanceLauncher, js1, instance);
    Assert.assertEquals(launcherMetrics.getNumJobsLaunched().getCount(), 2);
    Assert.assertEquals(launcherMetrics.getNumJobsCompleted().getCount(), 2);
    asb.assertEquals(new Function<Void, Long>() {

        @Override
        public Long apply(Void input) {
            return launcherMetrics.getNumJobsCommitted().getCount();
        }
    }, 2l, "numJobsCommitted==2");
    Assert.assertEquals(launcherMetrics.getNumJobsFailed().getCount(), 0);
    Assert.assertEquals(launcherMetrics.getNumJobsRunning().getValue().intValue(), 0);
}
Also used : AssertWithBackoff(org.apache.gobblin.testing.AssertWithBackoff) GobblinInstanceDriver(org.apache.gobblin.runtime.api.GobblinInstanceDriver) JobSpec(org.apache.gobblin.runtime.api.JobSpec) ResolvedJobSpec(org.apache.gobblin.runtime.job_spec.ResolvedJobSpec) JobExecutionLauncher(org.apache.gobblin.runtime.api.JobExecutionLauncher) Test(org.testng.annotations.Test)

Example 4 with GobblinInstanceDriver

use of org.apache.gobblin.runtime.api.GobblinInstanceDriver in project incubator-gobblin by apache.

the class TestHadoopKerberosKeytabAuthenticationPlugin method testConstructor.

@Test
public void testConstructor() {
    final Config testConfig = ConfigFactory.parseMap(ImmutableMap.<String, Object>builder().put("hadoop-inject.hadoop.security.authentication", "simple").put("gobblin.instance.hadoop.loginUser", "foo").put("gobblin.instance.hadoop.loginUserKeytabFile", "/tmp/bar").build());
    GobblinInstanceDriver instance = Mockito.mock(GobblinInstanceDriver.class);
    Mockito.when(instance.getSysConfig()).thenReturn(DefaultConfigurableImpl.createFromConfig(testConfig));
    HadoopKerberosKeytabAuthenticationPlugin plugin = (HadoopKerberosKeytabAuthenticationPlugin) (new HadoopKerberosKeytabAuthenticationPlugin.ConfigBasedFactory()).createPlugin(instance);
    Assert.assertEquals(plugin.getLoginUser(), "foo");
    Assert.assertEquals(plugin.getLoginUserKeytabFile(), "/tmp/bar");
    Assert.assertEquals(plugin.getHadoopConf().get("hadoop.security.authentication"), "simple");
}
Also used : Config(com.typesafe.config.Config) GobblinInstanceDriver(org.apache.gobblin.runtime.api.GobblinInstanceDriver) Test(org.testng.annotations.Test)

Aggregations

GobblinInstanceDriver (org.apache.gobblin.runtime.api.GobblinInstanceDriver)4 Config (com.typesafe.config.Config)3 Test (org.testng.annotations.Test)3 JobSpec (org.apache.gobblin.runtime.api.JobSpec)2 ResolvedJobSpec (org.apache.gobblin.runtime.job_spec.ResolvedJobSpec)2 IOException (java.io.IOException)1 TimeoutException (java.util.concurrent.TimeoutException)1 GobblinInstanceEnvironment (org.apache.gobblin.runtime.api.GobblinInstanceEnvironment)1 GobblinInstancePluginFactory (org.apache.gobblin.runtime.api.GobblinInstancePluginFactory)1 JobCatalog (org.apache.gobblin.runtime.api.JobCatalog)1 JobExecutionDriver (org.apache.gobblin.runtime.api.JobExecutionDriver)1 JobExecutionLauncher (org.apache.gobblin.runtime.api.JobExecutionLauncher)1 JobExecutionResult (org.apache.gobblin.runtime.api.JobExecutionResult)1 SpecNotFoundException (org.apache.gobblin.runtime.api.SpecNotFoundException)1 NotOnCli (org.apache.gobblin.runtime.cli.NotOnCli)1 SimpleGobblinInstanceEnvironment (org.apache.gobblin.runtime.instance.SimpleGobblinInstanceEnvironment)1 StandardGobblinInstanceDriver (org.apache.gobblin.runtime.instance.StandardGobblinInstanceDriver)1 ImmutableFSJobCatalog (org.apache.gobblin.runtime.job_catalog.ImmutableFSJobCatalog)1 StaticJobCatalog (org.apache.gobblin.runtime.job_catalog.StaticJobCatalog)1 AssertWithBackoff (org.apache.gobblin.testing.AssertWithBackoff)1