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;
}
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);
}
}
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);
}
}
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();
}
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();
}
Aggregations