Search in sources :

Example 71 with SchedulerException

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());
}
Also used : ComplexJobTrigger(org.pentaho.platform.api.scheduler2.ComplexJobTrigger) Job(org.pentaho.platform.api.scheduler2.Job) Test(org.junit.Test)

Example 72 with SchedulerException

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());
}
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 73 with SchedulerException

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);
    }
}
Also used : SchedulerException(org.pentaho.platform.api.scheduler2.SchedulerException) IJobTrigger(org.pentaho.platform.api.scheduler2.IJobTrigger) Job(org.pentaho.platform.api.scheduler2.Job)

Example 74 with SchedulerException

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;
}
Also used : SchedulerException(org.quartz.SchedulerException) SQLException(java.sql.SQLException) IOException(java.io.IOException) Properties(java.util.Properties) IDBDatasourceService(org.pentaho.platform.api.data.IDBDatasourceService) DataSource(javax.sql.DataSource) DBDatasourceServiceException(org.pentaho.platform.api.data.DBDatasourceServiceException) ObjectFactoryException(org.pentaho.platform.api.engine.ObjectFactoryException) IScheduler(org.pentaho.platform.api.scheduler2.IScheduler)

Example 75 with SchedulerException

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

Aggregations

SchedulerException (org.pentaho.platform.api.scheduler2.SchedulerException)51 Test (org.junit.Test)49 Job (org.pentaho.platform.api.scheduler2.Job)43 IScheduler (org.pentaho.platform.api.scheduler2.IScheduler)23 ComplexJobTrigger (org.pentaho.platform.api.scheduler2.ComplexJobTrigger)18 SimpleJobTrigger (org.pentaho.platform.api.scheduler2.SimpleJobTrigger)16 Serializable (java.io.Serializable)15 IJobTrigger (org.pentaho.platform.api.scheduler2.IJobTrigger)11 Date (java.util.Date)10 JobTrigger (org.pentaho.platform.api.scheduler2.JobTrigger)9 Scheduler (org.quartz.Scheduler)9 ArrayList (java.util.ArrayList)8 IJobFilter (org.pentaho.platform.api.scheduler2.IJobFilter)8 IOException (java.io.IOException)6 Calendar (java.util.Calendar)6 HashMap (java.util.HashMap)6 CronTrigger (org.quartz.CronTrigger)6 SimpleTrigger (org.quartz.SimpleTrigger)6 Trigger (org.quartz.Trigger)6 Response (javax.ws.rs.core.Response)5