Search in sources :

Example 1 with GetReplicationInfoTask

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

Aggregations

CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)1 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)1 ServerUserInfo (com.cubrid.cubridmanager.core.common.model.ServerUserInfo)1 DbUserInfo (com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo)1 MasterInfo (com.cubrid.cubridmanager.core.replication.model.MasterInfo)1 ReplicationInfo (com.cubrid.cubridmanager.core.replication.model.ReplicationInfo)1 ReplicationParamInfo (com.cubrid.cubridmanager.core.replication.model.ReplicationParamInfo)1 SlaveInfo (com.cubrid.cubridmanager.core.replication.model.SlaveInfo)1 CheckDistributorDbTask (com.cubrid.cubridmanager.core.replication.task.CheckDistributorDbTask)1 GetReplAgentStatusTask (com.cubrid.cubridmanager.core.replication.task.GetReplAgentStatusTask)1 GetReplicatedTablesTask (com.cubrid.cubridmanager.core.replication.task.GetReplicatedTablesTask)1 GetReplicationInfoTask (com.cubrid.cubridmanager.core.replication.task.GetReplicationInfoTask)1 GetReplicationParamTask (com.cubrid.cubridmanager.core.replication.task.GetReplicationParamTask)1