Search in sources :

Example 6 with StatisticType

use of com.cubrid.cubridmanager.core.monstatistic.model.StatisticParamUtil.StatisticType in project cubrid-manager by CUBRID.

the class EditStatisticHostDialog method refreshDbAndBrokerData.

/**
	 * Refresh database and broker data for the selected host.
	 *
	 * @param isSupported whether selected CUBRID host support monitor statistic
	 *        feature
	 */
private void refreshDbAndBrokerData(boolean isSupported, boolean isInitial) {
    boolean isDbDataValid = false;
    boolean isBrokerDataValid = false;
    boolean isNeedInitDbNameValue = isNewHost || !isInitial || dbNameValue == null;
    boolean isNeedInitBrokerNameValue = isNewHost || !isInitial || brokerNameValue == null;
    boolean isDbContained = false;
    if (isSupported) {
        List<String> dbNameList = serverInfo.getAllDatabaseList();
        if (dbNameList != null && dbNameList.size() > 0) {
            GetDatabaseListTask getDatabaseListTask = new GetDatabaseListTask(serverInfo);
            getDatabaseListTask.execute();
            if (getDatabaseListTask.isSuccess()) {
                List<DatabaseInfo> dbInfoList = getDatabaseListTask.loadDatabaseInfo();
                int activeDbCount = 0;
                for (DatabaseInfo dbInfo : dbInfoList) {
                    if (DbRunningType.CS.equals(dbInfo.getRunningType())) {
                        for (String dbName : dbNameList) {
                            if (dbName.equals(dbInfo.getDbName())) {
                                activeDbCount++;
                                break;
                            }
                        }
                    }
                }
                if (activeDbCount != 0) {
                    isDbDataValid = true;
                    itemsDbName = new String[activeDbCount];
                    int itemsDbNameIndex = 0;
                    for (DatabaseInfo dbInfo : dbInfoList) {
                        if (DbRunningType.CS.equals(dbInfo.getRunningType())) {
                            for (String dbName : dbNameList) {
                                if (dbName.equals(dbInfo.getDbName())) {
                                    itemsDbName[itemsDbNameIndex++] = dbName;
                                    //check whether the DB name is in the DB name list when edit host
                                    if (isInitial && !isNewHost && dbName.equals(dbNameValue)) {
                                        isDbContained = true;
                                    }
                                    break;
                                }
                            }
                        }
                    }
                    if (isNeedInitDbNameValue) {
                        dbNameValue = itemsDbName[0];
                    }
                }
            }
            if (serverInfo.getBrokerInfos() != null && serverInfo.getBrokerInfos().getBorkerInfoList() != null && serverInfo.getBrokerInfos().getBorkerInfoList().getBrokerInfoList() != null && serverInfo.getBrokerInfos().getBorkerInfoList().getBrokerInfoList().size() > 0) {
                List<BrokerInfo> brokerInfoList = serverInfo.getBrokerInfos().getBorkerInfoList().getBrokerInfoList();
                itemsBrokerName = new String[brokerInfoList.size()];
                for (int i = 0; i < brokerInfoList.size(); i++) {
                    itemsBrokerName[i] = brokerInfoList.get(i).getName();
                }
                if (isNeedInitBrokerNameValue) {
                    brokerNameValue = itemsBrokerName[0];
                }
                isBrokerDataValid = true;
            }
        }
    }
    if (!isDbDataValid) {
        itemsDbName = ITEMS_EMPTY;
        if (isNeedInitDbNameValue) {
            dbNameValue = VALUE_DEFAULT;
        }
    }
    if (!isBrokerDataValid) {
        itemsBrokerName = ITEMS_EMPTY;
        if (isNeedInitBrokerNameValue) {
            brokerNameValue = VALUE_DEFAULT;
        }
    }
    StatisticType type = StatisticType.getEnumByMessage(comboDataType.getText());
    type = type == null ? StatisticType.DB : type;
    switch(type) {
        case DB:
            comboDbName.setItems(itemsDbName);
            comboDbName.setText(dbNameValue);
            isOkEnable[1] = (isInitial && !isNewHost) ? (isDbDataValid && isDbContained) : isDbDataValid;
            isOkEnable[2] = true;
            isOkEnable[3] = true;
            break;
        case DB_VOL:
            comboDbName.setItems(itemsDbName);
            comboDbName.setText(dbNameValue);
            isOkEnable[1] = isDbDataValid;
            if (isDbDataValid) {
                refreshDbVolData(dbNameValue, isInitial);
                isOkEnable[2] = !VALUE_DEFAULT.equals(dbVolNameValue);
            } else {
                itemsVolName = ITEMS_EMPTY;
                if (isNewHost || !isInitial || dbVolNameValue == null) {
                    dbVolNameValue = VALUE_DEFAULT;
                }
                isOkEnable[2] = false;
            }
            comboVolName.setItems(itemsVolName);
            comboVolName.setText(dbVolNameValue);
            isOkEnable[3] = true;
            break;
        case BROKER:
            comboBrokerName.setItems(itemsBrokerName);
            comboBrokerName.setText(brokerNameValue);
            isOkEnable[1] = true;
            isOkEnable[2] = true;
            isOkEnable[3] = isBrokerDataValid;
            break;
        case OS:
            isOkEnable[1] = true;
            isOkEnable[2] = true;
            isOkEnable[3] = true;
            break;
        default:
    }
}
Also used : GetDatabaseListTask(com.cubrid.cubridmanager.core.cubrid.database.task.GetDatabaseListTask) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) StatisticType(com.cubrid.cubridmanager.core.monstatistic.model.StatisticParamUtil.StatisticType) BrokerInfo(com.cubrid.cubridmanager.core.broker.model.BrokerInfo)

