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;
}
Aggregations