Search in sources :

Example 11 with RegistryCenterConfiguration

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

the class RegistryCenterServiceImpl method closeMoveOutNamespace.

private void closeMoveOutNamespace(String zkClusterKey, List<NamespaceZkClusterMapping> nsZkClusterMappingList, List<RegistryCenterConfiguration> regCenterConfList) {
    if (regCenterConfList == null) {
        return;
    }
    Iterator<RegistryCenterConfiguration> regIter = regCenterConfList.iterator();
    while (regIter.hasNext()) {
        RegistryCenterConfiguration conf = regIter.next();
        String namespace = conf.getNamespace();
        String nns = conf.getNameAndNamespace();
        boolean include = false;
        if (nsZkClusterMappingList != null) {
            for (NamespaceZkClusterMapping mapping : nsZkClusterMappingList) {
                if (namespace.equals(mapping.getNamespace())) {
                    include = true;
                    break;
                }
            }
        }
        if (!include) {
            synchronized (getNnsLock(nns)) {
                regIter.remove();
                closeNamespace(nns);
                log.info("closed the moved namespace info, namespace is {}, old zkClusterKey is {}", namespace, zkClusterKey);
            }
        }
    }
}
Also used : NamespaceZkClusterMapping(com.vip.saturn.job.console.mybatis.entity.NamespaceZkClusterMapping) RegistryCenterConfiguration(com.vip.saturn.job.console.domain.RegistryCenterConfiguration)

Example 12 with RegistryCenterConfiguration

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

the class RegistryCenterServiceImpl method findConfigsByZkCluster.

@Override
public List<RegistryCenterConfiguration> findConfigsByZkCluster(ZkCluster zkCluster) {
    List<String> namespaces = namespaceZkClusterMapping4SqlService.getAllNamespacesOfCluster(zkCluster.getZkClusterKey());
    if (namespaces == null || namespaces.isEmpty()) {
        return Lists.newArrayList();
    }
    List<RegistryCenterConfiguration> configs = Lists.newArrayList();
    for (String namespace : namespaces) {
        RegistryCenterConfiguration config = constructRegistryCenterConfiguration(zkCluster, namespace);
        configs.add(config);
    }
    return configs;
}
Also used : RegistryCenterConfiguration(com.vip.saturn.job.console.domain.RegistryCenterConfiguration)

Example 13 with RegistryCenterConfiguration

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

the class RegistryCenterServiceImpl method closeZkCluster.

/**
 * Close dashboardLeaderTreeCache, registryCenterClient, namespaceShardingListenerManager with this zkCluster
 */
private void closeZkCluster(ZkCluster zkCluster) {
    try {
        try {
            DashboardLeaderHandler dashboardLeaderHandler = dashboardLeaderTreeCacheMap.remove(zkCluster.getZkClusterKey());
            if (dashboardLeaderHandler != null) {
                dashboardLeaderHandler.shutdown();
            }
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
        ArrayList<RegistryCenterConfiguration> regCenterConfList = zkCluster.getRegCenterConfList();
        if (regCenterConfList != null) {
            for (RegistryCenterConfiguration conf : regCenterConfList) {
                String nns = conf.getNameAndNamespace();
                synchronized (getNnsLock(nns)) {
                    closeNamespace(nns);
                }
            }
        }
        if (zkCluster.getConnectionListener() != null) {
            zkCluster.getConnectionListener().shutdownNowUntilTerminated();
            zkCluster.setConnectionListener(null);
        }
        if (zkCluster.getCuratorFrameworkOp() != null && zkCluster.getCuratorFrameworkOp().getCuratorFramework() != null) {
            zkCluster.getCuratorFrameworkOp().getCuratorFramework().close();
        }
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }
}
Also used : RegistryCenterConfiguration(com.vip.saturn.job.console.domain.RegistryCenterConfiguration) DashboardLeaderHandler(com.vip.saturn.job.console.service.cache.DashboardLeaderHandler) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException)

Example 14 with RegistryCenterConfiguration

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

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

the class RegistryCenterServiceImpl method getCuratorFrameworkOp.

@Override
public CuratorRepository.CuratorFrameworkOp getCuratorFrameworkOp(String namespace) throws SaturnJobConsoleException {
    CuratorRepository.CuratorFrameworkOp curatorFrameworkOp = null;
    try {
        RegistryCenterConfiguration registryCenterConfiguration = findConfigByNamespace(namespace);
        if (registryCenterConfiguration == null) {
            throw new SaturnJobConsoleException("find registryCenterConfiguration failed");
        }
        String nns = registryCenterConfiguration.getNameAndNamespace();
        if (nns == null) {
            throw new SaturnJobConsoleException("get name and namespace failed");
        }
        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 curatorFramework = curatorRepository.connect(zkAddressList, namespace, digest);
                if (curatorFramework != null) {
                    registryCenterClient.setConnected(curatorFramework.getZookeeperClient().isConnected());
                    registryCenterClient.setCuratorClient(curatorFramework);
                    registryCenterClientMap.put(nns, registryCenterClient);
                    curatorFrameworkOp = curatorRepository.newCuratorFrameworkOp(curatorFramework);
                }
            } else {
                RegistryCenterClient registryCenterClient = registryCenterClientMap.get(nns);
                if (registryCenterClient != null) {
                    CuratorFramework curatorFramework = registryCenterClient.getCuratorClient();
                    if (curatorFramework != null) {
                        registryCenterClient.setConnected(curatorFramework.getZookeeperClient().isConnected());
                        curatorFrameworkOp = curatorRepository.newCuratorFrameworkOp(curatorFramework);
                    }
                }
            }
        }
    } catch (SaturnJobConsoleException e) {
        throw e;
    } catch (Exception e) {
        throw new SaturnJobConsoleException(e);
    }
    if (curatorFrameworkOp == null) {
        throw new SaturnJobConsoleException("Connect zookeeper failed");
    }
    return curatorFrameworkOp;
}
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) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException)

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