Search in sources :

Example 6 with NodeInfo

use of com.cubrid.cubridmanager.core.cubrid.service.model.NodeInfo in project cubrid-manager by CUBRID.

the class HaShardDemo method getRequiredInfo.

protected NodeInfo getRequiredInfo(ServerInfo serverInfo, List<DbLocationInfo> dbLocationInfoList) {
    NodeInfo info = null;
    //"getallsysparam"/"cubrid.conf"
    GetCubridConfParameterTask getCubridConfParameterTask = new GetCubridConfParameterTask(serverInfo);
    getCubridConfParameterTask.execute();
    if (!getCubridConfParameterTask.isSuccess()) {
        return null;
    }
    Map<String, Map<String, String>> cubConfParas = getCubridConfParameterTask.getConfParameters();
    String haMode = cubConfParas.get("common").get("ha_mode");
    if ("on".equals(haMode) || "replica".equals(haMode)) {
        info = getHaNodeInfo(serverInfo, haMode);
    } else if (CompatibleUtil.isAfter920(serverInfo)) {
        info = getShardNodeIndo92(serverInfo);
        if (info == null && CMServiceAnalysisUtil.isAccessedByRemoteHost(dbLocationInfoList)) {
            info = getBrokerNodeInfo(serverInfo);
        }
    } else {
        GetShardStatusTask getShardStatusTask = new GetShardStatusTask(serverInfo, null);
        getShardStatusTask.execute();
        if (getShardStatusTask.isSuccess()) {
            //check shard
            info = getShardNodeIndo(serverInfo);
            ((ShardNode) info).setShardsStatus(getShardStatusTask.getShardsStatus());
        } else if (CMServiceAnalysisUtil.isAccessedByRemoteHost(dbLocationInfoList)) {
            info = getBrokerNodeInfo(serverInfo);
        }
    }
    return info;
}
Also used : NodeInfo(com.cubrid.cubridmanager.core.cubrid.service.model.NodeInfo) GetCubridConfParameterTask(com.cubrid.cubridmanager.core.common.task.GetCubridConfParameterTask) Map(java.util.Map) GetShardStatusTask(com.cubrid.cubridmanager.core.shard.task.GetShardStatusTask)

Example 7 with NodeInfo

use of com.cubrid.cubridmanager.core.cubrid.service.model.NodeInfo 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);
    }
}
Also used : ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) GetDatabasesParameterTask(com.cubrid.cubridmanager.core.common.task.GetDatabasesParameterTask) ArrayList(java.util.ArrayList) ShardNode(com.cubrid.cubridmanager.core.cubrid.service.model.ShardNode) NodeInfo(com.cubrid.cubridmanager.core.cubrid.service.model.NodeInfo) MonitoringTask(com.cubrid.cubridmanager.core.common.task.MonitoringTask) Shards(com.cubrid.cubridmanager.core.shard.model.Shards) Shard(com.cubrid.cubridmanager.core.shard.model.Shard) Map(java.util.Map) DbLocationInfo(com.cubrid.cubridmanager.core.cubrid.service.model.DbLocationInfo)

Example 8 with NodeInfo

use of com.cubrid.cubridmanager.core.cubrid.service.model.NodeInfo in project cubrid-manager by CUBRID.

the class HaShardManager method findGroupByIp.

public List<NodeInfo> findGroupByIp(String ip) {
    List<NodeInfo> result = null;
    NodeInfo node = findByIp(ip);
    if (node != null) {
        result = findGroupByServiceName(node.getServiceName());
    }
    return result;
}
Also used : NodeInfo(com.cubrid.cubridmanager.core.cubrid.service.model.NodeInfo)

Example 9 with NodeInfo

use of com.cubrid.cubridmanager.core.cubrid.service.model.NodeInfo in project cubrid-manager by CUBRID.

the class HaShardManager method findGroupByHostName.

public List<NodeInfo> findGroupByHostName(String hostName) {
    List<NodeInfo> result = null;
    NodeInfo node = findByHostName(hostName);
    if (node != null) {
        result = findGroupByServiceName(node.getServiceName());
    }
    return result;
}
Also used : NodeInfo(com.cubrid.cubridmanager.core.cubrid.service.model.NodeInfo)

Example 10 with NodeInfo

use of com.cubrid.cubridmanager.core.cubrid.service.model.NodeInfo in project cubrid-manager by CUBRID.

the class HaShardDemoTest method testReplicaNode.

public void testReplicaNode() {
    try {
        demo.registerServiceAndBuildInfo(replicaIp, replicaCmPort, replicaCmUser, replicaCmPass, serviceName, replicaConnName, replicaHost);
        NodeInfo node = manager.findByIp(replicaIp);
        assertEquals(node.getType(), NodeType.REPLICA);
        assertEquals(node.getServiceName(), serviceName);
        assertEquals(node.getHostName(), replicaHost);
        assertEquals(node.getCmConnectName(), replicaConnName);
    } finally {
        ServerInfo serverInfo = ServerManager.getInstance().getServer(replicaIp, replicaCmPort, replicaCmUser);
        ServerManager.getInstance().removeServer(serverInfo.getHostAddress(), serverInfo.getHostMonPort(), serverInfo.getUserName());
    }
}
Also used : NodeInfo(com.cubrid.cubridmanager.core.cubrid.service.model.NodeInfo) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo)

Aggregations

NodeInfo (com.cubrid.cubridmanager.core.cubrid.service.model.NodeInfo)11 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)5 BrokerNode (com.cubrid.cubridmanager.core.cubrid.service.model.BrokerNode)2 HaNode (com.cubrid.cubridmanager.core.cubrid.service.model.HaNode)2 ShardNode (com.cubrid.cubridmanager.core.cubrid.service.model.ShardNode)2 Map (java.util.Map)2 GetCubridConfParameterTask (com.cubrid.cubridmanager.core.common.task.GetCubridConfParameterTask)1 GetDatabasesParameterTask (com.cubrid.cubridmanager.core.common.task.GetDatabasesParameterTask)1 MonitoringTask (com.cubrid.cubridmanager.core.common.task.MonitoringTask)1 DbLocationInfo (com.cubrid.cubridmanager.core.cubrid.service.model.DbLocationInfo)1 HaShardDemo (com.cubrid.cubridmanager.core.cubrid.service.task.HaShardDemo)1 HaShardManager (com.cubrid.cubridmanager.core.cubrid.service.task.HaShardManager)1 Shard (com.cubrid.cubridmanager.core.shard.model.Shard)1 Shards (com.cubrid.cubridmanager.core.shard.model.Shards)1 GetShardStatusTask (com.cubrid.cubridmanager.core.shard.task.GetShardStatusTask)1 ArrayList (java.util.ArrayList)1