Search in sources :

Example 16 with MonitoringTask

use of com.cubrid.cubridmanager.core.common.task.MonitoringTask 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 17 with MonitoringTask

use of com.cubrid.cubridmanager.core.common.task.MonitoringTask in project cubrid-manager by CUBRID.

the class FinishTask method call.

public Integer call() {
    ProgressBar bar = (ProgressBar) item.getData(MultiHostConnectionDialog.KEY_BAR);
    MonitorDashboardPreference monPref = new MonitorDashboardPreference();
    boolean isRunUpdateCmUserTask = false;
    BrokerInfos brokerInfos = null;
    int size = tasks.size();
    int taskIdx = 1;
    for (ITask task : tasks) {
        if (task instanceof MonitoringTask) {
            if (!serverInfo.isConnected()) {
                CMHostNodePersistManager.getInstance().addServer(serverInfo.getHostAddress(), serverInfo.getHostMonPort(), serverInfo.getUserName(), serverInfo);
                MonitoringTask monitoringTask = (MonitoringTask) task;
                serverInfo = monitoringTask.connectServer(Version.releaseVersion, monPref.getHAHeartBeatTimeout());
                if (serverInfo.isConnected()) {
                    CMHostNodePersistManager.getInstance().addServer(serverInfo.getHostAddress(), serverInfo.getHostMonPort(), serverInfo.getUserName(), serverInfo);
                } else {
                    CMHostNodePersistManager.getInstance().removeServer(serverInfo.getHostAddress(), serverInfo.getHostMonPort(), serverInfo.getUserName());
                }
            }
        } else if ((task instanceof UpdateCMUserTask)) {
            updateCMUserAuthInfo(task, isRunUpdateCmUserTask);
        } else {
            task.execute();
        }
        final String msg = task.getErrorMsg();
        if (msg != null && msg.length() > 0) {
            item.setText(3, msg);
            disConnect();
            isFinished = true;
            updateIcon();
            return 1;
        }
        if (task instanceof GetEnvInfoTask) {
            GetEnvInfoTask getEnvInfoTask = (GetEnvInfoTask) task;
            EnvInfo envInfo = getEnvInfoTask.loadEnvInfo();
            serverInfo.setEnvInfo(envInfo);
            String clientVersion = getClientVerion();
            if (!isClientSupport(clientVersion)) {
                item.setText(3, Messages.bind(Messages.errNoSupportServerVersion, clientVersion));
                disConnect();
                isFinished = true;
                updateIcon();
                return 2;
            }
            String jdbcVersion = serverInfo.getJdbcDriverVersion();
            if (serverInfo.validateJdbcVersion(jdbcVersion)) {
                if (ServerJdbcVersionMapping.JDBC_SELF_ADAPTING_VERSION.equals(jdbcVersion)) {
                    serverInfo.setJdbcDriverVersion(ServerInfo.getAutoDetectJdbcVersion(serverInfo.getFullServerVersionKey()));
                }
            } else {
                if (ServerJdbcVersionMapping.JDBC_SELF_ADAPTING_VERSION.equals(jdbcVersion)) {
                    item.setText(3, Messages.errNoSupportDriver);
                } else {
                    item.setText(3, Messages.errSelectSupportDriver);
                }
                disConnect();
                isFinished = true;
                updateIcon();
                return 3;
            }
        } else if (task instanceof GetDatabaseListTask) {
            GetDatabaseListTask getDatabaseListTask = (GetDatabaseListTask) task;
            List<DatabaseInfo> databaseInfoList = getDatabaseListTask.loadDatabaseInfo();
            if (databaseInfoList != null) {
                allDatabaseInfoList.addAll(databaseInfoList);
            }
        } else if (task instanceof GetCMConfParameterTask) {
            GetCMConfParameterTask getCMConfParameterTask = (GetCMConfParameterTask) task;
            Map<String, String> confParameters = getCMConfParameterTask.getConfParameters();
            ServerType serverType = ServerType.BOTH;
            if (confParameters != null) {
                String target = confParameters.get(CubridManagerConfParaConstants.CM_TARGET);
                if (target != null) {
                    if (target.indexOf("broker") >= 0 && target.indexOf("server") >= 0) {
                        serverType = ServerType.BOTH;
                    } else if (target.indexOf("broker") >= 0) {
                        serverType = ServerType.BROKER;
                    } else if (target.indexOf("server") >= 0) {
                        serverType = ServerType.DATABASE;
                    }
                }
            }
            if (serverInfo != null) {
                serverInfo.setServerType(serverType);
            }
        } else if (task instanceof CommonQueryTask) {
            CommonQueryTask<BrokerInfos> getBrokerTask = (CommonQueryTask<BrokerInfos>) task;
            brokerInfos = getBrokerTask.getResultModel();
            if (serverInfo != null) {
                serverInfo.setBrokerInfos(brokerInfos);
            }
        } else if (task instanceof GetCMUserListTask) {
            if (serverInfo != null && serverInfo.isConnected()) {
                GetCMUserListTask getUserInfoTask = (GetCMUserListTask) task;
                List<ServerUserInfo> serverUserInfoList = getUserInfoTask.getServerUserInfoList();
                for (int i = 0; serverUserInfoList != null && i < serverUserInfoList.size(); i++) {
                    ServerUserInfo userInfo = serverUserInfoList.get(i);
                    if (userInfo != null && userInfo.getUserName().equals(serverInfo.getUserName())) {
                        serverInfo.setLoginedUserInfo(userInfo);
                        break;
                    }
                }
                List<DatabaseInfo> databaseInfoList = serverInfo.getLoginedUserInfo().getDatabaseInfoList();
                if (databaseInfoList != null) {
                    authDatabaseList.addAll(databaseInfoList);
                }
                isRunUpdateCmUserTask = CubridDatabasesFolderLoader.filterDatabaseList(serverInfo, allDatabaseInfoList, authDatabaseList);
                if (isRunUpdateCmUserTask) {
                    serverInfo.getLoginedUserInfo().setDatabaseInfoList(authDatabaseList);
                }
            }
        } else if (task instanceof GetCubridConfParameterTask) {
            GetCubridConfParameterTask getCubridConfParameterTask = (GetCubridConfParameterTask) task;
            Map<String, Map<String, String>> confParas = getCubridConfParameterTask.getConfParameters();
            if (serverInfo != null) {
                serverInfo.setCubridConfParaMap(confParas);
            }
        } else if (task instanceof GetBrokerConfParameterTask) {
            GetBrokerConfParameterTask getBrokerConfParameterTask = (GetBrokerConfParameterTask) task;
            Map<String, Map<String, String>> confParas = getBrokerConfParameterTask.getConfParameters();
            if (serverInfo != null) {
                serverInfo.setBrokerConfParaMap(confParas);
            }
        } else if (task instanceof FinishTask) {
            isSuccess = true;
            server.getLoader().setLoaded(false);
            CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(server, CubridNodeChangedEventType.SERVER_CONNECTED));
        }
        bar.setSelection(taskIdx++ / size * 100);
        if (isCanceled()) {
            isFinished = true;
            updateIcon();
            return 4;
        }
    }
    bar.setSelection(100);
    item.setText(3, Messages.msgConneted);
    isFinished = true;
    return 0;
}
Also used : ServerType(com.cubrid.cubridmanager.core.common.model.ServerType) MonitorDashboardPreference(com.cubrid.cubridmanager.ui.mondashboard.preference.MonitorDashboardPreference) ITask(com.cubrid.common.core.task.ITask) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) BrokerInfos(com.cubrid.cubridmanager.core.broker.model.BrokerInfos) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) GetCMConfParameterTask(com.cubrid.cubridmanager.core.common.task.GetCMConfParameterTask) UpdateCMUserTask(com.cubrid.cubridmanager.core.common.task.UpdateCMUserTask) CommonQueryTask(com.cubrid.cubridmanager.core.common.task.CommonQueryTask) MonitoringTask(com.cubrid.cubridmanager.core.common.task.MonitoringTask) ArrayList(java.util.ArrayList) List(java.util.List) ServerUserInfo(com.cubrid.cubridmanager.core.common.model.ServerUserInfo) ProgressBar(org.eclipse.swt.widgets.ProgressBar) GetCMUserListTask(com.cubrid.cubridmanager.core.common.task.GetCMUserListTask) GetCubridConfParameterTask(com.cubrid.cubridmanager.core.common.task.GetCubridConfParameterTask) GetEnvInfoTask(com.cubrid.cubridmanager.core.common.task.GetEnvInfoTask) GetDatabaseListTask(com.cubrid.cubridmanager.core.cubrid.database.task.GetDatabaseListTask) GetBrokerConfParameterTask(com.cubrid.cubridmanager.core.broker.task.GetBrokerConfParameterTask) Map(java.util.Map) EnvInfo(com.cubrid.cubridmanager.core.common.model.EnvInfo)

