Search in sources :

Example 6 with DatabaseNode

use of com.cubrid.cubridmanager.ui.mondashboard.editor.model.DatabaseNode in project cubrid-manager by CUBRID.

the class SelectDbPage method createControl.

/**
	 * Create the control for this page
	 * 
	 * @param parent Composite
	 */
public void createControl(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.marginHeight = 10;
    layout.marginWidth = 10;
    composite.setLayout(layout);
    GridData gridData = new GridData(GridData.FILL_BOTH);
    composite.setLayoutData(gridData);
    Group dbInfoGroup = new Group(composite, SWT.NONE);
    dbInfoGroup.setText(Messages.grpSelectDb);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    dbInfoGroup.setLayoutData(gridData);
    layout = new GridLayout();
    layout.numColumns = 2;
    dbInfoGroup.setLayout(layout);
    Label dbNameLabel = new Label(dbInfoGroup, SWT.LEFT);
    dbNameLabel.setText(Messages.lblDbName);
    dbNameLabel.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
    dbNameCombo = new Combo(dbInfoGroup, SWT.LEFT | SWT.BORDER | SWT.READ_ONLY);
    dbNameCombo.setLayoutData(CommonUITool.createGridData(GridData.FILL_HORIZONTAL, 1, 1, 100, -1));
    dbNameCombo.addModifyListener(this);
    Label nickNameLable = new Label(dbInfoGroup, SWT.LEFT);
    nickNameLable.setText(Messages.lblNickName);
    nickNameLable.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
    nickNameText = new Text(dbInfoGroup, SWT.LEFT | SWT.BORDER);
    nickNameText.setLayoutData(CommonUITool.createGridData(GridData.FILL_HORIZONTAL, 1, 1, -1, -1));
    Label dbaPasswordLabel = new Label(dbInfoGroup, SWT.LEFT);
    dbaPasswordLabel.setText(Messages.lblDbaPassword);
    dbaPasswordLabel.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
    dbaPasswordText = new Text(dbInfoGroup, SWT.LEFT | SWT.BORDER | SWT.PASSWORD);
    dbaPasswordText.setLayoutData(CommonUITool.createGridData(GridData.FILL_HORIZONTAL, 1, 1, 100, -1));
    Composite btnComposite = new Composite(composite, SWT.NONE);
    RowLayout rowLayout = new RowLayout();
    rowLayout.spacing = 5;
    btnComposite.setLayout(rowLayout);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.horizontalAlignment = GridData.END;
    btnComposite.setLayoutData(gridData);
    addButton = new Button(btnComposite, SWT.NONE);
    addButton.setText(Messages.btnAddDb);
    addButton.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            String dbName = dbNameCombo.getText();
            String dbaPassword = dbaPasswordText.getText();
            String nickName = nickNameText.getText();
            if (nickName.trim().length() == 0) {
                nickName = dbName;
            }
            //check whether this database already be added
            if (isExist(dbName, hostNode)) {
                CommonUITool.openErrorBox(Messages.bind(Messages.errDbExist, dbName));
                return;
            }
            DatabaseInfo dbInfo = serverInfo.getLoginedUserInfo().getDatabaseInfo(dbName);
            TaskExecutor executor = new CommonTaskExec(null);
            VerifyDbUserPasswordTask verifyDbUserPasswordTask = null;
            if (dbInfo.isLogined() && dbInfo.getAuthLoginedDbUserInfo().getName().equalsIgnoreCase("dba")) {
                String password = dbInfo.getAuthLoginedDbUserInfo().getNoEncryptPassword();
                if (!dbaPassword.equals(password)) {
                    CommonUITool.openErrorBox(Messages.errDbaPassowrd);
                    return;
                }
            } else {
                verifyDbUserPasswordTask = new VerifyDbUserPasswordTask(serverInfo);
                verifyDbUserPasswordTask.setDbName(dbName);
                verifyDbUserPasswordTask.setDbUser("dba");
                verifyDbUserPasswordTask.setDbPassword(dbaPassword);
                executor.addTask(verifyDbUserPasswordTask);
            }
            GetHeartbeatNodeInfoTask getHeartbeatNodeInfoTask = new GetHeartbeatNodeInfoTask(serverInfo);
            getHeartbeatNodeInfoTask.setAllDb(false);
            List<String> dbList = new ArrayList<String>();
            dbList.add(dbName);
            getHeartbeatNodeInfoTask.setDbList(dbList);
            executor.addTask(getHeartbeatNodeInfoTask);
            new ExecTaskWithProgress(executor).exec(true, true);
            if (!executor.isSuccess()) {
                if (verifyDbUserPasswordTask != null && !verifyDbUserPasswordTask.isSuccess()) {
                    dbaPasswordText.selectAll();
                    dbaPasswordText.setFocus();
                }
                return;
            }
            List<HAHostStatusInfo> haHostStatusInfoList = getHeartbeatNodeInfoTask.getHAHostStatusList();
            HADatabaseStatusInfo haDbStatusInfo = getHeartbeatNodeInfoTask.getDatabaseStatusInfo(dbName);
            HAHostStatusInfo haHostStatusInfo = getHeartbeatNodeInfoTask.getHostStatusInfo(serverInfo.getHostAddress());
            //if this database is HA Mode,will get it's active database or standby database
            List<DatabaseNode> haDbNodeList = getHADatabaseList(haDbStatusInfo, haHostStatusInfoList, true);
            if (haHostStatusInfo == null) {
                haHostStatusInfo = HAUtil.getHAHostStatusInfo(serverInfo);
                if (haDbStatusInfo != null) {
                    haHostStatusInfo.addHADatabaseStatus(haDbStatusInfo);
                }
            }
            if (haDbStatusInfo == null) {
                haDbStatusInfo = HAUtil.getHADatabaseStatusInfo(dbName, haHostStatusInfo, serverInfo);
            }
            DatabaseNode dbNode = new DatabaseNode();
            hostNode.setHostStatusInfo(haHostStatusInfo);
            dbNode.setParent(hostNode);
            dbNode.setDbName(dbName);
            dbNode.setDbUser("dba");
            dbNode.setDbPassword(dbaPassword);
            dbNode.setName(nickName);
            dbNode.setHaDatabaseStatus(haDbStatusInfo);
            dbNode.setConnected(true);
            if (haDbNodeList == null) {
                haDbNodeList = new ArrayList<DatabaseNode>();
            }
            if (dbNode.getDbStatusType() == DBStatusType.ACTIVE || dbNode.getDbStatusType() == DBStatusType.TO_BE_ACTIVE) {
                haDbNodeList.add(0, dbNode);
            } else {
                haDbNodeList.add(dbNode);
            }
            addDbNodeToTable(haDbNodeList, haHostStatusInfoList);
        }
    });
    haModeBtn = new Button(dbInfoGroup, SWT.LEFT | SWT.CHECK);
    haModeBtn.setText(Messages.btnHAMode);
    haModeBtn.setLayoutData(CommonUITool.createGridData(GridData.FILL_HORIZONTAL, 2, 1, 100, -1));
    haModeBtn.setEnabled(false);
    createTable(composite);
    dbNameCombo.setFocus();
    setTitle(Messages.titleSelectDbPage);
    setMessage(Messages.msgSelectDbPage);
    setControl(composite);
}
Also used : Group(org.eclipse.swt.widgets.Group) CommonTaskExec(com.cubrid.common.ui.spi.progress.CommonTaskExec) Composite(org.eclipse.swt.widgets.Composite) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) ArrayList(java.util.ArrayList) Combo(org.eclipse.swt.widgets.Combo) Text(org.eclipse.swt.widgets.Text) GetHeartbeatNodeInfoTask(com.cubrid.cubridmanager.core.mondashboard.task.GetHeartbeatNodeInfoTask) HAHostStatusInfo(com.cubrid.cubridmanager.core.mondashboard.model.HAHostStatusInfo) GridLayout(org.eclipse.swt.layout.GridLayout) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) DatabaseNode(com.cubrid.cubridmanager.ui.mondashboard.editor.model.DatabaseNode) Button(org.eclipse.swt.widgets.Button) RowLayout(org.eclipse.swt.layout.RowLayout) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) ArrayList(java.util.ArrayList) List(java.util.List) HADatabaseStatusInfo(com.cubrid.cubridmanager.core.mondashboard.model.HADatabaseStatusInfo) VerifyDbUserPasswordTask(com.cubrid.cubridmanager.core.mondashboard.task.VerifyDbUserPasswordTask)

