Search in sources :

Example 1 with QuartzScheduler

use of com.thinkbiganalytics.scheduler.QuartzScheduler in project kylo by Teradata.

the class NifiStatsJmsReceiver method scheduleStatsCompaction.

/**
 * Schedule the compaction job in Quartz if the properties have this enabled with a Cron Expression
 */
private void scheduleStatsCompaction() {
    if (compactStatsEnabled && StringUtils.isNotBlank(compactStatsCronSchedule)) {
        QuartzScheduler scheduler = (QuartzScheduler) jobScheduler;
        JobIdentifier jobIdentifier = new DefaultJobIdentifier("Compact NiFi Processor Stats", "KYLO");
        TriggerIdentifier triggerIdentifier = new DefaultTriggerIdentifier(jobIdentifier.getName(), jobIdentifier.getGroup());
        try {
            scheduler.scheduleJob(jobIdentifier, triggerIdentifier, NiFiStatsCompactionQuartzJobBean.class, compactStatsCronSchedule, null);
        } catch (ObjectAlreadyExistsException e) {
            log.info("Unable to schedule the job to compact the NiFi processor stats.  It already exists.  Most likely another Kylo node has already schceduled this job. ");
        } catch (SchedulerException e) {
            throw new RuntimeException("Error scheduling job: Compact NiFi Processor Stats", e);
        }
    }
}
Also used : SchedulerException(org.quartz.SchedulerException) DefaultTriggerIdentifier(com.thinkbiganalytics.scheduler.model.DefaultTriggerIdentifier) QuartzScheduler(com.thinkbiganalytics.scheduler.QuartzScheduler) DefaultJobIdentifier(com.thinkbiganalytics.scheduler.model.DefaultJobIdentifier) JobIdentifier(com.thinkbiganalytics.scheduler.JobIdentifier) DefaultTriggerIdentifier(com.thinkbiganalytics.scheduler.model.DefaultTriggerIdentifier) TriggerIdentifier(com.thinkbiganalytics.scheduler.TriggerIdentifier) ObjectAlreadyExistsException(org.quartz.ObjectAlreadyExistsException) DefaultJobIdentifier(com.thinkbiganalytics.scheduler.model.DefaultJobIdentifier)

Example 2 with QuartzScheduler

use of com.thinkbiganalytics.scheduler.QuartzScheduler in project kylo by Teradata.

the class DefaultServiceLevelAgreementScheduler method enableServiceLevelAgreement.

/**
 * Used to enable the schedule of the SLA, so that once again executes after a being disabled
 *
 * @param sla The SLA to enable
 */
public void enableServiceLevelAgreement(ServiceLevelAgreement sla) {
    ServiceLevelAgreement.ID slaId = sla.getId();
    JobIdentifier scheduledJobId = null;
    if (scheduledJobNames.containsKey(slaId)) {
        scheduledJobId = jobIdentifierForName(scheduledJobNames.get(slaId));
    } else {
        scheduledJobId = jobIdentifierForName(sla.getName());
    }
    QuartzScheduler scheduler = (QuartzScheduler) jobScheduler;
    if (scheduledJobId != null && scheduler.jobExists(scheduledJobId)) {
        try {
            jobScheduler.resumeTriggersOnJob(scheduledJobId);
        } catch (JobSchedulerException e) {
            log.error("Unable to resume the schedule for the SLA {} ", sla.getName());
        }
    } else {
        log.info("Unable to resume the SLA job {} .  The Job does not exist", sla.getName());
    }
}
Also used : JobSchedulerException(com.thinkbiganalytics.scheduler.JobSchedulerException) ServiceLevelAgreement(com.thinkbiganalytics.metadata.sla.api.ServiceLevelAgreement) JcrServiceLevelAgreement(com.thinkbiganalytics.metadata.modeshape.sla.JcrServiceLevelAgreement) QuartzScheduler(com.thinkbiganalytics.scheduler.QuartzScheduler) JobIdentifier(com.thinkbiganalytics.scheduler.JobIdentifier) DefaultJobIdentifier(com.thinkbiganalytics.scheduler.model.DefaultJobIdentifier)

Example 3 with QuartzScheduler

use of com.thinkbiganalytics.scheduler.QuartzScheduler in project kylo by Teradata.

the class DefaultServiceLevelAgreementScheduler method unscheduleServiceLevelAgreement.

/**
 * removes the SLA, identified by slaId, from the scheduler, so that it is no longer executed.
 *
 * @param slaId The ServiceLevelAgreement id
 * @return true if we were able to remove the SLA from the scheduler
 */
