Search in sources :

Example 1 with ServerUserInfo

use of com.cubrid.cubridmanager.core.common.model.ServerUserInfo in project cubrid-manager by CUBRID.

the class SetupEnvTestCase method setupDatabaseInfo.

/**
	 * Setup database 8.4.0
	 *
	 */
private void setupDatabaseInfo() {
    serverInfo = new ServerInfo();
    serverInfo.setHostAddress(host);
    serverInfo.setHostMonPort(monport);
    serverInfo.setHostJSPort(jpport);
    serverInfo.setUserName(userName);
    serverInfo.setUserPassword(passwd);
    serverInfo.setJdbcDriverVersion(serverVersion);
    ServerManager.getInstance().addServer(host, monport, userName, serverInfo);
    MonitoringTask monTask = new MonitoringTask(serverInfo);
    serverInfo = monTask.connectServer(serverVersion, 1000);
    // get the latest token
    token = serverInfo.getHostToken();
    //get evnInfo
    if (envInfo == null) {
        GetEnvInfoTask envTask = new GetEnvInfoTask(serverInfo);
        envTask.loadEnvInfo();
        envTask.execute();
        envInfo = envTask.loadEnvInfo();
        serverInfo.setEnvInfo(envInfo);
    }
    assertNotNull(envInfo);
    serverPath = envInfo.getRootDir();
    dbRootDir = envInfo.getDatabaseDir();
    //get server type
    GetCMConfParameterTask getCMConfParameterTask = new GetCMConfParameterTask(serverInfo);
    getCMConfParameterTask.execute();
    assertEquals(null, getCMConfParameterTask.getErrorMsg());
    Map<String, String> confParameters = getCMConfParameterTask.getConfParameters();
    ServerType serverType = ServerType.BOTH;
    if (confParameters != null) {
        String target = confParameters.get(ConfConstants.CM_TARGET);
        if (target != null) {
            if (target.indexOf("broker") >= 0 && target.indexOf("server") >= 0) {
                serverType = ServerType.BOTH;
            } else if (target.indexOf("broker") >= 0) {
                serverType = ServerType.BROKER;
            } else if (target.indexOf("server") >= 0) {
                serverType = ServerType.DATABASE;
            }
        }
    }
    if (serverInfo != null) {
        serverInfo.setServerType(serverType);
    }
    //Get database list task
    if (serverType == ServerType.DATABASE || serverType == ServerType.BOTH) {
        final GetDatabaseListTask getDatabaseListTask = new GetDatabaseListTask(serverInfo);
        getDatabaseListTask.execute();
        assertEquals(null, getDatabaseListTask.getErrorMsg());
        List<DatabaseInfo> databaseInfoList = getDatabaseListTask.loadDatabaseInfo();
        for (DatabaseInfo dbInfo : databaseInfoList) {
            if (dbInfo.getDbName().equals(testDbName)) {
                databaseInfo = dbInfo;
                break;
            }
        }
        if (databaseInfo == null) {
            return;
        }
    }
    //get CubridManager user list task
    GetCMUserListTask getUserInfoTask = new GetCMUserListTask(serverInfo);
    getUserInfoTask.execute();
    assertEquals(null, getUserInfoTask.getErrorMsg());
    List<ServerUserInfo> serverUserInfoList = getUserInfoTask.getServerUserInfoList();
    for (int i = 0; serverUserInfoList != null && i < serverUserInfoList.size(); i++) {
        ServerUserInfo userInfo = serverUserInfoList.get(i);
        if (userInfo != null && userInfo.getUserName().equals(serverInfo.getUserName())) {
            serverInfo.setLoginedUserInfo(userInfo);
            break;
        }
    }
    List<DatabaseInfo> databaseInfoList = serverInfo.getLoginedUserInfo().getDatabaseInfoList();
    String dbDir = databaseInfo.getDbDir();
    DbRunningType type = databaseInfo.getRunningType();
    for (int i = 0; databaseInfoList != null && i < databaseInfoList.size(); i++) {
        if (testDbName.equalsIgnoreCase(databaseInfoList.get(i).getDbName())) {
            databaseInfo = databaseInfoList.get(i);
            databaseInfo.setDbDir(dbDir);
            databaseInfo.setBrokerIP(host);
            databaseInfo.setBrokerPort(port);
            databaseInfo.setCharSet(charset);
            databaseInfo.setRunningType(type);
            break;
        }
    }
    //get CUBRID conf parameter
    GetCubridConfParameterTask getCubridConfParameterTask = new GetCubridConfParameterTask(serverInfo);
    getCubridConfParameterTask.execute();
    assertEquals(null, getCubridConfParameterTask.getErrorMsg());
    Map<String, Map<String, String>> confParas = getCubridConfParameterTask.getConfParameters();
    if (serverInfo != null) {
        serverInfo.setCubridConfParaMap(confParas);
    }
    //get broker Info
    GetBrokerConfParameterTask getBrokerConfParameterTask = new GetBrokerConfParameterTask(serverInfo);
    getBrokerConfParameterTask.execute();
    assertEquals(null, getBrokerConfParameterTask.getErrorMsg());
    confParas = getBrokerConfParameterTask.getConfParameters();
    if (serverInfo != null) {
        serverInfo.setBrokerConfParaMap(confParas);
    }
    //Set JDBC driver
    String filePath = this.getFilePathInPlugin("/lib/JDBC-8.3.0.1004-cubrid.jar");
    if (filePath != null) {
        String version = JdbcClassLoaderFactory.validateJdbcFile(filePath);
        if (version != null) {
            JdbcClassLoaderFactory.registerClassLoader(filePath);
            serverInfo.setJdbcDriverVersion(version);
        }
    }
    filePath = this.getFilePathInPlugin("/lib/JDBC-8.3.1.0173-cubrid.jar");
    if (filePath != null) {
        String version = JdbcClassLoaderFactory.validateJdbcFile(filePath);
        if (version != null) {
            JdbcClassLoaderFactory.registerClassLoader(filePath);
            serverInfo.setJdbcDriverVersion(version);
        }
    }
    filePath = this.getFilePathInPlugin("/lib/JDBC-8.4.0.0196-cubrid.jar");
    if (filePath != null) {
        String version = JdbcClassLoaderFactory.validateJdbcFile(filePath);
        if (version != null) {
            JdbcClassLoaderFactory.registerClassLoader(filePath);
            serverInfo.setJdbcDriverVersion(version);
        }
    }
}
Also used : ServerType(com.cubrid.cubridmanager.core.common.model.ServerType) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) GetCMUserListTask(com.cubrid.cubridmanager.core.common.task.GetCMUserListTask) GetCubridConfParameterTask(com.cubrid.cubridmanager.core.common.task.GetCubridConfParameterTask) GetEnvInfoTask(com.cubrid.cubridmanager.core.common.task.GetEnvInfoTask) GetDatabaseListTask(com.cubrid.cubridmanager.core.cubrid.database.task.GetDatabaseListTask) GetCMConfParameterTask(com.cubrid.cubridmanager.core.common.task.GetCMConfParameterTask) MonitoringTask(com.cubrid.cubridmanager.core.common.task.MonitoringTask) ServerUserInfo(com.cubrid.cubridmanager.core.common.model.ServerUserInfo) GetBrokerConfParameterTask(com.cubrid.cubridmanager.core.broker.task.GetBrokerConfParameterTask) DbRunningType(com.cubrid.cubridmanager.core.common.model.DbRunningType) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with ServerUserInfo

