org.quartz.impl.matchers.GroupMatcher Java Examples

The following examples show how to use org.quartz.impl.matchers.GroupMatcher. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ScheduledJobListController.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
    * Get all waitting queue jobs scheduled in Quartz table and display job name, job start time and description. The
    * description will be in format "Lesson Name":"the lesson creator", or "The gate name":"The relatived lesson name".
    */
   @RequestMapping(path = "/joblist", method = RequestMethod.POST)
   public String execute(HttpServletRequest request) throws Exception {
ArrayList<ScheduledJobDTO> jobList = new ArrayList<>();
try {
    Set<JobKey> jobKeys = scheduler.getJobKeys(GroupMatcher.jobGroupEquals(Scheduler.DEFAULT_GROUP));
    for (JobKey jobKey : jobKeys) {
	ScheduledJobDTO jobDto = new ScheduledJobDTO();
	JobDetail detail = scheduler.getJobDetail(jobKey);
	jobDto.setName(jobKey.getName());
	jobDto.setDescription(detail.getDescription());
	List<Trigger> triggers = (List<Trigger>) scheduler.getTriggersOfJob(jobKey);
	for (Trigger trigger : triggers) {
	    jobDto.setStartDate(trigger.getStartTime());
	    jobList.add(jobDto);
	}
    }
} catch (SchedulerException e) {
    ScheduledJobListController.log.equals("Failed get job names:" + e.getMessage());
}

request.setAttribute("jobList", jobList);
return "joblist";
   }
 
Example #2
Source File: StoreJobTest.java    From quartz-redis-jobstore with Apache License 2.0 6 votes vote down vote up
@Test
public void resumeJobsEndsWith() throws Exception {
    Map<JobDetail, Set<? extends Trigger>> jobsAndTriggers = getJobsAndTriggers(2, 2, 2, 2);
    jobStore.storeJobsAndTriggers(jobsAndTriggers, false);

    // pause one of the job groups
    String pausedGroupName = new ArrayList<>(jobsAndTriggers.keySet()).get(0).getKey().getGroup();
    String substring = pausedGroupName.substring(pausedGroupName.length() - 1, pausedGroupName.length());
    Collection<String> pausedGroups = jobStore.pauseJobs(GroupMatcher.jobGroupEndsWith(substring));

    assertThat(pausedGroups, hasSize(1));
    assertThat(pausedGroups, containsInAnyOrder(pausedGroupName));

    // resume the paused jobs
    Collection<String> resumedGroups = jobStore.resumeJobs(GroupMatcher.jobGroupEndsWith(substring));

    assertThat(resumedGroups, hasSize(1));
    assertThat(resumedGroups, containsInAnyOrder(pausedGroupName));

    for (Trigger trigger : new ArrayList<>(jobsAndTriggers.entrySet()).get(0).getValue()) {
        assertEquals(Trigger.TriggerState.NORMAL, jobStore.getTriggerState(trigger.getKey()));
    }
}
 
Example #3
Source File: QuartzQueueAction.java    From rice with Educational Community License v2.0 6 votes vote down vote up
@Override
public ActionMessages establishRequiredState(HttpServletRequest request, ActionForm form) throws Exception {
    if ("moveToRouteQueue".equals(request.getParameter("methodToCall")) && request.getAttribute(RENDER_LIST_OVERRIDE) == null) {
        return null;
    }

    Scheduler scheduler = KSBServiceLocator.getScheduler();
    List<QuartzQueueForm> jobs = new ArrayList<QuartzQueueForm>();
    List<String> jobGroups = KSBServiceLocator.getScheduler().getJobGroupNames();

    for (int i = 0; i < jobGroups.size(); i++) {
        String jobGroup = KSBServiceLocator.getScheduler().getJobGroupNames().get(i);
        for(JobKey jobKey : scheduler.getJobKeys(GroupMatcher.jobGroupEquals(jobGroup))) {
            Trigger trigger = scheduler.getTriggersOfJob(jobKey).get(0);
            JobDetail jobDetail = scheduler.getJobDetail(jobKey);
            jobs.add(new QuartzQueueForm(jobDetail, trigger) );
        }
    }

    request.setAttribute("jobs", jobs);
    return null;
}
 
