use of org.elasticsearch.client.sniff.NodesSniffer in project ARLAS-server by gisaia.
the class ElasticTool method getRestHighLevelClient.
public static ImmutablePair<RestHighLevelClient, Sniffer> getRestHighLevelClient(HttpHost[] nodes, boolean ssl, String cred, boolean skipMaster, boolean sniffing) {
// disable JVM default policies of caching positive hostname resolutions indefinitely
// because the Elastic load balancer can change IP addresses
java.security.Security.setProperty("networkaddress.cache.ttl", "60");
java.security.Security.setProperty("networkaddress.cache.negative.ttl", "0");
RestClientBuilder restClientBuilder = RestClient.builder(nodes);
if (skipMaster) {
restClientBuilder.setNodeSelector(NodeSelector.SKIP_DEDICATED_MASTERS);
}
// Authentication needed ?
if (!StringUtil.isNullOrEmpty(cred)) {
String[] credentials = ElasticConfiguration.getCredentials(cred);
final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(credentials[0], credentials[1]));
restClientBuilder.setHttpClientConfigCallback(httpClientBuilder -> httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider));
}
RestHighLevelClient client = new RestHighLevelClient(restClientBuilder);
// Sniffing should be disabled with Elasticsearch Service (cloud)
Sniffer sniffer = null;
if (sniffing) {
SniffOnFailureListener sniffOnFailureListener = new SniffOnFailureListener();
restClientBuilder.setFailureListener(sniffOnFailureListener);
NodesSniffer nodesSniffer = new ElasticsearchNodesSniffer(client.getLowLevelClient(), ElasticsearchNodesSniffer.DEFAULT_SNIFF_REQUEST_TIMEOUT, ssl ? ElasticsearchNodesSniffer.Scheme.HTTPS : ElasticsearchNodesSniffer.Scheme.HTTP);
sniffer = Sniffer.builder(client.getLowLevelClient()).setSniffAfterFailureDelayMillis(30000).setNodesSniffer(nodesSniffer).build();
sniffOnFailureListener.setSniffer(sniffer);
}
return new ImmutablePair<>(client, sniffer);
}
use of org.elasticsearch.client.sniff.NodesSniffer in project quarkus by quarkusio.
the class RestClientBuilderHelper method createSniffer.
public static Sniffer createSniffer(RestClient client, ElasticsearchConfig config) {
SnifferBuilder builder = Sniffer.builder(client).setSniffIntervalMillis((int) config.discovery.refreshInterval.toMillis());
// https discovery support
if ("https".equalsIgnoreCase(config.protocol)) {
NodesSniffer hostsSniffer = new ElasticsearchNodesSniffer(client, // 1sec
ElasticsearchNodesSniffer.DEFAULT_SNIFF_REQUEST_TIMEOUT, ElasticsearchNodesSniffer.Scheme.HTTPS);
builder.setNodesSniffer(hostsSniffer);
}
return builder.build();
}
use of org.elasticsearch.client.sniff.NodesSniffer in project graylog2-server by Graylog2.
the class FilteredElasticsearchNodesSnifferTest method worksWithEmptyNodesListIfFilterIsSet.
@Test
void worksWithEmptyNodesListIfFilterIsSet() throws Exception {
final List<Node> nodes = Collections.emptyList();
final NodesSniffer nodesSniffer = new FilteredElasticsearchNodesSniffer(mockSniffer(nodes), "rack", "42");
assertThat(nodesSniffer.sniff()).isEqualTo(nodes);
}
use of org.elasticsearch.client.sniff.NodesSniffer in project graylog2-server by Graylog2.
the class FilteredElasticsearchNodesSnifferTest method returnsNoNodesIfFilterDoesNotMatch.
@Test
void returnsNoNodesIfFilterDoesNotMatch() throws Exception {
final List<Node> nodes = mockNodes();
final NodesSniffer nodesSniffer = new FilteredElasticsearchNodesSniffer(mockSniffer(nodes), "location", "alaska");
assertThat(nodesSniffer.sniff()).isEmpty();
}
use of org.elasticsearch.client.sniff.NodesSniffer in project graylog2-server by Graylog2.
the class FilteredElasticsearchNodesSnifferTest method returnsNodesMatchingGivenFilter.
@Test
void returnsNodesMatchingGivenFilter() throws Exception {
final List<Node> nodes = mockNodes();
final NodesSniffer nodesSniffer = new FilteredElasticsearchNodesSniffer(mockSniffer(nodes), "rack", "42");
assertThat(nodesSniffer.sniff()).containsExactly(nodeOnRack42);
}
Aggregations