Search in sources :

Example 1 with RunOnceJobListener

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

the class JobScheduler method scheduleGeneralConfiguredJobs.

/**
 * Schedule Gobblin jobs in general position
 */
private void scheduleGeneralConfiguredJobs() throws ConfigurationException, JobException, IOException {
    LOG.info("Scheduling configured jobs");
    for (Properties jobProps : loadGeneralJobConfigs()) {
        if (!jobProps.containsKey(ConfigurationKeys.JOB_SCHEDULE_KEY)) {
            // A job without a cron schedule is considered a one-time job
            jobProps.setProperty(ConfigurationKeys.JOB_RUN_ONCE_KEY, "true");
        }
        boolean runOnce = Boolean.valueOf(jobProps.getProperty(ConfigurationKeys.JOB_RUN_ONCE_KEY, "false"));
        scheduleJob(jobProps, runOnce ? new RunOnceJobListener() : new EmailNotificationJobListener());
        this.listener.addToJobNameMap(jobProps);
    }
}
Also used : EmailNotificationJobListener(org.apache.gobblin.runtime.listeners.EmailNotificationJobListener) Properties(java.util.Properties) RunOnceJobListener(org.apache.gobblin.runtime.listeners.RunOnceJobListener)

Example 2 with RunOnceJobListener

use of org.apache.gobblin.runtime.listeners.RunOnceJobListener 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 3 with RunOnceJobListener

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

the class PathAlterationListenerAdaptorForMonitor method rescheduleJob.

private void rescheduleJob(Properties jobProps) throws JobException {
    String jobName = jobProps.getProperty(ConfigurationKeys.JOB_NAME_KEY);
    Path jobPath = getJobPath(jobProps);
    // First unschedule and delete the old job
    if (this.jobNameMap.containsKey(jobPath)) {
        jobScheduler.unscheduleJob(this.jobNameMap.get(jobPath));
        this.jobNameMap.remove(jobPath);
    }
    boolean runOnce = Boolean.valueOf(jobProps.getProperty(ConfigurationKeys.JOB_RUN_ONCE_KEY, "false"));
    // Reschedule the job with the new job configuration
    jobScheduler.scheduleJob(jobProps, runOnce ? new RunOnceJobListener() : new EmailNotificationJobListener());
    addToJobNameMap(jobProps);
    LOG.debug("[JobScheduler] The new job " + jobName + " is rescheduled.");
}
Also used : Path(org.apache.hadoop.fs.Path) EmailNotificationJobListener(org.apache.gobblin.runtime.listeners.EmailNotificationJobListener) RunOnceJobListener(org.apache.gobblin.runtime.listeners.RunOnceJobListener)

Example 4 with RunOnceJobListener

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

the class PathAlterationListenerAdaptorForMonitor method loadNewCommonConfigAndHandleNewJob.

public void loadNewCommonConfigAndHandleNewJob(Path path, JobScheduler.Action action) {
    String customizedInfoAction = "";
    String customizedInfoResult = "";
    try {
        for (Properties jobProps : SchedulerUtils.loadGenericJobConfigs(jobScheduler.properties, path, jobConfigFileDirPath)) {
            try {
                switch(action) {
                    case SCHEDULE:
                        boolean runOnce = Boolean.valueOf(jobProps.getProperty(ConfigurationKeys.JOB_RUN_ONCE_KEY, "false"));
                        customizedInfoAction = "schedule";
                        customizedInfoResult = "creation or equivalent action";
                        addToJobNameMap(jobProps);
                        jobScheduler.scheduleJob(jobProps, runOnce ? new RunOnceJobListener() : new EmailNotificationJobListener());
                        break;
                    case RESCHEDULE:
                        customizedInfoAction = "reschedule";
                        customizedInfoResult = "change";
                        rescheduleJob(jobProps);
                        break;
                    case UNSCHEDULE:
                        throw new RuntimeException("Should not call loadNewCommonConfigAndHandleNewJob for unscheduling jobs.");
                    default:
                        break;
                }
            } catch (JobException je) {
                LOG.error("Failed to " + customizedInfoAction + " job reloaded from job configuration file " + jobProps.getProperty(ConfigurationKeys.JOB_CONFIG_FILE_PATH_KEY), je);
            }
        }
    } catch (ConfigurationException | IOException e) {
        LOG.error("Failed to reload job configuration files affected by " + customizedInfoResult + " to " + path.toString(), e);
    }
}
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)

Aggregations

EmailNotificationJobListener (org.apache.gobblin.runtime.listeners.EmailNotificationJobListener)4 RunOnceJobListener (org.apache.gobblin.runtime.listeners.RunOnceJobListener)4 Properties (java.util.Properties)3 IOException (java.io.IOException)2 ConfigurationException (org.apache.commons.configuration.ConfigurationException)2 JobException (org.apache.gobblin.runtime.JobException)2 Path (org.apache.hadoop.fs.Path)1