Search in sources :

Example 51 with JobDetail

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());
}
Also used : JobDetail(org.quartz.JobDetail) ProtoTrigger(co.cask.cdap.proto.ProtoTrigger) SchedulableProgramType(co.cask.cdap.api.schedule.SchedulableProgramType) ProgramId(co.cask.cdap.proto.id.ProgramId)

Example 52 with JobDetail

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();
}
Also used : JobDetail(org.quartz.JobDetail) Trigger(org.quartz.Trigger) Test(org.junit.Test)

Example 53 with JobDetail

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();
}
Also used : JobKey(org.quartz.JobKey) JobDetail(org.quartz.JobDetail) Test(org.junit.Test)

Example 54 with JobDetail

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();
}
Also used : JobDetail(org.quartz.JobDetail) Trigger(org.quartz.Trigger) Test(org.junit.Test)

Example 55 with JobDetail

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);
}
Also used : JobDetail(org.quartz.JobDetail)

Aggregations

JobDetail (org.quartz.JobDetail)131 SchedulerException (org.quartz.SchedulerException)59 Trigger (org.quartz.Trigger)51 Scheduler (org.quartz.Scheduler)34 Test (org.junit.Test)30 CronTrigger (org.quartz.CronTrigger)26 JobKey (org.quartz.JobKey)22 SimpleTrigger (org.quartz.SimpleTrigger)22 JobDataMap (org.quartz.JobDataMap)20 TriggerBuilder.newTrigger (org.quartz.TriggerBuilder.newTrigger)15 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)11 TriggerKey (org.quartz.TriggerKey)10 HashMap (java.util.HashMap)8 Date (java.util.Date)7 ArrayList (java.util.ArrayList)5 Command (org.openhab.core.types.Command)5 IOException (java.io.IOException)4 Serializable (java.io.Serializable)4 InetSocketAddress (java.net.InetSocketAddress)4 SocketChannel (java.nio.channels.SocketChannel)4