Example 7 with StatisticType

use of com.cubrid.cubridmanager.core.monstatistic.model.StatisticParamUtil.StatisticType in project cubrid-manager by CUBRID.

the class StatisticDataTest method testSingleHostChartItem.

public void testSingleHostChartItem() {
    StatisticData statisticData = new StatisticData();
    String data1 = "5523";
    String data2 = "3632";
    String data3 = "7639";
    statisticData.addData(data1);
    statisticData.addData(data2);
    statisticData.addData(data3);
    assertTrue(statisticData.getData().contains(Integer.parseInt(data1)));
    assertTrue(statisticData.getData().contains(Integer.parseInt(data2)));
    assertTrue(statisticData.getData().contains(Integer.parseInt(data3)));
    assertFalse(statisticData.getData().contains(data3));
    assertFalse(statisticData.getData().contains("2275"));
    String dbName = "demodb";
    statisticData.setDbName(dbName);
    assertEquals(statisticData.getDbName(), dbName);
    String dtype = TimeType.DAILY.getType();
    statisticData.setDtype(dtype);
    assertEquals(statisticData.getDtype(), dtype);
    String metric = MetricType.OS_CPU_IDLE.getMetric();
    statisticData.setMetric(metric);
    assertEquals(statisticData.getMetric(), metric);
    String ip = "127.0.0.1";
    int port = 8001;
    String user = "admin";
    String password = "123456";
    ServerInfo serverInfo = new ServerInfo();
    serverInfo.setHostAddress(ip);
    serverInfo.setHostMonPort(port);
    serverInfo.setUserName(user);
    serverInfo.setUserPassword(password);
    statisticData.setServerInfo(serverInfo);
    assertEquals(statisticData.getServerInfo(), serverInfo);
    assertEquals(statisticData.getTaskName(), "get_mon_statistic");
    StatisticType type = StatisticType.BROKER;
    statisticData.setType(type);
    assertEquals(statisticData.getType(), type);
    String volName = "demodb_lgat";
    statisticData.setVolName(volName);
    assertEquals(statisticData.getVolName(), volName);
    String bName = "query_editor";
    statisticData.setbName(bName);
    assertEquals(statisticData.getbName(), bName);
    assertNotNull(statisticData.getSimpleDescription(false));
    assertFalse(statisticData.getSimpleDescription(false).indexOf(bName) > -1);
    assertNotNull(statisticData.getDescription(false));
    assertTrue(statisticData.getDescription(false).indexOf(bName) > -1);
}
Also used : ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) StatisticType(com.cubrid.cubridmanager.core.monstatistic.model.StatisticParamUtil.StatisticType)

