Search in sources :

Example 1 with Shard

use of com.cubrid.cubridmanager.core.shard.model.Shard in project cubrid-manager by CUBRID.

the class HaShardDemo method registerServiceAndBuildInfo.

/**
	 * For HA, right now, we cannot get the host name from CMS, so need
	 * specified by user.
	 *
	 * @param ip
	 * @param port
	 * @param userName
	 * @param password
	 * @param serviceName
	 * @param connectName
	 * @param nodeName Node name that registered in /etc/hosts.
	 * @return
	 */
public void registerServiceAndBuildInfo(String ip, int port, String userName, String password, String serviceName, String connectName, String nodeName) {
    HaShardManager haShardManager = HaShardManager.getInstance();
    //build server info
    ServerInfo serverInfo = ServerManager.getInstance().getServer(ip, port, userName);
    if (serverInfo == null) {
        serverInfo = new ServerInfo();
        serverInfo.setHostAddress(ip);
        serverInfo.setHostMonPort(port);
        serverInfo.setHostJSPort(port + 1);
        serverInfo.setUserName(userName);
    }
    serverInfo.setServerName(connectName);
    serverInfo.setUserPassword(password);
    serverInfo.setJdbcDriverVersion("Auto Detect");
    // connect to server
    addServer(serverInfo);
    MonitoringTask monitoringTask = serverInfo.getMonitoringTask();
    String clientVersion = "9.3.0";
    serverInfo = monitoringTask.connectServer(clientVersion, 1000);
    if (serverInfo.isConnected()) {
        addServer(serverInfo);
        GetDatabasesParameterTask getDatabasesParameterTask = new GetDatabasesParameterTask(serverInfo);
        getDatabasesParameterTask.execute();
        if (!getDatabasesParameterTask.isSuccess()) {
            return;
        }
        List<Map<String, String>> dbParamMapList = getDatabasesParameterTask.getConfParameters();
        List<DbLocationInfo> dbLocationInfoList = new ArrayList<DbLocationInfo>();
        CMServiceAnalysisUtil.addDbLocaltionInfos(dbParamMapList, dbLocationInfoList);
        // get required info from server and build NodeInfo
        NodeInfo info = getRequiredInfo(serverInfo, dbLocationInfoList);
        if (info != null) {
            info.setDbLocationInfoList(dbLocationInfoList);
            info.setServiceName(serviceName);
            info.setCmConnectName(connectName);
            info.setIp(ip);
            info.setHostName(nodeName);
            info.setServerInfo(serverInfo);
            if (info instanceof ShardNode) {
                Shards shards = ((ShardNode) info).getShards();
                Shard shard = shards.getShardList().get(0);
                List<String> connections = shard.getShardConnectionFile().getConnections();
                for (String s : connections) {
                    String[] ar = s.split(",");
                    if (ip.equals(ar[2]) || nodeName.equals(ar[2])) {
                        //???
                        ((ShardNode) info).setSeverStatus("Shard #" + ar[0]);
                        //???
                        ((ShardNode) info).genStatus();
                    }
                }
            }
            haShardManager.add(info);
        }
    } else {
        removeServer(serverInfo);
    }
}
Also used : ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) GetDatabasesParameterTask(com.cubrid.cubridmanager.core.common.task.GetDatabasesParameterTask) ArrayList(java.util.ArrayList) ShardNode(com.cubrid.cubridmanager.core.cubrid.service.model.ShardNode) NodeInfo(com.cubrid.cubridmanager.core.cubrid.service.model.NodeInfo) MonitoringTask(com.cubrid.cubridmanager.core.common.task.MonitoringTask) Shards(com.cubrid.cubridmanager.core.shard.model.Shards) Shard(com.cubrid.cubridmanager.core.shard.model.Shard) Map(java.util.Map) DbLocationInfo(com.cubrid.cubridmanager.core.cubrid.service.model.DbLocationInfo)

Example 2 with Shard

use of com.cubrid.cubridmanager.core.shard.model.Shard in project cubrid-manager by CUBRID.

the class HaShardDemo method getShardNodeIndo92.

