Search in sources :

Example 1 with JobException

use of org.apache.gobblin.runtime.JobException 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 JobException

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

the class GobblinHelixJobScheduler method handleNewJobConfigArrival.

@Subscribe
public void handleNewJobConfigArrival(NewJobConfigArrivalEvent newJobArrival) {
    LOGGER.info("Received new job configuration of job " + newJobArrival.getJobName());
    try {
        Properties jobConfig = new Properties();
        jobConfig.putAll(this.properties);
        jobConfig.putAll(newJobArrival.getJobConfig());
        metrics.updateTimeBeforeJobScheduling(jobConfig);
        if (jobConfig.containsKey(ConfigurationKeys.JOB_SCHEDULE_KEY)) {
            LOGGER.info("Scheduling job " + newJobArrival.getJobName());
            scheduleJob(jobConfig, new MetricsTrackingListener(metrics));
        } else {
            LOGGER.info("No job schedule found, so running job " + newJobArrival.getJobName());
            this.jobExecutor.execute(new NonScheduledJobRunner(newJobArrival.getJobName(), jobConfig, new MetricsTrackingListener(metrics)));
        }
    } catch (JobException je) {
        LOGGER.error("Failed to schedule or run job " + newJobArrival.getJobName(), je);
    }
}
Also used : JobException(org.apache.gobblin.runtime.JobException) Properties(java.util.Properties) Subscribe(com.google.common.eventbus.Subscribe)

Example 3 with JobException

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

the class PathAlterationListenerAdaptorForMonitor method loadNewJobConfigAndHandleNewJob.

public void loadNewJobConfigAndHandleNewJob(Path path, JobScheduler.Action action) {
    // Load the new job configuration and schedule the new job
    String customizedInfo = "";
    try {
        Properties jobProps = SchedulerUtils.loadGenericJobConfig(this.jobScheduler.properties, path, jobConfigFileDirPath);
        LOG.debug("Loaded job properties: {}", jobProps);
        switch(action) {
            case SCHEDULE:
                boolean runOnce = Boolean.valueOf(jobProps.getProperty(ConfigurationKeys.JOB_RUN_ONCE_KEY, "false"));
                customizedInfo = "schedule";
                addToJobNameMap(jobProps);
                jobScheduler.scheduleJob(jobProps, runOnce ? new RunOnceJobListener() : new EmailNotificationJobListener());
                break;
            case RESCHEDULE:
                customizedInfo = "reschedule";
                rescheduleJob(jobProps);
                break;
            case UNSCHEDULE:
                throw new RuntimeException("Should not call loadNewJobConfigAndHandleNewJob for unscheduling jobs.");
            default:
                break;
        }
    } catch (ConfigurationException | IOException e) {
        LOG.error("Failed to load from job configuration file " + path.toString(), e);
    } catch (JobException je) {
        LOG.error("Failed to " + customizedInfo + " new job loaded from job configuration file " + path.toString(), je);
    }
}
Also used : JobException(org.apache.gobblin.runtime.JobException) EmailNotificationJobListener(org.apache.gobblin.runtime.listeners.EmailNotificationJobListener) ConfigurationException(org.apache.commons.configuration.ConfigurationException) IOException(java.io.IOException) Properties(java.util.Properties) RunOnceJobListener(org.apache.gobblin.runtime.listeners.RunOnceJobListener)

Example 4 with JobException

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

the class GobblinServiceJobScheduler method scheduleJob.

/**
 * Synchronize the job scheduling because the same flowSpec can be scheduled by different threads.
 */
@Override
public synchronized void scheduleJob(Properties jobProps, JobListener jobListener) throws JobException {
    Map<String, Object> additionalJobDataMap = Maps.newHashMap();
    additionalJobDataMap.put(ServiceConfigKeys.GOBBLIN_SERVICE_FLOWSPEC, this.scheduledFlowSpecs.get(jobProps.getProperty(ConfigurationKeys.JOB_NAME_KEY)));
    try {
        scheduleJob(jobProps, jobListener, additionalJobDataMap, GobblinServiceJob.class);
    } catch (Exception e) {
        throw new JobException("Failed to schedule job " + jobProps.getProperty(ConfigurationKeys.JOB_NAME_KEY), e);
    }
}
Also used : UnableToInterruptJobException(org.quartz.UnableToInterruptJobException) JobException(org.apache.gobblin.runtime.JobException) JobExecutionException(org.quartz.JobExecutionException) UnableToInterruptJobException(org.quartz.UnableToInterruptJobException) JobException(org.apache.gobblin.runtime.JobException)

Example 5 with JobException

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

the class GobblinServiceJobScheduler method runJob.

@Override
public void runJob(Properties jobProps, JobListener jobListener) throws JobException {
    try {
        Spec flowSpec = this.scheduledFlowSpecs.get(jobProps.getProperty(ConfigurationKeys.JOB_NAME_KEY));
        this.orchestrator.orchestrate(flowSpec);
    } catch (Exception e) {
        throw new JobException("Failed to run Spec: " + jobProps.getProperty(ConfigurationKeys.JOB_NAME_KEY), e);
    }
}
Also used : UnableToInterruptJobException(org.quartz.UnableToInterruptJobException) JobException(org.apache.gobblin.runtime.JobException) Spec(org.apache.gobblin.runtime.api.Spec) FlowSpec(org.apache.gobblin.runtime.api.FlowSpec) JobExecutionException(org.quartz.JobExecutionException) UnableToInterruptJobException(org.quartz.UnableToInterruptJobException) JobException(org.apache.gobblin.runtime.JobException)

Aggregations

JobException (org.apache.gobblin.runtime.JobException)13 UnableToInterruptJobException (org.quartz.UnableToInterruptJobException)6 Properties (java.util.Properties)5 FlowSpec (org.apache.gobblin.runtime.api.FlowSpec)3 IOException (java.io.IOException)2 ConfigurationException (org.apache.commons.configuration.ConfigurationException)2 Spec (org.apache.gobblin.runtime.api.Spec)2 EmailNotificationJobListener (org.apache.gobblin.runtime.listeners.EmailNotificationJobListener)2 RunOnceJobListener (org.apache.gobblin.runtime.listeners.RunOnceJobListener)2 JobExecutionException (org.quartz.JobExecutionException)2 Subscribe (com.google.common.eventbus.Subscribe)1 Closer (com.google.common.io.Closer)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Future (java.util.concurrent.Future)1 TimeUnit (java.util.concurrent.TimeUnit)1 Tag (org.apache.gobblin.metrics.Tag)1 JobLauncher (org.apache.gobblin.runtime.JobLauncher)1 Path (org.apache.hadoop.fs.Path)1 WorkflowContext (org.apache.helix.task.WorkflowContext)1