Search in sources :

Example 61 with JobExecutionException

use of org.quartz.JobExecutionException in project openhab1-addons by openhab.

the class EventJob method execute.

@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
    try {
        final String config = context.getJobDetail().getJobDataMap().getString(KEY_CONFIG);
        final String eventId = context.getJobDetail().getJobDataMap().getString(KEY_EVENT);
        final int recIndex = context.getJobDetail().getJobDataMap().getInt(KEY_REC_INDEX);
        final EventTrigger eventTrigger = EventTrigger.valueOf(context.getJobDetail().getJobDataMap().getString(KEY_EVENT_TRIGGER));
        CalendarRuntime calendarRuntime = EventStorage.getInstance().getEventCache().get(config);
        if (calendarRuntime == null) {
            throw new JobExecutionException("cannot get runtime for config: " + config, false);
        }
        EventContainer eventContainer = calendarRuntime.getEventMap().get(eventId);
        if (eventContainer == null) {
            throw new JobExecutionException("cannot get event-container for config: " + config + " and eventId: " + eventId, false);
        }
        if (eventContainer.getEventList().size() <= recIndex) {
            throw new JobExecutionException("cannot get recurence-event for config: " + config + " and eventId: " + eventId + " and occurence: " + recIndex, false);
        }
        CalDavEvent event = eventContainer.getEventList().get(recIndex);
        log.info("event {} for: {}", eventTrigger, event.getShortName());
        for (EventNotifier notifier : CalDavLoaderImpl.instance.getEventListenerList()) {
            try {
                if (eventTrigger == EventTrigger.BEGIN) {
                    notifier.eventBegins(event);
                } else if (eventTrigger == EventTrigger.END) {
                    notifier.eventEnds(event);
                } else {
                    throw new IllegalStateException("not implemented event trigger: " + eventTrigger);
                }
            } catch (Exception e) {
                log.error("error while invoking listener", e);
            }
        }
        if (eventTrigger == EventTrigger.END) {
            // if event is ended, remove it from the map
            calendarRuntime.getEventMap().remove(eventContainer.getEventId());
        }
    } catch (Exception e) {
        log.error("error executing event job", e);
        throw new JobExecutionException("error executing event job", e, false);
    }
}
Also used : JobExecutionException(org.quartz.JobExecutionException) EventContainer(org.openhab.io.caldav.internal.EventStorage.EventContainer) CalDavEvent(org.openhab.io.caldav.CalDavEvent) EventNotifier(org.openhab.io.caldav.EventNotifier) CalendarRuntime(org.openhab.io.caldav.internal.EventStorage.CalendarRuntime) JobExecutionException(org.quartz.JobExecutionException)

Example 62 with JobExecutionException

use of org.quartz.JobExecutionException in project openhab1-addons by openhab.

the class ChangeStateJob method execute.

/*
     * (non-Javadoc)
     *
     * @see org.quartz.Job#execute(org.quartz.JobExecutionContext)
     */
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
    String content = (String) context.getJobDetail().getJobDataMap().get(JOB_DATA_CONTENT_KEY);
    if (StringUtils.isNotBlank(content)) {
        String deviceId = content.split(";")[0];
        String state = content.split(";")[1];
        boolean setToOn = state == "on";
        logger.debug("About to execute ChangeStateJob with arguments {} {}", deviceId, state);
        try {
            MystromClient.ChangeState(deviceId, setToOn);
        } catch (Exception e) {
            throw new JobExecutionException("Executing command '" + deviceId + " " + state + "' throws an Exception. Job will be refired immediately.", e, true);
        }
    }
}
Also used : JobExecutionException(org.quartz.JobExecutionException) JobExecutionException(org.quartz.JobExecutionException)

Example 63 with JobExecutionException

use of org.quartz.JobExecutionException in project camel by apache.

the class CamelJob method execute.