use of com.cubrid.cubridmanager.core.common.model.ServerUserInfo in project cubrid-manager by CUBRID.

the class SetupEnvTestCase method setupDatabaseInfo930.

/**
	 * Setup database 9.3.0
	 *
	 */
private void setupDatabaseInfo930() throws Exception {
    serverInfo930 = new ServerInfo();
    serverInfo930.setHostAddress(host930);
    serverInfo930.setHostMonPort(monport930);
    serverInfo930.setHostJSPort(jpport930);
    serverInfo930.setUserName(userName930);
    serverInfo930.setUserPassword(passwd930);
    serverInfo930.setJdbcDriverVersion(serverVersion930);
    ServerManager.getInstance().addServer(host930, monport930, userName930, serverInfo930);
    MonitoringTask monTask = new MonitoringTask(serverInfo930);
    serverInfo930 = monTask.connectServer(serverVersion930, 1000);
    // get the latest token
    token930 = serverInfo930.getHostToken();
    //get evnInfo
    if (envInfo930 == null) {
        GetEnvInfoTask envTask = new GetEnvInfoTask(serverInfo930);
        envTask.loadEnvInfo();
        envTask.execute();
        envInfo930 = envTask.loadEnvInfo();
        serverInfo930.setEnvInfo(envInfo930);
    }
    assertNotNull(envInfo930);
    serverPath930 = envInfo930.getRootDir();
    dbRootDir930 = envInfo930.getDatabaseDir();
    //get server type
    GetCMConfParameterTask getCMConfParameterTask = new GetCMConfParameterTask(serverInfo930);
    getCMConfParameterTask.execute();
    assertEquals(null, getCMConfParameterTask.getErrorMsg());
    Map<String, String> confParameters = getCMConfParameterTask.getConfParameters();
    ServerType serverType = ServerType.BOTH;
    if (confParameters != null) {
        String target = confParameters.get(ConfConstants.CM_TARGET);
        if (target != null) {
            if (target.indexOf("broker") >= 0 && target.indexOf("server") >= 0) {
                serverType = ServerType.BOTH;
            } else if (target.indexOf("broker") >= 0) {
                serverType = ServerType.BROKER;
            } else if (target.indexOf("server") >= 0) {
                serverType = ServerType.DATABASE;
            }
        }
    }
    if (serverInfo930 != null) {
        serverInfo930.setServerType(serverType);
    }
    //Get database list task
    if (serverType == ServerType.DATABASE || serverType == ServerType.BOTH) {
        final GetDatabaseListTask getDatabaseListTask = new GetDatabaseListTask(serverInfo930);
        getDatabaseListTask.execute();
        assertEquals(null, getDatabaseListTask.getErrorMsg());
        List<DatabaseInfo> databaseInfoList = getDatabaseListTask.loadDatabaseInfo();
        for (DatabaseInfo dbInfo : databaseInfoList) {
            if (dbInfo.getDbName().equals(testDbName930)) {
                databaseInfo930 = dbInfo;
                break;
            }
        }
        if (databaseInfo930 == null) {
            return;
        }
    }
    //get CubridManager user list task
    GetCMUserListTask getUserInfoTask = new GetCMUserListTask(serverInfo930);
    getUserInfoTask.execute();
    assertEquals(null, getUserInfoTask.getErrorMsg());
    List<ServerUserInfo> serverUserInfoList = getUserInfoTask.getServerUserInfoList();
    for (int i = 0; serverUserInfoList != null && i < serverUserInfoList.size(); i++) {
        ServerUserInfo userInfo = serverUserInfoList.get(i);
        if (userInfo != null && userInfo.getUserName().equals(serverInfo930.getUserName())) {
            serverInfo930.setLoginedUserInfo(userInfo);
            break;
        }
    }
    List<DatabaseInfo> databaseInfoList = serverInfo930.getLoginedUserInfo().getDatabaseInfoList();
    String dbDir = databaseInfo930.getDbDir();
    DbRunningType type = databaseInfo930.getRunningType();
    for (int i = 0; databaseInfoList != null && i < databaseInfoList.size(); i++) {
        if (testDbName930.equalsIgnoreCase(databaseInfoList.get(i).getDbName())) {
            databaseInfo930 = databaseInfoList.get(i);
            databaseInfo930.setDbDir(dbDir);
            databaseInfo930.setBrokerIP(host930);
            databaseInfo930.setBrokerPort(port930);
            databaseInfo930.setCharSet(charset930);
            databaseInfo930.setRunningType(type);
            break;
        }
    }
    //get CUBRID conf parameter
    GetCubridConfParameterTask getCubridConfParameterTask = new GetCubridConfParameterTask(serverInfo930);
    getCubridConfParameterTask.execute();
    assertEquals(null, getCubridConfParameterTask.getErrorMsg());
    Map<String, Map<String, String>> confParas = getCubridConfParameterTask.getConfParameters();
    if (serverInfo930 != null) {
        serverInfo930.setCubridConfParaMap(confParas);
    }
    //get broker Info
    GetBrokerConfParameterTask getBrokerConfParameterTask = new GetBrokerConfParameterTask(serverInfo930);
    getBrokerConfParameterTask.execute();
    assertEquals(null, getBrokerConfParameterTask.getErrorMsg());
    confParas = getBrokerConfParameterTask.getConfParameters();
    if (serverInfo930 != null) {
        serverInfo930.setBrokerConfParaMap(confParas);
    }
    //Set JDBC driver
    String filePath = this.getFilePathInPlugin("/lib/JDBC-9.2.0.0155-cubrid.jar");
    if (filePath != null) {
        String version = JdbcClassLoaderFactory.validateJdbcFile(filePath);
        if (version != null) {
            JdbcClassLoaderFactory.registerClassLoader(filePath);
            serverInfo930.setJdbcDriverVersion(version);
        }
    }
}
Also used : ServerType(com.cubrid.cubridmanager.core.common.model.ServerType) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) GetCMUserListTask(com.cubrid.cubridmanager.core.common.task.GetCMUserListTask) GetCubridConfParameterTask(com.cubrid.cubridmanager.core.common.task.GetCubridConfParameterTask) GetEnvInfoTask(com.cubrid.cubridmanager.core.common.task.GetEnvInfoTask) GetDatabaseListTask(com.cubrid.cubridmanager.core.cubrid.database.task.GetDatabaseListTask) GetCMConfParameterTask(com.cubrid.cubridmanager.core.common.task.GetCMConfParameterTask) MonitoringTask(com.cubrid.cubridmanager.core.common.task.MonitoringTask) ServerUserInfo(com.cubrid.cubridmanager.core.common.model.ServerUserInfo) GetBrokerConfParameterTask(com.cubrid.cubridmanager.core.broker.task.GetBrokerConfParameterTask) DbRunningType(com.cubrid.cubridmanager.core.common.model.DbRunningType) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with ServerUserInfo

