Search in sources :

Example 1 with ClusterTbl

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();
    }
}
Also used : DcClusterTbl(com.ctrip.xpipe.redis.console.model.DcClusterTbl) ClusterTbl(com.ctrip.xpipe.redis.console.model.ClusterTbl) DcTbl(com.ctrip.xpipe.redis.console.model.DcTbl) DcClusterTbl(com.ctrip.xpipe.redis.console.model.DcClusterTbl)

Example 2 with ClusterTbl

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();
}
Also used : ClusterTbl(com.ctrip.xpipe.redis.console.model.ClusterTbl)

Example 3 with ClusterTbl

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());
}
Also used : ClusterTbl(com.ctrip.xpipe.redis.console.model.ClusterTbl) MigrationClusterTbl(com.ctrip.xpipe.redis.console.model.MigrationClusterTbl) ClusterMeta(com.ctrip.xpipe.redis.core.entity.ClusterMeta) Test(org.junit.Test) DirtiesContext(org.springframework.test.annotation.DirtiesContext)

Example 4 with ClusterTbl

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());
}
Also used : ClusterTbl(com.ctrip.xpipe.redis.console.model.ClusterTbl) MigrationClusterTbl(com.ctrip.xpipe.redis.console.model.MigrationClusterTbl) ClusterMeta(com.ctrip.xpipe.redis.core.entity.ClusterMeta) Test(org.junit.Test) DirtiesContext(org.springframework.test.annotation.DirtiesContext)

Example 5 with ClusterTbl

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());
}
Also used : ClusterTbl(com.ctrip.xpipe.redis.console.model.ClusterTbl) MigrationClusterTbl(com.ctrip.xpipe.redis.console.model.MigrationClusterTbl) ClusterMeta(com.ctrip.xpipe.redis.core.entity.ClusterMeta) Test(org.junit.Test) DirtiesContext(org.springframework.test.annotation.DirtiesContext)

Aggregations

ClusterTbl (com.ctrip.xpipe.redis.console.model.ClusterTbl)34 Test (org.junit.Test)28 MigrationClusterTbl (com.ctrip.xpipe.redis.console.model.MigrationClusterTbl)20 DirtiesContext (org.springframework.test.annotation.DirtiesContext)19 AbstractConsoleIntegrationTest (com.ctrip.xpipe.redis.console.AbstractConsoleIntegrationTest)10 ClusterMeta (com.ctrip.xpipe.redis.core.entity.ClusterMeta)10 AbstractMigrationTest (com.ctrip.xpipe.redis.console.migration.AbstractMigrationTest)6 DcMeta (com.ctrip.xpipe.redis.core.entity.DcMeta)5 DcTbl (com.ctrip.xpipe.redis.console.model.DcTbl)4 AbstractConsoleTest (com.ctrip.xpipe.redis.console.AbstractConsoleTest)3 RetMessage (com.ctrip.xpipe.redis.console.controller.api.RetMessage)3 ClusterCreateInfo (com.ctrip.xpipe.redis.console.controller.api.data.meta.ClusterCreateInfo)3 AbstractExceptionLogTask (com.ctrip.xpipe.concurrent.AbstractExceptionLogTask)1 XPipeConsoleConstant (com.ctrip.xpipe.redis.console.constant.XPipeConsoleConstant)1 KeeperContainerCreateInfo (com.ctrip.xpipe.redis.console.controller.api.data.meta.KeeperContainerCreateInfo)1 ClusterDao (com.ctrip.xpipe.redis.console.dao.ClusterDao)1 ServerException (com.ctrip.xpipe.redis.console.exception.ServerException)1 RetryCondition (com.ctrip.xpipe.redis.console.job.retry.RetryCondition)1 RetryNTimesOnCondition (com.ctrip.xpipe.redis.console.job.retry.RetryNTimesOnCondition)1 ClusterStatus (com.ctrip.xpipe.redis.console.migration.status.ClusterStatus)1