Search in sources :

Example 1 with IJobFilter

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

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

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

Example 4 with IJobFilter

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

the class SolutionImportHandlerIT method testImportSchedules.

@Test
@SuppressWarnings("unchecked")
public void testImportSchedules() throws PlatformImportException, SchedulerException {
    SolutionImportHandler importHandler = new SolutionImportHandler(Collections.emptyList());
    importHandler = spy(importHandler);
    List<JobScheduleRequest> requests = new ArrayList<JobScheduleRequest>(4);
    requests.add(createJobScheduleRequest("NORMAL", JobState.NORMAL));
    requests.add(createJobScheduleRequest("PAUSED", JobState.PAUSED));
    requests.add(createJobScheduleRequest("PAUSED", JobState.COMPLETE));
    requests.add(createJobScheduleRequest("PAUSED", JobState.ERROR));
    doReturn(new ArrayList<Job>()).when(importHandler).getAllJobs(any());
    importHandler.importSchedules(requests);
    List<Job> jobs = scheduler.getJobs(new IJobFilter() {

        @Override
        public boolean accept(Job job) {
            return true;
        }
    });
    assertEquals(4, jobs.size());
    for (Iterator<?> iterator = jobs.iterator(); iterator.hasNext(); ) {
        Job job = (Job) iterator.next();
        assertEquals(job.getJobName(), job.getState().toString());
    }
}
Also used : IJobFilter(org.pentaho.platform.api.scheduler2.IJobFilter) ArrayList(java.util.ArrayList) Job(org.pentaho.platform.api.scheduler2.Job) JobScheduleRequest(org.pentaho.platform.web.http.api.resources.JobScheduleRequest) Test(org.junit.Test)

Example 5 with IJobFilter

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

the class SchedulerService method getJobs.

public List<Job> getJobs() throws SchedulerException {
    IPentahoSession session = getSession();
    // this authentication wasn't matching with the job user name,
    final String principalName = session.getName();
    // changed to get name via the current session
    final Boolean canAdminister = canAdminister(session);
    List<Job> jobs = getScheduler().getJobs(new IJobFilter() {

        @Override
        public boolean accept(Job job) {
            if (canAdminister) {
                return !IBlockoutManager.BLOCK_OUT_JOB_NAME.equals(job.getJobName());
            }
            return principalName.equals(job.getUserName());
        }
    });
    return jobs;
}
Also used : IJobFilter(org.pentaho.platform.api.scheduler2.IJobFilter) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) Job(org.pentaho.platform.api.scheduler2.Job)

Aggregations

Job (org.pentaho.platform.api.scheduler2.Job)12 IJobFilter (org.pentaho.platform.api.scheduler2.IJobFilter)11 Test (org.junit.Test)8 ArrayList (java.util.ArrayList)7 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)4 Serializable (java.io.Serializable)3 IJobTrigger (org.pentaho.platform.api.scheduler2.IJobTrigger)3 IScheduler (org.pentaho.platform.api.scheduler2.IScheduler)3 SchedulerException (org.pentaho.platform.api.scheduler2.SchedulerException)3 Date (java.util.Date)2 ComplexJobTrigger (org.pentaho.platform.api.scheduler2.ComplexJobTrigger)2 SimpleJobTrigger (org.pentaho.platform.api.scheduler2.SimpleJobTrigger)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 CronTrigger (org.quartz.CronTrigger)2 SimpleTrigger (org.quartz.SimpleTrigger)2 Trigger (org.quartz.Trigger)2 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 JobTrigger (org.pentaho.platform.api.scheduler2.JobTrigger)1