protected NodeInfo getShardNodeIndo92(ServerInfo serverInfo) {
    ShardNode info = null;
    GetBrokerConfParameterTask getBrokerConfParameterTask = new GetBrokerConfParameterTask(serverInfo);
    getBrokerConfParameterTask.execute();
    if (!getBrokerConfParameterTask.isSuccess()) {
        return null;
    }
    Shards shards = new Shards();
    Map<String, Map<String, String>> confParams = getBrokerConfParameterTask.getConfParameters();
    List<Map<String, String>> shardParamsList = new ArrayList<Map<String, String>>();
    for (Entry<String, Map<String, String>> entry : confParams.entrySet()) {
        String brokerName = entry.getKey();
        Map<String, String> params = entry.getValue();
        if (StringUtils.equalsIgnoreCase(params.get("SHARD"), "ON")) {
            shardParamsList.add(params);
            Shard shard = new Shard();
            shard.setName(brokerName.toLowerCase(Locale.getDefault()));
            shard.setProperties(params);
            ShardConnection shardConnection = new ShardConnection();
            shard.setShardConnectionFile(shardConnection);
            GetShardConfTask<ShardConnection> getShardConnectionConfTask = new GetShardConfTask<ShardConnection>(serverInfo, shardConnection);
            getShardConnectionConfTask.execute();
            getShardConnectionConfTask.loadDataToModel();
            shard.setShardConnectionFile(shardConnection);
            shards.addShard(shard);
        }
    }
    if (shardParamsList.size() == 0) {
        return null;
    }
    info = new ShardNode();
    for (Map<String, String> params : shardParamsList) {
        String shardDbName = params.get("SHARD_DB_NAME");
        info.addDatabase(shardDbName);
    }
    GetDatabaseListTask getDatabaseListTask = new GetDatabaseListTask(serverInfo);
    getDatabaseListTask.execute();
    List<DatabaseInfo> databaseInfoList = getDatabaseListTask.loadDatabaseInfo();
    int shardDbCnt = info.getDatabases().size();
    int matchedCnt = 0;
    for (DatabaseInfo dbInfo : databaseInfoList) {
        for (String dbName : info.getDatabases()) {
            if (dbInfo.getDbName().equals(dbName)) {
                if (DbRunningType.CS.equals(dbInfo.getRunningType())) {
                    info.setDbStatus(dbName, "ON");
                } else {
                    info.setDbStatus(dbName, "OFF");
                }
                matchedCnt++;
                if (shardDbCnt <= matchedCnt) {
                    break;
                } else {
                    continue;
                }
            }
        }
    }
    info.setShards(shards);
    return info;
}
Also used : DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) ArrayList(java.util.ArrayList) GetShardConfTask(com.cubrid.cubridmanager.core.shard.task.GetShardConfTask) GetDatabaseListTask(com.cubrid.cubridmanager.core.cubrid.database.task.GetDatabaseListTask) ShardNode(com.cubrid.cubridmanager.core.cubrid.service.model.ShardNode) ShardConnection(com.cubrid.cubridmanager.core.shard.model.ShardConnection) GetBrokerConfParameterTask(com.cubrid.cubridmanager.core.broker.task.GetBrokerConfParameterTask) Shards(com.cubrid.cubridmanager.core.shard.model.Shards) Shard(com.cubrid.cubridmanager.core.shard.model.Shard) Map(java.util.Map)

Example 3 with Shard

use of com.cubrid.cubridmanager.core.shard.model.Shard in project cubrid-manager by CUBRID.

the class ShardsTaskFactory method generateTasks.

public ITask[] generateTasks() {
    ITask[] tasks = new ITask[deletes.size() + updates.size()];
    List<ITask> taskList = new ArrayList<ITask>();
    // if the shard has changed the name?
    for (Shard model : updates) {
        taskList.add(new SaveShardConfTask(this.serverInfo, model.getShardConnectionFile()));
        taskList.add(new SaveShardConfTask(this.serverInfo, model.getShardKeysFile()));
    }
    // Then, update shard.conf file.
    taskList.add(new SaveShardConfTask(this.serverInfo, shards));
    // Finally, delete the connection and key files.
    for (Shard model : deletes) {
        taskList.add(new DeleteShardFileTask(this.serverInfo, model.getName() + "_connection.txt"));
        taskList.add(new DeleteShardFileTask(this.serverInfo, model.getName() + "_key.txt"));
    }
    for (String deleteFileName : deleteFileNames) {
        taskList.add(new DeleteShardFileTask(this.serverInfo, deleteFileName + "_connection.txt"));
        taskList.add(new DeleteShardFileTask(this.serverInfo, deleteFileName + "_key.txt"));
    }
    tasks = taskList.toArray(tasks);
    return tasks;
}
Also used : ITask(com.cubrid.common.core.task.ITask) ArrayList(java.util.ArrayList) Shard(com.cubrid.cubridmanager.core.shard.model.Shard)

Example 4 with Shard

use of com.cubrid.cubridmanager.core.shard.model.Shard in project cubrid-manager by CUBRID.

the class ShardEnvStatusView method refresh.

