Search in sources :

Example 6 with ReplicationInfo

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

the class StartSlaveDbAction method isSupportedNode.

/**
	 * @see com.cubrid.common.ui.spi.action.ISelectionAction#isSupported(java
	 *      .lang.Object)
	 * @param obj Object
	 * @return boolean(whether to support)
	 */
public static boolean isSupportedNode(Object obj) {
    if (obj instanceof CubridDatabase) {
        CubridDatabase database = (CubridDatabase) obj;
        if (!database.isLogined()) {
            return false;
        }
        ServerUserInfo serverUserInfo = database.getServer().getServerInfo().getLoginedUserInfo();
        if (serverUserInfo == null || !serverUserInfo.isAdmin()) {
            return false;
        }
        if (!database.isDistributorDb()) {
            return false;
        }
        ReplicationInfo replInfo = (ReplicationInfo) database.getAdapter(ReplicationInfo.class);
        boolean isSupported = false;
        if (replInfo != null && replInfo.getSlaveList() != null) {
            for (int i = 0; i < replInfo.getSlaveList().size(); i++) {
                DatabaseInfo dbInfo = serverUserInfo.getDatabaseInfo(replInfo.getSlaveList().get(i).getSlaveDbName());
                if (dbInfo == null || dbInfo.getRunningType() == DbRunningType.CS) {
                    isSupported = false;
                    break;
                } else {
                    isSupported = true;
                }
            }
        }
        return isSupported;
    }
    return false;
}
Also used : DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) ServerUserInfo(com.cubrid.cubridmanager.core.common.model.ServerUserInfo) ReplicationInfo(com.cubrid.cubridmanager.core.replication.model.ReplicationInfo) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 7 with ReplicationInfo

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

the class StartSlaveDbAction method run.

/**
	 * Start database and refresh navigator
	 */
public void run() {
    Object[] obj = this.getSelectedObj();
    if (obj == null || obj.length == 0 || !isSupported(obj[0])) {
        setEnabled(false);
        return;
    }
    final ISchemaNode schemaNode = (ISchemaNode) obj[0];
    ReplicationInfo replInfo = (ReplicationInfo) schemaNode.getAdapter(ReplicationInfo.class);
    Set<CubridDatabase> databaseSet = new HashSet<CubridDatabase>();
    for (int j = 0; j < replInfo.getSlaveList().size(); j++) {
        CubridDatabase database = getDatabaseByName(schemaNode.getParent(), replInfo.getSlaveList().get(j).getSlaveDbName());
        databaseSet.add(database);
    }
    final Object[] dbObjectArr = new Object[databaseSet.size()];
    databaseSet.toArray(dbObjectArr);
    ISelectionProvider provider = getSelectionProvider();
    final Shell shell = getShell();
    if (provider instanceof TreeViewer && dbObjectArr.length > 0) {
        final TreeViewer viewer = (TreeViewer) provider;
        TaskExecutor taskExcutor = new TaskExecutor() {

            public boolean exec(final IProgressMonitor monitor) {
                Display display = Display.getDefault();
                if (monitor.isCanceled()) {
                    return false;
                }
                for (int i = 0; i < taskList.size(); i++) {
                    ISchemaNode node = (ISchemaNode) dbObjectArr[i];
                    final CubridDatabase database = node.getDatabase();
                    ITask task = taskList.get(i);
                    task.execute();
                    final String msg = task.getErrorMsg();
                    if (openErrorBox(shell, msg, monitor)) {
                        return false;
                    }
                    if (monitor.isCanceled()) {
                        return false;
                    }
                    database.removeAllChild();
                    if (database.getLoader() != null) {
                        database.getLoader().setLoaded(false);
                    }
                    database.setRunningType(DbRunningType.CS);
                    display.syncExec(new Runnable() {

                        public void run() {
                            viewer.refresh(database, true);
                        }
                    });
                    if (monitor.isCanceled()) {
                        return false;
                    }
                }
                return true;
            }
        };
        for (int i = 0; i < dbObjectArr.length; i++) {
            ISchemaNode node = (ISchemaNode) dbObjectArr[i];
            CubridDatabase database = node.getDatabase();
            CommonUpdateTask task = new CommonUpdateTask(CommonTaskName.START_DB_TASK_NAME, database.getServer().getServerInfo(), CommonSendMsg.getCommonDatabaseSendMsg());
            task.setDbName(database.getLabel());
            taskExcutor.addTask(task);
        }
        new ExecTaskWithProgress(taskExcutor).exec();
        if (taskExcutor.isSuccess()) {
            for (int i = 0; i < dbObjectArr.length; i++) {
                CubridDatabase database = (CubridDatabase) dbObjectArr[i];
                CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(database, CubridNodeChangedEventType.DATABASE_START));
            }
            ActionManager.getInstance().fireSelectionChanged(getSelection());
        }
    }
}
Also used : ITask(com.cubrid.common.core.task.ITask) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) TreeViewer(org.eclipse.jface.viewers.TreeViewer) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) Shell(org.eclipse.swt.widgets.Shell) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) ReplicationInfo(com.cubrid.cubridmanager.core.replication.model.ReplicationInfo) CommonUpdateTask(com.cubrid.cubridmanager.core.common.task.CommonUpdateTask) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) HashSet(java.util.HashSet) Display(org.eclipse.swt.widgets.Display)

