Search in sources :

Example 1 with ShardEvent

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);
}
Also used : ShardEvent(com.ctrip.xpipe.redis.console.notifier.shard.ShardEvent) ShardDeleteEvent(com.ctrip.xpipe.redis.console.notifier.shard.ShardDeleteEvent) ShardTbl(com.ctrip.xpipe.redis.console.model.ShardTbl) SetinelTbl(com.ctrip.xpipe.redis.console.model.SetinelTbl) Test(org.junit.Test)

Example 2 with 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());
    }
}
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 3 with ShardEvent

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);
        }
    }
}
Also used : ShardEvent(com.ctrip.xpipe.redis.console.notifier.shard.ShardEvent) ServerException(com.ctrip.xpipe.redis.console.exception.ServerException) DalException(org.unidal.dal.jdbc.DalException) ServerException(com.ctrip.xpipe.redis.console.exception.ServerException) DalException(org.unidal.dal.jdbc.DalException)

Example 4 with ShardEvent

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();
    }
}
Also used : ShardEvent(com.ctrip.xpipe.redis.console.notifier.shard.ShardEvent) EventType(com.ctrip.xpipe.redis.console.notifier.EventType)

Aggregations

ShardEvent (com.ctrip.xpipe.redis.console.notifier.shard.ShardEvent)4 ShardDeleteEvent (com.ctrip.xpipe.redis.console.notifier.shard.ShardDeleteEvent)2 Test (org.junit.Test)2 AbstractConsoleIntegrationTest (com.ctrip.xpipe.redis.console.AbstractConsoleIntegrationTest)1 ServerException (com.ctrip.xpipe.redis.console.exception.ServerException)1 ClusterTbl (com.ctrip.xpipe.redis.console.model.ClusterTbl)1 SetinelTbl (com.ctrip.xpipe.redis.console.model.SetinelTbl)1 ShardTbl (com.ctrip.xpipe.redis.console.model.ShardTbl)1 EventType (com.ctrip.xpipe.redis.console.notifier.EventType)1 DalException (org.unidal.dal.jdbc.DalException)1