Search in sources :

Example 11 with SuccessResponseEntity

use of com.vip.saturn.job.console.controller.SuccessResponseEntity in project Saturn by vipshop.

the class DashboardController method domainProcessCount.

@ApiResponses(value = { @ApiResponse(code = 200, message = "Success/Fail", response = RequestResult.class) })
@GetMapping(value = "/domainProcessCount")
public SuccessResponseEntity domainProcessCount(@RequestParam(required = false) String zkClusterKey) throws SaturnJobConsoleException {
    if (StringUtils.isNotBlank(zkClusterKey)) {
        ZkCluster zkCluster = checkAndGetZkCluster(zkClusterKey);
        SaturnStatistics ss = dashboardService.allProcessAndErrorCountOfTheDay(zkCluster.getZkAddr());
        return ss == null ? new SuccessResponseEntity() : new SuccessResponseEntity(ss.getResult());
    }
    return new SuccessResponseEntity(dashboardService.allProcessAndErrorCountOfTheDayByAllZkCluster());
}
Also used : SaturnStatistics(com.vip.saturn.job.console.mybatis.entity.SaturnStatistics) SuccessResponseEntity(com.vip.saturn.job.console.controller.SuccessResponseEntity) ZkCluster(com.vip.saturn.job.console.domain.ZkCluster) ApiResponses(io.swagger.annotations.ApiResponses)

Example 12 with SuccessResponseEntity

use of com.vip.saturn.job.console.controller.SuccessResponseEntity in project Saturn by vipshop.

the class MarathonController method addContainer.

@PostMapping(value = "/container")
@ResponseBody
public SuccessResponseEntity addContainer(@AuditParam("namespace") @PathVariable String namespace, AddContainerModel addContainerModel, HttpServletRequest request) throws SaturnJobConsoleException {
    if (addContainerModel.getContainerToken() == null) {
        throw new SaturnJobConsoleException("Please input container token");
    }
    marathonService.checkContainerTokenNotNull(namespace, addContainerModel.getContainerToken());
    marathonService.saveOrUpdateContainerTokenIfNecessary(namespace, addContainerModel.getContainerToken());
    ContainerConfig containerConfig = new ContainerConfig();
    containerConfig.setTaskId(addContainerModel.getTaskId());
    containerConfig.setCmd(addContainerModel.getCmd());
    containerConfig.setCpus(addContainerModel.getCpus());
    containerConfig.setMem(addContainerModel.getMem());
    containerConfig.setInstances(addContainerModel.getInstances());
    containerConfig.setConstraints(addContainerModel.getConstraints());
    containerConfig.setEnv(addContainerModel.getEnv());
    containerConfig.setPrivileged(addContainerModel.getPrivileged() == null ? false : addContainerModel.getPrivileged());
    containerConfig.setForcePullImage(addContainerModel.getForcePullImage() == null ? true : addContainerModel.getForcePullImage());
    containerConfig.setParameters(addContainerModel.getParameters());
    containerConfig.setVolumes(addContainerModel.getVolumes());
    containerConfig.setImage(addContainerModel.getImage());
    containerConfig.setCreateTime(System.currentTimeMillis());
    String imageNew = "";
    String vipSaturnDcosRegistryUri = SaturnEnvProperties.VIP_SATURN_DCOS_REGISTRY_URI;
    if (vipSaturnDcosRegistryUri == null || vipSaturnDcosRegistryUri.trim().length() == 0) {
        throw new SaturnJobConsoleException("VIP_SATURN_DCOS_REGISTRY_URI is not configured");
    } else {
        if (vipSaturnDcosRegistryUri.startsWith("http://")) {
            String tmp = vipSaturnDcosRegistryUri.substring("http://".length());
            while (tmp.endsWith("/")) {
                tmp = tmp.substring(0, tmp.length() - 1);
            }
            imageNew = tmp + "/" + addContainerModel.getImage();
        } else if (vipSaturnDcosRegistryUri.startsWith("https://")) {
            String tmp = vipSaturnDcosRegistryUri.substring("https://".length());
            while (tmp.endsWith("/")) {
                tmp = tmp.substring(0, tmp.length() - 1);
            }
            imageNew = tmp + "/" + addContainerModel.getImage();
        }
    }
    containerConfig.setImage(imageNew);
    if (containerConfig.getEnv() == null) {
        containerConfig.setEnv(new HashMap<String, String>());
    }
    if (!containerConfig.getEnv().containsKey(SaturnEnvProperties.NAME_VIP_SATURN_ZK_CONNECTION)) {
        containerConfig.getEnv().put(SaturnEnvProperties.NAME_VIP_SATURN_ZK_CONNECTION, getCurrentZkAddr(request.getSession()));
    }
    marathonService.addContainer(namespace, containerConfig);
    return new SuccessResponseEntity();
}
Also used : ContainerConfig(com.vip.saturn.job.console.domain.container.ContainerConfig) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) SuccessResponseEntity(com.vip.saturn.job.console.controller.SuccessResponseEntity)