Example 8 with ReplicationInfo

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

the class SetDatabaseInfoPage method initialize.

/**
	 * initialize some values
	 */
private void initialize() {
    if (replNode != null && NodeType.DATABASE.equals(replNode.getType())) {
        ReplicationInfo replInfo = (ReplicationInfo) replNode.getAdapter(ReplicationInfo.class);
        if (replInfo != null && replInfo.getMasterList() != null && replInfo.getMasterList().size() > 0) {
            MasterInfo masterInfo = replInfo.getMasterList().get(0);
            ipText.setText(masterInfo.getMasterIp());
            masterDbNameText.setText(masterInfo.getMasterDbName());
        }
        if (replInfo != null && replInfo.getDistInfo() != null) {
            DistributorInfo distInfo = replInfo.getDistInfo();
            distDbNameText.setText(distInfo.getDistDbName());
        }
        if (replInfo != null && replInfo.getSlaveList() != null && replInfo.getSlaveList().size() > 0) {
            SlaveInfo slaveInfo = replInfo.getSlaveList().get(0);
            slaveDbNameText.setText(slaveInfo.getSlaveDbName());
        }
    }
    ipText.setEnabled(false);
    userNameText.setEnabled(false);
    masterDbNameText.setEnabled(false);
    distDbNameText.setEnabled(false);
    slaveDbNameText.setEnabled(false);
    portText.addModifyListener(this);
    passwordText.addModifyListener(this);
    distDbaPasswordText.addModifyListener(this);
}
Also used : MasterInfo(com.cubrid.cubridmanager.core.replication.model.MasterInfo) DistributorInfo(com.cubrid.cubridmanager.core.replication.model.DistributorInfo) ReplicationInfo(com.cubrid.cubridmanager.core.replication.model.ReplicationInfo) SlaveInfo(com.cubrid.cubridmanager.core.replication.model.SlaveInfo)

Example 9 with ReplicationInfo

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

the class CubridDatabaseLoader method loadReplication.

/**
	 * 
	 * Load replication function
	 * 
	 * @param parent the parent node
	 * @param monitor the monitor object
	 * @return <code>true</code> it can be loaded;<code>false</code> otherwise
	 */
