Search in sources :

Example 1 with ZkCluster

use of com.vip.saturn.job.console.domain.ZkCluster in project Saturn by vipshop.

the class JobConfigInitializationServiceImpl method exportAllToDb.

@Override
public void exportAllToDb(final String userName) throws SaturnJobConsoleException {
    final ExportJobConfigPageStatus exportJobConfigPageStatus = new ExportJobConfigPageStatus();
    temporarySharedStatusService.delete(ShareStatusModuleNames.EXPORT_JOB_CONFIG_PAGE_STATUS);
    temporarySharedStatusService.create(ShareStatusModuleNames.EXPORT_JOB_CONFIG_PAGE_STATUS, gson.toJson(exportJobConfigPageStatus));
    executorService.execute(new Runnable() {

        @Override
        public void run() {
            log.info("start to export all to db");
            try {
                log.info("start to delete all from table job_config");
                deleteAll();
                log.info("delete all from table job_config successfully");
                Collection<ZkCluster> zkClusters = registryCenterService.getZkClusterList();
                if (zkClusters != null) {
                    for (ZkCluster tmp : zkClusters) {
                        exportToDbByZkCluster(userName, tmp, exportJobConfigPageStatus);
                    }
                }
                exportJobConfigPageStatus.setSuccess(true);
            } catch (Exception e) {
                log.error(e.getMessage(), e);
                exportJobConfigPageStatus.setSuccess(false);
            } finally {
                exportJobConfigPageStatus.setExported(true);
                temporarySharedStatusService.update(ShareStatusModuleNames.EXPORT_JOB_CONFIG_PAGE_STATUS, gson.toJson(exportJobConfigPageStatus));
            }
        }
    });
}
Also used : ExportJobConfigPageStatus(com.vip.saturn.job.console.domain.ExportJobConfigPageStatus) Collection(java.util.Collection) ZkCluster(com.vip.saturn.job.console.domain.ZkCluster) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException)

Example 2 with ZkCluster

use of com.vip.saturn.job.console.domain.ZkCluster in project Saturn by vipshop.

the class JobConfigInitializationServiceImpl method getRegistryCenterConfigurations.

@Override
public List<RegistryCenterConfiguration> getRegistryCenterConfigurations() throws SaturnJobConsoleException {
    Collection<ZkCluster> zkClusterList = registryCenterService.getZkClusterList();
    List<RegistryCenterConfiguration> rccs = new ArrayList<>();
    if (zkClusterList != null) {
        for (ZkCluster zkCluster : zkClusterList) {
            if (zkCluster != null && !zkCluster.isOffline()) {
                rccs.addAll(zkCluster.getRegCenterConfList());
            }
        }
    }
    return rccs;
}
Also used : RegistryCenterConfiguration(com.vip.saturn.job.console.domain.RegistryCenterConfiguration) ArrayList(java.util.ArrayList) ZkCluster(com.vip.saturn.job.console.domain.ZkCluster)

Example 3 with ZkCluster

use of com.vip.saturn.job.console.domain.ZkCluster in project Saturn by vipshop.

the class JobConfigInitializationServiceImpl method exportToDbByZkCluster.

private void exportToDbByZkCluster(String userName, ZkCluster tmp, ExportJobConfigPageStatus exportJobConfigPageStatus) throws SaturnJobConsoleException {
    log.info(" start to export db by single zkCluster, zkCluster Addr is :{}", tmp.getZkAddr());
    ZkCluster zkCluster = tmp;
    ArrayList<RegistryCenterConfiguration> oldRccs = zkCluster.getRegCenterConfList();
    ArrayList<RegistryCenterConfiguration> rccs = new ArrayList<RegistryCenterConfiguration>(oldRccs);
    for (RegistryCenterConfiguration rcc : rccs) {
        List<String> jobNames = getAllUnSystemJobs(rcc.getNamespace(), zkCluster.getCuratorFramework());
        for (String jobName : jobNames) {
            try {
                JobSettings jobSettings = getJobSettings(jobName, rcc, zkCluster.getCuratorFramework());
                CurrentJobConfig current = mapper.map(jobSettings, CurrentJobConfig.class);
                current.setCreateBy(userName);
                current.setCreateTime(new Date());
                current.setLastUpdateBy(userName);
                current.setLastUpdateTime(new Date());
                current.setNamespace(rcc.getNamespace());
                currentJobConfigService.create(current);
            } catch (Exception e) {
                log.error(e.getMessage(), e);
                throw new SaturnJobConsoleException(e.getMessage());
            }
        }
        exportJobConfigPageStatus.setSuccessJobNum(exportJobConfigPageStatus.getSuccessJobNum() + jobNames.size());
        exportJobConfigPageStatus.setSuccessNamespaceNum(exportJobConfigPageStatus.getSuccessNamespaceNum() + 1);
        temporarySharedStatusService.update(ShareStatusModuleNames.EXPORT_JOB_CONFIG_PAGE_STATUS, gson.toJson(exportJobConfigPageStatus));
    }
    log.info("export db by single zkCluster successfully, zkCluster Addr is :{}", tmp.getZkAddr());
}
Also used : RegistryCenterConfiguration(com.vip.saturn.job.console.domain.RegistryCenterConfiguration) JobSettings(com.vip.saturn.job.console.domain.JobSettings) CurrentJobConfig(com.vip.saturn.job.console.mybatis.entity.CurrentJobConfig) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) ArrayList(java.util.ArrayList) ZkCluster(com.vip.saturn.job.console.domain.ZkCluster) Date(java.util.Date) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException)

