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());
}
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());
}
}
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());
}
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);
}
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());
}
Aggregations