Search in sources :

Example 1 with GetShardStatusTask

use of com.cubrid.cubridmanager.core.shard.task.GetShardStatusTask in project cubrid-manager by CUBRID.

the class HaShardDemo method getRequiredInfo.

protected NodeInfo getRequiredInfo(ServerInfo serverInfo, List<DbLocationInfo> dbLocationInfoList) {
    NodeInfo info = null;
    //"getallsysparam"/"cubrid.conf"
    GetCubridConfParameterTask getCubridConfParameterTask = new GetCubridConfParameterTask(serverInfo);
    getCubridConfParameterTask.execute();
    if (!getCubridConfParameterTask.isSuccess()) {
        return null;
    }
    Map<String, Map<String, String>> cubConfParas = getCubridConfParameterTask.getConfParameters();
    String haMode = cubConfParas.get("common").get("ha_mode");
    if ("on".equals(haMode) || "replica".equals(haMode)) {
        info = getHaNodeInfo(serverInfo, haMode);
    } else if (CompatibleUtil.isAfter920(serverInfo)) {
        info = getShardNodeIndo92(serverInfo);
        if (info == null && CMServiceAnalysisUtil.isAccessedByRemoteHost(dbLocationInfoList)) {
            info = getBrokerNodeInfo(serverInfo);
        }
    } else {
        GetShardStatusTask getShardStatusTask = new GetShardStatusTask(serverInfo, null);
        getShardStatusTask.execute();
        if (getShardStatusTask.isSuccess()) {
            //check shard
            info = getShardNodeIndo(serverInfo);
            ((ShardNode) info).setShardsStatus(getShardStatusTask.getShardsStatus());
        } else if (CMServiceAnalysisUtil.isAccessedByRemoteHost(dbLocationInfoList)) {
            info = getBrokerNodeInfo(serverInfo);
        }
    }
    return info;
}
Also used : NodeInfo(com.cubrid.cubridmanager.core.cubrid.service.model.NodeInfo) GetCubridConfParameterTask(com.cubrid.cubridmanager.core.common.task.GetCubridConfParameterTask) Map(java.util.Map) GetShardStatusTask(com.cubrid.cubridmanager.core.shard.task.GetShardStatusTask)

Example 2 with GetShardStatusTask

use of com.cubrid.cubridmanager.core.shard.task.GetShardStatusTask 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 3 with GetShardStatusTask

use of com.cubrid.cubridmanager.core.shard.task.GetShardStatusTask in project cubrid-manager by CUBRID.