private boolean loadReplication(final ICubridNode parent, final IProgressMonitor monitor) {
    CubridDatabase database = (CubridDatabase) parent;
    ServerInfo serverInfo = parent.getServer().getServerInfo();
    ServerUserInfo serverUserInfo = serverInfo.getLoginedUserInfo();
    if (serverUserInfo == null || !serverUserInfo.isAdmin()) {
        return true;
    }
    DbUserInfo dbUserInfo = database.getDatabaseInfo().getAuthLoginedDbUserInfo();
    if (dbUserInfo == null || dbUserInfo.getName() == null || !dbUserInfo.getName().trim().equalsIgnoreCase("DBA")) {
        return true;
    }
    String dbPassword = dbUserInfo.getNoEncryptPassword();
    //add for replication support,only can be supported after version 8.2.2 and in linux OS
    if (serverInfo.isSupportReplication() == 0) {
        final CheckDistributorDbTask checkDistributorDbTask = new CheckDistributorDbTask(serverInfo);
        checkDistributorDbTask.setDistDbName(database.getLabel());
        checkDistributorDbTask.setDbaPassword(dbPassword);
        checkDistributorDbTask.setRunningMode(database.getRunningType() == DbRunningType.CS);
        final GetReplicationInfoTask getReplicationInfoTask = new GetReplicationInfoTask(serverInfo);
        getReplicationInfoTask.setDistDbName(database.getLabel());
        getReplicationInfoTask.setDbaPassword(dbPassword);
        getReplicationInfoTask.setRunningMode(database.getRunningType() == DbRunningType.CS);
        final GetReplicatedTablesTask getReplicatedTablesTask = new GetReplicatedTablesTask(serverInfo);
        getReplicatedTablesTask.setDistdbName(database.getLabel());
        getReplicatedTablesTask.setDistdbPassword(dbPassword);
        getReplicatedTablesTask.setRunningMode(database.getRunningType() == DbRunningType.CS);
        final GetReplicationParamTask getReplicationParamTask = new GetReplicationParamTask(serverInfo);
        getReplicationParamTask.setDistDbName(database.getLabel());
        getReplicationParamTask.setDistDbDbaPasswd(dbPassword);
        getReplicationParamTask.setRunningMode(database.getRunningType() == DbRunningType.CS);
        final GetReplAgentStatusTask getReplAgentStatusTask = new GetReplAgentStatusTask(serverInfo);
        getReplAgentStatusTask.setDbName(database.getLabel());
        monitorCancel(monitor, new ITask[] { checkDistributorDbTask, getReplicationInfoTask, getReplicatedTablesTask, getReplicationParamTask, getReplAgentStatusTask });
        checkDistributorDbTask.execute();
        if (!checkResult(checkDistributorDbTask, monitor)) {
            return false;
        }
        boolean isDistdb = checkDistributorDbTask.isDistributorDb();
        database.getDatabaseInfo().setDistributorDb(isDistdb);
        if (isDistdb) {
            getReplicationInfoTask.execute();
            if (!checkResult(getReplicationInfoTask, monitor)) {
                return false;
            }
            ReplicationInfo replInfo = getReplicationInfoTask.getReplicationInfo();
            database.getDatabaseInfo().setReplInfo(replInfo);
            if (replInfo != null && replInfo.getDistInfo() != null) {
                replInfo.getDistInfo().setDistDbPath(database.getDatabaseInfo().getDbDir());
            }
            if (replInfo != null && replInfo.getMasterList() != null && replInfo.getMasterList().size() > 0 && replInfo.getSlaveList() != null && replInfo.getSlaveList().size() > 0) {
                MasterInfo masterInfo = replInfo.getMasterList().get(0);
                SlaveInfo slaveInfo = replInfo.getSlaveList().get(0);
                getReplicatedTablesTask.setMasterdbName(masterInfo.getMasterDbName());
                getReplicatedTablesTask.setSlavedbName(slaveInfo.getSlaveDbName());
                getReplicatedTablesTask.execute();
                if (!checkResult(getReplicatedTablesTask, monitor)) {
                    return false;
                }
                String[] classNames = getReplicatedTablesTask.getReplicatedTables();
                boolean isReplAll = getReplicatedTablesTask.isReplicateAll();
                if (classNames != null && classNames.length > 0) {
                    masterInfo.setReplTableList(Arrays.asList(classNames));
                }
                masterInfo.setReplAllTable(isReplAll);
                getReplicationParamTask.setMasterDbName(masterInfo.getMasterDbName());
                getReplicationParamTask.setSlaveDbName(replInfo.getSlaveList().get(0).getSlaveDbName());
                getReplicationParamTask.execute();
                if (!checkResult(getReplicationParamTask, monitor)) {
                    return false;
                }
                ReplicationParamInfo paramInfo = getReplicationParamTask.getReplicationParams();
                slaveInfo.setParamInfo(paramInfo);
            }
            getReplAgentStatusTask.execute();
            if (!checkResult(getReplAgentStatusTask, monitor)) {
                return false;
            }
            boolean isActive = getReplAgentStatusTask.isActive();
            replInfo.getDistInfo().setAgentActive(isActive);
        }
    }
    return true;
}
Also used : GetReplicationInfoTask(com.cubrid.cubridmanager.core.replication.task.GetReplicationInfoTask) GetReplAgentStatusTask(com.cubrid.cubridmanager.core.replication.task.GetReplAgentStatusTask) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) GetReplicatedTablesTask(com.cubrid.cubridmanager.core.replication.task.GetReplicatedTablesTask) GetReplicationParamTask(com.cubrid.cubridmanager.core.replication.task.GetReplicationParamTask) DbUserInfo(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo) MasterInfo(com.cubrid.cubridmanager.core.replication.model.MasterInfo) CheckDistributorDbTask(com.cubrid.cubridmanager.core.replication.task.CheckDistributorDbTask) ReplicationParamInfo(com.cubrid.cubridmanager.core.replication.model.ReplicationParamInfo) ServerUserInfo(com.cubrid.cubridmanager.core.common.model.ServerUserInfo) ReplicationInfo(com.cubrid.cubridmanager.core.replication.model.ReplicationInfo) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) SlaveInfo(com.cubrid.cubridmanager.core.replication.model.SlaveInfo)

