use of com.ctrip.xpipe.redis.core.entity.ClusterMeta in project x-pipe by ctripcorp.
the class ClusterServersApiTest method randomCluster.
private ClusterMeta randomCluster() {
ClusterMeta clusterMeta = new ClusterMeta();
clusterMeta.setId(getTestName());
return clusterMeta;
}
use of com.ctrip.xpipe.redis.core.entity.ClusterMeta 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.entity.ClusterMeta in project x-pipe by ctripcorp.
the class AbstractMetaServerContextTest method randomClusterMeta.
protected ClusterMeta randomClusterMeta() {
DcMeta dcMeta = getDcMeta(dc);
ClusterMeta clusterMeta = (ClusterMeta) dcMeta.getClusters().values().toArray()[0];
return MetaClone.clone(clusterMeta);
}
use of com.ctrip.xpipe.redis.core.entity.ClusterMeta in project x-pipe by ctripcorp.
the class SingleShardMigrationTest method testCheckExceptionFail.
@Test
@DirtiesContext
public void testCheckExceptionFail() {
mockFailCheckCommand(migrationCommandBuilder, "cluster1", "shard1", dcB, dcB, new Throwable("mocked check fail"));
mockSuccessPrevPrimaryDcCommand(migrationCommandBuilder, "cluster1", "shard1", dcA);
mockSuccessNewPrimaryDcCommand(migrationCommandBuilder, "cluster1", "shard1", dcB);
mockSuccessOtherDcCommand(migrationCommandBuilder, "cluster1", "shard1", dcB, dcA);
ClusterTbl originalCluster = clusterService.find(1);
Assert.assertEquals(ClusterStatus.Lock.toString(), originalCluster.getStatus());
Assert.assertEquals(1, originalCluster.getActivedcId());
Assert.assertEquals(1, migrationCluster.getMigrationCluster().getSourceDcId());
Assert.assertEquals(2, migrationCluster.getMigrationCluster().getDestinationDcId());
Assert.assertEquals("Initiated", migrationCluster.getStatus().toString());
Assert.assertEquals(ShardMigrationResultStatus.FAIL, migrationShard.getShardMigrationResult().getStatus());
Assert.assertFalse(migrationShard.getShardMigrationResult().stepSuccess(ShardMigrationStep.CHECK));
Assert.assertFalse(migrationShard.getShardMigrationResult().stepSuccess(ShardMigrationStep.MIGRATE_PREVIOUS_PRIMARY_DC));
Assert.assertFalse(migrationShard.getShardMigrationResult().stepSuccess(ShardMigrationStep.MIGRATE_NEW_PRIMARY_DC));
Assert.assertFalse(migrationShard.getShardMigrationResult().stepSuccess(ShardMigrationStep.MIGRATE_OTHER_DC));
Assert.assertFalse(migrationShard.getShardMigrationResult().stepSuccess(ShardMigrationStep.MIGRATE));
Assert.assertNull(migrationShard.getShardMigrationResult().getSteps().get(ShardMigrationStep.CHECK));
migrationCluster.process();
sleep(1000);
ClusterTbl currentCluster = clusterService.find(1);
Assert.assertEquals(ClusterStatus.Lock.toString(), currentCluster.getStatus());
Assert.assertEquals(1, currentCluster.getActivedcId());
Assert.assertEquals(ShardMigrationResultStatus.FAIL, migrationShard.getShardMigrationResult().getStatus());
Assert.assertFalse(migrationShard.getShardMigrationResult().stepSuccess(ShardMigrationStep.CHECK));
Assert.assertFalse(migrationShard.getShardMigrationResult().stepSuccess(ShardMigrationStep.MIGRATE_PREVIOUS_PRIMARY_DC));
Assert.assertFalse(migrationShard.getShardMigrationResult().stepSuccess(ShardMigrationStep.MIGRATE_NEW_PRIMARY_DC));
Assert.assertFalse(migrationShard.getShardMigrationResult().stepSuccess(ShardMigrationStep.MIGRATE_OTHER_DC));
Assert.assertFalse(migrationShard.getShardMigrationResult().stepSuccess(ShardMigrationStep.MIGRATE));
Assert.assertFalse(migrationShard.getShardMigrationResult().getSteps().get(ShardMigrationStep.CHECK).equals(""));
ClusterMeta prevPrimaryDcMeta = clusterMetaService.getClusterMeta(dcA, "cluster1");
Assert.assertEquals(dcA, prevPrimaryDcMeta.getActiveDc());
ClusterMeta newPrimaryDcMeta = clusterMetaService.getClusterMeta(dcB, "cluster1");
Assert.assertEquals(dcA, newPrimaryDcMeta.getActiveDc());
}
use of com.ctrip.xpipe.redis.core.entity.ClusterMeta in project x-pipe by ctripcorp.
the class SingleShardMigrationTest method testMigratePrevExceptionFail.
@Test
@DirtiesContext
public void testMigratePrevExceptionFail() {
mockSuccessCheckCommand(migrationCommandBuilder, "cluster1", "shard1", dcB, dcB);
mockFailPrevPrimaryDcCommand(migrationCommandBuilder, "cluster1", "shard1", dcA, new Throwable("mocked prev fail"));
mockSuccessNewPrimaryDcCommand(migrationCommandBuilder, "cluster1", "shard1", dcB);
mockSuccessOtherDcCommand(migrationCommandBuilder, "cluster1", "shard1", dcB, dcA);
ClusterTbl originalCluster = clusterService.find(1);
Assert.assertEquals(ClusterStatus.Lock.toString(), originalCluster.getStatus());
Assert.assertEquals(1, originalCluster.getActivedcId());
Assert.assertEquals(1, migrationCluster.getMigrationCluster().getSourceDcId());
Assert.assertEquals(2, migrationCluster.getMigrationCluster().getDestinationDcId());
Assert.assertEquals("Initiated", migrationCluster.getStatus().toString());
Assert.assertEquals(ShardMigrationResultStatus.FAIL, migrationShard.getShardMigrationResult().getStatus());
Assert.assertFalse(migrationShard.getShardMigrationResult().stepSuccess(ShardMigrationStep.CHECK));
Assert.assertFalse(migrationShard.getShardMigrationResult().stepSuccess(ShardMigrationStep.MIGRATE_PREVIOUS_PRIMARY_DC));
Assert.assertFalse(migrationShard.getShardMigrationResult().stepSuccess(ShardMigrationStep.MIGRATE_NEW_PRIMARY_DC));
Assert.assertFalse(migrationShard.getShardMigrationResult().stepSuccess(ShardMigrationStep.MIGRATE_OTHER_DC));
Assert.assertFalse(migrationShard.getShardMigrationResult().stepSuccess(ShardMigrationStep.MIGRATE));
migrationCluster.process();
sleep(1000);
ClusterTbl currentCluster = clusterService.find(1);
Assert.assertEquals(ClusterStatus.Normal.toString(), currentCluster.getStatus());
Assert.assertEquals(2, currentCluster.getActivedcId());
Assert.assertEquals(ShardMigrationResultStatus.SUCCESS, migrationShard.getShardMigrationResult().getStatus());
Assert.assertTrue(migrationShard.getShardMigrationResult().stepSuccess(ShardMigrationStep.CHECK));
Assert.assertTrue(migrationShard.getShardMigrationResult().stepSuccess(ShardMigrationStep.MIGRATE_PREVIOUS_PRIMARY_DC));
String message = migrationShard.getShardMigrationResult().getSteps().get(ShardMigrationStep.MIGRATE_PREVIOUS_PRIMARY_DC).getValue();
Assert.assertTrue(message.indexOf("Ignore:java.lang.Throwable: mocked prev fail") > 0);
Assert.assertTrue(migrationShard.getShardMigrationResult().stepSuccess(ShardMigrationStep.MIGRATE_NEW_PRIMARY_DC));
Assert.assertTrue(migrationShard.getShardMigrationResult().stepSuccess(ShardMigrationStep.MIGRATE_OTHER_DC));
Assert.assertTrue(migrationShard.getShardMigrationResult().stepSuccess(ShardMigrationStep.MIGRATE));
ClusterMeta prevPrimaryDcMeta = clusterMetaService.getClusterMeta(dcA, "cluster1");
Assert.assertEquals(dcB, prevPrimaryDcMeta.getActiveDc());
ClusterMeta newPrimaryDcMeta = clusterMetaService.getClusterMeta(dcB, "cluster1");
Assert.assertEquals(dcB, newPrimaryDcMeta.getActiveDc());
}
Aggregations