use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.RestHighLevelClient in project sonarqube by SonarSource.
the class EsConnectorImpl method buildRestHighLevelClient.
private RestHighLevelClient buildRestHighLevelClient() {
HttpHost[] httpHosts = hostAndPorts.stream().map(hostAndPort -> new HttpHost(hostAndPort.getHost(), hostAndPort.getPortOrDefault(9001))).toArray(HttpHost[]::new);
if (LOG.isDebugEnabled()) {
String addresses = Arrays.stream(httpHosts).map(t -> t.getHostName() + ":" + t.getPort()).collect(Collectors.joining(", "));
LOG.debug("Connected to Elasticsearch node: [{}]", addresses);
}
RestClientBuilder builder = RestClient.builder(httpHosts).setHttpClientConfigCallback(httpClientBuilder -> {
if (searchPassword != null) {
BasicCredentialsProvider provider = getBasicCredentialsProvider(searchPassword);
httpClientBuilder.setDefaultCredentialsProvider(provider);
}
return httpClientBuilder;
});
return new RestHighLevelClient(builder);
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.RestHighLevelClient in project sonarqube by SonarSource.
the class EsConnectorImpl method getRestHighLevelClient.
private RestHighLevelClient getRestHighLevelClient() {
RestHighLevelClient res = this.restClient.get();
if (res != null) {
return res;
}
RestHighLevelClient restHighLevelClient = buildRestHighLevelClient();
this.restClient.set(restHighLevelClient);
return restHighLevelClient;
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.RestHighLevelClient 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]"), ""));
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.RestHighLevelClient in project metron by apache.
the class ElasticsearchRequestSubmitterTest method setup.
public ElasticsearchRequestSubmitter setup(SearchResponse response) throws IOException {
// mocks
RestHighLevelClient highLevelClient = mock(RestHighLevelClient.class);
ElasticsearchClient client = new ElasticsearchClient(mock(RestClient.class), highLevelClient);
// the client should return the given search response
when(highLevelClient.search(any())).thenReturn(response);
return new ElasticsearchRequestSubmitter(client);
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.RestHighLevelClient in project metron by apache.
the class ElasticsearchUpdateDaoTest method setup.
@BeforeEach
public void setup() {
accessConfig = new AccessConfig();
retrieveLatestDao = mock(ElasticsearchRetrieveLatestDao.class);
RestHighLevelClient highLevel = mock(RestHighLevelClient.class);
ElasticsearchClient client = new ElasticsearchClient(mock(RestClient.class), highLevel);
updateDao = new ElasticsearchUpdateDao(client, accessConfig, retrieveLatestDao);
}
Aggregations