Example #4
Source File: DefaultClusteredJobStore.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * <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;
}
 
Example #5
Source File: ScheduleServiceImpl.java    From fixflow with Apache License 2.0 6 votes vote down vote up
public List<JobDetail> getJobList(String queryId){
	if(!getIsEnabled()){
		throw new FixFlowScheduleException(ExceptionCode.QUARZTEXCEPTION_ISENABLE);
	}
	Scheduler scheduler = getScheduler();
	List<JobDetail> jobList = new ArrayList<JobDetail>();
	Set<JobKey> set = new HashSet<JobKey>();
	try {
		//如果queryId不为空,则返回queryId对应的job,否则返回所有job
		if(StringUtil.isNotEmpty(queryId)){
			set = scheduler.getJobKeys(GroupMatcher.jobGroupContains(queryId));
		}else{
			List<String> groupNames = scheduler.getJobGroupNames();
			for(String groupName:groupNames){
				set.addAll(scheduler.getJobKeys(GroupMatcher.jobGroupEquals(groupName)));
			}
		}
		for(JobKey key :set){
			JobDetail job = scheduler.getJobDetail(key); 
			jobList.add(job);
		}
	}catch (SchedulerException e) {
			throw new FixFlowException(e.getMessage(),e);
		}
	return jobList;
}
 
Example #6
Source File: DefaultClusteredJobStore.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * <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;
}
 
Example #7
Source File: JobStoreSupport.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * protected
 * <p>
 * Resume (un-pause) all triggers - equivalent of calling <code>resumeTriggerGroup(group)</code>
 * on every group.
 * </p>
 * 
 * <p>
 * If any <code>Trigger</code> missed one or more fire-times, then the
 * <code>Trigger</code>'s misfire instruction will be applied.
 * </p>
 * 
 * @see #pauseAll(Connection)
 */
public void resumeAll(Connection conn)
    throws JobPersistenceException {

    List<String> names = getTriggerGroupNames(conn);

    for (String name: names) {
        resumeTriggerGroup(conn, GroupMatcher.triggerGroupEquals(name));
    }

    try {
        getDelegate().deletePausedTriggerGroup(conn, ALL_GROUPS_PAUSED);
    } catch (SQLException e) {
        throw new JobPersistenceException(
                "Couldn't resume all trigger groups: " + e.getMessage(), e);
    }
}
 
Example #8
Source File: DefaultClusteredJobStore.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * <p>
 * Resume (un-pause) all triggers - equivalent of calling <code>resumeTriggerGroup(group)</code> on every group.
 * </p>
 * <p>
 * If any <code>Trigger</code> missed one or more fire-times, then the <code>Trigger</code>'s misfire instruction will
 * be applied.
 * </p>
 * 
 * @see #pauseAll()
 */
@Override
public void resumeAll() throws JobPersistenceException {

  lock();
  try {
    jobFacade.clearPausedJobGroups();
    List<String> names = getTriggerGroupNames();

    for (String name : names) {
      resumeTriggers(GroupMatcher.triggerGroupEquals(name));
    }
  } finally {
    unlock();
  }
}
 
Example #9
Source File: ManagerListenerTest.java    From roboconf-platform with Apache License 2.0 6 votes vote down vote up
@Test
@SuppressWarnings( "unchecked" )
public void testApplicationDeleted_exceptionWhileListingJobs() throws Exception {

	RoboconfScheduler roboconfScheduler = Mockito.mock( RoboconfScheduler.class );
	roboconfScheduler.scheduler = Mockito.mock( Scheduler.class );
	Mockito
		.when( roboconfScheduler.scheduler.getTriggerKeys( Mockito.any( GroupMatcher.class )))
		.thenThrow( new SchedulerException( "For test" ));

	ManagerListener listener = new ManagerListener( roboconfScheduler );
	listener.application(
			new Application( "app", Mockito.mock( ApplicationTemplate.class )),
			EventType.DELETED );

	Mockito
		.verify( roboconfScheduler.scheduler, Mockito.times( 1 ))
		.getTriggerKeys( Mockito.any( GroupMatcher.class ));
}
 
