Search in sources :

Example 21 with CobarDO

use of com.alibaba.cobar.manager.dataobject.xml.CobarDO in project cobar by alibaba.

the class ClusterInstantPerfValueAjax method listCobarMemoryUsage.

private List<Pair<Long, Integer>> listCobarMemoryUsage(AjaxParams params) {
    List<Pair<Long, Integer>> result = new ArrayList<Pair<Long, Integer>>();
    List<CobarDO> nodes = xmlAccesser.getCobarDAO().getCobarList(params.getClusterId(), ConstantDefine.ACTIVE);
    for (CobarDO node : nodes) {
        CobarAdapterDAO perfAccesser = cobarAccesser.getAccesser(node.getId());
        if (!perfAccesser.checkConnection()) {
            StringBuilder sb = new StringBuilder("listCobarMemoryUsage: cobar connect error for Name:");
            sb.append(node.getName()).append(" Host:").append(node.getHost());
            logger.error(sb.toString());
            continue;
        }
        ServerStatus ss = perfAccesser.getServerStatus();
        int memoryUsage = 0;
        if (ss.getTotalMemory() != 0)
            memoryUsage = Math.round(ss.getUsedMemory() * 100 / ss.getTotalMemory());
        result.add(new Pair<Long, Integer>(node.getId(), memoryUsage));
    }
    return result;
}
Also used : CobarAdapterDAO(com.alibaba.cobar.manager.dao.CobarAdapterDAO) ServerStatus(com.alibaba.cobar.manager.dataobject.cobarnode.ServerStatus) ArrayList(java.util.ArrayList) CobarDO(com.alibaba.cobar.manager.dataobject.xml.CobarDO) Pair(com.alibaba.cobar.manager.util.Pair)

Example 22 with CobarDO

use of com.alibaba.cobar.manager.dataobject.xml.CobarDO in project cobar by alibaba.

the class CobarControlAjax method killConnections.

private boolean killConnections(AjaxParams params) {
    long cobarId = params.getCobarNodeId();
    long connecId = params.getConnectionId();
    CobarDO cobar = xmlAccesser.getCobarDAO().getCobarById(cobarId);
    if (!cobar.getStatus().equals(ConstantDefine.ACTIVE)) {
        return false;
    }
    CobarAdapterDAO control = cobarAccesser.getAccesser(cobarId);
    if (control.checkConnection()) {
        control.killConnection(connecId);
        return true;
    }
    return false;
}
Also used : CobarAdapterDAO(com.alibaba.cobar.manager.dao.CobarAdapterDAO) CobarDO(com.alibaba.cobar.manager.dataobject.xml.CobarDO)

Example 23 with CobarDO

use of com.alibaba.cobar.manager.dataobject.xml.CobarDO in project cobar by alibaba.

the class CobarControlAjax method getCobarList.

private List<Map<String, Object>> getCobarList(AjaxParams params) {
    long clusterId = params.getClusterId();
    List<CobarDO> cobarList = xmlAccesser.getCobarDAO().getCobarList(clusterId, ConstantDefine.ACTIVE);
    ListSortUtil.sortCobarByName(cobarList);
    List<Map<String, Object>> cobarViewList = new ArrayList<Map<String, Object>>();
    for (CobarDO c : cobarList) {
        CobarAdapterDAO perf = cobarAccesser.getAccesser(c.getId());
        if (perf.checkConnection()) {
            Map<String, Object> cobarMap = new HashMap<String, Object>();
            cobarMap.put("id", c.getId());
            cobarMap.put("name", c.getName());
            cobarViewList.add(cobarMap);
        }
    }
    return cobarViewList;
}
Also used : CobarAdapterDAO(com.alibaba.cobar.manager.dao.CobarAdapterDAO) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JSONObject(net.sf.json.JSONObject) CobarDO(com.alibaba.cobar.manager.dataobject.xml.CobarDO) HashMap(java.util.HashMap) Map(java.util.Map)

Example 24 with CobarDO

use of com.alibaba.cobar.manager.dataobject.xml.CobarDO in project cobar by alibaba.

the class CobarAccesser method getAccesser.

