Search in sources :

Example 1 with ShardConnection

use of com.cubrid.cubridmanager.core.shard.model.ShardConnection 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 2 with ShardConnection

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

the class CubridShardsFolderLoader 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;
        }
        ServerInfo serverInfo = parent.getServer().getServerInfo();
        if (serverInfo == null) {
            LOGGER.error("The serverInfo is a null.");
            return;
        }
        ServerUserInfo userInfo = serverInfo.getLoginedUserInfo();
        if (userInfo == null || CasAuthType.AUTH_NONE == userInfo.getCasAuth()) {
            parent.removeAllChild();
            CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent((ICubridNode) parent, CubridNodeChangedEventType.CONTAINER_NODE_REFRESH));
            return;
        }
        Display display = Display.getDefault();
        boolean statusTag = false;
        boolean confTag = false;
        Shards shards = new Shards();
        GetShardConfTask<Shards> getShardConfTask = new GetShardConfTask<Shards>(serverInfo, shards);
        monitorCancel(monitor, new ITask[] { getShardConfTask });
        getShardConfTask.execute();
        if (!monitor.isCanceled() && !getShardConfTask.isSuccess()) {
            final String errorMsg = getShardConfTask.getErrorMsg();
            confTag = false;
            cubridShardFolder.setEnable(false);
            parent.removeAllChild();
            display.syncExec(new Runnable() {

                public void run() {
                    CommonUITool.openErrorBox(errorMsg);
                }
            });
            setLoaded(true);
        // return;
        } else {
            confTag = true;
            getShardConfTask.loadDataToModel();
            serverInfo.setShards(shards);
        }
        GetShardStatusTask getShardStatusTask = new GetShardStatusTask(serverInfo, null);
        monitorCancel(monitor, new ITask[] { getShardStatusTask });
        getShardStatusTask.execute();
        ShardsStatus shardsStatus = null;
        if (getShardStatusTask.isSuccess()) {
            shardsStatus = getShardStatusTask.getShardsStatus();
            cubridShardFolder.setRunning(true);
            statusTag = true;
        } else {
            final String errorMsg = getShardStatusTask.getErrorMsg();
            if (!monitor.isCanceled() && errorMsg != null && errorMsg.trim().length() > 0) {
                statusTag = false;
                if (errorMsg.trim().contains("cubrid shard is not running")) {
                    cubridShardFolder.setRunning(false);
                    parent.removeAllChild();
                // return;
                } else {
                    display.syncExec(new Runnable() {

                        public void run() {
                            CommonUITool.openErrorBox(errorMsg);
                        }
                    });
                }
            }
        }
        if (monitor.isCanceled()) {
            setLoaded(true);
            return;
        }
        List<ICubridNode> oldNodeList = parent.getChildren();
        parent.removeAllChild();
        Map<String, ShardStatus> tmpCache = new HashMap<String, ShardStatus>();
        if (statusTag) {
            List<ShardStatus> shardStatuss = (shardsStatus == null || shardsStatus.getShardStatuss() == null) ? null : shardsStatus.getShardStatuss();
            for (int i = 0; shardStatuss != null && i < shardStatuss.size(); i++) {
                ShardStatus shard = shardStatuss.get(i);
                tmpCache.put(shard.getName(), shard);
            }
        }
        if (confTag) {
            List<Shard> shardList = (shards == null || shards.getShardList() == null) ? null : shards.getShardList();
            for (int i = 0; shardList != null && i < shardList.size(); i++) {
                Shard shard = shardList.get(i);
                //
                ShardConnection shardConnection = new ShardConnection();
                shard.setShardConnectionFile(shardConnection);
                GetShardConfTask<ShardConnection> getShardConnectionConfTask = new GetShardConfTask<ShardConnection>(serverInfo, shardConnection);
                getShardConnectionConfTask.execute();
                getShardConnectionConfTask.loadDataToModel();
                ShardKeys shardKeys = new ShardKeys();
                shard.setShardKeysFile(shardKeys);
                GetShardConfTask<ShardKeys> getShardKeyConfTask = new GetShardConfTask<ShardKeys>(serverInfo, shardKeys);
                getShardKeyConfTask.execute();
                getShardKeyConfTask.loadDataToModel();
                //
                String id = parent.getId() + NODE_SEPARATOR + shard.getName();
                ICubridNode shardNode = isContained(oldNodeList, id);
                ShardStatus shardStatus = tmpCache.get(shard.getName());
                String shardLabel = shardStatus != null ? " (" + shardStatus.getPort() + "," + shardStatus.getAccessMode() + ")" : "";
                if (shardNode == null) {
                    shardNode = new CubridShard(id, shard.getName() + shardLabel);
                    ((CubridShard) shardNode).setName(shard.getName());
                    shardNode.setType(CubridNodeType.SHARD);
                    shardNode.setContainer(true);
                    shardNode.setModelObj(shard);
                    shardNode.setLoader(new CubridShardFolderLoader());
                } else {
                    shardNode.setModelObj(shard);
                    if (shardNode.getLoader() != null && shardNode.getLoader().isLoaded()) {
                        shardNode.getLoader().setLoaded(false);
                        shardNode.getChildren(monitor);
                    }
                }
                ((CubridShard) shardNode).setRunning(shardStatus != null);
                parent.addChild(shardNode);
            }
        }
        Collections.sort(parent.getChildren());
        setLoaded(true);
        CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent((ICubridNode) parent, CubridNodeChangedEventType.CONTAINER_NODE_REFRESH));
    }
}
Also used : ShardStatus(com.cubrid.cubridmanager.core.shard.model.ShardStatus) ShardKeys(com.cubrid.cubridmanager.core.shard.model.ShardKeys) HashMap(java.util.HashMap) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) GetShardConfTask(com.cubrid.cubridmanager.core.shard.task.GetShardConfTask) ShardConnection(com.cubrid.cubridmanager.core.shard.model.ShardConnection) CubridShard(com.cubrid.cubridmanager.ui.spi.model.CubridShard) ServerUserInfo(com.cubrid.cubridmanager.core.common.model.ServerUserInfo) ShardsStatus(com.cubrid.cubridmanager.core.shard.model.ShardsStatus) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) Shards(com.cubrid.cubridmanager.core.shard.model.Shards) CubridShard(com.cubrid.cubridmanager.ui.spi.model.CubridShard) Shard(com.cubrid.cubridmanager.core.shard.model.Shard) GetShardStatusTask(com.cubrid.cubridmanager.core.shard.task.GetShardStatusTask) Display(org.eclipse.swt.widgets.Display)