Example #10
Source File: CronJobManagerImpl.java    From attic-aurora with Apache License 2.0 6 votes vote down vote up
@Override
public Map<IJobKey, CrontabEntry> getScheduledJobs() {
  // NOTE: no synchronization is needed here since this is just a dump of internal quartz state
  // for debugging.
  ImmutableMap.Builder<IJobKey, CrontabEntry> scheduledJobs = ImmutableMap.builder();
  try {
    for (JobKey jobKey : scheduler.getJobKeys(GroupMatcher.anyGroup())) {
      // The quartz API allows jobs to have multiple triggers. We don't use that feature but
      // we're defensive here since this function is used for debugging.
      Optional<CronTrigger> trigger = FluentIterable.from(scheduler.getTriggersOfJob(jobKey))
          .filter(CronTrigger.class)
          .first()
          .toJavaUtil();
      if (trigger.isPresent()) {
        scheduledJobs.put(
            Quartz.auroraJobKey(jobKey),
            Quartz.crontabEntry(trigger.get()));
      }
    }
  } catch (SchedulerException e) {
    throw new RuntimeException(e);
  }
  return scheduledJobs.build();
}
 
Example #11
Source File: RemoteMBeanScheduler.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * <p>
 * Calls the equivalent method on the 'proxied' <code>QuartzScheduler</code>,
 * passing the <code>SchedulingContext</code> associated with this
 * instance.
 * </p>
 */
public void pauseJobs(GroupMatcher<JobKey> matcher) throws SchedulerException {
    String operation = null;
    switch (matcher.getCompareWithOperator()) {
        case EQUALS:
            operation = "pauseJobGroup";
            break;
        case STARTS_WITH:
            operation = "pauseJobsStartingWith";
            break;
        case ENDS_WITH:
            operation = "pauseJobsEndingWith";
            break;
        case CONTAINS:
            operation = "pauseJobsContaining";
        case ANYTHING:
            operation = "pauseJobsAll";
    }

    invoke(
            operation,
            new Object[] { matcher.getCompareToValue() },
            new String[] { String.class.getName() });
}
 
Example #12
Source File: StoreJobTest.java    From quartz-redis-jobstore with Apache License 2.0 6 votes vote down vote up
@Test
public void pauseJobsStartsWith() throws Exception {
    JobDetail job1 = getJobDetail("job1", "jobGroup1");
    storeJobAndTriggers(job1, getCronTrigger("trigger1", "triggerGroup1", job1.getKey()), getCronTrigger("trigger2", "triggerGroup1", job1.getKey()));
    JobDetail job2 = getJobDetail("job2", "yobGroup1");
    CronTriggerImpl trigger3 = getCronTrigger("trigger3", "triggerGroup3", job2.getKey());
    CronTriggerImpl trigger4 = getCronTrigger("trigger4", "triggerGroup4", job2.getKey());
    storeJobAndTriggers(job2, trigger3, trigger4);

    // pause jobs with groups beginning with "yob"
    Collection<String> pausedJobs = jobStore.pauseJobs(GroupMatcher.jobGroupStartsWith("yob"));
    assertThat(pausedJobs, hasSize(1));
    assertThat(pausedJobs, containsInAnyOrder("yobGroup1"));

    // ensure that the job was added to the paused jobs set
    assertTrue(jedis.sismember(schema.pausedJobGroupsSet(), schema.jobGroupSetKey(job2.getKey())));

    // ensure that the job's triggers have been paused
    assertEquals(Trigger.TriggerState.PAUSED, jobStore.getTriggerState(trigger3.getKey()));
    assertEquals(Trigger.TriggerState.PAUSED, jobStore.getTriggerState(trigger4.getKey()));
}
 
