Search in sources :

Example 16 with Audit

use of com.vip.saturn.job.console.aop.annotation.Audit 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);
    }
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) 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)

Example 17 with Audit

use of com.vip.saturn.job.console.aop.annotation.Audit 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);
    }
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) NamespaceDomainInfo(com.vip.saturn.job.console.domain.NamespaceDomainInfo) 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 18 with Audit

use of com.vip.saturn.job.console.aop.annotation.Audit 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 19 with Audit

use of com.vip.saturn.job.console.aop.annotation.Audit in project Saturn by vipshop.

the class ExecutorConfigController method createOrUpdateConfig.

@ApiResponses(value = { @ApiResponse(code = 200, message = "Success/Fail", response = RequestResult.class) })
@Audit
@PostMapping
public SuccessResponseEntity createOrUpdateConfig(@AuditParam(value = "key") @RequestParam String key, @AuditParam(value = "value") @RequestParam String value) throws SaturnJobConsoleException {
    assertIsPermitted(PermissionKeys.systemConfig);
    String executorConfigsJsonInDB = systemConfigService.getValueDirectly(SystemConfigProperties.EXECUTOR_CONFIGS);
    JSONObject jsonObject = parseExecutorConfigJson(executorConfigsJsonInDB);
    if (jsonObject == null) {
        jsonObject = new JSONObject();
    }
    // I'm sure that key and value is not null, because @RequestParam required is true
    jsonObject.put(key.trim(), value.trim());
    String configStr = jsonObject.toJSONString();
    log.info("Start to update executor config data {}", configStr);
    // update zk
    List<ZkCluster> onlineZkClusterList = registryCenterService.getOnlineZkClusterList();
    for (ZkCluster zkCluster : onlineZkClusterList) {
        updateConfigInZk(configStr, zkCluster);
    }
    // update db
    SystemConfig systemConfig = new SystemConfig();
    systemConfig.setProperty(SystemConfigProperties.EXECUTOR_CONFIGS);
    systemConfig.setValue(configStr);
    systemConfigService.insertOrUpdate(systemConfig);
    log.info("Update executor config to db successfully");
    return new SuccessResponseEntity();
}
Also used : SystemConfig(com.vip.saturn.job.console.mybatis.entity.SystemConfig) JSONObject(com.alibaba.fastjson.JSONObject) SuccessResponseEntity(com.vip.saturn.job.console.controller.SuccessResponseEntity) ZkCluster(com.vip.saturn.job.console.domain.ZkCluster) Audit(com.vip.saturn.job.console.aop.annotation.Audit) PostMapping(org.springframework.web.bind.annotation.PostMapping) ApiResponses(io.swagger.annotations.ApiResponses)

Example 20 with Audit

use of com.vip.saturn.job.console.aop.annotation.Audit in project Saturn by vipshop.

the class AuthorizationManageController method addUserRoles.

@ApiResponses(value = { @ApiResponse(code = 200, message = "Success/Fail", response = RequestResult.class) })
@Audit
@PostMapping("/addUserRoles")
public SuccessResponseEntity addUserRoles(@AuditParam("userNames") @RequestParam String userNames, @AuditParam("roleKey") @RequestParam String roleKey, @AuditParam("namespaces") @RequestParam String namespaces, @AuditParam("needApproval") @RequestParam Boolean needApproval) throws SaturnJobConsoleException {
    assertIsSystemAdmin();
    String currentLoginUserName = getCurrentLoginUserName();
    List<String> userNameList = strSplitToList(userNames);
    List<String> namespaceList = strSplitToList(namespaces);
    // if add user to global role, the namespaces is empty
    if (namespaceList.isEmpty()) {
        namespaceList.add("");
    }
    for (String userName : userNameList) {
        for (String namespace : namespaceList) {
            Date now = new Date();
            UserRole userRole = new UserRole();
            userRole.setUserName(userName);
            userRole.setRoleKey(roleKey);
            userRole.setNamespace(namespace);
            userRole.setNeedApproval(needApproval);
            userRole.setIsDeleted(false);
            userRole.setCreatedBy(currentLoginUserName);
            userRole.setCreateTime(now);
            userRole.setLastUpdatedBy(currentLoginUserName);
            userRole.setLastUpdateTime(now);
            authorizationManageService.addUserRole(userRole);
        }
    }
    return new SuccessResponseEntity();
}
Also used : UserRole(com.vip.saturn.job.console.mybatis.entity.UserRole) SuccessResponseEntity(com.vip.saturn.job.console.controller.SuccessResponseEntity) Date(java.util.Date) Audit(com.vip.saturn.job.console.aop.annotation.Audit) PostMapping(org.springframework.web.bind.annotation.PostMapping) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

Audit (com.vip.saturn.job.console.aop.annotation.Audit)24 SaturnJobConsoleException (com.vip.saturn.job.console.exception.SaturnJobConsoleException)13 SaturnJobConsoleHttpException (com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException)12 ApiResponses (io.swagger.annotations.ApiResponses)12 ResponseEntity (org.springframework.http.ResponseEntity)12 SuccessResponseEntity (com.vip.saturn.job.console.controller.SuccessResponseEntity)10 PostMapping (org.springframework.web.bind.annotation.PostMapping)10 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8 UserRole (com.vip.saturn.job.console.mybatis.entity.UserRole)6 SystemConfig (com.vip.saturn.job.console.mybatis.entity.SystemConfig)4 Date (java.util.Date)4 HttpHeaders (org.springframework.http.HttpHeaders)3 JobConfig (com.vip.saturn.job.console.domain.JobConfig)2 AlarmInfo (com.vip.saturn.job.integrate.entity.AlarmInfo)2 File (java.io.File)2 SimpleDateFormat (java.text.SimpleDateFormat)2 MultipartFile (org.springframework.web.multipart.MultipartFile)2 JSONObject (com.alibaba.fastjson.JSONObject)1 JobDiffInfo (com.vip.saturn.job.console.domain.JobDiffInfo)1 NamespaceDomainInfo (com.vip.saturn.job.console.domain.NamespaceDomainInfo)1