Search in sources :

Example 6 with StatisticChartItem

use of com.cubrid.cubridmanager.core.monstatistic.model.StatisticChartItem 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)

Example 7 with StatisticChartItem

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

the class MonitorStatisticEditor method updateStatisticItem.

public void updateStatisticItem(StatisticChartItem item) {
    if (item == null || item.getSeries() == -1) {
        return;
    }
    StatisticChartItem oldItem = statisticItemList.get(item.getSeries());
    MonitorStatisticChart chart = chartList.get(oldItem.getSeries());
    statisticDataMap.remove(oldItem);
    chartList.remove(oldItem);
    statisticItemList.set(item.getSeries(), item);
    chartList.set(oldItem.getSeries(), chart);
    Map<StatisticChartItem, List<StatisticData>> dataMap = refreshData(item);
    chart.refreshChart(dataMap.get(item));
    chart.updateGroupName(item.getName());
    statisticDataMap.put(item, dataMap.get(item));
    monitorStatisticPersistManager.saveStatistic();
}
Also used : List(java.util.List) ArrayList(java.util.ArrayList) StatisticChartItem(com.cubrid.cubridmanager.core.monstatistic.model.StatisticChartItem) MonitorStatisticChart(com.cubrid.cubridmanager.ui.monstatistic.editor.internal.MonitorStatisticChart)

Example 8 with StatisticChartItem

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

the class MonitorStatisticEditor method refreshToolbar.

private void refreshToolbar(boolean isEditMode) {
    if (isEditMode) {
        changeModeItem.setText(MESSAGE_EDIT_MODE);
        changeModeItem.setImage(CubridManagerUIPlugin.getImage("icons/navigator/status_item.png"));
    } else {
        changeModeItem.setText(MESSAGE_View_MODE);
        changeModeItem.setImage(CubridManagerUIPlugin.getImage("icons/action/auto_backup_edit.png"));
    }
    ToolItem[] items = toolbar.getItems();
    for (int i = 1; i < items.length; i++) {
        items[i].dispose();
    }
    if (isEditMode) {
        ToolItem addItem = new ToolItem(toolbar, SWT.PUSH);
        addItem.setText(Messages.btnAdd);
        addItem.setImage(CubridManagerUIPlugin.getImage("icons/action/auto_backup_add.png"));
        addItem.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(final SelectionEvent event) {
                openEditStatisticItemDialog();
            }
        });
        ToolItem deleteItem = new ToolItem(toolbar, SWT.PUSH);
        deleteItem.setText(Messages.btnDelete);
        deleteItem.setImage(CubridManagerUIPlugin.getImage("icons/action/auto_backup_delete.png"));
        deleteItem.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(final SelectionEvent event) {
                if (!CommonUITool.openConfirmBox(Messages.confirmMultiStatisticChartRemoveWarn)) {
                    return;
                }
                List<StatisticChartItem> chartItemList = new ArrayList<StatisticChartItem>();
                for (MonitorStatisticChart chart : chartList) {
                    if (chart.getSelection()) {
                        chartItemList.add(chart.getStatisticChartItem());
                    }
                }
                removeStatisticItem(chartItemList);
            }
        });
        ToolItem refreshItem = new ToolItem(toolbar, SWT.PUSH);
        refreshItem.setText(Messages.btnRefresh);
        refreshItem.setToolTipText(Messages.RefreshTooltip);
        refreshItem.setImage(CommonUIPlugin.getImage("icons/action/refresh.png"));
        refreshItem.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(final SelectionEvent event) {
                statisticDataMap = refreshData(statisticItemList);
                for (MonitorStatisticChart chart : chartList) {
                    chart.refreshChart(statisticDataMap.get(chart.getStatisticChartItem()));
                }
            }
        });
        selectBtn = new Button(toolbarComp, SWT.CHECK);
        final GridData gdSelectBtn = new GridData(SWT.LEFT, SWT.CENTER, false, false);
        selectBtn.setLayoutData(gdSelectBtn);
        selectBtn.setText(MESSAGE_SELECT_ALL);
        selectBtn.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(final SelectionEvent event) {
                Button btn = (Button) event.widget;
                for (MonitorStatisticChart item : chartList) {
                    item.setSelection(btn.getSelection());
                }
                if (btn.getSelection()) {
                    btn.setText(MESSAGE_DESELECT_ALL);
                } else {
                    btn.setText(MESSAGE_SELECT_ALL);
                }
                btn.getParent().layout();
            }
        });
    } else {
        ToolItem refreshItem = new ToolItem(toolbar, SWT.PUSH);
        refreshItem.setText(Messages.btnRefresh);
        refreshItem.setToolTipText(Messages.RefreshTooltip);
        refreshItem.setImage(CommonUIPlugin.getImage("icons/action/refresh.png"));
        refreshItem.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(final SelectionEvent event) {
                statisticDataMap = refreshData(statisticItemList);
                for (MonitorStatisticChart chart : chartList) {
                    chart.refreshChart(statisticDataMap.get(chart.getStatisticChartItem()));
                }
            }
        });
        if (selectBtn != null) {
            selectBtn.dispose();
        }
    }
    toolbarComp.layout();
}
Also used : Button(org.eclipse.swt.widgets.Button) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) GridData(org.eclipse.swt.layout.GridData) List(java.util.List) ArrayList(java.util.ArrayList) StatisticChartItem(com.cubrid.cubridmanager.core.monstatistic.model.StatisticChartItem) MonitorStatisticChart(com.cubrid.cubridmanager.ui.monstatistic.editor.internal.MonitorStatisticChart) ToolItem(org.eclipse.swt.widgets.ToolItem)

