@Test public void testTriggerJobById() throws SchedulerException { Long jobId = 1L; AbstractJob job = createGriffinJob(); given(jobRepo.findByIdAndDeleted(jobId,false)).willReturn(job); Scheduler scheduler = mock(Scheduler.class); given(scheduler.checkExists(any(JobKey.class))).willReturn(true); ListenerManager listenerManager = mock(ListenerManager.class); given(scheduler.getListenerManager()).willReturn(listenerManager); given(factory.getScheduler()).willReturn(scheduler); JobInstanceBean jobInstanceBean = createJobInstance(); given(instanceRepo.findByTriggerKey(anyString())).willReturn(Collections.singletonList(jobInstanceBean)); String result = jobService.triggerJobById(jobId); assertTrue(result.matches("DEFAULT\\.[0-9a-f\\-]{49}")); verify(scheduler, times(1)).scheduleJob(any()); }
@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; }