Search in sources :

Example 11 with MonitoringTask

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

the class CreateReplicationJobExecutor method createDistributor.

/**
	 * create distributor database
	 * 
	 * @param dbName String
	 * @param monitor IProgressMonitor
	 * @param taskList List<ITask>
	 * @return status
	 */
private IStatus createDistributor(String dbName, final IProgressMonitor monitor, List<ITask> taskList) {
    monitor.subTask(Messages.bind(Messages.createDistJobName, dbName));
    Display display = Display.getDefault();
    MonitoringTask monitoringTask = null;
    boolean isExecuteStopDbTask = true;
    MonitorDashboardPreference monPref = new MonitorDashboardPreference();
    for (ITask task : taskList) {
        if (task instanceof MonitoringTask) {
            monitoringTask = (MonitoringTask) task;
            ServerInfo serverInfo = monitoringTask.getServerInfo();
            CMHostNodePersistManager.getInstance().addServer(serverInfo.getHostAddress(), serverInfo.getHostMonPort(), serverInfo.getUserName(), serverInfo);
            monitoringTask.connectServer(Version.releaseVersion, monPref.getHAHeartBeatTimeout());
        } else if (task instanceof CommonUpdateTask && task.getTaskname().equals(CommonTaskName.STOP_DB_TASK_NAME)) {
            if (isDeleteDb && isExecuteStopDbTask) {
                task.execute();
            } else {
                continue;
            }
        } else if (task instanceof CommonUpdateTask && task.getTaskname().equals(CommonTaskName.DELETE_DATABASE_TASK_NAME)) {
            if (isDeleteDb) {
                task.execute();
            } else {
                continue;
            }
        } else {
            task.execute();
        }
        if (monitor.isCanceled()) {
            disConnect(monitoringTask);
            return Status.CANCEL_STATUS;
        }
        final String msg = task.getErrorMsg();
        if (msg != null && msg.length() > 0 && !monitor.isCanceled()) {
            disConnect(monitoringTask);
            return new Status(IStatus.ERROR, CubridManagerUIPlugin.PLUGIN_ID, msg);
        }
        if (task instanceof GetDatabaseListTask) {
            GetDatabaseListTask getDatabaseListTask = (GetDatabaseListTask) task;
            final String distdbName = (String) getDatabaseListTask.getData("dbName");
            List<DatabaseInfo> dbInfoList = getDatabaseListTask.loadDatabaseInfo();
            boolean isDbExist = false;
            for (int i = 0; i < dbInfoList.size(); i++) {
                DatabaseInfo dbInfo = dbInfoList.get(i);
                if (dbName.equalsIgnoreCase(dbInfo.getDbName())) {
                    isDbExist = true;
                    display.syncExec(new Runnable() {

                        public void run() {
                            isDeleteDb = CommonUITool.openConfirmBox(Messages.bind(Messages.msgConfirmDeleteDb, distdbName));
                        }
                    });
                    if (dbInfo.getRunningType() == DbRunningType.CS) {
                        isExecuteStopDbTask = true;
                    }
                    break;
                }
            }
            if (isDbExist && !isDeleteDb) {
                disConnect(monitoringTask);
                return Status.CANCEL_STATUS;
            }
        }
    }
    disConnect(monitoringTask);
    isDeleteDb = false;
    return Status.OK_STATUS;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) MonitorDashboardPreference(com.cubrid.cubridmanager.ui.mondashboard.preference.MonitorDashboardPreference) ITask(com.cubrid.common.core.task.ITask) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) GetDatabaseListTask(com.cubrid.cubridmanager.core.cubrid.database.task.GetDatabaseListTask) MonitoringTask(com.cubrid.cubridmanager.core.common.task.MonitoringTask) CommonUpdateTask(com.cubrid.cubridmanager.core.common.task.CommonUpdateTask) Display(org.eclipse.swt.widgets.Display)

Example 12 with MonitoringTask

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

the class CreateReplicationJobExecutor method startReplServer.

/**
	 * start replication server
	 * 
	 * @param serverName String
	 * @param monitor IProgressMonitor
	 * @param taskList List<ITask
	 * @return status
	 */
