Search in sources :

Example 6 with SlaveNode

use of com.cubrid.cubridmanager.ui.replication.editor.model.SlaveNode 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 7 with SlaveNode

use of com.cubrid.cubridmanager.ui.replication.editor.model.SlaveNode in project cubrid-manager by CUBRID.

the class ReplicationEditor method createReplication.

/**
	 * create the replication
	 * 
	 * @param replicationsList List<List<Node>>
	 */
private void createReplication(List<List<Node>> replicationsList) {
    List<String> tempList = new ArrayList<String>();
    CreateReplicationJobExecutor executor = new CreateReplicationJobExecutor(this);
    for (int i = 0; i < replicationsList.size(); i++) {
        List<Node> replicationList = replicationsList.get(i);
        MasterNode masterDb = null;
        DistributorNode distDb = null;
        SlaveNode slaveDb = null;
        for (int j = 0; j < replicationList.size(); j++) {
            Node node = replicationList.get(j);
            if (node instanceof MasterNode) {
                masterDb = (MasterNode) node;
            } else if (node instanceof DistributorNode) {
                distDb = (DistributorNode) node;
            } else if (node instanceof SlaveNode) {
                slaveDb = (SlaveNode) node;
            }
            HostNode host = (HostNode) node.getParent();
            String str = host.getIp() + ":" + host.getPort() + ":" + node.getName();
            if (isExist(str, tempList)) {
                continue;
            }
            tempList.add(str);
            String errorMsg = null;
            if (node instanceof MasterNode) {
                errorMsg = CreateReplicationUtil.createMasterTaskGroup(masterDb, CreateReplicationUtil.getAllSlaveOfMaster((MasterNode) node, replicationsList), executor);
                if (errorMsg == null) {
                    errorMsg = CreateReplicationUtil.createReplServerTaskGroup(masterDb, executor);
                }
            } else if (node instanceof DistributorNode) {
                if (j > 2) {
                    errorMsg = CreateReplicationUtil.createDistributorTaskGroup(masterDb, slaveDb, distDb, executor);
                } else {
                    errorMsg = CreateReplicationUtil.createDistributorTaskGroup(masterDb, distDb, executor);
                }
                if (errorMsg == null) {
                    errorMsg = CreateReplicationUtil.createAgentTaskGroup(distDb, executor);
                }
            } else if (node instanceof SlaveNode) {
                errorMsg = CreateReplicationUtil.createSlaveTaskGroup(masterDb, distDb, slaveDb, executor);
                if (j > 2 && errorMsg == null) {
                    errorMsg = CreateReplicationUtil.createSlaveMasterTaskGroup(masterDb, slaveDb, executor);
                    if (errorMsg == null) {
                        errorMsg = CreateReplicationUtil.createReplServerTaskGroup(masterDb, executor);
                    }
                }
            }
            if (errorMsg != null) {
                CommonUITool.openErrorBox(errorMsg);
                isEditable = true;
                setDirty(true);
                return;
            }
        }
    }
    JobFamily jobFamily = new JobFamily();
    jobFamily.setServerName(JobFamily.ALL_SERVER);
    jobFamily.setDbName(JobFamily.ALL_DB);
    executor.schedule(Messages.createReplicationJobName, jobFamily, true, Job.SHORT);
}
Also used : MasterNode(com.cubrid.cubridmanager.ui.replication.editor.model.MasterNode) SlaveNode(com.cubrid.cubridmanager.ui.replication.editor.model.SlaveNode) ContainerNode(com.cubrid.cubridmanager.ui.replication.editor.model.ContainerNode) SlaveNode(com.cubrid.cubridmanager.ui.replication.editor.model.SlaveNode) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) MasterNode(com.cubrid.cubridmanager.ui.replication.editor.model.MasterNode) Node(com.cubrid.cubridmanager.ui.replication.editor.model.Node) LeafNode(com.cubrid.cubridmanager.ui.replication.editor.model.LeafNode) DistributorNode(com.cubrid.cubridmanager.ui.replication.editor.model.DistributorNode) HostNode(com.cubrid.cubridmanager.ui.replication.editor.model.HostNode) HostNode(com.cubrid.cubridmanager.ui.replication.editor.model.HostNode) ArrayList(java.util.ArrayList) JobFamily(com.cubrid.common.ui.spi.progress.JobFamily) Point(org.eclipse.draw2d.geometry.Point) DistributorNode(com.cubrid.cubridmanager.ui.replication.editor.model.DistributorNode)

Example 8 with SlaveNode

use of com.cubrid.cubridmanager.ui.replication.editor.model.SlaveNode in project cubrid-manager by CUBRID.

