public ShellNativeClient newNodeClient(String clusterName) {
Settings settings = ImmutableSettings.settingsBuilder()
.put("name", shellSettings.settings().get(ShellSettings.NODE_NAME))
.put("http.enabled", false)
.build();
Node node = NodeBuilder.nodeBuilder().clusterName(clusterName).client(true).settings(settings).build();
node.start();
//unfortunately the es clients are not type safe, need to cast it
Client client = node.client();
if (! (client instanceof org.elasticsearch.client.node.NodeClient) ) {
throw new RuntimeException("Unable to create node client: the returned node isn't a NodeClient!");
}
org.elasticsearch.client.node.NodeClient nodeClient = (org.elasticsearch.client.node.NodeClient)client;
//if clusterKo we immediately close both the client and the node that we just created
if (clusterKo(nodeClient)) {
nodeClient.close();
node.close();
return null;
}
AbstractClient<org.elasticsearch.client.node.NodeClient, JsonInput, JsonOutput> shellClient = clientWrapper.wrapEsNodeClient(node, nodeClient);
resourceRegistry.registerResource(shellClient);