Example #13
Source File: RAMJobStore.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * <p>
 * Resume (un-pause) all of the <code>{@link Trigger}s</code> in the
 * given group.
 * </p>
 *
 * <p>
 * If any <code>Trigger</code> missed one or more fire-times, then the
 * <code>Trigger</code>'s misfire instruction will be applied.
 * </p>
 *
 */
public List<String> resumeTriggers(GroupMatcher<TriggerKey> matcher) {
    Set<String> groups = new HashSet<String>();

    synchronized (lock) {
        Set<TriggerKey> keys = getTriggerKeys(matcher);

        for (TriggerKey triggerKey: keys) {
            groups.add(triggerKey.getGroup());
            if(triggersByKey.get(triggerKey) != null) {
                String jobGroup = triggersByKey.get(triggerKey).jobKey.getGroup();
                if(pausedJobGroups.contains(jobGroup)) {
                    continue;
                }
            }
            resumeTrigger(triggerKey);
        }
        for (String group : groups) {
            pausedTriggerGroups.remove(group);
        }
    }

    return new ArrayList<String>(groups);
}
 
Example #14
Source File: SiteScheduledJobsController.java    From engine with GNU General Public License v3.0 6 votes vote down vote up
@GetMapping(URL_LIST)
@SuppressWarnings("unchecked")
public List<Map<String, String>> listScheduledJobs() throws SchedulerException {
    List<Map<String, String>> jobs = new LinkedList<>();
    SiteContext siteContext = SiteContext.getCurrent();
    Scheduler scheduler = siteContext.getScheduler();
    if(scheduler != null) {
        List<String> groups = scheduler.getJobGroupNames();
        for (String group : groups) {
            Set<JobKey> keys = scheduler.getJobKeys(GroupMatcher.jobGroupEquals(group));
            for (JobKey key : keys) {
                List<Trigger> triggers = (List<Trigger>)scheduler.getTriggersOfJob(key);
                Map<String, String> job = new HashMap<>();
                job.put("name", key.getName());
                job.put("nextFireTime", triggers.get(0).getNextFireTime().toInstant().toString());
                jobs.add(job);
            }
        }
    }
    return jobs;
}
 
Example #15
Source File: QuartzSchedulerMBeanImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public TabularData getAllJobDetails() throws Exception {
    try {
        List<JobDetail> detailList = new ArrayList<JobDetail>();
        for (String jobGroupName : scheduler.getJobGroupNames()) {
            for (JobKey jobKey : scheduler.getJobKeys(GroupMatcher.jobGroupEquals(jobGroupName))) {
                detailList.add(scheduler.getJobDetail(jobKey));
            }
        }
        return JobDetailSupport.toTabularData(detailList.toArray(new JobDetail[detailList.size()]));
    } catch (Exception e) {
        throw newPlainException(e);
    }
}
 
Example #16
Source File: ScheduleService.java    From elasticsearch-quartz with Apache License 2.0 5 votes vote down vote up
public void resumeJobs(final GroupMatcher<JobKey> matcher) {
    try {
        scheduler.resumeJobs(matcher);
    } catch (final SchedulerException e) {
        throw new QuartzSchedulerException(e);
    }
}
 
Example #17
Source File: RoboconfSchedulerTest.java    From roboconf-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testLoadAllJobs_exception() throws Exception {

	Utils.createDirectory( this.scheduler.getSchedulerDirectory());

	// Create several job FILES
	final int max = 5;
	for( int i=0; i<max; i++ ) {

		Properties props = new Properties();
		props.put( RoboconfScheduler.JOB_NAME, "job " + i );
		props.put( RoboconfScheduler.APP_NAME, "app" );
		props.put( RoboconfScheduler.CMD_NAME, "cmd" );
		props.put( RoboconfScheduler.CRON, "0 0 0 ? 1 *" );

		Utils.writePropertiesFile( props, this.scheduler.getJobFile( "job-id-" + i ));
	}

	// Throw an exception when a job is scheduled
	this.scheduler.scheduler = Mockito.mock( Scheduler.class );
	Mockito.when( this.scheduler.scheduler.scheduleJob(
			Mockito.any( JobDetail.class ),
			Mockito.any( Trigger.class ))).thenThrow( new SchedulerException( "For test" ));

	// Load the jobs...
	this.scheduler.loadJobs();
	File schedulerDirectory = this.scheduler.getSchedulerDirectory();

	Set<JobKey> jobKeys = this.scheduler.scheduler.getJobKeys( GroupMatcher.anyJobGroup());
	Assert.assertEquals( 0, jobKeys.size());
	Assert.assertEquals( max, Utils.listAllFiles( schedulerDirectory ).size());
}
 
