Issue with TransportClient on 5.2.1


(Michael Rozing) #1

hi,
i'm trying to upgrade our ES to 5.2.1 from 2.3.1 and i'm having a ton of issues...
currently i'm facing the following problem:
our java application uses the TransportClient for connecting to our ES servers.
i'm following your "updated" documentation and it seems to be obsolete..
https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/transport-client.html
i'm assuming PreBuiltTransportClient is a class i create that should derive from TransportClient?
our old code(2.3.1) is as follows:

final Settings.Builder settings = Settings.settingsBuilder();
settings.put("cluster.name", config.get("cluster.name", "elasticsearch"));
settings.put("client.transport.sniff", config.getBoolean("client.transport.sniff", true));
settings.put("client.transport.ignore_cluster_name", config.getBoolean("client.transport.ignore_cluster_name", true));
settings.put("client.transport.ping_timeout", config.get("client.transport.ping_timeout", "10s"));
settings.put("client.transport.nodes_sampler_interval", config.get("client.transport.nodes_sampler_interval", "10s"));
settings.put("node.data", config.getBoolean("node.data", false));

final TransportClient transportclient = new TransportClient.Builder().settings(settings).build();
transportclient.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(IP[for this example localhost or 127.0.0.1 will do]), 9300));

then we call the .perpareSearch etc etc...

I've converted the code to compile with the 5.2.1 java sdk,
these are the errors:

first i got the Unsupported transport.type [] error, which i've somehow found other guys with the same problem and "fixed" it by adding settings.put("transport.type", "local"); (tho i believe it is a bad fix!)
since there are no other transport types available... tho it is probably problematic since we need to execute the request on a remote machine eventually..
LocalTransport.java in the doStart creates a default localAddress with a value of "1".... I tried giving it a value of 127.0.0.1 by setting the param "transport.local.address" in settings i got an exception that this param is not valid in settings..... (a change from 5.0...)

now my debug observations:
after setting the localAdress, next the TransportClientNodesService.addTransportAddresses is being called (to add my custom node address(127.0.0.1:9300).
then TransportClientNodesService.SniffNodesSampler::doSample::run is being called to verify that the node i've given is "connectable"..
it goes to LocalTransport::connectToNode and looks inside the "transports" map that contains only the key "1" to verify if the current node i'm adding ("127.0.0.1") exists there.. obviously it doesn't, since only "1" exists there...
then it gets ConnectTransportException and the node is not added to the connectedNodes...
so finally i get the lovely result: NoNodeAvailableException[None of the configured nodes are available: [{#transport#-1}{YAsFCt4NR6aGgs2TqlQpKg}{localhost}{127.0.0.1:9300}]]

my code is:
public PgwsTransportClient(final Settings settings) {
super(settings, Collections.EMPTY_LIST);
}

final Settings.Builder settingsBuilder = Settings.builder();
settingsBuilder.put("cluster.name", config.get("cluster.name", "elasticsearch"));
settingsBuilder.put("client.transport.sniff", config.getBoolean("client.transport.sniff", true));
settingsBuilder.put("client.transport.ignore_cluster_name", config.getBoolean("client.transport.ignore_cluster_name", true));
settingsBuilder.put("client.transport.ping_timeout", config.get("client.transport.ping_timeout", "10s"));
settingsBuilder.put("client.transport.nodes_sampler_interval", config.get("client.transport.nodes_sampler_interval", "10s"));
settingsBuilder.put("transport.type", "local");
settingsBuilder.put("node.data", config.getBoolean("node.data", false));
Settings settings = settingsBuilder.build();

TransportClient transportclient = new PgwsTransportClient(settings);
transportclient.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("127.0.0.1"), 9300));

the issues summary:

  1. untested documentation
  2. tansport.type -> only local is available...
  3. when using local transport type, it won't connect to localhost
  4. can't set "transport.local.address" param in settings

best regards


(David Pilato) #2

Nope. PreBuiltTransportClient is provided in elasticsearch jar.

In your settings, I'd just keep:

settings.put("client.transport.sniff", config.getBoolean("client.transport.sniff", true));
settings.put("client.transport.ping_timeout", config.get("client.transport.ping_timeout", "10s"));
settings.put("client.transport.nodes_sampler_interval", config.get("client.transport.nodes_sampler_interval", "10s"));

And please format your code using </> icon as explained in this guide. It will make your post more readable.

Or use markdown style like:

```
CODE
```

(Michael Rozing) #3

It helped! thank you very much!


(system) closed #4

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.