Example 13 with SuccessResponseEntity

use of com.vip.saturn.job.console.controller.SuccessResponseEntity in project Saturn by vipshop.

the class UtilsController method getZkClusterKeys.

@ApiResponses(value = { @ApiResponse(code = 200, message = "Success/Fail", response = RequestResult.class) })
@GetMapping(value = "/zkClusterKeys")
public SuccessResponseEntity getZkClusterKeys() {
    Collection<ZkCluster> zkClusters = registryCenterService.getZkClusterList();
    List<String> zkClusterKeys = Lists.newArrayList();
    for (ZkCluster zkCluster : zkClusters) {
        zkClusterKeys.add(zkCluster.getZkClusterKey());
    }
    return new SuccessResponseEntity(zkClusterKeys);
}
Also used : SuccessResponseEntity(com.vip.saturn.job.console.controller.SuccessResponseEntity) ZkCluster(com.vip.saturn.job.console.domain.ZkCluster) GetMapping(org.springframework.web.bind.annotation.GetMapping) ApiResponses(io.swagger.annotations.ApiResponses)

Example 14 with SuccessResponseEntity

use of com.vip.saturn.job.console.controller.SuccessResponseEntity in project Saturn by vipshop.

the class ConsoleConfigController method updateConfig.

/**
 * 更新配置项。
 *
 * @param key 配置key
 * @param value 配置值
 */
@ApiResponses(value = { @ApiResponse(code = 200, message = "Success/Fail", response = RequestResult.class) })
@Audit
@PostMapping("/update")
public SuccessResponseEntity updateConfig(@AuditParam(value = "key") @RequestParam String key, @AuditParam(value = "value") @RequestParam String value) throws SaturnJobConsoleException {
    assertIsPermitted(PermissionKeys.systemConfig);
    // 不能更新EXECUTOR_CONFIGS
    if (SystemConfigProperties.EXECUTOR_CONFIGS.equals(key)) {
        throw new SaturnJobConsoleException(String.format("配置项不能为%s", key));
    }
    SystemConfig systemConfig = new SystemConfig();
    systemConfig.setProperty(key);
    systemConfig.setValue(value);
    systemConfigService.updateConfig(systemConfig);
    return new SuccessResponseEntity();
}
Also used : SystemConfig(com.vip.saturn.job.console.mybatis.entity.SystemConfig) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) 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 15 with SuccessResponseEntity

use of com.vip.saturn.job.console.controller.SuccessResponseEntity in project Saturn by vipshop.

the class AuthorizationController method updateUserRole.

@ApiResponses(value = { @ApiResponse(code = 200, message = "Success/Fail", response = RequestResult.class) })
@Audit
@PostMapping("/updateUserRole")
public SuccessResponseEntity updateUserRole(@AuditParam("preUserName") @RequestParam String preUserName, @AuditParam("preRoleKey") @RequestParam String preRoleKey, @AuditParam("preNamespace") @RequestParam String preNamespace, @AuditParam("userName") @RequestParam String userName, @AuditParam("roleKey") @RequestParam String roleKey, @AuditParam("namespace") @RequestParam String namespace, @AuditParam("needApproval") @RequestParam Boolean needApproval, HttpSession httpSession) throws SaturnJobConsoleException {
    assertIsSystemAdmin();
    String currentLoginUserName = getCurrentLoginUserName();
    Date now = new Date();
    UserRole pre = new UserRole();
    pre.setUserName(preUserName);
    pre.setRoleKey(preRoleKey);
    pre.setNamespace(preNamespace);
    pre.setLastUpdateTime(now);
    pre.setLastUpdatedBy(currentLoginUserName);
    UserRole cur = new UserRole();
    cur.setUserName(userName);
    cur.setRoleKey(roleKey);
    cur.setNamespace(namespace);
    cur.setNeedApproval(needApproval);
    cur.setCreatedBy(currentLoginUserName);
    cur.setCreateTime(now);
    cur.setLastUpdatedBy(currentLoginUserName);
    cur.setLastUpdateTime(now);
    cur.setIsDeleted(false);
    authorizationService.updateUserRole(pre, cur);
    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

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