Example #18
Source File: RemoteScheduler.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <p>
 * Calls the equivalent method on the 'proxied' <code>QuartzScheduler</code>.
 * </p>
 */
public void resumeTriggers(GroupMatcher<TriggerKey> matcher) throws SchedulerException {
    try {
        getRemoteScheduler().resumeTriggers(matcher);
    } catch (RemoteException re) {
        throw invalidateHandleCreateException(
                "Error communicating with remote scheduler.", re);
    }
}
 
Example #19
Source File: QuartzSchedulerMBeanImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private void pauseTriggers(GroupMatcher<TriggerKey> matcher) throws Exception {
    try {
        scheduler.pauseTriggers(matcher);
    } catch (Exception e) {
        throw newPlainException(e);
    }
}
 
Example #20
Source File: JobStoreImpl.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns all trigger keys that are matched by passed in matcher.
 */
private Set<TriggerKey> getTriggerKeys(final ODatabaseDocumentTx db,
                                       final GroupMatcher<TriggerKey> matcher)
    throws JobPersistenceException
{
  Iterable<TriggerEntity> matches = triggerEntityAdapter.browseWithPredicate
      (db, input -> matcher.isMatch(input.getValue().getKey()));

  Set<TriggerKey> result = new HashSet<>();
  for (TriggerEntity entity : matches) {
    result.add(entity.getValue().getKey());
  }
  return result;
}
 
Example #21
Source File: AbstractTerracottaJobStore.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Collection<String> pauseTriggers(GroupMatcher<TriggerKey> matcher) throws JobPersistenceException {
  try {
    return realJobStore.pauseTriggers(matcher);
  } catch (RejoinException e) {
    throw new JobPersistenceException("Pausing triggers failed due to client rejoin", e);
  }
}
 
Example #22
Source File: QuartzSchedulerMBeanImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public List<String> getJobNames(String groupName) throws Exception {
    try {
        List<String> jobNames = new ArrayList<String>();
        for(JobKey key: scheduler.getJobKeys(GroupMatcher.jobGroupEquals(groupName))) {
            jobNames.add(key.getName());
        }
        return jobNames;
    } catch (Exception e) {
        throw newPlainException(e);
    }
}
 
Example #23
Source File: JobStoreImpl.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns all trigger groups that are matched by passed in matcher.
 */
private Set<String> getTriggerGroups(final ODatabaseDocumentTx db, final GroupMatcher<TriggerKey> matcher) throws JobPersistenceException {
  Set<String> groups = new HashSet<>();
  for (TriggerKey triggerKey : getTriggerKeys(db, matcher)) {
    groups.add(triggerKey.getGroup());
  }
  return groups;
}
 
Example #24
Source File: QuartzScheduler.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <p>
 * Pause all of the <code>{@link org.quartz.JobDetail}s</code> in the
 * matching groups - by pausing all of their <code>Trigger</code>s.
 * </p>
 *  
 */
public void pauseJobs(GroupMatcher<JobKey> groupMatcher)
    throws SchedulerException {
    validateState();

    if(groupMatcher == null) {
        groupMatcher = GroupMatcher.groupEquals(Scheduler.DEFAULT_GROUP);
    }
    
    Collection<String> pausedGroups = resources.getJobStore().pauseJobs(groupMatcher);
    notifySchedulerThread(0L);
    for (String pausedGroup : pausedGroups) {
        notifySchedulerListenersPausedJobs(pausedGroup);
    }
}
 
