Search in sources :

Example 46 with IXMLMemento

use of com.cubrid.cubridmanager.core.common.xml.IXMLMemento in project cubrid-manager by CUBRID.

the class MonitorStatisticPersistManager method loadMonitorStatistic.

/**
	 *
	 * Load MonitorStatistic nodes
	 *
	 */
protected void loadMonitorStatistic() {
    synchronized (this) {
        IXMLMemento memento = PersistUtils.getXMLMemento(CubridManagerUIPlugin.PLUGIN_ID, MONITOR_STATISTIC_XML_CONTENT);
        if (memento != null) {
            IXMLMemento[] monitorsPerHost = memento.getChildren("monitorsPerHost");
            for (int i = 0; i < monitorsPerHost.length; i++) {
                boolean isMultiHost = monitorsPerHost[i].getBoolean("isMultihost");
                String hostId = HOST_ID_FOR_MULTI_HOST;
                if (!isMultiHost) {
                    hostId = monitorsPerHost[i].getString("hostId");
                }
                IXMLMemento[] children = monitorsPerHost[i].getChildren("monitor");
                List<MonitorStatistic> monitorStatisticList = new ArrayList<MonitorStatistic>();
                for (int j = 0; j < children.length; j++) {
                    String id = children[j].getString("name");
                    String label = id;
                    if (!isMultiHost && id.indexOf("@") != -1) {
                        label = id.substring(0, id.indexOf("@"));
                    }
                    MonitorStatistic node = new MonitorStatistic(id, label, iconPath);
                    node.setType(CubridNodeType.MONITOR_STATISTIC_PAGE);
                    node.setMultiHost(isMultiHost);
                    IXMLMemento[] chartChildren = children[j].getChildren("chart");
                    for (int k = 0; chartChildren != null && k < chartChildren.length; k++) {
                        String typeStr = chartChildren[k].getString("type");
                        StatisticType type = StatisticType.valueOf(typeStr);
                        int series = chartChildren[k].getInteger("series");
                        String dType = chartChildren[k].getString("dtype");
                        if (!isMultiHost) {
                            SingleHostChartItem item = new SingleHostChartItem(id, type);
                            item.setSeries(series);
                            item.setDType(dType);
                            String metrics = chartChildren[k].getString("metrics");
                            String[] metricAr = metrics.split(",");
                            for (String metric : metricAr) {
                                item.addMetric(metric);
                            }
                            String dbName = null;
                            switch(type) {
                                case DB:
                                    dbName = chartChildren[k].getString("dbname");
                                    item.setDbName(dbName);
                                    break;
                                case DB_VOL:
                                    dbName = chartChildren[k].getString("dbname");
                                    String volName = chartChildren[k].getString("volname");
                                    item.setDbName(dbName);
                                    item.setVolName(volName);
                                    break;
                                case BROKER:
                                    String brokerName = chartChildren[k].getString("bname");
                                    item.setBrokerName(brokerName);
                                    break;
                                case OS:
                                    break;
                                default:
                                    break;
                            }
                            node.addStatisticItem(item);
                        } else {
                            IXMLMemento[] hostChildren = chartChildren[k].getChildren("host");
                            MultiHostChartItem item = new MultiHostChartItem(id, type);
                            item.setSeries(series);
                            item.setDType(dType);
                            for (int m = 0; hostChildren != null && m < hostChildren.length; m++) {
                                String cubridServerId = hostChildren[m].getString("cubridServerId");
                                String ip = hostChildren[m].getString("ip");
                                int port = hostChildren[m].getInteger("port");
                                String user = hostChildren[m].getString("user");
                                String pass = hostChildren[m].getString("password");
                                StatisticChartHost host;
                                if (cubridServerId != null) {
                                    host = new StatisticChartHost(cubridServerId);
                                } else {
                                    host = new StatisticChartHost(ip, port, user, CipherUtils.decrypt(pass));
                                }
                                String metric = hostChildren[m].getString("metric");
                                host.setMetric(metric);
                                String dbName = null;
                                switch(type) {
                                    case DB:
                                        dbName = hostChildren[m].getString("dbname");
                                        host.setDbName(dbName);
                                        break;
                                    case DB_VOL:
                                        dbName = hostChildren[m].getString("dbname");
                                        String volName = hostChildren[m].getString("volname");
                                        host.setDbName(dbName);
                                        host.setVolName(volName);
                                        break;
                                    case BROKER:
                                        String brokerName = hostChildren[m].getString("bname");
                                        host.setBrokerName(brokerName);
                                        break;
                                    case OS:
                                        break;
                                    default:
                                        break;
                                }
                                item.addStatisticChartHost(host);
                            }
                            node.addStatisticItem(item);
                        }
                    }
                    monitorStatisticList.add(node);
                }
                monitorStatisticMap.put(hostId, monitorStatisticList);
            }
        }
    }
}
Also used : SingleHostChartItem(com.cubrid.cubridmanager.core.monstatistic.model.SingleHostChartItem) IXMLMemento(com.cubrid.cubridmanager.core.common.xml.IXMLMemento) ArrayList(java.util.ArrayList) MultiHostChartItem(com.cubrid.cubridmanager.core.monstatistic.model.MultiHostChartItem) StatisticType(com.cubrid.cubridmanager.core.monstatistic.model.StatisticParamUtil.StatisticType) MonitorStatistic(com.cubrid.common.ui.spi.model.MonitorStatistic) StatisticChartHost(com.cubrid.cubridmanager.core.monstatistic.model.StatisticChartHost)

