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());
}
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);
}
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;
}
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;
}
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());
}
}
Aggregations