Search in sources :

Example 1 with JobLauncher

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

the class GobblinHelixJobScheduler method scheduleJobImmediately.

public Future<?> scheduleJobImmediately(Properties jobProps, JobListener jobListener) {
    RetriggeringJobCallable retriggeringJob = new RetriggeringJobCallable(jobProps, jobListener);
    final Future<?> future = this.jobExecutor.submit(retriggeringJob);
    return new Future() {

        @Override
        public boolean cancel(boolean mayInterruptIfRunning) {
            if (!GobblinHelixJobScheduler.this.isCancelRequested()) {
                return false;
            }
            boolean result = true;
            try {
                JobLauncher jobLauncher = retriggeringJob.getCurrentJobLauncher();
                if (jobLauncher != null) {
                    jobLauncher.cancelJob(jobListener);
                }
            } catch (JobException e) {
                LOGGER.error("Failed to cancel job " + jobProps.getProperty(ConfigurationKeys.JOB_NAME_KEY), e);
                result = false;
            }
            if (mayInterruptIfRunning) {
                result &= future.cancel(true);
            }
            return result;
        }

        @Override
        public boolean isCancelled() {
            return future.isCancelled();
        }

        @Override
        public boolean isDone() {
            return future.isDone();
        }

        @Override
        public Object get() throws InterruptedException, ExecutionException {
            return future.get();
        }

        @Override
        public Object get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
            return future.get(timeout, unit);
        }
    };
}
Also used : JobException(org.apache.gobblin.runtime.JobException) JobLauncher(org.apache.gobblin.runtime.JobLauncher) Future(java.util.concurrent.Future) TimeUnit(java.util.concurrent.TimeUnit)

Example 2 with JobLauncher

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

the class Kafka08DataWriterIntegrationTest method testErrors.

@Test
public void testErrors() throws Exception {
    log.warn("Process id = " + ManagementFactory.getRuntimeMXBean().getName());
    int numRecordsPerExtract = 5;
    int numParallel = 2;
    int errorEvery = 2000;
    int totalRecords = numRecordsPerExtract * numParallel;
    int totalSuccessful = totalRecords / errorEvery + totalRecords % errorEvery;
    {
        Closer closer = Closer.create();
        try {
            kafkaTestHelper.provisionTopic(TOPIC);
            jobProps.setProperty("source.numRecordsPerExtract", "" + numRecordsPerExtract);
            jobProps.setProperty("source.numParallelism", "" + numParallel);
            jobProps.setProperty("writer.kafka.producerConfig.flaky.errorType", "regex");
            // all records from partition 0 will be dropped.
            jobProps.setProperty("writer.kafka.producerConfig.flaky.regexPattern", ":index:0.*");
            jobProps.setProperty("job.commit.policy", "partial");
            jobProps.setProperty("publish.at.job.level", "false");
            // number of records in partition 1
            totalSuccessful = 5;
            JobLauncher jobLauncher = closer.register(JobLauncherFactory.newJobLauncher(gobblinProps, jobProps));
            jobLauncher.launchJob(null);
        } catch (Exception e) {
            log.error("Failed to run job with exception ", e);
            Assert.fail("Should not throw exception on running the job");
        } finally {
            closer.close();
        }
        // test records written
        testRecordsWritten(totalSuccessful, TOPIC);
    }
    boolean trySecond = true;
    if (trySecond) {
        Closer closer = Closer.create();
        try {
            jobProps.setProperty("source.numRecordsPerExtract", "" + numRecordsPerExtract);
            jobProps.setProperty("source.numParallelism", "" + numParallel);
            jobProps.setProperty("writer.kafka.producerConfig.flaky.errorType", "nth");
            jobProps.setProperty("writer.kafka.producerConfig.flaky.errorEvery", "" + errorEvery);
            JobLauncher jobLauncher = closer.register(JobLauncherFactory.newJobLauncher(gobblinProps, jobProps));
            jobLauncher.launchJob(null);
            totalSuccessful = totalRecords / errorEvery + totalRecords % errorEvery;
        } catch (Exception e) {
            log.error("Failed to run job with exception ", e);
            Assert.fail("Should not throw exception on running the job");
        } finally {
            closer.close();
        }
    }
    // test records written
    testRecordsWritten(totalSuccessful, TOPIC);
}
Also used : Closer(com.google.common.io.Closer) JobLauncher(org.apache.gobblin.runtime.JobLauncher) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Test(org.testng.annotations.Test)

Example 3 with JobLauncher

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

the class CopyIntegrationTest method testTarGzCopy.