Example 10 with ReplicationInfo

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

the class DatabaseInfoTest method testGetReplInfo.

/**
	 * Test method for
	 * {@link com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo#getReplInfo()}
	 * .
	 */
public void testGetReplInfo() {
    bean.setReplInfo(new ReplicationInfo());
    assertNotNull(bean.getReplInfo());
}
Also used : ReplicationInfo(com.cubrid.cubridmanager.core.replication.model.ReplicationInfo)

Aggregations

ReplicationInfo (com.cubrid.cubridmanager.core.replication.model.ReplicationInfo)17 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)9 MasterInfo (com.cubrid.cubridmanager.core.replication.model.MasterInfo)6 ISchemaNode (com.cubrid.common.ui.spi.model.ISchemaNode)5 ServerUserInfo (com.cubrid.cubridmanager.core.common.model.ServerUserInfo)5 SlaveInfo (com.cubrid.cubridmanager.core.replication.model.SlaveInfo)5 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)4 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)4 ITask (com.cubrid.common.core.task.ITask)3 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)3 DistributorInfo (com.cubrid.cubridmanager.core.replication.model.DistributorInfo)3 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)3 CubridNodeChangedEvent (com.cubrid.common.ui.spi.event.CubridNodeChangedEvent)2 CommonTaskExec (com.cubrid.common.ui.spi.progress.CommonTaskExec)2 TreeNode (com.cubrid.cubridmanager.core.common.socket.TreeNode)2 CommonUpdateTask (com.cubrid.cubridmanager.core.common.task.CommonUpdateTask)2 ReplicationParamInfo (com.cubrid.cubridmanager.core.replication.model.ReplicationParamInfo)2 HashSet (java.util.HashSet)2 ISelectionProvider (org.eclipse.jface.viewers.ISelectionProvider)2 TreeViewer (org.eclipse.jface.viewers.TreeViewer)2