Search in sources :

Example 41 with SaturnJobConsoleException

use of com.vip.saturn.job.console.exception.SaturnJobConsoleException in project Saturn by vipshop.

the class RestApiServiceImpl method createNamespace.

@Transactional(rollbackFor = { Exception.class })
@Override
public void createNamespace(NamespaceDomainInfo namespaceDomainInfo) throws SaturnJobConsoleException {
    String namespace = namespaceDomainInfo.getNamespace();
    String zkClusterKey = namespaceDomainInfo.getZkCluster();
    ZkCluster currentCluster = registryCenterService.getZkCluster(zkClusterKey);
    if (currentCluster == null) {
        throw new SaturnJobConsoleHttpException(HttpStatus.BAD_REQUEST.value(), String.format(ERR_MSG_TEMPLATE_FAIL_TO_CREATE, namespace, "not found zkcluster" + zkClusterKey));
    }
    if (checkNamespaceExists(namespace)) {
        throw new SaturnJobConsoleHttpException(HttpStatus.BAD_REQUEST.value(), String.format(ERR_MSG_NS_ALREADY_EXIST, namespace));
    }
    try {
        // 创建 namespaceInfo
        NamespaceInfo namespaceInfo = constructNamespaceInfo(namespaceDomainInfo);
        namespaceInfoService.create(namespaceInfo);
        // 创建 zkcluster 和 namespaceInfo 关系
        namespaceZkClusterMapping4SqlService.insert(namespace, "", zkClusterKey, NAMESPACE_CREATOR_NAME);
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw new SaturnJobConsoleHttpException(HttpStatus.INTERNAL_SERVER_ERROR.value(), String.format(ERR_MSG_TEMPLATE_FAIL_TO_CREATE, namespace, e.getMessage()));
    }
}
Also used : ZkCluster(com.vip.saturn.job.console.domain.ZkCluster) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException) NamespaceInfo(com.vip.saturn.job.console.mybatis.entity.NamespaceInfo) ReportAlarmException(com.vip.saturn.job.integrate.exception.ReportAlarmException) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 42 with SaturnJobConsoleException

use of com.vip.saturn.job.console.exception.SaturnJobConsoleException in project Saturn by vipshop.

the class ServerDimensionServiceImpl method getAllServersBriefInfo.

