use of com.ctrip.xpipe.redis.console.notifier.shard.ShardEvent in project x-pipe by ctripcorp.
the class ShardServiceImplTest method testCreateShardEvent.
@Test
public void testCreateShardEvent() {
String sentinelAddress1 = "10.8.187.27:44400,10.8.187.28:44400,10.8.107.230:44400,10.8.107.169:44400,10.8.107.77:44400";
String sentinelAddress2 = "10.28.68.81:33355,10.28.68.82:33355,10.28.68.83:33355,10.8.107.198:33355,10.8.107.199:33355";
ShardTbl shardTbl = shardService.find(clusterName, shardNames[0]);
Map<Long, SetinelTbl> setinelTblMap = Maps.newHashMapWithExpectedSize(2);
setinelTblMap.put(1L, new SetinelTbl().setSetinelAddress(sentinelAddress1));
setinelTblMap.put(2L, new SetinelTbl().setSetinelAddress(sentinelAddress2));
ShardEvent shardEvent = shardService.createShardDeleteEvent(clusterName, shardNames[0], shardTbl, setinelTblMap);
Assert.assertTrue(shardEvent instanceof ShardDeleteEvent);
Assert.assertEquals(EventType.DELETE, shardEvent.getShardEventType());
Assert.assertEquals(clusterName, shardEvent.getClusterName());
Assert.assertEquals(shardNames[0], shardEvent.getShardName());
Assert.assertEquals(sentinelAddress1 + "," + sentinelAddress2, shardEvent.getShardSentinels());
System.out.println(shardEvent);
}
use of com.ctrip.xpipe.redis.console.notifier.shard.ShardEvent 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.notifier.shard.ShardEvent in project x-pipe by ctripcorp.
the class ShardServiceImpl method deleteShard.
@Override
public void deleteShard(final String clusterName, final String shardName) {
final ShardTbl shard = queryHandler.handleQuery(new DalQuery<ShardTbl>() {
@Override
public ShardTbl doQuery() throws DalException {
return dao.findShard(clusterName, shardName, ShardTblEntity.READSET_FULL);
}
});
if (null != shard) {
// Call shard event
Map<Long, SetinelTbl> sentinels = sentinelService.findByShard(shard.getId());
ShardEvent shardEvent = createShardDeleteEvent(clusterName, shardName, shard, sentinels);
try {
shardDao.deleteShardsBatch(shard);
} catch (Exception e) {
throw new ServerException(e.getMessage());
}
shardEvent.onEvent();
}
/**
* Notify meta server *
*/
List<DcTbl> relatedDcs = dcService.findClusterRelatedDc(clusterName);
if (null != relatedDcs) {
for (DcTbl dc : relatedDcs) {
notifier.notifyClusterUpdate(dc.getDcName(), clusterName);
}
}
}
use of com.ctrip.xpipe.redis.console.notifier.shard.ShardEvent in project x-pipe by ctripcorp.
the class DefaultClusterDeleteEventListener method update.
@Override
public void update(Object args, Observable observable) {
EventType type = (EventType) args;
if (!(observable instanceof ClusterDeleteEvent) || type != EventType.DELETE) {
logger.info("[update] observable object not ShardDeleteEvent, skip. observable: {}, args: {}", observable.getClass().getName(), args.getClass().getName());
return;
}
ClusterDeleteEvent clusterDeleteEvent = (ClusterDeleteEvent) observable;
for (ShardEvent shardEvent : clusterDeleteEvent.getShardEvents()) {
shardEvent.onEvent();
}
}
Aggregations