private IStatus startReplServer(String serverName, final IProgressMonitor monitor, List<ITask> taskList) {
    monitor.subTask(Messages.bind(Messages.startReplServerJobName, serverName));
    MonitoringTask monitoringTask = null;
    MonitorDashboardPreference monPref = new MonitorDashboardPreference();
    for (ITask task : taskList) {
        if (task instanceof MonitoringTask) {
            monitoringTask = (MonitoringTask) task;
            ServerInfo serverInfo = monitoringTask.getServerInfo();
            CMHostNodePersistManager.getInstance().addServer(serverInfo.getHostAddress(), serverInfo.getHostMonPort(), serverInfo.getUserName(), serverInfo);
            monitoringTask.connectServer(Version.releaseVersion, monPref.getHAHeartBeatTimeout());
        } else {
            task.execute();
        }
        if (monitor.isCanceled()) {
            disConnect(monitoringTask);
            return Status.CANCEL_STATUS;
        }
        final String msg = task.getErrorMsg();
        if (msg != null && msg.length() > 0 && !monitor.isCanceled()) {
            disConnect(monitoringTask);
            return new Status(IStatus.ERROR, CubridManagerUIPlugin.PLUGIN_ID, msg);
        }
    }
    disConnect(monitoringTask);
    return Status.OK_STATUS;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) MonitorDashboardPreference(com.cubrid.cubridmanager.ui.mondashboard.preference.MonitorDashboardPreference) ITask(com.cubrid.common.core.task.ITask) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) MonitoringTask(com.cubrid.cubridmanager.core.common.task.MonitoringTask)

Example 13 with MonitoringTask

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

the class SetHostInfoDialog method connect.

/**
	 * connect the host
	 * 
	 * @param buttonId int
	 */
private void connect(final int buttonId) {
    final String ip = ipText.getText();
    final String port = portText.getText();
    final String userName = userNameText.getText();
    final String password = passwordText.getText();
    boolean isConnected = ServerManager.getInstance().isConnected(ip, Integer.parseInt(port), userName);
    if (isConnected && hostInfo != null) {
        ServerInfo serverInfo = CMHostNodePersistManager.getInstance().getServerInfo(ip, Integer.parseInt(port), userName);
        if (!serverInfo.getLoginedUserInfo().isAdmin()) {
            CommonUITool.openErrorBox(Messages.bind(Messages.errInvalidUser, ip));
            return;
        }
        hostInfo.setIp(ip);
        hostInfo.setPort(port);
        hostInfo.setUserName(userName);
        hostInfo.setPassword(password);
        hostInfo.setName(ip + ":" + port);
        List<DatabaseInfo> databaseInfoList = serverInfo.getLoginedUserInfo().getDatabaseInfoList();
        hostInfo.setDatabaseInfoList(databaseInfoList);
        hostInfo.setDbPath(serverInfo.getEnvInfo().getDatabaseDir());
        hostInfo.setOsInfoType(serverInfo.getServerOsInfo());
        setReturnCode(buttonId);
        close();
        return;
    }
    if (!isConnected) {
        final ServerInfo serverInfo = new ServerInfo();
        serverInfo.setHostAddress(ip);
        serverInfo.setHostMonPort(Integer.parseInt(port));
        serverInfo.setHostJSPort(Integer.parseInt(port) + 1);
        serverInfo.setUserName(userName);
        serverInfo.setUserPassword(password);
        TaskExecutor taskExcutor = new ConnectHostTaskExecutor(serverInfo, buttonId);
        MonitoringTask monitoringTask = new MonitoringTask(serverInfo);
        taskExcutor.addTask(monitoringTask);
        GetEnvInfoTask getEnvInfoTask = new GetEnvInfoTask(serverInfo);
        taskExcutor.addTask(getEnvInfoTask);
        GetCMConfParameterTask getCMConfParameterTask = new GetCMConfParameterTask(serverInfo);
        taskExcutor.addTask(getCMConfParameterTask);
        GetDatabaseListTask getDatabaseListTask = new GetDatabaseListTask(serverInfo);
        taskExcutor.addTask(getDatabaseListTask);
        new ExecTaskWithProgress(taskExcutor).exec(true, true);
    }
}
Also used : GetDatabaseListTask(com.cubrid.cubridmanager.core.cubrid.database.task.GetDatabaseListTask) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) GetCMConfParameterTask(com.cubrid.cubridmanager.core.common.task.GetCMConfParameterTask) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) MonitoringTask(com.cubrid.cubridmanager.core.common.task.MonitoringTask) GetEnvInfoTask(com.cubrid.cubridmanager.core.common.task.GetEnvInfoTask)

Example 14 with MonitoringTask

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

the class SetupEnvTestCase method setupDatabaseInfo831.

/**
	 * * Setup database 8.3.1
	 *
	 */
