use of com.ctrip.xpipe.redis.console.migration.model.impl.DefaultMigrationShard in project x-pipe by ctripcorp.
the class MigrationEventDao method loadMigrationEvent.
private MigrationEvent loadMigrationEvent(List<MigrationEventTbl> details) {
if (!CollectionUtils.isEmpty(details)) {
MigrationEvent event = new DefaultMigrationEvent(details.get(0));
for (MigrationEventTbl detail : details) {
MigrationClusterTbl cluster = detail.getRedundantClusters();
MigrationShardTbl shard = detail.getRedundantShards();
if (null == event.getMigrationCluster(cluster.getClusterId())) {
event.addMigrationCluster(new DefaultMigrationCluster(executors, scheduled, event, detail.getRedundantClusters(), dcService, clusterService, shardService, redisService, migrationService));
}
MigrationCluster migrationCluster = event.getMigrationCluster(cluster.getClusterId());
migrationCluster.addNewMigrationShard(new DefaultMigrationShard(migrationCluster, shard, migrationCluster.getClusterShards().get(shard.getShardId()), migrationCluster.getClusterDcs(), migrationService));
}
return event;
}
throw new BadRequestException("Cannot load migration event from null.");
}
use of com.ctrip.xpipe.redis.console.migration.model.impl.DefaultMigrationShard in project x-pipe by ctripcorp.
the class DefaultMigrationShardTest method prepareMockData.
private void prepareMockData() {
String clusterName = "test-cluster";
when(mockedMigrationCluster.getCurrentCluster()).thenReturn((new ClusterTbl()).setId(1).setClusterName(clusterName).setActivedcId(1L));
when(mockedMigrationCluster.clusterName()).thenReturn(clusterName);
when(mockedMigrationCluster.getMigrationCluster()).thenReturn((new MigrationClusterTbl()).setClusterId(1).setDestinationDcId(2L));
when(mockedMigrationCluster.getRedisService()).thenReturn(mockedRedisService);
final AtomicInteger cnt = new AtomicInteger(0);
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
Object[] args = invocation.getArguments();
System.out.println(args[0]);
if (cnt.incrementAndGet() == 3) {
if (migrationShard.getShardMigrationResult().stepSuccess(ShardMigrationStep.MIGRATE_NEW_PRIMARY_DC)) {
migrationShard.doMigrateOtherDc();
}
}
;
return null;
}
}).when(mockedMigrationCluster).update(anyObject(), anyObject());
mockedMigrationShard = (new MigrationShardTbl()).setId(1).setKeyId(1).setShardId(1).setMigrationClusterId(1);
mockedCurrentShard = (new ShardTbl()).setId(1).setKeyId(1).setShardName("test-shard").setClusterId(1).setSetinelMonitorName("test-shard-monitor");
mockedDcs.put(1L, (new DcTbl()).setId(1).setKeyId(1).setDcName("dc-a"));
mockedDcs.put(2L, (new DcTbl()).setId(2).setKeyId(2).setDcName("dc-b"));
migrationShard = new DefaultMigrationShard(mockedMigrationCluster, mockedMigrationShard, mockedCurrentShard, mockedDcs, mockedMigrationService, mockedCommandBuilder);
}
use of com.ctrip.xpipe.redis.console.migration.model.impl.DefaultMigrationShard in project x-pipe by ctripcorp.
the class MultiShardMigrationTest method prepare.
@Before
public void prepare() {
MockitoAnnotations.initMocks(this);
Map<Long, DcTbl> dcs = new HashMap<>();
for (DcTbl dc : dcService.findClusterRelatedDc(clusterName)) {
dcs.put(dc.getId(), dc);
}
createShards();
MigrationClusterTbl migrationClusterTbl = migrationService.findMigrationCluster(1L, clusterId);
migrationCluster = new DefaultMigrationCluster(executors, scheduled, migrationEvent, migrationClusterTbl, dcService, clusterService, shardService, redisService, migrationService);
for (int cnt = 1; cnt != TEST_SHARD_CNT + 1; ++cnt) {
MigrationShardTbl migrationShardTbl = new MigrationShardTbl();
migrationShardTbl.setId(cnt).setMigrationClusterId(1).setShardId(cnt).setLog("");
ShardTbl shardTbl = new ShardTbl();
shardTbl.setId(cnt).setClusterId(clusterId).setShardName(getShardName(cnt)).setSetinelMonitorName("cluster1-" + getShardName(cnt));
MigrationShard migrationShard = new DefaultMigrationShard(migrationCluster, migrationShardTbl, shardTbl, dcs, migrationService, migrationCommandBuilder);
migrationCluster.addNewMigrationShard(migrationShard);
}
}
use of com.ctrip.xpipe.redis.console.migration.model.impl.DefaultMigrationShard in project x-pipe by ctripcorp.
the class DefaultMigrationClusterTest method prepare.
@Before
public void prepare() {
MockitoAnnotations.initMocks(this);
dcA = dcNames[0];
dcB = dcNames[1];
MigrationClusterTbl migrationClusterTbl = migrationService.findMigrationCluster(1L, 1L);
migrationCluster = new DefaultMigrationCluster(executors, scheduled, migrationEvent, migrationClusterTbl, dcService, clusterService, shardService, redisService, migrationService);
Map<Long, DcTbl> dcs = new HashMap<>();
for (DcTbl dc : dcService.findClusterRelatedDc("cluster1")) {
dcs.put(dc.getId(), dc);
}
migrationShard = new DefaultMigrationShard(migrationCluster, migrationService.findMigrationShards(1).get(0), shardService.find(1), dcs, migrationService, migrationCommandBuilder);
migrationCluster.addNewMigrationShard(migrationShard);
}
use of com.ctrip.xpipe.redis.console.migration.model.impl.DefaultMigrationShard in project x-pipe by ctripcorp.
the class MigrationEventDaoTest method testShardResult.
@Test
@DirtiesContext
public void testShardResult() {
MigrationEvent event = migrationEventDao.buildMigrationEvent(2);
// update check
MigrationCluster migrationCluster = event.getMigrationClusters().get(0);
List<MigrationShard> migrationShards = migrationCluster.getMigrationShards();
migrationShards.forEach(migrationShard -> {
ShardMigrationResult result = randomResult();
((DefaultMigrationShard) migrationShard).updateShardMigrationResult(result);
migrationShard.update(null, null);
});
MigrationEvent eventNew = migrationEventDao.buildMigrationEvent(2);
MigrationCluster migrationClusterNew = eventNew.getMigrationClusters().get(0);
Assert.assertEquals(migrationCluster.clusterName(), migrationClusterNew.clusterName());
List<MigrationShard> migrationShardsNew = migrationClusterNew.getMigrationShards();
Assert.assertEquals(migrationShards.size(), migrationShardsNew.size());
for (int i = 0; i < migrationShards.size(); i++) {
ShardMigrationResult result = migrationShards.get(i).getShardMigrationResult();
ShardMigrationResult resultNew = migrationShardsNew.get(i).getShardMigrationResult();
Assert.assertFalse(result == resultNew);
Assert.assertEquals(result, resultNew);
}
}
Aggregations