Search in sources :

Example 16 with RegistryCenterConfiguration

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

the class RegistryCenterServiceImpl method connect.

@Override
public RegistryCenterClient connect(final String nameAndNameSpace) {
    final RegistryCenterClient registryCenterClient = new RegistryCenterClient();
    registryCenterClient.setNameAndNamespace(nameAndNameSpace);
    if (nameAndNameSpace == null) {
        return registryCenterClient;
    }
    synchronized (getNnsLock(nameAndNameSpace)) {
        if (!registryCenterClientMap.containsKey(nameAndNameSpace)) {
            RegistryCenterConfiguration registryCenterConfiguration = findConfig(nameAndNameSpace);
            if (registryCenterConfiguration == null) {
                return registryCenterClient;
            }
            String zkAddressList = registryCenterConfiguration.getZkAddressList();
            String namespace = registryCenterConfiguration.getNamespace();
            String digest = registryCenterConfiguration.getDigest();
            registryCenterClient.setZkAddr(zkAddressList);
            CuratorFramework client = curatorRepository.connect(zkAddressList, namespace, digest);
            if (client == null) {
                return registryCenterClient;
            }
            registryCenterClient.setConnected(client.getZookeeperClient().isConnected());
            registryCenterClient.setCuratorClient(client);
            registryCenterClientMap.put(nameAndNameSpace, registryCenterClient);
            return registryCenterClient;
        } else {
            RegistryCenterClient registryCenterClient2 = registryCenterClientMap.get(nameAndNameSpace);
            if (registryCenterClient2 != null) {
                if (registryCenterClient2.getCuratorClient() != null) {
                    registryCenterClient2.setConnected(registryCenterClient2.getCuratorClient().getZookeeperClient().isConnected());
                } else {
                    registryCenterClient2.setConnected(false);
                }
                return registryCenterClient2;
            }
            return registryCenterClient;
        }
    }
}
Also used : RegistryCenterConfiguration(com.vip.saturn.job.console.domain.RegistryCenterConfiguration) CuratorFramework(org.apache.curator.framework.CuratorFramework) RegistryCenterClient(com.vip.saturn.job.console.domain.RegistryCenterClient)

Example 17 with RegistryCenterConfiguration

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

the class RegistryCenterServiceImpl method initOrUpdateNamespace.