Example 7 with DatabaseNode

use of com.cubrid.cubridmanager.ui.mondashboard.editor.model.DatabaseNode in project cubrid-manager by CUBRID.

the class DbDashboardHistoryAction method run.

/**
	 * Open monitor host detail windows.
	 */
public void run() {
    if (getSelectedObj() == null || getSelectedObj().length == 0) {
        return;
    }
    Object obj = getSelectedObj()[0];
    if (!(obj instanceof DatabaseMonitorPart)) {
        return;
    }
    DatabaseMonitorPart part = (DatabaseMonitorPart) obj;
    DatabaseNode dn = (DatabaseNode) part.getModel();
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null) {
        return;
    }
    IWorkbenchPage page = window.getActivePage();
    if (page == null) {
        return;
    }
    HostNode hn = dn.getParent();
    String secondaryId = new StringBuffer(dn.getDbName()).append("&").append(hn.getUserName()).append("&").append(hn.getIp()).append("&").append(hn.getPort()).toString();
    IViewReference viewReference = page.findViewReference(DbDashboardHistoryViewPart.ID, secondaryId);
    if (viewReference == null) {
        try {
            IViewPart viewPart = page.showView(DbDashboardHistoryViewPart.ID, secondaryId, IWorkbenchPage.VIEW_ACTIVATE);
            ((DbDashboardHistoryViewPart) viewPart).init((DatabaseNode) part.getModel());
        } catch (PartInitException ex) {
            viewReference = null;
        }
    } else {
        IViewPart viewPart = viewReference.getView(false);
        window.getActivePage().bringToTop(viewPart);
        ((DbDashboardHistoryViewPart) viewPart).init((DatabaseNode) part.getModel());
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IViewPart(org.eclipse.ui.IViewPart) DatabaseNode(com.cubrid.cubridmanager.ui.mondashboard.editor.model.DatabaseNode) HostNode(com.cubrid.cubridmanager.ui.mondashboard.editor.model.HostNode) IViewReference(org.eclipse.ui.IViewReference) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) DbDashboardHistoryViewPart(com.cubrid.cubridmanager.ui.mondashboard.editor.DbDashboardHistoryViewPart) PartInitException(org.eclipse.ui.PartInitException) DatabaseMonitorPart(com.cubrid.cubridmanager.ui.mondashboard.editor.parts.DatabaseMonitorPart)

