Search in sources :

Example 21 with GetCubridConfParameterTask

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

the class RenameDatabaseDialog method renameDb.

/**
	 * Execute task and rename database
	 */
private void renameDb() {
    newDBName = databaseNameText.getText();
    isCanFinished = true;
    TaskJobExecutor taskExec = new TaskJobExecutor() {

        public IStatus exec(final IProgressMonitor monitor) {
            Display.getDefault().syncExec(new Runnable() {

                public void run() {
                    getShell().setVisible(false);
                }
            });
            if (monitor.isCanceled()) {
                cancel();
                Display.getDefault().syncExec(new Runnable() {

                    public void run() {
                        close();
                    }
                });
                return Status.CANCEL_STATUS;
            }
            List<String> cubridConfContentList = null;
            for (ITask task : taskList) {
                if (task instanceof SetCubridConfParameterTask) {
                    if (cubridConfContentList == null) {
                        LOGGER.warn("cubridConfContentList is null. Skip SetCubridConfParameterTask.");
                        continue;
                    }
                    SetCubridConfParameterTask setParaTask = (SetCubridConfParameterTask) task;
                    setParaTask.setConfContents(cubridConfContentList);
                }
                task.execute();
                final String msg = task.getErrorMsg();
                if (msg != null && msg.length() > 0 && !monitor.isCanceled() && !isCanceled()) {
                    Display.getDefault().syncExec(new Runnable() {

                        public void run() {
                            getShell().setVisible(true);
                        }
                    });
                    return new Status(IStatus.ERROR, CubridManagerUIPlugin.PLUGIN_ID, msg);
                }
                if (isCanceled()) {
                    return Status.CANCEL_STATUS;
                }
                if (task instanceof CheckDirTask) {
                    CheckDirTask checkDirTask = (CheckDirTask) task;
                    final String[] dirs = checkDirTask.getNoExistDirectory();
                    if (dirs != null && dirs.length > 0) {
                        Display.getDefault().syncExec(new Runnable() {

                            public void run() {
                                CreateDirDialog dialog = new CreateDirDialog(getShell());
                                dialog.setDirs(dirs);
                                if (dialog.open() != IDialogConstants.OK_ID) {
                                    isCanFinished = false;
                                }
                            }
                        });
                    }
                } else if (task instanceof GetCubridConfParameterTask) {
                    GetCubridConfParameterTask getCubridConfParameterTask = (GetCubridConfParameterTask) task;
                    cubridConfContentList = CoreUtils.renameDatabaseFromServiceServer(getCubridConfParameterTask, cubridConfContentList, database.getName(), newDBName);
                }
                if (!isCanFinished || monitor.isCanceled()) {
                    cancel();
                    Display.getDefault().syncExec(new Runnable() {

                        public void run() {
                            close();
                        }
                    });
                    return Status.CANCEL_STATUS;
                }
            }
            return Status.OK_STATUS;
        }

        public void done(IJobChangeEvent event) {
            if (event.getResult() == Status.OK_STATUS) {
                Display.getDefault().syncExec(new Runnable() {

                    public void run() {
                        iUpdateUIWithJob.completeAll();
                        close();
                    }
                });
            }
        }
    };
    CheckDirTask checkDirTask = new CheckDirTask(database.getServer().getServerInfo());
    RenameDbTask renameDbTask = new RenameDbTask(database.getServer().getServerInfo());
    renameDbTask.setDbName(database.getLabel());
    renameDbTask.setNewDbName(newDBName);
    if (exVolumePathButton.getSelection()) {
        checkDirTask.setDirectory(new String[] { exVolumePathText.getText() });
        renameDbTask.setExVolumePath(exVolumePathText.getText());
        renameDbTask.setAdvanced(false);
    } else if (renameVolumeButton.getSelection()) {
        List<String> pathList = new ArrayList<String>();
        List<String> volumeChangedList = new ArrayList<String>();
        for (int i = 0; spaceInfoList != null && i < spaceInfoList.size(); i++) {
            Map<String, String> map = spaceInfoList.get(i);
            String oldName = map.get("0");
            String newName = map.get("1");
            String oldPath = map.get("2");
            String newPath = map.get("3");
            addVolumePath(pathList, newPath);
            oldPath = oldPath.replaceAll(":", "|");
            newPath = newPath.replaceAll(":", "|");
            volumeChangedList.add(oldPath + "/" + oldName + ":" + newPath + "/" + newName);
        }
        String[] checkedDirs = new String[pathList.size()];
        pathList.toArray(checkedDirs);
        checkDirTask.setDirectory(checkedDirs);
        renameDbTask.setAdvanced(true);
        renameDbTask.setIndividualVolume(volumeChangedList);
    }
    if (forceDelBackupVolumeButton.getSelection()) {
        renameDbTask.setForceDel(true);
    } else {
        renameDbTask.setForceDel(false);
    }
    taskExec.addTask(renameDbTask);
    GetCubridConfParameterTask getCubridConfParameterTask = new GetCubridConfParameterTask(database.getServer().getServerInfo());
    taskExec.addTask(getCubridConfParameterTask);
    SetCubridConfParameterTask setCubridConfParameterTask = new SetCubridConfParameterTask(database.getServer().getServerInfo());
    taskExec.addTask(setCubridConfParameterTask);
    JobFamily jobFamily = new JobFamily();
    String serverName = database.getServer().getName();
    String dbName = database.getName();
    jobFamily.setServerName(serverName);
    jobFamily.setDbName(dbName);
    String jobName = Messages.msgRenameDBRearJobName + " - " + dbName + "@" + serverName;
    taskExec.schedule(jobName, jobFamily, true, Job.SHORT);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) TaskJobExecutor(com.cubrid.common.ui.spi.progress.TaskJobExecutor) ITask(com.cubrid.common.core.task.ITask) SetCubridConfParameterTask(com.cubrid.cubridmanager.core.common.task.SetCubridConfParameterTask) RenameDbTask(com.cubrid.cubridmanager.core.cubrid.database.task.RenameDbTask) GetCubridConfParameterTask(com.cubrid.cubridmanager.core.common.task.GetCubridConfParameterTask) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) JobFamily(com.cubrid.common.ui.spi.progress.JobFamily) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) List(java.util.List) ArrayList(java.util.ArrayList) DbSpaceInfoList(com.cubrid.cubridmanager.core.cubrid.dbspace.model.DbSpaceInfoList) CheckDirTask(com.cubrid.cubridmanager.core.cubrid.database.task.CheckDirTask) Map(java.util.Map) HashMap(java.util.HashMap)