Example 47 with IXMLMemento

use of com.cubrid.cubridmanager.core.common.xml.IXMLMemento in project cubrid-manager by CUBRID.

the class MonitorStatisticPersistManager method saveStatistic.

/**
	 *
	 * Save MonitorStatistic nodes
	 *
	 */
public void saveStatistic() {
    synchronized (this) {
        XMLMemento memento = XMLMemento.createWriteRoot("monitors");
        Iterator<String> keySetIterator = monitorStatisticMap.keySet().iterator();
        while (keySetIterator.hasNext()) {
            String hostId = keySetIterator.next();
            boolean isMultiHost = HOST_ID_FOR_MULTI_HOST.equals(hostId);
            IXMLMemento monsPerHostMemento = memento.createChild("monitorsPerHost");
            monsPerHostMemento.putBoolean("isMultihost", isMultiHost);
            if (!isMultiHost) {
                monsPerHostMemento.putString("hostId", hostId);
            }
            List<MonitorStatistic> monitorStatisticList = monitorStatisticMap.get(hostId);
            if (monitorStatisticList == null) {
                continue;
            }
            Iterator<MonitorStatistic> nodeIterator = monitorStatisticList.iterator();
            while (nodeIterator.hasNext()) {
                MonitorStatistic node = nodeIterator.next();
                IXMLMemento monMemento = monsPerHostMemento.createChild("monitor");
                monMemento.putString("name", node.getId());
                //save StatisticItem list
                List<StatisticChartItem> statisticItemList = node.getStatisticItemList();
                Iterator<StatisticChartItem> itemIterator = statisticItemList.iterator();
                while (itemIterator.hasNext()) {
                    if (!node.isMultiHost()) {
                        SingleHostChartItem item = (SingleHostChartItem) itemIterator.next();
                        IXMLMemento chartMemento = monMemento.createChild("chart");
                        chartMemento.putInteger("series", item.getSeries());
                        chartMemento.putString("name", item.getName());
                        chartMemento.putString("type", item.getType().toString());
                        chartMemento.putString("dtype", item.getDType());
                        chartMemento.putString("metrics", ArrayUtil.collectionToCSString(item.getMetricList()));
                        switch(item.getType()) {
                            case DB:
                                chartMemento.putString("dbname", item.getDbName());
                                break;
                            case DB_VOL:
                                chartMemento.putString("dbname", item.getDbName());
                                chartMemento.putString("volname", item.getVolName());
                                break;
                            case BROKER:
                                chartMemento.putString("bname", item.getBrokerName());
                                break;
                            case OS:
                                break;
                            default:
                                break;
                        }
                    } else {
                        MultiHostChartItem item = (MultiHostChartItem) itemIterator.next();
                        IXMLMemento chartMemento = monMemento.createChild("chart");
                        chartMemento.putInteger("series", item.getSeries());
                        chartMemento.putString("name", item.getName());
                        chartMemento.putString("type", item.getType().toString());
                        chartMemento.putString("dtype", item.getDType());
                        //save HostInfo list
                        List<StatisticChartHost> hostList = item.getHostList();
                        Iterator<StatisticChartHost> hostIterator = hostList.iterator();
                        while (hostIterator.hasNext()) {
                            StatisticChartHost host = (StatisticChartHost) hostIterator.next();
                            IXMLMemento hostMemento = chartMemento.createChild("host");
                            hostMemento.putString("cubridServerId", host.getCubridServerId());
                            hostMemento.putString("ip", host.getIp());
                            hostMemento.putInteger("port", host.getPort());
                            hostMemento.putString("user", host.getUser());
                            hostMemento.putString("password", CipherUtils.encrypt(host.getPassword()));
                            hostMemento.putString("metric", host.getMetric());
                            switch(item.getType()) {
                                case DB:
                                    hostMemento.putString("dbname", host.getDbName());
                                    break;
                                case DB_VOL:
                                    hostMemento.putString("dbname", host.getDbName());
                                    hostMemento.putString("volname", host.getVolName());
                                    break;
                                case BROKER:
                                    hostMemento.putString("bname", host.getBrokerName());
                                    break;
                                case OS:
                                    break;
                                default:
                                    break;
                            }
                        }
                    }
                }
            }
        }
        PersistUtils.saveXMLMemento(CubridManagerUIPlugin.PLUGIN_ID, MONITOR_STATISTIC_XML_CONTENT, memento);
    }
}
Also used : SingleHostChartItem(com.cubrid.cubridmanager.core.monstatistic.model.SingleHostChartItem) IXMLMemento(com.cubrid.cubridmanager.core.common.xml.IXMLMemento) StatisticChartItem(com.cubrid.cubridmanager.core.monstatistic.model.StatisticChartItem) MultiHostChartItem(com.cubrid.cubridmanager.core.monstatistic.model.MultiHostChartItem) XMLMemento(com.cubrid.cubridmanager.core.common.xml.XMLMemento) IXMLMemento(com.cubrid.cubridmanager.core.common.xml.IXMLMemento) MonitorStatistic(com.cubrid.common.ui.spi.model.MonitorStatistic) StatisticChartHost(com.cubrid.cubridmanager.core.monstatistic.model.StatisticChartHost)