Example 8 with DatabaseNode

use of com.cubrid.cubridmanager.ui.mondashboard.editor.model.DatabaseNode in project cubrid-manager by CUBRID.

the class MonitorDetailAction method isSupported.

/**
	 * 
	 * 
	 * @see com.cubrid.common.ui.spi.action.ISelectionAction#isSupported(java.lang.Object)
	 * @param obj Object
	 * @return is supported.
	 */
public boolean isSupported(Object obj) {
    HostNode hostNode = null;
    if (obj instanceof HostMonitorPart) {
        hostNode = (HostNode) ((HostMonitorPart) obj).getModel();
    } else if (obj instanceof BrokerMonitorPart) {
        BrokerNode brokerNode = (BrokerNode) ((BrokerMonitorPart) obj).getModel();
        hostNode = brokerNode.getParent();
    }
    if (hostNode != null) {
        return hostNode.isConnected();
    }
    if (obj instanceof DatabaseMonitorPart) {
        DatabaseNode dbNode = (DatabaseNode) ((DatabaseMonitorPart) obj).getModel();
        hostNode = dbNode.getParent();
        return hostNode.isConnected() && dbNode.isConnected();
    }
    return false;
}
Also used : BrokerNode(com.cubrid.cubridmanager.ui.mondashboard.editor.model.BrokerNode) DatabaseNode(com.cubrid.cubridmanager.ui.mondashboard.editor.model.DatabaseNode) BrokerMonitorPart(com.cubrid.cubridmanager.ui.mondashboard.editor.parts.BrokerMonitorPart) HostNode(com.cubrid.cubridmanager.ui.mondashboard.editor.model.HostNode) HostMonitorPart(com.cubrid.cubridmanager.ui.mondashboard.editor.parts.HostMonitorPart) DatabaseMonitorPart(com.cubrid.cubridmanager.ui.mondashboard.editor.parts.DatabaseMonitorPart)

