Search in sources :

Example 1 with UserDO

use of com.alibaba.cobar.manager.dataobject.xml.UserDO 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 UserDO

use of com.alibaba.cobar.manager.dataobject.xml.UserDO 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 UserDO

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

the class ClusterListScreen method handleRequestInternal.

@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
    UserDO user = (UserDO) request.getSession().getAttribute("user");
    List<ClusterDO> list = xmlAccesser.getClusterDAO().listAllCluster();
    ListSortUtil.sortClusterBySortId(list);
    List<Map<String, Object>> clusterList = new ArrayList<Map<String, Object>>();
    for (ClusterDO e : list) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("id", e.getId());
        map.put("name", CobarStringUtil.htmlEscapedString(e.getName()));
        map.put("maintContact", e.getMaintContact());
        map.put("onlineTime", e.getOnlineTime());
        clusterList.add(map);
    }
    return new ModelAndView("v_clusterList", new FluenceHashMap<String, Object>().putKeyValue("clusterList", clusterList).putKeyValue("user", user));
}
Also used : ClusterDO(com.alibaba.cobar.manager.dataobject.xml.ClusterDO) 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) HashMap(java.util.HashMap) FluenceHashMap(com.alibaba.cobar.manager.util.FluenceHashMap) Map(java.util.Map)

Example 4 with UserDO

use of com.alibaba.cobar.manager.dataobject.xml.UserDO 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 5 with UserDO

use of com.alibaba.cobar.manager.dataobject.xml.UserDO 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)

Aggregations

UserDO (com.alibaba.cobar.manager.dataobject.xml.UserDO)39 ModelAndView (org.springframework.web.servlet.ModelAndView)22 HashMap (java.util.HashMap)15 Map (java.util.Map)15 ClusterDO (com.alibaba.cobar.manager.dataobject.xml.ClusterDO)11 CobarDO (com.alibaba.cobar.manager.dataobject.xml.CobarDO)10 FluenceHashMap (com.alibaba.cobar.manager.util.FluenceHashMap)10 ArrayList (java.util.ArrayList)10 CobarAdapterDAO (com.alibaba.cobar.manager.dao.CobarAdapterDAO)7 PropertyUtilsBean (org.apache.commons.beanutils.PropertyUtilsBean)5 Test (org.junit.Test)5 Iterator (java.util.Iterator)4 Entry (java.util.Map.Entry)4 IOException (java.io.IOException)3 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)3 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)3 MockHttpSession (org.springframework.mock.web.MockHttpSession)3 UserDAOImple (com.alibaba.cobar.manager.dao.xml.UserDAOImple)1 ConnectionStatus (com.alibaba.cobar.manager.dataobject.cobarnode.ConnectionStatus)1 DataNodesStatus (com.alibaba.cobar.manager.dataobject.cobarnode.DataNodesStatus)1