use of org.pentaho.platform.api.scheduler2.SchedulerException in project pentaho-platform by pentaho.
the class QuartzSchedulerIT method testRemoveJob.
@Test
public void testRemoveJob() throws SchedulerException {
scheduler.pause();
ComplexJobTrigger trigger = new ComplexJobTrigger();
trigger.addYearlyRecurrence(2050);
scheduler.createJob("testName1", TestAction.class, jobParams, trigger);
Assert.assertEquals(1, scheduler.getJobs(null).size());
for (Job oldJob : scheduler.getJobs(null)) {
scheduler.removeJob(oldJob.getJobId());
}
Assert.assertEquals(0, scheduler.getJobs(null).size());
}
use of org.pentaho.platform.api.scheduler2.SchedulerException 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());
}
use of org.pentaho.platform.api.scheduler2.SchedulerException in project pentaho-platform by pentaho.
the class PentahoBlockoutManager method getBlockOut.
@Override
public IJobTrigger getBlockOut(String blockOutJobId) {
try {
Job blockOutJob = this.scheduler.getJob(blockOutJobId);
IJobTrigger blockOutJobTrigger = blockOutJob.getJobTrigger();
blockOutJobTrigger.setDuration(((Number) blockOutJob.getJobParams().get(DURATION_PARAM)).longValue());
return blockOutJobTrigger;
} catch (SchedulerException e) {
throw new RuntimeException(e);
}
}
use of org.pentaho.platform.api.scheduler2.SchedulerException in project pentaho-platform by pentaho.
the class EmbeddedQuartzSystemListener method startup.
public boolean startup(final IPentahoSession session) {
boolean result = true;
Properties quartzProps = null;
if (quartzPropertiesFile != null) {
quartzProps = PentahoSystem.getSystemSettings().getSystemSettingsProperties(quartzPropertiesFile);
} else if (quartzProperties != null) {
quartzProps = quartzProperties;
}
try {
if (quartzProps == null) {
quartzProps = findPropertiesInClasspath();
}
if (quartzProps == null) {
result = false;
} else {
// $NON-NLS-1$
String dsName = quartzProps.getProperty("org.quartz.dataSource.myDS.jndiURL");
if (dsName != null) {
IDBDatasourceService datasourceService = getQuartzDatasourceService(session);
String boundDsName = datasourceService.getDSBoundName(dsName);
if (boundDsName != null) {
// $NON-NLS-1$
quartzProps.setProperty("org.quartz.dataSource.myDS.jndiURL", boundDsName);
}
DataSource ds = datasourceService.getDataSource(dsName);
result = verifyQuartzIsConfigured(ds);
}
// $NON-NLS-1$
QuartzScheduler scheduler = (QuartzScheduler) PentahoSystem.get(IScheduler.class, "IScheduler2", null);
if (logger.isDebugEnabled()) {
// $NON-NLS-1$
logger.debug("Quartz configured with properties");
// $NON-NLS-1$
quartzProps.store(System.out, "debugging");
}
scheduler.setQuartzSchedulerFactory(new org.quartz.impl.StdSchedulerFactory(quartzProps));
if (logger.isDebugEnabled()) {
logger.debug(scheduler.getQuartzScheduler().getSchedulerName());
}
scheduler.start();
}
} catch (IOException ex) {
result = false;
logger.error(Messages.getInstance().getErrorString("EmbeddedQuartzSystemListener.ERROR_0004_LOAD_PROPERTIES_FROM_CLASSPATH"), // $NON-NLS-1$
ex);
} catch (ObjectFactoryException objface) {
logger.error(Messages.getInstance().getErrorString("EmbeddedQuartzSystemListener.ERROR_0005_UNABLE_TO_INSTANTIATE_OBJECT", EmbeddedQuartzSystemListener.class.getName()), // $NON-NLS-1$
objface);
result = false;
} catch (DBDatasourceServiceException dse) {
logger.error(Messages.getInstance().getErrorString("EmbeddedQuartzSystemListener.ERROR_0006_UNABLE_TO_GET_DATASOURCE", EmbeddedQuartzSystemListener.class.getName()), // $NON-NLS-1$
dse);
result = false;
} catch (SQLException sqle) {
// $NON-NLS-1$
logger.error("EmbeddedQuartzSystemListener.ERROR_0007_SQLERROR", sqle);
result = false;
} catch (SchedulerException e) {
logger.error(Messages.getInstance().getErrorString("EmbeddedQuartzSystemListener.ERROR_0001_Scheduler_Not_Initialized", EmbeddedQuartzSystemListener.class.getName()), // $NON-NLS-1$
e);
result = false;
} catch (org.pentaho.platform.api.scheduler2.SchedulerException e) {
logger.error(Messages.getInstance().getErrorString("EmbeddedQuartzSystemListener.ERROR_0001_Scheduler_Not_Initialized", EmbeddedQuartzSystemListener.class.getName()), // $NON-NLS-1$
e);
result = false;
}
return result;
}
use of org.pentaho.platform.api.scheduler2.SchedulerException 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());
}
Aggregations