Search in sources :

Example 1 with CMHostNodePersistManager

use of com.cubrid.cubridmanager.ui.spi.persist.CMHostNodePersistManager in project cubrid-manager by CUBRID.

the class LoadMonitorStatisticDataProgress method buildServerInfo.

/**
	 * Build ServerInfo for multi-host monitor statistic.
	 * 
	 * @param hostInfo
	 * @return
	 */
public static ServerInfo buildServerInfo(StatisticChartHost hostInfo) {
    final CMHostNodePersistManager hostNodePersistManager = CMHostNodePersistManager.getInstance();
    ServerInfo serverInfo = hostInfo.getServerInfo();
    String serverName = null;
    String ip = null;
    int port = 0;
    String username = null;
    String password = null;
    boolean isInitial = false;
    /* For multi-host monitor statistic, will not keep the connection in ServerManager.
		 * So if the ServerInfo is null or disconnected, try to get the ServerInfo from ServerManager. 
		 * If failure, then build the ServerInfo with IP/Port/User Name/Password. 
		 */
    if (serverInfo == null || !serverInfo.isConnected()) {
        CubridServer cubridServer;
        if (hostInfo.getCubridServerId() != null) {
            serverName = hostInfo.getCubridServerId();
            cubridServer = hostNodePersistManager.getServer(serverName);
            if (cubridServer != null) {
                isInitial = true;
                ip = cubridServer.getHostAddress();
                port = Integer.parseInt(cubridServer.getMonPort());
                username = cubridServer.getUserName();
                password = cubridServer.getPassword();
            }
        }
        if (!isInitial) {
            ip = hostInfo.getIp();
            serverName = ip;
            port = hostInfo.getPort();
            username = hostInfo.getUser();
            password = hostInfo.getPassword();
        }
        serverInfo = hostNodePersistManager.getServerInfo(ip, port, username);
        if (serverInfo == null) {
            //if (serverInfo == null || !serverInfo.isConnected()) {
            serverInfo = new ServerInfo();
            serverInfo.setServerName(serverName);
            serverInfo.setHostAddress(ip);
            serverInfo.setHostMonPort(port);
            serverInfo.setHostJSPort(port + 1);
            serverInfo.setUserName(username);
            serverInfo.setUserPassword(password);
        }
    }
    return serverInfo;
}
Also used : CMHostNodePersistManager(com.cubrid.cubridmanager.ui.spi.persist.CMHostNodePersistManager) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) CubridServer(com.cubrid.common.ui.spi.model.CubridServer)

Aggregations

CubridServer (com.cubrid.common.ui.spi.model.CubridServer)1 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)1 CMHostNodePersistManager (com.cubrid.cubridmanager.ui.spi.persist.CMHostNodePersistManager)1