Search in sources :

Example 16 with ClusterTbl

use of com.ctrip.xpipe.redis.console.model.ClusterTbl in project x-pipe by ctripcorp.

the class MetaUpdateTest method testUpdateCLusterWithNoNeedUpdate.

@Test
public void testUpdateCLusterWithNoNeedUpdate() throws Exception {
    String CLUSTER_NAME = "cluster-name";
    String EXPECTED_MESSAGE = String.format("No field changes for cluster: %s", CLUSTER_NAME);
    long ORG_ID = 5L;
    ClusterTbl clusterTbl = new ClusterTbl().setClusterName(CLUSTER_NAME).setClusterDescription("").setActivedcId(1).setIsXpipeInterested(true).setStatus("normal").setClusterLastModifiedTime(DateTimeUtils.currentTimeAsString());
    clusterDao.createCluster(clusterTbl);
    ClusterCreateInfo clusterInfo = new ClusterCreateInfo();
    clusterInfo.setClusterName(CLUSTER_NAME);
    clusterInfo.setClusterAdminEmails("test@ctrip.com");
    clusterInfo.setOrganizationId(ORG_ID);
    RetMessage retMessage = clusterController.updateCluster(clusterInfo);
    logger.info("{}", retMessage.getMessage());
    RetMessage retMessage1 = clusterController.updateCluster(clusterInfo);
    Assert.assertEquals(RetMessage.SUCCESS_STATE, retMessage1.getState());
    Assert.assertEquals(EXPECTED_MESSAGE, retMessage1.getMessage());
    ClusterTbl cluster = clusterDao.findClusterAndOrgByName(CLUSTER_NAME);
    Assert.assertEquals(ORG_ID, cluster.getOrganizationInfo().getOrgId());
}
Also used : ClusterTbl(com.ctrip.xpipe.redis.console.model.ClusterTbl) RetMessage(com.ctrip.xpipe.redis.console.controller.api.RetMessage) ClusterCreateInfo(com.ctrip.xpipe.redis.console.controller.api.data.meta.ClusterCreateInfo) AbstractConsoleIntegrationTest(com.ctrip.xpipe.redis.console.AbstractConsoleIntegrationTest) Test(org.junit.Test)

Example 17 with ClusterTbl

use of com.ctrip.xpipe.redis.console.model.ClusterTbl in project x-pipe by ctripcorp.

the class ClusterDeleteEventFactoryTest method createClusterEvent.

@Test
public void createClusterEvent() throws Exception {
    List<ClusterTbl> clusters = clusterService.findAllClustersWithOrgInfo();
    ClusterEvent clusterEvent = clusterDeleteEventFactory.createClusterEvent(clusters.get(0).getClusterName());
    Assert.assertTrue(clusterEvent instanceof ClusterDeleteEvent);
    for (ShardEvent shardEvent : clusterEvent.getShardEvents()) {
        Assert.assertTrue(shardEvent instanceof ShardDeleteEvent);
        Assert.assertEquals(clusterEvent.getClusterName(), shardEvent.getClusterName());
    }
}
Also used : ClusterTbl(com.ctrip.xpipe.redis.console.model.ClusterTbl) ShardEvent(com.ctrip.xpipe.redis.console.notifier.shard.ShardEvent) ShardDeleteEvent(com.ctrip.xpipe.redis.console.notifier.shard.ShardDeleteEvent) AbstractConsoleIntegrationTest(com.ctrip.xpipe.redis.console.AbstractConsoleIntegrationTest) Test(org.junit.Test)

Example 18 with ClusterTbl

use of com.ctrip.xpipe.redis.console.model.ClusterTbl in project x-pipe by ctripcorp.

the class MetaUpdateTest method updateCluster.

@Test
public void updateCluster() throws Exception {
    String CLUSTER_NAME = "cluster-name";
    int SUCCESS_STATE = RetMessage.SUCCESS_STATE;
    long ORG_ID = 5L;
    ClusterTbl clusterTbl = new ClusterTbl().setClusterName(CLUSTER_NAME).setClusterDescription("").setActivedcId(1).setIsXpipeInterested(true).setStatus("normal").setClusterLastModifiedTime(DateTimeUtils.currentTimeAsString());
    clusterDao.createCluster(clusterTbl);
    ClusterCreateInfo clusterInfo = new ClusterCreateInfo();
    clusterInfo.setClusterName(CLUSTER_NAME);
    clusterInfo.setClusterAdminEmails("test@ctrip.com");
    clusterInfo.setOrganizationId(ORG_ID);
    RetMessage retMessage = clusterController.updateCluster(clusterInfo);
    logger.info("{}", retMessage.getMessage());
    Assert.assertEquals(SUCCESS_STATE, retMessage.getState());
    ClusterTbl cluster = clusterDao.findClusterAndOrgByName(CLUSTER_NAME);
    Assert.assertEquals(ORG_ID, cluster.getOrganizationInfo().getOrgId());
}
Also used : ClusterTbl(com.ctrip.xpipe.redis.console.model.ClusterTbl) RetMessage(com.ctrip.xpipe.redis.console.controller.api.RetMessage) ClusterCreateInfo(com.ctrip.xpipe.redis.console.controller.api.data.meta.ClusterCreateInfo) AbstractConsoleIntegrationTest(com.ctrip.xpipe.redis.console.AbstractConsoleIntegrationTest) Test(org.junit.Test)

Example 19 with ClusterTbl

use of com.ctrip.xpipe.redis.console.model.ClusterTbl in project x-pipe by ctripcorp.

the class AlertManager method postConstruct.

@PostConstruct
public void postConstruct() {
    scheduled.scheduleWithFixedDelay(new AbstractExceptionLogTask() {

        @Override
        protected void doRun() throws Exception {
            alertClusterWhiteList = consoleConfig.getAlertWhileList();
        }
    }, 0, 30, TimeUnit.SECONDS);
    scheduled.scheduleWithFixedDelay(new AbstractExceptionLogTask() {

        @Override
        protected void doRun() throws Exception {
            logger.info("[clusterCreateTimeMapper][execute]");
            List<ClusterTbl> clusterTbls = clusterService.findAllClustersWithOrgInfo();
            for (ClusterTbl clusterTbl : clusterTbls) {
                clusterCreateTime.put(clusterTbl.getClusterName(), clusterTbl.getCreateTime());
            }
        }
    }, 1, 60, TimeUnit.MINUTES);
}
Also used : ClusterTbl(com.ctrip.xpipe.redis.console.model.ClusterTbl) AbstractExceptionLogTask(com.ctrip.xpipe.concurrent.AbstractExceptionLogTask) PostConstruct(javax.annotation.PostConstruct)

Example 20 with ClusterTbl

use of com.ctrip.xpipe.redis.console.model.ClusterTbl in project x-pipe by ctripcorp.

the class SingleShardMigrationTest method testCheckFail.

@Test
@DirtiesContext
public void testCheckFail() {
    mockFailCheckCommand(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));
    Assert.assertNull(migrationShard.getShardMigrationResult().getSteps().get(ShardMigrationStep.CHECK));
    migrationCluster.process();
    sleep(1000);
    ClusterTbl currentCluster = clusterService.find(1);
    Assert.assertEquals(MigrationStatus.CheckingFail, migrationCluster.getStatus());
    ;
    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)

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