use of com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException 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.SaturnJobConsoleHttpException in project Saturn by vipshop.
the class JobOperationRestApiController method constructJobConfig.
private JobConfig constructJobConfig(String namespace, Map<String, Object> reqParams) throws SaturnJobConsoleException {
JobConfig jobConfig = new JobConfig();
checkMissingParameter("namespace", namespace);
jobConfig.setNamespace(namespace);
if (!reqParams.containsKey("jobConfig")) {
throw new SaturnJobConsoleHttpException(HttpStatus.BAD_REQUEST.value(), String.format(INVALID_REQUEST_MSG, "jobConfig", "cannot be blank"));
}
Map<String, Object> configParams = (Map<String, Object>) reqParams.get("jobConfig");
jobConfig.setJobName(checkAndGetParametersValueAsString(reqParams, "jobName", true));
jobConfig.setDescription(checkAndGetParametersValueAsString(reqParams, "description", false));
jobConfig.setChannelName(checkAndGetParametersValueAsString(configParams, "channelName", false));
jobConfig.setCron(checkAndGetParametersValueAsString(configParams, "cron", false));
jobConfig.setJobClass(checkAndGetParametersValueAsString(configParams, "jobClass", false));
jobConfig.setJobParameter(checkAndGetParametersValueAsString(configParams, "jobParameter", false));
String jobType = checkAndGetParametersValueAsString(configParams, "jobType", true);
if (JobBriefInfo.JobType.UNKOWN_JOB.equals(JobBriefInfo.JobType.getJobType(jobType))) {
throw new SaturnJobConsoleHttpException(HttpStatus.BAD_REQUEST.value(), String.format(INVALID_REQUEST_MSG, "jobType", "is malformed"));
}
jobConfig.setJobType(jobType);
jobConfig.setLoadLevel(checkAndGetParametersValueAsInteger(configParams, "loadLevel", false));
jobConfig.setLocalMode(checkAndGetParametersValueAsBoolean(configParams, "localMode", false));
jobConfig.setPausePeriodDate(checkAndGetParametersValueAsString(configParams, "pausePeriodDate", false));
jobConfig.setPausePeriodTime(checkAndGetParametersValueAsString(configParams, "pausePeriodTime", false));
jobConfig.setPreferList(checkAndGetParametersValueAsString(configParams, "preferList", false));
jobConfig.setQueueName(checkAndGetParametersValueAsString(configParams, "queueName", false));
jobConfig.setShardingItemParameters(checkAndGetParametersValueAsString(configParams, "shardingItemParameters", true));
jobConfig.setShardingTotalCount(checkAndGetParametersValueAsInteger(configParams, "shardingTotalCount", true));
jobConfig.setTimeout4AlarmSeconds(checkAndGetParametersValueAsInteger(configParams, "timeout4AlarmSeconds", false));
jobConfig.setTimeoutSeconds(checkAndGetParametersValueAsInteger(configParams, "timeout4Seconds", false));
jobConfig.setUseDispreferList(checkAndGetParametersValueAsBoolean(configParams, "useDispreferList", false));
jobConfig.setUseSerial(checkAndGetParametersValueAsBoolean(configParams, "useSerial", false));
jobConfig.setJobDegree(checkAndGetParametersValueAsInteger(configParams, "jobDegree", false));
jobConfig.setDependencies(checkAndGetParametersValueAsString(configParams, "dependencies", false));
jobConfig.setTimeZone(checkAndGetParametersValueAsString(configParams, "timeZone", false));
jobConfig.setTimeoutSeconds(checkAndGetParametersValueAsInteger(configParams, "timeoutSeconds", false));
jobConfig.setProcessCountIntervalSeconds(checkAndGetParametersValueAsInteger(configParams, "processCountIntervalSeconds", false));
jobConfig.setGroups(checkAndGetParametersValueAsString(configParams, "groups", false));
jobConfig.setShowNormalLog(checkAndGetParametersValueAsBoolean(configParams, "showNormalLog", false));
return jobConfig;
}
use of com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException 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.SaturnJobConsoleHttpException 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);
}
}
use of com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException in project Saturn by vipshop.
the class JobOperationRestApiController method disable.
@RequestMapping(value = { "/{namespace}/{jobName}/disable", "/{namespace}/jobs/{jobName}/disable" }, method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public ResponseEntity<Object> disable(@PathVariable("namespace") String namespace, @PathVariable("jobName") String jobName) throws SaturnJobConsoleException {
HttpHeaders httpHeaders = new HttpHeaders();
try {
checkMissingParameter("namespace", namespace);
checkMissingParameter("jobName", jobName);
restApiService.disableJob(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