/** * Find the job detail * @param id the job id * @return the job detail response */ @RequestMapping(value = "/{id}", method = RequestMethod.GET) public JsonResponse findJobDetail(@PathVariable("id") Long id){ Response<JobDetail> findResp = jobService.findJobDetailById(id); if(!findResp.isSuccess()){ return JsonResponse.notOk(messages.get(findResp.getErr())); } return JsonResponse.ok(findResp.getData()); }
/** * Get the job's current schedule server * @param jobId the job id * @return the job schedule server */ private String getScheduleServer(Long jobId){ Response<String> serverResp = jobService.findServerOfJob(jobId); if (!serverResp.isSuccess()){ throw new JobServerException(serverResp.getErr().toString()); } String server = serverResp.getData(); if (Strings.isNullOrEmpty(server)){ throw new JobServerException("job.not.scheduled.by.server"); } return server; }
@RequestMapping(value = JOB_SCHEDULE + "/{jobId}", method = RequestMethod.POST) public Boolean scheduleJob(@PathVariable(value = "jobId") Long jobId){ Response<Boolean> bindResp = jobService.bindJob2Server(jobId, host.get()); if (!bindResp.isSuccess()){ return Boolean.FALSE; } // start to schedule the job return jobPool.scheduleJob(jobId); }
Response<JobDetail> findResp = jobService.findJobDetailById(e.getJobId()); if (!findResp.isSuccess()){ Logs.error("failed to find job detail(event={}), cause: {}", e, findResp.getErr()); context.setJobName(jobDetail.getJob().getClazz()); Response<String> schedulerResp = jobService.findServerOfJob(e.getJobId()); if (!schedulerResp.isSuccess()){ Logs.error("failed to find the job(event={})'s scheduler, cause: {}", e, schedulerResp.getErr());
/** * Remove the job from the pool, and will delete the job from zk * @param jobId the job id */ public Boolean removeJob(Long jobId){ Response<JobDetail> findResp = jobService.findJobDetailById(jobId); if (!findResp.isSuccess()){ Logs.error("failed to find the job detail when remove job(id={}), cause: {}", jobId, findResp.getErr()); return Boolean.TRUE; } if (removeJob(findResp.getData())){ // unbind the job from the server Response<Boolean> unbindResp = jobService.unbindJobServer(serverHost.get(), jobId); if (!unbindResp.isSuccess() || !unbindResp.getData()){ return Boolean.FALSE; } return Boolean.TRUE; } return Boolean.FALSE; }
/** * Delete the job dependence * @param jobId the job id * @param nextJobId the next job id * @return return true if add successfully, or false */ @RequestMapping(value = "/{jobId}/del_next/{nextJobId}", method = RequestMethod.POST) public JsonResponse deleteDependenceJob( @PathVariable("jobId") Long jobId, @PathVariable("nextJobId") Long nextJobId){ Response<Boolean> deleteResp = jobService.deleteNextJob(jobId, nextJobId); if (!deleteResp.isSuccess()){ return JsonResponse.notOk(messages.get(deleteResp.getErr())); } return JsonResponse.ok(deleteResp.getData()); }
/** * Add the job dependence * @param jobId the job id * @param nextJob the next job * @return return true if add successfully, or false */ @RequestMapping(value = "/{jobId}/next", method = RequestMethod.POST) public JsonResponse addDependenceJob( @PathVariable("jobId") Long jobId, @RequestBody SaveNextJob nextJob){ JobDependence dependence = new JobDependence(); dependence.setJobId(jobId); dependence.setNextJobId(nextJob.getNextJobId()); Response<Boolean> addResp = jobService.addJobDependence(dependence); if (!addResp.isSuccess()){ return JsonResponse.notOk(messages.get(addResp.getErr())); } return JsonResponse.ok(addResp.getData()); }
/** * Delete the job * @param jobId the job id * @return the delete result */ @RequestMapping(value = "/{jobId}/delete", method = RequestMethod.POST) public JsonResponse deleteJob(@PathVariable("jobId") Long jobId){ // remove the job Response<Boolean> removeResp = serverService.removeJob(jobId); if (!removeResp.isSuccess() || !removeResp.getData()){ return JsonResponse.notOk(messages.get(removeResp.getErr())); } // delete the job Response<Boolean> deleteResp = jobService.deleteJob(jobId); if (!deleteResp.isSuccess() || !deleteResp.getData()){ return JsonResponse.notOk(messages.get(deleteResp.getErr())); } return JsonResponse.ok(); }
/** * Create a new job instance and shards * @param detail the job detail * @return the new job instance */ private JobInstance createInstanceAndShards(JobDetail detail, JobTriggerType triggerType) { JobInstance instance = new JobInstance(); instance.setJobId(detail.getJob().getId()); instance.setStatus(JobInstanceStatus.RUNNING.value()); instance.setTriggerType(triggerType.value()); instance.setServer(serverHost.get()); instance.setStartTime(new Date()); Response<Boolean> saveResp = jobService.createJobInstanceAndShards(instance, detail.getConfig()); if (!saveResp.isSuccess() || !saveResp.getData()){ throw new JobInstanceCreateException(saveResp.getErr().toString()); } return instance; }
public Boolean scheduleJob(Long jobId) { Response<JobDetail> findResp = jobService.findJobDetailById(jobId); if (!findResp.isSuccess()){ Logs.error("failed to find job detail when schedule job(id={}), cause: {}", jobId, findResp.getErr()); return Boolean.TRUE; } scheduleJob(findResp.getData()); return Boolean.TRUE; }
/** * Pause the job * @param jobId the job id */ public Boolean pauseJob(Long jobId){ Response<JobDetail> findResp = jobService.findJobDetailById(jobId); if (!findResp.isSuccess()){ Logs.error("failed to find job detail when pause job(id={}), cause: {}", jobId, findResp.getErr()); return Boolean.TRUE; } return pauseJob(findResp.getData()); }
/** * Resume the job schedule * @param jobId the job id */ public Boolean resumeJob(Long jobId){ Response<JobDetail> findResp = jobService.findJobDetailById(jobId); if (!findResp.isSuccess()){ Logs.error("failed to find job detail when resume job(id={}), cause: {}", jobId, findResp.getErr()); return Boolean.TRUE; } return resumeJob(findResp.getData()); }
/** * Reload the job to be scheduled * @param jobId the job id * @return return true if reload successfully, or not */ public Boolean reloadJob(Long jobId) { Response<JobDetail> findResp = jobService.findJobDetailById(jobId); if (!findResp.isSuccess()){ Logs.error("failed to find job detail when remove job(id={}), cause: {}", jobId, findResp.getErr()); return Boolean.TRUE; } return reloadJob(findResp.getData()); }
/** * Trigger the job immediately * @param jobId the job id * @param triggerType the trigger type * @see JobTriggerType */ public Boolean triggerJob(Long jobId, JobTriggerType triggerType){ Response<JobDetail> findResp = jobService.findJobDetailById(jobId); if (!findResp.isSuccess()){ Logs.error("failed to find job detail when trigger job(id={}), cause: {}", jobId, findResp.getErr()); return Boolean.TRUE; } return triggerJob(findResp.getData(), triggerType); }
private void checkJobState(Long jobId, JobState expectState, JobState targetState) { Response<JobDetail> jobResp = jobService.findJobDetailById(jobId); if(!jobResp.isSuccess()){ throw new JobFindException(); } JobDetail jobDetail = jobResp.getData(); if (jobDetail == null){ Logs.warn("The job(id={}) isn't exist.", jobId); throw new JobNotExistException(jobId); } String appName = jobDetail.getApp().getAppName(); String jobClass = jobDetail.getJob().getClazz(); jobSupport.checkJobStateOperate(appName, jobClass, expectState, targetState); }