use of com.couchbase.connector.config.es.AwsConfig in project couchbase-elasticsearch-connector by couchbase.
the class ElasticsearchHelper method newElasticsearchClient.
public static RestHighLevelClient newElasticsearchClient(List<HttpHost> hosts, String username, String password, boolean secureConnection, Supplier<KeyStore> trustStore, ClientCertConfig clientCert, AwsConfig aws, TimeValue bulkRequestTimeout) throws Exception {
final int connectTimeoutMillis = (int) SECONDS.toMillis(5);
final int socketTimeoutMillis = (int) Math.max(SECONDS.toMillis(60), toMillis(bulkRequestTimeout) + SECONDS.toMillis(3));
LOGGER.info("Elasticsearch client connect timeout = {}ms; socket timeout={}ms", connectTimeoutMillis, socketTimeoutMillis);
final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password));
final SSLContext sslContext = !secureConnection ? null : newSslContext(trustStore.get(), clientCert);
final RestClientBuilder builder = RestClient.builder(Iterables.toArray(hosts, HttpHost.class)).setHttpClientConfigCallback(httpClientBuilder -> {
httpClientBuilder.setSSLContext(sslContext);
if (!clientCert.use()) {
httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
}
awsSigner(aws).ifPresent(httpClientBuilder::addInterceptorLast);
return httpClientBuilder;
}).setRequestConfigCallback(requestConfigBuilder -> requestConfigBuilder.setConnectTimeout(connectTimeoutMillis).setSocketTimeout(socketTimeoutMillis)).setFailureListener(new RestClient.FailureListener() {
@Override
public void onFailure(Node host) {
Metrics.elasticsearchHostOffline().increment();
}
});
return new RestHighLevelClient(builder);
}
Aggregations