Example 8 with StatisticType

use of com.cubrid.cubridmanager.core.monstatistic.model.StatisticParamUtil.StatisticType in project cubrid-manager by CUBRID.

the class StatisticParamUtilTest method testStatisticParamUtil.

public void testStatisticParamUtil() {
    assertNotNull(StatisticParamUtil.getDateTypes());
    for (StatisticType type : StatisticType.values()) {
        assertNotNull(type.getMessage());
        assertNotNull(type.getMetricTypeSet());
        assertNotNull(StatisticParamUtil.getSendMsgItems(type));
        assertNotNull(StatisticParamUtil.getSupportedMetricTypes(type));
        switch(type) {
            case DB:
                assertEquals(StatisticType.getEnumByMessage(Messages.msgDataDb), type);
                break;
            case DB_VOL:
                assertEquals(StatisticType.getEnumByMessage(Messages.msgDataDbVol), type);
                break;
            case BROKER:
                assertEquals(StatisticType.getEnumByMessage(Messages.msgDataBroker), type);
                break;
            case OS:
                assertEquals(StatisticType.getEnumByMessage(Messages.msgDataOs), type);
                break;
            default:
        }
        for (MetricType metric : MetricType.values()) {
            switch(type) {
                case DB:
                    if (metric.getMetric().startsWith("db")) {
                        assertTrue(StatisticParamUtil.isSupportedMetric(type, metric.getMetric()));
                        assertTrue(StatisticParamUtil.isSupportedMetricType(type, metric));
                    } else {
                        assertFalse(StatisticParamUtil.isSupportedMetric(type, metric.getMetric()));
                        assertFalse(StatisticParamUtil.isSupportedMetricType(type, metric));
                    }
                    break;
                case DB_VOL:
                    if (metric.getMetric().startsWith("vol")) {
                        assertTrue(StatisticParamUtil.isSupportedMetric(type, metric.getMetric()));
                        assertTrue(StatisticParamUtil.isSupportedMetricType(type, metric));
                    } else {
                        assertFalse(StatisticParamUtil.isSupportedMetric(type, metric.getMetric()));
                        assertFalse(StatisticParamUtil.isSupportedMetricType(type, metric));
                    }
                    break;
                case BROKER:
                    if (metric.getMetric().startsWith("broker")) {
                        assertTrue(StatisticParamUtil.isSupportedMetric(type, metric.getMetric()));
                        assertTrue(StatisticParamUtil.isSupportedMetricType(type, metric));
                    } else {
                        assertFalse(StatisticParamUtil.isSupportedMetric(type, metric.getMetric()));
                        assertFalse(StatisticParamUtil.isSupportedMetricType(type, metric));
                    }
                    break;
                case OS:
                    if (metric.getMetric().startsWith("os")) {
                        assertTrue(StatisticParamUtil.isSupportedMetric(type, metric.getMetric()));
                        assertTrue(StatisticParamUtil.isSupportedMetricType(type, metric));
                    } else {
                        assertFalse(StatisticParamUtil.isSupportedMetric(type, metric.getMetric()));
                        assertFalse(StatisticParamUtil.isSupportedMetricType(type, metric));
                    }
                    break;
                default:
            }
        }
    }
    for (MetricType metric : MetricType.values()) {
        assertNotNull(metric.getMessage());
        assertNotNull(metric.getMetric());
        assertNotNull(metric.getChartName());
        assertEquals(MetricType.getEnumByMessage(metric.getMessage()), metric);
        assertEquals(MetricType.getEnumByMetric(metric.getMetric()), metric);
        Set<MetricType> metricSet = StatisticParamUtil.getCompatibleMetricsForDisplay(metric.getMetric());
        assertNotNull(metricSet);
        MetricType metric2 = metricSet.iterator().next();
        assertTrue(StatisticParamUtil.isCompatibleMetricForDisplay(metric.getMetric(), metric2.getMetric()));
        if (metric.getMetric().startsWith("db")) {
            assertEquals(StatisticParamUtil.getTypeByMetric(metric), StatisticType.DB);
            assertEquals(StatisticParamUtil.getTypeByMetric(metric.getMetric()), StatisticType.DB);
        } else if (metric.getMetric().startsWith("vol")) {
            assertEquals(StatisticParamUtil.getTypeByMetric(metric), StatisticType.DB_VOL);
            assertEquals(StatisticParamUtil.getTypeByMetric(metric.getMetric()), StatisticType.DB_VOL);
        } else if (metric.getMetric().startsWith("broker")) {
            assertEquals(StatisticParamUtil.getTypeByMetric(metric), StatisticType.BROKER);
            assertEquals(StatisticParamUtil.getTypeByMetric(metric.getMetric()), StatisticType.BROKER);
        } else {
            assertEquals(StatisticParamUtil.getTypeByMetric(metric), StatisticType.OS);
            assertEquals(StatisticParamUtil.getTypeByMetric(metric.getMetric()), StatisticType.OS);
        }
        if (metric.getMetric().indexOf("cpu") > -1 || metric.getMetric().indexOf("ratio") > -1) {
            assertTrue(StatisticParamUtil.isPercentageData(metric.getMetric()));
        } else {
            assertFalse(StatisticParamUtil.isPercentageData(metric.getMetric()));
        }
        if (metric.getMetric().indexOf("mem") > -1) {
            assertTrue(StatisticParamUtil.isMemoryData(metric.getMetric()));
        } else {
            assertFalse(StatisticParamUtil.isMemoryData(metric.getMetric()));
        }
        if (metric.getMetric().indexOf("freespace") > -1 || metric.getMetric().indexOf("disk") > -1) {
            assertTrue(StatisticParamUtil.isDiskData(metric.getMetric()));
        } else {
            assertFalse(StatisticParamUtil.isDiskData(metric.getMetric()));
        }
    }
    testTimeType();
    testDbMetricType();
    testOsMetricType();
}
Also used : StatisticType(com.cubrid.cubridmanager.core.monstatistic.model.StatisticParamUtil.StatisticType) DbMetricType(com.cubrid.cubridmanager.core.monstatistic.model.StatisticParamUtil.DbMetricType) MetricType(com.cubrid.cubridmanager.core.monstatistic.model.StatisticParamUtil.MetricType) OsMetricType(com.cubrid.cubridmanager.core.monstatistic.model.StatisticParamUtil.OsMetricType)