@Override
public Map<String, Object> getAllServersBriefInfo() {
    CuratorRepository.CuratorFrameworkOp curatorFrameworkOp = curatorRepository.inSessionClient();
    HashMap<String, Object> model = new HashMap<String, Object>();
    Map<String, ServerBriefInfo> sbfMap = new LinkedHashMap<String, ServerBriefInfo>();
    List<String> jobs = new ArrayList<>();
    try {
        jobs = jobDimensionService.getAllUnSystemJobs(curatorFrameworkOp);
    } catch (SaturnJobConsoleException e) {
        log.error(e.getMessage(), e);
    }
    Map<String, Map<String, Integer>> jobNameExecutorNameTotalLevel = new HashMap<>();
    String executorNodePath = ExecutorNodePath.getExecutorNodePath();
    if (curatorFrameworkOp.checkExists(executorNodePath)) {
        List<String> executors = curatorFrameworkOp.getChildren(executorNodePath);
        if (!CollectionUtils.isEmpty(executors)) {
            for (String executor : executors) {
                ServerBriefInfo sbf = new ServerBriefInfo(executor);
                String ip = curatorFrameworkOp.getData(ExecutorNodePath.getExecutorNodePath(executor, "ip"));
                sbf.setServerIp(ip);
                sbf.setNoTraffic(curatorFrameworkOp.checkExists(ExecutorNodePath.getExecutorNodePath(executor, "noTraffic")));
                String lastBeginTime = curatorFrameworkOp.getData(ExecutorNodePath.getExecutorNodePath(sbf.getExecutorName(), "lastBeginTime"));
                sbf.setLastBeginTime(null == lastBeginTime ? null : dateFormat.format(new Date(Long.parseLong(lastBeginTime))));
                if (!Strings.isNullOrEmpty(ip)) {
                    sbf.setStatus(ServerStatus.ONLINE);
                } else {
                    sbf.setStatus(ServerStatus.OFFLINE);
                }
                sbf.setVersion(curatorFrameworkOp.getData(ExecutorNodePath.getExecutorNodePath(executor, "version")));
                if (!CollectionUtils.isEmpty(jobs)) {
                    for (String jobName : jobs) {
                        String serverNodePath = JobNodePath.getServerNodePath(jobName);
                        if (!curatorFrameworkOp.checkExists(serverNodePath)) {
                            continue;
                        }
                        if (Strings.isNullOrEmpty(sbf.getServerIp())) {
                            String serverIp = curatorFrameworkOp.getData(JobNodePath.getServerNodePath(jobName, executor, "ip"));
                            sbf.setServerIp(serverIp);
                        }
                        Map<String, Integer> executorNameWithTotalLevel = null;
                        if (jobNameExecutorNameTotalLevel.containsKey(jobName)) {
                            executorNameWithTotalLevel = jobNameExecutorNameTotalLevel.get(jobName);
                        } else {
                            executorNameWithTotalLevel = new LinkedHashMap<>();
                            jobNameExecutorNameTotalLevel.put(jobName, executorNameWithTotalLevel);
                        }
                        if (ServerStatus.ONLINE.equals(sbf.getStatus())) {
                            // 负荷分布图只显示online的Executor
                            executorNameWithTotalLevel.put(executor, 0);
                        }
                        String sharding = curatorFrameworkOp.getData(JobNodePath.getServerNodePath(jobName, executor, "sharding"));
                        if (!Strings.isNullOrEmpty(sharding)) {
                            // 如果有分片信息则前端需要屏蔽删除按钮
                            sbf.setHasSharding(true);
                            if (JobStatus.STOPPED.equals(jobDimensionService.getJobStatus(jobName))) {
                                // 作业状态为STOPPED的即使有残留分片也不显示该分片
                                continue;
                            }
                            if (ServerStatus.OFFLINE.equals(sbf.getStatus())) {
                                // offline的executor即使有残留分片也不显示该分片
                                continue;
                            }
                            // concat executorSharding
                            String executorSharding = jobName + ":" + sharding;
                            if (Strings.isNullOrEmpty(sbf.getSharding())) {
                                // 如果有分片信息则前端需要屏蔽删除按钮
                                sbf.setSharding(executorSharding);
                            } else {
                                sbf.setSharding(sbf.getSharding() + "<br/>" + executorSharding);
                            }
                            // calculate totalLoadLevel
                            String loadLevelNode = curatorFrameworkOp.getData(JobNodePath.getConfigNodePath(jobName, "loadLevel"));
                            Integer loadLevel = 1;
                            if (!Strings.isNullOrEmpty(loadLevelNode)) {
                                loadLevel = Integer.parseInt(loadLevelNode);
                            }
                            Integer totalLoadLevel = sbf.getTotalLoadLevel();
                            int thisJobsLoad = (sharding.split(",").length * loadLevel);
                            sbf.setTotalLoadLevel((sbf.getTotalLoadLevel() == null ? 0 : totalLoadLevel) + thisJobsLoad);
                            executorNameWithTotalLevel.put(executor, thisJobsLoad);
                        }
                    }
                }
                sbfMap.put(executor, sbf);
            }
        }
        model.put("serverInfos", sbfMap.values());
        model.put("jobShardLoadLevels", jobNameExecutorNameTotalLevel);
    }
    return model;
}
Also used : ServerBriefInfo(com.vip.saturn.job.console.domain.ServerBriefInfo) CuratorRepository(com.vip.saturn.job.console.repository.zookeeper.CuratorRepository) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException)

Example 43 with SaturnJobConsoleException

use of com.vip.saturn.job.console.exception.SaturnJobConsoleException in project Saturn by vipshop.

the class JobOverviewController method getJobOverviewByStatusAndPage.

