Search in sources :

Example 1 with SetinelTbl

use of com.ctrip.xpipe.redis.console.model.SetinelTbl in project x-pipe by ctripcorp.

the class SentinelUpdateControllerTest method testConvert2SentinelTbl.

@Test
public void testConvert2SentinelTbl() throws Exception {
    when(dcService.find(anyString())).thenReturn(new DcTbl().setId(1));
    SentinelModel sentinelModel = new SentinelModel().setDcName("JQ").setDesc("test").setSentinels(Arrays.asList(new HostPort("127.0.0.1", 6379), new HostPort("127.0.0.1", 6380), new HostPort("127.0.0.1", 6381)));
    SetinelTbl setinelTbl = controller.convert2SentinelTbl(sentinelModel);
    Assert.assertEquals(1, setinelTbl.getDcId());
    Assert.assertEquals("test", setinelTbl.getSetinelDescription());
    Assert.assertEquals("127.0.0.1:6379,127.0.0.1:6380,127.0.0.1:6381", setinelTbl.getSetinelAddress());
}
Also used : DcTbl(com.ctrip.xpipe.redis.console.model.DcTbl) SentinelModel(com.ctrip.xpipe.redis.console.model.SentinelModel) HostPort(com.ctrip.xpipe.endpoint.HostPort) SetinelTbl(com.ctrip.xpipe.redis.console.model.SetinelTbl) Test(org.junit.Test)

Example 2 with SetinelTbl

use of com.ctrip.xpipe.redis.console.model.SetinelTbl 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 3 with SetinelTbl

use of com.ctrip.xpipe.redis.console.model.SetinelTbl 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 4 with SetinelTbl

use of com.ctrip.xpipe.redis.console.model.SetinelTbl in project x-pipe by ctripcorp.

the class SentinelUpdateController method convert2SentinelTbl.

@VisibleForTesting
protected SetinelTbl convert2SentinelTbl(SentinelModel sentinelModel) {
    StringBuilder sb = new StringBuilder();
    for (HostPort hostPort : sentinelModel.getSentinels()) {
        sb.append(hostPort.getHost()).append(':').append(hostPort.getPort()).append(',');
    }
    String sentinels = sb.deleteCharAt(sb.length() - 1).toString();
    SetinelTbl proto = new SetinelTbl();
    proto.setSetinelAddress(sentinels);
    proto.setDeleted(false);
    proto.setSetinelDescription(sentinelModel.getDesc());
    proto.setDcId(dcService.find(sentinelModel.getDcName()).getId());
    return proto;
}
Also used : HostPort(com.ctrip.xpipe.endpoint.HostPort) SetinelTbl(com.ctrip.xpipe.redis.console.model.SetinelTbl) VisibleForTesting(com.ctrip.xpipe.utils.VisibleForTesting)

Example 5 with SetinelTbl

use of com.ctrip.xpipe.redis.console.model.SetinelTbl in project x-pipe by ctripcorp.

the class SentinelUpdateController method addSentinel.

@RequestMapping(value = "/sentinels", method = RequestMethod.POST)
public RetMessage addSentinel(@RequestBody SentinelModel sentinelModel) {
    try {
        SetinelTbl sentinel = convert2SentinelTbl(sentinelModel);
        sentinelService.insert(sentinel);
        return RetMessage.createSuccessMessage("Successfully create Sentinel");
    } catch (Exception e) {
        return RetMessage.createFailMessage(e.getMessage());
    }
}
Also used : SetinelTbl(com.ctrip.xpipe.redis.console.model.SetinelTbl) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

SetinelTbl (com.ctrip.xpipe.redis.console.model.SetinelTbl)7 Test (org.junit.Test)4 HostPort (com.ctrip.xpipe.endpoint.HostPort)2 ShardTbl (com.ctrip.xpipe.redis.console.model.ShardTbl)2 ShardDeleteEvent (com.ctrip.xpipe.redis.console.notifier.shard.ShardDeleteEvent)2 AbstractConsoleTest (com.ctrip.xpipe.redis.console.AbstractConsoleTest)1 DcTbl (com.ctrip.xpipe.redis.console.model.DcTbl)1 SentinelModel (com.ctrip.xpipe.redis.console.model.SentinelModel)1 ShardEvent (com.ctrip.xpipe.redis.console.notifier.shard.ShardEvent)1 VisibleForTesting (com.ctrip.xpipe.utils.VisibleForTesting)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1