Search in sources :

Example 21 with SchedulerException

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

the class QuartzScheduler method createJob.

/**
 * {@inheritDoc}
 */
public Job createJob(String jobName, Class<? extends IAction> action, Map<String, Serializable> jobParams, IJobTrigger trigger, IBackgroundExecutionStreamProvider outputStreamProvider) throws SchedulerException {
    if (action == null) {
        // $NON-NLS-1$
        throw new SchedulerException(Messages.getInstance().getString("QuartzScheduler.ERROR_0003_ACTION_IS_NULL"));
    }
    if (jobParams == null) {
        jobParams = new HashMap<String, Serializable>();
    }
    jobParams.put(RESERVEDMAPKEY_ACTIONCLASS, action.getName());
    Job ret = createJob(jobName, jobParams, trigger, outputStreamProvider);
    ret.setSchedulableClass(action.getName());
    return ret;
}
Also used : Serializable(java.io.Serializable) SchedulerException(org.pentaho.platform.api.scheduler2.SchedulerException) Job(org.pentaho.platform.api.scheduler2.Job)

Example 22 with SchedulerException

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

the class QuartzScheduler method getJobs.

/**
 * {@inheritDoc}
 */
@SuppressWarnings("unchecked")
public List<Job> getJobs(IJobFilter filter) throws SchedulerException {
    ArrayList<Job> jobs = new ArrayList<Job>();
    try {
        Scheduler scheduler = getQuartzScheduler();
        for (String groupName : scheduler.getJobGroupNames()) {
            for (String jobId : scheduler.getJobNames(groupName)) {
                for (Trigger trigger : scheduler.getTriggersOfJob(jobId, groupName)) {
                    if ("MANUAL_TRIGGER".equals(trigger.getGroup())) {
                        continue;
                    }
                    Job job = new Job();
                    job.setGroupName(groupName);
                    JobDetail jobDetail = scheduler.getJobDetail(jobId, groupName);
                    if (jobDetail != null) {
                        job.setUserName(jobDetail.getGroup());
                        JobDataMap jobDataMap = jobDetail.getJobDataMap();
                        if (jobDataMap != null) {
                            Map<String, Serializable> wrappedMap = jobDataMap.getWrappedMap();
                            job.setJobParams(wrappedMap);
                        }
                    }
                    job.setJobId(jobId);
                    setJobTrigger(scheduler, job, trigger);
                    job.setJobName(QuartzJobKey.parse(jobId).getJobName());
                    job.setNextRun(trigger.getFireTimeAfter(new Date()));
                    job.setLastRun(trigger.getPreviousFireTime());
                    if ((filter == null) || filter.accept(job)) {
                        jobs.add(job);
                    }
                }
            }
        }
    } catch (org.quartz.SchedulerException e) {
        throw new SchedulerException(Messages.getInstance().getString("QuartzScheduler.ERROR_0004_FAILED_TO_LIST_JOBS"), // $NON-NLS-1$
        e);
    }
    return jobs;
}
Also used : JobDataMap(org.quartz.JobDataMap) Serializable(java.io.Serializable) SchedulerException(org.pentaho.platform.api.scheduler2.SchedulerException) Scheduler(org.quartz.Scheduler) IScheduler(org.pentaho.platform.api.scheduler2.IScheduler) ArrayList(java.util.ArrayList) Date(java.util.Date) JobDetail(org.quartz.JobDetail) CronTrigger(org.quartz.CronTrigger) SimpleJobTrigger(org.pentaho.platform.api.scheduler2.SimpleJobTrigger) JobTrigger(org.pentaho.platform.api.scheduler2.JobTrigger) ComplexJobTrigger(org.pentaho.platform.api.scheduler2.ComplexJobTrigger) Trigger(org.quartz.Trigger) SimpleTrigger(org.quartz.SimpleTrigger) IJobTrigger(org.pentaho.platform.api.scheduler2.IJobTrigger) Job(org.pentaho.platform.api.scheduler2.Job)

Example 23 with SchedulerException

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

the class QuartzScheduler method validateJobParams.

