Search in sources :

Example 1 with ElasticsearchNodesSniffer

use of org.elasticsearch.client.sniff.ElasticsearchNodesSniffer in project graylog2-server by Graylog2.

the class FilteredElasticsearchNodesSniffer method create.

static FilteredElasticsearchNodesSniffer create(RestClient restClient, long sniffRequestTimeoutMillis, ElasticsearchNodesSniffer.Scheme scheme, String filter) {
    final String attribute;
    final String value;
    if (!Strings.isNullOrEmpty(filter)) {
        final String[] conditions = filter.split(":");
        if (conditions.length < 2) {
            throw new IllegalArgumentException("Invalid filter specified for ES node discovery: " + filter);
        }
        attribute = conditions[0].trim();
        value = conditions[1].trim();
    } else {
        attribute = null;
        value = null;
    }
    final NodesSniffer nodesSniffer = new ElasticsearchNodesSniffer(restClient, sniffRequestTimeoutMillis, scheme);
    return new FilteredElasticsearchNodesSniffer(nodesSniffer, attribute, value);
}
Also used : ElasticsearchNodesSniffer(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.sniff.ElasticsearchNodesSniffer) NodesSniffer(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.sniff.NodesSniffer) ElasticsearchNodesSniffer(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.sniff.ElasticsearchNodesSniffer)

Example 2 with ElasticsearchNodesSniffer

use of org.elasticsearch.client.sniff.ElasticsearchNodesSniffer 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);
}
Also used : BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) ElasticsearchNodesSniffer(org.elasticsearch.client.sniff.ElasticsearchNodesSniffer) NodesSniffer(org.elasticsearch.client.sniff.NodesSniffer) RestClientBuilder(org.elasticsearch.client.RestClientBuilder) Sniffer(org.elasticsearch.client.sniff.Sniffer) ElasticsearchNodesSniffer(org.elasticsearch.client.sniff.ElasticsearchNodesSniffer) NodesSniffer(org.elasticsearch.client.sniff.NodesSniffer) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) CredentialsProvider(org.apache.http.client.CredentialsProvider) RestHighLevelClient(org.elasticsearch.client.RestHighLevelClient) SniffOnFailureListener(org.elasticsearch.client.sniff.SniffOnFailureListener) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) ElasticsearchNodesSniffer(org.elasticsearch.client.sniff.ElasticsearchNodesSniffer)

Example 3 with ElasticsearchNodesSniffer

use of org.elasticsearch.client.sniff.ElasticsearchNodesSniffer 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();
}
Also used : SnifferBuilder(org.elasticsearch.client.sniff.SnifferBuilder) NodesSniffer(org.elasticsearch.client.sniff.NodesSniffer) ElasticsearchNodesSniffer(org.elasticsearch.client.sniff.ElasticsearchNodesSniffer) ElasticsearchNodesSniffer(org.elasticsearch.client.sniff.ElasticsearchNodesSniffer)

Example 4 with ElasticsearchNodesSniffer

use of org.elasticsearch.client.sniff.ElasticsearchNodesSniffer in project hibernate-search by hibernate.

the class ElasticsearchClientFactoryImpl method createSniffer.

private Sniffer createSniffer(ConfigurationPropertySource propertySource, RestClient client, ServerUris hosts) {
    boolean discoveryEnabled = DISCOVERY_ENABLED.get(propertySource);
    if (discoveryEnabled) {
        SnifferBuilder builder = Sniffer.builder(client).setSniffIntervalMillis(DISCOVERY_REFRESH_INTERVAL.get(propertySource) * // The configured value is in seconds
        1_000);
        // https discovery support
        if (hosts.isSslEnabled()) {
            NodesSniffer hostsSniffer = new ElasticsearchNodesSniffer(client, // 1sec
            ElasticsearchNodesSniffer.DEFAULT_SNIFF_REQUEST_TIMEOUT, ElasticsearchNodesSniffer.Scheme.HTTPS);
            builder.setNodesSniffer(hostsSniffer);
        }
        return builder.build();
    } else {
        return null;
    }
}
Also used : SnifferBuilder(org.elasticsearch.client.sniff.SnifferBuilder) ElasticsearchNodesSniffer(org.elasticsearch.client.sniff.ElasticsearchNodesSniffer) NodesSniffer(org.elasticsearch.client.sniff.NodesSniffer) ElasticsearchNodesSniffer(org.elasticsearch.client.sniff.ElasticsearchNodesSniffer)

Aggregations

ElasticsearchNodesSniffer (org.elasticsearch.client.sniff.ElasticsearchNodesSniffer)3 NodesSniffer (org.elasticsearch.client.sniff.NodesSniffer)3 SnifferBuilder (org.elasticsearch.client.sniff.SnifferBuilder)2 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)1 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)1 CredentialsProvider (org.apache.http.client.CredentialsProvider)1 BasicCredentialsProvider (org.apache.http.impl.client.BasicCredentialsProvider)1 RestClientBuilder (org.elasticsearch.client.RestClientBuilder)1 RestHighLevelClient (org.elasticsearch.client.RestHighLevelClient)1 SniffOnFailureListener (org.elasticsearch.client.sniff.SniffOnFailureListener)1 Sniffer (org.elasticsearch.client.sniff.Sniffer)1 ElasticsearchNodesSniffer (org.graylog.shaded.elasticsearch7.org.elasticsearch.client.sniff.ElasticsearchNodesSniffer)1 NodesSniffer (org.graylog.shaded.elasticsearch7.org.elasticsearch.client.sniff.NodesSniffer)1