Example 48 with IXMLMemento

use of com.cubrid.cubridmanager.core.common.xml.IXMLMemento in project cubrid-manager by CUBRID.

the class CQBGroupNodePersistManager method loadGroupNode.

/**
	 * Load group nodes from xml memento.
	 *
	 * @param memento IXMLMemento
	 */
private void loadGroupNode(IXMLMemento memento) {
    if (memento != null) {
        IXMLMemento[] children = memento.getChildren("group");
        for (int i = 0; i < children.length; i++) {
            String id = children[i].getString("id");
            String name = children[i].getString("name");
            CubridGroupNode cgn = getGroupById(id);
            if (cgn == null) {
                cgn = new CubridGroupNode(id, name, DEFAULT_GROUP_NODE.getIconPath());
                groupNodeList.add(cgn);
            }
            cgn.setLoader(DEFAULT_GROUP_NODE.getLoader());
            IXMLMemento[] items = children[i].getChildren("item");
            for (IXMLMemento item : items) {
                String itemId = item.getString("id");
                CubridDatabase cs = CQBDBNodePersistManager.getInstance().getDatabase(itemId);
                if (cs == null || cs.getParent() != null) {
                    continue;
                }
                cgn.addChild(cs);
            }
        }
    }
    //groupNodeList.size >=1
    if (groupNodeList.isEmpty()) {
        try {
            CubridGroupNode defaultGroup = (CubridGroupNode) DEFAULT_GROUP_NODE.clone();
            groupNodeList.add(defaultGroup);
            List<CubridDatabase> servers = CQBDBNodePersistManager.getInstance().getAllDatabase();
            for (CubridDatabase server : servers) {
                defaultGroup.addChild(server);
            }
        } catch (CloneNotSupportedException e) {
            LOGGER.error(e.getMessage());
        }
    }
}
Also used : CubridGroupNode(com.cubrid.common.ui.spi.model.CubridGroupNode) IXMLMemento(com.cubrid.cubridmanager.core.common.xml.IXMLMemento) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 49 with IXMLMemento

