Search in sources :

Example 51 with JobKey

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;
}
Also used : TriggerKey(org.quartz.TriggerKey) JobKey(org.quartz.JobKey) HashMap(java.util.HashMap)

Example 52 with JobKey

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();
    }
}
Also used : TriggerKey(org.quartz.TriggerKey) JobKey(org.quartz.JobKey) Trigger(org.quartz.Trigger) SchedulerException(org.quartz.SchedulerException) List(java.util.List) ArrayList(java.util.ArrayList)

Example 53 with JobKey

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

Example 54 with JobKey

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);
}
Also used : JobKey(org.quartz.JobKey)

Example 55 with 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();
}
Also used : JobKey(org.quartz.JobKey) JobDataMap(org.quartz.JobDataMap) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Scheduler(org.quartz.Scheduler) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

JobKey (org.quartz.JobKey)66 SchedulerException (org.quartz.SchedulerException)33 JobDetail (org.quartz.JobDetail)22 Trigger (org.quartz.Trigger)19 Scheduler (org.quartz.Scheduler)17 TriggerKey (org.quartz.TriggerKey)15 Test (org.junit.Test)13 ArrayList (java.util.ArrayList)6 List (java.util.List)6 CronTrigger (org.quartz.CronTrigger)6 JobDataMap (org.quartz.JobDataMap)6 TriggerBuilder.newTrigger (org.quartz.TriggerBuilder.newTrigger)5 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)4 Date (java.util.Date)4 HashMap (java.util.HashMap)4 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)2 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)2 Hashtable (java.util.Hashtable)2 Scheduled (org.apache.deltaspike.scheduler.api.Scheduled)2 CronScheduleBuilder (org.quartz.CronScheduleBuilder)2