Search in sources :

Example 1 with ClusterMeta

use of com.ctrip.xpipe.redis.core.entity.ClusterMeta in project x-pipe by ctripcorp.

the class MetaServerPrepareResourcesAndStart method setupZkNodes.

private void setupZkNodes(CuratorFramework client, DcMeta dcMeta) throws Exception {
    for (ClusterMeta clusterMeta : dcMeta.getClusters().values()) {
        for (ShardMeta shardMeta : clusterMeta.getShards().values()) {
            String path = MetaZkConfig.getKeeperLeaderLatchPath(clusterMeta.getId(), shardMeta.getId());
            client.createContainers(path);
        }
    }
    String metaPath = MetaZkConfig.getMetaRootPath();
    client.createContainers(metaPath);
}
Also used : ClusterMeta(com.ctrip.xpipe.redis.core.entity.ClusterMeta) ShardMeta(com.ctrip.xpipe.redis.core.entity.ShardMeta)

Example 2 with ClusterMeta

use of com.ctrip.xpipe.redis.core.entity.ClusterMeta in project x-pipe by ctripcorp.

the class BaseSampleMonitor method generatePlan.

@Override
public Collection<BaseSamplePlan<T>> generatePlan(List<DcMeta> dcMetas) {
    Map<Pair<String, String>, BaseSamplePlan<T>> plans = new HashMap<>();
    for (DcMeta dcMeta : dcMetas) {
        for (ClusterMeta clusterMeta : dcMeta.getClusters().values()) {
            if (!addCluster(dcMeta.getId(), clusterMeta)) {
                continue;
            }
            for (ShardMeta shardMeta : clusterMeta.getShards().values()) {
                Pair<String, String> cs = new Pair<>(clusterMeta.getId(), shardMeta.getId());
                BaseSamplePlan<T> plan = plans.get(cs);
                if (plan == null) {
                    plan = createPlan(dcMeta.getId(), clusterMeta.getId(), shardMeta.getId());
                    plans.put(cs, plan);
                }
                for (RedisMeta redisMeta : shardMeta.getRedises()) {
                    log.debug("[generatePlan]{}", redisMeta.desc());
                    addRedis(plan, dcMeta.getId(), redisMeta);
                }
                if (plan.isEmpty()) {
                    plans.remove(cs);
                }
            }
        }
    }
    return plans.values();
}
Also used : ClusterMeta(com.ctrip.xpipe.redis.core.entity.ClusterMeta) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) DcMeta(com.ctrip.xpipe.redis.core.entity.DcMeta) ShardMeta(com.ctrip.xpipe.redis.core.entity.ShardMeta) RedisMeta(com.ctrip.xpipe.redis.core.entity.RedisMeta) Pair(com.ctrip.xpipe.tuple.Pair)

Example 3 with ClusterMeta

use of com.ctrip.xpipe.redis.core.entity.ClusterMeta in project x-pipe by ctripcorp.

the class DefaultRedisSessionManager method getInUseRedises.

private Set<HostPort> getInUseRedises() {
    Set<HostPort> redisInUse = new HashSet<>();
    List<DcMeta> dcMetas = new LinkedList<>(metaCache.getXpipeMeta().getDcs().values());
    if (dcMetas.isEmpty())
        return null;
    for (DcMeta dcMeta : dcMetas) {
        if (dcMeta == null)
            break;
        for (ClusterMeta clusterMeta : dcMeta.getClusters().values()) {
            for (ShardMeta shardMeta : clusterMeta.getShards().values()) {
                for (RedisMeta redisMeta : shardMeta.getRedises()) {
                    redisInUse.add(new HostPort(redisMeta.getIp(), redisMeta.getPort()));
                }
            }
        }
    }
    return redisInUse;
}
Also used : ClusterMeta(com.ctrip.xpipe.redis.core.entity.ClusterMeta) DcMeta(com.ctrip.xpipe.redis.core.entity.DcMeta) HostPort(com.ctrip.xpipe.endpoint.HostPort) ShardMeta(com.ctrip.xpipe.redis.core.entity.ShardMeta) RedisMeta(com.ctrip.xpipe.redis.core.entity.RedisMeta) LinkedList(java.util.LinkedList) HashSet(java.util.HashSet)

