Search in sources :

Example 1 with AlarmInfo

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);
    }
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) AlarmInfo(com.vip.saturn.job.integrate.entity.AlarmInfo) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with AlarmInfo

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;
}
Also used : AlarmInfo(com.vip.saturn.job.integrate.entity.AlarmInfo) Map(java.util.Map)

Example 3 with 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);
    }
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) AlarmInfo(com.vip.saturn.job.integrate.entity.AlarmInfo) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException) Audit(com.vip.saturn.job.console.aop.annotation.Audit) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with 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, 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);
    }
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) AlarmInfo(com.vip.saturn.job.integrate.entity.AlarmInfo) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException) Audit(com.vip.saturn.job.console.aop.annotation.Audit) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with AlarmInfo

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;
}
Also used : AlarmInfo(com.vip.saturn.job.integrate.entity.AlarmInfo) Map(java.util.Map)

Aggregations

AlarmInfo (com.vip.saturn.job.integrate.entity.AlarmInfo)5 SaturnJobConsoleException (com.vip.saturn.job.console.exception.SaturnJobConsoleException)3 SaturnJobConsoleHttpException (com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException)3 ResponseEntity (org.springframework.http.ResponseEntity)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 Audit (com.vip.saturn.job.console.aop.annotation.Audit)2 Map (java.util.Map)2