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