Search in sources :

Example 6 with CobarDO

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

the class ClusterInstantPerfValueAjax method getClusterThroughput.

@SuppressWarnings("unchecked")
private List<Map<String, Object>> getClusterThroughput(AjaxParams params) {
    List<Map<String, Object>> result = new ArrayList<Map<String, Object>>();
    JSONArray array = params.getArray();
    JSONObject json = null;
    Map<Long, JSONObject> cobarRequest = new HashMap<Long, JSONObject>();
    for (int i = 0; i < array.size(); i++) {
        JSONObject js = array.getJSONObject(i);
        if ("cluster".equals(js.getString("flag"))) {
            json = js;
        } else if ("cobar".equals(js.getString("flag"))) {
            cobarRequest.put(js.getLong("id"), js);
        }
    }
    PropertyUtilsBean util = new PropertyUtilsBean();
    long clusterId = params.getClusterId();
    List<CobarDO> nodes = xmlAccesser.getCobarDAO().getCobarList(clusterId, ConstantDefine.ACTIVE);
    AjaxResult cluster = new AjaxResult();
    cluster.setId(clusterId);
    cluster.setFlag("cluster");
    long timestamp = 0;
    for (CobarDO node : nodes) {
        CobarAdapterDAO perfAccesser = cobarAccesser.getAccesser(node.getId());
        if (!perfAccesser.checkConnection()) {
            StringBuilder sb = new StringBuilder("getClusterThroughput: cobar connect error for Name:");
            sb.append(node.getName()).append(" Host:").append(node.getHost());
            logger.error(sb.toString());
            continue;
        }
        AjaxResult re = new AjaxResult();
        List<ProcessorStatus> list = perfAccesser.listProccessorStatus();
        List<CommandStatus> cmdList = perfAccesser.listCommandStatus();
        long cobarNetIn = groupByPList(list, NET_IN);
        long cobarNetOut = groupByPList(list, NET_OUT);
        long cobarRequestCount = groupByCList(cmdList, REQUEST_COUNT);
        cluster.addRequest(cobarRequestCount);
        cluster.addNetIn(cobarNetIn);
        cluster.addNetOut(cobarNetOut);
        re.setId(node.getId());
        re.setFlag("cobar");
        re.setNetIn(cobarNetIn);
        re.setNetOut(cobarNetOut);
        re.setConnection(groupByPList(list, CONNECTION));
        re.setRequest(cobarRequestCount);
        timestamp = list.get(list.size() - 1).getSampleTimeStamp();
        re.setTimestamp(timestamp);
        JSONObject jsonTmp = cobarRequest.get(node.getId());
        if (jsonTmp != null) {
            re.setNetIn_deriv(FormatUtil.formatNetwork(Math.round(MathUtil.getDerivate(cobarNetIn, jsonTmp.getLong("netIn"), timestamp, jsonTmp.getLong("timestamp"), 1000.0))));
            re.setNetOut_deriv(FormatUtil.formatNetwork(Math.round(MathUtil.getDerivate(cobarNetOut, jsonTmp.getLong("netOut"), timestamp, jsonTmp.getLong("timestamp"), 1000.0))));
            re.setRequest_deriv(FormatUtil.formatNumber(Math.round(MathUtil.getDerivate(cobarRequestCount, jsonTmp.getLong("reCount"), timestamp, jsonTmp.getLong("timestamp"), 1000.0))));
        }
        Map<String, Object> map = null;
        try {
            map = util.describe(re);
        } catch (Exception e) {
            logger.error(e);
            throw new RuntimeException(e);
        }
        if (null != map) {
            result.add(map);
        }
    }
    cluster.setTimestamp(timestamp);
    if (null != json && json.getLong("netIn") != -1) {
        long o_tiemstamp = json.getLong("timestamp");
        cluster.setNetIn_deriv(FormatUtil.formatNetwork(Math.round(MathUtil.getDerivate(cluster.getNetIn(), json.getLong("netIn"), timestamp, o_tiemstamp, 1000.0))));
        cluster.setNetOut_deriv(FormatUtil.formatNetwork(Math.round(MathUtil.getDerivate(cluster.getNetOut(), json.getLong("netOut"), timestamp, o_tiemstamp, 1000.0))));
        cluster.setRequest_deriv(FormatUtil.formatNumber(Math.round(MathUtil.getDerivate(cluster.getRequest(), json.getLong("reCount"), timestamp, o_tiemstamp, 1000.0))));
    }
    Map<String, Object> m = null;
    try {
        m = util.describe(cluster);
    } catch (Exception e) {
        logger.error(e);
        throw new RuntimeException(e);
    }
    if (null != m) {
        result.add(m);
    }
    return result;
}
Also used : HashMap(java.util.HashMap) PropertyUtilsBean(org.apache.commons.beanutils.PropertyUtilsBean) ArrayList(java.util.ArrayList) CobarAdapterDAO(com.alibaba.cobar.manager.dao.CobarAdapterDAO) JSONArray(net.sf.json.JSONArray) CobarDO(com.alibaba.cobar.manager.dataobject.xml.CobarDO) ProcessorStatus(com.alibaba.cobar.manager.dataobject.cobarnode.ProcessorStatus) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) JSONObject(net.sf.json.JSONObject) JSONObject(net.sf.json.JSONObject) CommandStatus(com.alibaba.cobar.manager.dataobject.cobarnode.CommandStatus) HashMap(java.util.HashMap) Map(java.util.Map)

