Search in sources :

Example 1 with StartReplServerTask

use of com.cubrid.cubridmanager.core.replication.task.StartReplServerTask 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)

Example 2 with StartReplServerTask

use of com.cubrid.cubridmanager.core.replication.task.StartReplServerTask in project cubrid-manager by CUBRID.

the class CreateReplicationUtil method createReplServerTaskGroup.

/**
	 * 
	 * Fill in the related tasks of replication server to executor
	 * 
	 * @param master MasterNode
	 * @param executor CreateReplicationJobExecutor
	 * @return null or error message
	 */
public static String createReplServerTaskGroup(MasterNode master, CreateReplicationJobExecutor executor) {
    TaskGroup taskGroup = new TaskGroup(IConstants.REPL_GROUP_NAME_START_REPL_SERVER);
    taskGroup.setTarget(master.getDbName());
    HostNode masterHost = (HostNode) master.getParent();
    final String ip = masterHost.getIp();
    final String port = masterHost.getPort();
    final String userName = masterHost.getUserName();
    final String password = masterHost.getPassword();
    boolean isConnected = ServerManager.getInstance().isConnected(ip, Integer.parseInt(port), userName);
    ServerInfo serverInfo = new ServerInfo();
    if (isConnected) {
        serverInfo = ServerManager.getInstance().getServer(ip, Integer.parseInt(port), userName);
        if (!serverInfo.getLoginedUserInfo().isAdmin()) {
            return Messages.bind(Messages.errInvalidUser, ip);
        }
    } else {
        serverInfo.setHostAddress(ip);
        serverInfo.setHostMonPort(Integer.parseInt(port));
        serverInfo.setHostJSPort(Integer.parseInt(port) + 1);
        serverInfo.setUserName(userName);
        serverInfo.setUserPassword(password);
        MonitoringTask monitoringTask = new MonitoringTask(serverInfo);
        taskGroup.addTask(monitoringTask);
    }
    StartReplServerTask startReplServerTask = new StartReplServerTask(serverInfo);
    startReplServerTask.setDbName(master.getDbName());
    startReplServerTask.setServerPort(master.getReplServerPort());
    taskGroup.addTask(startReplServerTask);
    executor.addGroupTask(taskGroup);
    return null;
}
Also used : ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) HostNode(com.cubrid.cubridmanager.ui.replication.editor.model.HostNode) MonitoringTask(com.cubrid.cubridmanager.core.common.task.MonitoringTask) StartReplServerTask(com.cubrid.cubridmanager.core.replication.task.StartReplServerTask) TaskGroup(com.cubrid.common.ui.spi.progress.TaskGroup)

Aggregations

ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)2 MonitoringTask (com.cubrid.cubridmanager.core.common.task.MonitoringTask)2 StartReplServerTask (com.cubrid.cubridmanager.core.replication.task.StartReplServerTask)2 ITask (com.cubrid.common.core.task.ITask)1 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)1 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)1 TaskGroup (com.cubrid.common.ui.spi.progress.TaskGroup)1 GetReplServerStatusTask (com.cubrid.cubridmanager.core.replication.task.GetReplServerStatusTask)1 StopReplServerTask (com.cubrid.cubridmanager.core.replication.task.StopReplServerTask)1 MonitorDashboardPreference (com.cubrid.cubridmanager.ui.mondashboard.preference.MonitorDashboardPreference)1 HostNode (com.cubrid.cubridmanager.ui.replication.editor.model.HostNode)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 Display (org.eclipse.swt.widgets.Display)1