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);
}
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));
}
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);
}
}
}
Aggregations