Search in sources :

Example 1 with ClusterDO

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

the class ClusterDAOImple method read.

private boolean read() {
    FileInputStream is = null;
    lock.lock();
    try {
        map.clear();
        is = new FileInputStream(xmlPath);
        xpp.setInput(is, "UTF-8");
        while (!(xpp.getEventType() == XmlPullParser.END_TAG && "clusters".equals(xpp.getName()))) {
            if (xpp.getEventType() == XmlPullParser.START_TAG && "cluster".equals(xpp.getName())) {
                ClusterDO cluster = read(xpp);
                if (null == cluster) {
                    throw new XmlPullParserException("Cluster read error");
                }
                maxId = (maxId < cluster.getId()) ? cluster.getId() : maxId;
                map.put(cluster.getId(), cluster);
            }
            xpp.next();
        }
        is.close();
        return true;
    } catch (FileNotFoundException e) {
        logger.error(e.getMessage(), e);
    } catch (XmlPullParserException e) {
        logger.error(e.getMessage(), e);
    } catch (IOException e) {
        logger.error(e.getMessage(), e);
    } finally {
        maxId = maxId < 0 ? 0 : maxId;
        lock.unlock();
    }
    if (null != is) {
        try {
            is.close();
        } catch (IOException e) {
            logger.error(e.getMessage(), e);
        }
    }
    return false;
}
Also used : ClusterDO(com.alibaba.cobar.manager.dataobject.xml.ClusterDO) FileNotFoundException(java.io.FileNotFoundException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream)

Example 2 with ClusterDO

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

the class ClusterDAOImple method checkName.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public boolean checkName(String name, long id) {
    Iterator it = map.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry<Long, ClusterDO> entry = (Entry<Long, ClusterDO>) it.next();
        ClusterDO cluster = entry.getValue();
        if (cluster.getId() == id) {
            continue;
        }
        if (name.equals(cluster.getName())) {
            return false;
        }
    }
    return true;
}
Also used : Entry(java.util.Map.Entry) ClusterDO(com.alibaba.cobar.manager.dataobject.xml.ClusterDO) Iterator(java.util.Iterator) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with ClusterDO

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

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

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

Aggregations

ClusterDO (com.alibaba.cobar.manager.dataobject.xml.ClusterDO)30 ModelAndView (org.springframework.web.servlet.ModelAndView)16 HashMap (java.util.HashMap)15 Map (java.util.Map)15 FluenceHashMap (com.alibaba.cobar.manager.util.FluenceHashMap)12 UserDO (com.alibaba.cobar.manager.dataobject.xml.UserDO)11 ArrayList (java.util.ArrayList)11 CobarDO (com.alibaba.cobar.manager.dataobject.xml.CobarDO)9 PropertyUtilsBean (org.apache.commons.beanutils.PropertyUtilsBean)7 Test (org.junit.Test)7 CobarAdapterDAO (com.alibaba.cobar.manager.dao.CobarAdapterDAO)5 IOException (java.io.IOException)5 Iterator (java.util.Iterator)3 Entry (java.util.Map.Entry)3 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)2 ClusterDAOImple (com.alibaba.cobar.manager.dao.xml.ClusterDAOImple)1 ConnectionStatus (com.alibaba.cobar.manager.dataobject.cobarnode.ConnectionStatus)1 DataNodesStatus (com.alibaba.cobar.manager.dataobject.cobarnode.DataNodesStatus)1 ServerStatus (com.alibaba.cobar.manager.dataobject.cobarnode.ServerStatus)1 FileInputStream (java.io.FileInputStream)1