use of com.cubrid.cubridmanager.core.monstatistic.model.MultiHostChartItem in project cubrid-manager by CUBRID.
the class EditMultiHostStatisticItemDialog method okPressed.
public void okPressed() {
int series = 0;
if (!isNew) {
series = statisticChartItem.getSeries();
}
statisticChartItem = new MultiHostChartItem(editor.getNodeId(), type, timeType.getType());
Iterator<StatisticChartHost> it = hostList.iterator();
while (it.hasNext()) {
((MultiHostChartItem) statisticChartItem).addStatisticChartHost(it.next());
}
if (!isNew) {
statisticChartItem.setSeries(series);
}
LoadMonitorStatisticDataProgress.tearDownDisconnectedServer();
super.okPressed();
}
use of com.cubrid.cubridmanager.core.monstatistic.model.MultiHostChartItem in project cubrid-manager by CUBRID.
the class EditMultiHostStatisticItemDialog method createDialogArea.
/**
* Creates and returns the contents of the upper part of this dialog (above
* the button bar).
*
* @param parent The parent composite to contain the dialog area
* @return the dialog area control
*/
protected Control createDialogArea(Composite parent) {
final Composite parentComp = (Composite) super.createDialogArea(parent);
final int DEFAULT_WIDTH = 80;
Composite compHost = new Composite(parentComp, SWT.RESIZE);
compHost.setLayout(new FillLayout());
compHost.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
hostTableViewer = new TableViewer(compHost, SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER);
hostTableViewer.getTable().setHeaderVisible(true);
hostTableViewer.getTable().setLinesVisible(true);
hostTableViewer.addDoubleClickListener(new IDoubleClickListener() {
public void doubleClick(DoubleClickEvent event) {
TableItem[] tableItems = hostTableViewer.getTable().getSelection();
StatisticChartHost hostItem = (StatisticChartHost) tableItems[0].getData();
openAddStatisticHostDialog(hostItem, hostList.size() == 1, false);
}
});
//Host Name
final TableViewerColumn nameColumn = new TableViewerColumn(hostTableViewer, SWT.LEFT);
nameColumn.getColumn().setWidth(DEFAULT_WIDTH);
nameColumn.getColumn().setText(Messages.lblHostName);
//IP
final TableViewerColumn ipColumn = new TableViewerColumn(hostTableViewer, SWT.LEFT);
ipColumn.getColumn().setWidth(DEFAULT_WIDTH);
ipColumn.getColumn().setText(Messages.lblIp);
//Port
final TableViewerColumn portColumn = new TableViewerColumn(hostTableViewer, SWT.LEFT);
portColumn.getColumn().setWidth(50);
portColumn.getColumn().setText(Messages.lblPort);
//Data Type
final TableViewerColumn dataTypeColumn = new TableViewerColumn(hostTableViewer, SWT.LEFT);
dataTypeColumn.getColumn().setWidth(DEFAULT_WIDTH);
dataTypeColumn.getColumn().setText(Messages.lblDataType);
//Time Type
final TableViewerColumn timeTypeColumn = new TableViewerColumn(hostTableViewer, SWT.LEFT);
timeTypeColumn.getColumn().setWidth(DEFAULT_WIDTH);
timeTypeColumn.getColumn().setText(Messages.lblTimeType);
//Database Name
final TableViewerColumn dbNameColumn = new TableViewerColumn(hostTableViewer, SWT.LEFT);
dbNameColumn.getColumn().setWidth(DEFAULT_WIDTH);
dbNameColumn.getColumn().setText(Messages.lblDbName);
//Database Volume Name
final TableViewerColumn volNameColumn = new TableViewerColumn(hostTableViewer, SWT.LEFT);
volNameColumn.getColumn().setWidth(DEFAULT_WIDTH);
volNameColumn.getColumn().setText(Messages.lblVolName);
//Broker Name
final TableViewerColumn brokerColumn = new TableViewerColumn(hostTableViewer, SWT.LEFT);
brokerColumn.getColumn().setWidth(DEFAULT_WIDTH);
brokerColumn.getColumn().setText(Messages.lblBrokerName);
//Metric
final TableViewerColumn metricColumn = new TableViewerColumn(hostTableViewer, SWT.LEFT);
metricColumn.getColumn().setWidth(DEFAULT_WIDTH);
metricColumn.getColumn().setText(Messages.lblMetric);
hostTableViewer.setContentProvider(new HostTableViewerContentProvider());
hostTableViewer.setLabelProvider(new HostTableViewerLabelProvider());
hostTableViewer.getTable().addFocusListener(new FocusAdapter() {
@Override
public void focusGained(FocusEvent event) {
ActionManager.getInstance().changeFocusProvider(hostTableViewer.getTable());
}
});
hostTableViewer.getTable().addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
TableItem[] items = hostTableViewer.getTable().getSelection();
btnEditHost.setEnabled(items.length > 0);
btnDeleteHost.setEnabled(items.length > 0);
}
});
Composite compBtn = new Composite(parentComp, SWT.RESIZE);
GridLayout layoutCompBtn = new GridLayout(6, false);
layoutCompBtn.marginRight = 0;
// layoutCompBtn.numColumns = 6;
layoutCompBtn.marginWidth = 0;
compBtn.setLayout(layoutCompBtn);
compBtn.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
btnAddHost = new Button(compBtn, SWT.NONE);
btnAddHost.setText(Messages.btnAddHost);
btnAddHost.addSelectionListener(new ButtonAddHostAdapter());
btnEditHost = new Button(compBtn, SWT.NONE);
btnEditHost.setText(Messages.btnEditHost);
btnEditHost.addSelectionListener(new ButtonEditHostAdapter());
btnEditHost.setEnabled(false);
btnDeleteHost = new Button(compBtn, SWT.NONE);
btnDeleteHost.setText(Messages.btnDelHost);
btnDeleteHost.addSelectionListener(new ButtonDeleteHostAdapter());
btnDeleteHost.setEnabled(false);
if (!isNew && statisticChartItem != null) {
MultiHostChartItem multiHostChartItem = (MultiHostChartItem) statisticChartItem;
type = multiHostChartItem.getType();
timeType = TimeType.getEnumByType(multiHostChartItem.getDType());
hostList = multiHostChartItem.getHostList();
hostTableViewer.setInput(hostList);
} else {
hostList = new ArrayList<StatisticChartHost>();
}
return parentComp;
}
use of com.cubrid.cubridmanager.core.monstatistic.model.MultiHostChartItem 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;
}
use of com.cubrid.cubridmanager.core.monstatistic.model.MultiHostChartItem in project cubrid-manager by CUBRID.
the class MonitorStatisticPersistManager method loadMonitorStatistic.
/**
*
* Load MonitorStatistic nodes
*
*/
protected void loadMonitorStatistic() {
synchronized (this) {
IXMLMemento memento = PersistUtils.getXMLMemento(CubridManagerUIPlugin.PLUGIN_ID, MONITOR_STATISTIC_XML_CONTENT);
if (memento != null) {
IXMLMemento[] monitorsPerHost = memento.getChildren("monitorsPerHost");
for (int i = 0; i < monitorsPerHost.length; i++) {
boolean isMultiHost = monitorsPerHost[i].getBoolean("isMultihost");
String hostId = HOST_ID_FOR_MULTI_HOST;
if (!isMultiHost) {
hostId = monitorsPerHost[i].getString("hostId");
}
IXMLMemento[] children = monitorsPerHost[i].getChildren("monitor");
List<MonitorStatistic> monitorStatisticList = new ArrayList<MonitorStatistic>();
for (int j = 0; j < children.length; j++) {
String id = children[j].getString("name");
String label = id;
if (!isMultiHost && id.indexOf("@") != -1) {
label = id.substring(0, id.indexOf("@"));
}
MonitorStatistic node = new MonitorStatistic(id, label, iconPath);
node.setType(CubridNodeType.MONITOR_STATISTIC_PAGE);
node.setMultiHost(isMultiHost);
IXMLMemento[] chartChildren = children[j].getChildren("chart");
for (int k = 0; chartChildren != null && k < chartChildren.length; k++) {
String typeStr = chartChildren[k].getString("type");
StatisticType type = StatisticType.valueOf(typeStr);
int series = chartChildren[k].getInteger("series");
String dType = chartChildren[k].getString("dtype");
if (!isMultiHost) {
SingleHostChartItem item = new SingleHostChartItem(id, type);
item.setSeries(series);
item.setDType(dType);
String metrics = chartChildren[k].getString("metrics");
String[] metricAr = metrics.split(",");
for (String metric : metricAr) {
item.addMetric(metric);
}
String dbName = null;
switch(type) {
case DB:
dbName = chartChildren[k].getString("dbname");
item.setDbName(dbName);
break;
case DB_VOL:
dbName = chartChildren[k].getString("dbname");
String volName = chartChildren[k].getString("volname");
item.setDbName(dbName);
item.setVolName(volName);
break;
case BROKER:
String brokerName = chartChildren[k].getString("bname");
item.setBrokerName(brokerName);
break;
case OS:
break;
default:
break;
}
node.addStatisticItem(item);
} else {
IXMLMemento[] hostChildren = chartChildren[k].getChildren("host");
MultiHostChartItem item = new MultiHostChartItem(id, type);
item.setSeries(series);
item.setDType(dType);
for (int m = 0; hostChildren != null && m < hostChildren.length; m++) {
String cubridServerId = hostChildren[m].getString("cubridServerId");
String ip = hostChildren[m].getString("ip");
int port = hostChildren[m].getInteger("port");
String user = hostChildren[m].getString("user");
String pass = hostChildren[m].getString("password");
StatisticChartHost host;
if (cubridServerId != null) {
host = new StatisticChartHost(cubridServerId);
} else {
host = new StatisticChartHost(ip, port, user, CipherUtils.decrypt(pass));
}
String metric = hostChildren[m].getString("metric");
host.setMetric(metric);
String dbName = null;
switch(type) {
case DB:
dbName = hostChildren[m].getString("dbname");
host.setDbName(dbName);
break;
case DB_VOL:
dbName = hostChildren[m].getString("dbname");
String volName = hostChildren[m].getString("volname");
host.setDbName(dbName);
host.setVolName(volName);
break;
case BROKER:
String brokerName = hostChildren[m].getString("bname");
host.setBrokerName(brokerName);
break;
case OS:
break;
default:
break;
}
item.addStatisticChartHost(host);
}
node.addStatisticItem(item);
}
}
monitorStatisticList.add(node);
}
monitorStatisticMap.put(hostId, monitorStatisticList);
}
}
}
}
use of com.cubrid.cubridmanager.core.monstatistic.model.MultiHostChartItem in project cubrid-manager by CUBRID.
the class MonitorStatisticPersistManager method saveStatistic.
/**
*
* Save MonitorStatistic nodes
*
*/
public void saveStatistic() {
synchronized (this) {
XMLMemento memento = XMLMemento.createWriteRoot("monitors");
Iterator<String> keySetIterator = monitorStatisticMap.keySet().iterator();
while (keySetIterator.hasNext()) {
String hostId = keySetIterator.next();
boolean isMultiHost = HOST_ID_FOR_MULTI_HOST.equals(hostId);
IXMLMemento monsPerHostMemento = memento.createChild("monitorsPerHost");
monsPerHostMemento.putBoolean("isMultihost", isMultiHost);
if (!isMultiHost) {
monsPerHostMemento.putString("hostId", hostId);
}
List<MonitorStatistic> monitorStatisticList = monitorStatisticMap.get(hostId);
if (monitorStatisticList == null) {
continue;
}
Iterator<MonitorStatistic> nodeIterator = monitorStatisticList.iterator();
while (nodeIterator.hasNext()) {
MonitorStatistic node = nodeIterator.next();
IXMLMemento monMemento = monsPerHostMemento.createChild("monitor");
monMemento.putString("name", node.getId());
//save StatisticItem list
List<StatisticChartItem> statisticItemList = node.getStatisticItemList();
Iterator<StatisticChartItem> itemIterator = statisticItemList.iterator();
while (itemIterator.hasNext()) {
if (!node.isMultiHost()) {
SingleHostChartItem item = (SingleHostChartItem) itemIterator.next();
IXMLMemento chartMemento = monMemento.createChild("chart");
chartMemento.putInteger("series", item.getSeries());
chartMemento.putString("name", item.getName());
chartMemento.putString("type", item.getType().toString());
chartMemento.putString("dtype", item.getDType());
chartMemento.putString("metrics", ArrayUtil.collectionToCSString(item.getMetricList()));
switch(item.getType()) {
case DB:
chartMemento.putString("dbname", item.getDbName());
break;
case DB_VOL:
chartMemento.putString("dbname", item.getDbName());
chartMemento.putString("volname", item.getVolName());
break;
case BROKER:
chartMemento.putString("bname", item.getBrokerName());
break;
case OS:
break;
default:
break;
}
} else {
MultiHostChartItem item = (MultiHostChartItem) itemIterator.next();
IXMLMemento chartMemento = monMemento.createChild("chart");
chartMemento.putInteger("series", item.getSeries());
chartMemento.putString("name", item.getName());
chartMemento.putString("type", item.getType().toString());
chartMemento.putString("dtype", item.getDType());
//save HostInfo list
List<StatisticChartHost> hostList = item.getHostList();
Iterator<StatisticChartHost> hostIterator = hostList.iterator();
while (hostIterator.hasNext()) {
StatisticChartHost host = (StatisticChartHost) hostIterator.next();
IXMLMemento hostMemento = chartMemento.createChild("host");
hostMemento.putString("cubridServerId", host.getCubridServerId());
hostMemento.putString("ip", host.getIp());
hostMemento.putInteger("port", host.getPort());
hostMemento.putString("user", host.getUser());
hostMemento.putString("password", CipherUtils.encrypt(host.getPassword()));
hostMemento.putString("metric", host.getMetric());
switch(item.getType()) {
case DB:
hostMemento.putString("dbname", host.getDbName());
break;
case DB_VOL:
hostMemento.putString("dbname", host.getDbName());
hostMemento.putString("volname", host.getVolName());
break;
case BROKER:
hostMemento.putString("bname", host.getBrokerName());
break;
case OS:
break;
default:
break;
}
}
}
}
}
}
PersistUtils.saveXMLMemento(CubridManagerUIPlugin.PLUGIN_ID, MONITOR_STATISTIC_XML_CONTENT, memento);
}
}
Aggregations