use of com.cubrid.cubridmanager.core.cubrid.service.model.BrokerNode in project cubrid-manager by CUBRID.
the class HaShardManagerTest method testShard.
public void testShard() {
HaShardManager manager = HaShardManager.getInstance();
assertNotNull(manager);
HaNode replicaNode = new HaNode(NodeType.REPLICA);
replicaNode.setIp(replicaIp);
replicaNode.setServiceName(haServiceName);
ShardNode shardNode = new ShardNode();
shardNode.setIp(shardIp);
shardNode.setServiceName(shardServiceName);
BrokerNode brokerNode = new BrokerNode();
brokerNode.setIp(brokerIp);
brokerNode.setHostName(brokerHost);
brokerNode.setServiceName(haServiceName);
manager.add(brokerNode);
manager.add(shardNode);
manager.add(replicaNode);
List<NodeInfo> nodeList = manager.getNodeList();
assertTrue(nodeList.contains(replicaNode));
assertTrue(nodeList.contains(shardNode));
assertTrue(nodeList.contains(brokerNode));
int index = manager.find(brokerNode);
assertEquals(nodeList.get(index), brokerNode);
BrokerNode brokerNode2 = new BrokerNode();
String brokerIp2 = "127.0.0.1";
brokerNode2.setIp(brokerIp2);
assertTrue(manager.find(brokerNode2) == -1);
assertEquals(manager.findByIp(shardIp), shardNode);
assertNull(manager.findByIp(brokerIp2));
List<NodeInfo> haGroups = manager.findGroupByIp(replicaIp);
assertTrue(haGroups.size() == 2);
assertTrue(haGroups.contains(replicaNode));
assertTrue(haGroups.contains(brokerNode));
assertFalse(haGroups.contains(shardNode));
List<NodeInfo> shardGroups = manager.findGroupByServiceName(shardServiceName);
assertTrue(shardGroups.size() == 1);
assertTrue(shardGroups.contains(shardNode));
assertFalse(shardGroups.contains(replicaNode));
List<NodeInfo> haList = manager.getHaNodes();
assertTrue(haList.size() == 1);
assertTrue(haList.contains(replicaNode));
assertFalse(haList.contains(brokerNode));
List<NodeInfo> shardList = manager.getShardNodes();
assertTrue(shardList.size() == 1);
assertTrue(shardList.contains(shardNode));
assertFalse(shardList.contains(brokerNode));
List<NodeInfo> brokerList = manager.getBrokerNodes();
assertTrue(brokerList.size() == 1);
assertTrue(brokerList.contains(brokerNode));
assertFalse(brokerList.contains(shardNode));
int haIndex = manager.find(replicaNode);
int shardIndex = manager.find(shardNode);
assertTrue(haIndex > shardIndex);
manager.sort();
int haIndex2 = manager.find(replicaNode);
int shardIndex2 = manager.find(shardNode);
assertTrue(haIndex2 < shardIndex2);
//test remove method
manager.remove(shardNode);
assertTrue(manager.find(shardNode) == -1);
assertNull(manager.findByIp(shardIp));
manager.add(shardNode);
manager.remove(brokerNode);
testRegisterBrokerHostInHaShard(manager);
}
use of com.cubrid.cubridmanager.core.cubrid.service.model.BrokerNode in project cubrid-manager by CUBRID.
the class HaShardManagerTest method testHa.
// test ha/shard separately because of use only 3 node to install cubrid
// we suppose that: HA/shard node on the same machine
public void testHa() {
HaShardManager manager = HaShardManager.getInstance();
assertNotNull(manager);
HaNode haNode = new HaNode(NodeType.SLAVE);
haNode.setIp(haIp);
haNode.setHostName(haHost);
haNode.setServiceName(haServiceName);
HaNode replicaNode = new HaNode(NodeType.REPLICA);
replicaNode.setIp(replicaIp);
replicaNode.setServiceName(haServiceName);
BrokerNode brokerNode = new BrokerNode();
brokerNode.setIp(brokerIp);
brokerNode.setHostName(brokerHost);
brokerNode.setServiceName(haServiceName);
manager.add(brokerNode);
manager.add(replicaNode);
manager.add(haNode);
List<NodeInfo> nodeList = manager.getNodeList();
assertTrue(nodeList.contains(haNode));
assertTrue(nodeList.contains(replicaNode));
assertTrue(nodeList.contains(brokerNode));
int index = manager.find(brokerNode);
assertEquals(nodeList.get(index), brokerNode);
BrokerNode brokerNode2 = new BrokerNode();
String brokerIp2 = "127.0.0.1";
brokerNode2.setIp(brokerIp2);
assertTrue(manager.find(brokerNode2) == -1);
assertEquals(manager.findByIp(brokerIp), brokerNode);
assertNull(manager.findByIp(brokerIp2));
assertEquals(manager.findByHostName(haHost), haNode);
assertNull(manager.findByHostName("localhost"));
List<NodeInfo> haGroups = manager.findGroupByIp(haIp);
assertTrue(haGroups.size() == 3);
assertTrue(haGroups.contains(haNode));
assertTrue(haGroups.contains(replicaNode));
assertTrue(haGroups.contains(brokerNode));
List<NodeInfo> haGroups2 = manager.findGroupByHostName(haHost);
assertTrue(haGroups2.size() == 3);
assertTrue(haGroups2.contains(haNode));
assertTrue(haGroups2.contains(replicaNode));
assertTrue(haGroups2.contains(brokerNode));
List<NodeInfo> shardGroups = manager.findGroupByServiceName(shardServiceName);
assertTrue(shardGroups.size() == 0);
List<NodeInfo> haList = manager.getHaNodes();
assertTrue(haList.size() == 2);
assertTrue(haList.contains(haNode));
assertTrue(haList.contains(replicaNode));
assertFalse(haList.contains(brokerNode));
List<NodeInfo> shardList = manager.getShardNodes();
assertTrue(shardList.size() == 0);
List<NodeInfo> brokerList = manager.getBrokerNodes();
assertTrue(brokerList.size() == 1);
assertTrue(brokerList.contains(brokerNode));
assertFalse(brokerList.contains(haNode));
int haIndex = manager.find(haNode);
int brokerIndex = manager.find(brokerNode);
assertTrue(haIndex > brokerIndex);
manager.sort();
int haIndex2 = manager.find(haNode);
int brokerIndex2 = manager.find(brokerNode);
assertTrue(haIndex2 < brokerIndex2);
//test remove method
manager.remove(brokerNode);
assertTrue(manager.find(brokerNode) == -1);
assertNull(manager.findByIp(brokerIp));
testRegisterBrokerHostInHaShard(manager);
}
use of com.cubrid.cubridmanager.core.cubrid.service.model.BrokerNode in project cubrid-manager by CUBRID.
the class HaShardManagerTest method testRegisterBrokerHostInHaShard.
public void testRegisterBrokerHostInHaShard(HaShardManager manager) {
try {
HaShardDemo demo = new HaShardDemo();
demo.registerServiceAndBuildInfo(brokerIp, brokerCmPort, brokerCmUser, brokerCmPass, haServiceName, brokerConnName, brokerHost);
manager.registerBrokerHostInHaShard();
BrokerNode brokerNode = (BrokerNode) manager.findByIp(brokerIp);
Set<String> hostSet = brokerNode.getHostSet();
if (hostSet != null && hostSet.contains(haHost)) {
HaNode haNode = (HaNode) manager.findByHostName(haHost);
assertTrue(haNode.getRemoteBrokers().contains(brokerNode));
}
} finally {
ServerInfo serverInfo = ServerManager.getInstance().getServer(brokerIp, brokerCmPort, brokerCmUser);
if (serverInfo != null) {
ServerManager.getInstance().removeServer(serverInfo.getHostAddress(), serverInfo.getHostMonPort(), serverInfo.getUserName());
}
}
}
use of com.cubrid.cubridmanager.core.cubrid.service.model.BrokerNode in project cubrid-manager by CUBRID.
the class HaShardDemo method getBrokerNodeInfo.
protected NodeInfo getBrokerNodeInfo(ServerInfo serverInfo) {
BrokerNode nodeInfo = new BrokerNode();
BrokerInfos brokerInfos = new BrokerInfos();
GetBrokerStatusInfosTask<BrokerInfos> getBrokerStatusInfosTask = new GetBrokerStatusInfosTask<BrokerInfos>(serverInfo, CommonSendMsg.getGetBrokerStatusItems(), brokerInfos);
getBrokerStatusInfosTask.execute();
if (!getBrokerStatusInfosTask.isSuccess()) {
return null;
}
brokerInfos = getBrokerStatusInfosTask.getResultModel();
BrokerInfoList brokerInfoList = brokerInfos.getBorkerInfoList();
if (!(brokerInfoList != null && brokerInfoList.getBrokerInfoList() != null && brokerInfoList.getBrokerInfoList().size() > 0)) {
return null;
}
nodeInfo.setBrokerInfoList(brokerInfoList);
//Set<String> dbHosts = new HashSet<String>();
for (BrokerInfo brokerInfo : brokerInfoList.getBrokerInfoList()) {
if (brokerInfo == null) {
continue;
}
String brokerName = brokerInfo.getName();
String brokerPort = brokerInfo.getPort();
BrokerStatusInfos brokerStatusInfos = new BrokerStatusInfos();
GetBrokerStatusInfosTask<BrokerStatusInfos> statisTask = new GetBrokerStatusInfosTask<BrokerStatusInfos>(serverInfo, CommonSendMsg.getGetBrokerStatusItems(), brokerStatusInfos);
statisTask.setBrokerName(brokerName);
statisTask.execute();
if (!statisTask.isSuccess()) {
continue;
}
brokerStatusInfos = statisTask.getResultModel();
nodeInfo.addBrokerStatus(brokerPort, brokerStatusInfos);
}
return nodeInfo;
}
Aggregations