Example 9 with DatabaseNode

use of com.cubrid.cubridmanager.ui.mondashboard.editor.model.DatabaseNode in project cubrid-manager by CUBRID.

the class DataGeneratorPool method isHasConnection.

/**
	 * 
	 * Return whether has connection
	 * 
	 * @param ip String
	 * @param port String
	 * @param userName String
	 * @return boolean
	 */
public boolean isHasConnection(String ip, String port, String userName) {
    Iterator<DataGenerator> it = map.values().iterator();
    while (it.hasNext()) {
        DataGenerator generator = it.next();
        List<DataUpdateListener> listenerList = generator.getListeners();
        for (DataUpdateListener listener : listenerList) {
            HostNode hostNode = null;
            if (listener.getModel() instanceof HostNode) {
                hostNode = (HostNode) listener.getModel();
            } else if (listener.getModel() instanceof DatabaseNode) {
                hostNode = ((DatabaseNode) listener.getModel()).getParent();
            } else if (listener.getModel() instanceof BrokerNode) {
                hostNode = ((BrokerNode) listener.getModel()).getParent();
            }
            if (hostNode != null && hostNode.isConnected() && ip.equals(hostNode.getIp()) && port.equals(hostNode.getPort()) && userName.equals(hostNode.getUserName())) {
                return true;
            }
        }
    }
    return false;
}
Also used : BrokerNode(com.cubrid.cubridmanager.ui.mondashboard.editor.model.BrokerNode) DatabaseNode(com.cubrid.cubridmanager.ui.mondashboard.editor.model.DatabaseNode) HostNode(com.cubrid.cubridmanager.ui.mondashboard.editor.model.HostNode)

Example 10 with DatabaseNode

use of com.cubrid.cubridmanager.ui.mondashboard.editor.model.DatabaseNode in project cubrid-manager by CUBRID.

the class DataProvider method getUpdateValue.

/**
	 * Get the newest update data
	 * 
	 * @return DataChangedEvent
	 */
