use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.RestHighLevelClient in project hazelcast by hazelcast.
the class ElasticSourcePTest method runProcessor.
private TestSupport runProcessor(FunctionEx<ActionRequest, RequestOptions> optionsFn, List<Shard> shards, boolean slicing, boolean coLocatedReading) throws Exception {
RestHighLevelClient client = mockClient;
ElasticSourceConfiguration<String> configuration = new ElasticSourceConfiguration<String>(() -> client, () -> new SearchRequest("*"), optionsFn, SearchHit::getSourceAsString, slicing, coLocatedReading, KEEP_ALIVE, 5);
// This constructor calls the client so it has to be called after specific mock setup in each test method
// rather than in setUp()
processor = new ElasticSourceP<>(configuration, shards);
return TestSupport.verifyProcessor(() -> processor).disableSnapshots();
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.RestHighLevelClient in project sonarqube by SonarSource.
the class EsClientProviderTest method connection_to_local_es_when_cluster_mode_is_disabled.
@Test
public void connection_to_local_es_when_cluster_mode_is_disabled() {
settings.setProperty(CLUSTER_ENABLED.getKey(), false);
settings.setProperty(SEARCH_HOST.getKey(), localhostHostname);
settings.setProperty(SEARCH_PORT.getKey(), 9000);
settings.setProperty(ES_PORT.getKey(), 8080);
EsClient client = underTest.provide(settings.asConfig());
RestHighLevelClient nativeClient = client.nativeClient();
assertThat(nativeClient.getLowLevelClient().getNodes()).hasSize(1);
Node node = nativeClient.getLowLevelClient().getNodes().get(0);
assertThat(node.getHost().getAddress().getHostName()).isEqualTo(localhostHostname);
assertThat(node.getHost().getPort()).isEqualTo(9000);
assertThat(logTester.logs(LoggerLevel.INFO)).has(new Condition<>(s -> s.contains("Connected to local Elasticsearch: [http://" + localhostHostname + ":9000]"), ""));
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.RestHighLevelClient in project sonarqube by SonarSource.
the class EsClientProviderTest method connection_to_remote_es_nodes_when_cluster_mode_is_enabled_and_local_es_is_disabled.
@Test
public void connection_to_remote_es_nodes_when_cluster_mode_is_enabled_and_local_es_is_disabled() {
settings.setProperty(CLUSTER_ENABLED.getKey(), true);
settings.setProperty(CLUSTER_NODE_TYPE.getKey(), "application");
settings.setProperty(CLUSTER_SEARCH_HOSTS.getKey(), format("%s:8080,%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(8080);
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 + ":8080, http://" + localhostHostname + ":8081]"), ""));
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.RestHighLevelClient in project metron by apache.
the class ElasticsearchDaoTest method setup.
private void setup(RestStatus status, int maxSearchResults, Map<String, FieldType> metadata) throws Exception {
// setup the mock search hits
SearchHit hit1 = mock(SearchHit.class);
when(hit1.getId()).thenReturn("id1");
when(hit1.getSource()).thenReturn(new HashMap<String, Object>() {
{
put("field", "value1");
}
});
when(hit1.getScore()).thenReturn(0.1f);
SearchHit hit2 = mock(SearchHit.class);
when(hit2.getId()).thenReturn("id2");
when(hit2.getSource()).thenReturn(new HashMap<String, Object>() {
{
put("field", "value2");
}
});
when(hit2.getScore()).thenReturn(0.2f);
// search hits
SearchHit[] hits = { hit1, hit2 };
SearchHits searchHits = mock(SearchHits.class);
when(searchHits.getHits()).thenReturn(hits);
when(searchHits.getTotalHits()).thenReturn(Integer.toUnsignedLong(hits.length));
// search response which returns the search hits
org.elasticsearch.action.search.SearchResponse response = mock(org.elasticsearch.action.search.SearchResponse.class);
when(response.status()).thenReturn(status);
when(response.getHits()).thenReturn(searchHits);
// provides column metadata
ElasticsearchColumnMetadataDao columnMetadataDao = mock(ElasticsearchColumnMetadataDao.class);
when(columnMetadataDao.getColumnMetadata(any())).thenReturn(metadata);
// returns the search response
requestSubmitter = mock(ElasticsearchRequestSubmitter.class);
when(requestSubmitter.submitSearch(any())).thenReturn(response);
RestHighLevelClient highLevel = mock(RestHighLevelClient.class);
ElasticsearchClient client = new ElasticsearchClient(mock(RestClient.class), highLevel);
// provides configuration
AccessConfig config = mock(AccessConfig.class);
when(config.getMaxSearchResults()).thenReturn(maxSearchResults);
ElasticsearchSearchDao elasticsearchSearchDao = new ElasticsearchSearchDao(client, config, columnMetadataDao, requestSubmitter);
ElasticsearchRetrieveLatestDao elasticsearchRetrieveLatestDao = new ElasticsearchRetrieveLatestDao(client);
ElasticsearchUpdateDao elasticsearchUpdateDao = new ElasticsearchUpdateDao(client, config, elasticsearchRetrieveLatestDao);
dao = new ElasticsearchDao(client, config, elasticsearchSearchDao, elasticsearchUpdateDao, elasticsearchRetrieveLatestDao, columnMetadataDao, requestSubmitter);
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.RestHighLevelClient in project metron by apache.
the class ElasticsearchClientFactory method create.
/**
* Creates an Elasticsearch client from settings provided via the global config.
*
* @return new client
*/
public static ElasticsearchClient create(Map<String, Object> globalConfig) {
ElasticsearchClientConfig esClientConfig = new ElasticsearchClientConfig(getEsSettings(globalConfig));
HttpHost[] httpHosts = getHttpHosts(globalConfig, esClientConfig.getConnectionScheme());
RestClientBuilder builder = RestClient.builder(httpHosts);
builder.setRequestConfigCallback(reqConfigBuilder -> {
// Modifies request config builder with connection and socket timeouts.
// https://www.elastic.co/guide/en/elasticsearch/client/java-rest/5.6/_timeouts.html
reqConfigBuilder.setConnectTimeout(esClientConfig.getConnectTimeoutMillis());
reqConfigBuilder.setSocketTimeout(esClientConfig.getSocketTimeoutMillis());
return reqConfigBuilder;
});
builder.setMaxRetryTimeoutMillis(esClientConfig.getMaxRetryTimeoutMillis());
builder.setHttpClientConfigCallback(clientBuilder -> {
clientBuilder.setDefaultIOReactorConfig(getIOReactorConfig(esClientConfig));
clientBuilder.setDefaultCredentialsProvider(getCredentialsProvider(esClientConfig));
clientBuilder.setSSLContext(getSSLContext(esClientConfig));
return clientBuilder;
});
RestClient lowLevelClient = builder.build();
RestHighLevelClient client = new RestHighLevelClient(lowLevelClient);
return new ElasticsearchClient(lowLevelClient, client);
}
Aggregations