Search in sources :

Example 26 with RestClientBuilder

use of org.elasticsearch.client.RestClientBuilder in project ranger by apache.

the class ElasticSearchIndexBootStrapper method createClient.

private void createClient() {
    try {
        RestClientBuilder restClientBuilder = getRestClientBuilder(hosts, protocol, user, password, port);
        client = new RestHighLevelClient(restClientBuilder);
    } catch (Throwable t) {
        lastLoggedAt.updateAndGet(lastLoggedAt -> {
            long now = System.currentTimeMillis();
            long elapsed = now - lastLoggedAt;
            if (elapsed > TimeUnit.MINUTES.toMillis(1)) {
                LOG.severe("Can't connect to ElasticSearch server: " + connectionString() + t);
                return now;
            } else {
                return lastLoggedAt;
            }
        });
    }
}
Also used : RestClient(org.elasticsearch.client.RestClient) AuthSchemeProvider(org.apache.http.auth.AuthSchemeProvider) StringUtils(org.apache.commons.lang.StringUtils) RegistryBuilder(org.apache.http.config.RegistryBuilder) RestClientBuilder(org.elasticsearch.client.RestClientBuilder) XContentType(org.elasticsearch.common.xcontent.XContentType) AuthSchemes(org.apache.http.client.config.AuthSchemes) OpenIndexRequest(org.elasticsearch.action.admin.indices.open.OpenIndexRequest) Settings(org.elasticsearch.common.settings.Settings) KerberosCredentialsProvider(org.apache.ranger.authorization.credutils.kerberos.KerberosCredentialsProvider) Locale(java.util.Locale) CredentialReader(org.apache.ranger.credentialapi.CredentialReader) TimeValue(org.elasticsearch.common.unit.TimeValue) Lookup(org.apache.http.config.Lookup) RequestOptions(org.elasticsearch.client.RequestOptions) SPNegoSchemeFactory(org.apache.http.impl.auth.SPNegoSchemeFactory) Path(java.nio.file.Path) CreateIndexRequest(org.elasticsearch.client.indices.CreateIndexRequest) Files(java.nio.file.Files) IOException(java.io.IOException) KeyStore(java.security.KeyStore) Logger(java.util.logging.Logger) RestHighLevelClient(org.elasticsearch.client.RestHighLevelClient) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) TimeUnit(java.util.concurrent.TimeUnit) AtomicLong(java.util.concurrent.atomic.AtomicLong) Paths(java.nio.file.Paths) CredentialsProviderUtil(org.apache.ranger.authorization.credutils.CredentialsProviderUtil) CreateIndexResponse(org.elasticsearch.client.indices.CreateIndexResponse) CredentialsProvider(org.apache.http.client.CredentialsProvider) HttpHost(org.apache.http.HttpHost) RestClientBuilder(org.elasticsearch.client.RestClientBuilder) RestHighLevelClient(org.elasticsearch.client.RestHighLevelClient)

Example 27 with RestClientBuilder

use of org.elasticsearch.client.RestClientBuilder in project pancm_project by xuwujing.

the class EsParticipleSearchTest method init.

/*
     * 初始化服务
     */
private static void init() {
    RestClientBuilder restClientBuilder = RestClient.builder(new HttpHost(elasticIp, elasticPort));
    client = new RestHighLevelClient(restClientBuilder);
}
Also used : HttpHost(org.apache.http.HttpHost) RestClientBuilder(org.elasticsearch.client.RestClientBuilder) RestHighLevelClient(org.elasticsearch.client.RestHighLevelClient)

Example 28 with RestClientBuilder

use of org.elasticsearch.client.RestClientBuilder in project pancm_project by xuwujing.

the class EsAggregationSearchTest method init.

/*
     * 初始化服务
     */
private static void init() {
    RestClientBuilder restClientBuilder = RestClient.builder(new HttpHost(elasticIp, elasticPort));
    client = new RestHighLevelClient(restClientBuilder);
}
Also used : HttpHost(org.apache.http.HttpHost) RestClientBuilder(org.elasticsearch.client.RestClientBuilder) RestHighLevelClient(org.elasticsearch.client.RestHighLevelClient)

Example 29 with RestClientBuilder

use of org.elasticsearch.client.RestClientBuilder in project pancm_project by xuwujing.

the class EsAggregationSearchTest2 method init.

/*
     * 初始化服务
     */
private static void init() {
    RestClientBuilder restClientBuilder = RestClient.builder(new HttpHost(elasticIp, elasticPort));
    client = new RestHighLevelClient(restClientBuilder);
}
Also used : HttpHost(org.apache.http.HttpHost) RestClientBuilder(org.elasticsearch.client.RestClientBuilder) RestHighLevelClient(org.elasticsearch.client.RestHighLevelClient)

Example 30 with RestClientBuilder

use of org.elasticsearch.client.RestClientBuilder in project pancm_project by xuwujing.

the class IpHandler method init.

/*
     * 初始化服务
     */
private static RestHighLevelClient init() {
    if (client == null) {
        synchronized (EsUtil.class) {
            if (client == null) {
                RestClientBuilder restClientBuilder = RestClient.builder(httpHosts);
                client = new RestHighLevelClient(restClientBuilder);
            }
        }
    }
    return client;
}
Also used : RestClientBuilder(org.elasticsearch.client.RestClientBuilder) RestHighLevelClient(org.elasticsearch.client.RestHighLevelClient)

Aggregations

RestClientBuilder (org.elasticsearch.client.RestClientBuilder)34 HttpHost (org.apache.http.HttpHost)27 RestHighLevelClient (org.elasticsearch.client.RestHighLevelClient)23 RestClient (org.elasticsearch.client.RestClient)15 IOException (java.io.IOException)11 CredentialsProvider (org.apache.http.client.CredentialsProvider)11 ArrayList (java.util.ArrayList)7 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)7 BasicCredentialsProvider (org.apache.http.impl.client.BasicCredentialsProvider)7 File (java.io.File)6 List (java.util.List)6 Locale (java.util.Locale)6 KeyStore (java.security.KeyStore)5 Map (java.util.Map)5 StringUtils (org.apache.commons.lang.StringUtils)5 AuthSchemeProvider (org.apache.http.auth.AuthSchemeProvider)5 AuthSchemes (org.apache.http.client.config.AuthSchemes)5 Lookup (org.apache.http.config.Lookup)5 RegistryBuilder (org.apache.http.config.RegistryBuilder)5 SPNegoSchemeFactory (org.apache.http.impl.auth.SPNegoSchemeFactory)5