use of org.quartz.JobDetail in project cdap by caskdata.
the class TimeScheduler method addProgramSchedule.
@Override
public void addProgramSchedule(ProgramSchedule schedule) throws AlreadyExistsException, SchedulerException {
checkInitialized();
ProgramId program = schedule.getProgramId();
SchedulableProgramType programType = program.getType().getSchedulableType();
try {
assertScheduleDoesNotExist(program, programType, schedule.getName());
} catch (org.quartz.SchedulerException e) {
throw new SchedulerException(e);
}
JobDetail job = addJob(program, programType);
scheduleJob(program, programType, schedule.getName(), ((ProtoTrigger.TimeTrigger) schedule.getTrigger()).getCronExpression(), job, schedule.getProperties());
}
use of org.quartz.JobDetail 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.JobDetail in project cdap by caskdata.
the class DatasetBasedTimeScheduleStoreTest method testSchedulerWithoutPersistence.
@Test
public void testSchedulerWithoutPersistence() throws SchedulerException, UnsupportedTypeException {
JobKey jobKey = scheduleJobWithTrigger(false);
verifyJobAndTriggers(jobKey, 1, Trigger.TriggerState.NORMAL);
//Shutdown scheduler.
schedulerTearDown();
//restart scheduler.
schedulerSetup(false);
//read the job
JobDetail jobStored = scheduler.getJobDetail(jobKey);
// The job with old job key should not exist since it is not persisted.
Assert.assertNull(jobStored);
schedulerTearDown();
}
use of org.quartz.JobDetail 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();
}
use of org.quartz.JobDetail in project cdap by caskdata.
the class DatasetBasedTimeScheduleStoreTest method verifyJobAndTriggers.
private void verifyJobAndTriggers(JobKey jobKey, int expectedTriggersSize, Trigger.TriggerState expectedTriggerState) throws SchedulerException {
JobDetail jobStored = scheduler.getJobDetail(jobKey);
List<? extends Trigger> triggers = scheduler.getTriggersOfJob(jobKey);
Assert.assertEquals(jobStored.getKey().getName(), jobKey.getName());
Assert.assertEquals(expectedTriggersSize, triggers.size());
verifyTriggerState(triggers, expectedTriggerState);
}
Aggregations