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());
}
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() });
}
}
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));
}
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));
}
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;
}
Aggregations