Search in sources :

Example 1 with GetMonitorStatisticDataTask

use of com.cubrid.cubridmanager.core.monstatistic.task.GetMonitorStatisticDataTask in project cubrid-manager by CUBRID.

the class LoadMonitorStatisticDataProgress method run.

/* (non-Javadoc)
	 * @see org.eclipse.jface.operation.IRunnableWithProgress#run(org.eclipse.core.runtime.IProgressMonitor)
	 */
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
    if (statisticItemList == null) {
        success = false;
        return;
    }
    if (isMultiHost) {
        for (StatisticChartItem chartItem : statisticItemList) {
            if (!(chartItem instanceof MultiHostChartItem)) {
                statisticDataMap.put(chartItem, EMPTY_STATISTIC_DATA_LIST);
                continue;
            }
            MultiHostChartItem item = (MultiHostChartItem) chartItem;
            if (item.getHostList() == null || item.getHostList().size() == 0) {
                statisticDataMap.put(chartItem, EMPTY_STATISTIC_DATA_LIST);
                continue;
            }
            List<StatisticData> dataList = new ArrayList<StatisticData>();
            for (StatisticChartHost host : item.getHostList()) {
                //build ServerInfo
                ServerInfo serverInfo = buildServerInfo(host);
                StatisticData statisticData = new StatisticData();
                statisticData.setServerInfo(serverInfo);
                GetMonitorStatisticDataTask<StatisticData> getStatisticDatatask = new GetMonitorStatisticDataTask<StatisticData>(serverInfo, StatisticParamUtil.getSendMsgItems(item.getType()), statisticData);
                getStatisticDatatask.setMetric(host.getMetric());
                getStatisticDatatask.setDateType(item.getDType());
                /*[TOOLS-3742] Initial StatisticData for GetMonitorStatisticDataTask failure*/
                statisticData.setMetric(host.getMetric());
                statisticData.setDtype(item.getDType());
                switch(item.getType()) {
                    case DB:
                        getStatisticDatatask.setDbName(host.getDbName());
                        statisticData.setDbName(host.getDbName());
                        break;
                    case DB_VOL:
                        getStatisticDatatask.setDbName(host.getDbName());
                        getStatisticDatatask.setVolName(host.getVolName());
                        statisticData.setDbName(host.getDbName());
                        statisticData.setVolName(host.getVolName());
                        break;
                    case BROKER:
                        getStatisticDatatask.setBrokerName(host.getBrokerName());
                        statisticData.setbName(host.getBrokerName());
                        break;
                    case OS:
                        break;
                    default:
                        break;
                }
                if (!serverInfo.isConnected()) {
                    disconnectedServerSet.add(serverInfo);
                    MonitoringTask monitoringTask = serverInfo.getMonitoringTask();
                    serverInfo = monitoringTask.connectServer(Version.releaseVersion, 1000);
                }
                if (serverInfo.isConnected()) {
                    addServer(serverInfo);
                    getStatisticDatatask.execute();
                    if (getStatisticDatatask.isSuccess()) {
                        statisticData = getStatisticDatatask.getResultModel();
                        dataList.add(statisticData);
                    } else {
                        dataList.add(statisticData);
                    }
                } else {
                    removeServer(serverInfo);
                    dataList.add(statisticData);
                }
            }
            statisticDataMap.put(chartItem, dataList);
        }
        tearDownDisconnectedServer();
    } else {
        //for single host
        for (StatisticChartItem chartItem : statisticItemList) {
            if (!(chartItem instanceof SingleHostChartItem)) {
                statisticDataMap.put(chartItem, EMPTY_STATISTIC_DATA_LIST);
                continue;
            }
            SingleHostChartItem item = (SingleHostChartItem) chartItem;
            if (item.getMetricList() == null || item.getMetricList().size() == 0) {
                statisticDataMap.put(chartItem, EMPTY_STATISTIC_DATA_LIST);
                continue;
            }
            List<StatisticData> dataList = new ArrayList<StatisticData>();
            for (int i = 0; i < item.getMetricList().size(); i++) {
                String metric = item.getMetricList().get(i);
                StatisticData statisticData = new StatisticData();
                statisticData.setServerInfo(serverInfo);
                GetMonitorStatisticDataTask<StatisticData> task = new GetMonitorStatisticDataTask<StatisticData>(serverInfo, StatisticParamUtil.getSendMsgItems(item.getType()), statisticData);
                task.setMetric(metric);
                task.setDateType(item.getDType());
                statisticData.setMetric(metric);
                statisticData.setDtype(item.getDType());
                switch(item.getType()) {
                    case DB:
                        task.setDbName(item.getDbName());
                        statisticData.setDbName(item.getDbName());
                        break;
                    case DB_VOL:
                        task.setDbName(item.getDbName());
                        task.setVolName(item.getVolName());
                        statisticData.setDbName(item.getDbName());
                        statisticData.setVolName(item.getVolName());
                        break;
                    case BROKER:
                        task.setBrokerName(item.getBrokerName());
                        statisticData.setbName(item.getBrokerName());
                        break;
                    case OS:
                        break;
                    default:
                        break;
                }
                task.execute();
                if (task.isSuccess()) {
                    statisticData = task.getResultModel();
                    dataList.add(statisticData);
                } else if (task.getErrorMsg() != null && (task.getErrorMsg().indexOf("invalid token") != -1 || !serverInfo.isConnected())) {
                    /*[TOOLS-3742] when invalid token or connect server failure, give out error message*/
                    errorMsg = task.getErrorMsg();
                    //build StatisticData with no data
                    for (; i < item.getMetricList().size(); i++) {
                        String metric2 = item.getMetricList().get(i);
                        StatisticData data = (StatisticData) statisticData.clone();
                        data.setMetric(metric2);
                        dataList.add(data);
                    }
                    break;
                }
            }
            statisticDataMap.put(chartItem, dataList);
        }
    }
    success = true;
}
Also used : SingleHostChartItem(com.cubrid.cubridmanager.core.monstatistic.model.SingleHostChartItem) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) ArrayList(java.util.ArrayList) StatisticChartItem(com.cubrid.cubridmanager.core.monstatistic.model.StatisticChartItem) StatisticData(com.cubrid.cubridmanager.core.monstatistic.model.StatisticData) MultiHostChartItem(com.cubrid.cubridmanager.core.monstatistic.model.MultiHostChartItem) GetMonitorStatisticDataTask(com.cubrid.cubridmanager.core.monstatistic.task.GetMonitorStatisticDataTask) MonitoringTask(com.cubrid.cubridmanager.core.common.task.MonitoringTask) StatisticChartHost(com.cubrid.cubridmanager.core.monstatistic.model.StatisticChartHost)

Aggregations

ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)1 MonitoringTask (com.cubrid.cubridmanager.core.common.task.MonitoringTask)1 MultiHostChartItem (com.cubrid.cubridmanager.core.monstatistic.model.MultiHostChartItem)1 SingleHostChartItem (com.cubrid.cubridmanager.core.monstatistic.model.SingleHostChartItem)1 StatisticChartHost (com.cubrid.cubridmanager.core.monstatistic.model.StatisticChartHost)1 StatisticChartItem (com.cubrid.cubridmanager.core.monstatistic.model.StatisticChartItem)1 StatisticData (com.cubrid.cubridmanager.core.monstatistic.model.StatisticData)1 GetMonitorStatisticDataTask (com.cubrid.cubridmanager.core.monstatistic.task.GetMonitorStatisticDataTask)1 ArrayList (java.util.ArrayList)1