Search in sources :

Example 21 with ZkCluster

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

the class RegistryCenterServiceImpl method bindNamespaceAndZkCluster.

@Transactional(rollbackFor = { Exception.class })
@Override
public void bindNamespaceAndZkCluster(String namespace, String zkClusterKey, String updatedBy) throws SaturnJobConsoleException {
    ZkCluster currentCluster = 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));
    }
    // namespace必须要存在
    if (!checkNamespaceExists(namespace)) {
        throw new SaturnJobConsoleHttpException(HttpStatus.BAD_REQUEST.value(), ERR_MSG_NS_NOT_FOUND);
    }
    // 判断其它集群是否有该域
    String zkClusterKeyOther = namespaceZkClusterMapping4SqlService.getZkClusterKey(namespace);
    if (zkClusterKeyOther != null) {
        ZkCluster zkClusterOther = getZkCluster(zkClusterKeyOther);
        if (zkClusterOther == null) {
            throw new SaturnJobConsoleException("zk cluster 不存在:" + zkClusterKeyOther);
        }
        if (zkClusterOther.getZkClusterKey().equals(zkClusterKey)) {
            throw new SaturnJobConsoleException("Namespace已经存在于此zk集群,不能重复添加");
        } else {
            throw new SaturnJobConsoleException("Namespace存在于另外的zk集群:" + zkClusterOther.getZkClusterKey() + ",不能重复添加");
        }
    }
    try {
        namespaceZkClusterMapping4SqlService.insert(namespace, "", zkClusterKey, updatedBy);
        postBindNamespaceAndZkCluster(namespace, currentCluster);
        // refresh
        notifyRefreshRegCenter();
    } catch (Exception e) {
        namespaceZkClusterMapping4SqlService.remove(namespace, updatedBy);
        throw new SaturnJobConsoleException(e.getMessage());
    }
}
Also used : SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) ZkCluster(com.vip.saturn.job.console.domain.ZkCluster) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 22 with ZkCluster

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

the class RegistryCenterServiceImpl method exportNamespaceInfo.

@Override
public File exportNamespaceInfo(List<String> namespaceList) throws SaturnJobConsoleException {
    Set<String> targetNamespaceSet = null;
    if (namespaceList != null) {
        targetNamespaceSet = Sets.newHashSet(namespaceList);
    }
    List<RegistryCenterConfiguration> namespaceInfoList = Lists.newLinkedList();
    Collection<ZkCluster> zkClusterList = getZkClusterList();
    for (ZkCluster zkCluster : zkClusterList) {
        List<RegistryCenterConfiguration> namespacesOfZkCluster = zkCluster.getRegCenterConfList();
        for (RegistryCenterConfiguration ns : namespacesOfZkCluster) {
            if (targetNamespaceSet == null || targetNamespaceSet.contains(ns.getNamespace())) {
                namespaceInfoList.add(ns);
            }
        }
    }
    return exportNamespaceInfo2Excel(namespaceInfoList);
}
Also used : RegistryCenterConfiguration(com.vip.saturn.job.console.domain.RegistryCenterConfiguration) ZkCluster(com.vip.saturn.job.console.domain.ZkCluster)

Example 23 with ZkCluster

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

the class RegistryCenterServiceImpl method refreshNamespaceShardingListenerManagerMap.

/**
 * 创建或者移除namespaceShardingManager.
 */
private void refreshNamespaceShardingListenerManagerMap() {
    Iterator<Entry<String, ZkCluster>> iterator = zkClusterMap.entrySet().iterator();
    while (iterator.hasNext()) {
        Entry<String, ZkCluster> next = iterator.next();
        ZkCluster zkCluster = next.getValue();
        ArrayList<RegistryCenterConfiguration> regCenterConfList = zkCluster.getRegCenterConfList();
        if (regCenterConfList == null) {
            continue;
        }
        for (RegistryCenterConfiguration conf : regCenterConfList) {
            String nns = conf.getNameAndNamespace();
            if (!namespaceShardingListenerManagerMap.containsKey(nns)) {
                if (isZKClusterCanBeComputed(conf.getZkClusterKey())) {
                    createNamespaceShardingManager(conf, nns);
                }
            } else {
                NamespaceShardingManager namespaceShardingManager = namespaceShardingListenerManagerMap.get(nns);
                if (!isZKClusterCanBeComputed(conf.getZkClusterKey())) {
                    namespaceShardingManager.stopWithCurator();
                    namespaceShardingListenerManagerMap.remove(nns);
                }
            }
        }
    }
}
Also used : Entry(java.util.Map.Entry) RegistryCenterConfiguration(com.vip.saturn.job.console.domain.RegistryCenterConfiguration) NamespaceShardingManager(com.vip.saturn.job.sharding.NamespaceShardingManager) ZkCluster(com.vip.saturn.job.console.domain.ZkCluster)

Example 24 with ZkCluster

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

the class RegistryCenterServiceImpl method getZkClusterInfo.

private Map<String, ZkCluster> getZkClusterInfo() {
    LinkedHashMap<String, ZkCluster> newClusterMap = new LinkedHashMap<>();
    List<ZkClusterInfo> allZkClusterInfoList = zkClusterInfoService.getAllZkClusterInfo();
    if (allZkClusterInfoList != null) {
        for (ZkClusterInfo zkClusterInfo : allZkClusterInfoList) {
            ZkCluster zkCluster = new ZkCluster();
            zkCluster.setZkClusterKey(zkClusterInfo.getZkClusterKey());
            zkCluster.setZkAlias(zkClusterInfo.getAlias());
            zkCluster.setZkAddr(zkClusterInfo.getConnectString());
            zkCluster.setDescription(zkClusterInfo.getDescription());
            newClusterMap.put(zkClusterInfo.getZkClusterKey(), zkCluster);
        }
    }
    return newClusterMap;
}
Also used : ZkCluster(com.vip.saturn.job.console.domain.ZkCluster) ZkClusterInfo(com.vip.saturn.job.console.mybatis.entity.ZkClusterInfo)

Example 25 with ZkCluster

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

the class RegistryCenterServiceImpl method connectToZkClusterIfPossible.

private void connectToZkClusterIfPossible(Map<String, ZkCluster> newClusterMap) {
    Iterator<Entry<String, ZkCluster>> iterator = newClusterMap.entrySet().iterator();
    while (iterator.hasNext()) {
        Entry<String, ZkCluster> next = iterator.next();
        ZkCluster zkCluster = next.getValue();
        CuratorRepository.CuratorFrameworkOp curatorFrameworkOp = zkCluster.getCuratorFrameworkOp();
        if (curatorFrameworkOp == null) {
            createNewConnect(zkCluster);
            if (!zkCluster.isOffline()) {
                updateExecutorConfigToZkIfNecessary(zkCluster);
            }
        }
    }
}
Also used : Entry(java.util.Map.Entry) CuratorRepository(com.vip.saturn.job.console.repository.zookeeper.CuratorRepository) ZkCluster(com.vip.saturn.job.console.domain.ZkCluster)

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