use of com.cubrid.cubridmanager.core.common.task.GetDatabasesParameterTask 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);
}
}
Aggregations