Issue 1:
Elasticsearch version:

2.3.3

Plugins installed: []

head

JVM version:

java version "1.7.0_79"

Java(TM) SE Runtime Environment (build 1.7.0_79-b15)

Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)

OS version:

LSB Version: :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch

Distributor ID: CentOS

Description: CentOS release 6.7 (Final)

Release: 6.7

Codename: Final

Description of the problem including expected versus actual behavior:

Steps to reproduce:

set es config

cluster.name: es-tmp-cluster

node.master: true

node.data: false

discovery.zen.ping.unicast.hosts: ["10.20.20.2:9300"]

network.bind_host: 0.0.0.0

network.publish_host: 10.20.20.2

every node have two network card. one is for public network 192.20.20.2 the other is for es private network is 10.20.20.2

when i run set sniff to true

import org.elasticsearch.client.transport.TransportClient;

import org.elasticsearch.common.settings.Settings;

import org.elasticsearch.common.transport.InetSocketTransportAddress;

import java.net.InetAddress;

import java.net.UnknownHostException;

/**

@author Ricky

*/

public class Test {

public static void main(String[] args) throws UnknownHostException {

Settings settings = Settings.settingsBuilder()
.put("cluster.name", "test-tmp-cluster")
.put("client.transport.sniff", true)
.put("client.transport.ignore_cluster_name", false)
.put("client.transport.ping_timeout", "30s")
.put("client.transport.nodes_sampler_interval", "5s")
.build();

TransportClient client = TransportClient.builder().settings(settings).build()
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("192.20.20.2"), 9300));

client.prepareIndex("test_index", "test_type").setSource("{\"name\":\"Ricky\"}").execute().actionGet();

client.close();

}

}

Provide logs (if relevant):

INFO: [Chan Luichow] modules [], plugins [], sites []

Oct 13, 2016 10:19:55 PM org.elasticsearch.transport.netty.NettyTransport exceptionCaught

WARNING: [Chan Luichow] exception caught on transport layer [[id: 0x0128ca17]], closing connection

java.net.NoRouteToHostException: No route to host

at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)

at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:739)

at org.jboss.netty.channel.socket.nio.NioClientBoss.connect(NioClientBoss.java:152)

at org.jboss.netty.channel.socket.nio.NioClientBoss.processSelectedKeys(NioClientBoss.java:105)

at org.jboss.netty.channel.socket.nio.NioClientBoss.process(NioClientBoss.java:79)

at org.jboss.netty.channel.socket.nio.AbstractNioSelector.run(AbstractNioSelector.java:337)

at org.jboss.netty.channel.socket.nio.NioClientBoss.run(NioClientBoss.java:42)

at org.jboss.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108)

at org.jboss.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:42)

at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)

at java.lang.Thread.run(Thread.java:745)

Oct 13, 2016 10:19:56 PM org.elasticsearch.transport.netty.NettyTransport exceptionCaught

WARNING: [Chan Luichow] exception caught on transport layer [[id: 0x9fabc4ac]], closing connection

java.net.NoRouteToHostException: No route to host

at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)

at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:739)

at org.jboss.netty.channel.socket.nio.NioClientBoss.connect(NioClientBoss.java:152)

at org.jboss.netty.channel.socket.nio.NioClientBoss.processSelectedKeys(NioClientBoss.java:105)

at org.jboss.netty.channel.socket.nio.NioClientBoss.process(NioClientBoss.java:79)

at org.jboss.netty.channel.socket.nio.AbstractNioSelector.run(AbstractNioSelector.java:337)

at org.jboss.netty.channel.socket.nio.NioClientBoss.run(NioClientBoss.java:42)

at org.jboss.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108)

at org.jboss.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:42)

at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)

at java.lang.Thread.run(Thread.java:745)

Exception in thread "main" NoNodeAvailableException[None of the configured nodes are available: [{#transport#-1}{192.20.20.2}{192.20.20.2:9300}]]

at org.elasticsearch.client.transport.TransportClientNodesService.ensureNodesAreAvailable(TransportClientNodesService.java:290)

at org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:207)

at org.elasticsearch.client.transport.support.TransportProxyClient.execute(TransportProxyClient.java:55)

at org.elasticsearch.client.transport.TransportClient.doExecute(TransportClient.java:288)

at org.elasticsearch.client.support.AbstractClient.execute(AbstractClient.java:359)

at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:86)

at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:56)

at Test.main(Test.java:33)

Issue 2:
When using the TransportClient with Sniffing, the Java application is using any of the profiles that you configure internally in the nodes. That way, is hard to separate the ports that the TransportClient uses to connect to the cluster, and the connections between the node.

Using a static pool resolves the issue, because you just use a fixed list of Ips+Hosts.

We should consider adding a new setting to the TransportClient to define a (set) of profiles (or default) so we don't use non-permitted endpoints when sniffing.