use of org.quartz.impl.triggers.CronTriggerImpl in project elastic-job by dangdangdotcom.
the class JobScheduleControllerTest method assertRescheduleJobFailure.
@Test(expected = JobSystemException.class)
public void assertRescheduleJobFailure() throws NoSuchFieldException, SchedulerException {
when(schedulerFacade.loadJobConfiguration()).thenReturn(LiteJobConfiguration.newBuilder(new SimpleJobConfiguration(JobCoreConfiguration.newBuilder("test_job", "0/1 * * * * ?", 3).build(), TestSimpleJob.class.getCanonicalName())).build());
when(scheduler.getTrigger(TriggerKey.triggerKey("test_job_Trigger"))).thenReturn(new CronTriggerImpl());
doThrow(SchedulerException.class).when(scheduler).rescheduleJob(eq(TriggerKey.triggerKey("test_job_Trigger")), Matchers.<Trigger>any());
ReflectionUtils.setFieldValue(jobScheduleController, "scheduler", scheduler);
try {
jobScheduleController.rescheduleJob("0/1 * * * * ?");
} finally {
verify(scheduler).rescheduleJob(eq(TriggerKey.triggerKey("test_job_Trigger")), Matchers.<Trigger>any());
}
}
use of org.quartz.impl.triggers.CronTriggerImpl in project opennms by OpenNMS.
the class ReportScheduler method buildReportSchedule.
private void buildReportSchedule() {
synchronized (m_lock) {
for (Report report : m_configDao.getReports()) {
JobDetail detail = null;
CronTriggerImpl trigger = null;
try {
detail = new JobDetailImpl(report.getReportName(), JOB_GROUP, ReportJob.class, false, false);
detail.getJobDataMap().put(ReportJob.KEY, report);
trigger = new CronTriggerImpl(report.getReportName(), JOB_GROUP, report.getCronSchedule());
trigger.setMisfireInstruction(CronTrigger.MISFIRE_INSTRUCTION_DO_NOTHING);
getScheduler().scheduleJob(detail, trigger);
} catch (ParseException e) {
LOG.error("buildReportSchedule: {}", e.getMessage(), e);
} catch (SchedulerException e) {
LOG.error("buildReportSchedule: {}", e.getMessage(), e);
}
}
}
}
use of org.quartz.impl.triggers.CronTriggerImpl in project opennms by OpenNMS.
the class DefaultSchedulerService method addCronTrigger.
/*
* (non-Javadoc)
* @see
* org.opennms.web.svclayer.support.SchedulerService#addCronTrigger(org
* .opennms.web.report.database.model.DatabaseReportCriteria,
* java.lang.String, java.lang.String, java.lang.String,
* org.springframework.webflow.execution.RequestContext)
*/
/** {@inheritDoc} */
@Override
public String addCronTrigger(String id, ReportParameters criteria, DeliveryOptions deliveryOptions, String cronExpression, RequestContext context) {
CronTriggerImpl cronTrigger = null;
try {
if (m_reportWrapperService.validate(criteria, id) == false) {
LOG.error(PARAMETER_ERROR);
context.getMessageContext().addMessage(new MessageBuilder().error().defaultText(PARAMETER_ERROR).build());
return ERROR;
} else {
try {
cronTrigger = new CronTriggerImpl();
cronTrigger.setGroup(m_triggerGroup);
cronTrigger.setName(deliveryOptions.getInstanceId());
cronTrigger.setJobName(m_jobDetail.getKey().getName());
cronTrigger.setCronExpression(cronExpression);
// cronTrigger = new CronTrigger(triggerName, m_triggerGroup,
// cronExpression);
} catch (ParseException e) {
LOG.error(TRIGGER_PARSE_ERROR, e);
context.getMessageContext().addMessage(new MessageBuilder().error().defaultText(TRIGGER_PARSE_ERROR).build());
context.getMessageContext().addMessage(new MessageBuilder().error().defaultText(e.getMessage()).build());
return ERROR;
}
cronTrigger.setJobName(m_jobDetail.getKey().getName());
cronTrigger.getJobDataMap().put("criteria", (ReportParameters) criteria);
cronTrigger.getJobDataMap().put("reportId", id);
cronTrigger.getJobDataMap().put("mode", ReportMode.SCHEDULED);
cronTrigger.getJobDataMap().put("deliveryOptions", (DeliveryOptions) deliveryOptions);
try {
m_scheduler.scheduleJob(cronTrigger);
} catch (SchedulerException e) {
LOG.error(SCHEDULER_ERROR, e);
context.getMessageContext().addMessage(new MessageBuilder().error().defaultText(SCHEDULER_ERROR).build());
return ERROR;
}
return SUCCESS;
}
} catch (ReportServiceLocatorException e) {
LOG.error(REPORTID_ERROR);
context.getMessageContext().addMessage(new MessageBuilder().error().defaultText(REPORTID_ERROR).build());
return ERROR;
}
}
use of org.quartz.impl.triggers.CronTriggerImpl in project elastic-job by dangdangdotcom.
the class JobScheduleControllerTest method assertRescheduleJobSuccess.
@Test
public void assertRescheduleJobSuccess() throws NoSuchFieldException, SchedulerException {
when(schedulerFacade.loadJobConfiguration()).thenReturn(LiteJobConfiguration.newBuilder(new SimpleJobConfiguration(JobCoreConfiguration.newBuilder("test_job", "0/1 * * * * ?", 3).build(), TestSimpleJob.class.getCanonicalName())).build());
when(scheduler.getTrigger(TriggerKey.triggerKey("test_job_Trigger"))).thenReturn(new CronTriggerImpl());
ReflectionUtils.setFieldValue(jobScheduleController, "scheduler", scheduler);
when(scheduler.isShutdown()).thenReturn(false);
jobScheduleController.rescheduleJob("0/1 * * * * ?");
verify(scheduler).rescheduleJob(eq(TriggerKey.triggerKey("test_job_Trigger")), Matchers.<Trigger>any());
}
use of org.quartz.impl.triggers.CronTriggerImpl in project spring-framework by spring-projects.
the class CronTriggerFactoryBean method afterPropertiesSet.
@Override
public void afterPropertiesSet() throws ParseException {
if (this.name == null) {
this.name = this.beanName;
}
if (this.group == null) {
this.group = Scheduler.DEFAULT_GROUP;
}
if (this.jobDetail != null) {
this.jobDataMap.put("jobDetail", this.jobDetail);
}
if (this.startDelay > 0 || this.startTime == null) {
this.startTime = new Date(System.currentTimeMillis() + this.startDelay);
}
if (this.timeZone == null) {
this.timeZone = TimeZone.getDefault();
}
CronTriggerImpl cti = new CronTriggerImpl();
cti.setName(this.name);
cti.setGroup(this.group);
if (this.jobDetail != null) {
cti.setJobKey(this.jobDetail.getKey());
}
cti.setJobDataMap(this.jobDataMap);
cti.setStartTime(this.startTime);
cti.setCronExpression(this.cronExpression);
cti.setTimeZone(this.timeZone);
cti.setCalendarName(this.calendarName);
cti.setPriority(this.priority);
cti.setMisfireInstruction(this.misfireInstruction);
cti.setDescription(this.description);
this.cronTrigger = cti;
}
Aggregations