public boolean unscheduleServiceLevelAgreement(ServiceLevelAgreement.ID slaId) {
    boolean unscheduled = false;
    JobIdentifier scheduledJobId = null;
    try {
        if (scheduledJobNames.containsKey(slaId)) {
            scheduledJobId = jobIdentifierForName(scheduledJobNames.get(slaId));
        }
        QuartzScheduler scheduler = (QuartzScheduler) jobScheduler;
        if (scheduledJobId != null && scheduler.jobExists(scheduledJobId)) {
            log.info("Unscheduling sla job " + scheduledJobId.getName());
            jobScheduler.deleteJob(scheduledJobId);
            scheduledJobNames.remove(slaId);
            unscheduled = true;
            if (clusterService.isClustered()) {
                clusterService.sendMessageToOthers(QTZ_JOB_UNSCHEDULED_MESSAGE_TYPE, new ScheduledServiceLevelAgreementClusterMessage(slaId, scheduledJobId));
            }
        } else {
            log.info("Unable to unschedule/delete the SLA job.  Referencing SLA Id: {}.  It doesn't exist. Scheduled Jobs are: {}  ", slaId, scheduledJobNames);
        }
    } catch (JobSchedulerException e) {
        log.error("Unable to delete the SLA Job " + scheduledJobId);
    }
    return unscheduled;
}
Also used : JobSchedulerException(com.thinkbiganalytics.scheduler.JobSchedulerException) QuartzScheduler(com.thinkbiganalytics.scheduler.QuartzScheduler) JobIdentifier(com.thinkbiganalytics.scheduler.JobIdentifier) DefaultJobIdentifier(com.thinkbiganalytics.scheduler.model.DefaultJobIdentifier)

Example 4 with QuartzScheduler

use of com.thinkbiganalytics.scheduler.QuartzScheduler in project kylo by Teradata.

the class DefaultServiceLevelAgreementScheduler method scheduleSlaJob.

/**
 * Schedule the SlaQuartzJobBean for the given sla
 *
 * @param jobIdentifier the job identifier for this schedule
 * @param slaId         the SLA id
 */
private void scheduleSlaJob(JobIdentifier jobIdentifier, ServiceLevelAgreement.ID slaId) {
    QuartzScheduler scheduler = (QuartzScheduler) jobScheduler;
    TriggerIdentifier triggerIdentifier = triggerIdentifier(jobIdentifier);
    Map<String, Object> map = new HashMap<String, Object>();
    map.put(SlaQuartzJobBean.SLA_ID_PARAM, slaId);
    try {
        scheduler.scheduleJob(jobIdentifier, triggerIdentifier, SlaQuartzJobBean.class, (StringUtils.isBlank(defaultCron) ? DEFAULT_CRON : defaultCron), map);
    } catch (SchedulerException e) {
        throw new RuntimeException("Error scheduling job", e);
    }
}
Also used : SchedulerException(org.quartz.SchedulerException) JobSchedulerException(com.thinkbiganalytics.scheduler.JobSchedulerException) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) QuartzScheduler(com.thinkbiganalytics.scheduler.QuartzScheduler) DefaultTriggerIdentifier(com.thinkbiganalytics.scheduler.model.DefaultTriggerIdentifier) TriggerIdentifier(com.thinkbiganalytics.scheduler.TriggerIdentifier)

Example 5 with QuartzScheduler

use of com.thinkbiganalytics.scheduler.QuartzScheduler in project kylo by Teradata.

the class DefaultServiceLevelAgreementScheduler method run.

/**
 * Called on startup as part of the PostMetadataConfigAction.
 */
@Override
public void run() {
    if (kyloVersionProvider.isUpToDate()) {
        log.info("PostMetadataConfigAction called for DefaultServiceLevelAgreementScheduler.  About to schedule the SLA's ");
        metadataAccess.read(() -> {
            List<? extends ServiceLevelAgreement> agreements = slaProvider.getAgreements();
            if (agreements != null) {
                log.info("About to schedule {} SLA's", agreements.size());
                for (ServiceLevelAgreement agreement : agreements) {
                    JobIdentifier jobIdentifier = slaJobName(agreement);
                    QuartzScheduler scheduler = (QuartzScheduler) jobScheduler;
                    if (!scheduler.jobExists(jobIdentifier)) {
                        scheduleServiceLevelAgreement(agreement);
                    } else {
                        scheduledJobNames.put(agreement.getId(), jobIdentifier.getName());
                    }
                }
            } else {
                log.info("No SLA's found to schedule.");
            }
            return null;
        }, MetadataAccess.SERVICE);
    }
}
Also used : ServiceLevelAgreement(com.thinkbiganalytics.metadata.sla.api.ServiceLevelAgreement) JcrServiceLevelAgreement(com.thinkbiganalytics.metadata.modeshape.sla.JcrServiceLevelAgreement) QuartzScheduler(com.thinkbiganalytics.scheduler.QuartzScheduler) JobIdentifier(com.thinkbiganalytics.scheduler.JobIdentifier) DefaultJobIdentifier(com.thinkbiganalytics.scheduler.model.DefaultJobIdentifier)

Aggregations

QuartzScheduler (com.thinkbiganalytics.scheduler.QuartzScheduler)6 JobIdentifier (com.thinkbiganalytics.scheduler.JobIdentifier)5 DefaultJobIdentifier (com.thinkbiganalytics.scheduler.model.DefaultJobIdentifier)5 JobSchedulerException (com.thinkbiganalytics.scheduler.JobSchedulerException)4 JcrServiceLevelAgreement (com.thinkbiganalytics.metadata.modeshape.sla.JcrServiceLevelAgreement)3 ServiceLevelAgreement (com.thinkbiganalytics.metadata.sla.api.ServiceLevelAgreement)3 TriggerIdentifier (com.thinkbiganalytics.scheduler.TriggerIdentifier)2 DefaultTriggerIdentifier (com.thinkbiganalytics.scheduler.model.DefaultTriggerIdentifier)2 SchedulerException (org.quartz.SchedulerException)2 HashMap (java.util.HashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ObjectAlreadyExistsException (org.quartz.ObjectAlreadyExistsException)1