Example 7 with CobarDO

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

the class ClusterInstantPerfValueAjax method getStatus.

private List<Pair<Long, String>> getStatus(AjaxParams params) {
    List<Pair<Long, String>> result = new ArrayList<Pair<Long, String>>();
    List<CobarDO> nodes = xmlAccesser.getCobarDAO().getCobarList(params.getClusterId(), ConstantDefine.ACTIVE);
    for (CobarDO node : nodes) {
        if (ConstantDefine.IN_ACTIVE.equals(node.getStatus())) {
            result.add(new Pair<Long, String>(node.getId(), ConstantDefine.IN_ACTIVE));
            continue;
        }
        CobarAdapterDAO perfAccesser = cobarAccesser.getAccesser(node.getId());
        if (!perfAccesser.checkConnection()) {
            StringBuilder sb = new StringBuilder("getStatus: cobar connect error for Name:");
            sb.append(node.getName()).append(" Host:").append(node.getHost());
            logger.error(sb.toString());
            result.add(new Pair<Long, String>(node.getId(), ConstantDefine.ERROR));
        } else {
            result.add(new Pair<Long, String>(node.getId(), ConstantDefine.ACTIVE));
        }
    }
    return result;
}
Also used : CobarAdapterDAO(com.alibaba.cobar.manager.dao.CobarAdapterDAO) ArrayList(java.util.ArrayList) CobarDO(com.alibaba.cobar.manager.dataobject.xml.CobarDO) Pair(com.alibaba.cobar.manager.util.Pair)

Example 8 with CobarDO

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

the class CobarDetailScreen method handleRequestInternal.

@SuppressWarnings("unchecked")
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) {
    UserDO user = (UserDO) request.getSession().getAttribute("user");
    long nodeId = 0;
    try {
        nodeId = Long.parseLong(request.getParameter("nodeId").trim());
    } catch (Exception e) {
        throw new IllegalArgumentException("parameter 'nodeId' is invalid: " + request.getParameter("nodeId"));
    }
    CobarDO cobar = xmlAccesser.getCobarDAO().getCobarById(nodeId);
    if (null == cobar) {
        throw new IllegalArgumentException("no cobar exsit for id : " + nodeId);
    }
    PropertyUtilsBean util = new PropertyUtilsBean();
    Map<String, Object> cobarMap = null;
    try {
        cobarMap = util.describe(cobar);
    } catch (Exception e1) {
        throw new RuntimeException(e1);
    }
    cobarMap.remove("class");
    cobarMap.remove("name");
    cobarMap.put("name", CobarStringUtil.htmlEscapedString(cobar.getName()));
    ClusterDO cluster = xmlAccesser.getClusterDAO().getClusterById(cobar.getClusterId());
    Map<String, Object> clusterMap = new HashMap<String, Object>();
    clusterMap.put("id", cluster.getId());
    clusterMap.put("name", CobarStringUtil.htmlEscapedString(cluster.getName()));
    return new ModelAndView("v_cobarDetail", new FluenceHashMap<String, Object>().putKeyValue("user", user).putKeyValue("cluster", clusterMap).putKeyValue("cobarNode", cobarMap));
}
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)

Example 9 with CobarDO

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

the class CobarListScreen 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);
    ListSortUtil.sortCobarByName(cobarList);
    int aCount = xmlAccesser.getCobarDAO().getCobarList(clusterId, ConstantDefine.ACTIVE).size();
    int iCount = xmlAccesser.getCobarDAO().getCobarList(clusterId, ConstantDefine.IN_ACTIVE).size();
    Map<String, Integer> count = new HashMap<String, Integer>();
    count.put("aCount", aCount);
    count.put("iCount", iCount);
    count.put("tCount", (aCount + iCount));
    PropertyUtilsBean util = new PropertyUtilsBean();
    Map<String, Object> clusterMap;
    try {
        clusterMap = util.describe(cluster);
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
    clusterMap.remove("class");
    clusterMap.remove("name");
    clusterMap.remove("deployDesc");
    clusterMap.put("name", CobarStringUtil.htmlEscapedString(cluster.getName()));
    clusterMap.put("deployDesc", CobarStringUtil.htmlEscapedString(cluster.getDeployDesc()));
    List<Map<String, Object>> cobarListMap = new ArrayList<Map<String, Object>>();
    for (CobarDO c : cobarList) {
        Map<String, Object> cobarMap;
        try {
            cobarMap = util.describe(c);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        cobarMap.remove("class");
        cobarMap.remove("name");
        cobarMap.put("name", CobarStringUtil.htmlEscapedString(c.getName()));
        cobarListMap.add(cobarMap);
    }
    return new ModelAndView("v_cobarList", new FluenceHashMap<String, Object>().putKeyValue("cluster", clusterMap).putKeyValue("cobarList", cobarListMap).putKeyValue("count", count).putKeyValue("user", user));
}
Also used : HashMap(java.util.HashMap) FluenceHashMap(com.alibaba.cobar.manager.util.FluenceHashMap) PropertyUtilsBean(org.apache.commons.beanutils.PropertyUtilsBean) UserDO(com.alibaba.cobar.manager.dataobject.xml.UserDO) ArrayList(java.util.ArrayList) ModelAndView(org.springframework.web.servlet.ModelAndView) 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)

