@Test(expected = GriffinException.NotFoundException.class) public void testTriggerJobByIdFail() throws SchedulerException { Long jobId = 1L; given(jobRepo.findByIdAndDeleted(jobId,false)).willReturn(null); jobService.triggerJobById(jobId); }
@Override public String triggerJobById(Long id) throws SchedulerException { AbstractJob job = jobRepo.findByIdAndDeleted(id, false); validateJobExist(job); Scheduler scheduler = factory.getScheduler(); JobKey jobKey = jobKey(job.getName(), job.getGroup()); if (scheduler.checkExists(jobKey)) { Trigger trigger = TriggerBuilder.newTrigger() .forJob(jobKey) .startNow() .build(); scheduler.scheduleJob(trigger); return trigger.getKey().toString(); } else { throw new GriffinException.NotFoundException(JOB_ID_DOES_NOT_EXIST); } }
JobServiceImpl implements JobService { @Override public String triggerJobById(Long id) throws SchedulerException { AbstractJob job = jobRepo.findByIdAndDeleted(id, false); validateJobExist(job); Scheduler scheduler = factory.getScheduler(); JobKey jobKey = jobKey(job.getName(), job.getGroup()); if (scheduler.checkExists(jobKey)) { Trigger trigger = TriggerBuilder.newTrigger() .forJob(jobKey) .startNow() .build(); scheduler.scheduleJob(trigger); return trigger.getKey().toString(); } else { throw new GriffinException.NotFoundException(JOB_ID_DOES_NOT_EXIST); } } }
JobServiceImpl implements JobService { @Override public String triggerJobById(Long id) throws SchedulerException { AbstractJob job = jobRepo.findByIdAndDeleted(id, false); validateJobExist(job); Scheduler scheduler = factory.getScheduler(); JobKey jobKey = jobKey(job.getName(), job.getGroup()); if (scheduler.checkExists(jobKey)) { Trigger trigger = TriggerBuilder.newTrigger() .forJob(jobKey) .startNow() .build(); scheduler.scheduleJob(trigger); return trigger.getKey().toString(); } else { throw new GriffinException.NotFoundException(JOB_ID_DOES_NOT_EXIST); } } JobServiceImpl(); }
JobServiceImpl implements JobService { @Override public String triggerJobById(Long id) throws SchedulerException { AbstractJob job = jobRepo.findByIdAndDeleted(id, false); validateJobExist(job); Scheduler scheduler = factory.getScheduler(); JobKey jobKey = jobKey(job.getName(), job.getGroup()); if (scheduler.checkExists(jobKey)) { Trigger trigger = TriggerBuilder.newTrigger() .forJob(jobKey) .startNow() .build(); scheduler.scheduleJob(trigger); return trigger.getKey().toString(); } else { throw new GriffinException.NotFoundException(JOB_ID_DOES_NOT_EXIST); } } JobServiceImpl(); @Override List<AbstractJob> getAliveJobs(String type); @Override AbstractJob addJob(AbstractJob job); @Override AbstractJob getJobConfig(Long jobId); @Override AbstractJob onAction(Long jobId, String action); @Override void deleteJob(Long jobId); @Override void deleteJob(String name); @Override List<JobInstanceBean> findInstancesOfJob(
        Long jobId,
        int page,
        int size); @Override JobInstanceBean findInstance(Long id); @Override List<JobInstanceBean> findInstancesByTriggerKey(String triggerKey); @Override JobHealth getHealthInfo(); @Scheduled(fixedDelayString = "${jobInstance.expired.milliseconds}") void deleteExpiredJobInstance(); void deleteJobsRelateToMeasure(Long measureId); @Scheduled(fixedDelayString = "${jobInstance.fixedDelay.in.milliseconds}") void syncInstancesOfAllJobs(); Boolean isJobHealthy(Long jobId); @Override String getJobHdfsSinksPath(String jobName, long timestamp); @Override String triggerJobById(Long id); }
JobServiceImpl implements JobService { @Override public String triggerJobById(Long id) throws SchedulerException { AbstractJob job = jobRepo.findByIdAndDeleted(id, false); validateJobExist(job); Scheduler scheduler = factory.getScheduler(); JobKey jobKey = jobKey(job.getName(), job.getGroup()); if (scheduler.checkExists(jobKey)) { Trigger trigger = TriggerBuilder.newTrigger() .forJob(jobKey) .startNow() .build(); scheduler.scheduleJob(trigger); return trigger.getKey().toString(); } else { throw new GriffinException.NotFoundException(JOB_ID_DOES_NOT_EXIST); } } JobServiceImpl(); @Override List<AbstractJob> getAliveJobs(String type); @Override AbstractJob addJob(AbstractJob job); @Override AbstractJob getJobConfig(Long jobId); @Override AbstractJob onAction(Long jobId, String action); @Override void deleteJob(Long jobId); @Override void deleteJob(String name); @Override List<JobInstanceBean> findInstancesOfJob(
        Long jobId,
        int page,
        int size); @Override JobInstanceBean findInstance(Long id); @Override List<JobInstanceBean> findInstancesByTriggerKey(String triggerKey); @Override JobHealth getHealthInfo(); @Scheduled(fixedDelayString = "${jobInstance.expired.milliseconds}") void deleteExpiredJobInstance(); void deleteJobsRelateToMeasure(Long measureId); @Scheduled(fixedDelayString = "${jobInstance.fixedDelay.in.milliseconds}") void syncInstancesOfAllJobs(); Boolean isJobHealthy(Long jobId); @Override String getJobHdfsSinksPath(String jobName, long timestamp); @Override String triggerJobById(Long id); static final String GRIFFIN_JOB_ID; }