Search in sources :

Example 6 with RegistryCenterConfiguration

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

the class RegistryCenterServiceImpl method initMoveInNamespace.

private void initMoveInNamespace(List<String> allOnlineNamespacesTemp, String zkClusterKey, ZkCluster zkCluster, List<NamespaceZkClusterMapping> nsZkClusterMappingList, List<RegistryCenterConfiguration> regCenterConfList) {
    if (nsZkClusterMappingList == null || zkCluster.isOffline()) {
        return;
    }
    for (NamespaceZkClusterMapping mapping : nsZkClusterMappingList) {
        String namespace = mapping.getNamespace();
        String name = StringUtils.deleteWhitespace(mapping.getName());
        if (SaturnSelfNodePath.ROOT_NAME.equals(namespace)) {
            log.error("The namespace cannot be {}", SaturnSelfNodePath.ROOT_NAME);
            continue;
        }
        boolean include = false;
        if (regCenterConfList != null) {
            for (RegistryCenterConfiguration conf : regCenterConfList) {
                if (!namespace.equals(conf.getNamespace())) {
                    continue;
                }
                include = true;
                String nnsOld = conf.getNameAndNamespace();
                // update name
                conf.setName(name);
                conf.initNameAndNamespace();
                String nnsNew = conf.getNameAndNamespace();
                if (!nnsOld.equals(nnsNew)) {
                    synchronized (getNnsLock(nnsOld)) {
                        closeNamespace(nnsOld);
                        log.info("closed the namespace info because it's nns is changed, namespace is {}", namespace);
                    }
                }
                break;
            }
        }
        if (!include) {
            CuratorFramework curatorFramework = zkCluster.getCuratorFramework();
            initNamespaceZkNodeIfNecessary(namespace, curatorFramework);
            RegistryCenterConfiguration conf = new RegistryCenterConfiguration(name, namespace, zkCluster.getZkAddr());
            conf.setZkClusterKey(zkClusterKey);
            conf.setVersion(getVersion(namespace, curatorFramework));
            conf.setZkAlias(zkCluster.getZkAlias());
            NamespaceInfo namespaceInfo = getNamespaceInfo(namespace);
            if (namespaceInfo != null) {
                postConstructRegistryCenterConfiguration(conf, namespaceInfo.getContent());
            }
            zkCluster.getRegCenterConfList().add(conf);
        }
        if (!allOnlineNamespacesTemp.contains(namespace)) {
            allOnlineNamespacesTemp.add(namespace);
        }
    }
}
Also used : NamespaceZkClusterMapping(com.vip.saturn.job.console.mybatis.entity.NamespaceZkClusterMapping) RegistryCenterConfiguration(com.vip.saturn.job.console.domain.RegistryCenterConfiguration) CuratorFramework(org.apache.curator.framework.CuratorFramework) NamespaceInfo(com.vip.saturn.job.console.mybatis.entity.NamespaceInfo)

Example 7 with RegistryCenterConfiguration

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

the class ReuseUtils method reuse.

public static void reuse(String namespace, RegistryCenterService registryCenterService, CuratorRepository curatorRepository, ReuseCallBackWithoutReturn callBack) throws SaturnJobConsoleException {
    try {
        RegistryCenterConfiguration registryCenterConfiguration = registryCenterService.findConfigByNamespace(namespace);
        if (registryCenterConfiguration == null) {
            throw new SaturnJobConsoleException(ERROR_CODE_NOT_EXISTED, String.format(NAMESPACE_NOT_EXIST_TEMPLATE, namespace));
        }
        RegistryCenterClient registryCenterClient = registryCenterService.connectByNamespace(namespace);
        if (registryCenterClient != null && registryCenterClient.isConnected()) {
            CuratorFramework curatorClient = registryCenterClient.getCuratorClient();
            CuratorRepository.CuratorFrameworkOp curatorFrameworkOp = curatorRepository.newCuratorFrameworkOp(curatorClient);
            ThreadLocalCuratorClient.setCuratorClient(curatorClient);
            callBack.call(curatorFrameworkOp);
        } else {
            throw new SaturnJobConsoleException("Connect zookeeper failed");
        }
    } catch (SaturnJobConsoleException e) {
        throw e;
    } catch (Throwable t) {
        log.error(t.getMessage(), t);
        throw new SaturnJobConsoleException(t);
    } finally {
        ThreadLocalCuratorClient.clear();
    }
}
Also used : RegistryCenterConfiguration(com.vip.saturn.job.console.domain.RegistryCenterConfiguration) CuratorFramework(org.apache.curator.framework.CuratorFramework) CuratorRepository(com.vip.saturn.job.console.repository.zookeeper.CuratorRepository) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) RegistryCenterClient(com.vip.saturn.job.console.domain.RegistryCenterClient)

Example 8 with RegistryCenterConfiguration

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

the class RegistryCenterServiceImpl method updateRegistryCenterConfiguration.

private void updateRegistryCenterConfiguration(String namespace, String zkAddressList, String zkClusterName) {
    List<RegistryCenterConfiguration> sourceRegCenterConfList = zkClusterMap.get(zkClusterName).getRegCenterConfList();
    boolean regCenterConfAlreadyExisted = false;
    for (RegistryCenterConfiguration conf : sourceRegCenterConfList) {
        if (conf.getNamespace().equals(namespace)) {
            regCenterConfAlreadyExisted = true;
            break;
        }
    }
    if (!regCenterConfAlreadyExisted) {
        RegistryCenterConfiguration registryCenterConfiguration = new RegistryCenterConfiguration("", namespace, zkAddressList);
        zkClusterMap.get(zkClusterName).getRegCenterConfList().add(registryCenterConfiguration);
    }
}
Also used : RegistryCenterConfiguration(com.vip.saturn.job.console.domain.RegistryCenterConfiguration)

Example 9 with RegistryCenterConfiguration

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

the class RegistryCenterServiceImpl method constructRegistryCenterConfiguration.

protected RegistryCenterConfiguration constructRegistryCenterConfiguration(ZkCluster zkCluster, String namespace) {
    RegistryCenterConfiguration config = new RegistryCenterConfiguration("", namespace, zkCluster.getZkAddr());
    config.setZkClusterKey(zkCluster.getZkClusterKey());
    config.setZkAlias(zkCluster.getZkAlias());
    return config;
}
Also used : RegistryCenterConfiguration(com.vip.saturn.job.console.domain.RegistryCenterConfiguration)

Example 10 with RegistryCenterConfiguration

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

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