use of com.cubrid.cubridmanager.core.common.model.ServerUserInfo in project cubrid-manager by CUBRID.

the class SetupEnvTestCase method loginTestDatabase.

protected void loginTestDatabase() {
    if (databaseInfo.isLogined()) {
        return;
    }
    LoginDatabaseTask loginDatabaseTask = new LoginDatabaseTask(serverInfo);
    loginDatabaseTask.setCMUser(userName);
    loginDatabaseTask.setDbName(testDbName);
    loginDatabaseTask.setDbUser(dbaUserName);
    loginDatabaseTask.setDbPassword(dbaPassword);
    loginDatabaseTask.execute();
    assertEquals(null, loginDatabaseTask.getErrorMsg());
    DbUserInfo dbUserInfo = loginDatabaseTask.getLoginedDbUserInfo();
    dbUserInfo.setNoEncryptPassword(dbaPassword);
    databaseInfo.setLogined(true);
    databaseInfo.setAuthLoginedDbUserInfo(dbUserInfo);
    UpdateCMUserTask updateCMUserTask = new UpdateCMUserTask(serverInfo);
    updateCMUserTask.setCmUserName(userName);
    ServerUserInfo userInfo = serverInfo.getLoginedUserInfo();
    updateCMUserTask.setCasAuth(userInfo.getCasAuth().getText());
    updateCMUserTask.setDbCreator(userInfo.getDbCreateAuthType().getText());
    updateCMUserTask.setStatusMonitorAuth(userInfo.getStatusMonitorAuth().getText());
    List<String> dbNameList = new ArrayList<String>();
    List<String> dbUserList = new ArrayList<String>();
    List<String> dbPasswordList = new ArrayList<String>();
    List<String> dbBrokerPortList = new ArrayList<String>();
    List<DatabaseInfo> authDatabaseList = userInfo.getDatabaseInfoList();
    if (authDatabaseList != null && !authDatabaseList.isEmpty()) {
        int size = authDatabaseList.size();
        for (int i = 0; i < size; i++) {
            DatabaseInfo databaseInfo = authDatabaseList.get(i);
            dbNameList.add(databaseInfo.getDbName());
            dbUserList.add(databaseInfo.getAuthLoginedDbUserInfo().getName());
            dbBrokerPortList.add(databaseInfo.getBrokerIP() + "," + databaseInfo.getBrokerPort());
            String password = databaseInfo.getAuthLoginedDbUserInfo().getNoEncryptPassword();
            dbPasswordList.add(password == null ? "" : password);
        }
    }
    String[] dbNameArr = new String[dbNameList.size()];
    String[] dbUserArr = new String[dbUserList.size()];
    String[] dbPasswordArr = new String[dbPasswordList.size()];
    String[] dbBrokerPortArr = new String[dbBrokerPortList.size()];
    updateCMUserTask.setDbAuth(dbNameList.toArray(dbNameArr), dbUserList.toArray(dbUserArr), dbPasswordList.toArray(dbPasswordArr), dbBrokerPortList.toArray(dbBrokerPortArr));
    updateCMUserTask.execute();
    assertEquals(null, updateCMUserTask.getErrorMsg());
}
Also used : DbUserInfo(com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo) LoginDatabaseTask(com.cubrid.cubridmanager.core.cubrid.database.task.LoginDatabaseTask) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) UpdateCMUserTask(com.cubrid.cubridmanager.core.common.task.UpdateCMUserTask) ArrayList(java.util.ArrayList) ServerUserInfo(com.cubrid.cubridmanager.core.common.model.ServerUserInfo)

