Search in sources :

Example 1 with RestartBrokerTask

use of com.cubrid.cubridmanager.core.broker.task.RestartBrokerTask in project cubrid-manager by CUBRID.

the class DatabaseDashboardEditor method createBrokerComposite.

/**
	 * craete broker composite
	 *
	 * @param bar
	 * @param bar index
	 *
	 */
public void createBrokerComposite(ExpandBar bar, int index) {
    ExpandItem brokerItem = new ExpandItem(bar, SWT.NONE, index);
    brokerItem.setText(Messages.exportDashboardBrokerTableTitle);
    Composite brokerComposite = new Composite(bar, SWT.None);
    brokerComposite.setLayout(new FillLayout());
    brokerInfoTableViewer = new TableViewer(brokerComposite, SWT.BORDER | SWT.FULL_SELECTION);
    brokerInfoTable = brokerInfoTableViewer.getTable();
    brokerInfoTable.setHeaderVisible(true);
    brokerInfoTable.setLinesVisible(true);
    final TableViewerColumn columnVolumn = new TableViewerColumn(brokerInfoTableViewer, SWT.CENTER);
    columnVolumn.getColumn().setWidth(100);
    columnVolumn.getColumn().setText("Broker");
    columnVolumn.getColumn().setToolTipText(com.cubrid.cubridmanager.ui.host.Messages.tipBrokerName);
    final TableViewerColumn columnType = new TableViewerColumn(brokerInfoTableViewer, SWT.CENTER);
    columnType.getColumn().setWidth(80);
    columnType.getColumn().setText("ID");
    columnType.getColumn().setToolTipText(Messages.brokerTableIDColumnTip);
    final TableViewerColumn columnSize = new TableViewerColumn(brokerInfoTableViewer, SWT.CENTER);
    columnSize.getColumn().setWidth(100);
    columnSize.getColumn().setText("PID");
    columnSize.getColumn().setToolTipText(Messages.brokerTablePIDColumnTip);
    final TableViewerColumn columnQPS = new TableViewerColumn(brokerInfoTableViewer, SWT.CENTER);
    columnQPS.getColumn().setWidth(100);
    columnQPS.getColumn().setText("QPS");
    columnQPS.getColumn().setToolTipText(com.cubrid.cubridmanager.ui.host.Messages.tipQps);
    final TableViewerColumn columnFreeSize = new TableViewerColumn(brokerInfoTableViewer, SWT.CENTER);
    columnFreeSize.getColumn().setWidth(100);
    columnFreeSize.getColumn().setText("LQS");
    columnFreeSize.getColumn().setToolTipText(Messages.brokerTableLQSColumnTip);
    final TableViewerColumn columnTotalSize = new TableViewerColumn(brokerInfoTableViewer, SWT.CENTER);
    columnTotalSize.getColumn().setWidth(80);
    columnTotalSize.getColumn().setText(Messages.multiDatabaseLoginDialogColumnStatus);
    columnTotalSize.getColumn().setToolTipText(Messages.multiDatabaseLoginDialogColumnStatus);
    final TableViewerColumn columnLocation = new TableViewerColumn(brokerInfoTableViewer, SWT.CENTER);
    columnLocation.getColumn().setWidth(140);
    columnLocation.getColumn().setText(Messages.brokerTableLastConnectTimeColumnLabel);
    columnLocation.getColumn().setToolTipText(Messages.brokerTableLastConnectTimeColumnLabel);
    brokerInfoTableViewer.setContentProvider(new TableContentProvider());
    brokerInfoTableViewer.setLabelProvider(new TableLabelProvider());
    brokerInfoTableViewer.setInput(brokerInfoListData);
    brokerItem.setControl(brokerComposite);
    brokerItem.setHeight(140);
    brokerItem.setExpanded(true);
    Menu menu = new Menu(this.getSite().getShell(), SWT.POP_UP);
    final MenuItem itemRestartCAS = new MenuItem(menu, SWT.PUSH);
    itemRestartCAS.setText(Messages.exportDashboardMenuRestartServer);
    itemRestartCAS.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            int i = brokerInfoTable.getSelectionIndex();
            if (i < 0) {
                return;
            }
            String brokerName = brokerInfoTable.getItem(i).getText(0);
            String serverId = brokerInfoTable.getItem(i).getText(1);
            if (!CommonUITool.openConfirmBox(Messages.bind(com.cubrid.cubridmanager.ui.broker.Messages.restartBrokerServerMsg, serverId))) {
                return;
            }
            ServerInfo serverInfo = database.getServer().getServerInfo();
            RestartBrokerTask restartTask = new RestartBrokerTask(serverInfo);
            restartTask.setBrokerName(brokerName);
            restartTask.setApplyServerNum(serverId);
            TaskExecutor taskExecutor = new CommonTaskExec(Messages.bind(com.cubrid.cubridmanager.ui.broker.Messages.restartBrokerServerTaskName, serverId));
            taskExecutor.addTask(restartTask);
            new ExecTaskWithProgress(taskExecutor).exec();
            if (taskExecutor.isSuccess()) {
                // refresh
                brokerInfoListData.clear();
                asinfoLst.clear();
                brokerInfoTable.remove(i);
                loadBrokerInfo();
                //recompute database's qps
                long qps = 0;
                for (HashMap<String, ApplyServerInfo> brokerValueMap : asinfoLst) {
                    for (Entry<String, ApplyServerInfo> entry : brokerValueMap.entrySet()) {
                        ApplyServerInfo applyServerInfo = entry.getValue();
                        qps += Long.valueOf(applyServerInfo.getAs_num_query());
                    }
                }
                Map<String, String> dbInfoMap = brokerInfoListData.get(0);
                dbInfoMap.put("2", Long.toString(qps));
                if (CompatibleUtil.isSupportGetCPUAndMemoryInfo(database.getDatabaseInfo())) {
                    dbInfoTableViewer.refresh();
                }
                brokerInfoTableViewer.refresh();
            }
        }
    });
    final MenuItem itemShowSqlLog = new MenuItem(menu, SWT.PUSH);
    itemShowSqlLog.setText(Messages.exportDashboardMenuShowSQLLog);
    itemShowSqlLog.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            showLogView("sql");
        }
    });
    final MenuItem itemShowSlowQueryLog = new MenuItem(menu, SWT.PUSH);
    itemShowSlowQueryLog.setText(Messages.exportDashboardMenuShowSlowQueryLog);
    itemShowSlowQueryLog.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            showLogView("slow");
        }
    });
    menu.addMenuListener(new MenuListener() {

        public void menuHidden(MenuEvent e) {
        }

        public void menuShown(MenuEvent e) {
            int i = brokerInfoTable.getSelectionIndex();
            if (i < 0) {
                Menu menu = (Menu) e.getSource();
                menu.setVisible(false);
            }
        }
    });
    brokerInfoTable.setMenu(menu);
    tableViewOnBarIndexMap.put(brokerInfoTableViewer, index);
}
Also used : CommonTaskExec(com.cubrid.common.ui.spi.progress.CommonTaskExec) Composite(org.eclipse.swt.widgets.Composite) HashMap(java.util.HashMap) ApplyServerInfo(com.cubrid.cubridmanager.core.broker.model.ApplyServerInfo) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) MenuListener(org.eclipse.swt.events.MenuListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) MenuItem(org.eclipse.swt.widgets.MenuItem) FillLayout(org.eclipse.swt.layout.FillLayout) TableLabelProvider(com.cubrid.common.ui.spi.TableLabelProvider) ApplyServerInfo(com.cubrid.cubridmanager.core.broker.model.ApplyServerInfo) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) DbLotEntry(com.cubrid.cubridmanager.core.cubrid.database.model.lock.DbLotEntry) Entry(java.util.Map.Entry) ExpandItem(org.eclipse.swt.widgets.ExpandItem) TableContentProvider(com.cubrid.common.ui.spi.TableContentProvider) SelectionEvent(org.eclipse.swt.events.SelectionEvent) RestartBrokerTask(com.cubrid.cubridmanager.core.broker.task.RestartBrokerTask) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) Menu(org.eclipse.swt.widgets.Menu) TableViewer(org.eclipse.jface.viewers.TableViewer) Map(java.util.Map) TreeMap(java.util.TreeMap) HashMap(java.util.HashMap) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) MenuEvent(org.eclipse.swt.events.MenuEvent)

Aggregations

TableContentProvider (com.cubrid.common.ui.spi.TableContentProvider)1 TableLabelProvider (com.cubrid.common.ui.spi.TableLabelProvider)1 CommonTaskExec (com.cubrid.common.ui.spi.progress.CommonTaskExec)1 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)1 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)1 ApplyServerInfo (com.cubrid.cubridmanager.core.broker.model.ApplyServerInfo)1 RestartBrokerTask (com.cubrid.cubridmanager.core.broker.task.RestartBrokerTask)1 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)1 DbLotEntry (com.cubrid.cubridmanager.core.cubrid.database.model.lock.DbLotEntry)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 TreeMap (java.util.TreeMap)1 TableViewer (org.eclipse.jface.viewers.TableViewer)1 TableViewerColumn (org.eclipse.jface.viewers.TableViewerColumn)1 MenuEvent (org.eclipse.swt.events.MenuEvent)1 MenuListener (org.eclipse.swt.events.MenuListener)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 FillLayout (org.eclipse.swt.layout.FillLayout)1