the class CubridBrokersFolderLoader 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();
        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;
        }
        BrokerInfos brokerInfos = new BrokerInfos();
        final CommonQueryTask<BrokerInfos> task = new CommonQueryTask<BrokerInfos>(serverInfo, CommonSendMsg.getCommonSimpleSendMsg(), brokerInfos);
        monitorCancel(monitor, new ITask[] { task });
        task.execute();
        final String errorMsg = task.getErrorMsg();
        if (!monitor.isCanceled() && errorMsg != null && errorMsg.trim().length() > 0) {
            parent.removeAllChild();
            Display display = Display.getDefault();
            display.syncExec(new Runnable() {

                public void run() {
                    CommonUITool.openErrorBox(errorMsg);
                }
            });
            setLoaded(true);
            return;
        }
        if (monitor.isCanceled()) {
            setLoaded(true);
            return;
        }
        brokerInfos = task.getResultModel();
        List<ICubridNode> oldNodeList = parent.getChildren();
        parent.removeAllChild();
        List<BrokerInfo> brokerInfoList = (brokerInfos == null || brokerInfos.getBorkerInfoList() == null) ? null : brokerInfos.getBorkerInfoList().getBrokerInfoList();
        for (int i = 0; brokerInfoList != null && i < brokerInfoList.size(); i++) {
            BrokerInfo brokerInfo = brokerInfoList.get(i);
            String id = parent.getId() + NODE_SEPARATOR + brokerInfo.getName();
            ICubridNode brokerInfoNode = isContained(oldNodeList, id);
            if (brokerInfoNode == null) {
                brokerInfoNode = new CubridBroker(id, brokerInfo.getName(), "icons/navigator/broker.png");
                ((CubridBroker) brokerInfoNode).setStartedIconPath("icons/navigator/broker_started.png");
                brokerInfoNode.setType(CubridNodeType.BROKER);
                brokerInfoNode.setContainer(true);
                brokerInfoNode.setModelObj(brokerInfo);
                brokerInfoNode.setViewId(BrokerStatusView.ID);
                brokerInfoNode.setLoader(new CubridBrokerFolderLoader());
            } else {
                brokerInfoNode.setModelObj(brokerInfo);
                if (brokerInfoNode.getLoader() != null && brokerInfoNode.getLoader().isLoaded()) {
                    brokerInfoNode.getLoader().setLoaded(false);
                    brokerInfoNode.getChildren(monitor);
                }
            }
            parent.addChild(brokerInfoNode);
        }
        serverInfo.setBrokerInfos(brokerInfos);
        // For the Shard Broker Folder
        if (CompatibleUtil.isSupportShard(serverInfo)) {
            Shards shards = new Shards();
            GetShardConfTask<Shards> getShardConfTask = new GetShardConfTask<Shards>(serverInfo, shards);
            getShardConfTask.execute();
            // !"File(?) open error".equals(errorMsg.trim())) {
            if (getShardConfTask.isSuccess()) {
                GetShardStatusTask getShardStatusTask = new GetShardStatusTask(serverInfo, null);
                getShardStatusTask.execute();
                boolean runningShard = getShardStatusTask.isSuccess();
                serverInfo.setShards(shards);
                shards.setRunning(runningShard);
                String shardFolderId = parent.getId() + NODE_SEPARATOR + SHARD_FOLDER_ID;
                ICubridNode shardFolder = parent.getChild(shardFolderId);
                if (shardFolder == null) {
                    shardFolder = new CubridShardFolder(shardFolderId, SHARD_FOLDER_NAME);
                    ICubridNodeLoader loader = new CubridShardsFolderLoader((CubridShardFolder) shardFolder);
                    loader.setLevel(getLevel());
                    shardFolder.setLoader(loader);
                    parent.addChild(shardFolder);
                // shardFolder.getChildren(monitor);
                } else {
                    if (shardFolder.getLoader() != null && shardFolder.getLoader().isLoaded()) {
                        shardFolder.getLoader().setLoaded(false);
                        shardFolder.getChildren(monitor);
                    }
                }
            }
        }
        Collections.sort(parent.getChildren());
        setLoaded(true);
        CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent((ICubridNode) parent, CubridNodeChangedEventType.CONTAINER_NODE_REFRESH));
    }
}
Also used : ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) BrokerInfos(com.cubrid.cubridmanager.core.broker.model.BrokerInfos) CubridBroker(com.cubrid.cubridmanager.ui.spi.model.CubridBroker) CubridShardFolder(com.cubrid.cubridmanager.ui.spi.model.CubridShardFolder) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) GetShardConfTask(com.cubrid.cubridmanager.core.shard.task.GetShardConfTask) BrokerInfo(com.cubrid.cubridmanager.core.broker.model.BrokerInfo) ICubridNodeLoader(com.cubrid.common.ui.spi.model.ICubridNodeLoader) CommonQueryTask(com.cubrid.cubridmanager.core.common.task.CommonQueryTask) ServerUserInfo(com.cubrid.cubridmanager.core.common.model.ServerUserInfo) Shards(com.cubrid.cubridmanager.core.shard.model.Shards) GetShardStatusTask(com.cubrid.cubridmanager.core.shard.task.GetShardStatusTask) Display(org.eclipse.swt.widgets.Display)

Example 4 with GetShardStatusTask

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

Aggregations

GetShardStatusTask (com.cubrid.cubridmanager.core.shard.task.GetShardStatusTask)4 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)3 Shards (com.cubrid.cubridmanager.core.shard.model.Shards)3 GetShardConfTask (com.cubrid.cubridmanager.core.shard.task.GetShardConfTask)3 CubridNodeChangedEvent (com.cubrid.common.ui.spi.event.CubridNodeChangedEvent)2 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)2 ServerUserInfo (com.cubrid.cubridmanager.core.common.model.ServerUserInfo)2 Shard (com.cubrid.cubridmanager.core.shard.model.Shard)2 ShardStatus (com.cubrid.cubridmanager.core.shard.model.ShardStatus)2 ShardsStatus (com.cubrid.cubridmanager.core.shard.model.ShardsStatus)2 HashMap (java.util.HashMap)2 Display (org.eclipse.swt.widgets.Display)2 ICubridNodeLoader (com.cubrid.common.ui.spi.model.ICubridNodeLoader)1 BrokerInfo (com.cubrid.cubridmanager.core.broker.model.BrokerInfo)1 BrokerInfos (com.cubrid.cubridmanager.core.broker.model.BrokerInfos)1 CommonQueryTask (com.cubrid.cubridmanager.core.common.task.CommonQueryTask)1 GetCubridConfParameterTask (com.cubrid.cubridmanager.core.common.task.GetCubridConfParameterTask)1 NodeInfo (com.cubrid.cubridmanager.core.cubrid.service.model.NodeInfo)1 ShardConnection (com.cubrid.cubridmanager.core.shard.model.ShardConnection)1 ShardKeys (com.cubrid.cubridmanager.core.shard.model.ShardKeys)1