private void initOrUpdateNamespace(List<String> allOnlineNamespacesTemp, ZkCluster zkCluster, List<NamespaceZkClusterMapping> nsZkClusterMappingList, List<RegistryCenterConfiguration> regCenterConfList) {
    if (nsZkClusterMappingList == null || zkCluster.isOffline()) {
        return;
    }
    CuratorRepository.CuratorFrameworkOp curatorFrameworkOp = zkCluster.getCuratorFrameworkOp();
    ArrayList<RegistryCenterConfiguration> newRegCenterConfList = new ArrayList<>();
    try {
        for (NamespaceZkClusterMapping mapping : nsZkClusterMappingList) {
            String namespace = mapping.getNamespace();
            // 过滤$SaturnSelf
            if (SaturnSelfNodePath.ROOT_NAME.equals(namespace)) {
                continue;
            }
            // 如果这个标记为true,意味是新域,或者是迁移过来的域
            boolean isNamespaceNotIncludeInOriginRegCenerConfList = false;
            if (isNamespaceNotIncludeInRegCenterConfList(namespace, regCenterConfList)) {
                // 对于新添加的域,需要初始化一些znode
                initNamespaceZkNodeIfNecessary(namespace, curatorFrameworkOp);
                isNamespaceNotIncludeInOriginRegCenerConfList = true;
            }
            try {
                if (isNamespaceNotIncludeInOriginRegCenerConfList || isNewerVersionSaturnNamespace(namespace, curatorFrameworkOp)) {
                    NamespaceInfo namespaceInfo = getNamespaceInfo(namespace);
                    if (namespaceInfo == null && !isNamespaceInfoNotFoundCanBeCalculate()) {
                        log.warn("No info about namespace {}, just skip it.", namespace);
                        continue;
                    }
                    RegistryCenterConfiguration conf = new RegistryCenterConfiguration(mapping.getName(), namespace, zkCluster.getZkAddr());
                    conf.setZkClusterKey(zkCluster.getZkClusterKey());
                    conf.setVersion(getVersion(namespace, curatorFrameworkOp));
                    conf.setZkAlias(zkCluster.getZkAlias());
                    if (namespaceInfo != null) {
                        postConstructRegistryCenterConfiguration(conf, namespaceInfo.getContent());
                    }
                    newRegCenterConfList.add(conf);
                    if (!allOnlineNamespacesTemp.contains(namespace)) {
                        allOnlineNamespacesTemp.add(namespace);
                    }
                }
            } catch (Exception e) {
                log.error(e.getMessage(), e);
            }
        }
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }
    // 如果nns有改变,则需要关闭旧的
    if (regCenterConfList != null) {
        for (RegistryCenterConfiguration conf : regCenterConfList) {
            String namespace = conf.getNamespace();
            String nns = conf.getNameAndNamespace();
            for (RegistryCenterConfiguration confNew : newRegCenterConfList) {
                String namespaceNew = confNew.getNamespace();
                if (namespace.equals(namespaceNew)) {
                    String nnsNew = confNew.getNameAndNamespace();
                    if (!nns.equals(nnsNew)) {
                        synchronized (getNnsLock(nns)) {
                            closeNamespace(nns);
                            log.info("closed the namespace info because it's nns is changed, namespace is {}", namespace);
                        }
                    }
                    break;
                }
            }
        }
    }
    int oldSize = regCenterConfList != null ? regCenterConfList.size() : 0;
    if (oldSize != newRegCenterConfList.size()) {
        log.info("Zkcluster [{}] namespace size change from {} to {}", zkCluster.getZkClusterKey(), oldSize, newRegCenterConfList.size());
    }
    zkCluster.setRegCenterConfList(newRegCenterConfList);
}
Also used : NamespaceZkClusterMapping(com.vip.saturn.job.console.mybatis.entity.NamespaceZkClusterMapping) RegistryCenterConfiguration(com.vip.saturn.job.console.domain.RegistryCenterConfiguration) CuratorRepository(com.vip.saturn.job.console.repository.zookeeper.CuratorRepository) NamespaceInfo(com.vip.saturn.job.console.mybatis.entity.NamespaceInfo) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException)

Example 18 with RegistryCenterConfiguration

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

the class RegistryCenterServiceImpl method connectByNamespace.

@Override
public RegistryCenterClient connectByNamespace(String namespace) {
    RegistryCenterConfiguration registryCenterConfiguration = findConfigByNamespace(namespace);
    if (registryCenterConfiguration == null) {
        return new RegistryCenterClient();
    }
    String nns = registryCenterConfiguration.getNameAndNamespace();
    if (nns == null) {
        return new RegistryCenterClient();
    }
    String zkAddressList = registryCenterConfiguration.getZkAddressList();
    String digest = registryCenterConfiguration.getDigest();
    synchronized (getNnsLock(nns)) {
        if (!registryCenterClientMap.containsKey(nns)) {
            final RegistryCenterClient registryCenterClient = new RegistryCenterClient();
            registryCenterClient.setNameAndNamespace(nns);
            registryCenterClient.setZkAddr(zkAddressList);
            CuratorFramework client = curatorRepository.connect(zkAddressList, namespace, digest);
            if (client == null) {
                return registryCenterClient;
            }
            registryCenterClient.setConnected(client.getZookeeperClient().isConnected());
            registryCenterClient.setCuratorClient(client);
            registryCenterClientMap.put(nns, registryCenterClient);
            return registryCenterClient;
        } else {
            RegistryCenterClient registryCenterClient = registryCenterClientMap.get(nns);
            if (registryCenterClient == null) {
                registryCenterClient = new RegistryCenterClient();
                registryCenterClient.setNameAndNamespace(namespace);
                registryCenterClient.setZkAddr(zkAddressList);
            } else {
                if (registryCenterClient.getCuratorClient() != null) {
                    registryCenterClient.setConnected(registryCenterClient.getCuratorClient().getZookeeperClient().isConnected());
                } else {
                    registryCenterClient.setConnected(false);
                }
            }
            return registryCenterClient;
        }
    }
}
Also used : RegistryCenterConfiguration(com.vip.saturn.job.console.domain.RegistryCenterConfiguration) CuratorFramework(org.apache.curator.framework.CuratorFramework) RegistryCenterClient(com.vip.saturn.job.console.domain.RegistryCenterClient)