Example 22 with GetCubridConfParameterTask

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

the class DeleteDatabaseDialog method deleteDatabase.

/**
	 * 
	 * Delete the database
	 * 
	 * @return <code>true</code> if successful;<code>false</code> otherwise
	 */
private boolean deleteDatabase() {
    TaskExecutor taskExcutor = new TaskExecutor() {

        public boolean exec(final IProgressMonitor monitor) {
            if (monitor.isCanceled()) {
                return false;
            }
            String taskName = Messages.bind(Messages.delDbTaskName, database.getName());
            monitor.beginTask(taskName, IProgressMonitor.UNKNOWN);
            boolean isActiveReplServer = false;
            boolean isActiveReplAgent = false;
            List<String> cubridConfContentList = null;
            for (ITask task : taskList) {
                if (task instanceof GetReplServerStatusTask) {
                    GetReplServerStatusTask getReplServerStatusTask = (GetReplServerStatusTask) task;
                    getReplServerStatusTask.execute();
                    isActiveReplServer = getReplServerStatusTask.isActive();
                } else if (task instanceof StopReplServerTask) {
                    if (isActiveReplServer) {
                        task.execute();
                    }
                } else if (task instanceof GetReplAgentStatusTask) {
                    GetReplAgentStatusTask getReplAgentStatusTask = (GetReplAgentStatusTask) task;
                    getReplAgentStatusTask.execute();
                    isActiveReplAgent = getReplAgentStatusTask.isActive();
                } else if (task instanceof StopReplicationAgentTask) {
                    if (isActiveReplAgent) {
                        task.execute();
                    }
                } else if (task instanceof SetCubridConfParameterTask) {
                    if (cubridConfContentList == null) {
                        continue;
                    } else {
                        SetCubridConfParameterTask setParaTask = (SetCubridConfParameterTask) task;
                        setParaTask.setConfContents(cubridConfContentList);
                        setParaTask.execute();
                    }
                } else {
                    task.execute();
                }
                final String msg = task.getErrorMsg();
                if (openErrorBox(getShell(), msg, monitor)) {
                    return false;
                }
                if (monitor.isCanceled()) {
                    return false;
                }
                if (task instanceof GetCubridConfParameterTask) {
                    GetCubridConfParameterTask getCubridConfParameterTask = (GetCubridConfParameterTask) task;
                    cubridConfContentList = CoreUtils.deleteDatabaseFromServiceServer(getCubridConfParameterTask, cubridConfContentList, database.getName());
                }
            }
            return true;
        }
    };
    ServerInfo serverInfo = database.getServer().getServerInfo();
    //check the replication server and agent
    if (serverInfo.isSupportReplication() == 0) {
        if (database.isDistributorDb()) {
            GetReplAgentStatusTask getReplAgentStatusTask = new GetReplAgentStatusTask(serverInfo);
            getReplAgentStatusTask.setDbName(database.getLabel());
            taskExcutor.addTask(getReplAgentStatusTask);
            StopReplicationAgentTask stopReplAgentTask = new StopReplicationAgentTask(serverInfo);
            stopReplAgentTask.setDbName(database.getLabel());
            taskExcutor.addTask(stopReplAgentTask);
        } else {
            GetReplServerStatusTask getReplServerStatusTask = new GetReplServerStatusTask(serverInfo);
            getReplServerStatusTask.setDbName(database.getLabel());
            taskExcutor.addTask(getReplServerStatusTask);
            StopReplServerTask stopReplServerTask = new StopReplServerTask(serverInfo);
            stopReplServerTask.setDbName(database.getLabel());
            taskExcutor.addTask(stopReplServerTask);
        }
    }
    CommonUpdateTask deleteDbtask = new CommonUpdateTask(CommonTaskName.DELETE_DATABASE_TASK_NAME, serverInfo, CommonSendMsg.getDeletedbSendMsg());
    deleteDbtask.setDbName(database.getName());
    if (deleteBackupVolumesButton.getSelection()) {
        deleteDbtask.setDelbackup(YesNoType.Y);
    } else {
        deleteDbtask.setDelbackup(YesNoType.N);
    }
    taskExcutor.addTask(deleteDbtask);
    GetCubridConfParameterTask getCubridConfParameterTask = new GetCubridConfParameterTask(serverInfo);
    taskExcutor.addTask(getCubridConfParameterTask);
    SetCubridConfParameterTask setCubridConfParameterTask = new SetCubridConfParameterTask(serverInfo);
    taskExcutor.addTask(setCubridConfParameterTask);
    new ExecTaskWithProgress(taskExcutor).exec(true, false);
    if (taskExcutor.isSuccess()) {
        setReturnCode(DELETE_ID);
        close();
        return true;
    } else {
        return false;
    }
}
Also used : ITask(com.cubrid.common.core.task.ITask) GetReplAgentStatusTask(com.cubrid.cubridmanager.core.replication.task.GetReplAgentStatusTask) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) StopReplicationAgentTask(com.cubrid.cubridmanager.core.replication.task.StopReplicationAgentTask) SetCubridConfParameterTask(com.cubrid.cubridmanager.core.common.task.SetCubridConfParameterTask) GetCubridConfParameterTask(com.cubrid.cubridmanager.core.common.task.GetCubridConfParameterTask) 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) CommonUpdateTask(com.cubrid.cubridmanager.core.common.task.CommonUpdateTask)

