Search in sources :

Example 6 with NamespaceZkClusterMapping

use of com.vip.saturn.job.console.mybatis.entity.NamespaceZkClusterMapping in project Saturn by vipshop.

the class NamespaceAndJobServiceImpl method createNamespaceAndCloneJobs.

@Override
public void createNamespaceAndCloneJobs(String srcNamespace, String namespace, String zkClusterName, String createBy) throws SaturnJobConsoleException {
    logger.info("start createNamespaceAndCloneJobs, srcNamespace: {}, namespace: {}, zkClusterName: {}", srcNamespace, namespace, zkClusterName);
    NamespaceZkClusterMapping mapping = namespaceZkClusterMappingRepository.selectByNamespace(srcNamespace);
    if (mapping == null) {
        throw new SaturnJobConsoleException("no zkCluster mapping is not found");
    }
    NamespaceDomainInfo namespaceInfo = new NamespaceDomainInfo();
    namespaceInfo.setNamespace(namespace);
    namespaceInfo.setZkCluster(zkClusterName);
    namespaceInfo.setContent("");
    try {
        registryCenterService.createNamespace(namespaceInfo);
        registryCenterService.refreshRegistryCenterForNamespace(zkClusterName, srcNamespace);
    } catch (SaturnJobConsoleHttpException e) {
        if (StringUtils.equals(String.format(ERR_MSG_NS_ALREADY_EXIST, namespace), e.getMessage())) {
            logger.warn("namespace already exists, ignore this exception and move on");
        } else {
            throw e;
        }
    }
    namespaceService.importJobsFromNamespaceToNamespace(srcNamespace, namespace, createBy);
    logger.info("finish createNamespaceAndCloneJobs, srcNamespace: {}, namespace: {}, zkClusterName: {}", srcNamespace, namespace, zkClusterName);
}
Also used : NamespaceZkClusterMapping(com.vip.saturn.job.console.mybatis.entity.NamespaceZkClusterMapping) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) NamespaceDomainInfo(com.vip.saturn.job.console.domain.NamespaceDomainInfo) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException)

Example 7 with NamespaceZkClusterMapping

use of com.vip.saturn.job.console.mybatis.entity.NamespaceZkClusterMapping in project Saturn by vipshop.

the class NamespaceZkClusterMappingServiceImpl method getNamespaceZkClusterMappingList.

@Override
public List<NamespaceZkClusterMappingVo> getNamespaceZkClusterMappingList() throws SaturnJobConsoleException {
    List<NamespaceZkClusterMappingVo> result = new ArrayList<>();
    List<NamespaceZkClusterMapping> namespaceZkClusterMappingList = namespaceZkclusterMapping4SqlService.getAllMappings();
    if (namespaceZkClusterMappingList != null) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        for (NamespaceZkClusterMapping tmp : namespaceZkClusterMappingList) {
            try {
                if (tmp.getIsDeleted() == 0) {
                    NamespaceZkClusterMappingVo vo = new NamespaceZkClusterMappingVo();
                    vo.setNamespace(tmp.getNamespace());
                    vo.setZkClusterKey(tmp.getZkClusterKey());
                    vo.setCreateTime(sdf.format(tmp.getCreateTime()));
                    vo.setCreatedBy(tmp.getCreatedBy());
                    vo.setLastUpdateTime(sdf.format(tmp.getLastUpdateTime()));
                    vo.setLastUpdatedBy(tmp.getLastUpdatedBy());
                    result.add(vo);
                }
            } catch (Exception e) {
                log.error(e.getMessage(), e);
            }
        }
    }
    return result;
}
Also used : NamespaceZkClusterMapping(com.vip.saturn.job.console.mybatis.entity.NamespaceZkClusterMapping) ArrayList(java.util.ArrayList) NamespaceZkClusterMappingVo(com.vip.saturn.job.console.domain.NamespaceZkClusterMappingVo) SimpleDateFormat(java.text.SimpleDateFormat) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException)

Example 8 with NamespaceZkClusterMapping

use of com.vip.saturn.job.console.mybatis.entity.NamespaceZkClusterMapping in project Saturn by vipshop.

the class RegistryCenterServiceImpl method refreshRegistryCenter.

