use of org.quartz.JobKey in project cachecloud by sohutv.
the class MachineCenterImpl method deployMachineMonitor.
/**
* 为监控每台机器的状态部署trigger
*
* @param hostId 机器id
* @param ip ip
* @return 是否部署成功
*/
@Override
public boolean deployMachineMonitor(final long hostId, final String ip) {
Assert.isTrue(hostId > 0);
Assert.hasText(ip);
Map<String, Object> dataMap = new HashMap<String, Object>();
dataMap.put(ConstUtils.HOST_KEY, ip);
dataMap.put(ConstUtils.HOST_ID_KEY, hostId);
JobKey jobKey = JobKey.jobKey(ConstUtils.MACHINE_MONITOR_JOB_NAME, ConstUtils.MACHINE_MONITOR_JOB_GROUP);
TriggerKey triggerKey = TriggerKey.triggerKey(ip, ConstUtils.MACHINE_MONITOR_TRIGGER_GROUP + hostId);
boolean result = schedulerCenter.deployJobByCron(jobKey, triggerKey, dataMap, ScheduleUtil.getHourCronByHostId(hostId), false);
return result;
}
use of org.quartz.JobKey in project OpenClinica by OpenClinica.
the class CoreSecureController method pingJobServer.
private void pingJobServer(HttpServletRequest request) {
String jobName = (String) request.getSession().getAttribute("jobName");
String groupName = (String) request.getSession().getAttribute("groupName");
Integer datasetId = (Integer) request.getSession().getAttribute("datasetId");
try {
if (jobName != null && groupName != null) {
LOGGER.debug("trying to retrieve status on " + jobName + " " + groupName);
Trigger.TriggerState triggerState = getScheduler(request).getTriggerState(new TriggerKey(jobName, groupName));
LOGGER.debug("found state: " + triggerState);
org.quartz.JobDetail details = getScheduler(request).getJobDetail(new JobKey(jobName, groupName));
List contexts = getScheduler(request).getCurrentlyExecutingJobs();
org.quartz.JobDataMap dataMap = details.getJobDataMap();
String failMessage = dataMap.getString("failMessage");
if (triggerState == Trigger.TriggerState.NONE) {
// TODO i18n
if (failMessage != null) {
// The extract data job failed with the message:
// ERROR: relation "demographics" already exists
// More information may be available in the log files.
addPageMessage("The extract data job failed with the message: <br/><br/>" + failMessage + "<br/><br/>More information may be available in the log files.", request);
} else {
String successMsg = dataMap.getString("SUCCESS_MESSAGE");
if (successMsg != null) {
if (successMsg.contains("$linkURL")) {
successMsg = decodeLINKURL(successMsg, datasetId);
}
addPageMessage("Your Extract is now completed. Please go to review them at <a href='ViewDatasets'>View Datasets</a> or <a href='ExportDataset?datasetId=" + datasetId + "'>View Specific Dataset</a>." + successMsg, request);
} else {
addPageMessage("Your Extract is now completed. Please go to review them at <a href='ViewDatasets'>View Datasets</a> or <a href='ExportDataset?datasetId=" + datasetId + "'>View Specific Dataset</a>.", request);
}
}
request.getSession().removeAttribute("jobName");
request.getSession().removeAttribute("groupName");
request.getSession().removeAttribute("datasetId");
} else {
}
}
} catch (SchedulerException se) {
se.printStackTrace();
}
}
use of org.quartz.JobKey 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;
}
use of org.quartz.JobKey in project camel by apache.
the class ScheduledRoutePolicy method deleteRouteJob.
public void deleteRouteJob(Action action, ScheduledRouteDetails scheduledRouteDetails) throws SchedulerException {
JobKey jobKey = retrieveJobKey(action, scheduledRouteDetails);
if (!getScheduler().isShutdown()) {
getScheduler().deleteJob(jobKey);
}
LOG.debug("Scheduled job: {} is deleted", jobKey);
}
use of org.quartz.JobKey in project camel by apache.
the class QuartzManuallyTriggerJobTest method testQuartzCronRoute.
@Test
public void testQuartzCronRoute() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMinimumMessageCount(1);
QuartzComponent component = context.getComponent("quartz2", QuartzComponent.class);
Scheduler scheduler = component.getScheduler();
// collect all jobKeys of this route (ideally only one).
ArrayList<JobKey> jobKeys = new ArrayList<JobKey>();
for (String group : scheduler.getJobGroupNames()) {
for (JobKey jobKey : scheduler.getJobKeys(GroupMatcher.jobGroupEquals(group))) {
jobKeys.add(jobKey);
}
}
JobDataMap jobDataMap = scheduler.getJobDetail(jobKeys.get(0)).getJobDataMap();
// trigger job manually
scheduler.triggerJob(jobKeys.get(0), jobDataMap);
assertMockEndpointsSatisfied();
}
Aggregations