Search in sources :

Example 81 with SchedulerException

use of org.quartz.SchedulerException in project opennms by OpenNMS.

the class ImportJobFactory method newJob.

/**
 * {@inheritDoc}
 */
@Override
public Job newJob(final TriggerFiredBundle bundle, final Scheduler scheduler) throws SchedulerException {
    JobDetail jobDetail = bundle.getJobDetail();
    Class<ImportJob> jobClass = getJobClass(jobDetail);
    ImportJob job = null;
    try {
        job = jobClass.newInstance();
        job.setProvisioner(getProvisioner());
        return job;
    } catch (Throwable e) {
        SchedulerException se = new SchedulerException("failed to create job class: " + jobDetail.getJobClass().getName() + "; " + e.getLocalizedMessage(), e);
        throw se;
    }
}
Also used : JobDetail(org.quartz.JobDetail) SchedulerException(org.quartz.SchedulerException)

Example 82 with SchedulerException

use of org.quartz.SchedulerException in project opennms by OpenNMS.

the class ImportScheduler method buildImportSchedule.

/**
 * <p>buildImportSchedule</p>
 */
protected void buildImportSchedule() {
    synchronized (m_lock) {
        Iterator<RequisitionDef> it = m_configDao.getDefs().iterator();
        while (it.hasNext()) {
            RequisitionDef def = it.next();
            JobDetail detail = null;
            CronTriggerImpl trigger = null;
            try {
                detail = new JobDetailImpl(def.getImportName().orElse(null), JOB_GROUP, ImportJob.class, false, false);
                detail.getJobDataMap().put(ImportJob.URL, def.getImportUrlResource().orElse(null));
                detail.getJobDataMap().put(ImportJob.RESCAN_EXISTING, def.getRescanExisting());
                trigger = new CronTriggerImpl(def.getImportName().orElse(null), JOB_GROUP, def.getCronSchedule().orElse(null));
                trigger.setMisfireInstruction(CronTrigger.MISFIRE_INSTRUCTION_DO_NOTHING);
                getScheduler().scheduleJob(detail, trigger);
            } catch (ParseException e) {
                LOG.error("buildImportSchedule: {}", e.getLocalizedMessage(), e);
            } catch (SchedulerException e) {
                LOG.error("buildImportSchedule: {}", e.getLocalizedMessage(), e);
            }
        }
    }
    printCurrentSchedule();
}
Also used : JobDetail(org.quartz.JobDetail) SchedulerException(org.quartz.SchedulerException) JobDetailImpl(org.quartz.impl.JobDetailImpl) CronTriggerImpl(org.quartz.impl.triggers.CronTriggerImpl) RequisitionDef(org.opennms.netmgt.config.provisiond.RequisitionDef) ParseException(java.text.ParseException)

Example 83 with SchedulerException

use of org.quartz.SchedulerException in project opennms by OpenNMS.

the class ImportScheduler method removeCurrentJobsFromSchedule.

/**
 * Iterates of current job list and removes each job from the underlying schedule
 *
 * @throws org.quartz.SchedulerException if any.
 */
protected void removeCurrentJobsFromSchedule() throws SchedulerException {
    printCurrentSchedule();
    synchronized (m_lock) {
        for (JobKey key : m_scheduler.getJobKeys(GroupMatcher.<JobKey>groupEquals(JOB_GROUP))) {
            String jobName = key.getName();
            try {
                getScheduler().deleteJob(new JobKey(jobName, JOB_GROUP));
            } catch (SchedulerException e) {
                LOG.error("removeCurrentJobsFromSchedule: {}", e.getLocalizedMessage(), e);
            }
        }
    }
    printCurrentSchedule();
}
Also used : JobKey(org.quartz.JobKey) SchedulerException(org.quartz.SchedulerException)

Example 84 with SchedulerException

use of org.quartz.SchedulerException in project opennms by OpenNMS.

the class ReportJobFactory method newJob.

/**
 * {@inheritDoc}
 */
