use of com.alibaba.cobar.net.mysql.RowDataPacket 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;
}
use of com.alibaba.cobar.net.mysql.RowDataPacket in project cobar by alibaba.
the class ShowHelp method execute.
public static void execute(ManagerConnection c) {
ByteBuffer buffer = c.allocate();
// write header
buffer = header.write(buffer, c);
// write fields
for (FieldPacket field : fields) {
buffer = field.write(buffer, c);
}
// write eof
buffer = eof.write(buffer, c);
// write rows
byte packetId = eof.packetId;
for (String key : keys) {
RowDataPacket row = getRow(key, helps.get(key), c.getCharset());
row.packetId = ++packetId;
buffer = row.write(buffer, c);
}
// write last eof
EOFPacket lastEof = new EOFPacket();
lastEof.packetId = ++packetId;
buffer = lastEof.write(buffer, c);
// post write
c.write(buffer);
}
use of com.alibaba.cobar.net.mysql.RowDataPacket in project cobar by alibaba.
the class ShowHelp method getRow.
private static RowDataPacket getRow(String stmt, String desc, String charset) {
RowDataPacket row = new RowDataPacket(FIELD_COUNT);
row.add(StringUtil.encode(stmt, charset));
row.add(StringUtil.encode(desc, charset));
return row;
}
use of com.alibaba.cobar.net.mysql.RowDataPacket in project cobar by alibaba.
the class ShowParser method getRow.
private static RowDataPacket getRow(String charset) {
RowDataPacket row = new RowDataPacket(FIELD_COUNT);
row.add(null);
row.add(null);
row.add(null);
row.add(null);
row.add(null);
row.add(null);
row.add(null);
return row;
}
use of com.alibaba.cobar.net.mysql.RowDataPacket in project cobar by alibaba.
the class ShowRouter method execute.
public static void execute(ManagerConnection c) {
ByteBuffer buffer = c.allocate();
// write header
buffer = header.write(buffer, c);
// write fields
for (FieldPacket field : fields) {
buffer = field.write(buffer, c);
}
// write eof
buffer = eof.write(buffer, c);
// write rows
byte packetId = eof.packetId;
for (NIOProcessor p : CobarServer.getInstance().getProcessors()) {
RowDataPacket row = getRow(p, c.getCharset());
row.packetId = ++packetId;
buffer = row.write(buffer, c);
}
// write last eof
EOFPacket lastEof = new EOFPacket();
lastEof.packetId = ++packetId;
buffer = lastEof.write(buffer, c);
// write buffer
c.write(buffer);
}
Aggregations