Example 23 with GetCubridConfParameterTask

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

the class CreateReplicationJobExecutor method createMaster.

/**
	 * create master database
	 * 
	 * @param dbName String
	 * @param monitor IProgressMonitor
	 * @param taskList List<ITask>
	 * @return status
	 */
private IStatus createMaster(final String dbName, final IProgressMonitor monitor, List<ITask> taskList) {
    monitor.subTask(Messages.bind(Messages.createMasterJobName, dbName));
    Display display = Display.getDefault();
    MonitoringTask monitoringTask = null;
    boolean isExecuteSetParaTask = true;
    boolean isExecuteStopDbTask = true;
    boolean isExecuteStartDbTask = false;
    Map<String, Map<String, String>> confParaMaps = 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 if (task instanceof StopReplServerTask) {
            if (isExecuteStopReplServerTask) {
                task.execute();
            } else {
                continue;
            }
        } else if (task instanceof SetCubridConfParameterTask) {
            if (isExecuteSetParaTask) {
                SetCubridConfParameterTask setCubridConfParameterTask = (SetCubridConfParameterTask) task;
                setCubridConfParameterTask.setConfParameters(confParaMaps);
                task.execute();
            } else {
                continue;
            }
        } else if (task instanceof CommonUpdateTask && task.getTaskname().equals(CommonTaskName.STOP_DB_TASK_NAME)) {
            if (isExecuteStopDbTask) {
                task.execute();
            } else {
                continue;
            }
        } else if (task instanceof CommonUpdateTask && task.getTaskname().equals(CommonTaskName.START_DB_TASK_NAME)) {
            if (isExecuteStartDbTask) {
                task.execute();
            } else {
                continue;
            }
        } else if (task instanceof GetTransferProgressTask) {
            GetTransferProgressTask getTransferProgressTask = (GetTransferProgressTask) task;
            monitor.subTask(Messages.transFileJobName);
            if (pid != null) {
                while (!isCanceled()) {
                    getTransferProgressTask.setPid(pid);
                    getTransferProgressTask.execute();
                    TransFileProgressInfo progressInfo = getTransferProgressTask.getProgressInfo();
                    if (getTransferProgressTask.isSuccess() && progressInfo != null) {
                        String transferStatus = progressInfo.getTransferStatus();
                        String transferNote = progressInfo.getTransferNote();
                        if (transferStatus != null && transferStatus.equals("success")) {
                            pid = null;
                            cancelTransFileTask = null;
                            break;
                        } else if (transferStatus != null && transferStatus.equals("failure")) {
                            pid = null;
                            cancelTransFileTask = null;
                            getTransferProgressTask.setErrorMsg(transferNote);
                            break;
                        } else {
                            try {
                                Thread.sleep(1000);
                            } catch (InterruptedException e) {
                                e.printStackTrace();
                            }
                        }
                    } else {
                        break;
                    }
                }
            }
        } else if (task instanceof CancelTransFileTask) {
            cancelTransFileTask = (CancelTransFileTask) task;
        } 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 GetReplServerStatusTask) {
            GetReplServerStatusTask getReplServerStatusTask = (GetReplServerStatusTask) task;
            boolean isActive = getReplServerStatusTask.isActive();
            if (isActive) {
                display.syncExec(new Runnable() {

                    public void run() {
                        isExecuteStopReplServerTask = CommonUITool.openConfirmBox(Messages.bind(Messages.msgConfirmStopReplServer, dbName));
                    }
                });
                if (!isExecuteStopReplServerTask) {
                    disConnect(monitoringTask);
                    return Status.CANCEL_STATUS;
                }
            }
        } else if (task instanceof GetCubridConfParameterTask) {
            GetCubridConfParameterTask getCubridConfParameterTask = (GetCubridConfParameterTask) task;
            confParaMaps = getCubridConfParameterTask.getConfParameters();
            String mdbName = (String) getCubridConfParameterTask.getData("dbName");
            Map<String, String> dbMap = confParaMaps.get("[@" + mdbName + "]");
            if (dbMap == null) {
                Map<String, String> commonMap = confParaMaps.get(ConfConstants.COMMON_SECTION_NAME);
                if (commonMap != null && commonMap.get(ConfConstants.REPLICATION) != null && commonMap.get(ConfConstants.REPLICATION).equalsIgnoreCase("yes")) {
                    isExecuteSetParaTask = false;
                } else if (commonMap != null) {
                    isExecuteSetParaTask = true;
                    commonMap.put(ConfConstants.REPLICATION, "yes");
                }
            } else {
                String replStr = dbMap.get(ConfConstants.REPLICATION);
                if (replStr == null || replStr.equalsIgnoreCase("no")) {
                    isExecuteSetParaTask = true;
                    dbMap.put(ConfConstants.REPLICATION, "yes");
                } else {
                    isExecuteSetParaTask = false;
                }
            }
        } else if (task instanceof GetDatabaseListTask) {
            GetDatabaseListTask getDatabaseListTask = (GetDatabaseListTask) task;
            String mdbName = (String) getDatabaseListTask.getData("dbName");
            List<DatabaseInfo> dbInfoList = getDatabaseListTask.loadDatabaseInfo();
            for (int i = 0; i < dbInfoList.size(); i++) {
                DatabaseInfo dbInfo = dbInfoList.get(i);
                if (mdbName.equalsIgnoreCase(dbInfo.getDbName())) {
                    if (dbInfo.getRunningType() == DbRunningType.CS) {
                        isExecuteStopDbTask = isExecuteSetParaTask;
                    }
                    isExecuteStartDbTask = dbInfo.getRunningType() == DbRunningType.STANDALONE || isExecuteStopDbTask;
                    break;
                }
            }
        } else if (task instanceof TransFileTask) {
            TransFileTask transFileTask = (TransFileTask) task;
            pid = transFileTask.getTransFilePid();
        }
    }
    disConnect(monitoringTask);
    return Status.OK_STATUS;
}
Also used : TransFileProgressInfo(com.cubrid.cubridmanager.core.replication.model.TransFileProgressInfo) 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) StopReplServerTask(com.cubrid.cubridmanager.core.replication.task.StopReplServerTask) CancelTransFileTask(com.cubrid.cubridmanager.core.replication.task.CancelTransFileTask) CancelTransFileTask(com.cubrid.cubridmanager.core.replication.task.CancelTransFileTask) TransFileTask(com.cubrid.cubridmanager.core.replication.task.TransFileTask) MonitoringTask(com.cubrid.cubridmanager.core.common.task.MonitoringTask) CommonUpdateTask(com.cubrid.cubridmanager.core.common.task.CommonUpdateTask) GetTransferProgressTask(com.cubrid.cubridmanager.core.replication.task.GetTransferProgressTask) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) SetCubridConfParameterTask(com.cubrid.cubridmanager.core.common.task.SetCubridConfParameterTask) GetCubridConfParameterTask(com.cubrid.cubridmanager.core.common.task.GetCubridConfParameterTask) GetDatabaseListTask(com.cubrid.cubridmanager.core.cubrid.database.task.GetDatabaseListTask) GetReplServerStatusTask(com.cubrid.cubridmanager.core.replication.task.GetReplServerStatusTask) Map(java.util.Map) Display(org.eclipse.swt.widgets.Display)