public DataChangedEvent getUpdateValue() {
    setDefaultValue();
    DataChangedEvent dataChangedEvent = new DataChangedEvent(this);
    Set<MondashDataResult> resultSet = new HashSet<MondashDataResult>();
    try {
        executeInThread();
    } catch (InterruptedException e) {
        LOGGER.error("", e);
    }
    // handle with the data
    //get host status
    Map<IDiagPara, String> hostMap = new HashMap<IDiagPara, String>();
    if (isExecuteHostStatTask) {
        performHostStatTask(hostMap);
    }
    //get broker status
    if (isExecuteBrokerStatTask) {
        performBrokerDiagTask(hostMap);
    }
    if (isExecuteHostStatTask || isExecuteBrokerStatTask) {
        MondashDataResult hostResult = new MondashDataResult();
        hostResult.setName(generator.getName());
        hostResult.putUpdateMap(hostMap);
        resultSet.add(hostResult);
    }
    //get HA node status
    List<HAHostStatusInfo> haHostStatusInfoList = null;
    if (isExecuteHeartbeatTask) {
        performHeartbeatNodeInfoTask();
        haHostStatusInfoList = getHeartbeatNodeInfoTask == null ? null : getHeartbeatNodeInfoTask.getHAHostStatusList();
    }
    //get database status
    List<HADatabaseStatusInfo> dbStatusInfoList = null;
    String dbStatusErrorInfo = null;
    if (isExecuteDbModeTask) {
        dbStatusErrorInfo = getDbModeTask.getErrorMsg();
        if (dbStatusErrorInfo != null && dbStatusErrorInfo.trim().length() > 0) {
            dbStatusErrorInfo += ", can not get database status.";
        }
        dbStatusInfoList = getDbModeTask.getDbModes();
    }
    //get some broker status
    DataChangedEvent event = brokerDataProvider == null ? null : brokerDataProvider.getUpdateValue();
    for (int i = 0; i < uniqueBrokerNodeList.size(); i++) {
        BrokerNode brokerNode = uniqueBrokerNodeList.get(i);
        if (event != null) {
            String brokerName = brokerNode.getBrokerName();
            dataChangedEvent.getBrokerInfosMap().put(brokerName, event.getBrokerInfosMap().get(brokerName));
            dataChangedEvent.getBrokerStatusInfosMap().put(brokerName, event.getBrokerStatusInfosMap().get(brokerName));
            dataChangedEvent.getBrokerDiagDataMap().put(brokerName, event.getBrokerDiagDataMap().get(brokerName));
        }
    }
    //get some databases status
    for (int i = 0; i < dbDataProviderList.size(); i++) {
        Set<MondashDataResult> dbResultSet = dbDataProviderList.get(i).getUpdateValue().getResultSet();
        if (dbResultSet != null) {
            resultSet.addAll(dbResultSet);
        }
        //set error
        DatabaseNode dbNode = dbDataProviderList.get(i).getDatabaseNode();
        if (StringUtil.isNotEmpty(dbStatusErrorInfo) && dbNode.getParent().isConnected()) {
            dbNode.setErrorMsg(dbStatusErrorInfo);
        }
        HADatabaseStatusInfo dbStatusInfo = HAUtil.getDatabaseStatusInfo(dbStatusInfoList, dbNode.getDbName());
        String errorInfo = dbStatusInfo == null ? null : dbStatusInfo.getErrorInfo();
        if (StringUtil.isNotEmpty(errorInfo) && dbNode.getParent().isConnected()) {
            dbNode.setErrorMsg(errorInfo);
        }
    }
    if (requestCount < 2) {
        requestCount++;
    }
    dataChangedEvent.setResultSet(resultSet);
    dataChangedEvent.setHaHostStatusInfoList(haHostStatusInfoList);
    dataChangedEvent.setDbStatusInfoList(dbStatusInfoList);
    setErrorMsg(errorMsg);
    if (errorMsg != null && errorMsg.trim().length() > 0) {
        LOGGER.error(errorMsg);
    }
    return dataChangedEvent;
}
Also used : HashMap(java.util.HashMap) IDiagPara(com.cubrid.cubridmanager.core.monitoring.model.IDiagPara) HAHostStatusInfo(com.cubrid.cubridmanager.core.mondashboard.model.HAHostStatusInfo) BrokerNode(com.cubrid.cubridmanager.ui.mondashboard.editor.model.BrokerNode) DatabaseNode(com.cubrid.cubridmanager.ui.mondashboard.editor.model.DatabaseNode) HADatabaseStatusInfo(com.cubrid.cubridmanager.core.mondashboard.model.HADatabaseStatusInfo) HashSet(java.util.HashSet)

Aggregations

DatabaseNode (com.cubrid.cubridmanager.ui.mondashboard.editor.model.DatabaseNode)36 HostNode (com.cubrid.cubridmanager.ui.mondashboard.editor.model.HostNode)20 BrokerNode (com.cubrid.cubridmanager.ui.mondashboard.editor.model.BrokerNode)14 DatabaseMonitorPart (com.cubrid.cubridmanager.ui.mondashboard.editor.parts.DatabaseMonitorPart)11 ArrayList (java.util.ArrayList)9 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)6 HADatabaseStatusInfo (com.cubrid.cubridmanager.core.mondashboard.model.HADatabaseStatusInfo)5 HAHostStatusInfo (com.cubrid.cubridmanager.core.mondashboard.model.HAHostStatusInfo)4 HashMap (java.util.HashMap)4 List (java.util.List)4 Point (org.eclipse.draw2d.geometry.Point)4 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)4 SelectionEvent (org.eclipse.swt.events.SelectionEvent)4 GridData (org.eclipse.swt.layout.GridData)4 RowLayout (org.eclipse.swt.layout.RowLayout)4 Button (org.eclipse.swt.widgets.Button)4 Composite (org.eclipse.swt.widgets.Composite)4 Label (org.eclipse.swt.widgets.Label)4 DefaultCubridNode (com.cubrid.common.ui.spi.model.DefaultCubridNode)3 BrokerDBListNode (com.cubrid.cubridmanager.ui.mondashboard.editor.model.BrokerDBListNode)3