Search in sources :

Example 1 with RestHighLevelClientProvider

use of io.openk9.search.client.api.RestHighLevelClientProvider in project openk9 by smclab.

the class ElasticSearchActivator method activate.

@Activate
public void activate(BundleContext bundleContext) throws IOException {
    CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
    credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(_elasticSearchConfiguration.getUsername(), _elasticSearchConfiguration.getPassword()));
    RestClientBuilder builder = RestClient.builder(Arrays.stream(_elasticSearchConfiguration.hosts()).map(e -> e.split(":")).map(e -> new HttpHost(e[0], Integer.parseInt(e[1]))).toArray(HttpHost[]::new));
    builder.setHttpClientConfigCallback(httpClientBuilder -> httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider));
    RestHighLevelClient restHighLevelClient = new RestHighLevelClient(builder);
    RestHighLevelClientProvider restHighLevelClientProvider = new RestHighLevelClientProviderImpl(restHighLevelClient);
    ServiceRegistration<RestHighLevelClientProvider> serviceRegistration = bundleContext.registerService(RestHighLevelClientProvider.class, restHighLevelClientProvider, null);
    _registrationList.add(AutoCloseables.mergeAutoCloseableToSafe(serviceRegistration::unregister, restHighLevelClient));
}
Also used : RestClient(org.elasticsearch.client.RestClient) Arrays(java.util.Arrays) ElasticSearchConfiguration(io.openk9.search.client.api.configuration.ElasticSearchConfiguration) RestClientBuilder(org.elasticsearch.client.RestClientBuilder) Iterator(java.util.Iterator) Deactivate(org.osgi.service.component.annotations.Deactivate) IOException(java.io.IOException) RestHighLevelClient(org.elasticsearch.client.RestHighLevelClient) BundleContext(org.osgi.framework.BundleContext) ArrayList(java.util.ArrayList) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) AutoCloseables(io.openk9.osgi.util.AutoCloseables) Component(org.osgi.service.component.annotations.Component) List(java.util.List) AuthScope(org.apache.http.auth.AuthScope) Modified(org.osgi.service.component.annotations.Modified) Activate(org.osgi.service.component.annotations.Activate) CredentialsProvider(org.apache.http.client.CredentialsProvider) Reference(org.osgi.service.component.annotations.Reference) RestHighLevelClientProvider(io.openk9.search.client.api.RestHighLevelClientProvider) HttpHost(org.apache.http.HttpHost) ServiceRegistration(org.osgi.framework.ServiceRegistration) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) RestHighLevelClientProvider(io.openk9.search.client.api.RestHighLevelClientProvider) HttpHost(org.apache.http.HttpHost) RestClientBuilder(org.elasticsearch.client.RestClientBuilder) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) CredentialsProvider(org.apache.http.client.CredentialsProvider) RestHighLevelClient(org.elasticsearch.client.RestHighLevelClient) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) Activate(org.osgi.service.component.annotations.Activate)

Aggregations

AutoCloseables (io.openk9.osgi.util.AutoCloseables)1 RestHighLevelClientProvider (io.openk9.search.client.api.RestHighLevelClientProvider)1 ElasticSearchConfiguration (io.openk9.search.client.api.configuration.ElasticSearchConfiguration)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Iterator (java.util.Iterator)1 List (java.util.List)1 HttpHost (org.apache.http.HttpHost)1 AuthScope (org.apache.http.auth.AuthScope)1 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)1 CredentialsProvider (org.apache.http.client.CredentialsProvider)1 BasicCredentialsProvider (org.apache.http.impl.client.BasicCredentialsProvider)1 RestClient (org.elasticsearch.client.RestClient)1 RestClientBuilder (org.elasticsearch.client.RestClientBuilder)1 RestHighLevelClient (org.elasticsearch.client.RestHighLevelClient)1 BundleContext (org.osgi.framework.BundleContext)1 ServiceRegistration (org.osgi.framework.ServiceRegistration)1 Activate (org.osgi.service.component.annotations.Activate)1 Component (org.osgi.service.component.annotations.Component)1