Search in sources :

Example 1 with DbLocationInfo

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

the class CMServiceAnalysisUtil method addDbLocaltionInfos.

/**
	 * Put DbLocationInfo(s) into
	 * <i>dbLocationInfoList(List<DbLocationInfo>)</i>. DbLocationInfo is
	 * constructed by the info stored in <i>dbParamMapList(List<Map<String,
	 * String>>)</i>
	 *
	 * @param dbParamMapList
	 * @param dbLocationInfoList
	 */
public static void addDbLocaltionInfos(List<Map<String, String>> dbParamMapList, List<DbLocationInfo> dbLocationInfoList) {
    if (dbParamMapList == null || dbLocationInfoList == null) {
        return;
    }
    for (Map<String, String> dbParamMap : dbParamMapList) {
        if (StringUtil.isEmpty(dbParamMap.get("db-name"))) {
            continue;
        }
        DbLocationInfo dbLocalInfo = new DbLocationInfo();
        dbLocalInfo.setDbName(dbParamMap.get("db-name"));
        dbLocalInfo.setVolPath(dbParamMap.get("vol-path"));
        if (!StringUtil.isEmpty(dbParamMap.get("db-host"))) {
            String[] dbHostAr = dbParamMap.get("db-host").split(":");
            dbLocalInfo.addAllDbHosts(dbHostAr);
        }
        dbLocalInfo.setLogPath(dbParamMap.get("log-path"));
        dbLocalInfo.setLobBasePath(dbParamMap.get("lob-base-path"));
        dbLocationInfoList.add(dbLocalInfo);
    }
}
Also used : DbLocationInfo(com.cubrid.cubridmanager.core.cubrid.service.model.DbLocationInfo)

Example 2 with DbLocationInfo

use of com.cubrid.cubridmanager.core.cubrid.service.model.DbLocationInfo 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 3 with DbLocationInfo

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

the class CMServiceAnalysisUtilTest method testCMServiceAnalysisUtil.

public void testCMServiceAnalysisUtil() {
    //test isLocalHost()
    String host = "127.0.0.1";
    String host2 = "localhost";
    String host3 = "192.168.1.60";
    String host4 = "www.cubrid.org";
    assertTrue(CMServiceAnalysisUtil.isLocalHost(host));
    assertTrue(CMServiceAnalysisUtil.isLocalHost(host2));
    assertFalse(CMServiceAnalysisUtil.isLocalHost(host3));
    assertFalse(CMServiceAnalysisUtil.isLocalHost(host4));
    //test isIp()
    assertTrue(CMServiceAnalysisUtil.isIp("127.0.0.1"));
    assertTrue(CMServiceAnalysisUtil.isIp("192.168.1.60"));
    assertFalse(CMServiceAnalysisUtil.isIp("192.168.1.256"));
    assertFalse(CMServiceAnalysisUtil.isIp("www.cubrid.org"));
    //test addDbLocaltionInfos()
    List<DbLocationInfo> dbLocationInfoList = new ArrayList<DbLocationInfo>();
    Map<String, String> dbParamMap = new HashMap<String, String>();
    dbParamMap.put("db-name", "demodb");
    dbParamMap.put("vol-path", "/home1/demo/CUBRID/databases/demodb");
    dbParamMap.put("db-host", "dev-cub-ha-002.ncl:dev-cub-ha-004.ncl");
    dbParamMap.put("log-path", "/home1/demo/CUBRID/databases/demodb");
    dbParamMap.put("lob-base-path", "file:/home1/demo/CUBRID/databases/demodb/lob");
    List<Map<String, String>> dbParamMapList = new ArrayList<Map<String, String>>();
    dbParamMapList.add(dbParamMap);
    CMServiceAnalysisUtil.addDbLocaltionInfos(dbParamMapList, dbLocationInfoList);
    assertTrue(dbLocationInfoList.size() > 0);
    DbLocationInfo dbLocalInfo = dbLocationInfoList.get(0);
    assertNotNull(dbLocalInfo);
    assertEquals(dbLocalInfo.getDbName(), "demodb");
    //test convertHaStatToNodeType()
    NodeType type1 = CMServiceAnalysisUtil.convertHaStatToNodeType("master");
    NodeType type2 = CMServiceAnalysisUtil.convertHaStatToNodeType("slave");
    NodeType type3 = CMServiceAnalysisUtil.convertHaStatToNodeType("replica");
    assertEquals(type1, NodeType.MASTER);
    assertEquals(type2, NodeType.SLAVE);
    assertEquals(type3, NodeType.REPLICA);
    //test isAccessedByRemoteHost()
    assertTrue(CMServiceAnalysisUtil.isAccessedByRemoteHost(dbLocationInfoList));
}
Also used : HashMap(java.util.HashMap) NodeType(com.cubrid.cubridmanager.core.cubrid.service.model.NodeType) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) DbLocationInfo(com.cubrid.cubridmanager.core.cubrid.service.model.DbLocationInfo)

Aggregations

DbLocationInfo (com.cubrid.cubridmanager.core.cubrid.service.model.DbLocationInfo)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)1 GetDatabasesParameterTask (com.cubrid.cubridmanager.core.common.task.GetDatabasesParameterTask)1 MonitoringTask (com.cubrid.cubridmanager.core.common.task.MonitoringTask)1 NodeInfo (com.cubrid.cubridmanager.core.cubrid.service.model.NodeInfo)1 NodeType (com.cubrid.cubridmanager.core.cubrid.service.model.NodeType)1 ShardNode (com.cubrid.cubridmanager.core.cubrid.service.model.ShardNode)1 Shard (com.cubrid.cubridmanager.core.shard.model.Shard)1 Shards (com.cubrid.cubridmanager.core.shard.model.Shards)1 HashMap (java.util.HashMap)1