Search in sources :

Example 1 with NodeType

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

the class HaShardDemo method getHaNodeInfo.

protected NodeInfo getHaNodeInfo(ServerInfo serverInfo, String haMode) {
    //"heartbeatlist"
    GetHeartbeatNodeInfoTask getHeartbeatNodeInfoTask = new GetHeartbeatNodeInfoTask(serverInfo);
    getHeartbeatNodeInfoTask.setAllDb(true);
    getHeartbeatNodeInfoTask.execute();
    if (!getHeartbeatNodeInfoTask.isSuccess()) {
        return null;
    }
    String status = getHeartbeatNodeInfoTask.getCurrentHostStatus();
    NodeType type = CMServiceAnalysisUtil.convertHaStatToNodeType(status);
    HaNode nodeInfo = null;
    if (type != NodeType.NORMAL) {
        nodeInfo = new HaNode(type);
        nodeInfo.buildStatus("ON");
        nodeInfo.setHostStatusInfoList(getHeartbeatNodeInfoTask.getHAHostStatusList());
    } else if ("on".equals(haMode)) {
        nodeInfo = new HaNode(NodeType.SLAVE);
        nodeInfo.buildStatus("OFF");
    } else if ("replica".equals(haMode)) {
        nodeInfo = new HaNode(NodeType.REPLICA);
        nodeInfo.buildStatus("OFF");
    }
    //"getallsysparam"/"cubrid_ha.conf"
    GetHAConfParameterTask getHAConfParameterTask = new GetHAConfParameterTask(serverInfo);
    getHAConfParameterTask.execute();
    BrokerInfos brokerInfos = new BrokerInfos();
    GetBrokerStatusInfosTask<BrokerInfos> getBrokerStatusInfosTask = new GetBrokerStatusInfosTask<BrokerInfos>(serverInfo, CommonSendMsg.getGetBrokerStatusItems(), brokerInfos);
    getBrokerStatusInfosTask.execute();
    if (!getHAConfParameterTask.isSuccess() || !getBrokerStatusInfosTask.isSuccess()) {
        return null;
    }
    brokerInfos = getBrokerStatusInfosTask.getResultModel();
    if (brokerInfos != null) {
        nodeInfo.setBrokerInfoList(brokerInfos.getBorkerInfoList());
    }
    Map<String, Map<String, String>> haConfParas = getHAConfParameterTask.getConfParameters();
    Map<String, String> haCommonConf = haConfParas.get("[common]");
    //		String haNodeStr = haCommonConf.get("ha_node_list").substring("cubrid@".length());
    //		List<String> haNodeList = Arrays.asList(haNodeStr.split(":"));
    //		String replicaStr = haCommonConf.get("ha_replica_list");
    //		List<String> replicaNodeList = Arrays.asList(replicaStr.substring("cubrid@".length()).split(":"));
    String dbList = haCommonConf.get("ha_db_list");
    if (dbList.indexOf(",") > -1) {
        String[] dbAr = dbList.split(",");
        for (String s : dbAr) {
            if (s.trim().length() > 0) {
                nodeInfo.addDatabase(s);
            }
        }
    } else {
        nodeInfo.addDatabase(dbList);
    }
    return nodeInfo;
}
Also used : HaNode(com.cubrid.cubridmanager.core.cubrid.service.model.HaNode) BrokerInfos(com.cubrid.cubridmanager.core.broker.model.BrokerInfos) NodeType(com.cubrid.cubridmanager.core.cubrid.service.model.NodeType) GetBrokerStatusInfosTask(com.cubrid.cubridmanager.core.broker.task.GetBrokerStatusInfosTask) GetHAConfParameterTask(com.cubrid.cubridmanager.core.common.task.GetHAConfParameterTask) Map(java.util.Map) GetHeartbeatNodeInfoTask(com.cubrid.cubridmanager.core.mondashboard.task.GetHeartbeatNodeInfoTask)

Example 2 with NodeType

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

NodeType (com.cubrid.cubridmanager.core.cubrid.service.model.NodeType)2 Map (java.util.Map)2 BrokerInfos (com.cubrid.cubridmanager.core.broker.model.BrokerInfos)1 GetBrokerStatusInfosTask (com.cubrid.cubridmanager.core.broker.task.GetBrokerStatusInfosTask)1 GetHAConfParameterTask (com.cubrid.cubridmanager.core.common.task.GetHAConfParameterTask)1 DbLocationInfo (com.cubrid.cubridmanager.core.cubrid.service.model.DbLocationInfo)1 HaNode (com.cubrid.cubridmanager.core.cubrid.service.model.HaNode)1 GetHeartbeatNodeInfoTask (com.cubrid.cubridmanager.core.mondashboard.task.GetHeartbeatNodeInfoTask)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1