Search in sources :

Example 1 with JobExecutionDriver

use of org.apache.gobblin.runtime.api.JobExecutionDriver 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 2 with JobExecutionDriver

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

the class TestWorkUnitStreamSource method test.

/**
 * This test uses a slow source to verify that we can stream work units through local job launcher, with available units
 * being processes eagerly even if not all work units are available.
 */
@Test
public void test() throws Exception {
    String eventBusId = UUID.randomUUID().toString();
    MyListener listener = new MyListener();
    EventBus eventBus = TestingEventBuses.getEventBus(eventBusId);
    eventBus.register(listener);
    EmbeddedGobblin embeddedGobblin = new EmbeddedGobblin("testStreamedSource").setConfiguration(EventBusPublishingTaskFactory.EVENTBUS_ID_KEY, eventBusId).setConfiguration(ConfigurationKeys.SOURCE_CLASS_KEY, MySource.class.getName()).setConfiguration(EventBusPublishingTaskFactory.Source.NUM_TASKS_KEY, "5");
    JobExecutionDriver driver = embeddedGobblin.runAsync();
    if (!listener.iteratorReady.tryAcquire(2, TimeUnit.SECONDS)) {
        throw new RuntimeException("Failed to get start signal.");
    }
    Assert.assertFalse(listener.tasksRun.tryAcquire(50, TimeUnit.MILLISECONDS));
    eventBus.post(new MySource.NextWorkUnit());
    Assert.assertTrue(listener.tasksRun.tryAcquire(500, TimeUnit.MILLISECONDS));
    Assert.assertFalse(listener.tasksRun.tryAcquire(50, TimeUnit.MILLISECONDS));
    eventBus.post(new MySource.NextWorkUnit());
    Assert.assertTrue(listener.tasksRun.tryAcquire(500, TimeUnit.MILLISECONDS));
    Assert.assertFalse(listener.tasksRun.tryAcquire(50, TimeUnit.MILLISECONDS));
    eventBus.post(new MySource.NextWorkUnit());
    eventBus.post(new MySource.NextWorkUnit());
    eventBus.post(new MySource.NextWorkUnit());
    JobExecutionResult result = driver.get(5, TimeUnit.SECONDS);
    Assert.assertTrue(result.isSuccessful());
    SetMultimap<String, Integer> eventsSeen = listener.getEventsSeenMap();
    Set<Integer> expected = Sets.newHashSet(0, 1, 2, 3, 4);
    Assert.assertEquals(eventsSeen.get(EventBusPublishingTaskFactory.RUN_EVENT), expected);
    Assert.assertEquals(eventsSeen.get(EventBusPublishingTaskFactory.COMMIT_EVENT), expected);
    Assert.assertEquals(eventsSeen.get(EventBusPublishingTaskFactory.PUBLISH_EVENT), expected);
}
Also used : JobExecutionResult(org.apache.gobblin.runtime.api.JobExecutionResult) EventBus(com.google.common.eventbus.EventBus) EmbeddedGobblin(org.apache.gobblin.runtime.embedded.EmbeddedGobblin) JobExecutionDriver(org.apache.gobblin.runtime.api.JobExecutionDriver) Test(org.testng.annotations.Test)

Example 3 with JobExecutionDriver

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

the class JobBrokerInjectionTest method testBrokerIsAcquiredAndShared.