the class ReplicationEditor method doSave.

/**
	 * @see org.eclipse.ui.part.EditorPart#doSave(org.eclipse.core.runtime.IProgressMonitor)
	 * @param monitor IProgressMonitor
	 */
public void doSave(IProgressMonitor monitor) {
    List<ContainerNode> hostNodeList = diagram.getChildNodeList();
    int hostSize = 0;
    if (hostNodeList != null) {
        hostSize = hostNodeList.size();
    }
    //check the host number,2 at less
    if (hostSize <= 1) {
        CommonUITool.openErrorBox(this.getSite().getShell(), Messages.errInvalidReplDesign);
        monitor.setCanceled(true);
        return;
    }
    //check the host and replication component information integrity
    for (int i = 0; i < hostSize; i++) {
        HostNode host = (HostNode) hostNodeList.get(i);
        if (!host.isValid()) {
            CommonUITool.openErrorBox(this.getSite().getShell(), Messages.bind(Messages.errInvalidHost, host.getName()));
            monitor.setCanceled(true);
            return;
        }
        List<LeafNode> leafNodeList = host.getChildNodeList();
        for (int j = 0; j < leafNodeList.size(); j++) {
            LeafNode node = leafNodeList.get(j);
            if (!node.isValid()) {
                CommonUITool.openErrorBox(this.getSite().getShell(), Messages.bind(Messages.errInvalidReplComponent, node.getName()));
                monitor.setCanceled(true);
                return;
            }
        }
    }
    //check the replication component connection validity
    List<List<Node>> replicationsList = new ArrayList<List<Node>>();
    for (int i = 0; i < hostSize; i++) {
        HostNode host = (HostNode) hostNodeList.get(i);
        List<LeafNode> leafNodeList = host.getChildNodeList();
        for (int j = 0; j < leafNodeList.size(); j++) {
            LeafNode node = leafNodeList.get(j);
            if (node instanceof MasterNode) {
                List<ArrowConnection> connList = node.getOutgoingConnections();
                if (connList == null || connList.isEmpty()) {
                    CommonUITool.openErrorBox(this.getSite().getShell(), Messages.bind(Messages.errInvalidMasterConn1, node.getName()));
                    monitor.setCanceled(true);
                    return;
                } else {
                    for (int k = 0; k < connList.size(); k++) {
                        LOGGER.debug("Replication chain" + k);
                        LOGGER.debug(node.getName());
                        List<Node> replicationList = new ArrayList<Node>();
                        replicationList.add(node);
                        HostNode masterHost = (HostNode) node.getParent();
                        ArrowConnection conn = connList.get(k);
                        HostNode distHost = (HostNode) conn.getTarget().getParent();
                        if (masterHost.getName().equals(distHost.getName())) {
                            CommonUITool.openErrorBox(this.getSite().getShell(), Messages.bind(Messages.errInvalidMasterConn2, new String[] { node.getName(), conn.getTarget().getName() }));
                            monitor.setCanceled(true);
                            return;
                        }
                        createReplChain(replicationList, conn);
                        replicationsList.add(replicationList);
                    }
                }
            } else if (node instanceof DistributorNode) {
                if (node.getIncomingConnections() == null || node.getIncomingConnections().size() == 0) {
                    CommonUITool.openErrorBox(this.getSite().getShell(), Messages.bind(Messages.errInvalidDistConn1, node.getName()));
                    monitor.setCanceled(true);
                    return;
                }
                if (node.getOutgoingConnections() == null || node.getOutgoingConnections().size() == 0) {
                    CommonUITool.openErrorBox(this.getSite().getShell(), Messages.bind(Messages.errInvalidDistConn2, node.getName()));
                    monitor.setCanceled(true);
                    return;
                }
            } else if (node instanceof SlaveNode && (node.getIncomingConnections() == null || node.getIncomingConnections().isEmpty())) {
                CommonUITool.openErrorBox(this.getSite().getShell(), Messages.bind(Messages.errInvalidSlaveConn, node.getName()));
                monitor.setCanceled(true);
                return;
            }
        }
    }
    int count = replicationsList.size();
    if (count <= 0) {
        CommonUITool.openErrorBox(this.getSite().getShell(), Messages.errInvalidReplDesign);
        monitor.setCanceled(true);
        return;
    }
    for (int i = 0; i < count; i++) {
        List<Node> replcationlist = replicationsList.get(i);
        int size = replcationlist.size();
        if (size < 3) {
            CommonUITool.openErrorBox(this.getSite().getShell(), Messages.errInvalidReplDesign);
            monitor.setCanceled(true);
            return;
        }
        if (!(replcationlist.get(size - 1) instanceof SlaveNode)) {
            CommonUITool.openErrorBox(this.getSite().getShell(), Messages.errInvalidReplDesign);
            monitor.setCanceled(true);
            return;
        }
        //check the connection validity,
        for (int j = 1; j + 1 < size; j++) {
            Node node1 = (Node) replcationlist.get(j).getParent();
            Node node2 = (Node) replcationlist.get(j + 1).getParent();
            //from the slave to the distributor can not in the same host
            if (j % 2 == 0) {
                if (node1.getName().equals(node2.getName())) {
                    CommonUITool.openErrorBox(this.getSite().getShell(), Messages.bind(Messages.errInvalidConn1, new String[] { node1.getName(), node2.getName() }));
                    monitor.setCanceled(true);
                    return;
                }
            } else {
                //from the distributor to the slave must be in the same host
                if (!node1.getName().equals(node2.getName())) {
                    CommonUITool.openErrorBox(this.getSite().getShell(), Messages.bind(Messages.errInvalidConn2, new String[] { node1.getName(), node2.getName() }));
                    monitor.setCanceled(true);
                    return;
                }
            }
        }
    }
    if (!CommonUITool.openConfirmBox(Messages.msgConfirmCreateRepl)) {
        return;
    }
    isEditable = false;
    getCommandStack().flush();
    setDirty(false);
    createReplication(replicationsList);
}
Also used : MasterNode(com.cubrid.cubridmanager.ui.replication.editor.model.MasterNode) SlaveNode(com.cubrid.cubridmanager.ui.replication.editor.model.SlaveNode) HostNode(com.cubrid.cubridmanager.ui.replication.editor.model.HostNode) ContainerNode(com.cubrid.cubridmanager.ui.replication.editor.model.ContainerNode) SlaveNode(com.cubrid.cubridmanager.ui.replication.editor.model.SlaveNode) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) MasterNode(com.cubrid.cubridmanager.ui.replication.editor.model.MasterNode) Node(com.cubrid.cubridmanager.ui.replication.editor.model.Node) LeafNode(com.cubrid.cubridmanager.ui.replication.editor.model.LeafNode) DistributorNode(com.cubrid.cubridmanager.ui.replication.editor.model.DistributorNode) HostNode(com.cubrid.cubridmanager.ui.replication.editor.model.HostNode) ArrayList(java.util.ArrayList) Point(org.eclipse.draw2d.geometry.Point) LeafNode(com.cubrid.cubridmanager.ui.replication.editor.model.LeafNode) ArrowConnection(com.cubrid.cubridmanager.ui.replication.editor.model.ArrowConnection) ContainerNode(com.cubrid.cubridmanager.ui.replication.editor.model.ContainerNode) List(java.util.List) ArrayList(java.util.ArrayList) DistributorNode(com.cubrid.cubridmanager.ui.replication.editor.model.DistributorNode)

