use of com.cubrid.cubridmanager.core.monstatistic.model.SingleHostChartItem in project cubrid-manager by CUBRID.
the class EditSingleHostStatisticItemDialog method okPressed.
/**
* When press "ok" button, call it.
*/
public void okPressed() {
StatisticType type = StatisticType.getEnumByMessage(comboDataType.getText());
String timeType = getTimeType();
int series = 0;
if (!isNew) {
series = statisticChartItem.getSeries();
}
statisticChartItem = new SingleHostChartItem(editor.getNodeId(), type);
statisticChartItem.setDType(timeType);
switch(type) {
case DB:
((SingleHostChartItem) statisticChartItem).setDbName(comboDbName.getText());
break;
case DB_VOL:
((SingleHostChartItem) statisticChartItem).setDbName(comboDbName.getText());
((SingleHostChartItem) statisticChartItem).setVolName(comboVolName.getText());
break;
case BROKER:
((SingleHostChartItem) statisticChartItem).setBrokerName(comboBrokerName.getText());
break;
case OS:
break;
default:
}
for (Group grp : grpMetricList) {
if (grp.getChildren() == null) {
continue;
}
for (Control control : grp.getChildren()) {
if (control instanceof Button) {
if (((Button) control).getSelection()) {
((SingleHostChartItem) statisticChartItem).addMetric(MetricType.getEnumByMessage(((Button) control).getText()).getMetric());
}
}
}
}
if (!isNew) {
statisticChartItem.setSeries(series);
}
super.okPressed();
}
use of com.cubrid.cubridmanager.core.monstatistic.model.SingleHostChartItem in project cubrid-manager by CUBRID.
the class EditSingleHostStatisticItemDialog 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);
parentComp.setLayout(new GridLayout(1, false));
GridData gdParent = new GridData(SWT.FILL);
gdParent.widthHint = DIALOG_AREA_WIDTH;
gdParent.heightHint = LINE_HEIGHT * 11;
parentComp.setLayoutData(gdParent);
//init data
StatisticType statisticType = StatisticType.DB;
if (!isNew && statisticChartItem != null) {
statisticType = statisticChartItem.getType();
oldDataType = statisticType;
dataTypeValue = statisticType.getMessage();
TimeType timeType = TimeType.getEnumByType(statisticChartItem.getDType());
timeValue = timeType == null ? TimeType.DAILY.getMessage() : timeType.getMessage();
switch(statisticType) {
case DB:
dbNameValue = ((SingleHostChartItem) statisticChartItem).getDbName();
break;
case DB_VOL:
dbNameValue = ((SingleHostChartItem) statisticChartItem).getDbName();
dbVolNameValue = ((SingleHostChartItem) statisticChartItem).getVolName();
break;
case BROKER:
brokerNameValue = ((SingleHostChartItem) statisticChartItem).getBrokerName();
break;
case OS:
break;
default:
}
}
compDataType = new Composite(parentComp, SWT.RESIZE);
GridLayout layoutCompDataType = new GridLayout(4, false);
compDataType.setLayout(layoutCompDataType);
final Label lblDataType = new Label(compDataType, SWT.NONE);
GridData gdlblDataType = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
gdlblDataType.widthHint = 120;
lblDataType.setText(Messages.lblDataType);
comboDataType = new Combo(compDataType, SWT.NONE | SWT.READ_ONLY);
GridData gdComboDataType = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
gdComboDataType.widthHint = 180;
comboDataType.setLayoutData(gdComboDataType);
comboDataType.setItems(itemsDataType);
comboDataType.setText(dataTypeValue);
comboDataType.addSelectionListener(new ComboDataTypeSelectionAdapter());
final Label lblTimeType = new Label(compDataType, SWT.NONE);
GridData gdlblTimeType = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
gdlblTimeType.widthHint = 120;
lblTimeType.setText(Messages.lblTimeType);
comboTimeType = new Combo(compDataType, SWT.NONE | SWT.READ_ONLY);
GridData gdComboTimeType = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
gdComboTimeType.widthHint = 180;
comboTimeType.setLayoutData(gdComboTimeType);
comboTimeType.setItems(itemsTimeType);
comboTimeType.setText(timeValue);
compMetrics = new Composite(parentComp, SWT.RESIZE);
refreshChangeableItems(statisticType);
if (!isNew && statisticChartItem != null) {
List<String> metricList = ((SingleHostChartItem) statisticChartItem).getMetricList();
for (Group grp : grpMetricList) {
if (grp.getChildren() == null) {
continue;
}
boolean isFindInGroup = false;
for (Control control : grp.getChildren()) {
if (control instanceof Button) {
Button btn = ((Button) control);
btn.setEnabled(false);
String msg = btn.getText();
MetricType metricType = MetricType.getEnumByMessage(msg);
for (String metric : metricList) {
if (metric.equals(metricType.getMetric())) {
btn.setSelection(true);
isFindInGroup = true;
break;
}
}
}
}
if (isFindInGroup) {
for (Control control : grp.getChildren()) {
if (control instanceof Button) {
((Button) control).setEnabled(true);
}
}
}
}
}
//add btn
final Composite btnComp = new Composite(parentComp, SWT.NONE);
btnComp.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
{
GridLayout layout = new GridLayout();
layout.marginRight = 5;
layout.numColumns = 1;
layout.marginWidth = 0;
btnComp.setLayout(layout);
}
btnClearAll = new Button(btnComp, SWT.NONE);
btnClearAll.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
btnClearAll.setText(Messages.btnCleanSelected);
btnClearAll.addSelectionListener(new ButtonCleanAllSelectionAdapter());
return parentComp;
}
use of com.cubrid.cubridmanager.core.monstatistic.model.SingleHostChartItem 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.SingleHostChartItem 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.SingleHostChartItem 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