@Test
public void testBrokerIsAcquiredAndShared() throws Exception {
    StandardGobblinInstanceLauncher.Builder instanceLauncherBuilder = StandardGobblinInstanceLauncher.builder().withInstanceName("testSubmitToJobCatalog");
    instanceLauncherBuilder.driver();
    StandardGobblinInstanceLauncher instanceLauncher = instanceLauncherBuilder.build();
    instanceLauncher.startAsync();
    instanceLauncher.awaitRunning(5, TimeUnit.SECONDS);
    JobSpec js1 = JobSpec.builder().withConfig(ConfigFactory.parseResources("brokerTest/SimpleHelloWorldJob.jobconf")).build();
    final String eventBusId = js1.getConfig().resolve().getString(GobblinTestEventBusWriter.FULL_EVENTBUSID_KEY);
    TestingEventBusAsserter asserter = new TestingEventBusAsserter(eventBusId);
    final StandardGobblinInstanceDriver instance = (StandardGobblinInstanceDriver) instanceLauncher.getDriver();
    final ArrayBlockingQueue<JobExecutionDriver> jobDrivers = new ArrayBlockingQueue<>(1);
    JobLifecycleListener js1Listener = new FilteredJobLifecycleListener(JobSpecFilter.eqJobSpecURI(js1.getUri()), new DefaultJobLifecycleListenerImpl(instance.getLog()) {

        @Override
        public void onJobLaunch(JobExecutionDriver jobDriver) {
            super.onJobLaunch(jobDriver);
            try {
                jobDrivers.offer(jobDriver, 5, TimeUnit.SECONDS);
            } catch (InterruptedException e) {
                instance.getLog().error("Offer interrupted.");
            }
        }
    });
    instance.registerWeakJobLifecycleListener(js1Listener);
    instance.getMutableJobCatalog().put(js1);
    JobExecutionDriver jobDriver = jobDrivers.poll(10, TimeUnit.SECONDS);
    Assert.assertNotNull(jobDriver);
    JobExecutionResult jobResult = jobDriver.get(100000, TimeUnit.SECONDS);
    Assert.assertTrue(jobResult.isSuccessful());
    Queue<TestingEventBuses.Event> events = asserter.getEvents();
    Set<Long> seenInstanceObjectIds = Sets.newHashSet();
    Set<Long> seenJobObjectIds = Sets.newHashSet();
    Set<Long> seenTaskObjectIds = Sets.newHashSet();
    for (TestingEventBuses.Event event : events) {
        MyRecord record = (MyRecord) event.getValue();
        seenInstanceObjectIds.add(record.getInstanceSharedObjectId());
        seenJobObjectIds.add(record.getJobSharedObjectId());
        seenTaskObjectIds.add(record.getTaskSharedObjectId());
    }
    // Should see same instance and job id (only 1 id in the set), but 5 different task ids for each task
    Assert.assertEquals(seenInstanceObjectIds.size(), 1);
    Assert.assertEquals(seenJobObjectIds.size(), 1);
    Assert.assertEquals(seenTaskObjectIds.size(), 5);
    asserter.clear();
    instance.getMutableJobCatalog().remove(js1.getUri());
    instance.getMutableJobCatalog().put(js1);
    jobDriver = jobDrivers.poll(10, TimeUnit.SECONDS);
    Assert.assertNotNull(jobDriver);
    jobResult = jobDriver.get(10, TimeUnit.SECONDS);
    Assert.assertTrue(jobResult.isSuccessful());
    events = asserter.getEvents();
    for (TestingEventBuses.Event event : events) {
        MyRecord record = (MyRecord) event.getValue();
        seenInstanceObjectIds.add(record.getInstanceSharedObjectId());
        seenJobObjectIds.add(record.getJobSharedObjectId());
        seenTaskObjectIds.add(record.getTaskSharedObjectId());
    }
    // A different job should produce a new shared object id
    Assert.assertEquals(seenInstanceObjectIds.size(), 1);
    Assert.assertEquals(seenJobObjectIds.size(), 2);
    Assert.assertEquals(seenTaskObjectIds.size(), 10);
}
Also used : StandardGobblinInstanceDriver(org.apache.gobblin.runtime.instance.StandardGobblinInstanceDriver) DefaultJobLifecycleListenerImpl(org.apache.gobblin.runtime.std.DefaultJobLifecycleListenerImpl) JobExecutionResult(org.apache.gobblin.runtime.api.JobExecutionResult) TestingEventBuses(org.apache.gobblin.writer.test.TestingEventBuses) TestingEventBusAsserter(org.apache.gobblin.writer.test.TestingEventBusAsserter) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) StandardGobblinInstanceLauncher(org.apache.gobblin.runtime.instance.StandardGobblinInstanceLauncher) FilteredJobLifecycleListener(org.apache.gobblin.runtime.std.FilteredJobLifecycleListener) JobLifecycleListener(org.apache.gobblin.runtime.api.JobLifecycleListener) JobSpec(org.apache.gobblin.runtime.api.JobSpec) JobExecutionDriver(org.apache.gobblin.runtime.api.JobExecutionDriver) FilteredJobLifecycleListener(org.apache.gobblin.runtime.std.FilteredJobLifecycleListener) Test(org.testng.annotations.Test)

