Search in sources :

Example 1 with TransFileProgressInfo

use of com.cubrid.cubridmanager.core.replication.model.TransFileProgressInfo in project cubrid-manager by CUBRID.

the class GetTransferProgressTaskTest method testReceive.

public void testReceive() throws Exception {
    if (StringUtil.isEqual(SystemParameter.getParameterValue("useMockTest"), "y"))
        return;
    String filepath = this.getFilePathInPlugin("/com/cubrid/cubridmanager/core/replication/task/test.message/GetTransferProgress_receive");
    String msg = Tool.getFileContent(filepath);
    //case 1
    TreeNode node = MessageUtil.parseResponse(msg);
    GetTransferProgressTask task = new GetTransferProgressTask(serverInfo);
    task.setResponse(node);
    TransFileProgressInfo progressInfo = task.getProgressInfo();
    assertEquals(progressInfo.getTransferStatus(), "success");
    assertEquals(progressInfo.getTransferNote(), "none");
    assertEquals(progressInfo.getSourceDir(), "/tmp");
    assertEquals(progressInfo.getDestHost(), "192.168.1.220");
    assertEquals(progressInfo.getDestDir(), "/home/biaozhang/new_build_cubrid32/databases/target_dir");
    assertEquals(progressInfo.getFileNum(), "2");
    Map<String, String> map = progressInfo.getFileProgressMap();
    assertEquals(map.get("biaodb_src_bk0v000"), "100%");
    assertEquals(map.get("biaodb_src_bkvinf"), "100%");
    //case 2
    String msg1 = msg.replaceFirst("transfer_status:success", "transfer_status:failure");
    msg1 = msg1.replaceFirst("transfer_note:none", "transfer_note:sorry");
    node = MessageUtil.parseResponse(msg1);
    task.setResponse(node);
    progressInfo = task.getProgressInfo();
    assertEquals(progressInfo.getTransferStatus(), "failure");
    assertEquals(progressInfo.getTransferNote(), "sorry");
    //case 3
    String msg2 = msg.replaceFirst("transfer_status:success", "transfer_status:transfering");
    node = MessageUtil.parseResponse(msg2);
    task.setResponse(node);
    progressInfo = task.getProgressInfo();
    assertEquals(progressInfo.getTransferStatus(), "transfering");
    //case 4
    msg = msg.replaceFirst("open:progress_file_list", "open:aa");
    node = MessageUtil.parseResponse(msg);
    task.setResponse(node);
    task.getProgressInfo();
    msg = msg.replaceFirst("open:aa", "");
    msg = msg.replaceFirst("close:progress_file_list", "");
    node = MessageUtil.parseResponse(msg);
    task.setResponse(node);
    task.getProgressInfo();
    //exception case1
    task.setResponse(null);
    assertTrue(task.getProgressInfo() == null);
    //exception case2
    task.setResponse(node);
    task.setErrorMsg("has error");
    assertTrue(task.getProgressInfo() == null);
}
Also used : TransFileProgressInfo(com.cubrid.cubridmanager.core.replication.model.TransFileProgressInfo) TreeNode(com.cubrid.cubridmanager.core.common.socket.TreeNode)

Example 2 with TransFileProgressInfo

use of com.cubrid.cubridmanager.core.replication.model.TransFileProgressInfo in project cubrid-manager by CUBRID.

the class TransFileProgressInfoTest method testSlaveInfo.

