use of com.vip.saturn.job.integrate.entity.AlarmInfo 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.integrate.entity.AlarmInfo in project Saturn by vipshop.
the class AlarmRestApiController method constructAlarmInfo.
private AlarmInfo constructAlarmInfo(Map<String, Object> reqParams) throws SaturnJobConsoleException {
AlarmInfo alarmInfo = new AlarmInfo();
String level = checkAndGetParametersValueAsString(reqParams, "level", true);
alarmInfo.setLevel(level);
alarmInfo.setType(ALARM_TYPE);
String name = checkAndGetParametersValueAsString(reqParams, "name", true);
alarmInfo.setName(name);
String title = checkAndGetParametersValueAsString(reqParams, "title", true);
alarmInfo.setTitle(title);
String message = checkAndGetParametersValueAsString(reqParams, "message", false);
if (StringUtils.isNotBlank(message)) {
alarmInfo.setMessage(message);
}
Map<String, String> customFields = (Map<String, String>) reqParams.get("additionalInfo");
if (customFields != null) {
alarmInfo.getCustomFields().putAll(customFields);
}
return alarmInfo;
}
use of com.vip.saturn.job.integrate.entity.AlarmInfo 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) 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);
log.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.integrate.entity.AlarmInfo 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.integrate.entity.AlarmInfo in project Saturn by vipshop.
the class AlarmRestApiController method constructAlarmInfo.
private AlarmInfo constructAlarmInfo(Map<String, Object> reqParams) throws SaturnJobConsoleException {
AlarmInfo alarmInfo = new AlarmInfo();
String level = checkAndGetParametersValueAsString(reqParams, "level", true);
alarmInfo.setLevel(level);
alarmInfo.setType(ALARM_TYPE);
String name = checkAndGetParametersValueAsString(reqParams, "name", true);
alarmInfo.setName(name);
String title = checkAndGetParametersValueAsString(reqParams, "title", true);
alarmInfo.setTitle(title);
String message = checkAndGetParametersValueAsString(reqParams, "message", false);
if (StringUtils.isNotBlank(message)) {
alarmInfo.setMessage(message);
}
Map<String, String> customFields = (Map<String, String>) reqParams.get("additionalInfo");
if (customFields != null) {
alarmInfo.getCustomFields().putAll(customFields);
}
return alarmInfo;
}
Aggregations