Example 10 with CobarDO

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

the class ConnectionControlScreen method handleRequestInternal.

@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
    UserDO user = (UserDO) request.getSession().getAttribute("user");
    String id = request.getParameter("clusterId");
    long clusterId = -1;
    if (null != id) {
        clusterId = Long.parseLong(id);
    }
    String cobarNodeId = request.getParameter("cobarNodeId");
    long cobarId = -1;
    if (null != cobarNodeId) {
        cobarId = Long.parseLong(cobarNodeId);
    }
    List<ClusterDO> cList = xmlAccesser.getClusterDAO().listAllCluster();
    List<Map<String, Object>> clusterList = new ArrayList<Map<String, Object>>();
    ListSortUtil.sortClusterByName(cList);
    for (ClusterDO e : cList) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("id", e.getId());
        map.put("name", CobarStringUtil.htmlEscapedString(e.getName()));
        clusterList.add(map);
    }
    List<CobarDO> cobarList = null;
    if (null != cList && cList.size() > 0) {
        if (-1 == clusterId) {
            clusterId = cList.get(0).getId();
            cobarList = xmlAccesser.getCobarDAO().getCobarList(clusterId, ConstantDefine.ACTIVE);
        } else {
            cobarList = xmlAccesser.getCobarDAO().getCobarList(clusterId, ConstantDefine.ACTIVE);
        }
    }
    List<Map<String, Object>> cobarViewList = null;
    if (null != cobarList && cobarList.size() > 0) {
        ListSortUtil.sortCobarByName(cobarList);
        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", CobarStringUtil.htmlEscapedString(c.getName()));
                cobarViewList.add(cobarMap);
            }
        }
    }
    /* cobarId=-2, cobar InActive; cobarId=-3, connection error */
    List<ConnectionStatus> connecList = null;
    if (cobarId > 0) {
        CobarDO cobar = xmlAccesser.getCobarDAO().getCobarById(cobarId);
        if (cobar.getStatus().equals(ConstantDefine.ACTIVE)) {
            CobarAdapterDAO perf = cobarAccesser.getAccesser(cobarId);
            if (!perf.checkConnection()) {
                cobarId = -3;
            } else {
                connecList = perf.listConnectionStatus();
            }
        } else {
            cobarId = -2;
        }
    }
    List<Map<String, Object>> returnList = new ArrayList<Map<String, Object>>();
    if (null != connecList) {
        ListSortUtil.sortConnections(connecList);
        for (ConnectionStatus c : connecList) {
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("processor", c.getProcessor());
            map.put("id", c.getId());
            map.put("host", c.getHost());
            map.put("port", c.getPort());
            map.put("local_port", c.getLocal_port());
            map.put("schema", c.getSchema());
            map.put("charset", c.getCharset());
            map.put("netIn", FormatUtil.formatStore(c.getNetIn()));
            map.put("netOut", FormatUtil.formatStore(c.getNetOut()));
            map.put("aliveTime", FormatUtil.formatTime(c.getAliveTime() * 1000, 2));
            map.put("attempsCount", FormatUtil.formatNumber(c.getAttempsCount()));
            map.put("recvBuffer", FormatUtil.formatStore(c.getRecvBuffer()));
            map.put("sendQueue", c.getSendQueue());
            map.put("channel", c.getChannel());
            returnList.add(map);
        }
    }
    return new ModelAndView("c_connection", new FluenceHashMap<String, Object>().putKeyValue("cList", clusterList).putKeyValue("cobarList", cobarViewList).putKeyValue("clusterId", clusterId).putKeyValue("cobarId", cobarId).putKeyValue("connecList", returnList).putKeyValue("user", user));
}
Also used : CobarAdapterDAO(com.alibaba.cobar.manager.dao.CobarAdapterDAO) HashMap(java.util.HashMap) FluenceHashMap(com.alibaba.cobar.manager.util.FluenceHashMap) UserDO(com.alibaba.cobar.manager.dataobject.xml.UserDO) ArrayList(java.util.ArrayList) ModelAndView(org.springframework.web.servlet.ModelAndView) CobarDO(com.alibaba.cobar.manager.dataobject.xml.CobarDO) ClusterDO(com.alibaba.cobar.manager.dataobject.xml.ClusterDO) ConnectionStatus(com.alibaba.cobar.manager.dataobject.cobarnode.ConnectionStatus) 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