Example #25
Source File: StoreJobTest.java    From quartz-redis-jobstore with Apache License 2.0 5 votes vote down vote up
@Test
public void getJobKeys() throws Exception {
    jobStore.storeJob(getJobDetail("job1", "group1"), false);
    jobStore.storeJob(getJobDetail("job2", "group1"), false);
    jobStore.storeJob(getJobDetail("job3", "group2"), false);

    Set<JobKey> jobKeys = jobStore.getJobKeys(GroupMatcher.jobGroupEquals("group1"));

    assertThat(jobKeys, hasSize(2));
    assertThat(jobKeys, containsInAnyOrder(new JobKey("job1", "group1"), new JobKey("job2", "group1")));

    jobStore.storeJob(getJobDetail("job4", "awesomegroup1"), false);

    jobKeys = jobStore.getJobKeys(GroupMatcher.jobGroupContains("group"));

    assertThat(jobKeys, hasSize(4));
    assertThat(jobKeys, containsInAnyOrder(new JobKey("job1", "group1"), new JobKey("job2", "group1"),
            new JobKey("job4", "awesomegroup1"), new JobKey("job3", "group2")));

    jobKeys = jobStore.getJobKeys(GroupMatcher.jobGroupStartsWith("awe"));

    assertThat(jobKeys, hasSize(1));
    assertThat(jobKeys, containsInAnyOrder(new JobKey("job4", "awesomegroup1")));

    jobKeys = jobStore.getJobKeys(GroupMatcher.jobGroupEndsWith("1"));

    assertThat(jobKeys, hasSize(3));
    assertThat(jobKeys, containsInAnyOrder(new JobKey("job1", "group1"), new JobKey("job2", "group1"),
            new JobKey("job4", "awesomegroup1")));
}
 
Example #26
Source File: StoreTriggerTest.java    From quartz-redis-jobstore with Apache License 2.0 5 votes vote down vote up
@Test
public void getTriggerKeys() throws Exception {
    JobDetail job = getJobDetail();
    jobStore.storeTrigger(getCronTrigger("trigger1", "group1", job.getKey()), false);
    jobStore.storeTrigger(getCronTrigger("trigger2", "group1", job.getKey()), false);
    jobStore.storeTrigger(getCronTrigger("trigger3", "group2", job.getKey()), false);
    jobStore.storeTrigger(getCronTrigger("trigger4", "group3", job.getKey()), false);

    Set<TriggerKey> triggerKeys = jobStore.getTriggerKeys(GroupMatcher.triggerGroupEquals("group1"));

    assertThat(triggerKeys, hasSize(2));
    assertThat(triggerKeys, containsInAnyOrder(new TriggerKey("trigger2", "group1"), new TriggerKey("trigger1", "group1")));

    jobStore.storeTrigger(getCronTrigger("trigger4", "triggergroup1", job.getKey()), false);

    triggerKeys = jobStore.getTriggerKeys(GroupMatcher.triggerGroupContains("group"));

    assertThat(triggerKeys, hasSize(5));

    triggerKeys = jobStore.getTriggerKeys(GroupMatcher.triggerGroupEndsWith("1"));

    assertThat(triggerKeys, hasSize(3));
    assertThat(triggerKeys, containsInAnyOrder(new TriggerKey("trigger2", "group1"),
            new TriggerKey("trigger1", "group1"), new TriggerKey("trigger4", "triggergroup1")));

    triggerKeys = jobStore.getTriggerKeys(GroupMatcher.triggerGroupStartsWith("trig"));

    assertThat(triggerKeys, hasSize(1));
    assertThat(triggerKeys, containsInAnyOrder(new TriggerKey("trigger4", "triggergroup1")));
}
 
Example #27
Source File: RAMJobStore.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <p>
 * Pause all of the known <code>{@link Trigger}s</code> matching.
 * </p>
 *
 * <p>
 * The JobStore should "remember" the groups paused, and impose the
 * pause on any new triggers that are added to one of these groups while the group is
 * paused.
 * </p>
 *
 */