/**
	 * Refreshes this view
	 * 
	 * @param isUpdateTable
	 *            whether update table
	 * @param isRefreshChanged
	 *            whether refresh changed
	 * 
	 */
public void refresh() {
    ServerInfo site = cubridNode.getServer().getServerInfo();
    Shards shards = new Shards();
    GetShardConfTask<Shards> getShardConfTask = new GetShardConfTask<Shards>(site, shards);
    getShardConfTask.execute();
    if (!getShardConfTask.isSuccess()) {
        CommonUITool.openErrorBox(getShardConfTask.getErrorMsg());
        return;
    }
    getShardConfTask.loadDataToModel();
    GetShardStatusTask getShardStatusTask = new GetShardStatusTask(site, null);
    getShardStatusTask.execute();
    if (!getShardStatusTask.isSuccess()) {
        CommonUITool.openErrorBox(getShardStatusTask.getErrorMsg());
        return;
    }
    ShardsStatus shardsStatus = getShardStatusTask.getShardsStatus();
    Map<String, ShardStatus> tmpCache = new HashMap<String, ShardStatus>();
    List<ShardStatus> newShardInfoList = shardsStatus.getShardStatuss();
    if (newShardInfoList == null) {
        LOGGER.error("The newShardInfoList is a null.");
        return;
    }
    for (int i = 0; newShardInfoList != null && i < newShardInfoList.size(); i++) {
        ShardStatus shard = newShardInfoList.get(i);
        tmpCache.put(shard.getName(), shard);
    }
    List<Shard> shardList = shards.getShardList();
    for (int i = 0; shardList != null && i < shardList.size(); i++) {
        Shard shard = shardList.get(i);
        ShardStatus newShardInfo = tmpCache.get(shard.getName());
        if (newShardInfo == null) {
            newShardInfo = new ShardStatus();
            newShardInfo.setName(shard.getName());
            newShardInfo.setStatus(OnOffType.OFF.getText());
            newShardInfo.setPort(shard.getValue(CubridShardConfParaConstants.BROKER_PORT));
            newShardInfoList.add(newShardInfo);
        } else {
            newShardInfo.setStatus(OnOffType.ON.getText());
        }
    }
    tableViewer.setInput(newShardInfoList);
    tableViewer.refresh();
}
Also used : ShardStatus(com.cubrid.cubridmanager.core.shard.model.ShardStatus) ShardsStatus(com.cubrid.cubridmanager.core.shard.model.ShardsStatus) HashMap(java.util.HashMap) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) GetShardConfTask(com.cubrid.cubridmanager.core.shard.task.GetShardConfTask) Shards(com.cubrid.cubridmanager.core.shard.model.Shards) Shard(com.cubrid.cubridmanager.core.shard.model.Shard) GetShardStatusTask(com.cubrid.cubridmanager.core.shard.task.GetShardStatusTask)

Example 5 with Shard

use of com.cubrid.cubridmanager.core.shard.model.Shard in project cubrid-manager by CUBRID.

the class CubridBrokerLogFolderLoader method load.

/**
	 * 
	 * Load children object for parent
	 * 
	 * @param parent the parent node
	 * @param monitor the IProgressMonitor object
	 */
