Search in sources :

Example 16 with ShardMeta

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

the class GeneratePlanTest method testGeneratePlan.

@Test
public void testGeneratePlan() {
    List<DcMeta> dcMetas = Lists.newArrayList(new DcMeta("SHAJQ").addCluster(new ClusterMeta("cluster1").setActiveDc("SHAJQ").setBackupDcs("SHAOY").addShard(new ShardMeta("shard1"))), new DcMeta("SHAOY").addCluster(new ClusterMeta("cluster1").setActiveDc("SHAJQ").setBackupDcs("SHAOY").addShard(new ShardMeta("shard1"))));
    Collection result = monitor.generatePlan(dcMetas);
    Assert.assertEquals(0, result.size());
}
Also used : ClusterMeta(com.ctrip.xpipe.redis.core.entity.ClusterMeta) DcMeta(com.ctrip.xpipe.redis.core.entity.DcMeta) ShardMeta(com.ctrip.xpipe.redis.core.entity.ShardMeta) Collection(java.util.Collection) Test(org.junit.Test)

Example 17 with ShardMeta

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

the class ClientConfigMonitor method fromXPipe.

private CheckCluster fromXPipe(XpipeMeta xpipeMeta, String checkCluster) {
    XpipeMetaManager xpm = new DefaultXpipeMetaManager(xpipeMeta);
    CheckCluster result = new CheckCluster(checkCluster);
    for (String dc : xpipeMeta.getDcs().keySet()) {
        ClusterMeta clusterMeta = xpm.getClusterMeta(dc, checkCluster);
        if (clusterMeta == null) {
            continue;
        }
        for (ShardMeta shardMeta : clusterMeta.getShards().values()) {
            CheckShard orShard = result.getOrCreate(shardMeta.getId());
            shardMeta.getRedises().forEach(redis -> {
                orShard.addRedis(new CheckRedis(redis.getIp(), redis.getPort(), dc));
            });
        }
    }
    return result;
}
Also used : DefaultXpipeMetaManager(com.ctrip.xpipe.redis.core.meta.impl.DefaultXpipeMetaManager) ClusterMeta(com.ctrip.xpipe.redis.core.entity.ClusterMeta) ShardMeta(com.ctrip.xpipe.redis.core.entity.ShardMeta) XpipeMetaManager(com.ctrip.xpipe.redis.core.meta.XpipeMetaManager) DefaultXpipeMetaManager(com.ctrip.xpipe.redis.core.meta.impl.DefaultXpipeMetaManager)

Example 18 with ShardMeta

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

the class DefaultDynamicStateManager method add.

@Override
public void add(ClusterMeta clusterMeta) {
    clusterMetas.put(clusterMeta.getId(), clusterMeta);
    for (ShardMeta shardMeta : clusterMeta.getShards().values()) {
        for (KeeperMeta keeperMeta : shardMeta.getKeepers()) {
            final KeeperKey keeperKey = createKeeperKey(clusterMeta.getId(), shardMeta.getId(), keeperMeta);
            @SuppressWarnings("unused") KeeperHeartBeatManager keeperHeartBeatManager = MapUtils.getOrCreate(keepers, keeperKey, new ObjectFactory<KeeperHeartBeatManager>() {

                @Override
                public KeeperHeartBeatManager create() {
                    KeeperHeartBeatManager keeperHeartBeatManager = new DefaultKeeperHeartBeatManager(keeperKey, scheduled);
                    keeperHeartBeatManager.addObserver(DefaultDynamicStateManager.this);
                    return keeperHeartBeatManager;
                }
            });
        }
    }
}
Also used : ShardMeta(com.ctrip.xpipe.redis.core.entity.ShardMeta) KeeperHeartBeatManager(com.ctrip.xpipe.redis.meta.server.keeper.KeeperHeartBeatManager) KeeperMeta(com.ctrip.xpipe.redis.core.entity.KeeperMeta)

Example 19 with ShardMeta

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

the class BackupDcClusterRedisStateAjust method doRun.