public void execute(JobExecutionContext context) throws JobExecutionException {
    String camelContextName = (String) context.getJobDetail().getJobDataMap().get(QuartzConstants.QUARTZ_CAMEL_CONTEXT_NAME);
    String endpointUri = (String) context.getJobDetail().getJobDataMap().get(QuartzConstants.QUARTZ_ENDPOINT_URI);
    SchedulerContext schedulerContext;
    try {
        schedulerContext = context.getScheduler().getContext();
    } catch (SchedulerException e) {
        throw new JobExecutionException("Failed to obtain scheduler context for job " + context.getJobDetail().getName());
    }
    CamelContext camelContext = (CamelContext) schedulerContext.get(QuartzConstants.QUARTZ_CAMEL_CONTEXT + "-" + camelContextName);
    if (camelContext == null) {
        throw new JobExecutionException("No CamelContext could be found with name: " + camelContextName);
    }
    Trigger trigger = context.getTrigger();
    QuartzEndpoint endpoint = lookupQuartzEndpoint(camelContext, endpointUri, trigger);
    if (endpoint == null) {
        throw new JobExecutionException("No QuartzEndpoint could be found with endpointUri: " + endpointUri);
    }
    endpoint.onJobExecute(context);
}
Also used : CamelContext(org.apache.camel.CamelContext) SchedulerException(org.quartz.SchedulerException) JobExecutionException(org.quartz.JobExecutionException) Trigger(org.quartz.Trigger) SchedulerContext(org.quartz.SchedulerContext)

Example 64 with JobExecutionException

use of org.quartz.JobExecutionException in project camel by apache.

the class QuartzEndpoint method onJobExecute.

/**
     * This method is invoked when a Quartz job is fired.
     *
     * @param jobExecutionContext the Quartz Job context
     */
public void onJobExecute(final JobExecutionContext jobExecutionContext) throws JobExecutionException {
    boolean run = true;
    LoadBalancer balancer = getLoadBalancer();
    if (balancer instanceof ServiceSupport) {
        run = ((ServiceSupport) balancer).isRunAllowed();
    }
    if (!run) {
        // quartz scheduler could potential trigger during a route has been shutdown
        LOG.warn("Cannot execute Quartz Job with context: " + jobExecutionContext + " because processor is not started: " + balancer);
        return;
    }
    LOG.debug("Firing Quartz Job with context: {}", jobExecutionContext);
    Exchange exchange = createExchange(jobExecutionContext);
    try {
        balancer.process(exchange);
        if (exchange.getException() != null) {
            // propagate the exception back to Quartz
            throw new JobExecutionException(exchange.getException());
        }
    } catch (Exception e) {
        // log the error
        LOG.error(CamelExchangeException.createExceptionMessage("Error processing exchange", exchange, e));
        // and rethrow to let quartz handle it
        if (e instanceof JobExecutionException) {
            throw (JobExecutionException) e;
        }
        throw new JobExecutionException(e);
    }
}
Also used : Exchange(org.apache.camel.Exchange) ServiceSupport(org.apache.camel.support.ServiceSupport) JobExecutionException(org.quartz.JobExecutionException) LoadBalancer(org.apache.camel.processor.loadbalancer.LoadBalancer) RoundRobinLoadBalancer(org.apache.camel.processor.loadbalancer.RoundRobinLoadBalancer) JobExecutionException(org.quartz.JobExecutionException) SchedulerException(org.quartz.SchedulerException) CamelExchangeException(org.apache.camel.CamelExchangeException)

Example 65 with JobExecutionException

use of org.quartz.JobExecutionException in project camel by apache.

the class CamelJob method lookupQuartzEndpoint.