Example 4 with ServerUserInfo

use of com.cubrid.cubridmanager.core.common.model.ServerUserInfo in project cubrid-manager by CUBRID.

the class PropertyAction method isSupported.

/**
	 * 
	 * Return whether this action support this object,if not support,this action
	 * will be disabled
	 * 
	 * @param obj the Object
	 * @return <code>true</code> if support this obj;<code>false</code>
	 *         otherwise
	 */
public boolean isSupported(Object obj) {
    if (obj instanceof ICubridNode) {
        ICubridNode node = (ICubridNode) obj;
        CubridServer server = node.getServer();
        if (server == null || !server.isConnected()) {
            return false;
        }
        ServerUserInfo userInfo = server.getServerInfo().getLoginedUserInfo();
        String type = node.getType();
        if (CubridNodeType.SERVER.equals(type) || CubridNodeType.DATABASE_FOLDER.equals(type) || CubridNodeType.DATABASE.equals(type)) {
            return true;
        } else if (CubridNodeType.BROKER_FOLDER.equals(type) || CubridNodeType.BROKER.equals(type) || CubridNodeType.SHARD_FOLDER.equals(type) || CubridNodeType.SHARD.equals(type)) {
            return userInfo != null && (CasAuthType.AUTH_ADMIN == userInfo.getCasAuth() || CasAuthType.AUTH_MONITOR == userInfo.getCasAuth());
        }
    }
    return false;
}
Also used : ServerUserInfo(com.cubrid.cubridmanager.core.common.model.ServerUserInfo) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) CubridServer(com.cubrid.common.ui.spi.model.CubridServer)