public List<String> pauseTriggers(GroupMatcher<TriggerKey> matcher) {

    List<String> pausedGroups;
    synchronized (lock) {
        pausedGroups = new LinkedList<String>();

        StringMatcher.StringOperatorName operator = matcher.getCompareWithOperator();
        switch (operator) {
            case EQUALS:
                if(pausedTriggerGroups.add(matcher.getCompareToValue())) {
                    pausedGroups.add(matcher.getCompareToValue());
                }
                break;
            default :
                for (String group : triggersByGroup.keySet()) {
                    if(operator.evaluate(group, matcher.getCompareToValue())) {
                        if(pausedTriggerGroups.add(matcher.getCompareToValue())) {
                            pausedGroups.add(group);
                        }
                    }
                }
        }

        for (String pausedGroup : pausedGroups) {
            Set<TriggerKey> keys = getTriggerKeys(GroupMatcher.triggerGroupEquals(pausedGroup));

            for (TriggerKey key: keys) {
                pauseTrigger(key);
            }
        }
    }

    return pausedGroups;
}
 
Example #28
Source File: ManagerListenerTest.java    From roboconf-platform with Apache License 2.0 5 votes vote down vote up
@Test
@SuppressWarnings( "unchecked" )
public void testApplicationDeleted_exceptionWhileDeletingJobs() throws Exception {

	RoboconfScheduler roboconfScheduler = Mockito.mock( RoboconfScheduler.class );
	Mockito
		.doThrow( new IOException( "For test" ))
		.when( roboconfScheduler ).deleteJob( Mockito.anyString());

	Set<TriggerKey> triggerKeys = new HashSet<> ();
	triggerKeys.add( new TriggerKey( "job", "app" ));
	roboconfScheduler.scheduler = Mockito.mock( Scheduler.class );
	Mockito
		.when( roboconfScheduler.scheduler.getTriggerKeys( Mockito.any( GroupMatcher.class )))
		.thenReturn( triggerKeys );

	ManagerListener listener = new ManagerListener( roboconfScheduler );
	listener.application(
			new Application( "app", Mockito.mock( ApplicationTemplate.class )),
			EventType.DELETED );

	Mockito
		.verify( roboconfScheduler.scheduler, Mockito.times( 1 ))
		.getTriggerKeys( Mockito.any( GroupMatcher.class ));

	Mockito
		.verify( roboconfScheduler, Mockito.times( 1 ))
		.deleteJob( Mockito.anyString());
}
 
Example #29
Source File: JobStoreImpl.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Collection<String> resumeTriggers(final GroupMatcher<TriggerKey> matcher) throws JobPersistenceException {
  log.debug("Resume triggers: {}", matcher);

  return executeWrite(db -> {
    Set<String> groups = getTriggerGroups(db, matcher);
    for (String group : groups) {
      for (TriggerKey triggerKey : getTriggerKeys(db, GroupMatcher.triggerGroupEquals(group))) {
        resumeTrigger(db, triggerKey);
      }
    }
    return groups;
  });
}
 
Example #30
Source File: RemoteMBeanScheduler.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <p>
 * Calls the equivalent method on the 'proxied' <code>QuartzScheduler</code>,
 * passing the <code>SchedulingContext</code> associated with this
 * instance.
 * </p>
 */
public void resumeTriggers(GroupMatcher<TriggerKey> matcher) throws SchedulerException {
    String operation = null;
    switch (matcher.getCompareWithOperator()) {
        case EQUALS:
            operation = "resumeTriggerGroup";
            break;
        case CONTAINS:
            operation = "resumeTriggersContaining";
            break;
        case STARTS_WITH:
            operation = "resumeTriggersStartingWith";
            break;
        case ENDS_WITH:
            operation = "resumeTriggersEndingWith";
        case ANYTHING:
            operation = "resumeTriggersAll";
    }

    if (operation != null) {
        invoke(
                operation,
                new Object[] { matcher.getCompareToValue() },
                new String[] { String.class.getName() });
    } else {
        throw new SchedulerException("Unsupported GroupMatcher kind for resuming triggers: " + matcher.getCompareWithOperator());
    }
}