use of com.vip.saturn.job.console.exception.SaturnJobConsoleException in project Saturn by vipshop.
the class JobController method migrateJobNewTask.
@RequestMapping(value = "migrateJobNewTask", method = RequestMethod.POST)
public RequestResult migrateJobNewTask(final String jobName, final String newTask, HttpServletRequest request) {
RequestResult requestResult = new RequestResult();
try {
if (jobName == null) {
throw new SaturnJobConsoleException("The jobName cannot be null");
}
if (newTask == null) {
throw new SaturnJobConsoleException("The new task cannot be null");
}
if (jobName.trim().length() == 0) {
throw new SaturnJobConsoleException("The jobName cannot be empty string");
}
if (newTask.trim().length() == 0) {
throw new SaturnJobConsoleException("The new task cannot be empty string");
}
jobDimensionService.migrateJobNewTask(jobName.trim(), newTask.trim());
requestResult.setSuccess(true);
} catch (Exception e) {
requestResult.setSuccess(false);
requestResult.setMessage(e.getMessage());
}
return requestResult;
}
use of com.vip.saturn.job.console.exception.SaturnJobConsoleException in project Saturn by vipshop.
the class JobOperationController method batchToggleJobEnabledState.
@RequestMapping(value = "batchToggleJobEnabledState", method = RequestMethod.POST)
public RequestResult batchToggleJobEnabledState(HttpServletRequest request, String jobNames, Boolean state, Boolean confirmed) {
RequestResult requestResult = new RequestResult();
if (state == null) {
requestResult.setSuccess(false);
requestResult.setMessage("更改的状态有误。");
return requestResult;
}
String[] jobNameArr = jobNames.split(",");
if (jobNameArr == null || jobNameArr.length == 0) {
requestResult.setSuccess(false);
requestResult.setMessage("没有选中任何要操作的作业。");
return requestResult;
}
if (confirmed != null && !confirmed) {
for (String jobName : jobNameArr) {
if (jobName != null && jobName.trim().length() > 0) {
jobName = jobName.trim();
try {
if (state) {
// 启用时,检查其依赖的作业是否已经启动
List<JobConfig> dependentJobsStatus = jobDimensionService.getDependentJobsStatus(jobName);
if (dependentJobsStatus != null) {
String unableJobs = "";
for (JobConfig jobConfig : dependentJobsStatus) {
if (!jobConfig.getEnabled()) {
unableJobs += jobConfig.getJobName() + ",";
}
}
if (!unableJobs.equals("")) {
requestResult.setSuccess(false);
requestResult.setMessage("有作业依赖的作业还没启用,是否继续批量启用作业?");
requestResult.setObj("confirmDependencies");
return requestResult;
}
}
} else {
// 禁用时,检查依赖它的作业是否已经禁用
List<JobConfig> dependedJobsStatus = jobDimensionService.getDependedJobsStatus(jobName);
if (dependedJobsStatus != null) {
String enableJobs = "";
for (JobConfig jobConfig : dependedJobsStatus) {
if (jobConfig.getEnabled()) {
enableJobs += jobConfig.getJobName();
}
}
if (!enableJobs.equals("")) {
requestResult.setSuccess(false);
requestResult.setMessage("有作业被依赖的作业还没禁用,是否继续批量禁用作业?");
requestResult.setObj("confirmDependencies");
return requestResult;
}
}
}
} catch (SaturnJobConsoleException e) {
requestResult.setSuccess(false);
requestResult.setMessage(e.getMessage());
return requestResult;
} catch (Exception e) {
requestResult.setSuccess(false);
requestResult.setMessage(e.toString());
return requestResult;
}
}
}
}
StringBuilder messageSbf = new StringBuilder();
for (String jobName : jobNameArr) {
try {
Boolean isJobEnabled = jobDimensionService.isJobEnabled(jobName);
if (isJobEnabled == state) {
if (state) {
messageSbf.append("作业【" + jobName + "】已经是启动状态,");
} else {
messageSbf.append("作业【" + jobName + "】已经是禁用状态,");
}
}
JobStatus js = jobDimensionService.getJobStatus(jobName);
// enabled job
if (state) {
if (JobStatus.STOPPED.equals(js)) {
jobOperationService.setJobEnabledState(jobName, state);
} else {
messageSbf.append("作业【" + jobName + "】不处于stopped状态,不能启用,");
}
} else {
if (JobStatus.RUNNING.equals(js) || JobStatus.READY.equals(js)) {
jobOperationService.setJobEnabledState(jobName, state);
} else {
messageSbf.append("作业【" + jobName + "】不处于running或ready状态,不能禁用,");
}
}
} catch (Exception e) {
messageSbf.append("操作作业【" + jobName + "】出现内部错误,");
continue;
}
}
if (messageSbf.length() == 0) {
requestResult.setSuccess(true);
return requestResult;
} else {
requestResult.setSuccess(false);
// 去掉最后一个逗号
requestResult.setMessage(messageSbf.substring(0, messageSbf.length() - 1));
return requestResult;
}
}
use of com.vip.saturn.job.console.exception.SaturnJobConsoleException in project Saturn by vipshop.
the class JobOperationRestApiController method run.
@RequestMapping(value = "/{namespace}/jobs/{jobName}/run", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public ResponseEntity<Object> run(@PathVariable("namespace") String namespace, @PathVariable("jobName") String jobName) throws SaturnJobConsoleException {
try {
checkMissingParameter("namespace", namespace);
checkMissingParameter("jobName", jobName);
restApiService.runJobAtOnce(namespace, jobName);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
} catch (SaturnJobConsoleException e) {
throw e;
} catch (Exception e) {
throw new SaturnJobConsoleHttpException(HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage(), e);
}
}
use of com.vip.saturn.job.console.exception.SaturnJobConsoleException in project Saturn by vipshop.
the class JobOperationRestApiController method create.
@RequestMapping(value = "/{namespace}/jobs", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public ResponseEntity<Object> create(@PathVariable("namespace") String namespace, @RequestBody Map<String, Object> reqParams) throws SaturnJobConsoleException {
try {
JobConfig jobConfig = constructJobConfig(namespace, reqParams);
restApiService.createJob(namespace, jobConfig);
return new ResponseEntity<>(HttpStatus.CREATED);
} catch (SaturnJobConsoleException e) {
throw e;
} catch (Exception e) {
throw new SaturnJobConsoleHttpException(HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage(), e);
}
}
use of com.vip.saturn.job.console.exception.SaturnJobConsoleException in project Saturn by vipshop.
the class JobOperationRestApiController method enable.
@RequestMapping(value = { "/{namespace}/{jobName}/enable", "/{namespace}/jobs/{jobName}/enable" }, method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public ResponseEntity<Object> enable(@PathVariable("namespace") String namespace, @PathVariable("jobName") String jobName) throws SaturnJobConsoleException {
HttpHeaders httpHeaders = new HttpHeaders();
try {
checkMissingParameter("namespace", namespace);
checkMissingParameter("jobName", jobName);
restApiService.enableJob(namespace, jobName);
return new ResponseEntity<>(httpHeaders, HttpStatus.OK);
} catch (SaturnJobConsoleException e) {
throw e;
} catch (Exception e) {
throw new SaturnJobConsoleHttpException(HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage(), e);
}
}
Aggregations