Example 5 with ServerUserInfo

use of com.cubrid.cubridmanager.core.common.model.ServerUserInfo in project cubrid-manager by CUBRID.

the class ConnectHostExecutor method updateCMUserAuthInfo.

/**
	 * Construct the CM user authorization information
	 *
	 * @param task the UpdateCMUserTask object
	 * @param isRunUpdateCmUserTask whether update CM user task
	 */
private void updateCMUserAuthInfo(ITask task, boolean isRunUpdateCmUserTask) {
    if (isRunUpdateCmUserTask && serverInfo != null && serverInfo.isConnected()) {
        UpdateCMUserTask updateCMUserTask = (UpdateCMUserTask) task;
        ServerUserInfo userInfo = serverInfo.getLoginedUserInfo();
        updateCMUserTask.setCasAuth(userInfo.getCasAuth().getText());
        updateCMUserTask.setDbCreator(userInfo.getDbCreateAuthType().getText());
        updateCMUserTask.setStatusMonitorAuth(userInfo.getStatusMonitorAuth().getText());
        List<String> dbNameList = new ArrayList<String>();
        List<String> dbUserList = new ArrayList<String>();
        List<String> dbPasswordList = new ArrayList<String>();
        List<String> dbBrokerPortList = new ArrayList<String>();
        if (authDatabaseList != null && !authDatabaseList.isEmpty()) {
            int size = authDatabaseList.size();
            for (int i = 0; i < size; i++) {
                DatabaseInfo databaseInfo = authDatabaseList.get(i);
                dbNameList.add(databaseInfo.getDbName());
                dbUserList.add(databaseInfo.getAuthLoginedDbUserInfo().getName());
                dbBrokerPortList.add(QueryOptions.getBrokerIp(databaseInfo) + "," + databaseInfo.getBrokerPort());
                String password = databaseInfo.getAuthLoginedDbUserInfo().getNoEncryptPassword();
                dbPasswordList.add(password == null ? "" : password);
            }
        }
        String[] dbNameArr = new String[dbNameList.size()];
        String[] dbUserArr = new String[dbUserList.size()];
        String[] dbPasswordArr = new String[dbPasswordList.size()];
        String[] dbBrokerPortArr = new String[dbBrokerPortList.size()];
        updateCMUserTask.setDbAuth(dbNameList.toArray(dbNameArr), dbUserList.toArray(dbUserArr), dbPasswordList.toArray(dbPasswordArr), dbBrokerPortList.toArray(dbBrokerPortArr));
        updateCMUserTask.execute();
    }
}
Also used : DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) UpdateCMUserTask(com.cubrid.cubridmanager.core.common.task.UpdateCMUserTask) ArrayList(java.util.ArrayList) ServerUserInfo(com.cubrid.cubridmanager.core.common.model.ServerUserInfo)

