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;
}
Aggregations