private JobOverviewVo getJobOverviewByStatusAndPage(String namespace, JobStatus jobStatus, Map<String, Object> condition, int page, int size) throws SaturnJobConsoleException {
    JobOverviewVo jobOverviewVo = new JobOverviewVo();
    try {
        preHandleStatusAndCondition(condition, jobStatus);
        List<JobConfig4DB> unSystemJobs = jobService.getUnSystemJobsWithCondition(namespace, condition, page, size);
        if (unSystemJobs == null || unSystemJobs.isEmpty()) {
            jobOverviewVo.setJobs(Lists.<JobOverviewJobVo>newArrayList());
            jobOverviewVo.setTotalNumber(0);
            return jobOverviewVo;
        }
        Pageable pageable = PageableUtil.generatePageble(page, size);
        // 当 jobStatus 为null时,底层取数据已经做了分页,此处无需再次分页
        List<JobConfig4DB> targetJobs = jobStatus == null ? unSystemJobs : getJobSubListByPage(unSystemJobs, pageable);
        List<JobOverviewJobVo> jobOverviewList = updateJobOverviewDetail(namespace, targetJobs, jobStatus);
        jobOverviewVo.setJobs(jobOverviewList);
        jobOverviewVo.setTotalNumber(jobService.countUnSystemJobsWithCondition(namespace, condition));
    } catch (SaturnJobConsoleException e) {
        throw e;
    } catch (Exception e) {
        throw new SaturnJobConsoleException(e);
    }
    return jobOverviewVo;
}
Also used : Pageable(org.springframework.data.domain.Pageable) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) JobConfig4DB(com.vip.saturn.job.console.mybatis.entity.JobConfig4DB) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException)

Example 44 with SaturnJobConsoleException

use of com.vip.saturn.job.console.exception.SaturnJobConsoleException in project Saturn by vipshop.

the class JobOverviewController method getJobOverviewByPage.

private JobOverviewVo getJobOverviewByPage(String namespace, Map<String, Object> condition, int page, int size) throws SaturnJobConsoleException {
    JobOverviewVo jobOverviewVo = new JobOverviewVo();
    try {
        preHandleCondition(condition);
        List<JobConfig4DB> unSystemJobs = jobService.getUnSystemJobsWithCondition(namespace, condition, page, size);
        if (unSystemJobs == null || unSystemJobs.isEmpty()) {
            jobOverviewVo.setJobs(Lists.<JobOverviewJobVo>newArrayList());
            jobOverviewVo.setTotalNumber(0);
            return jobOverviewVo;
        }
        List<JobOverviewJobVo> jobOverviewList = updateJobOverviewDetail(namespace, unSystemJobs, null);
        jobOverviewVo.setJobs(jobOverviewList);
        jobOverviewVo.setTotalNumber(jobService.countUnSystemJobsWithCondition(namespace, condition));
    } catch (SaturnJobConsoleException e) {
        throw e;
    } catch (Exception e) {
        throw new SaturnJobConsoleException(e);
    }
    return jobOverviewVo;
}
Also used : SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) JobConfig4DB(com.vip.saturn.job.console.mybatis.entity.JobConfig4DB) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException)

Example 45 with SaturnJobConsoleException

use of com.vip.saturn.job.console.exception.SaturnJobConsoleException 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)

Aggregations

SaturnJobConsoleException (com.vip.saturn.job.console.exception.SaturnJobConsoleException)190 SaturnJobConsoleHttpException (com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException)56 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)56 CuratorRepository (com.vip.saturn.job.console.repository.zookeeper.CuratorRepository)39 RequestResult (com.vip.saturn.job.console.domain.RequestResult)31 ParseException (java.text.ParseException)28 ResponseEntity (org.springframework.http.ResponseEntity)26 Transactional (org.springframework.transaction.annotation.Transactional)23 JobConfig4DB (com.vip.saturn.job.console.mybatis.entity.JobConfig4DB)22 CuratorFrameworkOp (com.vip.saturn.job.console.repository.zookeeper.CuratorRepository.CuratorFrameworkOp)22 IOException (java.io.IOException)19 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)19 StatusLine (org.apache.http.StatusLine)18 HttpEntity (org.apache.http.HttpEntity)16 Audit (com.vip.saturn.job.console.aop.annotation.Audit)13 JobConfig (com.vip.saturn.job.console.domain.JobConfig)11 HttpHeaders (org.springframework.http.HttpHeaders)11 CurrentJobConfig (com.vip.saturn.job.console.mybatis.entity.CurrentJobConfig)9 ZkCluster (com.vip.saturn.job.console.domain.ZkCluster)8 ArrayList (java.util.ArrayList)8