Example 9 with StatisticChartItem

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

the class MonitorStatisticEditor method removeStatisticItem.

public void removeStatisticItem(StatisticChartItem item) {
    if (item == null) {
        return;
    }
    statisticItemList.remove(item);
    statisticDataMap.remove(item);
    chartList.remove(item.getSeries());
    Composite comp = compList.get(item.getSeries());
    compList.remove(item.getSeries());
    comp.dispose();
    for (int i = 0; i < statisticItemList.size(); i++) {
        StatisticChartItem chartItem = statisticItemList.get(i);
        chartItem.setSeries(i);
    }
    createHiddenItems();
    addItemCompIndex--;
    chartAreaRootComp.layout();
    monitorStatisticPersistManager.saveStatistic();
    updateScrolledCompositeHeight();
    scrolledComp.layout();
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) StatisticChartItem(com.cubrid.cubridmanager.core.monstatistic.model.StatisticChartItem)

Example 10 with StatisticChartItem

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

the class MonitorStatisticEditor method removeStatisticItem.

public void removeStatisticItem(List<StatisticChartItem> chartItemList) {
    if (chartItemList == null) {
        return;
    }
    List<Integer> indexList = new ArrayList<Integer>();
    for (StatisticChartItem chartItem : chartItemList) {
        indexList.add(statisticItemList.indexOf(chartItem));
    }
    for (StatisticChartItem chartItem : chartItemList) {
        statisticItemList.remove(chartItem);
        statisticDataMap.remove(chartItem);
        addItemCompIndex--;
    }
    Collections.sort(indexList);
    for (int i = indexList.size() - 1; i >= 0; i--) {
        int index = indexList.get(i);
        chartList.remove(index);
        Composite comp = compList.get(index);
        compList.remove(index);
        comp.dispose();
    }
    for (int i = 0; i < statisticItemList.size(); i++) {
        StatisticChartItem chartItem = statisticItemList.get(i);
        chartItem.setSeries(i);
    }
    createHiddenItems();
    chartAreaRootComp.layout();
    monitorStatisticPersistManager.saveStatistic();
    updateScrolledCompositeHeight();
    scrolledComp.layout();
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) ArrayList(java.util.ArrayList) StatisticChartItem(com.cubrid.cubridmanager.core.monstatistic.model.StatisticChartItem)

Aggregations

StatisticChartItem (com.cubrid.cubridmanager.core.monstatistic.model.StatisticChartItem)11 ArrayList (java.util.ArrayList)7 MonitorStatisticChart (com.cubrid.cubridmanager.ui.monstatistic.editor.internal.MonitorStatisticChart)5 List (java.util.List)5 ScrolledComposite (org.eclipse.swt.custom.ScrolledComposite)4 Composite (org.eclipse.swt.widgets.Composite)4 GridData (org.eclipse.swt.layout.GridData)3 MultiHostChartItem (com.cubrid.cubridmanager.core.monstatistic.model.MultiHostChartItem)2 SingleHostChartItem (com.cubrid.cubridmanager.core.monstatistic.model.SingleHostChartItem)2 StatisticChartHost (com.cubrid.cubridmanager.core.monstatistic.model.StatisticChartHost)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 MonitorStatistic (com.cubrid.common.ui.spi.model.MonitorStatistic)1 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)1 MonitoringTask (com.cubrid.cubridmanager.core.common.task.MonitoringTask)1 IXMLMemento (com.cubrid.cubridmanager.core.common.xml.IXMLMemento)1 XMLMemento (com.cubrid.cubridmanager.core.common.xml.XMLMemento)1 StatisticData (com.cubrid.cubridmanager.core.monstatistic.model.StatisticData)1 GetMonitorStatisticDataTask (com.cubrid.cubridmanager.core.monstatistic.task.GetMonitorStatisticDataTask)1 EditMultiHostStatisticItemDialog (com.cubrid.cubridmanager.ui.monstatistic.dialog.EditMultiHostStatisticItemDialog)1 EditSingleHostStatisticItemDialog (com.cubrid.cubridmanager.ui.monstatistic.dialog.EditSingleHostStatisticItemDialog)1