Search in sources :

Example 21 with IJobTrigger

use of org.pentaho.platform.api.scheduler2.IJobTrigger in project pentaho-platform by pentaho.

the class PentahoBlockoutManagerIT method testIsPartiallyBlocked.

/**
 * Test method for
 * {@link org.pentaho.platform.scheduler2.blockout.PentahoBlockoutManager#isPartiallyBlocked(org.quartz.IJobTrigger)}.
 */
@Test
public void testIsPartiallyBlocked() throws Exception {
    Calendar blockOutStartDate = new GregorianCalendar(2013, Calendar.JANUARY, 1, 0, 0, 0);
    IJobTrigger blockOutTrigger = new SimpleJobTrigger(blockOutStartDate.getTime(), null, -1, TIME.WEEK.time * 2 / 1000);
    blockOutTrigger.setDuration(duration);
    /*
     * Simple Schedule Triggers
     */
    Calendar trueScheduleStartDate1 = new GregorianCalendar(2013, Calendar.JANUARY, 15, 0, 0, 0);
    IJobTrigger trueSchedule1 = new SimpleJobTrigger(trueScheduleStartDate1.getTime(), null, -1, TIME.WEEK.time * 2 / 1000);
    Calendar trueScheduleStartDate2 = new GregorianCalendar(2013, Calendar.JANUARY, 15, 0, 0, 0);
    IJobTrigger trueSchedule2 = new SimpleJobTrigger(trueScheduleStartDate2.getTime(), null, -1, TIME.WEEK.time / 1000);
    Calendar falseScheduleStartDate1 = new GregorianCalendar(2013, Calendar.JANUARY, 1, 3, 0, 0);
    IJobTrigger falseSchedule1 = new SimpleJobTrigger(falseScheduleStartDate1.getTime(), null, -1, TIME.WEEK.time / 1000);
    Job blockOutJob = addBlockOutJob(blockOutTrigger);
    assertTrue(this.blockOutManager.isPartiallyBlocked(trueSchedule1));
    assertTrue(this.blockOutManager.isPartiallyBlocked(trueSchedule2));
    assertFalse(this.blockOutManager.isPartiallyBlocked(falseSchedule1));
    /*
     * Complex Schedule Triggers
     */
    IJobTrigger trueComplexScheduleTrigger = new ComplexJobTrigger();
    trueComplexScheduleTrigger.setStartTime(trueScheduleStartDate1.getTime());
    // $NON-NLS-1$
    trueComplexScheduleTrigger.setCronString("0 0 1 ? * 2-3 *");
    IJobTrigger falseComplexScheduleTrigger = new ComplexJobTrigger();
    falseComplexScheduleTrigger.setStartTime(trueScheduleStartDate1.getTime());
    // $NON-NLS-1$
    falseComplexScheduleTrigger.setCronString("0 0 1 ? * 2 *");
    assertTrue(this.blockOutManager.isPartiallyBlocked(trueComplexScheduleTrigger));
    assertFalse(this.blockOutManager.isPartiallyBlocked(falseComplexScheduleTrigger));
    /*
     * Complex Block Out IJobTrigger
     */
    deleteJob(blockOutJob.getJobId());
    blockOutTrigger = new ComplexJobTrigger();
    blockOutTrigger.setStartTime(blockOutStartDate.getTime());
    // $NON-NLS-1$
    blockOutTrigger.setCronString("0 0 0 ? * 3 *");
    blockOutTrigger.setDuration(duration);
    addBlockOutJob(blockOutTrigger);
    assertTrue(this.blockOutManager.isPartiallyBlocked(trueSchedule1));
    assertTrue(this.blockOutManager.isPartiallyBlocked(trueSchedule2));
    assertFalse(this.blockOutManager.isPartiallyBlocked(falseSchedule1));
    assertTrue(this.blockOutManager.isPartiallyBlocked(trueComplexScheduleTrigger));
    assertFalse(this.blockOutManager.isPartiallyBlocked(falseComplexScheduleTrigger));
}
Also used : SimpleJobTrigger(org.pentaho.platform.api.scheduler2.SimpleJobTrigger) ComplexJobTrigger(org.pentaho.platform.api.scheduler2.ComplexJobTrigger) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) GregorianCalendar(java.util.GregorianCalendar) IJobTrigger(org.pentaho.platform.api.scheduler2.IJobTrigger) Job(org.pentaho.platform.api.scheduler2.Job) Test(org.junit.Test)

Example 22 with IJobTrigger

use of org.pentaho.platform.api.scheduler2.IJobTrigger in project pentaho-platform by pentaho.

the class PentahoBlockoutManagerIT method addJob.

private Job addJob(IJobTrigger jobTrigger, String jobName, IAction action, Map<String, Serializable> jobParams) throws Exception {
    Job job = this.scheduler.createJob(jobName, action.getClass(), jobParams, jobTrigger);
    this.jobIdsToClear.add(job.getJobId());
    return job;
}
Also used : Job(org.pentaho.platform.api.scheduler2.Job)

Example 23 with IJobTrigger

use of org.pentaho.platform.api.scheduler2.IJobTrigger in project pentaho-platform by pentaho.

the class PentahoBlockoutManagerIT method testShouldFireNow.

/**
 * Test method for {@link org.pentaho.platform.scheduler2.blockout.PentahoBlockoutManager#shouldFireNow()}.
 */
