use of com.google.cloud.scheduler.v1beta1.Job in project pentaho-platform by pentaho.
the class JaxWsSchedulerServiceIT method testUpdateComplexJob.
/*
public static class TestQuartzScheduler extends QuartzScheduler {
@Override
protected String getCurrentUser() {
SecurityHelper.getInstance().becomeUser( TEST_USER );
return super.getCurrentUser();
}
}
*/
@Test(timeout = 1000 * 5 * 60)
public void testUpdateComplexJob() throws SchedulerException {
long start = System.currentTimeMillis() + 1000;
long end = System.currentTimeMillis() + 1000 + 5 * 60 * 60 * 100;
int startingMinute = (Calendar.getInstance().get(Calendar.MINUTE) + 10) % 60;
ComplexJobTrigger jobTrigger = new ComplexJobTrigger();
jobTrigger.setStartTime(new Date(start));
jobTrigger.setEndTime(new Date(end));
jobTrigger.setMinuteRecurrence(new IncrementalRecurrence(startingMinute, 1));
jobTrigger.setHourlyRecurrence((ITimeRecurrence) null);
System.out.println(jobTrigger.toString());
String jobId = schedulerSvc.createComplexJob("test job", jobParams, jobTrigger);
Assert.assertEquals(1, schedulerSvc.getJobs().length);
jobTrigger = new ComplexJobTrigger();
start = System.currentTimeMillis() + 2 * 1000;
end = System.currentTimeMillis() + 1000 + 7 * 60 * 60 * 100;
jobTrigger.setStartTime(new Date(start));
jobTrigger.setEndTime(new Date(end));
startingMinute = (Calendar.getInstance().get(Calendar.MINUTE) + 20) % 60;
jobTrigger.setMinuteRecurrence(new IncrementalRecurrence(startingMinute, 5));
jobTrigger.setHourlyRecurrence((ITimeRecurrence) null);
System.out.println(jobTrigger.toString());
HashMap<String, ParamValue> newJobParams = new HashMap<String, ParamValue>(jobParams);
newJobParams.put("newKey", new StringParamValue(""));
schedulerSvc.updateJobToUseComplexTrigger(jobId, newJobParams, jobTrigger);
Assert.assertEquals(1, schedulerSvc.getJobs().length);
Job job = schedulerSvc.getJobs()[0];
jobTrigger = (ComplexJobTrigger) job.getJobTrigger();
Assert.assertEquals((Integer) startingMinute, ((IncrementalRecurrence) jobTrigger.getMinuteRecurrences().get(0)).getStartingValue());
Assert.assertEquals((Integer) 5, ((IncrementalRecurrence) jobTrigger.getMinuteRecurrences().get(0)).getIncrement());
Assert.assertTrue(job.getJobParams().containsKey("newKey"));
Assert.assertEquals(new Date(start), jobTrigger.getStartTime());
Assert.assertEquals(new Date(end), jobTrigger.getEndTime());
}
use of com.google.cloud.scheduler.v1beta1.Job in project pentaho-platform by pentaho.
the class JaxWsSchedulerServiceIT method testUpdateSimpleJob.
@Test
public void testUpdateSimpleJob() throws SchedulerException {
long start = System.currentTimeMillis() + 1000;
long end = System.currentTimeMillis() + 1000 + 5 * 60 * 60 * 100;
SimpleJobTrigger jobTrigger = new SimpleJobTrigger();
jobTrigger.setStartTime(new Date(start));
jobTrigger.setEndTime(new Date(end));
jobTrigger.setRepeatInterval(10);
jobTrigger.setRepeatCount(20);
System.out.println(jobTrigger.toString());
String jobId = schedulerSvc.createSimpleJob("test job", jobParams, jobTrigger);
Assert.assertEquals(1, schedulerSvc.getJobs().length);
jobTrigger = new SimpleJobTrigger();
start = System.currentTimeMillis() + 1000;
end = System.currentTimeMillis() + 1000 + 5 * 60 * 60 * 100;
jobTrigger.setStartTime(new Date(start));
jobTrigger.setEndTime(new Date(end));
jobTrigger.setRepeatInterval(40);
jobTrigger.setRepeatCount(50);
System.out.println(jobTrigger.toString());
HashMap<String, ParamValue> newJobParams = new HashMap<String, ParamValue>(jobParams);
newJobParams.put("newKey", new StringParamValue(""));
schedulerSvc.updateJobToUseSimpleTrigger(jobId, newJobParams, jobTrigger);
Assert.assertEquals(1, schedulerSvc.getJobs().length);
Job job = schedulerSvc.getJobs()[0];
jobTrigger = (SimpleJobTrigger) job.getJobTrigger();
Assert.assertEquals(40, jobTrigger.getRepeatInterval());
Assert.assertEquals(50, jobTrigger.getRepeatCount());
Assert.assertTrue(job.getJobParams().containsKey("newKey"));
jobTrigger.getStartTime();
Assert.assertEquals(new Date(start), jobTrigger.getStartTime());
Assert.assertEquals(new Date(end), jobTrigger.getEndTime());
}
use of com.google.cloud.scheduler.v1beta1.Job 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 com.google.cloud.scheduler.v1beta1.Job in project pentaho-platform by pentaho.
the class PentahoPlatformExporter method exportSchedules.
protected void exportSchedules() {
log.debug("export schedules");
try {
List<Job> jobs = getScheduler().getJobs(null);
for (Job job : jobs) {
if (job.getJobName().equals(EmbeddedVersionCheckSystemListener.VERSION_CHECK_JOBNAME)) {
// if it doesn't exist and fails if you try to import it due to a null ActionClass
continue;
}
try {
JobScheduleRequest scheduleRequest = ScheduleExportUtil.createJobScheduleRequest(job);
getExportManifest().addSchedule(scheduleRequest);
} catch (IllegalArgumentException e) {
log.warn(e.getMessage(), e);
}
}
} catch (SchedulerException e) {
log.error(Messages.getInstance().getString("PentahoPlatformExporter.ERROR_EXPORTING_JOBS"), e);
}
}
use of com.google.cloud.scheduler.v1beta1.Job in project pentaho-platform by pentaho.
the class QuartzScheduler method getJob.
/**
* {@inheritDoc}
*/
@SuppressWarnings("unchecked")
public Job getJob(String jobId) throws SchedulerException {
try {
Scheduler scheduler = getQuartzScheduler();
QuartzJobKey jobKey = QuartzJobKey.parse(jobId);
String groupName = jobKey.getUserName();
for (Trigger trigger : scheduler.getTriggersOfJob(jobId, groupName)) {
Job job = new Job();
JobDetail jobDetail = scheduler.getJobDetail(jobId, groupName);
if (jobDetail != null) {
JobDataMap jobDataMap = jobDetail.getJobDataMap();
if (jobDataMap != null) {
Map<String, Serializable> wrappedMap = jobDataMap.getWrappedMap();
job.setJobParams(wrappedMap);
}
}
job.setJobId(jobId);
setJobTrigger(scheduler, job, trigger);
job.setUserName(jobDetail.getGroup());
return job;
}
} catch (org.quartz.SchedulerException e) {
throw new SchedulerException(Messages.getInstance().getString("QuartzScheduler.ERROR_0007_FAILED_TO_GET_JOB", jobId), // $NON-NLS-1$
e);
}
return null;
}
Aggregations