Example 18 with MonitoringTask

use of com.cubrid.cubridmanager.core.common.task.MonitoringTask in project cubrid-manager by CUBRID.

the class ConnectHostExecutor method runLoop.

private boolean runLoop(final IProgressMonitor monitor) {
    MonitorDashboardPreference monPref = new MonitorDashboardPreference();
    isContinue = true;
    boolean isRunUpdateCmUserTask = false;
    BrokerInfos brokerInfos = null;
    /*To avoid invalid thread access exception*/
    beginTask(monitor);
    for (ITask task : taskList) {
        if (task instanceof MonitoringTask) {
            if (!serverInfo.isConnected()) {
                addServerInHashMap(serverInfo);
                MonitoringTask monitoringTask = (MonitoringTask) task;
                serverInfo = monitoringTask.connectServer(Version.releaseVersion, monPref.getHAHeartBeatTimeout());
                if (serverInfo.isConnected()) {
                    addServerInHashMap(serverInfo);
                } else {
                    removeServerFromHashMap(serverInfo);
                }
            }
            changePassword();
        } else if ((task instanceof UpdateCMUserTask)) {
            updateCMUserAuthInfo(task, isRunUpdateCmUserTask);
        } else {
            task.execute();
        }
        final String msg = task.getErrorMsg();
        if (monitor.isCanceled()) {
            disConnect();
            return false;
        }
        if (msg != null) {
            boolean emptyMsg = StringUtil.isEmpty(msg);
            // for TOOLS-2142 logging
            try {
                if (task instanceof MonitoringTask) {
                    String request = ((MonitoringTask) task).getRequest();
                    char[] requestCharArray = request.toCharArray();
                    int sp = request.indexOf("id:");
                    if (sp != -1) {
                        sp += "id:".length();
                        for (int i = sp; i < requestCharArray.length; i++) {
                            if (requestCharArray[i] == '\n') {
                                break;
                            }
                            requestCharArray[i] = '*';
                        }
                    }
                    sp = request.indexOf("password:");
                    if (sp != -1) {
                        sp += "password:".length();
                        for (int i = sp; i < requestCharArray.length; i++) {
                            if (requestCharArray[i] == '\n') {
                                break;
                            }
                            requestCharArray[i] = '*';
                        }
                    }
                    LOGGER.debug("CMS request : \n" + new String(requestCharArray));
                    LOGGER.debug("CMS error : \n" + task.getErrorMsg());
                    LOGGER.debug("CMS warn : \n" + task.getWarningMsg());
                }
            } catch (Exception e) {
                LOGGER.error("", e);
            }
            String lowerMsg = msg.toLowerCase();
            // Connection refused: connect
            if (lowerMsg.indexOf("connection refused: connect") != -1) {
                String localizedMsg = Messages.errConnectionRefused;
                if (!prepareMessage(monitor, localizedMsg)) {
                    return false;
                }
            } else //the socket "Connection reset" occasional error is unnecessary to display, and it will affect user experience.
            if (lowerMsg.indexOf("connection reset") != -1) {
                String localizedMsg = Messages.errConnectionReset;
                if (!prepareMessage(monitor, localizedMsg)) {
                    return false;
                }
            } else // connect timed out
            if (lowerMsg.indexOf("connect timed out") != -1) {
                String localizedMsg = Messages.errConnectTimedOut;
                if (!prepareMessage(monitor, localizedMsg)) {
                    return false;
                }
            } else // user not found
            if (lowerMsg.indexOf("user not found") != -1) {
                String localizedMsg = Messages.errUserNotFound;
                if (!prepareMessage(monitor, localizedMsg)) {
                    return false;
                }
            } else // Incorrect password
            if (lowerMsg.indexOf("incorrect password") != -1) {
                String localizedMsg = Messages.errUserPasswordConnect;
                if (!prepareMessage(monitor, localizedMsg)) {
                    return false;
                }
            } else // No route to host connect
            if (lowerMsg.indexOf("no route to host connect") != -1) {
                String localizedMsg = Messages.errConnectAddress;
                if (!prepareMessage(monitor, localizedMsg)) {
                    return false;
                }
            } else // There is no error message but there have some error about brokers.
            if (emptyMsg && StringUtil.isEqual(task.getTaskname(), BrokerInfos.TASK_NAME)) {
                String localizedMsg = Messages.errConnectionByBrokerConfig;
                if (!prepareMessage(monitor, localizedMsg)) {
                    return false;
                }
            } else {
                String localizedMsg = Messages.bind(Messages.errConnectionFailed, msg);
                if (!prepareMessage(monitor, localizedMsg)) {
                    return false;
                }
            }
        }
        if (task instanceof GetEnvInfoTask) {
            GetEnvInfoTask getEnvInfoTask = (GetEnvInfoTask) task;
            EnvInfo envInfo = getEnvInfoTask.loadEnvInfo();
            serverInfo.setEnvInfo(envInfo);
            String clientVersion = getClientVerion();
            if (!isClientSupport(clientVersion)) {
                openErrorBox(shell, Messages.bind(Messages.errNoSupportServerVersion, clientVersion), monitor);
            }
            //for multi host monitor statistic and monitor dashboard
            if (isCheckJdbc) {
                String jdbcVersion = serverInfo.getJdbcDriverVersion();
                if (serverInfo.validateJdbcVersion(jdbcVersion)) {
                    if (ServerJdbcVersionMapping.JDBC_SELF_ADAPTING_VERSION.equals(jdbcVersion)) {
                        serverInfo.setJdbcDriverVersion(ServerInfo.getAutoDetectJdbcVersion(serverInfo.getFullServerVersionKey()));
                    }
                } else {
                    if (ServerJdbcVersionMapping.JDBC_SELF_ADAPTING_VERSION.equals(jdbcVersion)) {
                        openErrorBox(shell, Messages.errNoSupportDriver, monitor);
                    } else {
                        openErrorBox(shell, Messages.errSelectSupportDriver, monitor);
                    }
                    disConnect();
                    return false;
                }
            }
        } else if (task instanceof GetDatabaseListTask) {
            GetDatabaseListTask getDatabaseListTask = (GetDatabaseListTask) task;
            List<DatabaseInfo> databaseInfoList = getDatabaseListTask.loadDatabaseInfo();
            if (databaseInfoList != null) {
                allDatabaseInfoList.addAll(databaseInfoList);
            }
        } else if (task instanceof GetCMConfParameterTask) {
            GetCMConfParameterTask getCMConfParameterTask = (GetCMConfParameterTask) task;
            Map<String, String> confParameters = getCMConfParameterTask.getConfParameters();
            ServerType serverType = ServerType.BOTH;
            if (confParameters != null) {
                String target = confParameters.get(ConfConstants.CM_TARGET);
                if (target != null) {
                    if (target.indexOf("broker") >= 0 && target.indexOf("server") >= 0) {
                        serverType = ServerType.BOTH;
                    } else if (target.indexOf("broker") >= 0) {
                        serverType = ServerType.BROKER;
                    } else if (target.indexOf("server") >= 0) {
                        serverType = ServerType.DATABASE;
                    }
                }
                String supportMonStatistic = confParameters.get(ConfConstants.SUPPORT_MON_STATISTIC);
                if ("yes".equalsIgnoreCase(supportMonStatistic)) {
                    serverInfo.setSupportMonitorStatistic(true);
                } else {
                    serverInfo.setSupportMonitorStatistic(false);
                }
            }
            if (serverInfo != null) {
                serverInfo.setServerType(serverType);
            }
        } else if (task instanceof CommonQueryTask) {
            @SuppressWarnings("unchecked") CommonQueryTask<BrokerInfos> getBrokerTask = (CommonQueryTask<BrokerInfos>) task;
            brokerInfos = getBrokerTask.getResultModel();
            if (serverInfo != null) {
                serverInfo.setBrokerInfos(brokerInfos);
            }
        } else if (task instanceof GetCMUserListTask) {
            if (serverInfo != null && serverInfo.isConnected()) {
                GetCMUserListTask getUserInfoTask = (GetCMUserListTask) task;
                List<ServerUserInfo> serverUserInfoList = getUserInfoTask.getServerUserInfoList();
                for (int i = 0; serverUserInfoList != null && i < serverUserInfoList.size(); i++) {
                    ServerUserInfo userInfo = serverUserInfoList.get(i);
                    if (userInfo != null && userInfo.getUserName().equals(serverInfo.getUserName())) {
                        serverInfo.setLoginedUserInfo(userInfo);
                        break;
                    }
                }
                List<DatabaseInfo> databaseInfoList = serverInfo.getLoginedUserInfo().getDatabaseInfoList();
                if (databaseInfoList != null) {
                    authDatabaseList.addAll(databaseInfoList);
                }
                isRunUpdateCmUserTask = CubridDatabasesFolderLoader.filterDatabaseList(serverInfo, allDatabaseInfoList, authDatabaseList);
                if (isRunUpdateCmUserTask) {
                    serverInfo.getLoginedUserInfo().setDatabaseInfoList(authDatabaseList);
                }
            }
        } else if (task instanceof GetCubridConfParameterTask) {
            GetCubridConfParameterTask getCubridConfParameterTask = (GetCubridConfParameterTask) task;
            Map<String, Map<String, String>> confParas = getCubridConfParameterTask.getConfParameters();
            if (serverInfo != null) {
                serverInfo.setCubridConfParaMap(confParas);
            }
        } else if (task instanceof GetBrokerConfParameterTask) {
            GetBrokerConfParameterTask getBrokerConfParameterTask = (GetBrokerConfParameterTask) task;
            Map<String, Map<String, String>> confParas = getBrokerConfParameterTask.getConfParameters();
            if (serverInfo != null) {
                serverInfo.setBrokerConfParaMap(confParas);
            }
        }
        if (monitor.isCanceled() || !isContinue) {
            disConnect();
            return false;
        }
    }
    return true;
}
Also used : ServerType(com.cubrid.cubridmanager.core.common.model.ServerType) MonitorDashboardPreference(com.cubrid.cubridmanager.ui.mondashboard.preference.MonitorDashboardPreference) ITask(com.cubrid.common.core.task.ITask) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) BrokerInfos(com.cubrid.cubridmanager.core.broker.model.BrokerInfos) GetCMConfParameterTask(com.cubrid.cubridmanager.core.common.task.GetCMConfParameterTask) UpdateCMUserTask(com.cubrid.cubridmanager.core.common.task.UpdateCMUserTask) CommonQueryTask(com.cubrid.cubridmanager.core.common.task.CommonQueryTask) MonitoringTask(com.cubrid.cubridmanager.core.common.task.MonitoringTask) ArrayList(java.util.ArrayList) List(java.util.List) ServerUserInfo(com.cubrid.cubridmanager.core.common.model.ServerUserInfo) GetCMUserListTask(com.cubrid.cubridmanager.core.common.task.GetCMUserListTask) GetCubridConfParameterTask(com.cubrid.cubridmanager.core.common.task.GetCubridConfParameterTask) GetEnvInfoTask(com.cubrid.cubridmanager.core.common.task.GetEnvInfoTask) GetDatabaseListTask(com.cubrid.cubridmanager.core.cubrid.database.task.GetDatabaseListTask) GetBrokerConfParameterTask(com.cubrid.cubridmanager.core.broker.task.GetBrokerConfParameterTask) Map(java.util.Map) EnvInfo(com.cubrid.cubridmanager.core.common.model.EnvInfo)

