Search in sources :

Example 1 with ShardDeleteEvent

use of com.ctrip.xpipe.redis.console.notifier.shard.ShardDeleteEvent 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 ShardDeleteEvent

use of com.ctrip.xpipe.redis.console.notifier.shard.ShardDeleteEvent in project x-pipe by ctripcorp.

the class ClusterDeleteEventFactory method createClusterEvent.

@Override
public ClusterEvent createClusterEvent(String clusterName) {
    ClusterDeleteEvent clusterDeleteEvent = new ClusterDeleteEvent(clusterName, executors);
    List<ShardTbl> shardTbls = shardService.findAllByClusterName(clusterName);
    if (shardTbls != null) {
        for (ShardTbl shardTbl : shardTbls) {
            logger.info("[createClusterEvent] Create Shard Delete Event: {}", shardTbl);
            Map<Long, SetinelTbl> sentinelMap = sentinelService.findByShard(shardTbl.getId());
            ShardDeleteEvent shardEvent = new ShardDeleteEvent(clusterName, shardTbl.getShardName(), executors);
            shardEvent.setShardMonitorName(shardTbl.getSetinelMonitorName());
            shardEvent.setShardSentinels(getShardSentinelAddress(sentinelMap));
            shardDeleteEventListeners.forEach(shardDeleteEventListener -> shardEvent.addObserver(shardDeleteEventListener));
            clusterDeleteEvent.addShardEvent(shardEvent);
        }
    }
    clusterEventListeners.forEach(clusterDeleteEventListener -> clusterDeleteEvent.addObserver(clusterDeleteEventListener));
    return clusterDeleteEvent;
}
Also used : 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)

Example 3 with ShardDeleteEvent

use of com.ctrip.xpipe.redis.console.notifier.shard.ShardDeleteEvent 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 4 with ShardDeleteEvent

use of com.ctrip.xpipe.redis.console.notifier.shard.ShardDeleteEvent in project x-pipe by ctripcorp.

the class ShardServiceImpl method createShardDeleteEvent.

@VisibleForTesting
protected ShardDeleteEvent createShardDeleteEvent(String clusterName, String shardName, ShardTbl shardTbl, Map<Long, SetinelTbl> sentinelTblMap) {
    String monitorName = shardTbl.getSetinelMonitorName();
    ShardDeleteEvent shardDeleteEvent = new ShardDeleteEvent(clusterName, shardName, executors);
    shardDeleteEvent.setShardMonitorName(monitorName);
    // Splicing sentinel address as "127.0.0.1:6379,127.0.0.2:6380"
    StringBuffer sb = new StringBuffer();
    for (SetinelTbl setinelTbl : sentinelTblMap.values()) {
        sb.append(setinelTbl.getSetinelAddress()).append(",");
    }
    sb.deleteCharAt(sb.length() - 1);
    shardDeleteEvent.setShardSentinels(sb.toString());
    shardEventListeners.forEach(shardEventListener -> shardDeleteEvent.addObserver(shardEventListener));
    return shardDeleteEvent;
}
Also used : ShardDeleteEvent(com.ctrip.xpipe.redis.console.notifier.shard.ShardDeleteEvent) VisibleForTesting(com.ctrip.xpipe.utils.VisibleForTesting)

Example 5 with ShardDeleteEvent

use of com.ctrip.xpipe.redis.console.notifier.shard.ShardDeleteEvent in project x-pipe by ctripcorp.

the class DefaultSentinelManagerTest method removeSentinels.

@Test
public void removeSentinels() throws Exception {
    ShardDeleteEvent shardEvent = new ShardDeleteEvent("cluster", "shard", Executors.newFixedThreadPool(2));
    shardEvent.setShardSentinels("127.0.0.1:" + port);
    shardEvent.setShardMonitorName("sitemon-xpipegroup0");
    manager.removeShardSentinelMonitors(shardEvent);
}
Also used : ShardDeleteEvent(com.ctrip.xpipe.redis.console.notifier.shard.ShardDeleteEvent) AbstractConsoleIntegrationTest(com.ctrip.xpipe.redis.console.AbstractConsoleIntegrationTest) Test(org.junit.Test)

Aggregations

ShardDeleteEvent (com.ctrip.xpipe.redis.console.notifier.shard.ShardDeleteEvent)5 Test (org.junit.Test)3 AbstractConsoleIntegrationTest (com.ctrip.xpipe.redis.console.AbstractConsoleIntegrationTest)2 SetinelTbl (com.ctrip.xpipe.redis.console.model.SetinelTbl)2 ShardTbl (com.ctrip.xpipe.redis.console.model.ShardTbl)2 ShardEvent (com.ctrip.xpipe.redis.console.notifier.shard.ShardEvent)2 ClusterTbl (com.ctrip.xpipe.redis.console.model.ClusterTbl)1 VisibleForTesting (com.ctrip.xpipe.utils.VisibleForTesting)1