Search in sources :

Example 1 with ClusterMetaComparator

use of com.ctrip.xpipe.redis.core.meta.comparator.ClusterMetaComparator in project x-pipe by ctripcorp.

the class AbstractCurrentMetaObserver method update.

@SuppressWarnings("rawtypes")
@Override
public void update(Object args, Observable observable) {
    if (args instanceof NodeAdded) {
        ClusterMeta clusterMeta = (ClusterMeta) ((NodeAdded) args).getNode();
        logger.info("[update][add][{}]{}", getClass().getSimpleName(), clusterMeta.getId());
        handleClusterAdd(clusterMeta);
        return;
    }
    if (args instanceof NodeDeleted) {
        ClusterMeta clusterMeta = (ClusterMeta) ((NodeDeleted) args).getNode();
        logger.info("[update][delete][{}]{}", getClass().getSimpleName(), clusterMeta.getId());
        handleClusterDeleted(clusterMeta);
        return;
    }
    if (args instanceof ClusterMetaComparator) {
        ClusterMetaComparator clusterMetaComparator = (ClusterMetaComparator) args;
        logger.info("[update][modify][{}]{}", getClass().getSimpleName(), clusterMetaComparator);
        handleClusterModified(clusterMetaComparator);
        return;
    }
    throw new IllegalArgumentException("unknown argument:" + args);
}
Also used : ClusterMetaComparator(com.ctrip.xpipe.redis.core.meta.comparator.ClusterMetaComparator) ClusterMeta(com.ctrip.xpipe.redis.core.entity.ClusterMeta) NodeAdded(com.ctrip.xpipe.observer.NodeAdded) NodeDeleted(com.ctrip.xpipe.observer.NodeDeleted)

Example 2 with ClusterMetaComparator

use of com.ctrip.xpipe.redis.core.meta.comparator.ClusterMetaComparator in project x-pipe by ctripcorp.

the class CurrentMetaTest method testChange.

@Test
public void testChange() {
    ClusterMeta future = MetaClone.clone(clusterMeta);
    String newShardId = randomString(100);
    ShardMeta shardMeta = future.getShards().remove(shardId);
    shardMeta.setId(newShardId);
    future.addShard(shardMeta);
    ClusterMetaComparator comparator = new ClusterMetaComparator(clusterMeta, future);
    comparator.compare();
    currentMeta.changeCluster(comparator);
    Assert.assertFalse(currentMeta.hasShard(clusterId, shardId));
    Assert.assertTrue(currentMeta.hasShard(clusterId, newShardId));
}
Also used : ClusterMetaComparator(com.ctrip.xpipe.redis.core.meta.comparator.ClusterMetaComparator) ClusterMeta(com.ctrip.xpipe.redis.core.entity.ClusterMeta) ShardMeta(com.ctrip.xpipe.redis.core.entity.ShardMeta) Test(org.junit.Test) AbstractMetaServerTest(com.ctrip.xpipe.redis.meta.server.AbstractMetaServerTest)

Example 3 with ClusterMetaComparator

use of com.ctrip.xpipe.redis.core.meta.comparator.ClusterMetaComparator in project x-pipe by ctripcorp.

the class DefaultCurrentMetaManager method dcMetaChange.

private void dcMetaChange(DcMetaComparator comparator) {
    for (ClusterMeta clusterMeta : comparator.getAdded()) {
        if (currentClusterServer.hasKey(clusterMeta.getId())) {
            addCluster(clusterMeta.getId());
        } else {
            logger.info("[dcMetaChange][add][not interested]{}", clusterMeta.getId());
        }
    }
    for (ClusterMeta clusterMeta : comparator.getRemoved()) {
        if (currentClusterServer.hasKey(clusterMeta.getId())) {
            destroyCluster(clusterMeta);
        } else {
            logger.info("[dcMetaChange][destroy][not interested]{}", clusterMeta.getId());
        }
    }
    for (@SuppressWarnings("rawtypes") MetaComparator changedComparator : comparator.getMofified()) {
        ClusterMetaComparator clusterMetaComparator = (ClusterMetaComparator) changedComparator;
        String clusterId = clusterMetaComparator.getCurrent().getId();
        if (currentClusterServer.hasKey(clusterId)) {
            handleClusterChanged(clusterMetaComparator);
        } else {
            logger.info("[dcMetaChange][change][not interested]{}", clusterId);
        }
    }
}
Also used : ClusterMetaComparator(com.ctrip.xpipe.redis.core.meta.comparator.ClusterMetaComparator) ClusterMeta(com.ctrip.xpipe.redis.core.entity.ClusterMeta) ClusterMetaComparator(com.ctrip.xpipe.redis.core.meta.comparator.ClusterMetaComparator) MetaComparator(com.ctrip.xpipe.redis.core.meta.MetaComparator) DcMetaComparator(com.ctrip.xpipe.redis.core.meta.comparator.DcMetaComparator)

Aggregations

ClusterMeta (com.ctrip.xpipe.redis.core.entity.ClusterMeta)3 ClusterMetaComparator (com.ctrip.xpipe.redis.core.meta.comparator.ClusterMetaComparator)3 NodeAdded (com.ctrip.xpipe.observer.NodeAdded)1 NodeDeleted (com.ctrip.xpipe.observer.NodeDeleted)1 ShardMeta (com.ctrip.xpipe.redis.core.entity.ShardMeta)1 MetaComparator (com.ctrip.xpipe.redis.core.meta.MetaComparator)1 DcMetaComparator (com.ctrip.xpipe.redis.core.meta.comparator.DcMetaComparator)1 AbstractMetaServerTest (com.ctrip.xpipe.redis.meta.server.AbstractMetaServerTest)1 Test (org.junit.Test)1