Search in sources :

Example 16 with JobTrigger

use of org.pentaho.platform.api.scheduler2.JobTrigger 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)

Example 17 with JobTrigger

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

the class RepositoryCleanerSystemListener method rescheduleIfNecessary.

private void rescheduleIfNecessary(IScheduler scheduler, List<Job> jobs) throws SchedulerException {
    JobTrigger trigger = findJobTrigger();
    if (trigger == null) {
        return;
    }
    List<Job> matched = new ArrayList<Job>(jobs.size());
    for (Job job : jobs) {
        JobTrigger tr = job.getJobTrigger();
        // unfortunately, JobTrigger does not override equals
        if (trigger.getClass() != tr.getClass()) {
            logger.info("Removing job with id: " + job.getJobId());
            scheduler.removeJob(job.getJobId());
        } else {
            matched.add(job);
        }
    }
    if (matched.isEmpty()) {
        logger.info("Need to re-schedule job");
        scheduleJob(scheduler);
    }
}
Also used : ArrayList(java.util.ArrayList) Job(org.pentaho.platform.api.scheduler2.Job) SimpleJobTrigger(org.pentaho.platform.api.scheduler2.SimpleJobTrigger) JobTrigger(org.pentaho.platform.api.scheduler2.JobTrigger) ComplexJobTrigger(org.pentaho.platform.api.scheduler2.ComplexJobTrigger)

Example 18 with JobTrigger

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

the class RepositoryCleanerSystemListener method scheduleJob.

private void scheduleJob(IScheduler scheduler) throws SchedulerException {
    JobTrigger trigger = findJobTrigger();
    if (trigger != null) {
        logger.info("Creating new job with trigger: " + trigger);
        scheduler.createJob(RepositoryGcJob.JOB_NAME, RepositoryGcJob.class, null, trigger);
    }
}
Also used : SimpleJobTrigger(org.pentaho.platform.api.scheduler2.SimpleJobTrigger) JobTrigger(org.pentaho.platform.api.scheduler2.JobTrigger) ComplexJobTrigger(org.pentaho.platform.api.scheduler2.ComplexJobTrigger)

Example 19 with JobTrigger

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

the class EmbeddedVersionCheckSystemListener method scheduleJob.

protected void scheduleJob(final int versionRequestFlags, final int repeatSeconds) throws Exception {
    // $NON-NLS-1$
    IScheduler scheduler = PentahoSystem.get(IScheduler.class, "IScheduler2", null);
    deleteJobIfNecessary();
    Map<String, Serializable> parms = new HashMap<String, Serializable>();
    parms.put(VersionCheckerAction.VERSION_REQUEST_FLAGS, new Integer(versionRequestFlags));
    JobTrigger trigger = new SimpleJobTrigger(new Date(), null, -1, repeatSeconds);
    scheduler.createJob(EmbeddedVersionCheckSystemListener.VERSION_CHECK_JOBNAME, VersionCheckerAction.class, parms, trigger);
}
Also used : SimpleJobTrigger(org.pentaho.platform.api.scheduler2.SimpleJobTrigger) Serializable(java.io.Serializable) HashMap(java.util.HashMap) IScheduler(org.pentaho.platform.api.scheduler2.IScheduler) SimpleJobTrigger(org.pentaho.platform.api.scheduler2.SimpleJobTrigger) JobTrigger(org.pentaho.platform.api.scheduler2.JobTrigger) Date(java.util.Date)

Example 20 with JobTrigger

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

the class DefaultSchedulerService method createJob.

private String createJob(String jobName, Map<String, ParamValue> jobParams, JobTrigger trigger) throws SchedulerException {
    // $NON-NLS-1$
    logger.debug("Creating job with schedule " + trigger.toString());
    Job job = null;
    try {
        // $NON-NLS-1$
        IScheduler scheduler = PentahoSystem.get(IScheduler.class, "IScheduler2", null);
        Map<String, Serializable> properJobParams = toProperMap(jobParams);
        scheduler.validateJobParams(properJobParams);
        job = scheduler.createJob(jobName, getDefaultActionId(), properJobParams, trigger);
    } catch (SchedulerException e) {
        // temporary error logging.. this needs to become an aspect
        logger.error(e.getMessage(), e);
        throw e;
    }
    return job.getJobId();
}
Also used : Serializable(java.io.Serializable) SchedulerException(org.pentaho.platform.api.scheduler2.SchedulerException) Job(org.pentaho.platform.api.scheduler2.Job) IScheduler(org.pentaho.platform.api.scheduler2.IScheduler)

Aggregations

Job (org.pentaho.platform.api.scheduler2.Job)12 ComplexJobTrigger (org.pentaho.platform.api.scheduler2.ComplexJobTrigger)11 SimpleJobTrigger (org.pentaho.platform.api.scheduler2.SimpleJobTrigger)11 Test (org.junit.Test)9 Date (java.util.Date)8 Serializable (java.io.Serializable)7 IJobTrigger (org.pentaho.platform.api.scheduler2.IJobTrigger)7 JobTrigger (org.pentaho.platform.api.scheduler2.JobTrigger)7 HashMap (java.util.HashMap)5 IScheduler (org.pentaho.platform.api.scheduler2.IScheduler)5 SchedulerException (org.pentaho.platform.api.scheduler2.SchedulerException)5 ArrayList (java.util.ArrayList)3 Calendar (java.util.Calendar)3 CronJobTrigger (org.pentaho.platform.api.scheduler2.CronJobTrigger)3 QuartzScheduler (org.pentaho.platform.scheduler2.quartz.QuartzScheduler)3 IncrementalRecurrence (org.pentaho.platform.scheduler2.recur.IncrementalRecurrence)3 JobScheduleRequest (org.pentaho.platform.web.http.api.resources.JobScheduleRequest)3 ListParamValue (org.pentaho.platform.scheduler2.ws.ListParamValue)2 MapParamValue (org.pentaho.platform.scheduler2.ws.MapParamValue)2 ParamValue (org.pentaho.platform.scheduler2.ws.ParamValue)2