use of org.quartz.TriggerKey in project spring-boot by spring-projects.
the class QuartzEndpoint method quartzTrigger.
/**
* Return the details of the trigger identified by the given group name and trigger
* name.
* @param groupName the name of the group
* @param triggerName the name of the trigger
* @return the details of the trigger or {@code null} if such trigger does not exist
* @throws SchedulerException if retrieving the information from the scheduler failed
*/
public Map<String, Object> quartzTrigger(String groupName, String triggerName) throws SchedulerException {
TriggerKey triggerKey = TriggerKey.triggerKey(triggerName, groupName);
Trigger trigger = this.scheduler.getTrigger(triggerKey);
return (trigger != null) ? TriggerDescription.of(trigger).buildDetails(this.scheduler.getTriggerState(triggerKey), sanitizeJobDataMap(trigger.getJobDataMap())) : null;
}
use of org.quartz.TriggerKey in project spring-boot by spring-projects.
the class QuartzEndpointTests method mockTriggers.
private void mockTriggers(Trigger... triggers) throws SchedulerException {
MultiValueMap<String, TriggerKey> triggerKeys = new LinkedMultiValueMap<>();
for (Trigger trigger : triggers) {
TriggerKey key = trigger.getKey();
given(this.scheduler.getTrigger(key)).willReturn(trigger);
triggerKeys.add(key.getGroup(), key);
}
given(this.scheduler.getTriggerGroupNames()).willReturn(new ArrayList<>(triggerKeys.keySet()));
for (Entry<String, List<TriggerKey>> entry : triggerKeys.entrySet()) {
given(this.scheduler.getTriggerKeys(GroupMatcher.triggerGroupEquals(entry.getKey()))).willReturn(new LinkedHashSet<>(entry.getValue()));
}
}
use of org.quartz.TriggerKey in project midpoint by Evolveum.
the class TaskSynchronizer method synchronizeTask.
/**
* Task should be refreshed when entering this method.
*
* @return true if task info in Quartz was updated
*/
public boolean synchronizeTask(TaskQuartzImpl task, OperationResult parentResult) {
if (!task.isPersistent()) {
// transient tasks are not scheduled via Quartz!
return false;
}
boolean changed = false;
StringBuilder message = new StringBuilder();
OperationResult result = parentResult.createSubresult(OP_SYNCHRONIZE_TASK);
result.addArbitraryObjectAsParam("task", task);
try {
taskMigrator.migrateIfNeeded(task, result);
LOGGER.trace("Synchronizing task {}; isRecreateQuartzTrigger = {}", task, task.isRecreateQuartzTrigger());
Scheduler scheduler = localScheduler.getQuartzScheduler();
String oid = task.getOid();
JobKey jobKey = QuartzUtil.createJobKeyForTask(task);
TriggerKey standardTriggerKey = QuartzUtil.createTriggerKeyForTask(task);
TaskSchedulingStateType schedulingState = task.getSchedulingState();
boolean waitingOrClosedOrSuspended = schedulingState == TaskSchedulingStateType.WAITING || schedulingState == TaskSchedulingStateType.CLOSED || schedulingState == TaskSchedulingStateType.SUSPENDED;
if (!scheduler.checkExists(jobKey) && !waitingOrClosedOrSuspended) {
String m1 = "Quartz job does not exist for a task, adding it. Task = " + task;
message.append("[").append(m1).append("] ");
LOGGER.trace(" - {}", m1);
scheduler.addJob(QuartzUtil.createJobDetailForTask(task), false);
changed = true;
}
// CLOSED tasks should have no triggers; SUSPENDED and WAITING tasks should have no extra triggers
List<? extends Trigger> triggers = scheduler.getTriggersOfJob(jobKey);
boolean standardTriggerExists = triggers.stream().anyMatch(t -> t.getKey().equals(standardTriggerKey));
if (waitingOrClosedOrSuspended) {
for (Trigger trigger : triggers) {
if (schedulingState == TaskSchedulingStateType.CLOSED || !trigger.getKey().equals(standardTriggerKey)) {
String m1 = "Removing Quartz trigger " + trigger.getKey() + " for WAITING/CLOSED/SUSPENDED task " + task;
message.append("[").append(m1).append("] ");
LOGGER.trace(" - {}", m1);
scheduler.unscheduleJob(trigger.getKey());
changed = true;
} else {
// For SUSPENDED/WAITING tasks, we keep the standard trigger untouched. We want to preserve original
// scheduled time. (This might or might not be what the user wants ... but it has been so for so
// many years, so let's not change it now.)
//
// It's harmless to keep the standard trigger, because:
// 1) If a trigger is mistakenly alive, JobExecutor will take care of it.
// 2) If a trigger has wrong parameters, this will be corrected on task resume/unpause.
}
}
} else if (schedulingState == TaskSchedulingStateType.READY) {
Trigger triggerToBe;
try {
triggerToBe = QuartzUtil.createTriggerForTask(task);
} catch (ParseException e) {
String message2 = "Cannot create a trigger for a task " + this + " because of a cron expression parsing exception";
LoggingUtils.logUnexpectedException(LOGGER, message2, e);
result.recordFatalError(message2, e);
// TODO: implement error handling correctly
throw new SystemException("Cannot a trigger for a task because of a cron expression parsing exception", e);
}
if (triggerToBe == null) {
if (standardTriggerExists) {
// TODO what about non-standard triggers?
// These may be legal here (e.g. for a manually-run recurring task waiting to get a chance to run)
String m1 = "Removing standard Quartz trigger for RUNNABLE task that should not have it; task = " + task;
message.append("[").append(m1).append("] ");
LOGGER.trace(" - " + m1);
scheduler.unscheduleJob(TriggerKey.triggerKey(oid));
changed = true;
}
} else {
// if the trigger should exist and it does not...
if (!standardTriggerExists) {
String m1 = "Creating standard trigger for a RUNNABLE task " + task;
LOGGER.trace(" - " + m1);
message.append("[").append(m1).append("] ");
scheduler.scheduleJob(triggerToBe);
changed = true;
} else {
// we have to compare trigger parameters with the task's ones
Trigger triggerAsIs = scheduler.getTrigger(standardTriggerKey);
if (task.isRecreateQuartzTrigger() || QuartzUtil.triggersDiffer(triggerAsIs, triggerToBe)) {
String m1 = "Existing trigger has incompatible parameters or was explicitly requested to be recreated; recreating it. Task = " + task;
LOGGER.trace(" - " + m1);
message.append("[").append(m1).append("] ");
scheduler.rescheduleJob(standardTriggerKey, triggerToBe);
changed = true;
} else {
String m1 = "Existing trigger is OK, leaving it as is; task = " + task;
LOGGER.trace(" - " + m1);
message.append("[").append(m1).append("] ");
Trigger.TriggerState state = scheduler.getTriggerState(standardTriggerKey);
if (state == Trigger.TriggerState.PAUSED) {
String m2 = "However, the trigger is paused, resuming it; task = " + task;
LOGGER.trace(" - " + m2);
message.append("[").append(m2).append("] ");
scheduler.resumeTrigger(standardTriggerKey);
changed = true;
}
}
}
}
}
} catch (Exception e) {
String message2 = "Cannot synchronize repository/Quartz Job Store information for task " + task;
LoggingUtils.logUnexpectedException(LOGGER, message2, e);
result.recordFatalError(message2, e);
} finally {
if (result.isUnknown()) {
result.computeStatus();
result.recordStatus(result.getStatus(), message.toString());
}
}
LOGGER.trace("synchronizeTask finishing (changed: {}) for {}", changed, task);
return changed;
}
use of org.quartz.TriggerKey in project cachecloud by sohutv.
the class RedisCenterImpl method deployRedisCollection.
@Override
public boolean deployRedisCollection(long appId, String host, int port) {
Assert.isTrue(appId > 0);
Assert.hasText(host);
Assert.isTrue(port > 0);
Map<String, Object> dataMap = new HashMap<String, Object>();
dataMap.put(ConstUtils.HOST_KEY, host);
dataMap.put(ConstUtils.PORT_KEY, port);
dataMap.put(ConstUtils.APP_KEY, appId);
JobKey jobKey = JobKey.jobKey(ConstUtils.REDIS_JOB_NAME, ConstUtils.REDIS_JOB_GROUP);
TriggerKey triggerKey = TriggerKey.triggerKey(ObjectConvert.linkIpAndPort(host, port), ConstUtils.REDIS_TRIGGER_GROUP + appId);
return schedulerCenter.deployJobByCron(jobKey, triggerKey, dataMap, ScheduleUtil.getMinuteCronByAppId(appId), false);
}
use of org.quartz.TriggerKey in project cachecloud by sohutv.
the class RedisCenterImpl method deployRedisSlowLogCollection.
@Override
public boolean deployRedisSlowLogCollection(long appId, String host, int port) {
Assert.isTrue(appId > 0);
Assert.hasText(host);
Assert.isTrue(port > 0);
Map<String, Object> dataMap = new HashMap<String, Object>();
dataMap.put(ConstUtils.HOST_KEY, host);
dataMap.put(ConstUtils.PORT_KEY, port);
dataMap.put(ConstUtils.APP_KEY, appId);
JobKey jobKey = JobKey.jobKey(ConstUtils.REDIS_SLOWLOG_JOB_NAME, ConstUtils.REDIS_SLOWLOG_JOB_GROUP);
TriggerKey triggerKey = TriggerKey.triggerKey(ObjectConvert.linkIpAndPort(host, port), ConstUtils.REDIS_SLOWLOG_TRIGGER_GROUP + appId);
boolean result = schedulerCenter.deployJobByCron(jobKey, triggerKey, dataMap, ScheduleUtil.getRedisSlowLogCron(appId), false);
return result;
}
Aggregations