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));
}
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));
}
}
}
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;
}
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();
}
}
Aggregations