Search in sources :

Example 21 with ClusterTbl

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());
}
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 22 with ClusterTbl

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());
}
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 23 with ClusterTbl

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());
}
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 24 with ClusterTbl

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

Example 25 with 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);
}
Also used : ClusterTbl(com.ctrip.xpipe.redis.console.model.ClusterTbl) MigrationClusterTbl(com.ctrip.xpipe.redis.console.model.MigrationClusterTbl) RetryNTimesOnCondition(com.ctrip.xpipe.redis.console.job.retry.RetryNTimesOnCondition) ServerException(com.ctrip.xpipe.redis.console.exception.ServerException) TimeoutException(java.util.concurrent.TimeoutException) RetryCondition(com.ctrip.xpipe.redis.console.job.retry.RetryCondition) TimeoutException(java.util.concurrent.TimeoutException) VisibleForTesting(com.ctrip.xpipe.utils.VisibleForTesting)

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