Example 19 with RegistryCenterConfiguration

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

the class ZkDBDiffServiceImpl method initCuratorClient.

private CuratorRepository.CuratorFrameworkOp initCuratorClient(String namespace) {
    RegistryCenterConfiguration registryCenterConfiguration = registryCenterService.findConfigByNamespace(namespace);
    if (registryCenterConfiguration == null) {
        String errMsg = String.format(NAMESPACE_NOT_EXIST_TEMPLATE, namespace);
        log.warn(ERR_MSG_SKIP_DIFF, namespace, errMsg);
        return null;
    }
    RegistryCenterClient registryCenterClient = registryCenterService.connectByNamespace(namespace);
    if (registryCenterClient != null && registryCenterClient.isConnected()) {
        return curatorRepository.newCuratorFrameworkOp(registryCenterClient.getCuratorClient());
    }
    log.warn(ERR_MSG_SKIP_DIFF, namespace, "fail to connect to zk.");
    return null;
}
Also used : RegistryCenterConfiguration(com.vip.saturn.job.console.domain.RegistryCenterConfiguration) RegistryCenterClient(com.vip.saturn.job.console.domain.RegistryCenterClient)

Example 20 with RegistryCenterConfiguration

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

the class InitRegistryCenterService method initTreeJson.

/**
 * transfer /a/b/b1, /a/b/b2 to {"title":"a", "children":["title":"b", "children": ["title": b1, "title": b2]]}
 *
 * @param registryCenterConfiguration 注册中心配置类
 */
public static void initTreeJson(Set<RegistryCenterConfiguration> registryCenterConfiguration) {
    TreeNode treeData = new TreeNode();
    for (RegistryCenterConfiguration conf : registryCenterConfiguration) {
        String nameAndnameSpace = conf.getNameAndNamespace();
        if (nameAndnameSpace.startsWith("/")) {
            nameAndnameSpace = nameAndnameSpace.substring(1);
        }
        treeData = parseDirectory2Tree(nameAndnameSpace, treeData, conf.getNameAndNamespace(), conf.getDegree());
    }
    log.info("init tree data: {}", treeData);
}
Also used : RegistryCenterConfiguration(com.vip.saturn.job.console.domain.RegistryCenterConfiguration) TreeNode(com.vip.saturn.job.console.domain.TreeNode)

Aggregations

RegistryCenterConfiguration (com.vip.saturn.job.console.domain.RegistryCenterConfiguration)31 RegistryCenterClient (com.vip.saturn.job.console.domain.RegistryCenterClient)9 SaturnJobConsoleException (com.vip.saturn.job.console.exception.SaturnJobConsoleException)9 ZkCluster (com.vip.saturn.job.console.domain.ZkCluster)7 CuratorFramework (org.apache.curator.framework.CuratorFramework)7 SaturnJobConsoleHttpException (com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException)4 NamespaceZkClusterMapping (com.vip.saturn.job.console.mybatis.entity.NamespaceZkClusterMapping)4 CuratorRepository (com.vip.saturn.job.console.repository.zookeeper.CuratorRepository)4 ArrayList (java.util.ArrayList)3 TreeNode (com.vip.saturn.job.console.domain.TreeNode)2 NamespaceInfo (com.vip.saturn.job.console.mybatis.entity.NamespaceInfo)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 JobSettings (com.vip.saturn.job.console.domain.JobSettings)1 RequestResult (com.vip.saturn.job.console.domain.RequestResult)1 CurrentJobConfig (com.vip.saturn.job.console.mybatis.entity.CurrentJobConfig)1 DashboardLeaderHandler (com.vip.saturn.job.console.service.cache.DashboardLeaderHandler)1 NamespaceShardingManager (com.vip.saturn.job.sharding.NamespaceShardingManager)1 File (java.io.File)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1