public void testSlaveInfo() {
    TransFileProgressInfo progressInfo = new TransFileProgressInfo();
    String transferStatus = "success";
    String transferNote = "This is successfully";
    String sourceDir = "/home/cubrid/database/masterdb";
    String destHost = "192.168.1.221";
    String destDir = "/home/cubrid/database/sdb";
    String fileNum = "2";
    Map<String, String> fileProgressMap = new HashMap<String, String>();
    String fileName = "bak_db_001";
    String progress = "80%";
    fileProgressMap.put(fileName, progress);
    progressInfo.setTransferStatus(transferStatus);
    progressInfo.setTransferNote(transferNote);
    progressInfo.setSourceDir(sourceDir);
    progressInfo.setDestHost(destHost);
    progressInfo.setDestDir(destDir);
    progressInfo.setFileNum(fileNum);
    progressInfo.setFileProgressMap(fileProgressMap);
    assertEquals(progressInfo.getTransferStatus(), transferStatus);
    assertEquals(progressInfo.getTransferNote(), transferNote);
    assertEquals(progressInfo.getSourceDir(), sourceDir);
    assertEquals(progressInfo.getDestHost(), destHost);
    assertEquals(progressInfo.getFileNum(), fileNum);
    assertEquals(progressInfo.getFileProgressMap().get(fileName), progress);
    assertEquals(progressInfo.getDestDir(), destDir);
    progressInfo.getProgress(fileName);
    progressInfo.setFileProgressMap(null);
    progressInfo.getProgress(fileName);
}
Also used : TransFileProgressInfo(com.cubrid.cubridmanager.core.replication.model.TransFileProgressInfo) HashMap(java.util.HashMap)

Example 3 with TransFileProgressInfo

use of com.cubrid.cubridmanager.core.replication.model.TransFileProgressInfo in project cubrid-manager by CUBRID.

the class GetTransferProgressTask method getProgressInfo.

/**
	 * 
	 * Get transfer file progress information
	 * 
	 * @return the TransFileProgressInfo obj
	 */
public TransFileProgressInfo getProgressInfo() {
    TreeNode response = getResponse();
    if (response == null || (this.getErrorMsg() != null && getErrorMsg().trim().length() > 0)) {
        return null;
    }
    TransFileProgressInfo progressInfo = new TransFileProgressInfo();
    String transferStatus = response.getValue("transfer_status");
    String transferNote = response.getValue("transfer_note");
    String sourceDir = response.getValue("src_dir");
    String destHost = response.getValue("dest_host");
    String destDir = response.getValue("dest_dir");
    String fileNum = response.getValue("num_of_file");
    progressInfo.setTransferStatus(transferStatus);
    progressInfo.setTransferNote(transferNote);
    progressInfo.setSourceDir(sourceDir);
    progressInfo.setDestHost(destHost);
    progressInfo.setDestDir(destDir);
    progressInfo.setFileNum(fileNum);
    for (int i = 0; i < response.childrenSize(); i++) {
        TreeNode node = response.getChildren().get(i);
        if (node != null && node.getValue("open") != null && node.getValue("open").equals("progress_file_list")) {
            progressInfo.setFileProgressMap(node.getValuesByMap());
        }
    }
    return progressInfo;
}
Also used : TransFileProgressInfo(com.cubrid.cubridmanager.core.replication.model.TransFileProgressInfo) TreeNode(com.cubrid.cubridmanager.core.common.socket.TreeNode)

Example 4 with TransFileProgressInfo

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

Aggregations

TransFileProgressInfo (com.cubrid.cubridmanager.core.replication.model.TransFileProgressInfo)4 TreeNode (com.cubrid.cubridmanager.core.common.socket.TreeNode)2 ITask (com.cubrid.common.core.task.ITask)1 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)1 CommonUpdateTask (com.cubrid.cubridmanager.core.common.task.CommonUpdateTask)1 GetCubridConfParameterTask (com.cubrid.cubridmanager.core.common.task.GetCubridConfParameterTask)1 MonitoringTask (com.cubrid.cubridmanager.core.common.task.MonitoringTask)1 SetCubridConfParameterTask (com.cubrid.cubridmanager.core.common.task.SetCubridConfParameterTask)1 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)1 GetDatabaseListTask (com.cubrid.cubridmanager.core.cubrid.database.task.GetDatabaseListTask)1 CancelTransFileTask (com.cubrid.cubridmanager.core.replication.task.CancelTransFileTask)1 GetReplServerStatusTask (com.cubrid.cubridmanager.core.replication.task.GetReplServerStatusTask)1 GetTransferProgressTask (com.cubrid.cubridmanager.core.replication.task.GetTransferProgressTask)1 StopReplServerTask (com.cubrid.cubridmanager.core.replication.task.StopReplServerTask)1 TransFileTask (com.cubrid.cubridmanager.core.replication.task.TransFileTask)1 MonitorDashboardPreference (com.cubrid.cubridmanager.ui.mondashboard.preference.MonitorDashboardPreference)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1