Aggregations

SlaveNode (com.cubrid.cubridmanager.ui.replication.editor.model.SlaveNode)8 DistributorNode (com.cubrid.cubridmanager.ui.replication.editor.model.DistributorNode)7 MasterNode (com.cubrid.cubridmanager.ui.replication.editor.model.MasterNode)7 HostNode (com.cubrid.cubridmanager.ui.replication.editor.model.HostNode)5 LeafNode (com.cubrid.cubridmanager.ui.replication.editor.model.LeafNode)4 Point (org.eclipse.draw2d.geometry.Point)4 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)3 ContainerNode (com.cubrid.cubridmanager.ui.replication.editor.model.ContainerNode)3 ArrayList (java.util.ArrayList)3 CMWizardDialog (com.cubrid.common.ui.spi.dialog.CMWizardDialog)2 SetDistributorDbInfoDialog (com.cubrid.cubridmanager.ui.replication.editor.dialog.SetDistributorDbInfoDialog)2 SetSlaveDbInfoDialog (com.cubrid.cubridmanager.ui.replication.editor.dialog.SetSlaveDbInfoDialog)2 SetMasterDbInfoWizard (com.cubrid.cubridmanager.ui.replication.editor.dialog.wizard.SetMasterDbInfoWizard)2 ArrowConnection (com.cubrid.cubridmanager.ui.replication.editor.model.ArrowConnection)2 Node (com.cubrid.cubridmanager.ui.replication.editor.model.Node)2 Shell (org.eclipse.swt.widgets.Shell)2 CubridServer (com.cubrid.common.ui.spi.model.CubridServer)1 JobFamily (com.cubrid.common.ui.spi.progress.JobFamily)1 TaskGroup (com.cubrid.common.ui.spi.progress.TaskGroup)1 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)1