use of com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException in project Saturn by vipshop.
the class JobOperationRestApiController method updateJobCron.
@Audit(type = AuditType.REST)
@RequestMapping(value = { "/{namespace}/{jobName}/cron", "/{namespace}/jobs/{jobName}/cron" }, method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public ResponseEntity<Object> updateJobCron(@PathVariable("namespace") String namespace, @PathVariable("jobName") String jobName, @RequestBody Map<String, String> params, HttpServletRequest request) throws SaturnJobConsoleException {
HttpHeaders httpHeaders = new HttpHeaders();
try {
String cron = params.remove("cron");
checkMissingParameter("cron", cron);
restApiService.updateJobCron(namespace, jobName, cron, params);
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 NamespaceManagementRestApiController method create.
@Audit(type = AuditType.REST)
@RequestMapping(value = "/namespaces", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public ResponseEntity<Object> create(@RequestBody Map<String, Object> reqParams, HttpServletRequest request) throws SaturnJobConsoleException {
try {
NamespaceDomainInfo namespaceInfo = constructNamespaceDomainInfo(reqParams);
registryCenterService.createNamespace(namespaceInfo);
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 AlarmRestApiController method raise.
@Audit(type = AuditType.REST)
@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, HttpServletRequest request) throws SaturnJobConsoleException {
try {
String jobName = checkAndGetParametersValueAsString(reqParams, "jobName", false);
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, jobName, executorName, shardItem);
// (since 2.1.4) 如果alarm title是Executor_Restart,而且系统配置ALARM_RAISED_ON_EXECUTOR_RESTART=false, 只记录日志不发送告警
boolean isExecutorRestartAlarmEvent = isExecutorRestartAlarmEvent(alarmInfo);
if (isExecutorRestartAlarmEvent) {
boolean alarmRaisedOnExecutorRestart = systemConfigService.getBooleanValue(ALARM_RAISED_ON_EXECUTOR_RESTART, Boolean.FALSE);
if (!alarmRaisedOnExecutorRestart) {
logger.warn(alarmInfo.getMessage());
} else {
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 DiscoveryRestApiController method getZkConnStr.
/**
* 返回ZK连接串
*/
private String getZkConnStr(String namespace) throws SaturnJobConsoleHttpException {
if (StringUtils.isBlank(namespace)) {
throw new SaturnJobConsoleHttpException(HttpStatus.BAD_REQUEST.value(), String.format(MISSING_REQUEST_MSG, "namespace"));
}
String zkClusterKey = namespaceZkclusterMapping4SqlService.getZkClusterKey(namespace);
if (zkClusterKey == null) {
throw new SaturnJobConsoleHttpException(HttpStatus.NOT_FOUND.value(), "The namespace:[" + namespace + "] is not registered in Saturn.");
}
ZkClusterInfo zkClusterInfo = zkClusterInfoService.getByClusterKey(zkClusterKey);
if (zkClusterInfo == null) {
throw new SaturnJobConsoleHttpException(HttpStatus.INTERNAL_SERVER_ERROR.value(), "The clusterKey: [" + zkClusterKey + "] is not configured in db for " + namespace);
}
return zkClusterInfo.getConnectString();
}
use of com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException in project Saturn by vipshop.
the class ZkDiscoveryRestApiController method discoverZk.
@Audit(type = AuditType.REST)
@RequestMapping(value = "/discoverZk", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public ResponseEntity<Object> discoverZk(String namespace, HttpServletRequest request) throws SaturnJobConsoleException {
HttpHeaders headers = new HttpHeaders();
try {
checkMissingParameter("namespace", namespace);
String zkClusterKey = namespaceZkclusterMapping4SqlService.getZkClusterKey(namespace);
if (zkClusterKey == null) {
throw new SaturnJobConsoleHttpException(HttpStatus.NOT_FOUND.value(), "The namespace:[" + namespace + "] is not registered in Saturn.");
}
ZkClusterInfo zkClusterInfo = zkClusterInfoService.getByClusterKey(zkClusterKey);
if (zkClusterInfo == null) {
throw new SaturnJobConsoleHttpException(HttpStatus.INTERNAL_SERVER_ERROR.value(), "The clusterKey: [" + zkClusterKey + "] is not configured in db for " + namespace);
}
return new ResponseEntity<Object>(zkClusterInfo.getConnectString(), headers, HttpStatus.OK);
} catch (SaturnJobConsoleException e) {
throw e;
} catch (Exception e) {
throw new SaturnJobConsoleHttpException(HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage(), e);
}
}
Aggregations