Example 9 with StatisticType

use of com.cubrid.cubridmanager.core.monstatistic.model.StatisticParamUtil.StatisticType in project cubrid-manager by CUBRID.

the class GetMonitorStatisticDataTaskTest method testExecute.

public void testExecute() {
    StatisticType type = StatisticType.OS;
    StatisticData statisticData = new StatisticData();
    GetMonitorStatisticDataTask<StatisticData> task = new GetMonitorStatisticDataTask<StatisticData>(serverInfo930, StatisticParamUtil.getSendMsgItems(type), statisticData);
    String metric = MetricType.OS_CPU_USER.getMetric();
    String dType = TimeType.WEEKLY.getType();
    task.setMetric(metric);
    task.setDateType(dType);
    statisticData.setMetric(metric);
    statisticData.setDtype(dType);
    task.execute();
    assertNull(task.getErrorMsg());
    statisticData = task.getResultModel();
    assertNotNull(statisticData);
    assertNotNull(statisticData.getData());
    assertTrue(statisticData.getData().size() > 0);
}
Also used : StatisticType(com.cubrid.cubridmanager.core.monstatistic.model.StatisticParamUtil.StatisticType) StatisticData(com.cubrid.cubridmanager.core.monstatistic.model.StatisticData)

Example 10 with StatisticType

