Search in sources :

Example 16 with SuccessResponseEntity

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();
}
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 17 with 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);
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) SuccessResponseEntity(com.vip.saturn.job.console.controller.SuccessResponseEntity) GetMapping(org.springframework.web.bind.annotation.GetMapping) ApiResponses(io.swagger.annotations.ApiResponses)

Example 18 with SuccessResponseEntity

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

Example 19 with 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();
}
Also used : UserRole(com.vip.saturn.job.console.mybatis.entity.UserRole) SuccessResponseEntity(com.vip.saturn.job.console.controller.SuccessResponseEntity) Audit(com.vip.saturn.job.console.aop.annotation.Audit) PostMapping(org.springframework.web.bind.annotation.PostMapping) ApiResponses(io.swagger.annotations.ApiResponses)

Example 20 with 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);
}
Also used : SuccessResponseEntity(com.vip.saturn.job.console.controller.SuccessResponseEntity) ZkCluster(com.vip.saturn.job.console.domain.ZkCluster) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

SuccessResponseEntity (com.vip.saturn.job.console.controller.SuccessResponseEntity)24 ApiResponses (io.swagger.annotations.ApiResponses)23 ZkCluster (com.vip.saturn.job.console.domain.ZkCluster)11 Audit (com.vip.saturn.job.console.aop.annotation.Audit)10 PostMapping (org.springframework.web.bind.annotation.PostMapping)10 SaturnStatistics (com.vip.saturn.job.console.mybatis.entity.SaturnStatistics)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 SaturnJobConsoleException (com.vip.saturn.job.console.exception.SaturnJobConsoleException)3 User (com.vip.saturn.job.console.mybatis.entity.User)3 GetMapping (org.springframework.web.bind.annotation.GetMapping)3 JSONObject (com.alibaba.fastjson.JSONObject)2 ContainerConfig (com.vip.saturn.job.console.domain.container.ContainerConfig)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1