@Test
public void testTarGzCopy() throws Exception {
    Closer closer = Closer.create();
    try {
        JobLauncher jobLauncher = closer.register(JobLauncherFactory.newJobLauncher(gobblinProps, jobProps));
        jobLauncher.launchJob(null);
        String file1Path = gobblinProps.getProperty(ConfigurationKeys.DATA_PUBLISHER_FINAL_DIR) + "/LogData/sub1/sub2/text1.txt";
        String file2Path = gobblinProps.getProperty(ConfigurationKeys.DATA_PUBLISHER_FINAL_DIR) + "/LogData/sub1/sub2/text2.txt";
        FileSystem fs = FileSystem.getLocal(new Configuration());
        Assert.assertEquals(IOUtils.toString(closer.register(fs.open(new Path(file1Path)))), "text1");
        Assert.assertEquals(IOUtils.toString(closer.register(fs.open(new Path(file2Path)))), "text2");
    } finally {
        closer.close();
    }
}
Also used : Closer(com.google.common.io.Closer) Path(org.apache.hadoop.fs.Path) JobLauncher(org.apache.gobblin.runtime.JobLauncher) Configuration(org.apache.hadoop.conf.Configuration) FileSystem(org.apache.hadoop.fs.FileSystem) Test(org.testng.annotations.Test)

Example 4 with JobLauncher

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

the class JobLauncherExecutionDriver method create.

/**
 * Creates a new JobExecutionDriver which acts as an adapter to the legacy {@link JobLauncher} API.
 * @param sysConfig             the system/environment config
 * @param jobSpec               the JobSpec to be executed
 * @param jobLauncherType       an optional jobLauncher type; the value follows the convention of
 *        {@link JobLauncherFactory#newJobLauncher(java.util.Properties, java.util.Properties, String).
 *        If absent, {@link JobLauncherFactory#newJobLauncher(java.util.Properties, java.util.Properties)}
 *        will be used which looks for the {@link ConfigurationKeys#JOB_LAUNCHER_TYPE_KEY}
 *        in the system configuration.
 * @param jobExecStateListener  an optional listener to listen for state changes in the execution.
 * @param log                   an optional logger to be used; if none is specified, a default one
 *                              will be instantiated.
 */
public static JobLauncherExecutionDriver create(Configurable sysConfig, JobSpec jobSpec, Optional<JobLauncherFactory.JobLauncherType> jobLauncherType, Optional<Logger> log, boolean instrumentationEnabled, JobExecutionLauncher.StandardMetrics launcherMetrics, SharedResourcesBroker<GobblinScopeTypes> instanceBroker) {
    Logger actualLog = log.isPresent() ? log.get() : LoggerFactory.getLogger(JobLauncherExecutionDriver.class);
    JobExecutionStateListeners callbackDispatcher = new JobExecutionStateListeners(actualLog);
    JobExecutionUpdatable jobExec = JobExecutionUpdatable.createFromJobSpec(jobSpec);
    JobExecutionState jobState = new JobExecutionState(jobSpec, jobExec, Optional.<JobExecutionStateListener>of(callbackDispatcher));
    JobLauncher jobLauncher = createLauncher(sysConfig, jobSpec, actualLog, jobLauncherType.isPresent() ? Optional.of(jobLauncherType.get().toString()) : Optional.<String>absent(), instanceBroker);
    JobListenerToJobStateBridge bridge = new JobListenerToJobStateBridge(actualLog, jobState, instrumentationEnabled, launcherMetrics);
    DriverRunnable runnable = new DriverRunnable(jobLauncher, bridge, jobState, callbackDispatcher, jobExec);
    return new JobLauncherExecutionDriver(jobSpec, actualLog, runnable);
}
Also used : JobLauncher(org.apache.gobblin.runtime.JobLauncher) JobExecutionState(org.apache.gobblin.runtime.api.JobExecutionState) Logger(org.slf4j.Logger) JobExecutionUpdatable(org.apache.gobblin.runtime.std.JobExecutionUpdatable) JobExecutionStateListeners(org.apache.gobblin.runtime.std.JobExecutionStateListeners)

Aggregations

JobLauncher (org.apache.gobblin.runtime.JobLauncher)4 Closer (com.google.common.io.Closer)2 Test (org.testng.annotations.Test)2 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Future (java.util.concurrent.Future)1 TimeUnit (java.util.concurrent.TimeUnit)1 JobException (org.apache.gobblin.runtime.JobException)1 JobExecutionState (org.apache.gobblin.runtime.api.JobExecutionState)1 JobExecutionStateListeners (org.apache.gobblin.runtime.std.JobExecutionStateListeners)1 JobExecutionUpdatable (org.apache.gobblin.runtime.std.JobExecutionUpdatable)1 Configuration (org.apache.hadoop.conf.Configuration)1 FileSystem (org.apache.hadoop.fs.FileSystem)1 Path (org.apache.hadoop.fs.Path)1 Logger (org.slf4j.Logger)1