Search in sources :

Example 1 with CobarAdapterDAO

use of com.alibaba.cobar.manager.dao.CobarAdapterDAO in project cobar by alibaba.

the class StopHeartbeat method handleRequestInternal.

@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) {
    UserDO user = (UserDO) request.getSession().getAttribute("user");
    String datanodes = request.getParameter("datanodes");
    int time = Integer.parseInt(request.getParameter("stoptime"));
    long clusterId = Long.parseLong(request.getParameter("clusterIdK"));
    ClusterDO cluster = xmlAccesser.getClusterDAO().getClusterById(clusterId);
    List<Map<String, Object>> resultList = new ArrayList<Map<String, Object>>();
    if (logger.isWarnEnabled()) {
        StringBuilder log = new StringBuilder();
        log.append(user.getUsername()).append(" | stop heartbeat | cluster:");
        log.append(cluster.getName()).append(" | ");
        log.append(datanodes).append(" | time:");
        log.append(time);
        logger.warn(log.toString());
    }
    List<CobarDO> cobarList = null;
    lock.lock();
    try {
        cobarList = xmlAccesser.getCobarDAO().getCobarList(clusterId, ConstantDefine.ACTIVE);
        for (CobarDO c : cobarList) {
            CobarAdapterDAO control = cobarAccesser.getAccesser(c.getId());
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("name", CobarStringUtil.htmlEscapedString(c.getName()));
            if (control.checkConnection()) {
                int num = control.stopHeartbeat(datanodes, time);
                map.put("result", num + " rows");
            } else {
                map.put("result", "connction error!");
            }
            resultList.add(map);
        }
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("name", "UNKNOWN ERROR");
        map.put("result", "unknown exception occurs when stopping heartbeat");
        resultList.clear();
        resultList.add(map);
    } finally {
        lock.unlock();
    }
    return new ModelAndView("c_result", "resultList", resultList);
}
Also used : CobarAdapterDAO(com.alibaba.cobar.manager.dao.CobarAdapterDAO) HashMap(java.util.HashMap) 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) Map(java.util.Map)

Example 2 with CobarAdapterDAO

use of com.alibaba.cobar.manager.dao.CobarAdapterDAO in project cobar by alibaba.

the class SwitchDatanodes method handleRequestInternal.

@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
    String datanodes = request.getParameter("datanodes");
    int index = Integer.parseInt(request.getParameter("index"));
    long clusterId = Long.parseLong(request.getParameter("clusterIdK"));
    UserDO user = (UserDO) request.getSession().getAttribute("user");
    ClusterDO cluster = xmlAccesser.getClusterDAO().getClusterById(clusterId);
    List<Map<String, Object>> resultList = new ArrayList<Map<String, Object>>();
    List<CobarDO> cobarList = xmlAccesser.getCobarDAO().getCobarList(clusterId, ConstantDefine.ACTIVE);
    if (logger.isWarnEnabled()) {
        StringBuilder log = new StringBuilder();
        log.append(user.getUsername()).append(" | switch datanodes | cluster:");
        log.append(cluster.getName()).append(" | ");
        log.append(datanodes).append(" | index:");
        log.append(index);
        logger.warn(log.toString());
    }
    lock.lock();
    try {
        for (CobarDO c : cobarList) {
            CobarAdapterDAO control = cobarAccesser.getAccesser(c.getId());
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("name", CobarStringUtil.htmlEscapedString(c.getName()));
            if (control.checkConnection()) {
                int num = control.switchDataNode(datanodes, index);
                map.put("result", num + " rows");
            } else {
                map.put("result", "connction error!");
            }
            resultList.add(map);
        }
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("name", "UNKNOWN ERROR");
        map.put("result", "unknown exception occurs when switching");
        resultList.clear();
        resultList.add(map);
    } finally {
        lock.unlock();
    }
    return new ModelAndView("c_result", "resultList", resultList);
}
Also used : CobarAdapterDAO(com.alibaba.cobar.manager.dao.CobarAdapterDAO) HashMap(java.util.HashMap) 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) Map(java.util.Map)

Example 3 with CobarAdapterDAO

use of com.alibaba.cobar.manager.dao.CobarAdapterDAO in project cobar by alibaba.

the class ClusterInstantPerfValueAjax method getClusterInfo.