public void load(ICubridNode parent, final IProgressMonitor monitor) {
    synchronized (this) {
        if (isLoaded()) {
            return;
        }
        // add access and error and admin log folder to broker logs folder
        String[] brokerLogIdArr = { ACCESS_LOG_FOLDER_ID, ERROR_LOG_FOLDER_ID, ADMIN_LOG_FOLDER_ID };
        String[] brokerLogNameArr = { ACCESS_LOG_FOLDER_NAME, ERROR_LOG_FOLDER_NAME, ADMIN_LOG_FOLDER_NAME };
        String[] brokerLogTypeArr = { CubridNodeType.LOGS_BROKER_ACCESS_LOG_FOLDER, CubridNodeType.LOGS_BROKER_ERROR_LOG_FOLDER, CubridNodeType.LOGS_BROKER_ADMIN_LOG_FOLDER };
        String[] iconArr = { "icons/navigator/folder.png", "icons/navigator/folder.png", "icons/navigator/folder.png" };
        ICubridNode[] logFoldrNodeArr = new ICubridNode[3];
        for (int i = 0; i < brokerLogNameArr.length; i++) {
            String id = parent.getId() + NODE_SEPARATOR + brokerLogIdArr[i];
            logFoldrNodeArr[i] = parent.getChild(id);
            if (logFoldrNodeArr[i] == null) {
                logFoldrNodeArr[i] = new DefaultCubridNode(id, brokerLogNameArr[i], iconArr[i]);
                logFoldrNodeArr[i].setType(brokerLogTypeArr[i]);
                logFoldrNodeArr[i].setContainer(true);
                parent.addChild(logFoldrNodeArr[i]);
                if (i == 2) {
                    ICubridNodeLoader loader = new CubridAdminLogFolderLoader();
                    loader.setLevel(getLevel());
                    logFoldrNodeArr[i].setLoader(loader);
                    if (getLevel() == DEFINITE_LEVEL) {
                        logFoldrNodeArr[i].getChildren(monitor);
                    }
                }
            } else {
                if (logFoldrNodeArr[i].getLoader() != null) {
                    logFoldrNodeArr[i].getLoader().setLoaded(false);
                    logFoldrNodeArr[i].getChildren(monitor);
                }
            }
        }
        ServerInfo serverInfo = parent.getServer().getServerInfo();
        BrokerInfos brokerInfos = serverInfo.getBrokerInfos();
        Shards shards = serverInfo.getShards();
        monitorCancel(monitor, new ITask[] { loadBrokersTask, loadBrokrLogInfoTask });
        if (brokerInfos == null && !monitor.isCanceled()) {
            // load all borkers
            brokerInfos = new BrokerInfos();
            loadBrokersTask = new CommonQueryTask<BrokerInfos>(serverInfo, CommonSendMsg.getCommonSimpleSendMsg(), brokerInfos);
            loadBrokersTask.execute();
            final String errorMsg = loadBrokersTask.getErrorMsg();
            if (!monitor.isCanceled() && errorMsg != null && errorMsg.trim().length() > 0) {
                logFoldrNodeArr[0].removeAllChild();
                logFoldrNodeArr[1].removeAllChild();
                openErrorBox(errorMsg);
                setLoaded(true);
                return;
            }
            brokerInfos = loadBrokersTask.getResultModel();
            serverInfo.setBrokerInfos(brokerInfos);
        }
        if (monitor.isCanceled()) {
            setLoaded(true);
            return;
        }
        // load broker log file information
        List<BrokerLogInfos> brokerLogInfosList = new ArrayList<BrokerLogInfos>();
        if (brokerInfos != null) {
            BrokerInfoList list = brokerInfos.getBorkerInfoList();
            if (list != null && list.getBrokerInfoList() != null) {
                List<BrokerInfo> brokerInfoList = list.getBrokerInfoList();
                for (int i = 0; !monitor.isCanceled() && brokerInfoList != null && i < brokerInfoList.size(); i++) {
                    BrokerInfo brokerInfo = brokerInfoList.get(i);
                    BrokerLogInfos brokerLogInfos = new BrokerLogInfos();
                    loadBrokrLogInfoTask = new CommonQueryTask<BrokerLogInfos>(serverInfo, CommonSendMsg.getGetBrokerLogFileInfoMSGItems(), brokerLogInfos);
                    loadBrokrLogInfoTask.setBroker(brokerInfo.getName());
                    loadBrokrLogInfoTask.execute();
                    final String errorMsg = loadBrokrLogInfoTask.getErrorMsg();
                    if (!monitor.isCanceled() && errorMsg != null && errorMsg.trim().length() > 0) {
                        logFoldrNodeArr[0].removeAllChild();
                        logFoldrNodeArr[1].removeAllChild();
                        openErrorBox(errorMsg);
                        setLoaded(true);
                        return;
                    }
                    brokerLogInfos = loadBrokrLogInfoTask.getResultModel();
                    brokerLogInfosList.add(brokerLogInfos);
                }
            }
        }
        // load shard broker log file information
        if (shards != null) {
            List<Shard> shardList = shards.getShardList();
            if (shardList != null) {
                for (int i = 0; i < shardList.size(); i++) {
                    Shard shard = shardList.get(i);
                    BrokerLogInfos brokerLogInfos = new BrokerLogInfos();
                    loadBrokrLogInfoTask = new CommonQueryTask<BrokerLogInfos>(serverInfo, CommonSendMsg.getGetBrokerLogFileInfoMSGItems(), brokerLogInfos);
                    loadBrokrLogInfoTask.setBroker(shard.getName());
                    loadBrokrLogInfoTask.execute();
                    final String errorMsg = loadBrokrLogInfoTask.getErrorMsg();
                    if (!monitor.isCanceled() && errorMsg != null && errorMsg.trim().length() > 0) {
                        logFoldrNodeArr[0].removeAllChild();
                        logFoldrNodeArr[1].removeAllChild();
                        openErrorBox(errorMsg);
                        setLoaded(true);
                        return;
                    }
                    brokerLogInfos = loadBrokrLogInfoTask.getResultModel();
                    brokerLogInfosList.add(brokerLogInfos);
                }
            }
        }
        if (monitor.isCanceled()) {
            setLoaded(true);
            return;
        }
        logFoldrNodeArr[0].removeAllChild();
        logFoldrNodeArr[1].removeAllChild();
        for (BrokerLogInfos brokerLogInfos : brokerLogInfosList) {
            List<LogInfo> logInfoList = brokerLogInfos.getBrokerLogInfoList().getLogFileInfoList();
            if (logInfoList != null && !logInfoList.isEmpty()) {
                for (LogInfo logInfo : logInfoList) {
                    ICubridNode logInfoNode = new DefaultCubridNode("", logInfo.getName(), "");
                    logInfoNode.setContainer(false);
                    logInfoNode.setModelObj(logInfo);
                    logInfoNode.setEditorId(LogEditorPart.ID);
                    if (LogType.ACCESS.getText().toLowerCase().equals(logInfo.getType())) {
                        String id = logFoldrNodeArr[0].getId() + NODE_SEPARATOR + logInfo.getName();
                        logInfoNode.setId(id);
                        logInfoNode.setType(CubridNodeType.LOGS_BROKER_ACCESS_LOG);
                        logInfoNode.setIconPath("icons/navigator/log_item.png");
                        logFoldrNodeArr[0].addChild(logInfoNode);
                    } else if (LogType.ERROR.getText().toLowerCase().equals(logInfo.getType())) {
                        String id = logFoldrNodeArr[1].getId() + NODE_SEPARATOR + logInfo.getName();
                        logInfoNode.setId(id);
                        logInfoNode.setType(CubridNodeType.LOGS_BROKER_ERROR_LOG);
                        logInfoNode.setIconPath("icons/navigator/log_item.png");
                        logFoldrNodeArr[1].addChild(logInfoNode);
                    }
                }
            }
        }
        Collections.sort(logFoldrNodeArr[0].getChildren());
        Collections.sort(logFoldrNodeArr[1].getChildren());
        setLoaded(true);
        CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent((ICubridNode) parent, CubridNodeChangedEventType.CONTAINER_NODE_REFRESH));
        CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(logFoldrNodeArr[0], CubridNodeChangedEventType.CONTAINER_NODE_REFRESH));
        CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(logFoldrNodeArr[1], CubridNodeChangedEventType.CONTAINER_NODE_REFRESH));
    }
}
Also used : DefaultCubridNode(com.cubrid.common.ui.spi.model.DefaultCubridNode) LogInfo(com.cubrid.cubridmanager.core.logs.model.LogInfo) BrokerLogInfos(com.cubrid.cubridmanager.core.logs.model.BrokerLogInfos) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) BrokerInfos(com.cubrid.cubridmanager.core.broker.model.BrokerInfos) ArrayList(java.util.ArrayList) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) BrokerInfoList(com.cubrid.cubridmanager.core.broker.model.BrokerInfoList) BrokerInfo(com.cubrid.cubridmanager.core.broker.model.BrokerInfo) ICubridNodeLoader(com.cubrid.common.ui.spi.model.ICubridNodeLoader) Shards(com.cubrid.cubridmanager.core.shard.model.Shards) Shard(com.cubrid.cubridmanager.core.shard.model.Shard)

