use of com.alibaba.cobar.CobarNode in project cobar by alibaba.
the class ShowCobarCluster method getRows.
private static List<RowDataPacket> getRows(ServerConnection c) {
List<RowDataPacket> rows = new LinkedList<RowDataPacket>();
CobarConfig config = CobarServer.getInstance().getConfig();
CobarCluster cluster = config.getCluster();
Map<String, SchemaConfig> schemas = config.getSchemas();
SchemaConfig schema = (c.getSchema() == null) ? null : schemas.get(c.getSchema());
// 如果没有指定schema或者schema为null,则使用全部集群。
if (schema == null) {
Map<String, CobarNode> nodes = cluster.getNodes();
for (CobarNode n : nodes.values()) {
if (n != null && n.isOnline()) {
rows.add(getRow(n, c.getCharset()));
}
}
} else {
String group = (schema.getGroup() == null) ? "default" : schema.getGroup();
List<String> nodeList = cluster.getGroups().get(group);
if (nodeList != null && nodeList.size() > 0) {
Map<String, CobarNode> nodes = cluster.getNodes();
for (String id : nodeList) {
CobarNode n = nodes.get(id);
if (n != null && n.isOnline()) {
rows.add(getRow(n, c.getCharset()));
}
}
}
// 如果schema对应的group或者默认group都没有有效的节点,则使用全部集群。
if (rows.size() == 0) {
Map<String, CobarNode> nodes = cluster.getNodes();
for (CobarNode n : nodes.values()) {
if (n != null && n.isOnline()) {
rows.add(getRow(n, c.getCharset()));
}
}
}
}
if (rows.size() == 0) {
alarm.error(Alarms.CLUSTER_EMPTY + c.toString());
}
return rows;
}
use of com.alibaba.cobar.CobarNode in project cobar by alibaba.
the class ShowHeartbeat method getRows.
private static List<RowDataPacket> getRows() {
List<RowDataPacket> list = new LinkedList<RowDataPacket>();
CobarConfig conf = CobarServer.getInstance().getConfig();
// cobar nodes
Map<String, CobarNode> cobarNodes = conf.getCluster().getNodes();
List<String> cobarNodeKeys = new ArrayList<String>(cobarNodes.size());
cobarNodeKeys.addAll(cobarNodes.keySet());
Collections.sort(cobarNodeKeys);
for (String key : cobarNodeKeys) {
CobarNode node = cobarNodes.get(key);
if (node != null) {
CobarHeartbeat hb = node.getHeartbeat();
RowDataPacket row = new RowDataPacket(FIELD_COUNT);
row.add(node.getName().getBytes());
row.add("COBAR".getBytes());
row.add(node.getConfig().getHost().getBytes());
row.add(IntegerUtil.toBytes(node.getConfig().getPort()));
row.add(IntegerUtil.toBytes(hb.getStatus()));
row.add(IntegerUtil.toBytes(hb.getErrorCount()));
row.add(hb.isChecking() ? "checking".getBytes() : "idle".getBytes());
row.add(LongUtil.toBytes(hb.getTimeout()));
row.add(hb.getRecorder().get().getBytes());
String at = hb.lastActiveTime();
row.add(at == null ? null : at.getBytes());
row.add(hb.isStop() ? "true".getBytes() : "false".getBytes());
list.add(row);
}
}
// data nodes
Map<String, MySQLDataNode> dataNodes = conf.getDataNodes();
List<String> dataNodeKeys = new ArrayList<String>(dataNodes.size());
dataNodeKeys.addAll(dataNodes.keySet());
Collections.sort(dataNodeKeys, new Comparators<String>());
for (String key : dataNodeKeys) {
MySQLDataNode node = dataNodes.get(key);
if (node != null) {
MySQLHeartbeat hb = node.getHeartbeat();
RowDataPacket row = new RowDataPacket(FIELD_COUNT);
row.add(node.getName().getBytes());
row.add("MYSQL".getBytes());
if (hb != null) {
row.add(hb.getSource().getConfig().getHost().getBytes());
row.add(IntegerUtil.toBytes(hb.getSource().getConfig().getPort()));
row.add(IntegerUtil.toBytes(hb.getStatus()));
row.add(IntegerUtil.toBytes(hb.getErrorCount()));
row.add(hb.isChecking() ? "checking".getBytes() : "idle".getBytes());
row.add(LongUtil.toBytes(hb.getTimeout()));
row.add(hb.getRecorder().get().getBytes());
String lat = hb.getLastActiveTime();
row.add(lat == null ? null : lat.getBytes());
row.add(hb.isStop() ? "true".getBytes() : "false".getBytes());
} else {
row.add(null);
row.add(null);
row.add(null);
row.add(null);
row.add(null);
row.add(null);
row.add(null);
row.add(null);
row.add(null);
}
list.add(row);
}
}
return list;
}
Aggregations