Example 19 with MonitoringTask

use of com.cubrid.cubridmanager.core.common.task.MonitoringTask in project cubrid-manager by CUBRID.

the class SetDatabaseInfoPage method modifyText.

/**
	 * @see org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent)
	 * @param event ModifyEvent
	 */
public void modifyText(ModifyEvent event) {
    final String port = portText.getText();
    String password = passwordText.getText();
    String mdbPassword = masteDbaPasswordText.getText();
    String distdbPassword = distDbaPasswordText.getText();
    boolean isValidPort = ValidateUtil.isNumber(port);
    if (isValidPort) {
        int portVal = Integer.parseInt(port);
        if (portVal < 1024 || portVal > 65535) {
            isValidPort = false;
        }
    }
    if (!isValidPort) {
        setErrorMessage(Messages.errInvalidPort);
        setPageComplete(false);
        return;
    }
    boolean isValidPassword = password.length() >= 4 && password.indexOf(" ") < 0;
    if (!isValidPassword) {
        setErrorMessage(Messages.errInvalidPassword);
        setPageComplete(false);
        return;
    }
    boolean isValidMdbPassword = mdbPassword.length() >= 4 && mdbPassword.indexOf(" ") < 0;
    if (!isValidMdbPassword) {
        setErrorMessage(Messages.errInvalidMdbPassword);
        setPageComplete(false);
        return;
    }
    boolean isValidDistdbPassword = distdbPassword.length() >= 4 && distdbPassword.indexOf(" ") < 0;
    if (!isValidDistdbPassword) {
        setErrorMessage(Messages.errInvalidDistdbPassword);
        setPageComplete(false);
        return;
    }
    boolean isValid = isValidPort && isValidPassword && isValidMdbPassword && isValidDistdbPassword;
    setPageComplete(false);
    if (isValid) {
        final String ip = ipText.getText();
        final String userName = userNameText.getText();
        final MonitorDashboardPreference monPref = new MonitorDashboardPreference();
        TaskExecutor taskExcutor = new TaskExecutor() {

            public boolean exec(final IProgressMonitor monitor) {
                Display display = getShell().getDisplay();
                if (monitor.isCanceled()) {
                    return false;
                }
                boolean isConnected = false;
                for (ITask task : taskList) {
                    if (task instanceof MonitoringTask) {
                        MonitoringTask monitoringTask = (MonitoringTask) task;
                        monitoringTask.connectServer(Version.releaseVersion, monPref.getHAHeartBeatTimeout());
                        isConnected = true;
                    } else if (task instanceof LoginDatabaseTask) {
                        task.execute();
                    }
                    final String msg = task.getErrorMsg();
                    if (monitor.isCanceled()) {
                        if (isConnected) {
                            ServerManager.getInstance().setConnected(ip, Integer.parseInt(port), userName, false);
                        }
                        return false;
                    }
                    if (msg != null && msg.length() > 0 && !monitor.isCanceled()) {
                        monitor.done();
                        display.syncExec(new Runnable() {

                            public void run() {
                                setErrorMessage(msg);
                            }
                        });
                        if (isConnected) {
                            ServerManager.getInstance().setConnected(ip, Integer.parseInt(port), userName, false);
                        }
                        return false;
                    }
                }
                if (!monitor.isCanceled()) {
                    if (isConnected) {
                        ServerManager.getInstance().setConnected(ip, Integer.parseInt(port), userName, false);
                    }
                    display.syncExec(new Runnable() {

                        public void run() {
                            setErrorMessage(null);
                            setPageComplete(true);
                        }
                    });
                }
                return true;
            }
        };
        ServerInfo serverInfo = new ServerInfo();
        if (ServerManager.getInstance().isConnected(ip, Integer.parseInt(port), userName)) {
            serverInfo = CMHostNodePersistManager.getInstance().getServerInfo(ip, Integer.parseInt(port), userName);
        } else {
            serverInfo.setHostAddress(ip);
            serverInfo.setHostMonPort(Integer.parseInt(port));
            serverInfo.setHostJSPort(Integer.parseInt(port + 1));
            serverInfo.setUserName(userNameText.getText());
            serverInfo.setUserPassword(password);
            CMHostNodePersistManager.getInstance().addServer(ip, Integer.parseInt(port), userName, serverInfo);
            MonitoringTask monitoringTask = new MonitoringTask(serverInfo);
            taskExcutor.addTask(monitoringTask);
        }
        LoginDatabaseTask loginMDbTask = new LoginDatabaseTask(serverInfo);
        loginMDbTask.setCMUser("admin");
        loginMDbTask.setDbName(masterDbNameText.getText());
        loginMDbTask.setDbUser("dba");
        loginMDbTask.setDbPassword(masteDbaPasswordText.getText());
        taskExcutor.addTask(loginMDbTask);
        LoginDatabaseTask loginDistdbTask = new LoginDatabaseTask(replNode.getServer().getServerInfo());
        loginDistdbTask.setCMUser("admin");
        loginDistdbTask.setDbName(distDbNameText.getText());
        loginDistdbTask.setDbUser("dba");
        loginDistdbTask.setDbPassword(distDbaPasswordText.getText());
        taskExcutor.addTask(loginDistdbTask);
        new ExecTaskWithProgress(taskExcutor).exec(true, true);
    }
}
Also used : MonitorDashboardPreference(com.cubrid.cubridmanager.ui.mondashboard.preference.MonitorDashboardPreference) ITask(com.cubrid.common.core.task.ITask) LoginDatabaseTask(com.cubrid.cubridmanager.core.cubrid.database.task.LoginDatabaseTask) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) MonitoringTask(com.cubrid.cubridmanager.core.common.task.MonitoringTask) Display(org.eclipse.swt.widgets.Display)