Example 4 with ClusterMeta

use of com.ctrip.xpipe.redis.core.entity.ClusterMeta in project x-pipe by ctripcorp.

the class ClusterMetaServiceImpl method loadClusterMeta.

@Override
public ClusterMeta loadClusterMeta(DcMeta dcMeta, ClusterTbl clusterTbl, DcMetaQueryVO dcMetaQueryVO) {
    ClusterMeta clusterMeta = new ClusterMeta();
    clusterTbl.setActivedcId(getClusterMetaCurrentPrimaryDc(dcMetaQueryVO.getCurrentDc(), clusterTbl));
    clusterMeta.setId(clusterTbl.getClusterName());
    for (DcClusterTbl dcCluster : dcMetaQueryVO.getAllDcClusterMap().get(clusterTbl.getId())) {
        if (dcCluster.getDcId() == clusterTbl.getActivedcId()) {
            clusterMeta.setActiveDc(dcMetaQueryVO.getAllDcs().get(dcCluster.getDcId()).getDcName());
        } else {
            if (Strings.isNullOrEmpty(clusterMeta.getBackupDcs())) {
                clusterMeta.setBackupDcs(dcMetaQueryVO.getAllDcs().get(dcCluster.getDcId()).getDcName());
            } else {
                clusterMeta.setBackupDcs(clusterMeta.getBackupDcs() + "," + dcMetaQueryVO.getAllDcs().get(dcCluster.getDcId()).getDcName());
            }
        }
    }
    clusterMeta.setParent(dcMeta);
    for (ShardTbl shard : dcMetaQueryVO.getShardMap().get(clusterTbl.getClusterName())) {
        clusterMeta.addShard(shardMetaService.loadShardMeta(clusterMeta, clusterTbl, shard, dcMetaQueryVO));
    }
    return clusterMeta;
}
Also used : ClusterMeta(com.ctrip.xpipe.redis.core.entity.ClusterMeta)

Example 5 with ClusterMeta

use of com.ctrip.xpipe.redis.core.entity.ClusterMeta in project x-pipe by ctripcorp.

the class ClusterMetaServiceImpl method getClusterMeta.