Aggregations

ServerUserInfo (com.cubrid.cubridmanager.core.common.model.ServerUserInfo)101 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)33 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)23 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)21 CubridServer (com.cubrid.common.ui.spi.model.CubridServer)19 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)18 ArrayList (java.util.ArrayList)16 UpdateCMUserTask (com.cubrid.cubridmanager.core.common.task.UpdateCMUserTask)12 ServerType (com.cubrid.cubridmanager.core.common.model.ServerType)10 DbUserInfo (com.cubrid.cubridmanager.core.cubrid.user.model.DbUserInfo)10 CubridNodeChangedEvent (com.cubrid.common.ui.spi.event.CubridNodeChangedEvent)9 GetCMUserListTask (com.cubrid.cubridmanager.core.common.task.GetCMUserListTask)8 GetDatabaseListTask (com.cubrid.cubridmanager.core.cubrid.database.task.GetDatabaseListTask)8 CubridBrokerFolder (com.cubrid.cubridmanager.ui.spi.model.CubridBrokerFolder)8 Map (java.util.Map)8 MonitoringTask (com.cubrid.cubridmanager.core.common.task.MonitoringTask)7 ITask (com.cubrid.common.core.task.ITask)6 BrokerInfos (com.cubrid.cubridmanager.core.broker.model.BrokerInfos)6 GetBrokerConfParameterTask (com.cubrid.cubridmanager.core.broker.task.GetBrokerConfParameterTask)6 GetCMConfParameterTask (com.cubrid.cubridmanager.core.common.task.GetCMConfParameterTask)6