private void refreshRegistryCenter() {
    List<String> allOnlineNamespacesTemp = new ArrayList<>();
    // 获取新的zkClusters
    Map<String, ZkCluster> newClusterMap = getZkClusterInfo();
    // 对比旧的。不包含的,关闭操作;包含的,检查属性是否相同,如果相同,则直接赋值,否则,关闭旧的
    closeInvalidZkClient(newClusterMap);
    // 完善curatorFramework。如果没有,则新建
    connectToZkClusterIfPossible(newClusterMap);
    // 完善ZkCluster中的注册中心信息,关闭迁移了的域,新建迁移过来的域
    for (Map.Entry<String, ZkCluster> zkClusterEntry : newClusterMap.entrySet()) {
        ZkCluster zkCluster = zkClusterEntry.getValue();
        String key = zkClusterEntry.getKey();
        List<NamespaceZkClusterMapping> nsZkClusterMappingList = namespaceZkClusterMapping4SqlService.getAllMappingsOfCluster(key);
        // zkCluster对应的namespace列表
        List<RegistryCenterConfiguration> regCenterConfList = zkCluster.getRegCenterConfList();
        closeMoveOutNamespace(key, nsZkClusterMappingList, regCenterConfList);
        initOrUpdateNamespace(allOnlineNamespacesTemp, zkCluster, nsZkClusterMappingList, regCenterConfList);
    }
    // 直接赋值新的
    zkClusterMap = (LinkedHashMap<String, ZkCluster>) newClusterMap;
    log.info("new zkClusterMap is : {}", zkClusterMap);
    allOnlineNamespaces = allOnlineNamespacesTemp;
}
Also used : NamespaceZkClusterMapping(com.vip.saturn.job.console.mybatis.entity.NamespaceZkClusterMapping) RegistryCenterConfiguration(com.vip.saturn.job.console.domain.RegistryCenterConfiguration) ZkCluster(com.vip.saturn.job.console.domain.ZkCluster) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 9 with NamespaceZkClusterMapping

use of com.vip.saturn.job.console.mybatis.entity.NamespaceZkClusterMapping in project Saturn by vipshop.

the class RegistryCenterServiceImpl method getTargetNamespaceZkClusterMapping.

private List<NamespaceZkClusterMapping> getTargetNamespaceZkClusterMapping(String zkCluster, String namespace) {
    List<NamespaceZkClusterMapping> nsZkClusterMappingList = namespaceZkClusterMapping4SqlService.getAllMappingsOfCluster(zkCluster);
    List<NamespaceZkClusterMapping> filteredList = new ArrayList<>();
    for (NamespaceZkClusterMapping n : nsZkClusterMappingList) {
        if (n.getNamespace().equals(namespace)) {
            filteredList.add(n);
            break;
        }
    }
    return nsZkClusterMappingList;
}
Also used : NamespaceZkClusterMapping(com.vip.saturn.job.console.mybatis.entity.NamespaceZkClusterMapping)

Example 10 with NamespaceZkClusterMapping

use of com.vip.saturn.job.console.mybatis.entity.NamespaceZkClusterMapping in project Saturn by vipshop.

the class NamespaceZkClusterMapping4SqlServiceImpl method update.

@Transactional
@Override
public Integer update(String namespace, String name, String zkClusterKey, String lastUpdatedBy) {
    NamespaceZkClusterMapping namespaceZkClusterMapping = namespaceZkClusterMappingRepository.selectByNamespace(namespace);
    if (name != null) {
        namespaceZkClusterMapping.setName(name);
    }
    if (zkClusterKey != null) {
        namespaceZkClusterMapping.setZkClusterKey(zkClusterKey);
    }
    namespaceZkClusterMapping.setLastUpdatedBy(lastUpdatedBy);
    return namespaceZkClusterMappingRepository.updateById(namespaceZkClusterMapping);
}
Also used : NamespaceZkClusterMapping(com.vip.saturn.job.console.mybatis.entity.NamespaceZkClusterMapping) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

NamespaceZkClusterMapping (com.vip.saturn.job.console.mybatis.entity.NamespaceZkClusterMapping)11 RegistryCenterConfiguration (com.vip.saturn.job.console.domain.RegistryCenterConfiguration)4 Transactional (org.springframework.transaction.annotation.Transactional)4 SaturnJobConsoleException (com.vip.saturn.job.console.exception.SaturnJobConsoleException)3 SaturnJobConsoleHttpException (com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException)2 NamespaceInfo (com.vip.saturn.job.console.mybatis.entity.NamespaceInfo)2 ArrayList (java.util.ArrayList)2 NamespaceDomainInfo (com.vip.saturn.job.console.domain.NamespaceDomainInfo)1 NamespaceZkClusterMappingVo (com.vip.saturn.job.console.domain.NamespaceZkClusterMappingVo)1 ZkCluster (com.vip.saturn.job.console.domain.ZkCluster)1 CuratorRepository (com.vip.saturn.job.console.repository.zookeeper.CuratorRepository)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 CuratorFramework (org.apache.curator.framework.CuratorFramework)1