@Override
public ClusterMeta getClusterMeta(final String dcName, final String clusterName) {
    ExecutorService fixedThreadPool = Executors.newFixedThreadPool(5);
    Future<DcTbl> future_dcInfo = fixedThreadPool.submit(new Callable<DcTbl>() {

        @Override
        public DcTbl call() throws Exception {
            return dcService.find(dcName);
        }
    });
    Future<ClusterTbl> future_clusterInfo = fixedThreadPool.submit(new Callable<ClusterTbl>() {

        @Override
        public ClusterTbl call() throws Exception {
            return clusterService.find(clusterName);
        }
    });
    Future<DcClusterTbl> future_dcClusterInfo = fixedThreadPool.submit(new Callable<DcClusterTbl>() {

        @Override
        public DcClusterTbl call() throws Exception {
            return dcClusterService.find(dcName, clusterName);
        }
    });
    Future<List<ShardTbl>> future_shardsInfo = fixedThreadPool.submit(new Callable<List<ShardTbl>>() {

        @Override
        public List<ShardTbl> call() throws Exception {
            return shardService.findAllByClusterName(clusterName);
        }
    });
    Future<List<DcTbl>> future_clusterRelatedDc = fixedThreadPool.submit(new Callable<List<DcTbl>>() {

        @Override
        public List<DcTbl> call() throws Exception {
            return dcService.findClusterRelatedDc(clusterName);
        }
    });
    ClusterMeta clusterMeta = new ClusterMeta();
    clusterMeta.setId(clusterName);
    try {
        DcTbl dcInfo = future_dcInfo.get();
        ClusterTbl clusterInfo = future_clusterInfo.get();
        DcClusterTbl dcClusterInfo = future_dcClusterInfo.get();
        List<DcTbl> clusterRelatedDc = future_clusterRelatedDc.get();
        if (null == dcInfo || null == clusterInfo || null == dcClusterInfo)
            return clusterMeta;
        clusterMeta.setId(clusterInfo.getClusterName());
        clusterInfo.setActivedcId(getClusterMetaCurrentPrimaryDc(dcInfo, clusterInfo));
        for (DcTbl dc : clusterRelatedDc) {
            if (dc.getId() == clusterInfo.getActivedcId()) {
                clusterMeta.setActiveDc(dc.getDcName());
            } else {
                if (Strings.isNullOrEmpty(clusterMeta.getBackupDcs())) {
                    clusterMeta.setBackupDcs(dc.getDcName());
                } else {
                    clusterMeta.setBackupDcs(clusterMeta.getBackupDcs() + "," + dc.getDcName());
                }
            }
        }
        List<ShardTbl> shards = future_shardsInfo.get();
        if (null != shards) {
            for (ShardTbl shard : shards) {
                clusterMeta.addShard(shardMetaService.getShardMeta(dcInfo, clusterInfo, shard));
            }
        }
    } catch (ExecutionException e) {
        throw new DataNotFoundException("Cannot construct cluster-meta", e);
    } catch (InterruptedException e) {
        throw new ServerException("Concurrent execution failed.", e);
    } finally {
        fixedThreadPool.shutdown();
    }
    return clusterMeta;
}
Also used : DataNotFoundException(com.ctrip.xpipe.redis.console.exception.DataNotFoundException) List(java.util.List) ServerException(com.ctrip.xpipe.redis.console.exception.ServerException) ClusterMeta(com.ctrip.xpipe.redis.core.entity.ClusterMeta) ServerException(com.ctrip.xpipe.redis.console.exception.ServerException) DataNotFoundException(com.ctrip.xpipe.redis.console.exception.DataNotFoundException)

Aggregations

ClusterMeta (com.ctrip.xpipe.redis.core.entity.ClusterMeta)41 Test (org.junit.Test)25 ShardMeta (com.ctrip.xpipe.redis.core.entity.ShardMeta)13 ClusterTbl (com.ctrip.xpipe.redis.console.model.ClusterTbl)10 DirtiesContext (org.springframework.test.annotation.DirtiesContext)10 MigrationClusterTbl (com.ctrip.xpipe.redis.console.model.MigrationClusterTbl)8 DcMeta (com.ctrip.xpipe.redis.core.entity.DcMeta)5 AbstractConsoleIntegrationTest (com.ctrip.xpipe.redis.console.AbstractConsoleIntegrationTest)4 RedisMeta (com.ctrip.xpipe.redis.core.entity.RedisMeta)4 ClusterMetaComparator (com.ctrip.xpipe.redis.core.meta.comparator.ClusterMetaComparator)3 AbstractMetaServerTest (com.ctrip.xpipe.redis.meta.server.AbstractMetaServerTest)3 AbstractMetaServerClusterTest (com.ctrip.xpipe.redis.meta.server.cluster.AbstractMetaServerClusterTest)3 IOException (java.io.IOException)2 HttpServerErrorException (org.springframework.web.client.HttpServerErrorException)2 HostPort (com.ctrip.xpipe.endpoint.HostPort)1 NodeAdded (com.ctrip.xpipe.observer.NodeAdded)1 NodeDeleted (com.ctrip.xpipe.observer.NodeDeleted)1 AbstractConsoleTest (com.ctrip.xpipe.redis.console.AbstractConsoleTest)1 DataNotFoundException (com.ctrip.xpipe.redis.console.exception.DataNotFoundException)1 ServerException (com.ctrip.xpipe.redis.console.exception.ServerException)1