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);
}
}
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);
}
}
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);
}
}
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();
}
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();
}
Aggregations