private AjaxResult getClusterInfo(AjaxParams params) {
    JSONArray array = params.getArray();
    long clusterId = params.getClusterId();
    JSONObject json = null;
    if (array.size() > 0) {
        json = array.getJSONObject(0);
    }
    AjaxResult rs = new AjaxResult();
    rs.setId(clusterId);
    List<CobarDO> nodes = xmlAccesser.getCobarDAO().getCobarList(clusterId);
    rs.setTotal(nodes.size());
    for (CobarDO cobar : nodes) {
        if (ConstantDefine.IN_ACTIVE.equals(cobar.getStatus())) {
            continue;
        }
        CobarAdapterDAO perfAccesser = cobarAccesser.getAccesser(cobar.getId());
        if (!perfAccesser.checkConnection()) {
            rs.addError(1);
            StringBuilder sb = new StringBuilder("getClusterInfo : cobar connect error for [ Name:");
            sb.append(cobar.getName()).append(" Host:").append(cobar.getHost()).append(" ]");
            logger.error(sb.toString());
            continue;
        }
        rs.addActive(1);
        rs.setSchema(perfAccesser.listDataBases().size());
        List<ProcessorStatus> list = perfAccesser.listProccessorStatus();
        rs.addNetIn(groupByPList(list, NET_IN));
        rs.addNetOut(groupByPList(list, NET_OUT));
        rs.addConnection(groupByPList(list, CONNECTION));
        rs.setTimestamp(list.get(list.size() - 1).getSampleTimeStamp());
        List<CommandStatus> commandList = perfAccesser.listCommandStatus();
        rs.addRequest(groupByCList(commandList, REQUEST_COUNT));
    }
    if (json != null && json.getLong("netIn") != -1) {
        long o_tiemstamp = json.getLong("timestamp");
        rs.setNetIn_deriv(FormatUtil.formatNetwork(Math.round(MathUtil.getDerivate(rs.getNetIn(), json.getLong("netIn"), rs.getTimestamp(), o_tiemstamp, 1000.0))));
        rs.setNetOut_deriv(FormatUtil.formatNetwork(Math.round(MathUtil.getDerivate(rs.getNetOut(), json.getLong("netOut"), rs.getTimestamp(), o_tiemstamp, 1000.0))));
        rs.setRequest_deriv(FormatUtil.formatNumber(Math.round(MathUtil.getDerivate(rs.getRequest(), json.getLong("reCount"), rs.getTimestamp(), o_tiemstamp, 1000.0))));
    }
    return rs;
}
Also used : CobarAdapterDAO(com.alibaba.cobar.manager.dao.CobarAdapterDAO) JSONObject(net.sf.json.JSONObject) JSONArray(net.sf.json.JSONArray) CommandStatus(com.alibaba.cobar.manager.dataobject.cobarnode.CommandStatus) CobarDO(com.alibaba.cobar.manager.dataobject.xml.CobarDO) ProcessorStatus(com.alibaba.cobar.manager.dataobject.cobarnode.ProcessorStatus)

Example 4 with CobarAdapterDAO

use of com.alibaba.cobar.manager.dao.CobarAdapterDAO 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 5 with CobarAdapterDAO

use of com.alibaba.cobar.manager.dao.CobarAdapterDAO 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)

Aggregations

CobarAdapterDAO (com.alibaba.cobar.manager.dao.CobarAdapterDAO)24 CobarDO (com.alibaba.cobar.manager.dataobject.xml.CobarDO)16 ArrayList (java.util.ArrayList)15 HashMap (java.util.HashMap)15 Map (java.util.Map)14 JSONObject (net.sf.json.JSONObject)9 ModelAndView (org.springframework.web.servlet.ModelAndView)9 UserDO (com.alibaba.cobar.manager.dataobject.xml.UserDO)7 ClusterDO (com.alibaba.cobar.manager.dataobject.xml.ClusterDO)5 CommandStatus (com.alibaba.cobar.manager.dataobject.cobarnode.CommandStatus)4 ProcessorStatus (com.alibaba.cobar.manager.dataobject.cobarnode.ProcessorStatus)4 ServerStatus (com.alibaba.cobar.manager.dataobject.cobarnode.ServerStatus)4 JSONArray (net.sf.json.JSONArray)4 FluenceHashMap (com.alibaba.cobar.manager.util.FluenceHashMap)3 PropertyUtilsBean (org.apache.commons.beanutils.PropertyUtilsBean)3 ConnectionStatus (com.alibaba.cobar.manager.dataobject.cobarnode.ConnectionStatus)2 DataNodesStatus (com.alibaba.cobar.manager.dataobject.cobarnode.DataNodesStatus)2 Pair (com.alibaba.cobar.manager.util.Pair)2 IOException (java.io.IOException)2 ServletException (javax.servlet.ServletException)2