use of com.vip.saturn.job.console.controller.SuccessResponseEntity 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.controller.SuccessResponseEntity in project Saturn by vipshop.
the class ExecutorConfigController method getConfigs.
@ApiResponses(value = { @ApiResponse(code = 200, message = "Success/Fail", response = RequestResult.class) })
@GetMapping
public SuccessResponseEntity getConfigs() throws SaturnJobConsoleException {
assertIsPermitted(PermissionKeys.systemConfig);
String executorConfigsJsonInDB = systemConfigService.getValueDirectly(SystemConfigProperties.EXECUTOR_CONFIGS);
JSONObject jsonObject = parseExecutorConfigJson(executorConfigsJsonInDB);
if (jsonObject == null) {
return new SuccessResponseEntity(Lists.newArrayList());
}
List<Map<String, String>> result = new ArrayList<>();
Set<String> keys = jsonObject.keySet();
for (String key : keys) {
Map<String, String> element = new HashMap<>();
element.put("key", key);
element.put("value", jsonObject.getString(key));
result.add(element);
}
return new SuccessResponseEntity(result);
}
use of com.vip.saturn.job.console.controller.SuccessResponseEntity 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();
}
use of com.vip.saturn.job.console.controller.SuccessResponseEntity in project Saturn by vipshop.
the class AuthorizationManageController method deleteUserRole.
@ApiResponses(value = { @ApiResponse(code = 200, message = "Success/Fail", response = RequestResult.class) })
@Audit
@PostMapping("/deleteUserRole")
public SuccessResponseEntity deleteUserRole(@AuditParam("userName") @RequestParam String userName, @AuditParam("roleKey") @RequestParam String roleKey, @AuditParam("namespace") @RequestParam String namespace) throws SaturnJobConsoleException {
assertIsSystemAdmin();
UserRole userRole = new UserRole();
userRole.setUserName(userName);
userRole.setRoleKey(roleKey);
userRole.setNamespace(namespace);
String currentLoginUserName = getCurrentLoginUserName();
userRole.setLastUpdatedBy(currentLoginUserName);
authorizationManageService.deleteUserRole(userRole);
return new SuccessResponseEntity();
}
use of com.vip.saturn.job.console.controller.SuccessResponseEntity in project Saturn by vipshop.
the class DashboardController method getStatistics.
@ApiResponses(value = { @ApiResponse(code = 200, message = "Success/Fail", response = RequestResult.class) })
@GetMapping(value = "/count")
public SuccessResponseEntity getStatistics(@RequestParam(required = false) String zkClusterKey) throws SaturnJobConsoleException {
Map<String, Integer> countMap = Maps.newHashMap();
int executorInDockerCount = 0;
int executorNotInDockerCount = 0;
int jobCount = 0;
int domainCount = 0;
Collection<ZkCluster> zkClusters = null;
if (StringUtils.isNotBlank(zkClusterKey)) {
ZkCluster zkCluster = registryCenterService.getZkCluster(zkClusterKey);
zkClusters = Lists.newArrayList();
zkClusters.add(zkCluster);
} else {
zkClusters = registryCenterService.getZkClusterList();
}
for (ZkCluster zkCluster : zkClusters) {
// 不统计离线的zkcluster
if (zkCluster.isOffline()) {
continue;
}
String zkAddr = zkCluster.getZkAddr();
if (zkAddr != null) {
executorInDockerCount += dashboardService.executorInDockerCount(zkAddr);
executorNotInDockerCount += dashboardService.executorNotInDockerCount(zkAddr);
jobCount += dashboardService.jobCount(zkAddr);
}
domainCount += registryCenterService.domainCount(zkCluster.getZkClusterKey());
}
countMap.put("executorInDockerCount", executorInDockerCount);
countMap.put("executorNotInDockerCount", executorNotInDockerCount);
countMap.put("jobCount", jobCount);
countMap.put("domainCount", domainCount);
return new SuccessResponseEntity(countMap);
}
Aggregations