public CobarAdapterDAO getAccesser(long cobarId) {
    final CobarDO cobar = xmlAccesser.getCobarDAO().getCobarById(cobarId);
    if (cobar == null) {
        logger.error(new StringBuilder("Fail to get cobar information which id = ").append(cobarId).toString());
    }
    CobarAdapterDAO accesser = cobarAdapterDelegate.getCobarNodeAccesser(cobar.getHost(), cobar.getPort(), cobar.getUser(), cobar.getPassword());
    return accesser;
}
Also used : CobarAdapterDAO(com.alibaba.cobar.manager.dao.CobarAdapterDAO) CobarDO(com.alibaba.cobar.manager.dataobject.xml.CobarDO)

Example 25 with CobarDO

use of com.alibaba.cobar.manager.dataobject.xml.CobarDO in project cobar by alibaba.

the class MCobarListScreen method handleRequestInternal.

@SuppressWarnings({ "unchecked" })
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
    UserDO user = (UserDO) request.getSession().getAttribute("user");
    long clusterId = Long.parseLong(request.getParameter("clusterId"));
    ClusterDO cluster = xmlAccesser.getClusterDAO().getClusterById(clusterId);
    List<CobarDO> cobarList = xmlAccesser.getCobarDAO().getCobarList(clusterId);
    List<Map<String, Object>> cobarViewList = null;
    if (null != cobarList) {
        ListSortUtil.sortCobarByName(cobarList);
        cobarViewList = new ArrayList<Map<String, Object>>();
        PropertyUtilsBean util = new PropertyUtilsBean();
        for (CobarDO c : cobarList) {
            Map<String, Object> map = util.describe(c);
            map.remove("class");
            map.remove("name");
            map.put("name", CobarStringUtil.htmlEscapedString(c.getName()));
            cobarViewList.add(map);
        }
    }
    Map<String, Object> clusterView = new HashMap<String, Object>();
    clusterView.put("id", cluster.getId());
    clusterView.put("name", CobarStringUtil.htmlEscapedString(cluster.getName()));
    return new ModelAndView("m_cobarList", new FluenceHashMap<String, Object>().putKeyValue("cobarList", cobarViewList).putKeyValue("user", user).putKeyValue("cluster", clusterView));
}
Also used : PropertyUtilsBean(org.apache.commons.beanutils.PropertyUtilsBean) HashMap(java.util.HashMap) FluenceHashMap(com.alibaba.cobar.manager.util.FluenceHashMap) UserDO(com.alibaba.cobar.manager.dataobject.xml.UserDO) ModelAndView(org.springframework.web.servlet.ModelAndView) FluenceHashMap(com.alibaba.cobar.manager.util.FluenceHashMap) CobarDO(com.alibaba.cobar.manager.dataobject.xml.CobarDO) ClusterDO(com.alibaba.cobar.manager.dataobject.xml.ClusterDO) HashMap(java.util.HashMap) FluenceHashMap(com.alibaba.cobar.manager.util.FluenceHashMap) Map(java.util.Map)

Aggregations

CobarDO (com.alibaba.cobar.manager.dataobject.xml.CobarDO)35 CobarAdapterDAO (com.alibaba.cobar.manager.dao.CobarAdapterDAO)16 HashMap (java.util.HashMap)16 Map (java.util.Map)15 ArrayList (java.util.ArrayList)14 ModelAndView (org.springframework.web.servlet.ModelAndView)13 UserDO (com.alibaba.cobar.manager.dataobject.xml.UserDO)10 ClusterDO (com.alibaba.cobar.manager.dataobject.xml.ClusterDO)9 FluenceHashMap (com.alibaba.cobar.manager.util.FluenceHashMap)7 Test (org.junit.Test)7 PropertyUtilsBean (org.apache.commons.beanutils.PropertyUtilsBean)6 IOException (java.io.IOException)5 Iterator (java.util.Iterator)4 Entry (java.util.Map.Entry)4 JSONObject (net.sf.json.JSONObject)3 CommandStatus (com.alibaba.cobar.manager.dataobject.cobarnode.CommandStatus)2 ProcessorStatus (com.alibaba.cobar.manager.dataobject.cobarnode.ProcessorStatus)2 ServerStatus (com.alibaba.cobar.manager.dataobject.cobarnode.ServerStatus)2 Pair (com.alibaba.cobar.manager.util.Pair)2 JSONArray (net.sf.json.JSONArray)2