Example 24 with GetCubridConfParameterTask

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

the class CreateReplicationUtil method createMasterTaskGroup.

/**
	 * 
	 * Fill in the related tasks of creating master to executor according master
	 * information
	 * 
	 * @param master MasterNode
	 * @param slaveList List<SlaveNode>
	 * @param executor CreateReplicationJobExecutor
	 * @return null or error message
	 */
public static String createMasterTaskGroup(MasterNode master, List<SlaveNode> slaveList, CreateReplicationJobExecutor executor) {
    TaskGroup taskGroup = new TaskGroup(IConstants.REPL_GROUP_NAME_CREATE_MASTER);
    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);
    }
    GetReplServerStatusTask getReplServerStatusTask = new GetReplServerStatusTask(serverInfo);
    getReplServerStatusTask.setDbName(master.getDbName());
    taskGroup.addTask(getReplServerStatusTask);
    StopReplServerTask stopReplServerTask = new StopReplServerTask(serverInfo);
    stopReplServerTask.setDbName(master.getDbName());
    taskGroup.addTask(stopReplServerTask);
    GetCubridConfParameterTask getCubridConfParameterTask = new GetCubridConfParameterTask(serverInfo);
    getCubridConfParameterTask.putData("dbName", master.getDbName());
    taskGroup.addTask(getCubridConfParameterTask);
    SetCubridConfParameterTask setCubridConfParameterTask = new SetCubridConfParameterTask(serverInfo);
    taskGroup.addTask(setCubridConfParameterTask);
    GetDatabaseListTask getDatabaseListTask = new GetDatabaseListTask(serverInfo);
    getDatabaseListTask.putData("dbName", master.getDbName());
    taskGroup.addTask(getDatabaseListTask);
    CommonUpdateTask stopDbTask = new CommonUpdateTask(CommonTaskName.STOP_DB_TASK_NAME, serverInfo, CommonSendMsg.getCommonDatabaseSendMsg());
    stopDbTask.setDbName(master.getDbName());
    taskGroup.addTask(stopDbTask);
    CommonUpdateTask startDbTask = new CommonUpdateTask(CommonTaskName.START_DB_TASK_NAME, serverInfo, CommonSendMsg.getCommonDatabaseSendMsg());
    startDbTask.setDbName(master.getDbName());
    taskGroup.addTask(startDbTask);
    BackupDbTask backupDbTask = new BackupDbTask(serverInfo);
    backupDbTask.setDbName(master.getDbName());
    backupDbTask.setLevel("0");
    backupDbTask.setVolumeName(master.getDbName() + "_bk0v000");
    backupDbTask.setBackupDir(master.getDbPath());
    backupDbTask.setRemoveLog(false);
    backupDbTask.setCheckDatabaseConsist(true);
    backupDbTask.setThreadCount(String.valueOf(0));
    backupDbTask.setZiped(false);
    backupDbTask.setSafeReplication(false);
    taskGroup.addTask(backupDbTask);
    CancelTransFileTask cancelTransFileTask = new CancelTransFileTask(serverInfo);
    taskGroup.addTask(cancelTransFileTask);
    for (int i = 0; i < slaveList.size(); i++) {
        SlaveNode slave = slaveList.get(i);
        HostNode slaveHost = (HostNode) slave.getParent();
        TransFileTask transFileTask = new TransFileTask(serverInfo);
        transFileTask.setMasterDbDir(master.getDbPath());
        List<String> fileList = new ArrayList<String>();
        fileList.add(master.getDbName() + "_bk0v000");
        fileList.add(master.getDbName() + "_bkvinf");
        transFileTask.setBackupFileList(fileList);
        transFileTask.setSlaveDbHost(slaveHost.getIp());
        transFileTask.setSlaveCmServerPort(String.valueOf(Integer.parseInt(slaveHost.getPort()) + 1));
        transFileTask.setSlaveDbDir(slave.getDbPath());
        taskGroup.addTask(transFileTask);
        GetTransferProgressTask getTransferProgressTask = new GetTransferProgressTask(serverInfo);
        taskGroup.addTask(getTransferProgressTask);
    }
    executor.addGroupTask(taskGroup);
    return null;
}
Also used : SlaveNode(com.cubrid.cubridmanager.ui.replication.editor.model.SlaveNode) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) HostNode(com.cubrid.cubridmanager.ui.replication.editor.model.HostNode) SetCubridConfParameterTask(com.cubrid.cubridmanager.core.common.task.SetCubridConfParameterTask) ArrayList(java.util.ArrayList) BackupDbTask(com.cubrid.cubridmanager.core.cubrid.database.task.BackupDbTask) GetCubridConfParameterTask(com.cubrid.cubridmanager.core.common.task.GetCubridConfParameterTask) GetDatabaseListTask(com.cubrid.cubridmanager.core.cubrid.database.task.GetDatabaseListTask) GetReplServerStatusTask(com.cubrid.cubridmanager.core.replication.task.GetReplServerStatusTask) StopReplServerTask(com.cubrid.cubridmanager.core.replication.task.StopReplServerTask) CancelTransFileTask(com.cubrid.cubridmanager.core.replication.task.CancelTransFileTask) CancelTransFileTask(com.cubrid.cubridmanager.core.replication.task.CancelTransFileTask) TransFileTask(com.cubrid.cubridmanager.core.replication.task.TransFileTask) MonitoringTask(com.cubrid.cubridmanager.core.common.task.MonitoringTask) CommonUpdateTask(com.cubrid.cubridmanager.core.common.task.CommonUpdateTask) TaskGroup(com.cubrid.common.ui.spi.progress.TaskGroup) GetTransferProgressTask(com.cubrid.cubridmanager.core.replication.task.GetTransferProgressTask)

