Search in sources :

Example 1 with ESTransportClient

use of org.apache.sdap.mudrod.utils.ESTransportClient in project incubator-sdap-mudrod by apache.

the class ESDriver method makeClient.

/**
 * Generates a TransportClient or NodeClient
 *
 * @param props a populated {@link java.util.Properties} object
 * @return a constructed {@link org.elasticsearch.client.Client}
 * @throws IOException if there is an error building the
 *                     {@link org.elasticsearch.client.Client}
 */
protected Client makeClient(Properties props) throws IOException {
    String clusterName = props.getProperty(MudrodConstants.ES_CLUSTER);
    String hostsString = props.getProperty(MudrodConstants.ES_UNICAST_HOSTS);
    String[] hosts = hostsString.split(",");
    String portStr = props.getProperty(MudrodConstants.ES_TRANSPORT_TCP_PORT);
    int port = Integer.parseInt(portStr);
    Settings.Builder settingsBuilder = Settings.builder();
    // Set the cluster name and build the settings
    if (!clusterName.isEmpty())
        settingsBuilder.put("cluster.name", clusterName);
    settingsBuilder.put("http.type", "netty3");
    settingsBuilder.put("transport.type", "netty3");
    Settings settings = settingsBuilder.build();
    Client client = null;
    // Prefer TransportClient
    if (hosts != null && port > 1) {
        TransportClient transportClient = new ESTransportClient(settings);
        for (String host : hosts) transportClient.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(host), port));
        client = transportClient;
    } else if (clusterName != null) {
        node = new Node(settings);
        client = node.client();
    }
    return client;
}
Also used : TransportClient(org.elasticsearch.client.transport.TransportClient) ESTransportClient(org.apache.sdap.mudrod.utils.ESTransportClient) Node(org.elasticsearch.node.Node) TransportClient(org.elasticsearch.client.transport.TransportClient) ESTransportClient(org.apache.sdap.mudrod.utils.ESTransportClient) Client(org.elasticsearch.client.Client) ESTransportClient(org.apache.sdap.mudrod.utils.ESTransportClient) InetSocketTransportAddress(org.elasticsearch.common.transport.InetSocketTransportAddress) Settings(org.elasticsearch.common.settings.Settings)

Aggregations

ESTransportClient (org.apache.sdap.mudrod.utils.ESTransportClient)1 Client (org.elasticsearch.client.Client)1 TransportClient (org.elasticsearch.client.transport.TransportClient)1 Settings (org.elasticsearch.common.settings.Settings)1 InetSocketTransportAddress (org.elasticsearch.common.transport.InetSocketTransportAddress)1 Node (org.elasticsearch.node.Node)1