Example 4 with ZkCluster

use of com.vip.saturn.job.console.domain.ZkCluster in project Saturn by vipshop.

the class NamespaceZkClusterMappingServiceImpl method moveNamespaceTo.

@Transactional(rollbackFor = { SaturnJobConsoleException.class })
@Override
public void moveNamespaceTo(String namespace, String zkClusterKeyNew, String lastUpdatedBy, boolean updateDBOnly) throws SaturnJobConsoleException {
    try {
        log.info("start move {} to {}", namespace, zkClusterKeyNew);
        if (updateDBOnly) {
            namespaceZkclusterMapping4SqlService.update(namespace, null, zkClusterKeyNew, lastUpdatedBy);
        } else {
            String zkClusterKey = namespaceZkclusterMapping4SqlService.getZkClusterKey(namespace);
            if (zkClusterKey != null && zkClusterKey.equals(zkClusterKeyNew)) {
                // see
                throw new SaturnJobConsoleException("The namespace(" + namespace + ") is in " + zkClusterKey);
            // moveNamespaceBatchTo
            // before
            // modify
            }
            ZkCluster zkCluster = registryCenterService.getZkCluster(zkClusterKeyNew);
            if (zkCluster == null) {
                throw new SaturnJobConsoleException("The " + zkClusterKeyNew + " is not exists");
            }
            if (zkCluster.isOffline()) {
                throw new SaturnJobConsoleException("The " + zkClusterKeyNew + " zkCluster is offline");
            }
            String zkAddr = zkCluster.getZkAddr();
            CuratorRepository.CuratorFrameworkOp curatorFrameworkOp = registryCenterService.connectOnly(zkAddr, null);
            if (curatorFrameworkOp == null) {
                throw new SaturnJobConsoleException("The " + zkClusterKeyNew + " zkCluster is offline");
            }
            CuratorFramework curatorFramework = curatorFrameworkOp.getCuratorFramework();
            CuratorRepository.CuratorFrameworkOp curatorFrameworkOpByNamespace = registryCenterService.connectOnly(zkAddr, namespace);
            CuratorFramework curatorFrameworkByNamespace = curatorFrameworkOpByNamespace.getCuratorFramework();
            try {
                String namespaceNodePath = "/" + namespace;
                if (curatorFramework.checkExists().forPath(namespaceNodePath) != null) {
                    curatorFramework.delete().deletingChildrenIfNeeded().forPath(namespaceNodePath);
                }
                String jobsNodePath = namespaceNodePath + JobNodePath.get$JobsNodePath();
                curatorFramework.create().creatingParentsIfNeeded().withMode(CreateMode.PERSISTENT).forPath(jobsNodePath);
                List<CurrentJobConfig> configs = currentJobConfigService.findConfigsByNamespace(namespace);
                log.info("get configs success, {}", namespace);
                if (configs != null) {
                    for (CurrentJobConfig jobConfig : configs) {
                        jobOperationService.persistJobFromDB(jobConfig, curatorFrameworkOpByNamespace);
                        log.info("move {}-{} to zk success", namespace, jobConfig.getJobName());
                    }
                }
            } finally {
                curatorFramework.close();
                curatorFrameworkByNamespace.close();
            }
            log.info("move {} to zk {} success", namespace, zkClusterKeyNew);
            namespaceZkclusterMapping4SqlService.update(namespace, null, zkClusterKeyNew, lastUpdatedBy);
            log.info("update mapping table success, {}-{}", namespace, zkClusterKeyNew);
        }
    } catch (SaturnJobConsoleException e) {
        log.error(e.getMessage(), e);
        throw e;
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw new SaturnJobConsoleException(e);
    } finally {
        log.info("end move {} to {}", namespace, zkClusterKeyNew);
    }
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) CurrentJobConfig(com.vip.saturn.job.console.mybatis.entity.CurrentJobConfig) CuratorRepository(com.vip.saturn.job.console.repository.zookeeper.CuratorRepository) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) ZkCluster(com.vip.saturn.job.console.domain.ZkCluster) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with ZkCluster