use of com.cubrid.cubridmanager.core.monstatistic.model.StatisticParamUtil.StatisticType in project cubrid-manager by CUBRID.

the class MultiHostChartItemTest method testMultiHostChartItem.

public void testMultiHostChartItem() {
    String nodeId = "demo";
    MultiHostChartItem multiHostChartItem = new MultiHostChartItem(nodeId, StatisticType.DB);
    String dtype = TimeType.DAILY.getType();
    multiHostChartItem.setDType(dtype);
    assertEquals(multiHostChartItem.getDType(), dtype);
    List<StatisticChartHost> hostlist = new ArrayList<StatisticChartHost>();
    StatisticChartHost host = new StatisticChartHost("localhost");
    host.setMetric(MetricType.BROKER_ERR_Q.getMetric());
    hostlist.add(host);
    multiHostChartItem.setHostList(hostlist);
    StatisticChartHost host2 = new StatisticChartHost("localhost2");
    host2.setMetric(MetricType.BROKER_JQ.getMetric());
    multiHostChartItem.addStatisticChartHost(host2);
    assertNotNull(multiHostChartItem.getHostList());
    assertTrue(multiHostChartItem.getHostList().contains(host));
    assertTrue(multiHostChartItem.getHostList().contains(host2));
    assertTrue(multiHostChartItem.isMultiHost());
    assertNotNull(multiHostChartItem.getName());
    List<StatisticChartHost> hostlist2 = new ArrayList<StatisticChartHost>();
    multiHostChartItem.setHostList(hostlist2);
    assertEquals(multiHostChartItem.getName(), "");
    assertEquals(multiHostChartItem.getNodeId(), nodeId);
    multiHostChartItem.setSeries(5);
    assertEquals(multiHostChartItem.getSeries(), 5);
    StatisticType type = StatisticType.BROKER;
    multiHostChartItem.setType(type);
    assertEquals(multiHostChartItem.getType(), type);
}
Also used : StatisticType(com.cubrid.cubridmanager.core.monstatistic.model.StatisticParamUtil.StatisticType) ArrayList(java.util.ArrayList)

Aggregations

StatisticType (com.cubrid.cubridmanager.core.monstatistic.model.StatisticParamUtil.StatisticType)11 SingleHostChartItem (com.cubrid.cubridmanager.core.monstatistic.model.SingleHostChartItem)3 ArrayList (java.util.ArrayList)3 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)2 StatisticChartHost (com.cubrid.cubridmanager.core.monstatistic.model.StatisticChartHost)2 MetricType (com.cubrid.cubridmanager.core.monstatistic.model.StatisticParamUtil.MetricType)2 Button (org.eclipse.swt.widgets.Button)2 Control (org.eclipse.swt.widgets.Control)2 Group (org.eclipse.swt.widgets.Group)2 MonitorStatistic (com.cubrid.common.ui.spi.model.MonitorStatistic)1 BrokerInfo (com.cubrid.cubridmanager.core.broker.model.BrokerInfo)1 IXMLMemento (com.cubrid.cubridmanager.core.common.xml.IXMLMemento)1 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)1 GetDatabaseListTask (com.cubrid.cubridmanager.core.cubrid.database.task.GetDatabaseListTask)1 MultiHostChartItem (com.cubrid.cubridmanager.core.monstatistic.model.MultiHostChartItem)1 StatisticData (com.cubrid.cubridmanager.core.monstatistic.model.StatisticData)1 DbMetricType (com.cubrid.cubridmanager.core.monstatistic.model.StatisticParamUtil.DbMetricType)1 OsMetricType (com.cubrid.cubridmanager.core.monstatistic.model.StatisticParamUtil.OsMetricType)1 TimeType (com.cubrid.cubridmanager.core.monstatistic.model.StatisticParamUtil.TimeType)1 GridData (org.eclipse.swt.layout.GridData)1