Search in sources :

Example 16 with PhysicalDatasource

use of com.actiontech.dble.backend.datasource.PhysicalDatasource in project dble by actiontech.

the class ShowDatasourceCluster method getRows.

private static List<RowDataPacket> getRows(String charset) {
    List<RowDataPacket> list = new LinkedList<>();
    ServerConfig conf = DbleServer.getInstance().getConfig();
    // host nodes
    Map<String, PhysicalDBPool> dataHosts = conf.getDataHosts();
    for (PhysicalDBPool pool : dataHosts.values()) {
        for (PhysicalDatasource ds : pool.getAllDataSources()) {
            DBHeartbeat hb = ds.getHeartbeat();
            DataSourceSyncRecorder record = hb.getAsyncRecorder();
            Map<String, String> states = record.getRecords();
            RowDataPacket row = new RowDataPacket(FIELD_COUNT);
            if (!states.isEmpty()) {
                row.add(StringUtil.encode(ds.getName(), charset));
                row.add(StringUtil.encode(ds.getConfig().getIp(), charset));
                row.add(LongUtil.toBytes(ds.getConfig().getPort()));
                row.add(StringUtil.encode(states.get("wsrep_incoming_addresses") == null ? "" : states.get("wsrep_incoming_addresses"), charset));
                row.add(StringUtil.encode(states.get("wsrep_cluster_size") == null ? "" : states.get("wsrep_cluster_size"), charset));
                row.add(StringUtil.encode(states.get("wsrep_cluster_status") == null ? "" : states.get("wsrep_cluster_status"), charset));
                row.add(StringUtil.encode(states.get("wsrep_connected") == null ? "" : states.get("wsrep_connected"), charset));
                row.add(StringUtil.encode(states.get("wsrep_flow_control_paused") == null ? "" : states.get("wsrep_flow_control_paused"), charset));
                row.add(StringUtil.encode(states.get("wsrep_local_state_comment") == null ? "" : states.get("wsrep_local_state_comment"), charset));
                row.add(StringUtil.encode(states.get("wsrep_ready") == null ? "" : states.get("wsrep_ready"), charset));
                row.add(StringUtil.encode(states.get("wsrep_flow_control_paused_ns") == null ? "" : states.get("wsrep_flow_control_paused_ns"), charset));
                row.add(StringUtil.encode(states.get("wsrep_flow_control_recv") == null ? "" : states.get("wsrep_flow_control_recv"), charset));
                row.add(StringUtil.encode(states.get("wsrep_local_bf_aborts") == null ? "" : states.get("wsrep_local_bf_aborts"), charset));
                row.add(StringUtil.encode(states.get("wsrep_local_recv_queue_avg") == null ? "" : states.get("wsrep_local_recv_queue_avg"), charset));
                row.add(StringUtil.encode(states.get("wsrep_local_send_queue_avg") == null ? "" : states.get("wsrep_local_recv_queue_avg"), charset));
                row.add(StringUtil.encode(states.get("wsrep_apply_oool") == null ? "" : states.get("wsrep_apply_oool"), charset));
                row.add(StringUtil.encode(states.get("wsrep_apply_oooe") == null ? "" : states.get("wsrep_apply_oooe"), charset));
                list.add(row);
            }
        }
    }
    return list;
}
Also used : ServerConfig(com.actiontech.dble.config.ServerConfig) PhysicalDatasource(com.actiontech.dble.backend.datasource.PhysicalDatasource) DBHeartbeat(com.actiontech.dble.backend.heartbeat.DBHeartbeat) RowDataPacket(com.actiontech.dble.net.mysql.RowDataPacket) DataSourceSyncRecorder(com.actiontech.dble.statistic.DataSourceSyncRecorder) PhysicalDBPool(com.actiontech.dble.backend.datasource.PhysicalDBPool) LinkedList(java.util.LinkedList)

Example 17 with PhysicalDatasource

use of com.actiontech.dble.backend.datasource.PhysicalDatasource in project dble by actiontech.

the class ShowDatasourceSynDetail method getRows.

private static List<RowDataPacket> getRows(String name, String charset) {
    List<RowDataPacket> list = new LinkedList<>();
    ServerConfig conf = DbleServer.getInstance().getConfig();
    // host nodes
    Map<String, PhysicalDBPool> dataHosts = conf.getDataHosts();
    for (PhysicalDBPool pool : dataHosts.values()) {
        for (PhysicalDatasource ds : pool.getAllDataSources()) {
            DBHeartbeat hb = ds.getHeartbeat();
            DataSourceSyncRecorder record = hb.getAsyncRecorder();
            Map<String, String> states = record.getRecords();
            if (name.equals(ds.getName())) {
                List<Record> data = record.getAsyncRecords();
                for (Record r : data) {
                    RowDataPacket row = new RowDataPacket(FIELD_COUNT);
                    row.add(StringUtil.encode(ds.getName(), charset));
                    row.add(StringUtil.encode(ds.getConfig().getIp(), charset));
                    row.add(LongUtil.toBytes(ds.getConfig().getPort()));
                    row.add(StringUtil.encode(states.get("Master_Host"), charset));
                    row.add(LongUtil.toBytes(Long.parseLong(states.get("Master_Port"))));
                    row.add(StringUtil.encode(states.get("Master_User"), charset));
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    String time = sdf.format(new Date(r.getTime()));
                    row.add(StringUtil.encode(time, charset));
                    row.add(LongUtil.toBytes((Long) r.getValue()));
                    list.add(row);
                }
                break;
            }
        }
    }
    return list;
}
Also used : DBHeartbeat(com.actiontech.dble.backend.heartbeat.DBHeartbeat) RowDataPacket(com.actiontech.dble.net.mysql.RowDataPacket) DataSourceSyncRecorder(com.actiontech.dble.statistic.DataSourceSyncRecorder) PhysicalDBPool(com.actiontech.dble.backend.datasource.PhysicalDBPool) LinkedList(java.util.LinkedList) Date(java.util.Date) ServerConfig(com.actiontech.dble.config.ServerConfig) PhysicalDatasource(com.actiontech.dble.backend.datasource.PhysicalDatasource) Record(com.actiontech.dble.statistic.DataSourceSyncRecorder.Record) SimpleDateFormat(java.text.SimpleDateFormat)