private void setupDatabaseInfo831() {
    /*Setting Cubrid 8.3.1*/
    serverInfo831 = new ServerInfo();
    serverInfo831.setHostAddress(host831);
    serverInfo831.setHostMonPort(monport831);
    serverInfo831.setHostJSPort(jpport831);
    serverInfo831.setUserName(userName831);
    serverInfo831.setUserPassword(passwd831);
    serverInfo831.setJdbcDriverVersion(serverVersion831);
    ServerManager.getInstance().addServer(host831, monport831, userName831, serverInfo831);
    MonitoringTask monTask = new MonitoringTask(serverInfo831);
    serverInfo831 = monTask.connectServer(serverVersion831, 1000);
    // get the latest token
    token831 = serverInfo831.getHostToken();
    //get evnInfo
    if (envInfo831 == null) {
        GetEnvInfoTask envTask = new GetEnvInfoTask(serverInfo831);
        envTask.loadEnvInfo();
        envTask.execute();
        envInfo831 = envTask.loadEnvInfo();
        serverInfo831.setEnvInfo(envInfo831);
    }
    assertNotNull(envInfo831);
    serverPath831 = envInfo831.getRootDir();
    dbRootDir831 = envInfo831.getDatabaseDir();
    //get server type
    GetCMConfParameterTask getCMConfParameterTask = new GetCMConfParameterTask(serverInfo831);
    getCMConfParameterTask.execute();
    assertEquals(null, getCMConfParameterTask.getErrorMsg());
    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;
            }
        }
    }
    if (serverInfo831 != null) {
        serverInfo831.setServerType(serverType);
    }
    //Get database list task
    if (serverType == ServerType.DATABASE || serverType == ServerType.BOTH) {
        final GetDatabaseListTask getDatabaseListTask = new GetDatabaseListTask(serverInfo831);
        getDatabaseListTask.execute();
        assertEquals(null, getDatabaseListTask.getErrorMsg());
        List<DatabaseInfo> databaseInfoList = getDatabaseListTask.loadDatabaseInfo();
        for (DatabaseInfo dbInfo : databaseInfoList) {
            if (dbInfo.getDbName().equals(testDbName831)) {
                databaseInfo831 = dbInfo;
                break;
            }
        }
        if (databaseInfo831 == null) {
            return;
        }
    }
    //get CubridManager user list task
    GetCMUserListTask getUserInfoTask = new GetCMUserListTask(serverInfo831);
    getUserInfoTask.execute();
    assertEquals(null, getUserInfoTask.getErrorMsg());
    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(serverInfo831.getUserName())) {
            serverInfo831.setLoginedUserInfo(userInfo);
            break;
        }
    }
    List<DatabaseInfo> databaseInfoList = serverInfo831.getLoginedUserInfo().getDatabaseInfoList();
    String dbDir = databaseInfo831.getDbDir();
    DbRunningType type = databaseInfo831.getRunningType();
    for (int i = 0; databaseInfoList != null && i < databaseInfoList.size(); i++) {
        if (testDbName831.equalsIgnoreCase(databaseInfoList.get(i).getDbName())) {
            databaseInfo831 = databaseInfoList.get(i);
            databaseInfo831.setDbDir(dbDir);
            databaseInfo831.setBrokerIP(host831);
            databaseInfo831.setBrokerPort(port831);
            databaseInfo831.setCharSet(charset831);
            databaseInfo831.setRunningType(type);
            break;
        }
    }
    //get CUBRID conf parameter
    GetCubridConfParameterTask getCubridConfParameterTask = new GetCubridConfParameterTask(serverInfo831);
    getCubridConfParameterTask.execute();
    assertEquals(null, getCubridConfParameterTask.getErrorMsg());
    Map<String, Map<String, String>> confParas = getCubridConfParameterTask.getConfParameters();
    if (serverInfo831 != null) {
        serverInfo831.setCubridConfParaMap(confParas);
    }
    //get broker Info
    GetBrokerConfParameterTask getBrokerConfParameterTask = new GetBrokerConfParameterTask(serverInfo831);
    getBrokerConfParameterTask.execute();
    assertEquals(null, getBrokerConfParameterTask.getErrorMsg());
    confParas = getBrokerConfParameterTask.getConfParameters();
    if (serverInfo831 != null) {
        serverInfo831.setBrokerConfParaMap(confParas);
    }
    //Set JDBC driver
    String filePath = this.getFilePathInPlugin("/lib/JDBC-8.3.0.1004-cubrid.jar");
    if (filePath != null) {
        String version = JdbcClassLoaderFactory.validateJdbcFile(filePath);
        if (version != null) {
            JdbcClassLoaderFactory.registerClassLoader(filePath);
            serverInfo831.setJdbcDriverVersion(version);
        }
    }
    filePath = this.getFilePathInPlugin("/lib/JDBC-8.3.1.0173-cubrid.jar");
    if (filePath != null) {
        String version = JdbcClassLoaderFactory.validateJdbcFile(filePath);
        if (version != null) {
            JdbcClassLoaderFactory.registerClassLoader(filePath);
            serverInfo831.setJdbcDriverVersion(version);
        }
    }
}
Also used : ServerType(com.cubrid.cubridmanager.core.common.model.ServerType) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) 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) GetCMConfParameterTask(com.cubrid.cubridmanager.core.common.task.GetCMConfParameterTask) MonitoringTask(com.cubrid.cubridmanager.core.common.task.MonitoringTask) ServerUserInfo(com.cubrid.cubridmanager.core.common.model.ServerUserInfo) GetBrokerConfParameterTask(com.cubrid.cubridmanager.core.broker.task.GetBrokerConfParameterTask) DbRunningType(com.cubrid.cubridmanager.core.common.model.DbRunningType) HashMap(java.util.HashMap) Map(java.util.Map)

