Search in sources :

Example 86 with JobDetail

use of org.quartz.JobDetail in project series-rest-api by 52North.

the class PreRenderingJob method execute.

@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
    if (interrupted) {
        return;
    }
    LOGGER.info("Start prerendering task");
    final Stopwatch stopwatch = Stopwatch.startStopwatch();
    final JobDetail details = context.getJobDetail();
    JobDataMap jobDataMap = details.getJobDataMap();
    taskConfigPrerendering = readJobConfig(jobDataMap.getString(JOB_DATA_CONFIG_FILE));
    webappFolder = jobDataMap.getString(JOB_DATA_WEBAPP_FOLDER);
    List<RenderingConfig> phenomenonStyles = taskConfigPrerendering.getPhenomenonStyles();
    List<RenderingConfig> styles = taskConfigPrerendering.getSeriesStyles();
    for (RenderingConfig config : phenomenonStyles) {
        Map<String, String> parameters = new HashMap<>();
        parameters.put("phenomenon", config.getId());
        IoParameters query = QueryParameters.createFromQuery(parameters);
        for (DatasetOutput<?, ?> metadata : datasetService.getCondensedParameters(query)) {
            String timeseriesId = metadata.getId();
            renderConfiguredIntervals(timeseriesId, config);
            if (interrupted) {
                return;
            }
        }
    }
    for (RenderingConfig config : styles) {
        renderConfiguredIntervals(config.getId(), config);
        if (interrupted) {
            return;
        }
    }
    LOGGER.debug("prerendering took '{}'", stopwatch.stopInSeconds());
}
Also used : JobDetail(org.quartz.JobDetail) JobDataMap(org.quartz.JobDataMap) HashMap(java.util.HashMap) Stopwatch(org.n52.web.common.Stopwatch) IoParameters(org.n52.io.request.IoParameters) RenderingConfig(org.n52.io.PrerenderingJobConfig.RenderingConfig)

Example 87 with JobDetail

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

the class ScheduledRoutePolicy method scheduleRoute.

public void scheduleRoute(Action action, Route route) throws Exception {
    JobDetail jobDetail = createJobDetail(action, route);
    Trigger trigger = createTrigger(action, route);
    updateScheduledRouteDetails(action, jobDetail, trigger, route);
    loadCallbackDataIntoSchedulerContext(jobDetail, action, route);
    boolean isClustered = route.getRouteContext().getCamelContext().getComponent("quartz", QuartzComponent.class).isClustered();
    if (isClustered) {
        // check to see if the same job has already been setup through another node of the cluster
        JobDetail existingJobDetail = getScheduler().getJobDetail(jobDetail.getName(), jobDetail.getGroup());
        if (jobDetail.equals(existingJobDetail)) {
            if (LOG.isInfoEnabled()) {
                LOG.info("Skipping to schedule the job: {} for action: {} on route {} as the job: {} already existing inside the cluster", new Object[] { jobDetail.getFullName(), action, route.getId(), existingJobDetail.getFullName() });
            }
            // skip scheduling the same job again as one is already existing for the same routeId and action
            return;
        }
    }
    getScheduler().scheduleJob(jobDetail, trigger);
    if (LOG.isInfoEnabled()) {
        LOG.info("Scheduled trigger: {} for action: {} on route {}", new Object[] { trigger.getFullName(), action, route.getId() });
    }
}
Also used : JobDetail(org.quartz.JobDetail) Trigger(org.quartz.Trigger) QuartzComponent(org.apache.camel.component.quartz.QuartzComponent)

Example 88 with JobDetail

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

the class DelegateEndpointQuartzTest method testQuartzCronRoute.

@Test
public void testQuartzCronRoute() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMinimumMessageCount(3);
    assertMockEndpointsSatisfied();
    JobDetail job = mock.getReceivedExchanges().get(0).getIn().getHeader("jobDetail", JobDetail.class);
    assertNotNull(job);
    assertEquals("cron", job.getJobDataMap().get(QuartzConstants.QUARTZ_TRIGGER_TYPE));
    assertEquals("0/2 * * * * ?", job.getJobDataMap().get(QuartzConstants.QUARTZ_TRIGGER_CRON_EXPRESSION));
}
Also used : JobDetail(org.quartz.JobDetail) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Example 89 with JobDetail

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

the class QuartzCronRouteTest method testQuartzCronRoute.

@Test
public void testQuartzCronRoute() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMinimumMessageCount(3);
    assertMockEndpointsSatisfied();
    JobDetail job = mock.getReceivedExchanges().get(0).getIn().getHeader("jobDetail", JobDetail.class);
    assertNotNull(job);
    assertEquals("cron", job.getJobDataMap().get(QuartzConstants.QUARTZ_TRIGGER_TYPE));
    assertEquals("0/2 * * * * ?", job.getJobDataMap().get(QuartzConstants.QUARTZ_TRIGGER_CRON_EXPRESSION));
}
Also used : JobDetail(org.quartz.JobDetail) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Example 90 with JobDetail

use of org.quartz.JobDetail 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

JobDetail (org.quartz.JobDetail)131 SchedulerException (org.quartz.SchedulerException)59 Trigger (org.quartz.Trigger)51 Scheduler (org.quartz.Scheduler)34 Test (org.junit.Test)30 CronTrigger (org.quartz.CronTrigger)26 JobKey (org.quartz.JobKey)22 SimpleTrigger (org.quartz.SimpleTrigger)22 JobDataMap (org.quartz.JobDataMap)20 TriggerBuilder.newTrigger (org.quartz.TriggerBuilder.newTrigger)15 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)11 TriggerKey (org.quartz.TriggerKey)10 HashMap (java.util.HashMap)8 Date (java.util.Date)7 ArrayList (java.util.ArrayList)5 Command (org.openhab.core.types.Command)5 IOException (java.io.IOException)4 Serializable (java.io.Serializable)4 InetSocketAddress (java.net.InetSocketAddress)4 SocketChannel (java.nio.channels.SocketChannel)4