Use springboot to construct quartz’s rest api.

  springboot

Order

Add rest api to quartz’s operations on job and trigger

trigger

    @RequestMapping(value = "/trigger/keys",method = RequestMethod.GET)
    public Set<TriggerKey> getTriggerKeys(@RequestParam(required = false) String group) throws SchedulerException {
        if(StringUtils.isBlank(group)){
            return scheduler.getTriggerKeys(GroupMatcher.anyTriggerGroup());
        }

        return scheduler.getTriggerKeys(GroupMatcher.triggerGroupEquals(group));
    }

    @RequestMapping(value = "/trigger",method = RequestMethod.GET)
    public Trigger getTriggerDetail(@RequestParam(required = false) String group,
                                  @RequestParam String name) throws SchedulerException {
        if(StringUtils.isBlank(group)){
            return scheduler.getTrigger(TriggerKey.triggerKey(name));
        }

        return scheduler.getTrigger(TriggerKey.triggerKey(name,group));
    }

    @RequestMapping(value = "/trigger/pause",method = RequestMethod.POST)
    public void pauseTrigger(@RequestParam(required = false) String group,
                                    @RequestParam String name) throws SchedulerException {
        if(StringUtils.isBlank(group)){
            scheduler.pauseTrigger(TriggerKey.triggerKey(name));
        }

        scheduler.pauseTrigger(TriggerKey.triggerKey(name,group));
    }

    @RequestMapping(value = "/trigger/resume",method = RequestMethod.POST)
    public void resumeTrigger(@RequestParam(required = false) String group,
                             @RequestParam String name) throws SchedulerException {
        if(StringUtils.isBlank(group)){
            scheduler.resumeTrigger(TriggerKey.triggerKey(name));
        }

        scheduler.resumeTrigger(TriggerKey.triggerKey(name,group));
    }

    @RequestMapping(value = "/trigger",method = RequestMethod.DELETE)
    public void deleteTrigger(@RequestParam(required = false) String group,
                              @RequestParam String name) throws SchedulerException {
        TriggerKey triggerKey = null;
        if(StringUtils.isBlank(group)){
            triggerKey = TriggerKey.triggerKey(name);
        }else{
            triggerKey = TriggerKey.triggerKey(name,group);
        }
        scheduler.pauseTrigger(triggerKey);
        scheduler.unscheduleJob(triggerKey); //only remove trigger
    }

job

@RequestMapping(value = "/job/keys",method = RequestMethod.GET)
    public Set<JobKey> getJobKeys(@RequestParam(required = false) String group) throws SchedulerException {
        if(StringUtils.isBlank(group)){
            return scheduler.getJobKeys(GroupMatcher.anyJobGroup());
        }

        return scheduler.getJobKeys(GroupMatcher.jobGroupEquals(group));
    }

    @RequestMapping(value = "/job",method = RequestMethod.GET)
    public JobDetail getJobDetail(@RequestParam(required = false) String group,
                                            @RequestParam String name) throws SchedulerException {
        if(StringUtils.isBlank(group)){
            return scheduler.getJobDetail(JobKey.jobKey(name));
        }

        return scheduler.getJobDetail(JobKey.jobKey(name,group));
    }

    @RequestMapping(value = "/job",method = RequestMethod.DELETE)
    public void deleteJob(@RequestParam String group,
                          @RequestParam String name) throws SchedulerException {
        scheduler.deleteJob(JobKey.jobKey(name, group));
    }

Summary

The basic operations can be satisfied with rest, but the native api does not have paging processing for job and trigger, so when the amount of data is large, the query is more troublesome. The original query needs to be expanded.