use of com.ctrip.xpipe.redis.console.model.ClusterTbl in project x-pipe by ctripcorp.
the class SingleShardMigrationTest method testMigrateNewExceptionFail.
@Test
@DirtiesContext
public void testMigrateNewExceptionFail() {
mockSuccessCheckCommand(migrationCommandBuilder, "cluster1", "shard1", dcB, dcB);
mockSuccessPrevPrimaryDcCommand(migrationCommandBuilder, "cluster1", "shard1", dcA);
mockFailNewPrimaryDcCommand(migrationCommandBuilder, "cluster1", "shard1", dcB, new Throwable("mocked new fail"));
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.Migrating.toString(), currentCluster.getStatus());
Assert.assertEquals(1, currentCluster.getActivedcId());
Assert.assertEquals(MigrationStatus.PartialSuccess, migrationCluster.getStatus());
Assert.assertEquals(ShardMigrationResultStatus.FAIL, migrationShard.getShardMigrationResult().getStatus());
Assert.assertTrue(migrationShard.getShardMigrationResult().stepSuccess(ShardMigrationStep.CHECK));
Assert.assertTrue(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.assertNull(migrationShard.getShardMigrationResult().getSteps().get(ShardMigrationStep.MIGRATE_OTHER_DC));
Assert.assertFalse(migrationShard.getShardMigrationResult().stepSuccess(ShardMigrationStep.MIGRATE));
ClusterMeta prevPrimaryDcMeta = clusterMetaService.getClusterMeta(dcA, "cluster1");
Assert.assertEquals(dcA, prevPrimaryDcMeta.getActiveDc());
ClusterMeta newPrimaryDcMeta = clusterMetaService.getClusterMeta(dcB, "cluster1");
Assert.assertEquals(dcB, newPrimaryDcMeta.getActiveDc());
}
use of com.ctrip.xpipe.redis.console.model.ClusterTbl in project x-pipe by ctripcorp.
the class SingleShardMigrationTest method testSuccess.
@Test
@DirtiesContext
public void testSuccess() {
mockSuccessCheckCommand(migrationCommandBuilder, "cluster1", "shard1", dcB, dcB);
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));
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));
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());
}
use of com.ctrip.xpipe.redis.console.model.ClusterTbl in project x-pipe by ctripcorp.
the class SingleShardMigrationTest method testMigrateNewFail.
@Test
@DirtiesContext
public void testMigrateNewFail() {
mockSuccessCheckCommand(migrationCommandBuilder, "cluster1", "shard1", dcB, dcB);
mockSuccessPrevPrimaryDcCommand(migrationCommandBuilder, "cluster1", "shard1", dcA);
mockFailNewPrimaryDcCommand(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.Migrating.toString(), currentCluster.getStatus());
Assert.assertEquals(MigrationStatus.PartialSuccess, migrationCluster.getStatus());
Assert.assertEquals(1, currentCluster.getActivedcId());
Assert.assertEquals(ShardMigrationResultStatus.FAIL, migrationShard.getShardMigrationResult().getStatus());
Assert.assertTrue(migrationShard.getShardMigrationResult().stepSuccess(ShardMigrationStep.CHECK));
Assert.assertTrue(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.assertNull(migrationShard.getShardMigrationResult().getSteps().get(ShardMigrationStep.MIGRATE_OTHER_DC));
Assert.assertFalse(migrationShard.getShardMigrationResult().stepSuccess(ShardMigrationStep.MIGRATE));
ClusterMeta prevPrimaryDcMeta = clusterMetaService.getClusterMeta(dcA, "cluster1");
Assert.assertEquals(dcA, prevPrimaryDcMeta.getActiveDc());
ClusterMeta newPrimaryDcMeta = clusterMetaService.getClusterMeta(dcB, "cluster1");
Assert.assertEquals(dcB, newPrimaryDcMeta.getActiveDc());
}
use of com.ctrip.xpipe.redis.console.model.ClusterTbl in project x-pipe by ctripcorp.
the class ClusterMetaServiceImplTest method testGetClusterMetaCurrentPrimaryDcMigrating.
@Test
public void testGetClusterMetaCurrentPrimaryDcMigrating() {
long currentActiveDcId = randomInt();
long clusterId = randomInt();
long destinationDcId = currentActiveDcId + 1;
DcTbl dcTbl = new DcTbl();
ClusterTbl clusterTbl = new ClusterTbl();
clusterTbl.setId(clusterId);
clusterTbl.setActivedcId(currentActiveDcId);
clusterTbl.setStatus(ClusterStatus.Migrating.toString());
when(migrationService.findLatestUnfinishedMigrationCluster(clusterId)).thenReturn(new MigrationClusterTbl().setDestinationDcId(destinationDcId));
dcTbl.setId(destinationDcId);
Assert.assertEquals(destinationDcId, clusterMetaServiceImpl.getClusterMetaCurrentPrimaryDc(dcTbl, clusterTbl));
dcTbl.setId(destinationDcId + 1);
Assert.assertEquals(currentActiveDcId, clusterMetaServiceImpl.getClusterMetaCurrentPrimaryDc(dcTbl, clusterTbl));
dcTbl.setId(currentActiveDcId);
Assert.assertEquals(currentActiveDcId, clusterMetaServiceImpl.getClusterMetaCurrentPrimaryDc(dcTbl, clusterTbl));
}
use of com.ctrip.xpipe.redis.console.model.ClusterTbl in project x-pipe by ctripcorp.
the class DefaultMigrationCluster method updateStorageClusterStatus.
@VisibleForTesting
protected void updateStorageClusterStatus() throws Exception {
MigrationStatus migrationStatus = this.currentState.getStatus();
ClusterStatus clusterStatus = migrationStatus.getClusterStatus();
logger.info("[updateStat][updatedb]{}, {}", clusterName(), clusterStatus);
RetryTemplate<String> retryTemplate = new RetryNTimesOnCondition<>(new RetryCondition.AbstractRetryCondition<String>() {
@Override
public boolean isSatisfied(String s) {
return ClusterStatus.isSameClusterStatus(s, clusterStatus);
}
@Override
public boolean isExceptionExpected(Throwable th) {
if (th instanceof TimeoutException)
return true;
return false;
}
}, 3);
retryTemplate.execute(new AbstractCommand<String>() {
@Override
protected void doExecute() throws Exception {
try {
getClusterService().updateStatusById(clusterId(), clusterStatus);
ClusterTbl newCluster = getClusterService().find(clusterName());
future().setSuccess(newCluster.getStatus());
} catch (Exception e) {
future().setFailure(e.getCause());
}
}
@Override
protected void doReset() {
}
@Override
public String getName() {
return "update cluster status";
}
});
ClusterTbl newCluster = getClusterService().find(clusterName());
logger.info("[updateStat][getdb]{}, {}", clusterName(), newCluster != null ? newCluster.getStatus() : null);
}
Aggregations