Aggregations

Shard (com.cubrid.cubridmanager.core.shard.model.Shard)9 Shards (com.cubrid.cubridmanager.core.shard.model.Shards)7 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)4 GetShardConfTask (com.cubrid.cubridmanager.core.shard.task.GetShardConfTask)4 ArrayList (java.util.ArrayList)4 ShardNode (com.cubrid.cubridmanager.core.cubrid.service.model.ShardNode)3 ShardConnection (com.cubrid.cubridmanager.core.shard.model.ShardConnection)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ITask (com.cubrid.common.core.task.ITask)2 CubridNodeChangedEvent (com.cubrid.common.ui.spi.event.CubridNodeChangedEvent)2 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)2 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)2 GetDatabaseListTask (com.cubrid.cubridmanager.core.cubrid.database.task.GetDatabaseListTask)2 ShardStatus (com.cubrid.cubridmanager.core.shard.model.ShardStatus)2 ShardsStatus (com.cubrid.cubridmanager.core.shard.model.ShardsStatus)2 GetShardStatusTask (com.cubrid.cubridmanager.core.shard.task.GetShardStatusTask)2 DefaultCubridNode (com.cubrid.common.ui.spi.model.DefaultCubridNode)1 ICubridNodeLoader (com.cubrid.common.ui.spi.model.ICubridNodeLoader)1 BrokerInfo (com.cubrid.cubridmanager.core.broker.model.BrokerInfo)1