private void doFailover(String client) { // push back the client's all running shards jobService.returnJobInstanceShardsOfClient(client); }
private App findAppById(Long appId) { Response<App> findResp = appService.findById(appId); if (!findResp.isSuccess()){ throw new RuntimeException("Failed to find app, id = " + appId); } App app = findResp.getData(); if (app == null){ throw new RuntimeException("The app isn't exist, id = " + appId); } return app; } }
@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); }
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; }
/** * Enable the job, will start to scheduling the job * @param jobId the job id * @return the enable result */ @RequestMapping(value = "/{jobId}/enable", method = RequestMethod.POST) public JsonResponse enableJob(@PathVariable("jobId") Long jobId){ // enable the job Response<Boolean> enableResp = jobService.enableJob(jobId); if (!enableResp.isSuccess()){ return JsonResponse.notOk(messages.get(enableResp.getErr())); } // try to scheduling the job Response<Boolean> schedulingResp = serverService.scheduleJobIfPossible(jobId); if (!schedulingResp.isSuccess() || !schedulingResp.getData()){ return JsonResponse.notOk(messages.get(schedulingResp.getErr())); } return JsonResponse.ok(); }
private void notifyAllNextJobs(JobFinishedEvent e) { int pageNo = 1; int pageSize = 100; Long jobId = e.getJobId(); Response<Page<Long>> nextJobIdsResp; for (;;){ nextJobIdsResp = jobService.pagingNextJobIds(jobId, pageNo, pageSize); if (!nextJobIdsResp.isSuccess()){ Logs.error("failed to paging next job ids(jobId={}, pageNo={}, pageSize={}) when notify all next jobs, cause: {}", jobId, pageNo, pageSize, nextJobIdsResp.getErr()); break; } List<Long> nextJobIds = nextJobIdsResp.getData().getData(); if (CollectionUtil.isNullOrEmpty(nextJobIds)){ // there aren't next jobs break; } for (Long nextJobId : nextJobIds){ serverService.notifyJob(nextJobId); } pageNo ++; } }
/** * Disable the job, and stop the scheduling if necessary * @param jobId the job id * @return the disable result */ @RequestMapping(value = "/{jobId}/disable", method = RequestMethod.POST) public JsonResponse disableJob(@PathVariable("jobId") Long jobId){ // disable the job Response<Boolean> disableResp = jobService.disableJob(jobId); if (!disableResp.isSuccess() || !disableResp.getData()){ return JsonResponse.notOk(messages.get(disableResp.getErr())); } // try to remove job schedule Response<Boolean> removeResp = serverService.removeJob(jobId); if (!removeResp.isSuccess() || !removeResp.isSuccess()){ return JsonResponse.notOk(messages.get(removeResp.getErr())); } return JsonResponse.ok(); }
/** * 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(); }
@Override public void run() { Response<List<AlarmEvent>> pullResp = alarmService.pull(PULL_BATCH_SIZE); if (pullResp.isSuccess()){ if (!pullResp.getData().isEmpty()){ for (AlarmEvent event : pullResp.getData()){ alarm(event); } } } } }, 1L, 5, TimeUnit.SECONDS);
/** * Return one shard */ @RequestMapping(value = SHARD_RETURN, method = RequestMethod.POST) public JsonResponse returnShard( @RequestParam("instanceId") Long instanceId, @RequestParam("shardId") Long shardId, @RequestParam("client") String client){ Response<Boolean> returnResp = jobService.returnJobInstanceShard(instanceId, shardId, client); if (!returnResp.isSuccess()){ return JsonResponse.notOk(returnResp.getStatus(), returnResp.getErr()); } return JsonResponse.ok(returnResp.getData()); }
/** * Pull one shard */ @RequestMapping(value = SHARD_PULL, method = RequestMethod.POST) public JsonResponse pullShard( @RequestParam("instanceId") Long instanceId, @RequestParam("client") String client){ Response<PullShard> pullResp = jobService.pullJobInstanceShard(instanceId, client); if (!pullResp.isSuccess()){ return JsonResponse.notOk(pullResp.getStatus(), pullResp.getErr()); } return JsonResponse.ok(pullResp.getData()); }
@RequestMapping(value = "/servers/jobs", method = RequestMethod.GET) public JsonResponse listJobsByServer(@RequestParam("server") String server){ Response<List<Job>> findResp = jobService.findJobsByServer(server); if (!findResp.isSuccess()){ return JsonResponse.notOk(messages.get(findResp.getErr())); } return JsonResponse.ok(findResp.getData()); }
/** * Paging the job's assignments * @param jobId the job id * @return the job's assignments */ @RequestMapping(value = "/{jobId}/assigns", method = RequestMethod.GET) public JsonResponse listJobAssigns(@PathVariable("jobId") Long jobId){ Response<List<JobAssignDto>> listResp = jobService.listJobAssigns(jobId); if (!listResp.isSuccess()){ return JsonResponse.notOk(messages.get(listResp.getErr())); } return JsonResponse.ok(listResp.getData()); }
/** * Pause the job * @param jobId the job id * @return the pause result */ @RequestMapping(value = "/{jobId}/pause", method = RequestMethod.POST) public JsonResponse pauseJob(@PathVariable("jobId") Long jobId){ Response<Boolean> pauseResp = serverService.pauseJob(jobId); if (!pauseResp.isSuccess() || !pauseResp.getData()){ return JsonResponse.notOk(messages.get(pauseResp.getErr())); } return JsonResponse.ok(pauseResp.getData()); }
/** * Resume the job to be scheduled for pausing * @param jobId the job id * @return the resume result */ @RequestMapping(value = "/{jobId}/resume", method = RequestMethod.POST) public JsonResponse resumeJob(@PathVariable("jobId") Long jobId){ Response<Boolean> resumeResp = serverService.resumeJob(jobId); if (!resumeResp.isSuccess() || !resumeResp.getData()){ return JsonResponse.notOk(messages.get(resumeResp.getErr())); } return JsonResponse.ok(resumeResp.getData()); }
@RequestMapping(value = "/servers", method = RequestMethod.GET) public JsonResponse servers(){ Response<List<ServerInfo>> serversResp = clusterService.listServers(); if (!serversResp.isSuccess()){ Logs.error("failed to list servers, cause: {}", serversResp.getErr()); return JsonResponse.notOk(messages.get("servers.list.failed")); } return JsonResponse.ok(serversResp.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()); }
/** * 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()); }
/** * 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); }