Example 25 with GetCubridConfParameterTask

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

the class CoreUtilsTest method testChangeHAModeFromCubridConf.

public void testChangeHAModeFromCubridConf() {
    List<String> lst;
    try {
        lst = CoreUtils.changeHAModeFromCubridConf(null, null, null);
        assertTrue(lst == null);
    } catch (Exception e) {
        assertTrue(true);
    }
    try {
        lst = CoreUtils.changeHAModeFromCubridConf(null, null, "demodb");
        assertTrue(lst == null);
    } catch (Exception e) {
        assertTrue(true);
    }
    GetCubridConfParameterTask task = null;
    try {
        task = new GetCubridConfParameterTask(null);
        lst = CoreUtils.changeHAModeFromCubridConf(task, null, "demodb");
        assertTrue(lst == null);
    } catch (Exception e) {
        assertTrue(true);
    }
    try {
        List<String> clist = new ArrayList<String>();
        lst = CoreUtils.changeHAModeFromCubridConf(task, clist, "demodb");
        assertTrue(lst == null);
    } catch (Exception e) {
        assertTrue(true);
    }
    try {
        List<String> clist = new ArrayList<String>();
        lst = CoreUtils.changeHAModeFromCubridConf(null, clist, "demodb");
        assertTrue(lst == null);
    } catch (Exception e) {
        assertTrue(true);
    }
    try {
        List<String> clist = new ArrayList<String>();
        clist.add("check1");
        lst = CoreUtils.changeHAModeFromCubridConf(null, clist, "demodb");
        assertTrue(lst == null);
    } catch (Exception e) {
        assertTrue(true);
    }
    try {
        task = new GetCubridConfParameterTask(serverInfo);
        List<String> clist = new ArrayList<String>();
        clist.add("check1");
        lst = CoreUtils.changeHAModeFromCubridConf(task, clist, "demodb");
        assertTrue(lst == null);
    } catch (Exception e) {
        assertTrue(true);
    }
    try {
        task = new GetCubridConfParameterTask(serverInfo);
        List<String> clist = new ArrayList<String>();
        clist.add("check1");
        lst = CoreUtils.changeHAModeFromCubridConf(task, clist, "demodb");
        assertTrue(lst == null);
    } catch (Exception e) {
        assertTrue(true);
    }
    try {
        serverInfo.setConnected(false);
        task = new GetCubridConfParameterTask(serverInfo);
        List<String> clist = new ArrayList<String>();
        clist.add("check1");
        lst = CoreUtils.changeHAModeFromCubridConf(task, clist, "demodb");
        assertTrue(lst == null);
    } catch (Exception e) {
        assertTrue(true);
    }
    try {
        serverInfo.setAllDatabaseList(null);
        task = new GetCubridConfParameterTask(serverInfo);
        TreeNode response = new TreeNode();
        response.add("confdata", "ha_mode=ON");
        //			TreeNode child = new TreeNode();
        //			child.add("open", "conflist");
        //			child.add("confdata", "1");
        //			child.add("confdata", "2");
        //			response.addChild(child);
        TreeNode child2 = new TreeNode();
        child2.add("open", "conflist");
        child2.add("confdata", "[service]");
        child2.add("confdata", "service");
        child2.add("confdata", "common=1");
        child2.add("confdata", "[common]=2");
        child2.add("confdata", "ha_mode=ON");
        child2.add("confdata", ConfConstants.COMMON_SECTION);
        response.addChild(child2);
        task.setResponse(response);
        List<String> clist = new ArrayList<String>();
        clist.add("check1");
        lst = CoreUtils.changeHAModeFromCubridConf(task, clist, "demodb");
        assertTrue(lst == null);
    } catch (Exception e) {
        assertTrue(true);
    }
    try {
        task = new GetCubridConfParameterTask(serverInfo);
        task.getConfParameters().get(ConfConstants.COMMON_SECTION_NAME).put(ConfConstants.HA_MODE, "YES");
        List<String> clist = new ArrayList<String>();
        clist.add("check1");
        lst = CoreUtils.changeHAModeFromCubridConf(task, clist, "demodb");
        assertTrue(lst == null);
    } catch (Exception e) {
        assertTrue(true);
    }
    try {
        task = new GetCubridConfParameterTask(serverInfo);
        task.getConfParameters().get(ConfConstants.COMMON_SECTION_NAME).put(ConfConstants.HA_MODE, "REPLICA");
        List<String> clist = new ArrayList<String>();
        clist.add(ConfConstants.HA_MODE + "=on");
        lst = CoreUtils.changeHAModeFromCubridConf(task, clist, "demodb");
        assertTrue(lst == null);
    } catch (Exception e) {
        assertTrue(true);
    }
    try {
        task = new GetCubridConfParameterTask(serverInfo);
        task.getConfParameters().get(ConfConstants.COMMON_SECTION_NAME).put(ConfConstants.HA_MODE, "YES");
        List<String> clist = new ArrayList<String>();
        clist.add(ConfConstants.HA_MODE + "=off");
        lst = CoreUtils.changeHAModeFromCubridConf(task, clist, "demodb");
        assertTrue(lst == null);
    } catch (Exception e) {
        assertTrue(true);
    }
    try {
        task = new GetCubridConfParameterTask(serverInfo);
        task.getConfParameters().get(ConfConstants.COMMON_SECTION_NAME).put(ConfConstants.HA_MODE, "YES");
        List<String> clist = new ArrayList<String>();
        clist.add(ConfConstants.HA_MODE + "=on");
        lst = CoreUtils.changeHAModeFromCubridConf(task, clist, "demodb");
        assertTrue(lst == null);
    } catch (Exception e) {
        assertTrue(true);
    }
    try {
        task = new GetCubridConfParameterTask(serverInfo);
        task.getConfParameters().get(ConfConstants.COMMON_SECTION_NAME).put(ConfConstants.HA_MODE, "REPLICA");
        List<String> clist = new ArrayList<String>();
        clist.add(ConfConstants.HA_MODE + "=on");
        lst = CoreUtils.changeHAModeFromCubridConf(task, clist, "demodb");
        assertTrue(lst == null);
    } catch (Exception e) {
        assertTrue(true);
    }
    try {
        task = new GetCubridConfParameterTask(serverInfo);
        task.getConfParameters().get(ConfConstants.COMMON_SECTION_NAME).put(ConfConstants.HA_MODE, "ON");
        List<String> clist = new ArrayList<String>();
        clist.add(ConfConstants.HA_MODE + "=off");
        lst = CoreUtils.changeHAModeFromCubridConf(task, clist, "demodb");
        assertTrue(lst == null);
    } catch (Exception e) {
        assertTrue(true);
    }
    try {
        task = new GetCubridConfParameterTask(serverInfo);
        task.getConfParameters().get(ConfConstants.COMMON_SECTION_NAME).put(ConfConstants.HA_MODE, "ON");
        List<String> clist = new ArrayList<String>();
        clist.add(ConfConstants.HA_MODE + "=off");
        lst = CoreUtils.changeHAModeFromCubridConf(task, clist, "demodb");
        assertTrue(lst == null);
    } catch (Exception e) {
        assertTrue(true);
    }
    try {
        task = new GetCubridConfParameterTask(serverInfo);
        task.getConfParameters().get(ConfConstants.COMMON_SECTION_NAME).get("[@demodb]");
        List<String> clist = new ArrayList<String>();
        clist.add("check1");
        lst = CoreUtils.changeHAModeFromCubridConf(task, clist, "demodb");
        assertTrue(lst == null);
    } catch (Exception e) {
        assertTrue(true);
    }
    try {
        task = new GetCubridConfParameterTask(serverInfo);
        task.getConfParameters().get(ConfConstants.COMMON_SECTION_NAME).get("[@demodb]");
        List<String> clist = new ArrayList<String>();
        clist.add("check1");
        lst = CoreUtils.changeHAModeFromCubridConf(task, clist, "demodb");
        assertTrue(lst == null);
    } catch (Exception e) {
        assertTrue(true);
    }
    try {
        serverInfo.setConnected(false);
        task = new GetCubridConfParameterTask(serverInfo);
        task.getConfParameters().get(ConfConstants.COMMON_SECTION_NAME).get("[@demodb]");
        List<String> clist = new ArrayList<String>();
        clist.add("check1");
        lst = CoreUtils.changeHAModeFromCubridConf(task, clist, "demodb");
        assertTrue(lst == null);
    } catch (Exception e) {
        assertTrue(true);
    }
    try {
        serverInfo.setAllDatabaseList(null);
        task = new GetCubridConfParameterTask(serverInfo);
        task.getConfParameters().get(ConfConstants.COMMON_SECTION_NAME).get("[@demodb]");
        task.getConfParameters().get(ConfConstants.COMMON_SECTION_NAME).put(ConfConstants.HA_MODE, "ON");
        List<String> clist = new ArrayList<String>();
        clist.add("check1");
        lst = CoreUtils.changeHAModeFromCubridConf(task, clist, "demodb");
        assertTrue(lst == null);
    } catch (Exception e) {
        assertTrue(true);
    }
    try {
        task = new GetCubridConfParameterTask(serverInfo);
        task.getConfParameters().get(ConfConstants.COMMON_SECTION_NAME).get("[@demodb]");
        task.getConfParameters().get(ConfConstants.COMMON_SECTION_NAME).put(ConfConstants.HA_MODE, "YES");
        List<String> clist = new ArrayList<String>();
        clist.add("check1");
        lst = CoreUtils.changeHAModeFromCubridConf(task, clist, "demodb");
        assertTrue(lst == null);
    } catch (Exception e) {
        assertTrue(true);
    }
    try {
        task = new GetCubridConfParameterTask(serverInfo);
        task.getConfParameters().get(ConfConstants.COMMON_SECTION_NAME).get("[@demodb]");
        task.getConfParameters().get(ConfConstants.COMMON_SECTION_NAME).put(ConfConstants.HA_MODE, "REPLICA");
        List<String> clist = new ArrayList<String>();
        clist.add(ConfConstants.HA_MODE + "=on");
        lst = CoreUtils.changeHAModeFromCubridConf(task, clist, "demodb");
        assertTrue(lst == null);
    } catch (Exception e) {
        assertTrue(true);
    }
    try {
        task = new GetCubridConfParameterTask(serverInfo);
        task.getConfParameters().get(ConfConstants.COMMON_SECTION_NAME).get("[@demodb]");
        task.getConfParameters().get(ConfConstants.COMMON_SECTION_NAME).put(ConfConstants.HA_MODE, "YES");
        List<String> clist = new ArrayList<String>();
        clist.add(ConfConstants.HA_MODE + "=off");
        lst = CoreUtils.changeHAModeFromCubridConf(task, clist, "demodb");
        assertTrue(lst == null);
    } catch (Exception e) {
        assertTrue(true);
    }
    try {
        task = new GetCubridConfParameterTask(serverInfo);
        task.getConfParameters().get(ConfConstants.COMMON_SECTION_NAME).get("[@demodb]");
        task.getConfParameters().get(ConfConstants.COMMON_SECTION_NAME).put(ConfConstants.HA_MODE, "YES");
        List<String> clist = new ArrayList<String>();
        clist.add(ConfConstants.HA_MODE + "=on");
        lst = CoreUtils.changeHAModeFromCubridConf(task, clist, "demodb");
        assertTrue(lst == null);
    } catch (Exception e) {
        assertTrue(true);
    }
    try {
        task = new GetCubridConfParameterTask(serverInfo);
        task.getConfParameters().get(ConfConstants.COMMON_SECTION_NAME).get("[@demodb]");
        task.getConfParameters().get(ConfConstants.COMMON_SECTION_NAME).put(ConfConstants.HA_MODE, "REPLICA");
        List<String> clist = new ArrayList<String>();
        clist.add(ConfConstants.HA_MODE + "=on");
        lst = CoreUtils.changeHAModeFromCubridConf(task, clist, "demodb");
        assertTrue(lst == null);
    } catch (Exception e) {
        assertTrue(true);
    }
    try {
        task = new GetCubridConfParameterTask(serverInfo);
        task.getConfParameters().get(ConfConstants.COMMON_SECTION_NAME).get("[@demodb]");
        task.getConfParameters().get(ConfConstants.COMMON_SECTION_NAME).put(ConfConstants.HA_MODE, "ON");
        List<String> clist = new ArrayList<String>();
        clist.add(ConfConstants.HA_MODE + "=off");
        lst = CoreUtils.changeHAModeFromCubridConf(task, clist, "demodb");
        assertTrue(lst == null);
    } catch (Exception e) {
        assertTrue(true);
    }
    try {
        task = new GetCubridConfParameterTask(serverInfo);
        task.getConfParameters().get(ConfConstants.COMMON_SECTION_NAME).get("[@demodb]");
        task.getConfParameters().get(ConfConstants.COMMON_SECTION_NAME).put(ConfConstants.HA_MODE, "ON");
        List<String> clist = new ArrayList<String>();
        clist.add("# The createdb creates a log volume file of 'log_volume_size' size\n");
        clist.add("# if don't have any options about size.\n");
        clist.add("");
        clist.add("ha_mode=on");
        clist.add("");
        lst = CoreUtils.changeHAModeFromCubridConf(task, clist, "demodb");
        assertTrue(lst == null);
    } catch (Exception e) {
        assertTrue(true);
    }
    try {
        task = new GetCubridConfParameterTask(serverInfo);
        task.getConfParameters().get(ConfConstants.COMMON_SECTION_NAME).get("[@demodb]");
        task.getConfParameters().get(ConfConstants.COMMON_SECTION_NAME).put(ConfConstants.HA_MODE, "ON");
        List<String> clist = new ArrayList<String>();
        clist.add("# The createdb creates a log volume file of 'log_volume_size' size\n");
        clist.add("# if don't have any options about size.\n");
        clist.add("");
        clist.add("ha_mode=off");
        clist.add("");
        lst = CoreUtils.changeHAModeFromCubridConf(task, clist, "demodb");
        assertTrue(lst == null);
    } catch (Exception e) {
        assertTrue(true);
    }
    try {
        task = new GetCubridConfParameterTask(serverInfo);
        task.getConfParameters().get(ConfConstants.COMMON_SECTION_NAME).get("[@demodb]");
        task.getConfParameters().get(ConfConstants.COMMON_SECTION_NAME).put(ConfConstants.HA_MODE, "ON");
        List<String> clist = new ArrayList<String>();
        clist.add("# The createdb creates a log volume file of 'log_volume_size' size\n");
        clist.add("# if don't have any options about size.\n");
        clist.add("");
        clist.add("ha_mode=yes");
        clist.add("");
        lst = CoreUtils.changeHAModeFromCubridConf(task, clist, "demodb");
        assertTrue(lst == null);
    } catch (Exception e) {
        assertTrue(true);
    }
    try {
        task = new GetCubridConfParameterTask(serverInfo);
        task.getConfParameters().get(ConfConstants.COMMON_SECTION_NAME).get("[@demodb]");
        task.getConfParameters().get(ConfConstants.COMMON_SECTION_NAME).put(ConfConstants.HA_MODE, "ON");
        List<String> clist = new ArrayList<String>();
        clist.add("# The createdb creates a log volume file of 'log_volume_size' size\n");
        clist.add("# if don't have any options about size.\n");
        clist.add("");
        clist.add("ha_mode=replica");
        clist.add("");
        lst = CoreUtils.changeHAModeFromCubridConf(task, clist, "demodb");
        assertTrue(lst == null);
    } catch (Exception e) {
        assertTrue(true);
    }
}
Also used : TreeNode(com.cubrid.cubridmanager.core.common.socket.TreeNode) ArrayList(java.util.ArrayList) GetCubridConfParameterTask(com.cubrid.cubridmanager.core.common.task.GetCubridConfParameterTask)

