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