Example 4 with JobExecutionDriver

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

the class JobBrokerInjectionTest method launchJob.

private void launchJob(StandardGobblinInstanceLauncher instanceLauncher, JobSpec js1, GobblinInstanceDriver instance) throws TimeoutException, InterruptedException, ExecutionException {
    JobExecutionDriver jobDriver = instance.getJobLauncher().launchJob(js1);
    new Thread(jobDriver).run();
    JobExecutionResult jobResult = jobDriver.get(5, TimeUnit.SECONDS);
    Assert.assertTrue(jobResult.isSuccessful());
}
Also used : JobExecutionResult(org.apache.gobblin.runtime.api.JobExecutionResult) JobExecutionDriver(org.apache.gobblin.runtime.api.JobExecutionDriver)

Example 5 with JobExecutionDriver

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

the class TestStandardGobblinInstanceLauncher method checkLaunchJob.

private void checkLaunchJob(StandardGobblinInstanceLauncher instanceLauncher, JobSpec js1, GobblinInstanceDriver instance) throws TimeoutException, InterruptedException, ExecutionException {
    JobExecutionDriver jobDriver = instance.getJobLauncher().launchJob(js1);
    new Thread(jobDriver).run();
    JobExecutionResult jobResult = jobDriver.get(5, TimeUnit.SECONDS);
    Assert.assertTrue(jobResult.isSuccessful());
    instanceLauncher.stopAsync();
    instanceLauncher.awaitTerminated(5, TimeUnit.SECONDS);
    Assert.assertEquals(instance.getMetrics().getUpFlag().getValue().intValue(), 0);
    Assert.assertEquals(instance.getMetrics().getUptimeMs().getValue().longValue(), 0);
}
Also used : JobExecutionResult(org.apache.gobblin.runtime.api.JobExecutionResult) JobExecutionDriver(org.apache.gobblin.runtime.api.JobExecutionDriver)

Aggregations

JobExecutionDriver (org.apache.gobblin.runtime.api.JobExecutionDriver)9 JobExecutionResult (org.apache.gobblin.runtime.api.JobExecutionResult)8 Test (org.testng.annotations.Test)6 JobLifecycleListener (org.apache.gobblin.runtime.api.JobLifecycleListener)5 JobSpec (org.apache.gobblin.runtime.api.JobSpec)5 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)4 ResolvedJobSpec (org.apache.gobblin.runtime.job_spec.ResolvedJobSpec)4 DefaultJobLifecycleListenerImpl (org.apache.gobblin.runtime.std.DefaultJobLifecycleListenerImpl)4 FilteredJobLifecycleListener (org.apache.gobblin.runtime.std.FilteredJobLifecycleListener)4 TestingEventBusAsserter (org.apache.gobblin.writer.test.TestingEventBusAsserter)3 ArrayList (java.util.ArrayList)2 StandardGobblinInstanceDriver (org.apache.gobblin.runtime.instance.StandardGobblinInstanceDriver)2 EventBus (com.google.common.eventbus.EventBus)1 Config (com.typesafe.config.Config)1 IOException (java.io.IOException)1 URI (java.net.URI)1 TimeoutException (java.util.concurrent.TimeoutException)1 GobblinInstanceDriver (org.apache.gobblin.runtime.api.GobblinInstanceDriver)1 GobblinInstanceEnvironment (org.apache.gobblin.runtime.api.GobblinInstanceEnvironment)1 GobblinInstancePluginFactory (org.apache.gobblin.runtime.api.GobblinInstancePluginFactory)1