@Test
public void testShouldFireNow() throws Exception {
    Date blockOutStartDate = new Date(System.currentTimeMillis());
    IJobTrigger blockOutJobTrigger = new SimpleJobTrigger(blockOutStartDate, null, -1, TIME.WEEK.time * 2 / 1000);
    blockOutJobTrigger.setDuration(duration);
    Job blockOutJob = addBlockOutJob(blockOutJobTrigger);
    assertFalse(this.blockOutManager.shouldFireNow());
    deleteJob(blockOutJob.getJobId());
    blockOutStartDate = new Date(System.currentTimeMillis() + TIME.HOUR.time);
    blockOutJobTrigger = new SimpleJobTrigger(blockOutStartDate, null, -1, TIME.WEEK.time * 2 / 1000);
    blockOutJobTrigger.setDuration(duration);
    addBlockOutJob(blockOutJobTrigger);
    assertTrue(this.blockOutManager.shouldFireNow());
}
Also used : SimpleJobTrigger(org.pentaho.platform.api.scheduler2.SimpleJobTrigger) IJobTrigger(org.pentaho.platform.api.scheduler2.IJobTrigger) Job(org.pentaho.platform.api.scheduler2.Job) Date(java.util.Date) Test(org.junit.Test)

Example 24 with IJobTrigger

use of org.pentaho.platform.api.scheduler2.IJobTrigger in project pentaho-platform by pentaho.

the class QuartzSchedulerIT method createQuartzTriggerNotDefinedTriggerTest.

@Test(expected = SchedulerException.class)
public void createQuartzTriggerNotDefinedTriggerTest() throws Exception {
    final IJobTrigger trigger = mock(IJobTrigger.class);
    QuartzScheduler.createQuartzTrigger(trigger, getJobKey());
}
Also used : IJobTrigger(org.pentaho.platform.api.scheduler2.IJobTrigger) Test(org.junit.Test)

Example 25 with IJobTrigger

use of org.pentaho.platform.api.scheduler2.IJobTrigger in project pentaho-platform by pentaho.

the class BlockoutManagerUtil method getFireTimes.

public static List<Date> getFireTimes(IJobTrigger jobTrigger, IScheduler scheduler) {
    // Determines the maximum amount of fire times allowed to be calculated
    int n = 1000;
    Date startDate = new Date(System.currentTimeMillis());
    Date endDate = new Date(startDate.getTime() + 4 * TIME.YEAR.time);
    // Quartz Triggers
    if (scheduler instanceof QuartzScheduler) {
        try {
            List<Date> dates = new ArrayList<Date>();
            boolean endDateIsNull = jobTrigger.getEndTime() == null;
            // $NON-NLS-1$ //$NON-NLS-2$
            Trigger trigger = QuartzScheduler.createQuartzTrigger(jobTrigger, new QuartzJobKey("test", "test"));
            // add previous trigger (it might be currently active)
            // $NON-NLS-1$;
            IBlockoutManager manager = PentahoSystem.get(IBlockoutManager.class, "IBlockoutManager", null);
            if (manager != null) {
                List<Job> blockouts = manager.getBlockOutJobs();
                for (Job blockout : blockouts) {
                    if (blockout.getLastRun() != null) {
                        dates.add(blockout.getLastRun());
                    }
                }
            }
            for (int i = 0; i < n; i++) {
                Date nextFireTime = trigger.getFireTimeAfter(startDate);
                if ((nextFireTime == null) || (nextFireTime.after(endDate) || (!endDateIsNull && nextFireTime.after(jobTrigger.getEndTime())))) {
                    break;
                }
                dates.add(nextFireTime);
                startDate = nextFireTime;
            }
            return dates;
        } catch (SchedulerException e) {
            throw new RuntimeException(e);
        }
    }
    throw new RuntimeException(// $NON-NLS-1$
    "Can not calculate fire times for unsupported Scheduler Type: " + scheduler.getClass().getSimpleName());
}
Also used : SchedulerException(org.pentaho.platform.api.scheduler2.SchedulerException) QuartzJobKey(org.pentaho.platform.scheduler2.quartz.QuartzJobKey) ArrayList(java.util.ArrayList) QuartzScheduler(org.pentaho.platform.scheduler2.quartz.QuartzScheduler) Date(java.util.Date) CronJobTrigger(org.pentaho.platform.api.scheduler2.CronJobTrigger) SimpleJobTrigger(org.pentaho.platform.api.scheduler2.SimpleJobTrigger) Trigger(org.quartz.Trigger) IJobTrigger(org.pentaho.platform.api.scheduler2.IJobTrigger) ComplexJobTrigger(org.pentaho.platform.api.scheduler2.ComplexJobTrigger) Job(org.pentaho.platform.api.scheduler2.Job) IBlockoutManager(org.pentaho.platform.api.scheduler2.IBlockoutManager)

Aggregations

IJobTrigger (org.pentaho.platform.api.scheduler2.IJobTrigger)28 Test (org.junit.Test)18 ComplexJobTrigger (org.pentaho.platform.api.scheduler2.ComplexJobTrigger)13 SimpleJobTrigger (org.pentaho.platform.api.scheduler2.SimpleJobTrigger)12 Job (org.pentaho.platform.api.scheduler2.Job)11 Date (java.util.Date)8 SchedulerException (org.pentaho.platform.api.scheduler2.SchedulerException)7 ITimeRecurrence (org.pentaho.platform.api.scheduler2.recur.ITimeRecurrence)6 Serializable (java.io.Serializable)4 Calendar (java.util.Calendar)4 GregorianCalendar (java.util.GregorianCalendar)4 RecurrenceList (org.pentaho.platform.scheduler2.recur.RecurrenceList)4 IScheduler (org.pentaho.platform.api.scheduler2.IScheduler)3 QualifiedDayOfWeek (org.pentaho.platform.scheduler2.recur.QualifiedDayOfWeek)3 Trigger (org.quartz.Trigger)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 IAction (org.pentaho.platform.api.action.IAction)2 CronJobTrigger (org.pentaho.platform.api.scheduler2.CronJobTrigger)2 JobTrigger (org.pentaho.platform.api.scheduler2.JobTrigger)2