use of com.cubrid.cubridmanager.core.common.xml.IXMLMemento in project cubrid-manager by CUBRID.

the class CQBGroupNodePersistManager method saveAllGroupNode.

/**
	 * Save all group node.
	 *
	 */
public void saveAllGroupNode() {
    synchronized (this) {
        XMLMemento memento = XMLMemento.createWriteRoot("groups");
        for (CubridGroupNode group : groupNodeList) {
            IXMLMemento child = memento.createChild("group");
            child.putString("id", group.getId());
            child.putString("name", group.getName());
            for (ICubridNode cn : group.getChildren()) {
                IXMLMemento childHost = child.createChild("item");
                childHost.putString("id", cn.getId());
            }
        }
        PersistUtils.saveXMLMemento(ApplicationUtil.CQB_UI_PLUGIN_ID, COM_CUBRID_QB_DBGROUP, memento);
    }
}
Also used : CubridGroupNode(com.cubrid.common.ui.spi.model.CubridGroupNode) XMLMemento(com.cubrid.cubridmanager.core.common.xml.XMLMemento) IXMLMemento(com.cubrid.cubridmanager.core.common.xml.IXMLMemento) IXMLMemento(com.cubrid.cubridmanager.core.common.xml.IXMLMemento) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode)

Example 50 with IXMLMemento

use of com.cubrid.cubridmanager.core.common.xml.IXMLMemento in project cubrid-manager by CUBRID.

the class CQBGroupNodePersistManager method loadGroupNode.

/**
	 * Load group nodes from file preference.
	 *
	 * @param workspacePath String
	 * @return boolean whether import
	 */
public boolean loadGroupNode(String workspacePath) {
    synchronized (this) {
        String filePath = workspacePath + File.separator + ".metadata" + File.separator + ".plugins" + File.separator + "org.eclipse.core.runtime" + File.separator + ".settings" + File.separator + "com.cubrid.cubridquery.ui.prefs";
        PreferenceStore preference = new PreferenceStore(filePath);
        int size = groupNodeList.size();
        try {
            preference.load();
            String xmlString = preference.getString(COM_CUBRID_QB_DBGROUP);
            if (xmlString == null || xmlString.trim().length() == 0) {
                return false;
            }
            ByteArrayInputStream in = new ByteArrayInputStream(xmlString.getBytes("UTF-8"));
            IXMLMemento memento = XMLMemento.loadMemento(in);
            loadGroupNode(memento);
        } catch (IOException e) {
            LOGGER.error(e.getMessage());
        }
        boolean isImported = size != groupNodeList.size();
        if (isImported) {
            saveAllGroupNode();
        }
        return isImported;
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) IXMLMemento(com.cubrid.cubridmanager.core.common.xml.IXMLMemento) IOException(java.io.IOException) PreferenceStore(org.eclipse.jface.preference.PreferenceStore)

Aggregations

IXMLMemento (com.cubrid.cubridmanager.core.common.xml.IXMLMemento)54 XMLMemento (com.cubrid.cubridmanager.core.common.xml.XMLMemento)18 ByteArrayInputStream (java.io.ByteArrayInputStream)10 IOException (java.io.IOException)10 CubridServer (com.cubrid.common.ui.spi.model.CubridServer)8 ArrayList (java.util.ArrayList)7 DatabaseEditorConfig (com.cubrid.common.ui.spi.model.DatabaseEditorConfig)6 HashMap (java.util.HashMap)6 RGB (org.eclipse.swt.graphics.RGB)6 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)5 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)5 IEclipsePreferences (org.eclipse.core.runtime.preferences.IEclipsePreferences)5 InstanceScope (org.eclipse.core.runtime.preferences.InstanceScope)5 PreferenceStore (org.eclipse.jface.preference.PreferenceStore)5 CubridGroupNode (com.cubrid.common.ui.spi.model.CubridGroupNode)4 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)4 SQLHistoryDetail (com.cubrid.common.ui.query.control.SQLHistoryDetail)3 QueryRecord (com.cubrid.common.ui.query.tuner.QueryRecord)3 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)3 MonitorStatistic (com.cubrid.common.ui.spi.model.MonitorStatistic)3