/**
 * Checks if the text configuration for the input/output files is present.
 * If not - silently returns. If present checks if the input file is allowed to be scheduled.
 * @param jobParams scheduling job parameters
 * @throws SchedulerException the configuration is recognized but the file can't be scheduled, is a folder or doesn't exist.
 */
@Override
public void validateJobParams(Map<String, Serializable> jobParams) throws SchedulerException {
    final Object streamProviderObj = jobParams.get(RESERVEDMAPKEY_STREAMPROVIDER);
    if (streamProviderObj instanceof String) {
        String inputFilePath = null;
        final String inputOutputString = (String) streamProviderObj;
        final String[] tokens = inputOutputString.split(":");
        if (!ArrayUtils.isEmpty(tokens) && tokens.length == 2) {
            inputFilePath = tokens[0].split("=")[1].trim();
            if (StringUtils.isNotBlank(inputFilePath)) {
                final IUnifiedRepository repository = PentahoSystem.get(IUnifiedRepository.class);
                final RepositoryFile repositoryFile = repository.getFile(inputFilePath);
                if ((repositoryFile == null) || repositoryFile.isFolder() || !repositoryFile.isSchedulable()) {
                    throw new SchedulerException(Messages.getInstance().getString("QuartzScheduler.ERROR_0008_SCHEDULING_IS_NOT_ALLOWED"));
                }
            }
        }
    }
}
Also used : SchedulerException(org.pentaho.platform.api.scheduler2.SchedulerException) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository)

Example 24 with SchedulerException

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

the class PentahoBlockoutManager method willBlockSchedules.

@Override
public List<IJobTrigger> willBlockSchedules(IJobTrigger testBlockOutJobTrigger) {
    List<IJobTrigger> blockedSchedules = new ArrayList<IJobTrigger>();
    List<Job> scheduledJobs = new ArrayList<Job>();
    try {
        scheduledJobs = this.scheduler.getJobs(new IJobFilter() {

            @Override
            public boolean accept(Job job) {
                return !BLOCK_OUT_JOB_NAME.equals(job.getJobName());
            }
        });
    } catch (SchedulerException e) {
        throw new RuntimeException(e);
    }
    // Loop over trigger group names
    for (Job scheduledJob : scheduledJobs) {
        // Add schedule to list if block out conflicts at all
        if (BlockoutManagerUtil.willBlockSchedule(scheduledJob.getJobTrigger(), testBlockOutJobTrigger, this.scheduler)) {
            blockedSchedules.add(scheduledJob.getJobTrigger());
        }
    }
    return blockedSchedules;
}
Also used : IJobFilter(org.pentaho.platform.api.scheduler2.IJobFilter) SchedulerException(org.pentaho.platform.api.scheduler2.SchedulerException) IJobTrigger(org.pentaho.platform.api.scheduler2.IJobTrigger) ArrayList(java.util.ArrayList) Job(org.pentaho.platform.api.scheduler2.Job)

Example 25 with SchedulerException

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

the class EmbeddedVersionCheckSystemListener method deleteJobIfNecessary.

protected void deleteJobIfNecessary() throws SchedulerException {
    // $NON-NLS-1$
    IScheduler scheduler = PentahoSystem.get(IScheduler.class, "IScheduler2", null);
    IJobFilter filter = new IJobFilter() {

        public boolean accept(Job job) {
            return job.getJobName().contains(EmbeddedVersionCheckSystemListener.VERSION_CHECK_JOBNAME);
        }
    };
    // Like old code - remove the existing job and replace it
    List<Job> matchingJobs = scheduler.getJobs(filter);
    if ((matchingJobs != null) && (matchingJobs.size() > 0)) {
        for (Job verCkJob : matchingJobs) {
            scheduler.removeJob(verCkJob.getJobId());
        }
    }
}
Also used : IJobFilter(org.pentaho.platform.api.scheduler2.IJobFilter) Job(org.pentaho.platform.api.scheduler2.Job) IScheduler(org.pentaho.platform.api.scheduler2.IScheduler)

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