Search in sources :

Example 46 with Trigger

use of org.quartz.Trigger in project cdap by caskdata.

the class TimeScheduler method getScheduledRuntime.

private List<ScheduledRuntime> getScheduledRuntime(ProgramId program, SchedulableProgramType programType, boolean previousRuntimeRequested) throws SchedulerException {
    checkInitialized();
    List<ScheduledRuntime> scheduledRuntimes = new ArrayList<>();
    try {
        for (Trigger trigger : scheduler.getTriggersOfJob(jobKeyFor(program, programType))) {
            long time;
            if (previousRuntimeRequested) {
                if (trigger.getPreviousFireTime() == null) {
                    // previous fire time can be null for the triggers which are not yet fired
                    continue;
                }
                time = trigger.getPreviousFireTime().getTime();
            } else {
                if (scheduler.getTriggerState(trigger.getKey()) == Trigger.TriggerState.PAUSED) {
                    // if the trigger is paused, then skip getting the next fire time
                    continue;
                }
                time = trigger.getNextFireTime().getTime();
            }
            ScheduledRuntime runtime = new ScheduledRuntime(trigger.getKey().toString(), time);
            scheduledRuntimes.add(runtime);
        }
    } catch (org.quartz.SchedulerException e) {
        throw new SchedulerException(e);
    }
    return scheduledRuntimes;
}
Also used : ProtoTrigger(co.cask.cdap.proto.ProtoTrigger) Trigger(org.quartz.Trigger) ArrayList(java.util.ArrayList) ScheduledRuntime(co.cask.cdap.proto.ScheduledRuntime)

Example 47 with Trigger

use of org.quartz.Trigger in project cdap by caskdata.

the class TimeScheduler method resumeSchedule.

@Override
public synchronized void resumeSchedule(ProgramId program, SchedulableProgramType programType, String scheduleName) throws NotFoundException, SchedulerException {
    checkInitialized();
    try {
        TriggerKey triggerKey = getGroupedTriggerKey(program, programType, scheduleName);
        if (triggerKey.getGroup().equals(PAUSED_NEW_TRIGGERS_GROUP)) {
            Trigger neverScheduledTrigger = scheduler.getTrigger(triggerKey);
            TriggerBuilder<? extends Trigger> triggerBuilder = neverScheduledTrigger.getTriggerBuilder();
            // move this key from TimeScheduler#PAUSED_NEW_TRIGGERS_GROUP to the Key#DEFAULT_GROUP group
            // (when no group name is provided default is used)
            Trigger resumedTrigger = triggerBuilder.withIdentity(triggerKey.getName()).build();
            scheduler.rescheduleJob(neverScheduledTrigger.getKey(), resumedTrigger);
            triggerKey = resumedTrigger.getKey();
        }
        scheduler.resumeTrigger(triggerKey);
    } catch (org.quartz.SchedulerException e) {
        throw new SchedulerException(e);
    }
}
Also used : TriggerKey(org.quartz.TriggerKey) ProtoTrigger(co.cask.cdap.proto.ProtoTrigger) Trigger(org.quartz.Trigger)

Example 48 with Trigger

use of org.quartz.Trigger in project cdap by caskdata.

the class TimeScheduler method deleteSchedule.

@Override
public synchronized void deleteSchedule(ProgramId program, SchedulableProgramType programType, String scheduleName) throws NotFoundException, SchedulerException {
    checkInitialized();
    try {
        Trigger trigger = getTrigger(program, programType, scheduleName);
        scheduler.unscheduleJob(trigger.getKey());
        JobKey jobKey = trigger.getJobKey();
        if (scheduler.getTriggersOfJob(jobKey).isEmpty()) {
            scheduler.deleteJob(jobKey);
        }
    } catch (org.quartz.SchedulerException e) {
        throw new SchedulerException(e);
    }
}
Also used : JobKey(org.quartz.JobKey) ProtoTrigger(co.cask.cdap.proto.ProtoTrigger) Trigger(org.quartz.Trigger)

Example 49 with Trigger

use of org.quartz.Trigger in project cdap by caskdata.

the class DatasetBasedTimeScheduleStoreTest method testJobProperties.

@Test
public void testJobProperties() throws SchedulerException, UnsupportedTypeException, InterruptedException {
    schedulerSetup(true);
    JobDetail jobDetail = getJobDetail("mapreduce1");
    Trigger trigger = TriggerBuilder.newTrigger().withIdentity("g2").usingJobData(LogPrintingJob.KEY, LogPrintingJob.VALUE).startNow().withSchedule(CronScheduleBuilder.cronSchedule("0/1 * * * * ?")).build();
    //Schedule job
    scheduler.scheduleJob(jobDetail, trigger);
    //Make sure that the job gets triggered more than once.
    TimeUnit.SECONDS.sleep(3);
    scheduler.deleteJob(jobDetail.getKey());
    schedulerTearDown();
}
Also used : JobDetail(org.quartz.JobDetail) Trigger(org.quartz.Trigger) Test(org.junit.Test)

Example 50 with Trigger

use of org.quartz.Trigger in project cdap by caskdata.

the class DatasetBasedTimeScheduleStoreTest method testSimpleJobDeletion.

@Test
public void testSimpleJobDeletion() throws Exception {
    schedulerSetup(true);
    Trigger trigger = TriggerBuilder.newTrigger().withIdentity("g2").usingJobData(LogPrintingJob.KEY, LogPrintingJob.VALUE).startNow().withSchedule(CronScheduleBuilder.cronSchedule("0/1 * * * * ?")).build();
    int oldCount = scheduler.getJobKeys(GroupMatcher.anyJobGroup()).size();
    JobDetail jobDetail = getJobDetail("mr1");
    scheduler.scheduleJob(jobDetail, trigger);
    Assert.assertTrue(scheduler.unscheduleJob(trigger.getKey()));
    Assert.assertTrue(scheduler.deleteJob(jobDetail.getKey()));
    int newCount = scheduler.getJobKeys(GroupMatcher.anyJobGroup()).size();
    Assert.assertEquals(oldCount, newCount);
    schedulerTearDown();
    schedulerSetup(true);
    newCount = scheduler.getJobKeys(GroupMatcher.anyJobGroup()).size();
    Assert.assertEquals(oldCount, newCount);
    schedulerTearDown();
}
Also used : JobDetail(org.quartz.JobDetail) Trigger(org.quartz.Trigger) Test(org.junit.Test)

Aggregations

Trigger (org.quartz.Trigger)104 JobDetail (org.quartz.JobDetail)51 SchedulerException (org.quartz.SchedulerException)40 CronTrigger (org.quartz.CronTrigger)29 Test (org.junit.Test)23 Scheduler (org.quartz.Scheduler)22 JobDataMap (org.quartz.JobDataMap)21 SimpleTrigger (org.quartz.SimpleTrigger)20 TriggerKey (org.quartz.TriggerKey)20 TriggerBuilder.newTrigger (org.quartz.TriggerBuilder.newTrigger)19 JobKey (org.quartz.JobKey)16 ArrayList (java.util.ArrayList)13 Date (java.util.Date)12 List (java.util.List)5 Command (org.openhab.core.types.Command)5 InetSocketAddress (java.net.InetSocketAddress)4 SocketChannel (java.nio.channels.SocketChannel)4 ParseException (java.text.ParseException)4 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)4 ProtoTrigger (co.cask.cdap.proto.ProtoTrigger)3