use of com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException in project Saturn by vipshop.
the class JobOperationServiceImpl method setJobEnabledState.
@Transactional
@Override
public void setJobEnabledState(String jobName, boolean state) throws SaturnJobConsoleException {
CuratorRepository.CuratorFrameworkOp curatorFrameworkOp = curatorRepository.inSessionClient();
String namespace = curatorFrameworkOp.getCuratorFramework().getNamespace();
CurrentJobConfig oldCurrentJobConfig = currentJobConfigService.findConfigByNamespaceAndJobName(namespace, jobName);
if (oldCurrentJobConfig != null) {
oldCurrentJobConfig.setEnabled(state);
oldCurrentJobConfig.setLastUpdateTime(new Date());
try {
currentJobConfigService.updateByPrimaryKey(oldCurrentJobConfig);
} catch (Exception e) {
log.error("exception is thrown during change job state in db", e);
throw new SaturnJobConsoleHttpException(HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage(), e);
}
} else {
log.warn("job:{} not existed in db", jobName);
}
curatorFrameworkOp.update(JobNodePath.getConfigNodePath(jobName, "enabled"), state);
}
use of com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException in project Saturn by vipshop.
the class RestApiServiceImpl method updateNamespace.
@Override
public void updateNamespace(NamespaceDomainInfo namespaceDomainInfo) throws SaturnJobConsoleException {
String namespace = namespaceDomainInfo.getNamespace();
if (!checkNamespaceExists(namespace)) {
throw new SaturnJobConsoleHttpException(HttpStatus.BAD_REQUEST.value(), ERR_MSG_NS_NOT_FOUND);
}
try {
// 创建 namespaceInfo
NamespaceInfo namespaceInfo = constructNamespaceInfo(namespaceDomainInfo);
namespaceInfoService.update(namespaceInfo);
} catch (Exception e) {
log.error(e.getMessage(), e);
throw new SaturnJobConsoleHttpException(HttpStatus.INTERNAL_SERVER_ERROR.value(), String.format(ERR_MSG_TEMPLATE_FAIL_TO_CREATE, namespace, e.getMessage()));
}
}
use of com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException in project Saturn by vipshop.
the class AlarmRestApiController method raise.
@RequestMapping(value = "/raise", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public ResponseEntity<Object> raise(@PathVariable("namespace") String namespace, @RequestBody Map<String, Object> reqParams) throws SaturnJobConsoleException {
try {
String jobName = checkAndGetParametersValueAsString(reqParams, "jobName", true);
String executorName = checkAndGetParametersValueAsString(reqParams, "executorName", true);
Integer shardItem = checkAndGetParametersValueAsInteger(reqParams, "shardItem", false);
AlarmInfo alarmInfo = constructAlarmInfo(reqParams);
logger.info("try to raise alarm: {}, job: {}, executor: {}, item: {}", alarmInfo.toString(), jobName, executorName, shardItem);
// (since 2.1.4) 如果alarm title是Executor_Restart,而且系统配置ALARM_RAISED_ON_EXECUTOR_RESTART=false, 只记录日志不发送告警
boolean isExecutorRestartAlarmEvent = isExecutorRestartAlarmEvent(alarmInfo);
if (isExecutorRestartAlarmEvent) {
restApiService.raiseExecutorRestartAlarm(namespace, executorName, alarmInfo);
} else {
if (StringUtils.isBlank(jobName)) {
throw new SaturnJobConsoleHttpException(HttpStatus.BAD_REQUEST.value(), "Invalid request. Missing parameter: jobName");
}
restApiService.raiseAlarm(namespace, jobName, executorName, shardItem, alarmInfo);
}
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 query.
@RequestMapping(value = "/{namespace}/jobs/{jobName}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public ResponseEntity<Object> query(@PathVariable("namespace") String namespace, @PathVariable("jobName") String jobName) throws SaturnJobConsoleException {
HttpHeaders httpHeaders = new HttpHeaders();
try {
checkMissingParameter("namespace", namespace);
checkMissingParameter("jobName", jobName);
RestApiJobInfo restAPIJobInfo = restApiService.getRestAPIJobInfo(namespace, jobName);
return new ResponseEntity<Object>(restAPIJobInfo, 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 delete.
@RequestMapping(value = "/{namespace}/jobs/{jobName}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public ResponseEntity<Object> delete(@PathVariable("namespace") String namespace, @PathVariable("jobName") String jobName) throws SaturnJobConsoleException {
try {
checkMissingParameter("namespace", namespace);
checkMissingParameter("jobName", jobName);
restApiService.deleteJob(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);
}
}
Aggregations