Example 15 with MonitoringTask

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

the class DataProvider method setDefaultValue.

/**
	 * 
	 * Set the default value
	 * 
	 */
private void setDefaultValue() {
    boolean isOldExecuteHostStatTask = isExecuteHostStatTask;
    isExecuteHostStatTask = false;
    isExecuteHeartbeatTask = false;
    isExecuteBrokerStatTask = false;
    isExecuteDbModeTask = false;
    errorMsg = "";
    getHeartbeatNodeInfoTask = null;
    hostNodeList.clear();
    connectedHostNode = null;
    uniqueDbNodeList.clear();
    uniqueBrokerNodeList.clear();
    List<DataUpdateListener> listenerList = generator.getListeners();
    for (DataUpdateListener listener : listenerList) {
        addHaNode(listener.getModel());
    }
    if (connectedHostNode == null && !hostNodeList.isEmpty()) {
        connectedHostNode = hostNodeList.get(0);
    }
    if (connectedHostNode == null) {
        return;
    }
    filterDatabaseDataProvider();
    if (!uniqueBrokerNodeList.isEmpty()) {
        brokerDataProvider.setDataGenerator(generator);
        brokerDataProvider.setBrokerNodeList(uniqueBrokerNodeList);
    }
    //Connect host and set time out
    if (!connectedHostNode.isConnected() && !connectedHostNode.isConnecting()) {
        for (final HostNode hostNode : hostNodeList) {
            Display.getDefault().syncExec(new Runnable() {

                public void run() {
                    hostNode.setConnected(false);
                }
            });
        }
        ConnectionManager.connectHost(connectedHostNode, true, !isFirstConnected);
    }
    final boolean isCanConnected = connectedHostNode.isConnected();
    for (final HostNode hostNode : hostNodeList) {
        if (hostNode != connectedHostNode) {
            Display.getDefault().syncExec(new Runnable() {

                public void run() {
                    hostNode.setConnected(isCanConnected);
                    hostNode.setErrorMsg(connectedHostNode.getLastErrorMsg());
                }
            });
        }
    }
    if (isCanConnected) {
        isFirstConnected = true;
        serverInfo = connectedHostNode.getServerInfo();
        if (serverInfo != null) {
            MonitoringTask monitoringTask = serverInfo.getMonitoringTask();
            monitoringTask.setTimeout(DataProvider.TIME_OUT_MILL);
        }
    } else {
        isFirstConnected = false;
    }
    for (DataUpdateListener listener : listenerList) {
        if (listener instanceof HostMonitorPartHelper) {
            isExecuteHostStatTask = isCanConnected;
            isExecuteHeartbeatTask = isCanConnected;
        } else if (listener instanceof DatabaseMonitorPartHelper) {
            isExecuteHostStatTask = isCanConnected;
            isExecuteHeartbeatTask = isCanConnected;
            isExecuteDbModeTask = isCanConnected;
        } else if (listener instanceof HostDashboardViewPart) {
            isExecuteHostStatTask = isCanConnected;
            isExecuteBrokerStatTask = isCanConnected;
        } else if (listener instanceof DatabaseDashboardViewPart) {
            isExecuteHostStatTask = isCanConnected;
            isExecuteHeartbeatTask = isCanConnected;
            isExecuteDbModeTask = isCanConnected;
        }
    }
    ServerType serverType = serverInfo == null ? null : serverInfo.getServerType();
    isExecuteBrokerStatTask = isExecuteBrokerStatTask && (serverType == ServerType.BOTH || serverType == ServerType.BROKER);
    if (isOldExecuteHostStatTask != isExecuteHostStatTask) {
        hostStatRequestCount = 0;
    }
}
Also used : HostMonitorPartHelper(com.cubrid.cubridmanager.ui.mondashboard.editor.parts.helper.HostMonitorPartHelper) ServerType(com.cubrid.cubridmanager.core.common.model.ServerType) DatabaseMonitorPartHelper(com.cubrid.cubridmanager.ui.mondashboard.editor.parts.helper.DatabaseMonitorPartHelper) HostNode(com.cubrid.cubridmanager.ui.mondashboard.editor.model.HostNode) MonitoringTask(com.cubrid.cubridmanager.core.common.task.MonitoringTask) HostDashboardViewPart(com.cubrid.cubridmanager.ui.mondashboard.editor.HostDashboardViewPart) DatabaseDashboardViewPart(com.cubrid.cubridmanager.ui.mondashboard.editor.DatabaseDashboardViewPart)

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