protected QuartzEndpoint lookupQuartzEndpoint(CamelContext camelContext, JobExecutionContext quartzContext) throws JobExecutionException {
    TriggerKey triggerKey = quartzContext.getTrigger().getKey();
    JobDetail jobDetail = quartzContext.getJobDetail();
    JobKey jobKey = jobDetail.getKey();
    if (LOG.isDebugEnabled()) {
        LOG.debug("Looking up existing QuartzEndpoint with triggerKey={}", triggerKey);
    }
    // as we prefer to use the existing endpoint from the routes
    for (Route route : camelContext.getRoutes()) {
        Endpoint endpoint = route.getEndpoint();
        if (endpoint instanceof DelegateEndpoint) {
            endpoint = ((DelegateEndpoint) endpoint).getEndpoint();
        }
        if (endpoint instanceof QuartzEndpoint) {
            QuartzEndpoint quartzEndpoint = (QuartzEndpoint) endpoint;
            TriggerKey checkTriggerKey = quartzEndpoint.getTriggerKey();
            if (LOG.isTraceEnabled()) {
                LOG.trace("Checking route endpoint={} with checkTriggerKey={}", quartzEndpoint, checkTriggerKey);
            }
            if (triggerKey.equals(checkTriggerKey) || (jobDetail.requestsRecovery() && jobKey.getGroup().equals(checkTriggerKey.getGroup()) && jobKey.getName().equals(checkTriggerKey.getName()))) {
                return quartzEndpoint;
            }
        }
    }
    // fallback and lookup existing from registry (eg maybe a @Consume POJO with a quartz endpoint, and thus not from a route)
    String endpointUri = quartzContext.getMergedJobDataMap().getString(QuartzConstants.QUARTZ_ENDPOINT_URI);
    QuartzEndpoint result = null;
    // Even though the same camelContext.getEndpoint call, but if/else display different log.
    if (camelContext.hasEndpoint(endpointUri) != null) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Getting Endpoint from camelContext.");
        }
        result = camelContext.getEndpoint(endpointUri, QuartzEndpoint.class);
    } else if ((result = searchForEndpointMatch(camelContext, endpointUri)) != null) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Found match for endpoint URI = " + endpointUri + " by searching endpoint list.");
        }
    } else {
        LOG.warn("Cannot find existing QuartzEndpoint with uri: {}. Creating new endpoint instance.", endpointUri);
        result = camelContext.getEndpoint(endpointUri, QuartzEndpoint.class);
    }
    if (result == null) {
        throw new JobExecutionException("No QuartzEndpoint could be found with endpointUri: " + endpointUri);
    }
    return result;
}
Also used : TriggerKey(org.quartz.TriggerKey) JobDetail(org.quartz.JobDetail) JobKey(org.quartz.JobKey) JobExecutionException(org.quartz.JobExecutionException) Endpoint(org.apache.camel.Endpoint) DelegateEndpoint(org.apache.camel.DelegateEndpoint) DelegateEndpoint(org.apache.camel.DelegateEndpoint) Route(org.apache.camel.Route)

Aggregations

JobExecutionException (org.quartz.JobExecutionException)123 JobDataMap (org.quartz.JobDataMap)35 ArrayList (java.util.ArrayList)18 Date (java.util.Date)16 IgnoreProvisionException (org.apache.syncope.core.provisioning.api.pushpull.IgnoreProvisionException)16 SchedulerException (org.quartz.SchedulerException)16 HashMap (java.util.HashMap)15 ProvisioningReport (org.apache.syncope.core.provisioning.api.pushpull.ProvisioningReport)15 Test (org.junit.Test)13 Result (org.apache.syncope.common.lib.types.AuditElements.Result)12 JobDetail (org.quartz.JobDetail)12 PullActions (org.apache.syncope.core.provisioning.api.pushpull.PullActions)11 SQLException (java.sql.SQLException)10 PropagationException (org.apache.syncope.core.provisioning.api.propagation.PropagationException)10 DelegatedAdministrationException (org.apache.syncope.core.spring.security.DelegatedAdministrationException)10 Map (java.util.Map)9 JobExecutionContext (org.quartz.JobExecutionContext)9 List (java.util.List)8 IOException (java.io.IOException)7 Realm (org.apache.syncope.core.persistence.api.entity.Realm)7