Example 3 with ShardConnection

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

the class HaShardDemo method getShardNodeIndo.

protected NodeInfo getShardNodeIndo(ServerInfo serverInfo) {
    ShardNode nodeInfo = new ShardNode();
    Shards shards = new Shards();
    GetShardConfTask<Shards> getShardConfTask = new GetShardConfTask<Shards>(serverInfo, shards);
    getShardConfTask.execute();
    if (!getShardConfTask.isSuccess()) {
        return null;
    }
    getShardConfTask.loadDataToModel();
    serverInfo.setShards(shards);
    List<Shard> shardList = shards.getShardList();
    for (int i = 0; shardList != null && i < shardList.size(); i++) {
        Shard shard = shardList.get(i);
        String dbName = shard.getValue("SHARD_DB_NAME");
        nodeInfo.addDatabase(dbName);
        ShardConnection shardConnection = new ShardConnection();
        shard.setShardConnectionFile(shardConnection);
        GetShardConfTask<ShardConnection> getShardConnectionConfTask = new GetShardConfTask<ShardConnection>(serverInfo, shardConnection);
        getShardConnectionConfTask.execute();
        getShardConnectionConfTask.loadDataToModel();
    }
    GetDatabaseListTask getDatabaseListTask = new GetDatabaseListTask(serverInfo);
    getDatabaseListTask.execute();
    List<DatabaseInfo> databaseInfoList = getDatabaseListTask.loadDatabaseInfo();
    int shardDbCnt = nodeInfo.getDatabases().size();
    int matchedCnt = 0;
    for (DatabaseInfo dbInfo : databaseInfoList) {
        for (String dbName : nodeInfo.getDatabases()) {
            if (dbInfo.getDbName().equals(dbName)) {
                if (DbRunningType.CS.equals(dbInfo.getRunningType())) {
                    nodeInfo.setDbStatus(dbName, "ON");
                } else {
                    nodeInfo.setDbStatus(dbName, "OFF");
                }
                matchedCnt++;
                if (shardDbCnt <= matchedCnt) {
                    break;
                } else {
                    continue;
                }
            }
        }
    }
    nodeInfo.setShards(shards);
    return nodeInfo;
}
Also used : DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) 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) Shards(com.cubrid.cubridmanager.core.shard.model.Shards) Shard(com.cubrid.cubridmanager.core.shard.model.Shard)

Example 4 with ShardConnection

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

the class AddShardWizard method addPages.

public void addPages() {
    shards.addShard(shard);
    ShardConnection shardConnectionFile = new ShardConnection();
    shard.setShardConnectionFile(shardConnectionFile);
    ShardKeys shardKeysFile = new ShardKeys();
    shard.setShardKeysFile(shardKeysFile);
    shardWizardBrokerInfoPage = new ShardWizardBrokerInfoPage(shards, shard, server.getServerInfo());
    addPage(shardWizardBrokerInfoPage);
    ahardWizardConnectionPage = new ShardWizardConnectionPage(shardConnectionFile);
    addPage(ahardWizardConnectionPage);
    shardWizardKeysPage = new ShardWizardKeysPage(shard);
    addPage(shardWizardKeysPage);
    shardWizardAllInfoPage = new ShardWizardAllInfoPage(shards, shard);
    addPage(shardWizardAllInfoPage);
}
Also used : ShardKeys(com.cubrid.cubridmanager.core.shard.model.ShardKeys) ShardConnection(com.cubrid.cubridmanager.core.shard.model.ShardConnection)

Aggregations

ShardConnection (com.cubrid.cubridmanager.core.shard.model.ShardConnection)4 Shard (com.cubrid.cubridmanager.core.shard.model.Shard)3 Shards (com.cubrid.cubridmanager.core.shard.model.Shards)3 GetShardConfTask (com.cubrid.cubridmanager.core.shard.task.GetShardConfTask)3 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)2 GetDatabaseListTask (com.cubrid.cubridmanager.core.cubrid.database.task.GetDatabaseListTask)2 ShardNode (com.cubrid.cubridmanager.core.cubrid.service.model.ShardNode)2 ShardKeys (com.cubrid.cubridmanager.core.shard.model.ShardKeys)2 CubridNodeChangedEvent (com.cubrid.common.ui.spi.event.CubridNodeChangedEvent)1 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)1 GetBrokerConfParameterTask (com.cubrid.cubridmanager.core.broker.task.GetBrokerConfParameterTask)1 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)1 ServerUserInfo (com.cubrid.cubridmanager.core.common.model.ServerUserInfo)1 ShardStatus (com.cubrid.cubridmanager.core.shard.model.ShardStatus)1 ShardsStatus (com.cubrid.cubridmanager.core.shard.model.ShardsStatus)1 GetShardStatusTask (com.cubrid.cubridmanager.core.shard.task.GetShardStatusTask)1 CubridShard (com.cubrid.cubridmanager.ui.spi.model.CubridShard)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1