/** * <p> * Pause all of the <code>{@link Trigger}s</code> in the given group. * </p> * <p> * The JobStore should "remember" that the group is paused, and impose the pause on any new triggers that are added to * the group while the group is paused. * </p> */ @Override public Collection<String> pauseTriggers(GroupMatcher<TriggerKey> matcher) throws JobPersistenceException { HashSet<String> pausedGroups = new HashSet<String>(); lock(); try { Set<TriggerKey> triggerKeys = getTriggerKeys(matcher); for (TriggerKey key : triggerKeys) { triggerFacade.addPausedGroup(key.getGroup()); pausedGroups.add(key.getGroup()); pauseTrigger(key); } // make sure to account for an exact group match for a group that doesn't yet exist StringMatcher.StringOperatorName operator = matcher.getCompareWithOperator(); if (operator.equals(StringOperatorName.EQUALS)) { triggerFacade.addPausedGroup(matcher.getCompareToValue()); pausedGroups.add(matcher.getCompareToValue()); } } finally { unlock(); } return pausedGroups; }
/** * <p> * Pause all of the <code>{@link org.quartz.JobDetail}s</code> in the given group - by pausing all of their * <code>Trigger</code>s. * </p> * <p> * The JobStore should "remember" that the group is paused, and impose the pause on any new jobs that are added to the * group while the group is paused. * </p> */ @Override public Collection<String> pauseJobs(GroupMatcher<JobKey> matcher) throws JobPersistenceException { Collection<String> pausedGroups = new HashSet<String>(); lock(); try { Set<JobKey> jobKeys = getJobKeys(matcher); for (JobKey jobKey : jobKeys) { for (OperableTrigger trigger : getTriggersForJob(jobKey)) { pauseTrigger(trigger.getKey()); } pausedGroups.add(jobKey.getGroup()); } // make sure to account for an exact group match for a group that doesn't yet exist StringMatcher.StringOperatorName operator = matcher.getCompareWithOperator(); if (operator.equals(StringOperatorName.EQUALS)) { jobFacade.addPausedGroup(matcher.getCompareToValue()); pausedGroups.add(matcher.getCompareToValue()); } } finally { unlock(); } return pausedGroups; }
@Override public Set<JobKey> getJobKeys(GroupMatcher<JobKey> matcher) throws JobPersistenceException { if (matcher.getCompareWithOperator() != StringOperatorName.EQUALS) throw new UnsupportedOperationException(); Set<JobKey> jobKeys = new HashSet<>(); String jobGroupSetKey = createJobGroupSetKey(matcher.getCompareToValue()); try (Jedis jedis = pool.getResource()) { lockPool.acquire(); if(jedis.sismember(JOB_GROUPS_SET, jobGroupSetKey)) { Set<String> jobs = jedis.smembers(jobGroupSetKey); for(String job : jobs) jobKeys.add(new JobKey(job.split(":")[2], job.split(":")[1])); } } catch (Exception ex) { log.error("could not get job keys for job group: " + jobGroupSetKey, ex); throw new JobPersistenceException(ex.getMessage(), ex.getCause()); } finally { lockPool.release(); } return jobKeys; }
@Override public Set<TriggerKey> getTriggerKeys(GroupMatcher<TriggerKey> matcher) throws JobPersistenceException { if (matcher.getCompareWithOperator() != StringOperatorName.EQUALS) throw new UnsupportedOperationException(); Set<TriggerKey> triggerKeys = new HashSet<>(); String triggerGroupSetKey = createTriggerGroupSetKey(matcher.getCompareToValue()); try (Jedis jedis = pool.getResource()) { lockPool.acquire(); if(jedis.sismember(TRIGGER_GROUPS_SET, triggerGroupSetKey)) { Set<String> triggers = jedis.smembers(triggerGroupSetKey); for(String trigger : triggers) triggerKeys.add(new TriggerKey(trigger.split(":")[2], trigger.split(":")[1])); } } catch (Exception ex) { log.error("could not get trigger keys for trigger group: " + triggerGroupSetKey, ex); throw new JobPersistenceException(ex.getMessage(), ex.getCause()); } finally { lockPool.release(); } return triggerKeys; }
@Override public Collection<String> pauseTriggers(GroupMatcher<TriggerKey> matcher) throws JobPersistenceException { if (matcher.getCompareWithOperator() != StringOperatorName.EQUALS) throw new UnsupportedOperationException(); Set<String> pausedTriggerdGroups = new HashSet<>(); String triggerGroupSetKey = createTriggerGroupSetKey(matcher.getCompareToValue()); try (Jedis jedis = pool.getResource()) { lockPool.acquire(); if (pauseTriggers(triggerGroupSetKey, jedis)) pausedTriggerdGroups.add(triggerGroupSetKey); // as we currently support only EQUALS matcher's operator, the paused group set will consist of one paused group only. } catch (Exception ex) { log.error("could not pause triggers group: " + triggerGroupSetKey, ex); throw new JobPersistenceException(ex.getMessage(), ex.getCause()); } finally { lockPool.release(); } return pausedTriggerdGroups; }
@Override public Collection<String> pauseJobs(GroupMatcher<JobKey> groupMatcher) throws JobPersistenceException { if (groupMatcher.getCompareWithOperator() != StringOperatorName.EQUALS) throw new UnsupportedOperationException(); Set<String> pausedJobGroups = new HashSet<>(); String jobGroupSetKey = createJobGroupSetKey(groupMatcher.getCompareToValue()); try (Jedis jedis = pool.getResource()) { lockPool.acquire(); if (jedis.sadd(PAUSED_JOB_GROUPS_SET, jobGroupSetKey) > 0) { pausedJobGroups.add(jobGroupSetKey); Set<String> jobs = jedis.smembers(jobGroupSetKey); for (String job : jobs) pauseJob(job, jedis); } } catch (Exception ex) { log.error("could not pause job group: " + jobGroupSetKey, ex); throw new JobPersistenceException(ex.getMessage(), ex.getCause()); } finally { lockPool.release(); } return pausedJobGroups; }
/** * 查询所有定时任务 * * @param entity * @return Map * @throws SchedulerException */ @SuppressWarnings({ "rawtypes", "serial", "unchecked" }) @Override public Object selectByWhere(T entity) throws SchedulerException { List<String> groups = scheduler.getJobGroupNames(); List<HashMap<String, Object>> jobList = new ArrayList<HashMap<String, Object>>(); for (String group : groups) { if (null != entity.getGroup() && !group.contains(entity.getGroup())) { continue; } Set<JobKey> jobKeys = scheduler.getJobKeys(new GroupMatcher(group, StringOperatorName.EQUALS) { }); for (JobKey jobKey : jobKeys) { if (null != entity.getName() && !jobKey.toString().contains(entity.getName())) { continue; } JobDetail jobDetail = scheduler.getJobDetail(jobKey); HashMap<String, Object> jobInfoMap = new HashMap<String, Object>(); List<? extends Trigger> triggers = scheduler .getTriggersOfJob(jobKey); jobInfoMap.put("triggers", triggers); jobInfoMap.put("jobDetail", jobDetail); jobInfoMap.put("params", JSONArray.fromObject(jobDetail.getJobDataMap()) .toString()); jobInfoMap.put("type", "Kettle"); jobList.add(jobInfoMap); } } Map<String, Object> map = new HashMap<String, Object>(); map.put("jobList", jobList); map.put("scheduler", scheduler); return map; }
/** * <p> * Pause all of the <code>{@link org.quartz.Trigger}s</code> matching the * given groupMatcher. * </p> * * @see #resumeTriggerGroup(java.sql.Connection, org.quartz.impl.matchers.GroupMatcher) */ public Set<String> pauseTriggerGroup(Connection conn, GroupMatcher<TriggerKey> matcher) throws JobPersistenceException { try { getDelegate().updateTriggerGroupStateFromOtherStates( conn, matcher, STATE_PAUSED, STATE_ACQUIRED, STATE_WAITING, STATE_WAITING); getDelegate().updateTriggerGroupStateFromOtherState( conn, matcher, STATE_PAUSED_BLOCKED, STATE_BLOCKED); List<String> groups = getDelegate().selectTriggerGroups(conn, matcher); // make sure to account for an exact group match for a group that doesn't yet exist StringMatcher.StringOperatorName operator = matcher.getCompareWithOperator(); if (operator.equals(StringOperatorName.EQUALS) && !groups.contains(matcher.getCompareToValue())) { groups.add(matcher.getCompareToValue()); } for (String group : groups) { if (!getDelegate().isTriggerGroupPaused(conn, group)) { getDelegate().insertPausedTriggerGroup(conn, group); } } return new HashSet<String>(groups); } catch (SQLException e) { throw new JobPersistenceException("Couldn't pause trigger group '" + matcher + "': " + e.getMessage(), e); } }
@Override public Collection<String> resumeJobs(GroupMatcher<JobKey> matcher) throws JobPersistenceException { if (matcher.getCompareWithOperator() != StringOperatorName.EQUALS) throw new UnsupportedOperationException(); Set<String> resumedJobGroups = new HashSet<>(); String jobGroupSetKey = createJobGroupSetKey(matcher.getCompareToValue()); try (Jedis jedis = pool.getResource()) { lockPool.acquire(); if(!jedis.sismember(JOB_GROUPS_SET, jobGroupSetKey)) throw new JobPersistenceException("job group: " + jobGroupSetKey + " does not exist"); if (jedis.srem(PAUSED_JOB_GROUPS_SET, jobGroupSetKey) > 0) resumedJobGroups.add(jobGroupSetKey); Set<String> jobs = jedis.smembers(jobGroupSetKey); for (String job : jobs) resumeJob(new JobKey(job.split(":")[2], job.split(":")[1]), jedis); } catch (Exception ex) { log.error("could not resume job group: " + jobGroupSetKey, ex); throw new JobPersistenceException(ex.getMessage(), ex.getCause()); } finally { lockPool.release(); } return resumedJobGroups; }