Search in sources :

Example 11 with IScheduler

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

the class EmbeddedVersionCheckSystemListenerIT method testCreateJob.

@Test
public void testCreateJob() throws SchedulerException {
    IPentahoSession testSession = new StandaloneSession("TEST_USER");
    TestEmbeddedVersionCheckSystemListener listener = new TestEmbeddedVersionCheckSystemListener();
    // First setup like defaults
    listener.setDisableVersionCheck(false);
    listener.setRequestedReleases("Minor, GA");
    listener.setRepeatIntervalSeconds(86400);
    Assert.assertFalse(listener.isDisableVersionCheck());
    Assert.assertEquals("Minor, GA", listener.getRequestedReleases());
    Assert.assertEquals(86400, listener.getRepeatIntervalSeconds());
    listener.setRepeatIntervalSeconds(200);
    // makes sure that min isn't ignored
    Assert.assertEquals(43200, listener.calculateRepeatSeconds());
    // Expect 0 because Minor <> minor and GA <> ga
    Assert.assertEquals(0, listener.calculateRequestFlags());
    listener.setRequestedReleases("minor, ga");
    // should be 8 + 32 = 40
    Assert.assertEquals(40, listener.calculateRequestFlags());
    // Fake availability of version checker.
    listener.setFakeAvail();
    listener.startup(testSession);
    // $NON-NLS-1$
    IScheduler scheduler = PentahoSystem.get(IScheduler.class, "IScheduler2", null);
    IJobFilter filter = new IJobFilter() {

        public boolean accept(Job job) {
            return job.getJobName().contains("PentahoSystemVersionCheck");
        }
    };
    List<Job> matchingJobs = scheduler.getJobs(filter);
    Assert.assertEquals(1, matchingJobs.size());
    Job aJob = matchingJobs.get(0);
    Assert.assertTrue(aJob.getJobName().startsWith("PentahoSystemVersionCheck"));
    Assert.assertEquals(TEST_USER, aJob.getUserName());
    Map<String, Serializable> vcJobParms = aJob.getJobParams();
    Assert.assertTrue(vcJobParms.size() > 0);
    Assert.assertTrue(vcJobParms.containsKey(VersionCheckerAction.VERSION_REQUEST_FLAGS));
    Object val = vcJobParms.get(VersionCheckerAction.VERSION_REQUEST_FLAGS);
    Assert.assertNotNull(val);
    Assert.assertTrue(val instanceof Integer);
    Integer intVal = (Integer) val;
    Assert.assertEquals(40, intVal.intValue());
    listener.deleteJobIfNecessary();
    // Should have no jobs now
    matchingJobs = scheduler.getJobs(null);
    Assert.assertEquals(0, matchingJobs.size());
}
Also used : IJobFilter(org.pentaho.platform.api.scheduler2.IJobFilter) Serializable(java.io.Serializable) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) Job(org.pentaho.platform.api.scheduler2.Job) IScheduler(org.pentaho.platform.api.scheduler2.IScheduler) Test(org.junit.Test)

Example 12 with IScheduler

use of org.pentaho.platform.api.scheduler2.IScheduler 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 13 with IScheduler

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

the class RepositoryCleanerSystemListener method unscheduleJob.

private void unscheduleJob(IScheduler scheduler, List<Job> jobs) throws SchedulerException {
    for (Job job : jobs) {
        logger.info("Removing job with id: " + job.getJobId());
        scheduler.removeJob(job.getJobId());
    }
}
Also used : Job(org.pentaho.platform.api.scheduler2.Job)

Example 14 with IScheduler

use of org.pentaho.platform.api.scheduler2.IScheduler 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 15 with IScheduler

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

Aggregations

IScheduler (org.pentaho.platform.api.scheduler2.IScheduler)14 SimpleJobTrigger (org.pentaho.platform.api.scheduler2.SimpleJobTrigger)8 Job (org.pentaho.platform.api.scheduler2.Job)7 Serializable (java.io.Serializable)6 Date (java.util.Date)6 ComplexJobTrigger (org.pentaho.platform.api.scheduler2.ComplexJobTrigger)5 JobTrigger (org.pentaho.platform.api.scheduler2.JobTrigger)5 IJobTrigger (org.pentaho.platform.api.scheduler2.IJobTrigger)4 SchedulerException (org.pentaho.platform.api.scheduler2.SchedulerException)4 HashMap (java.util.HashMap)3 ArrayList (java.util.ArrayList)2 IAuthorizationPolicy (org.pentaho.platform.api.engine.IAuthorizationPolicy)2 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)2 IBlockoutManager (org.pentaho.platform.api.scheduler2.IBlockoutManager)2 IJobFilter (org.pentaho.platform.api.scheduler2.IJobFilter)2 QuartzScheduler (org.pentaho.platform.scheduler2.quartz.QuartzScheduler)2 Calendar (java.util.Calendar)1 GregorianCalendar (java.util.GregorianCalendar)1 Map (java.util.Map)1 WebService (javax.jws.WebService)1