Example 20 with MonitoringTask

use of com.cubrid.cubridmanager.core.common.task.MonitoringTask in project cubrid-manager by CUBRID.

the class ReplServerDialog method execute.

/**
	 * excute the task.
	 * 
	 * @param buttonId int
	 */
private void execute(final int buttonId) {
    final String ip = ipText.getText();
    final String port = portText.getText();
    final String userName = userNameText.getText();
    final String password = passwordText.getText();
    final String mdbName = mdbNameText.getText();
    final String replServerPort = replServerPortText.getText();
    TaskExecutor taskExcutor = new TaskExecutor() {

        public void disConnect() {
            ServerManager.getInstance().setConnected(ip, Integer.parseInt(port), userName, false);
        }

        public boolean exec(final IProgressMonitor monitor) {
            Display display = Display.getDefault();
            if (monitor.isCanceled()) {
                return false;
            }
            boolean isConnected = false;
            MonitorDashboardPreference monPref = new MonitorDashboardPreference();
            for (ITask task : taskList) {
                if (task instanceof MonitoringTask) {
                    MonitoringTask monitoringTask = (MonitoringTask) task;
                    monitoringTask.connectServer(Version.releaseVersion, monPref.getHAHeartBeatTimeout());
                    isConnected = true;
                } else if (task instanceof GetReplServerStatusTask) {
                    GetReplServerStatusTask getReplServerStatusTask = (GetReplServerStatusTask) task;
                    getReplServerStatusTask.execute();
                    isActive = getReplServerStatusTask.isActive();
                } else if (task instanceof StartReplServerTask) {
                    if (isActive) {
                        openErrorBox(getShell(), Messages.msgReplServerStarted, monitor);
                    } else {
                        StartReplServerTask startReplServerTask = (StartReplServerTask) task;
                        startReplServerTask.execute();
                        if (task.isSuccess()) {
                            openInformationgBox(getShell(), com.cubrid.cubridmanager.ui.common.Messages.titleSuccess, Messages.msgReplServerStartedSuccess, monitor);
                        }
                    }
                } else if (task instanceof StopReplServerTask) {
                    if (isActive) {
                        StopReplServerTask stopReplServerTask = (StopReplServerTask) task;
                        stopReplServerTask.execute();
                        if (task.isSuccess()) {
                            openInformationgBox(getShell(), com.cubrid.cubridmanager.ui.common.Messages.titleSuccess, Messages.msgReplServerStopedSuccess, monitor);
                        }
                    } else {
                        openErrorBox(getShell(), Messages.msgReplServerStoped, monitor);
                    }
                }
                if (monitor.isCanceled()) {
                    if (isConnected) {
                        disConnect();
                    }
                    return false;
                }
                final String msg = task.getErrorMsg();
                if (openErrorBox(getShell(), msg, monitor)) {
                    if (isConnected) {
                        ServerManager.getInstance().setConnected(ip, Integer.parseInt(port), userName, false);
                    }
                    return false;
                }
            }
            if (isConnected) {
                disConnect();
            }
            if (!monitor.isCanceled()) {
                display.syncExec(new Runnable() {

                    public void run() {
                        setReturnCode(buttonId);
                        close();
                    }
                });
            }
            return true;
        }
    };
    boolean isConnected = ServerManager.getInstance().isConnected(ip, Integer.parseInt(port), userName);
    ServerInfo serverInfo = new ServerInfo();
    if (isConnected) {
        serverInfo = CMHostNodePersistManager.getInstance().getServerInfo(ip, Integer.parseInt(port), userName);
    } else {
        serverInfo.setHostAddress(ip);
        serverInfo.setHostMonPort(Integer.parseInt(port));
        serverInfo.setHostJSPort(Integer.parseInt(port) + 1);
        serverInfo.setUserName(userName);
        serverInfo.setUserPassword(password);
        CMHostNodePersistManager.getInstance().addServer(ip, Integer.parseInt(port), userName, serverInfo);
        MonitoringTask monitoringTask = new MonitoringTask(serverInfo);
        taskExcutor.addTask(monitoringTask);
    }
    GetReplServerStatusTask getReplServerStatusTask = new GetReplServerStatusTask(serverInfo);
    getReplServerStatusTask.setDbName(mdbName);
    taskExcutor.addTask(getReplServerStatusTask);
    if (isStartReplServer) {
        StartReplServerTask task = new StartReplServerTask(serverInfo);
        task.setDbName(mdbName);
        task.setServerPort(replServerPort);
        taskExcutor.addTask(task);
    } else {
        StopReplServerTask task = new StopReplServerTask(serverInfo);
        task.setDbName(mdbName);
        taskExcutor.addTask(task);
    }
    new ExecTaskWithProgress(taskExcutor).exec();
}
Also used : MonitorDashboardPreference(com.cubrid.cubridmanager.ui.mondashboard.preference.MonitorDashboardPreference) ITask(com.cubrid.common.core.task.ITask) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) GetReplServerStatusTask(com.cubrid.cubridmanager.core.replication.task.GetReplServerStatusTask) StopReplServerTask(com.cubrid.cubridmanager.core.replication.task.StopReplServerTask) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) MonitoringTask(com.cubrid.cubridmanager.core.common.task.MonitoringTask) StartReplServerTask(com.cubrid.cubridmanager.core.replication.task.StartReplServerTask) Display(org.eclipse.swt.widgets.Display)

