Search in sources :

Example 1 with CronTriggerImpl

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());
    }
}
Also used : SimpleJobConfiguration(com.dangdang.ddframe.job.config.simple.SimpleJobConfiguration) CronTriggerImpl(org.quartz.impl.triggers.CronTriggerImpl) Test(org.junit.Test)

Example 2 with CronTriggerImpl

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);
            }
        }
    }
}
Also used : JobDetail(org.quartz.JobDetail) SchedulerException(org.quartz.SchedulerException) Report(org.opennms.netmgt.config.reportd.Report) JobDetailImpl(org.quartz.impl.JobDetailImpl) CronTriggerImpl(org.quartz.impl.triggers.CronTriggerImpl) ParseException(java.text.ParseException)

Example 3 with CronTriggerImpl

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;
    }
}
Also used : SchedulerException(org.quartz.SchedulerException) MessageBuilder(org.springframework.binding.message.MessageBuilder) CronTriggerImpl(org.quartz.impl.triggers.CronTriggerImpl) ParseException(java.text.ParseException) ReportServiceLocatorException(org.opennms.reporting.core.svclayer.ReportServiceLocatorException)

Example 4 with CronTriggerImpl

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());
}
Also used : SimpleJobConfiguration(com.dangdang.ddframe.job.config.simple.SimpleJobConfiguration) CronTriggerImpl(org.quartz.impl.triggers.CronTriggerImpl) Test(org.junit.Test)

Example 5 with CronTriggerImpl

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;
}
Also used : CronTriggerImpl(org.quartz.impl.triggers.CronTriggerImpl) Date(java.util.Date)

Aggregations

CronTriggerImpl (org.quartz.impl.triggers.CronTriggerImpl)6 ParseException (java.text.ParseException)3 SchedulerException (org.quartz.SchedulerException)3 SimpleJobConfiguration (com.dangdang.ddframe.job.config.simple.SimpleJobConfiguration)2 Test (org.junit.Test)2 JobDetail (org.quartz.JobDetail)2 JobDetailImpl (org.quartz.impl.JobDetailImpl)2 Date (java.util.Date)1 RequisitionDef (org.opennms.netmgt.config.provisiond.RequisitionDef)1 Report (org.opennms.netmgt.config.reportd.Report)1 ReportServiceLocatorException (org.opennms.reporting.core.svclayer.ReportServiceLocatorException)1 MessageBuilder (org.springframework.binding.message.MessageBuilder)1