use of com.cubrid.cubridmanager.core.cubrid.service.model.ShardNode 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.ShardNode in project cubrid-manager by CUBRID.
the class HaShardDemo method registerServiceAndBuildInfo.
/**
* For HA, right now, we cannot get the host name from CMS, so need
* specified by user.
*
* @param ip
* @param port
* @param userName
* @param password
* @param serviceName
* @param connectName
* @param nodeName Node name that registered in /etc/hosts.
* @return
*/
public void registerServiceAndBuildInfo(String ip, int port, String userName, String password, String serviceName, String connectName, String nodeName) {
HaShardManager haShardManager = HaShardManager.getInstance();
//build server info
ServerInfo serverInfo = ServerManager.getInstance().getServer(ip, port, userName);
if (serverInfo == null) {
serverInfo = new ServerInfo();
serverInfo.setHostAddress(ip);
serverInfo.setHostMonPort(port);
serverInfo.setHostJSPort(port + 1);
serverInfo.setUserName(userName);
}
serverInfo.setServerName(connectName);
serverInfo.setUserPassword(password);
serverInfo.setJdbcDriverVersion("Auto Detect");
// connect to server
addServer(serverInfo);
MonitoringTask monitoringTask = serverInfo.getMonitoringTask();
String clientVersion = "9.3.0";
serverInfo = monitoringTask.connectServer(clientVersion, 1000);
if (serverInfo.isConnected()) {
addServer(serverInfo);
GetDatabasesParameterTask getDatabasesParameterTask = new GetDatabasesParameterTask(serverInfo);
getDatabasesParameterTask.execute();
if (!getDatabasesParameterTask.isSuccess()) {
return;
}
List<Map<String, String>> dbParamMapList = getDatabasesParameterTask.getConfParameters();
List<DbLocationInfo> dbLocationInfoList = new ArrayList<DbLocationInfo>();
CMServiceAnalysisUtil.addDbLocaltionInfos(dbParamMapList, dbLocationInfoList);
// get required info from server and build NodeInfo
NodeInfo info = getRequiredInfo(serverInfo, dbLocationInfoList);
if (info != null) {
info.setDbLocationInfoList(dbLocationInfoList);
info.setServiceName(serviceName);
info.setCmConnectName(connectName);
info.setIp(ip);
info.setHostName(nodeName);
info.setServerInfo(serverInfo);
if (info instanceof ShardNode) {
Shards shards = ((ShardNode) info).getShards();
Shard shard = shards.getShardList().get(0);
List<String> connections = shard.getShardConnectionFile().getConnections();
for (String s : connections) {
String[] ar = s.split(",");
if (ip.equals(ar[2]) || nodeName.equals(ar[2])) {
//???
((ShardNode) info).setSeverStatus("Shard #" + ar[0]);
//???
((ShardNode) info).genStatus();
}
}
}
haShardManager.add(info);
}
} else {
removeServer(serverInfo);
}
}
use of com.cubrid.cubridmanager.core.cubrid.service.model.ShardNode in project cubrid-manager by CUBRID.
the class HaShardDemo method getShardNodeIndo92.
protected NodeInfo getShardNodeIndo92(ServerInfo serverInfo) {
ShardNode info = null;
GetBrokerConfParameterTask getBrokerConfParameterTask = new GetBrokerConfParameterTask(serverInfo);
getBrokerConfParameterTask.execute();
if (!getBrokerConfParameterTask.isSuccess()) {
return null;
}
Shards shards = new Shards();
Map<String, Map<String, String>> confParams = getBrokerConfParameterTask.getConfParameters();
List<Map<String, String>> shardParamsList = new ArrayList<Map<String, String>>();
for (Entry<String, Map<String, String>> entry : confParams.entrySet()) {
String brokerName = entry.getKey();
Map<String, String> params = entry.getValue();
if (StringUtils.equalsIgnoreCase(params.get("SHARD"), "ON")) {
shardParamsList.add(params);
Shard shard = new Shard();
shard.setName(brokerName.toLowerCase(Locale.getDefault()));
shard.setProperties(params);
ShardConnection shardConnection = new ShardConnection();
shard.setShardConnectionFile(shardConnection);
GetShardConfTask<ShardConnection> getShardConnectionConfTask = new GetShardConfTask<ShardConnection>(serverInfo, shardConnection);
getShardConnectionConfTask.execute();
getShardConnectionConfTask.loadDataToModel();
shard.setShardConnectionFile(shardConnection);
shards.addShard(shard);
}
}
if (shardParamsList.size() == 0) {
return null;
}
info = new ShardNode();
for (Map<String, String> params : shardParamsList) {
String shardDbName = params.get("SHARD_DB_NAME");
info.addDatabase(shardDbName);
}
GetDatabaseListTask getDatabaseListTask = new GetDatabaseListTask(serverInfo);
getDatabaseListTask.execute();
List<DatabaseInfo> databaseInfoList = getDatabaseListTask.loadDatabaseInfo();
int shardDbCnt = info.getDatabases().size();
int matchedCnt = 0;
for (DatabaseInfo dbInfo : databaseInfoList) {
for (String dbName : info.getDatabases()) {
if (dbInfo.getDbName().equals(dbName)) {
if (DbRunningType.CS.equals(dbInfo.getRunningType())) {
info.setDbStatus(dbName, "ON");
} else {
info.setDbStatus(dbName, "OFF");
}
matchedCnt++;
if (shardDbCnt <= matchedCnt) {
break;
} else {
continue;
}
}
}
}
info.setShards(shards);
return info;
}
use of com.cubrid.cubridmanager.core.cubrid.service.model.ShardNode in project cubrid-manager by CUBRID.
the class HaShardDemo method getShardNodeIndo.
protected NodeInfo getShardNodeIndo(ServerInfo serverInfo) {
ShardNode nodeInfo = new ShardNode();
Shards shards = new Shards();
GetShardConfTask<Shards> getShardConfTask = new GetShardConfTask<Shards>(serverInfo, shards);
getShardConfTask.execute();
if (!getShardConfTask.isSuccess()) {
return null;
}
getShardConfTask.loadDataToModel();
serverInfo.setShards(shards);
List<Shard> shardList = shards.getShardList();
for (int i = 0; shardList != null && i < shardList.size(); i++) {
Shard shard = shardList.get(i);
String dbName = shard.getValue("SHARD_DB_NAME");
nodeInfo.addDatabase(dbName);
ShardConnection shardConnection = new ShardConnection();
shard.setShardConnectionFile(shardConnection);
GetShardConfTask<ShardConnection> getShardConnectionConfTask = new GetShardConfTask<ShardConnection>(serverInfo, shardConnection);
getShardConnectionConfTask.execute();
getShardConnectionConfTask.loadDataToModel();
}
GetDatabaseListTask getDatabaseListTask = new GetDatabaseListTask(serverInfo);
getDatabaseListTask.execute();
List<DatabaseInfo> databaseInfoList = getDatabaseListTask.loadDatabaseInfo();
int shardDbCnt = nodeInfo.getDatabases().size();
int matchedCnt = 0;
for (DatabaseInfo dbInfo : databaseInfoList) {
for (String dbName : nodeInfo.getDatabases()) {
if (dbInfo.getDbName().equals(dbName)) {
if (DbRunningType.CS.equals(dbInfo.getRunningType())) {
nodeInfo.setDbStatus(dbName, "ON");
} else {
nodeInfo.setDbStatus(dbName, "OFF");
}
matchedCnt++;
if (shardDbCnt <= matchedCnt) {
break;
} else {
continue;
}
}
}
}
nodeInfo.setShards(shards);
return nodeInfo;
}
Aggregations