use of com.vip.saturn.job.console.domain.ZkCluster in project Saturn by vipshop.

the class DashboardController method count.

@RequestMapping(value = "count", method = RequestMethod.POST)
@ResponseBody
public Map<String, Integer> count(Boolean allZkCluster, String zkClusterKey) {
    Map<String, Integer> countMap = new HashMap<>();
    int executorInDockerCount = 0;
    int executorNotInDockerCount = 0;
    int jobCount = 0;
    int domainCount = 0;
    if (allZkCluster != null && allZkCluster) {
        Collection<ZkCluster> zkClusterList = registryCenterService.getZkClusterList();
        for (ZkCluster zkCluster : zkClusterList) {
            String zkAddr = zkCluster.getZkAddr();
            if (zkAddr != null) {
                executorInDockerCount += dashboardService.executorInDockerCount(zkAddr);
                executorNotInDockerCount += dashboardService.executorNotInDockerCount(zkAddr);
                jobCount += dashboardService.jobCount(zkAddr);
            }
            String zck = zkCluster.getZkClusterKey();
            if (zck != null) {
                domainCount += registryCenterService.domainCount(zck);
            }
        }
    } else {
        ZkCluster zkCluster = registryCenterService.getZkCluster(zkClusterKey);
        if (zkCluster != null) {
            executorInDockerCount = dashboardService.executorInDockerCount(zkCluster.getZkAddr());
            executorNotInDockerCount = dashboardService.executorNotInDockerCount(zkCluster.getZkAddr());
            jobCount = dashboardService.jobCount(zkCluster.getZkAddr());
            domainCount = registryCenterService.domainCount(zkCluster.getZkClusterKey());
        }
    }
    countMap.put("executorInDockerCount", executorInDockerCount);
    countMap.put("executorNotInDockerCount", executorNotInDockerCount);
    countMap.put("jobCount", jobCount);
    countMap.put("domainCount", domainCount);
    return countMap;
}
Also used : HashMap(java.util.HashMap) ZkCluster(com.vip.saturn.job.console.domain.ZkCluster) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

ZkCluster (com.vip.saturn.job.console.domain.ZkCluster)37 SuccessResponseEntity (com.vip.saturn.job.console.controller.SuccessResponseEntity)11 ApiResponses (io.swagger.annotations.ApiResponses)11 SaturnJobConsoleException (com.vip.saturn.job.console.exception.SaturnJobConsoleException)9 SaturnStatistics (com.vip.saturn.job.console.mybatis.entity.SaturnStatistics)8 Entry (java.util.Map.Entry)8 RegistryCenterConfiguration (com.vip.saturn.job.console.domain.RegistryCenterConfiguration)7 HashMap (java.util.HashMap)5 Transactional (org.springframework.transaction.annotation.Transactional)5 SaturnJobConsoleHttpException (com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException)4 ArrayList (java.util.ArrayList)4 CuratorRepository (com.vip.saturn.job.console.repository.zookeeper.CuratorRepository)3 CurrentJobConfig (com.vip.saturn.job.console.mybatis.entity.CurrentJobConfig)2 NamespaceInfo (com.vip.saturn.job.console.mybatis.entity.NamespaceInfo)2 CuratorFramework (org.apache.curator.framework.CuratorFramework)2 JSONObject (com.alibaba.fastjson.JSONObject)1 Audit (com.vip.saturn.job.console.aop.annotation.Audit)1 ExportJobConfigPageStatus (com.vip.saturn.job.console.domain.ExportJobConfigPageStatus)1 JobSettings (com.vip.saturn.job.console.domain.JobSettings)1 TreeNode (com.vip.saturn.job.console.domain.TreeNode)1