Search in sources :

Example 1 with DBHostConfig

use of com.actiontech.dble.config.model.DBHostConfig in project dble by actiontech.

the class ProxyMetaManager method getSelfNodes.

private Set<String> getSelfNodes(ServerConfig config) {
    Set<String> selfNode = null;
    for (Map.Entry<String, PhysicalDBPool> entry : config.getDataHosts().entrySet()) {
        PhysicalDBPool host = entry.getValue();
        DBHostConfig wHost = host.getSource().getConfig();
        if (("localhost".equalsIgnoreCase(wHost.getIp()) || "127.0.0.1".equalsIgnoreCase(wHost.getIp())) && wHost.getPort() == config.getSystem().getServerPort()) {
            for (Map.Entry<String, PhysicalDBNode> nodeEntry : config.getDataNodes().entrySet()) {
                if (nodeEntry.getValue().getDbPool().getHostName().equals(host.getHostName())) {
                    if (selfNode == null) {
                        selfNode = new HashSet<>(2);
                    }
                    selfNode.add(nodeEntry.getKey());
                }
            }
            break;
        }
    }
    return selfNode;
}
Also used : DBHostConfig(com.actiontech.dble.config.model.DBHostConfig) PhysicalDBNode(com.actiontech.dble.backend.datasource.PhysicalDBNode) PhysicalDBPool(com.actiontech.dble.backend.datasource.PhysicalDBPool)

Example 2 with DBHostConfig

use of com.actiontech.dble.config.model.DBHostConfig in project dble by actiontech.

the class ShowTableDataNode method getRows.

private static List<RowDataPacket> getRows(List<String> dataNodes, String charset) {
    List<RowDataPacket> list = new ArrayList<>();
    int sequence = 0;
    for (String dataNode : dataNodes) {
        PhysicalDBNode dn = DbleServer.getInstance().getConfig().getDataNodes().get(dataNode);
        DBHostConfig dbConfig = dn.getDbPool().getSource().getConfig();
        RowDataPacket row = new RowDataPacket(FIELD_COUNT);
        row.add(StringUtil.encode(dn.getName(), charset));
        row.add(LongUtil.toBytes(sequence));
        row.add(StringUtil.encode(dbConfig.getIp(), charset));
        row.add(LongUtil.toBytes(dbConfig.getPort()));
        row.add(StringUtil.encode(dn.getDatabase(), charset));
        row.add(StringUtil.encode(dbConfig.getUser(), charset));
        row.add(StringUtil.encode(dbConfig.getPassword(), charset));
        list.add(row);
        sequence++;
    }
    return list;
}
Also used : PhysicalDBNode(com.actiontech.dble.backend.datasource.PhysicalDBNode) DBHostConfig(com.actiontech.dble.config.model.DBHostConfig) RowDataPacket(com.actiontech.dble.net.mysql.RowDataPacket) ArrayList(java.util.ArrayList)

Example 3 with DBHostConfig

use of com.actiontech.dble.config.model.DBHostConfig in project dble by actiontech.

the class MySQLConnectionFactory method make.

@SuppressWarnings({ "unchecked", "rawtypes" })
public MySQLConnection make(MySQLDataSource pool, ResponseHandler handler, String schema) throws IOException {
    DBHostConfig dsc = pool.getConfig();
    NetworkChannel channel = openSocketChannel(DbleServer.getInstance().isAIO());
    MySQLConnection c = new MySQLConnection(channel, pool.isReadNode());
    c.setSocketParams(false);
    c.setHost(dsc.getIp());
    c.setPort(dsc.getPort());
    c.setUser(dsc.getUser());
    c.setPassword(dsc.getPassword());
    c.setSchema(schema);
    c.setHandler(new MySQLConnectionAuthenticator(c, handler));
    c.setPool(pool);
    c.setIdleTimeout(pool.getConfig().getIdleTimeout());
    if (channel instanceof AsynchronousSocketChannel) {
        ((AsynchronousSocketChannel) channel).connect(new InetSocketAddress(dsc.getIp(), dsc.getPort()), c, (CompletionHandler) DbleServer.getInstance().getConnector());
    } else {
        ((NIOConnector) DbleServer.getInstance().getConnector()).postConnect(c);
    }
    return c;
}
Also used : DBHostConfig(com.actiontech.dble.config.model.DBHostConfig) NetworkChannel(java.nio.channels.NetworkChannel) AsynchronousSocketChannel(java.nio.channels.AsynchronousSocketChannel) NIOConnector(com.actiontech.dble.net.NIOConnector) InetSocketAddress(java.net.InetSocketAddress)

Aggregations

DBHostConfig (com.actiontech.dble.config.model.DBHostConfig)3 PhysicalDBNode (com.actiontech.dble.backend.datasource.PhysicalDBNode)2 PhysicalDBPool (com.actiontech.dble.backend.datasource.PhysicalDBPool)1 NIOConnector (com.actiontech.dble.net.NIOConnector)1 RowDataPacket (com.actiontech.dble.net.mysql.RowDataPacket)1 InetSocketAddress (java.net.InetSocketAddress)1 AsynchronousSocketChannel (java.nio.channels.AsynchronousSocketChannel)1 NetworkChannel (java.nio.channels.NetworkChannel)1 ArrayList (java.util.ArrayList)1