Search in sources :

Example 1 with Node

use of org.elasticsearch.client.Node in project pinpoint by naver.

the class HighLevelConnectInterceptor method getHostList.

private List<String> getHostList(Object arg) {
    if (!(arg instanceof RestClient)) {
        return Collections.emptyList();
    }
    final List<String> hostList = new ArrayList<>();
    HttpHost[] httpHosts = null;
    if (arg instanceof HttpHostInfoAccessor) {
        httpHosts = ((HttpHostInfoAccessor) arg)._$PINPOINT$_getHttpHostInfo();
    }
    // v6.4 ~
    if (httpHosts == null) {
        for (Node node : ((RestClient) arg).getNodes()) {
            final String hostAddress = HostAndPort.toHostAndPortString(node.getHost().getHostName(), node.getHost().getPort());
            hostList.add(hostAddress);
        }
    } else {
        // v6.0 ~ 6.3
        for (HttpHost httpHost : httpHosts) {
            final String hostAddress = HostAndPort.toHostAndPortString(httpHost.getHostName(), httpHost.getPort());
            hostList.add(hostAddress);
        }
    }
    return hostList;
}
Also used : HttpHostInfoAccessor(com.navercorp.pinpoint.plugin.elasticsearch.accessor.HttpHostInfoAccessor) HttpHost(org.apache.http.HttpHost) Node(org.elasticsearch.client.Node) RestClient(org.elasticsearch.client.RestClient) ArrayList(java.util.ArrayList)

Example 2 with Node

use of org.elasticsearch.client.Node 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 3 with Node

use of org.elasticsearch.client.Node 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 4 with Node

use of org.elasticsearch.client.Node 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 5 with Node

use of org.elasticsearch.client.Node in project sonarqube by SonarSource.

the class EsClientProviderTest method es_client_provider_must_add_default_port_when_not_specified.

@Test
public void es_client_provider_must_add_default_port_when_not_specified() {
    settings.setProperty(CLUSTER_ENABLED.getKey(), true);
    settings.setProperty(CLUSTER_NODE_TYPE.getKey(), "application");
    settings.setProperty(CLUSTER_SEARCH_HOSTS.getKey(), format("%s,%s:8081", localhostHostname, localhostHostname));
    EsClient client = underTest.provide(settings.asConfig());
    RestHighLevelClient nativeClient = client.nativeClient();
    assertThat(nativeClient.getLowLevelClient().getNodes()).hasSize(2);
    Node node = nativeClient.getLowLevelClient().getNodes().get(0);
    assertThat(node.getHost().getAddress().getHostName()).isEqualTo(localhostHostname);
    assertThat(node.getHost().getPort()).isEqualTo(9001);
    node = nativeClient.getLowLevelClient().getNodes().get(1);
    assertThat(node.getHost().getAddress().getHostName()).isEqualTo(localhostHostname);
    assertThat(node.getHost().getPort()).isEqualTo(8081);
    assertThat(logTester.logs(LoggerLevel.INFO)).has(new Condition<>(s -> s.contains("Connected to remote Elasticsearch: [http://" + localhostHostname + ":9001, http://" + localhostHostname + ":8081]"), ""));
}
Also used : SEARCH_PORT(org.sonar.process.ProcessProperties.Property.SEARCH_PORT) ES_PORT(org.sonar.process.ProcessProperties.Property.ES_PORT) CLUSTER_ENABLED(org.sonar.process.ProcessProperties.Property.CLUSTER_ENABLED) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.junit.Test) Node(org.elasticsearch.client.Node) RestHighLevelClient(org.elasticsearch.client.RestHighLevelClient) MapSettings(org.sonar.api.config.internal.MapSettings) String.format(java.lang.String.format) InetAddress(java.net.InetAddress) CLUSTER_NODE_TYPE(org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_TYPE) Rule(org.junit.Rule) LogTester(org.sonar.api.utils.log.LogTester) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) CLUSTER_SEARCH_HOSTS(org.sonar.process.ProcessProperties.Property.CLUSTER_SEARCH_HOSTS) Condition(org.assertj.core.api.Condition) CLUSTER_NAME(org.sonar.process.ProcessProperties.Property.CLUSTER_NAME) SEARCH_HOST(org.sonar.process.ProcessProperties.Property.SEARCH_HOST) Before(org.junit.Before) LoggerLevel(org.sonar.api.utils.log.LoggerLevel) Node(org.elasticsearch.client.Node) RestHighLevelClient(org.elasticsearch.client.RestHighLevelClient) Test(org.junit.Test)

Aggregations

Node (org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Node)7 Node (org.elasticsearch.client.Node)6 NodesSniffer (org.graylog.shaded.elasticsearch7.org.elasticsearch.client.sniff.NodesSniffer)6 Test (org.junit.jupiter.api.Test)6 RestHighLevelClient (org.elasticsearch.client.RestHighLevelClient)4 Test (org.junit.Test)4 String.format (java.lang.String.format)3 InetAddress (java.net.InetAddress)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)3 Condition (org.assertj.core.api.Condition)3 Before (org.junit.Before)3 Rule (org.junit.Rule)3 MapSettings (org.sonar.api.config.internal.MapSettings)3 LogTester (org.sonar.api.utils.log.LogTester)3 LoggerLevel (org.sonar.api.utils.log.LoggerLevel)3 CLUSTER_ENABLED (org.sonar.process.ProcessProperties.Property.CLUSTER_ENABLED)3 CLUSTER_NAME (org.sonar.process.ProcessProperties.Property.CLUSTER_NAME)3 CLUSTER_NODE_TYPE (org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_TYPE)3 CLUSTER_SEARCH_HOSTS (org.sonar.process.ProcessProperties.Property.CLUSTER_SEARCH_HOSTS)3