Aggregations

GetCubridConfParameterTask (com.cubrid.cubridmanager.core.common.task.GetCubridConfParameterTask)27 GetDatabaseListTask (com.cubrid.cubridmanager.core.cubrid.database.task.GetDatabaseListTask)13 ArrayList (java.util.ArrayList)12 Map (java.util.Map)12 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)11 MonitoringTask (com.cubrid.cubridmanager.core.common.task.MonitoringTask)11 GetBrokerConfParameterTask (com.cubrid.cubridmanager.core.broker.task.GetBrokerConfParameterTask)10 GetCMConfParameterTask (com.cubrid.cubridmanager.core.common.task.GetCMConfParameterTask)10 ITask (com.cubrid.common.core.task.ITask)9 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)8 GetCMUserListTask (com.cubrid.cubridmanager.core.common.task.GetCMUserListTask)8 GetEnvInfoTask (com.cubrid.cubridmanager.core.common.task.GetEnvInfoTask)8 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)8 List (java.util.List)8 SetCubridConfParameterTask (com.cubrid.cubridmanager.core.common.task.SetCubridConfParameterTask)7 ServerType (com.cubrid.cubridmanager.core.common.model.ServerType)6 ServerUserInfo (com.cubrid.cubridmanager.core.common.model.ServerUserInfo)6 JobFamily (com.cubrid.common.ui.spi.progress.JobFamily)5 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)5 BrokerInfos (com.cubrid.cubridmanager.core.broker.model.BrokerInfos)5