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());
}
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);
}
}
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());
}
}
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);
}
}
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);
}
Aggregations