Search in sources :

Example 1 with NodesSniffer

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

the class FilteredElasticsearchNodesSnifferTest method returnsAllNodesIfFilterMatchesAll.

@Test
void returnsAllNodesIfFilterMatchesAll() throws Exception {
    final List<Node> nodes = mockNodes();
    final NodesSniffer nodesSniffer = new FilteredElasticsearchNodesSniffer(mockSniffer(nodes), "always", "true");
    assertThat(nodesSniffer.sniff()).isEqualTo(nodes);
}
Also used : Node(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Node) NodesSniffer(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.sniff.NodesSniffer) Test(org.junit.jupiter.api.Test)

Example 2 with NodesSniffer

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

the class FilteredElasticsearchNodesSnifferTest method doesNotFilterNodesIfNoFilterIsSet.

@Test
void doesNotFilterNodesIfNoFilterIsSet() throws Exception {
    final List<Node> nodes = mockNodes();
    final NodesSniffer nodesSniffer = new FilteredElasticsearchNodesSniffer(mockSniffer(nodes), null, null);
    assertThat(nodesSniffer.sniff()).isEqualTo(nodes);
}
Also used : Node(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Node) NodesSniffer(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.sniff.NodesSniffer) Test(org.junit.jupiter.api.Test)

Example 3 with NodesSniffer

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

the class FilteredElasticsearchNodesSnifferTest method returnsMatchingNodesIfGivenAttributeIsInList.

@Test
void returnsMatchingNodesIfGivenAttributeIsInList() throws Exception {
    final Node matchingNode = mockNode(ImmutableMap.of("something", ImmutableList.of("somevalue", "42", "pi")));
    final List<Node> nodes = Collections.singletonList(matchingNode);
    final NodesSniffer nodesSniffer = new FilteredElasticsearchNodesSniffer(mockSniffer(nodes), "something", "42");
    assertThat(nodesSniffer.sniff()).isEqualTo(nodes);
}
Also used : Node(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Node) NodesSniffer(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.sniff.NodesSniffer) Test(org.junit.jupiter.api.Test)

Example 4 with NodesSniffer

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

the class FilteredElasticsearchNodesSnifferTest method mockSniffer.

private NodesSniffer mockSniffer(List<Node> nodes) throws IOException {
    final NodesSniffer mockSniffer = mock(NodesSniffer.class);
    when(mockSniffer.sniff()).thenReturn(nodes);
    return mockSniffer;
}
Also used : NodesSniffer(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.sniff.NodesSniffer)

Example 5 with NodesSniffer

use of org.elasticsearch.client.sniff.NodesSniffer 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)

Aggregations

NodesSniffer (org.graylog.shaded.elasticsearch7.org.elasticsearch.client.sniff.NodesSniffer)8 Node (org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Node)6 Test (org.junit.jupiter.api.Test)6 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