@Override
public Job newJob(TriggerFiredBundle bundle, Scheduler scheduler) throws SchedulerException {
    JobDetail jobDetail = bundle.getJobDetail();
    Class<ReportJob> jobClass = getJobClass(jobDetail);
    ReportJob job = null;
    try {
        job = jobClass.newInstance();
        job.setReportd(getReportd());
        return job;
    } catch (Throwable e) {
        SchedulerException se = new SchedulerException("failed to create job class: " + jobDetail.getJobClass().getName() + "; " + e.getLocalizedMessage(), e);
        throw se;
    }
}
Also used : JobDetail(org.quartz.JobDetail) SchedulerException(org.quartz.SchedulerException)

Example 85 with SchedulerException

use of org.quartz.SchedulerException in project opennms by OpenNMS.

the class DefaultSchedulerService method execute.

/*
     * (non-Javadoc)
     * @see
     * org.opennms.web.svclayer.support.SchedulerService#execute(org.opennms
     * .web.report.database.model.DatabaseReportCriteria, java.lang.String,
     * org.springframework.webflow.execution.RequestContext)
     */
/**
 * {@inheritDoc}
 */
@Override
public String execute(String id, ReportParameters criteria, DeliveryOptions deliveryOptions, RequestContext context) {
    try {
        if (m_reportWrapperService.validate(criteria, id) == false) {
            context.getMessageContext().addMessage(new MessageBuilder().error().defaultText(PARAMETER_ERROR).build());
            return ERROR;
        } else {
            SimpleTriggerImpl trigger = new SimpleTriggerImpl(deliveryOptions.getInstanceId(), m_triggerGroup, new Date(), null, 0, 0L);
            trigger.setJobName(m_jobDetail.getKey().getName());
            trigger.getJobDataMap().put("criteria", (ReportParameters) criteria);
            trigger.getJobDataMap().put("reportId", id);
            trigger.getJobDataMap().put("mode", ReportMode.IMMEDIATE);
            trigger.getJobDataMap().put("deliveryOptions", (DeliveryOptions) deliveryOptions);
            try {
                m_scheduler.scheduleJob(trigger);
            } catch (SchedulerException e) {
                LOG.warn(SCHEDULER_ERROR, e);
                context.getMessageContext().addMessage(new MessageBuilder().error().defaultText(SCHEDULER_ERROR).build());
                return ERROR;
            }
            return SUCCESS;
        }
    } catch (ReportServiceLocatorException e) {
        LOG.error(REPORTID_ERROR, e);
        context.getMessageContext().addMessage(new MessageBuilder().error().defaultText(REPORTID_ERROR).build());
        return ERROR;
    }
}
Also used : SimpleTriggerImpl(org.quartz.impl.triggers.SimpleTriggerImpl) SchedulerException(org.quartz.SchedulerException) MessageBuilder(org.springframework.binding.message.MessageBuilder) ReportServiceLocatorException(org.opennms.reporting.core.svclayer.ReportServiceLocatorException) Date(java.util.Date)

Aggregations

SchedulerException (org.quartz.SchedulerException)133 JobDetail (org.quartz.JobDetail)59 Trigger (org.quartz.Trigger)42 Scheduler (org.quartz.Scheduler)37 JobKey (org.quartz.JobKey)33 SimpleTrigger (org.quartz.SimpleTrigger)19 JobDataMap (org.quartz.JobDataMap)18 CronTrigger (org.quartz.CronTrigger)17 TriggerBuilder.newTrigger (org.quartz.TriggerBuilder.newTrigger)15 ApplicationContext (org.springframework.context.ApplicationContext)15 ArrayList (java.util.ArrayList)12 SchedulerContext (org.quartz.SchedulerContext)12 IOException (java.io.IOException)11 TriggerKey (org.quartz.TriggerKey)10 Date (java.util.Date)9 JobExecutionException (org.quartz.JobExecutionException)9 StdSchedulerFactory (org.quartz.impl.StdSchedulerFactory)6 ParseException (java.text.ParseException)5 Command (org.openhab.core.types.Command)5 JobSystemException (com.dangdang.ddframe.job.exception.JobSystemException)4