use of com.ctrip.xpipe.redis.console.model.ClusterTbl in project x-pipe by ctripcorp.
the class ClusterController method findAllClusters.
@RequestMapping(value = "/clusters/all", method = RequestMethod.GET)
public List<ClusterTbl> findAllClusters(@RequestParam(required = false) String activeDcName) {
if (StringUtil.isEmpty(activeDcName)) {
return valueOrEmptySet(ClusterTbl.class, clusterService.findAllClustersWithOrgInfo());
} else {
DcTbl dc = dcService.findByDcName(activeDcName);
if (dc != null) {
List<ClusterTbl> clusters = clusterService.findClustersWithOrgInfoByActiveDcId(dc.getId());
if (!clusters.isEmpty()) {
List<Long> clusterIds = new ArrayList<Long>(clusters.size());
for (ClusterTbl c : clusters) {
clusterIds.add(c.getId());
}
List<DcClusterTbl> dcClusters = dcClusterService.findByClusterIds(clusterIds);
return joinClusterAndDcCluster(clusters, dcClusters);
}
}
return Collections.emptyList();
}
}
use of com.ctrip.xpipe.redis.console.model.ClusterTbl in project x-pipe by ctripcorp.
the class KeepercontainerDcController method getClusterNameById.
private String getClusterNameById(long clusterId) {
logger.debug("[getClusterNameById] clusterId: {}", clusterId);
ClusterTbl clusterTbl = clusterService.find(clusterId);
if (clusterTbl == null) {
return null;
}
return clusterTbl.getClusterName();
}
use of com.ctrip.xpipe.redis.console.model.ClusterTbl 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.console.model.ClusterTbl 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());
}
use of com.ctrip.xpipe.redis.console.model.ClusterTbl in project x-pipe by ctripcorp.
the class SingleShardMigrationTest method testMigrateOtherDcFail.
@Test
@DirtiesContext
public void testMigrateOtherDcFail() {
mockSuccessCheckCommand(migrationCommandBuilder, "cluster1", "shard1", dcB, dcB);
mockSuccessPrevPrimaryDcCommand(migrationCommandBuilder, "cluster1", "shard1", dcA);
mockSuccessNewPrimaryDcCommand(migrationCommandBuilder, "cluster1", "shard1", dcB);
mockFailOtherDcCommand(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.assertFalse(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