Aggregations

MonitoringTask (com.cubrid.cubridmanager.core.common.task.MonitoringTask)30 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)24 GetDatabaseListTask (com.cubrid.cubridmanager.core.cubrid.database.task.GetDatabaseListTask)17 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)12 ITask (com.cubrid.common.core.task.ITask)11 GetCubridConfParameterTask (com.cubrid.cubridmanager.core.common.task.GetCubridConfParameterTask)11 GetCMUserListTask (com.cubrid.cubridmanager.core.common.task.GetCMUserListTask)10 MonitorDashboardPreference (com.cubrid.cubridmanager.ui.mondashboard.preference.MonitorDashboardPreference)10 GetCMConfParameterTask (com.cubrid.cubridmanager.core.common.task.GetCMConfParameterTask)9 GetEnvInfoTask (com.cubrid.cubridmanager.core.common.task.GetEnvInfoTask)9 TaskGroup (com.cubrid.common.ui.spi.progress.TaskGroup)8 GetBrokerConfParameterTask (com.cubrid.cubridmanager.core.broker.task.GetBrokerConfParameterTask)8 ArrayList (java.util.ArrayList)8 Map (java.util.Map)8 ServerType (com.cubrid.cubridmanager.core.common.model.ServerType)7 ServerUserInfo (com.cubrid.cubridmanager.core.common.model.ServerUserInfo)7 UpdateCMUserTask (com.cubrid.cubridmanager.core.common.task.UpdateCMUserTask)7 HostNode (com.cubrid.cubridmanager.ui.replication.editor.model.HostNode)7 IStatus (org.eclipse.core.runtime.IStatus)6 Status (org.eclipse.core.runtime.Status)6