Search in sources :

Example 1 with ConnectionStatus

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

Example 2 with ConnectionStatus

use of com.alibaba.cobar.manager.dataobject.cobarnode.ConnectionStatus in project cobar by alibaba.

the class TestConnection method testActiveConnection.

@Test(timeout = 60000)
public void testActiveConnection() {
    //TestUtils.waitForMonment(50000);
    int listNum = 10;
    List<ConnectionStatus> connStatusList = null;
    try {
        //create connection
        for (int i = 0; i < listNum; i++) {
            Connection conn = sCobarNode.createDMLConnection("ddl_test");
            connList.add(conn);
        }
        //get connection num from manager
        connStatusList = cobarAdapter.listConnectionStatus();
        Assert.assertNotNull(connStatusList);
        connStatisic(connStatusList);
        Assert.assertEquals(connNum, listNum + 1);
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        Assert.fail();
    } finally {
        for (Connection conn : connList) {
            Assert.assertTrue(sCobarNode.detoryConnection(conn));
        }
    }
}
Also used : Connection(java.sql.Connection) ConnectionStatus(com.alibaba.cobar.manager.dataobject.cobarnode.ConnectionStatus) Test(org.junit.Test)

Example 3 with ConnectionStatus

use of com.alibaba.cobar.manager.dataobject.cobarnode.ConnectionStatus in project cobar by alibaba.

the class CobarNodeInstantPerfValueAjax method listConnection.

/**
     * Connection Tab
     * 
     * @param params
     * @return
     */
private List<Map<String, Object>> listConnection(AjaxParams params) {
    CobarAdapterDAO perfAccesser = cobarAccesser.getAccesser(params.getCobarNodeId());
    if (!perfAccesser.checkConnection()) {
        return null;
    }
    List<ConnectionStatus> list = perfAccesser.listConnectionStatus();
    if (null != list) {
        ListSortUtil.sortConnections(list);
    }
    List<Map<String, Object>> returnList = new ArrayList<Map<String, Object>>();
    for (ConnectionStatus c : list) {
        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 returnList;
}
Also used : CobarAdapterDAO(com.alibaba.cobar.manager.dao.CobarAdapterDAO) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JSONObject(net.sf.json.JSONObject) ConnectionStatus(com.alibaba.cobar.manager.dataobject.cobarnode.ConnectionStatus) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with ConnectionStatus

use of com.alibaba.cobar.manager.dataobject.cobarnode.ConnectionStatus in project cobar by alibaba.

the class TestConnection method testClosedConnection.

@Test(timeout = 60000)
public void testClosedConnection() {
    //TestUtils.waitForMonment(50000);
    int listNum = 10;
    List<ConnectionStatus> connStatusList = null;
    try {
        //create connection
        for (int i = 0; i < listNum; i++) {
            Connection conn = sCobarNode.createDMLConnection("ddl_test");
            connList.add(conn);
        }
        //destroy all connections
        for (Connection conn : connList) {
            Assert.assertTrue(sCobarNode.detoryConnection(conn));
        }
        //get connection num from manager
        connStatusList = cobarAdapter.listConnectionStatus();
        Assert.assertNotNull(connStatusList);
        connStatisic(connStatusList);
        Assert.assertEquals(connNum, 1);
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        Assert.fail();
    }
}
Also used : Connection(java.sql.Connection) ConnectionStatus(com.alibaba.cobar.manager.dataobject.cobarnode.ConnectionStatus) Test(org.junit.Test)

Aggregations

ConnectionStatus (com.alibaba.cobar.manager.dataobject.cobarnode.ConnectionStatus)4 CobarAdapterDAO (com.alibaba.cobar.manager.dao.CobarAdapterDAO)2 Connection (java.sql.Connection)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Test (org.junit.Test)2 ClusterDO (com.alibaba.cobar.manager.dataobject.xml.ClusterDO)1 CobarDO (com.alibaba.cobar.manager.dataobject.xml.CobarDO)1 UserDO (com.alibaba.cobar.manager.dataobject.xml.UserDO)1 FluenceHashMap (com.alibaba.cobar.manager.util.FluenceHashMap)1 JSONObject (net.sf.json.JSONObject)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1