Search in sources :

Example 66 with JobExecutionException

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

the class CamelJob method execute.

@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
    Exchange exchange = null;
    try {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Running CamelJob jobExecutionContext={}", context);
        }
        CamelContext camelContext = getCamelContext(context);
        QuartzEndpoint endpoint = lookupQuartzEndpoint(camelContext, context);
        exchange = endpoint.createExchange();
        exchange.setIn(new QuartzMessage(exchange, context));
        endpoint.getConsumerLoadBalancer().process(exchange);
        if (exchange.getException() != null) {
            throw new JobExecutionException(exchange.getException());
        }
    } catch (Exception e) {
        if (exchange != null) {
            LOG.error(CamelExchangeException.createExceptionMessage("Error processing exchange", exchange, e));
        } else {
            LOG.error("Failed to execute CamelJob.", 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) CamelContext(org.apache.camel.CamelContext) JobExecutionException(org.quartz.JobExecutionException) JobExecutionException(org.quartz.JobExecutionException) SchedulerException(org.quartz.SchedulerException) CamelExchangeException(org.apache.camel.CamelExchangeException)

Example 67 with JobExecutionException

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

the class CamelJob method getCamelContext.

protected CamelContext getCamelContext(JobExecutionContext context) throws JobExecutionException {
    SchedulerContext schedulerContext = getSchedulerContext(context);
    String camelContextName = context.getMergedJobDataMap().getString(QuartzConstants.QUARTZ_CAMEL_CONTEXT_NAME);
    CamelContext result = (CamelContext) schedulerContext.get(QuartzConstants.QUARTZ_CAMEL_CONTEXT + "-" + camelContextName);
    if (result == null) {
        throw new JobExecutionException("No CamelContext could be found with name: " + camelContextName);
    }
    return result;
}
Also used : CamelContext(org.apache.camel.CamelContext) JobExecutionException(org.quartz.JobExecutionException) SchedulerContext(org.quartz.SchedulerContext)

Example 68 with JobExecutionException

use of org.quartz.JobExecutionException in project ddf by codice.

the class CommandJob method doExecute.

public void doExecute(JobExecutionContext context) throws JobExecutionException {
    String commandInput;
    try {
        commandInput = checkInput(context);
    } catch (CommandException e) {
        LOGGER.debug("unable to get command from job execution context", e);
        return;
    }
    SessionFactory sessionFactory = getSessionFactory();
    if (sessionFactory == null) {
        LOGGER.debug("unable to create session factory: command=[{}]", commandInput);
        return;
    }
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    Session session = null;
    try (PrintStream output = getPrintStream(byteArrayOutputStream)) {
        session = sessionFactory.create(null, output, output);
        if (session == null) {
            LOGGER.debug("unable to create session: command=[{}]", commandInput);
            return;
        }
        if (commandInput != null) {
            try {
                LOGGER.trace("Executing command [{}]", commandInput);
                session.execute(commandInput);
                LOGGER.trace("Execution Output: {}", byteArrayOutputStream.toString(StandardCharsets.UTF_8.name()));
            } catch (CommandNotFoundException e) {
                LOGGER.info("Command could not be found. Make sure the command's library has been loaded and try again: {}", e.getLocalizedMessage());
                LOGGER.debug("Command not found.", e);
            } catch (Exception e) {
                LOGGER.info("Error with execution. ", e);
            }
        }
    } catch (UnsupportedEncodingException e) {
        LOGGER.info("Unable to produce output", e);
    } finally {
        if (session != null) {
            session.close();
        }
        try {
            byteArrayOutputStream.close();
        } catch (IOException e) {
            LOGGER.debug("Could not close output stream", e);
        }
    }
}
Also used : SessionFactory(org.apache.karaf.shell.api.console.SessionFactory) PrintStream(java.io.PrintStream) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) CommandNotFoundException(org.apache.felix.gogo.runtime.CommandNotFoundException) IOException(java.io.IOException) JobExecutionException(org.quartz.JobExecutionException) CommandNotFoundException(org.apache.felix.gogo.runtime.CommandNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Session(org.apache.karaf.shell.api.console.Session)

Example 69 with JobExecutionException

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

the class WeatherJob method execute.

/**
     * {@inheritDoc}
     */
@Override
public void execute(JobExecutionContext jobContext) throws JobExecutionException {
    JobDataMap jobDataMap = jobContext.getJobDetail().getJobDataMap();
    String locationId = jobDataMap.getString("locationId");
    logger.debug("Starting Weather job for location '{}'", locationId);
    try {
        LocationConfig locationConfig = context.getConfig().getLocationConfig(locationId);
        WeatherProvider weatherProvider = WeatherProviderFactory.createWeatherProvider(locationConfig.getProviderName());
        context.setWeather(locationId, weatherProvider.getWeather(locationConfig));
        weatherPublisher.publish(locationId);
    } catch (Exception ex) {
        logger.error(ex.getMessage(), ex);
        throw new JobExecutionException(ex.getMessage(), ex);
    }
}
Also used : JobDataMap(org.quartz.JobDataMap) JobExecutionException(org.quartz.JobExecutionException) WeatherProvider(org.openhab.binding.weather.internal.provider.WeatherProvider) LocationConfig(org.openhab.binding.weather.internal.common.LocationConfig) JobExecutionException(org.quartz.JobExecutionException)

Example 70 with JobExecutionException

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

the class ImportJob method execute.

/**
 * {@inheritDoc}
 */
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
    try {
        String url = context.getJobDetail().getJobDataMap().getString(URL);
        Assert.notNull(url);
        String rescanExisting = context.getJobDetail().getJobDataMap().getString(RESCAN_EXISTING);
        getProvisioner().doImport(url, rescanExisting == null ? Boolean.TRUE.toString() : rescanExisting);
    } catch (Throwable t) {
        throw new JobExecutionException(t);
    }
}
Also used : JobExecutionException(org.quartz.JobExecutionException)

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