@Override
protected void doRun() throws Exception {
    ClusterMeta clusterMeta = currentMetaManager.getClusterMeta(clusterId);
    if (clusterMeta == null) {
        logger.warn("[doRun][cluster null]{}", clusterId);
        return;
    }
    for (ShardMeta shardMeta : clusterMeta.getShards().values()) {
        logger.debug("[doRun]{}, {}", clusterId, shardMeta.getId());
        KeeperMeta keeperActive = currentMetaManager.getKeeperActive(clusterId, shardMeta.getId());
        if (keeperActive == null) {
            logger.debug("[doRun][keeper active null]{}, {}", clusterId, shardMeta.getId());
            continue;
        }
        List<RedisMeta> redisesNeedChange = getRedisesNeedToChange(shardMeta, keeperActive);
        if (redisesNeedChange.size() == 0) {
            continue;
        }
        logger.info("[doRun][change state]{}, {}, {}", clusterId, keeperActive, redisesNeedChange);
        new DefaultSlaveOfJob(redisesNeedChange, keeperActive.getIp(), keeperActive.getPort(), pool, scheduled, executors).execute().addListener(new CommandFutureListener<Void>() {

            @Override
            public void operationComplete(CommandFuture<Void> commandFuture) throws Exception {
                if (!commandFuture.isSuccess()) {
                    logger.error("[operationComplete][fail]" + commandFuture.command(), commandFuture.cause());
                }
            }
        });
    }
}
Also used : ClusterMeta(com.ctrip.xpipe.redis.core.entity.ClusterMeta) ShardMeta(com.ctrip.xpipe.redis.core.entity.ShardMeta) RedisMeta(com.ctrip.xpipe.redis.core.entity.RedisMeta) DefaultSlaveOfJob(com.ctrip.xpipe.redis.meta.server.job.DefaultSlaveOfJob) KeeperMeta(com.ctrip.xpipe.redis.core.entity.KeeperMeta)

Example 20 with ShardMeta

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

the class ClusterMetaComparatorTest method testAdded.

@Test
public void testAdded() {
    ShardMeta shard = differentShard(current);
    future.addShard(shard);
    ClusterMetaComparator clusterMetaComparator = new ClusterMetaComparator(current, future);
    clusterMetaComparator.compare();
    Assert.assertEquals(1, clusterMetaComparator.getAdded().size());
    Assert.assertEquals(shard, clusterMetaComparator.getAdded().toArray()[0]);
    Assert.assertEquals(0, clusterMetaComparator.getRemoved().size());
    Assert.assertEquals(0, clusterMetaComparator.getMofified().size());
}
Also used : ShardMeta(com.ctrip.xpipe.redis.core.entity.ShardMeta) Test(org.junit.Test)

Aggregations

ShardMeta (com.ctrip.xpipe.redis.core.entity.ShardMeta)23 ClusterMeta (com.ctrip.xpipe.redis.core.entity.ClusterMeta)13 Test (org.junit.Test)11 DcMeta (com.ctrip.xpipe.redis.core.entity.DcMeta)4 RedisMeta (com.ctrip.xpipe.redis.core.entity.RedisMeta)4 KeeperMeta (com.ctrip.xpipe.redis.core.entity.KeeperMeta)3 AbstractMetaServerTest (com.ctrip.xpipe.redis.meta.server.AbstractMetaServerTest)3 Releasable (com.ctrip.xpipe.api.lifecycle.Releasable)1 HostPort (com.ctrip.xpipe.endpoint.HostPort)1 AbstractConsoleIntegrationTest (com.ctrip.xpipe.redis.console.AbstractConsoleIntegrationTest)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 DcClusterShardTbl (com.ctrip.xpipe.redis.console.model.DcClusterShardTbl)1 XpipeMeta (com.ctrip.xpipe.redis.core.entity.XpipeMeta)1 XpipeMetaManager (com.ctrip.xpipe.redis.core.meta.XpipeMetaManager)1 ClusterMetaComparator (com.ctrip.xpipe.redis.core.meta.comparator.ClusterMetaComparator)1 DefaultXpipeMetaManager (com.ctrip.xpipe.redis.core.meta.impl.DefaultXpipeMetaManager)1 AbstractMetaServerClusterTest (com.ctrip.xpipe.redis.meta.server.cluster.AbstractMetaServerClusterTest)1 DefaultSlaveOfJob (com.ctrip.xpipe.redis.meta.server.job.DefaultSlaveOfJob)1