Example 18 with PhysicalDatasource

use of com.actiontech.dble.backend.datasource.PhysicalDatasource in project dble by actiontech.

the class ShowHeartbeatDetail method getRows.

private static List<RowDataPacket> getRows(String name, String charset) {
    List<RowDataPacket> list = new LinkedList<>();
    ServerConfig conf = DbleServer.getInstance().getConfig();
    String ip = "";
    int port = 0;
    DBHeartbeat hb = null;
    Map<String, PhysicalDBPool> dataHosts = conf.getDataHosts();
    for (PhysicalDBPool pool : dataHosts.values()) {
        for (PhysicalDatasource ds : pool.getAllDataSources()) {
            if (name.equals(ds.getName())) {
                hb = ds.getHeartbeat();
                ip = ds.getConfig().getIp();
                port = ds.getConfig().getPort();
                break;
            }
        }
    }
    if (hb != null) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Queue<HeartbeatRecorder.Record> heartbeatRecorders = hb.getRecorder().getRecordsAll();
        for (HeartbeatRecorder.Record record : heartbeatRecorders) {
            RowDataPacket row = new RowDataPacket(FIELD_COUNT);
            row.add(StringUtil.encode(name, charset));
            row.add(StringUtil.encode(ip, charset));
            row.add(IntegerUtil.toBytes(port));
            long time = record.getTime();
            String timeStr = sdf.format(new Date(time));
            row.add(StringUtil.encode(timeStr, charset));
            row.add(LongUtil.toBytes(record.getValue()));
            list.add(row);
        }
    } else {
        RowDataPacket row = new RowDataPacket(FIELD_COUNT);
        row.add(null);
        row.add(null);
        row.add(null);
        row.add(null);
        row.add(null);
        list.add(row);
    }
    return list;
}
Also used : DBHeartbeat(com.actiontech.dble.backend.heartbeat.DBHeartbeat) RowDataPacket(com.actiontech.dble.net.mysql.RowDataPacket) PhysicalDBPool(com.actiontech.dble.backend.datasource.PhysicalDBPool) ServerConfig(com.actiontech.dble.config.ServerConfig) PhysicalDatasource(com.actiontech.dble.backend.datasource.PhysicalDatasource) HeartbeatRecorder(com.actiontech.dble.statistic.HeartbeatRecorder) SimpleDateFormat(java.text.SimpleDateFormat)

Example 19 with PhysicalDatasource

use of com.actiontech.dble.backend.datasource.PhysicalDatasource in project dble by actiontech.

the class ConfigTest method testReadHostWeight.

/**
 * testReadHostWeight
 *
 * @throws Exception
 */
@Test
public void testReadHostWeight() throws Exception {
    ArrayList<PhysicalDatasource> okSources = new ArrayList<PhysicalDatasource>();
    PhysicalDBPool pool = this.dataHosts.get("localhost2");
    okSources.addAll(pool.getAllDataSources());
    PhysicalDatasource source = pool.randomSelect(okSources);
    Assert.assertTrue(source != null);
}
Also used : PhysicalDatasource(com.actiontech.dble.backend.datasource.PhysicalDatasource) ArrayList(java.util.ArrayList) PhysicalDBPool(com.actiontech.dble.backend.datasource.PhysicalDBPool) Test(org.junit.Test)

Aggregations

PhysicalDatasource (com.actiontech.dble.backend.datasource.PhysicalDatasource)19 PhysicalDBPool (com.actiontech.dble.backend.datasource.PhysicalDBPool)16 ServerConfig (com.actiontech.dble.config.ServerConfig)7 RowDataPacket (com.actiontech.dble.net.mysql.RowDataPacket)7 DBHeartbeat (com.actiontech.dble.backend.heartbeat.DBHeartbeat)5 LinkedList (java.util.LinkedList)4 Map (java.util.Map)4 PhysicalDBNode (com.actiontech.dble.backend.datasource.PhysicalDBNode)3 MySQLDataSource (com.actiontech.dble.backend.mysql.nio.MySQLDataSource)3 DataSourceSyncRecorder (com.actiontech.dble.statistic.DataSourceSyncRecorder)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 SimpleDateFormat (java.text.SimpleDateFormat)2 BackendConnection (com.actiontech.dble.backend.BackendConnection)1 MySQLConsistencyChecker (com.actiontech.dble.backend.heartbeat.MySQLConsistencyChecker)1 MySQLConnection (com.actiontech.dble.backend.mysql.nio.MySQLConnection)1 TableConfig (com.actiontech.dble.config.model.TableConfig)1 ConfigException (com.actiontech.dble.config.util.ConfigException)1 NIOProcessor (com.actiontech.dble.net.NIOProcessor)1 EOFPacket (com.actiontech.dble.net.mysql.EOFPacket)1