elasticsearch/src/main/java/org/apache/calcite/adapter/elasticsearch/ElasticsearchSchemaFactory.java
private static RestClient connect(List<HttpHost> hosts, String pathPrefix,
                                    String username, String password) {

    Objects.requireNonNull(hosts, "hosts or coordinates");
    Preconditions.checkArgument(!hosts.isEmpty(), "no ES hosts specified");
    // Two lists are considered equal when all of their corresponding elements are equal
    // making a list of RestClient parms a suitable cache key.
    List cacheKey = ImmutableList.of(hosts, pathPrefix, username, password);

    try {
      return REST_CLIENTS.get(cacheKey, new Callable<RestClient>() {
        @Override public RestClient call() {
          RestClientBuilder builder = RestClient.builder(hosts.toArray(new HttpHost[hosts.size()]));

          if (!Strings.isNullOrEmpty(username) && !Strings.isNullOrEmpty(password)) {
            CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
            credentialsProvider.setCredentials(AuthScope.ANY,
                new UsernamePasswordCredentials(username, password));
            builder.setHttpClientConfigCallback(httpClientBuilder ->
                httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider));
          }

          if (pathPrefix != null && !pathPrefix.isEmpty()) {
            builder.setPathPrefix(pathPrefix);
          }
          return builder.build();
        }
      });
    } catch (ExecutionException ex) {
      throw new RuntimeException("Cannot return a cached RestClient", ex);
    }
  }
/**
   * Builds Elastic rest client from user configuration.
   *
   * @param hosts list of ES HTTP Hosts to connect to
   * @param username the username of ES
   * @param password the password of ES
   * @return new or cached low-level rest http client for ES
   */
Builds Elastic rest client from user configuration.
@param hosts list of ES HTTP Hosts to connect to
@param username the username of ES
@param password the password of ES
@return new or cached low-level rest http client for ES
Builds Elastic rest client from user configuration . @param hosts list of ES HTTP Hosts to connect to @param username the username of ES @param password the password of ES @return new or cached low - level rest http client for ES
private static RestClient connect(List<HttpHost> hosts, String pathPrefix,
                                    String username, String password) {
    Objects.requireNonNull(hosts, "hosts or coordinates");
    Preconditions.checkArgument(!hosts.isEmpty(), "no ES hosts specified");
    List cacheKey = ImmutableList.of(hosts, pathPrefix, username, password);
    try {
      return REST_CLIENTS.get(cacheKey, new Callable<RestClient>() {
        @Override public RestClient call() {
          RestClientBuilder builder = RestClient.builder(hosts.toArray(new HttpHost[hosts.size()]));
          if (!Strings.isNullOrEmpty(username) && !Strings.isNullOrEmpty(password)) {
            CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
            credentialsProvider.setCredentials(AuthScope.ANY,
                new UsernamePasswordCredentials(username, password));
            builder.setHttpClientConfigCallback(httpClientBuilder ->
                httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider));
          }
          if (pathPrefix != null && !pathPrefix.isEmpty()) {
            builder.setPathPrefix(pathPrefix);
          }
          return builder.build();
        }
      });
    } catch (ExecutionException ex) {
      throw new RuntimeException("Cannot return a cached RestClient", ex);
    }
  }
private static RestClient connect ( List < HttpHost > hosts , String pathPrefix , String username , String password ) { Objects . requireNonNull ( hosts , "hosts or coordinates" ) ; Preconditions . checkArgument ( ! hosts . isEmpty ( ) , "no ES hosts specified" ) ; List cacheKey = ImmutableList . of ( hosts , pathPrefix , username , password ) ; try { return REST_CLIENTS . get ( cacheKey , new Callable < RestClient > ( ) { @ Override public RestClient call ( ) { RestClientBuilder builder = RestClient . builder ( hosts . toArray ( new HttpHost [ hosts . size ( ) ] ) ) ; if ( ! Strings . isNullOrEmpty ( username ) && ! Strings . isNullOrEmpty ( password ) ) { CredentialsProvider credentialsProvider = new BasicCredentialsProvider ( ) ; credentialsProvider . setCredentials ( AuthScope . ANY , new UsernamePasswordCredentials ( username , password ) ) ; builder . setHttpClientConfigCallback ( httpClientBuilder -> httpClientBuilder . setDefaultCredentialsProvider ( credentialsProvider ) ) ; } if ( pathPrefix != null && ! pathPrefix . isEmpty ( ) ) { builder . setPathPrefix ( pathPrefix ) ; } return builder . build ( ) ; } } ) ; } catch ( ExecutionException ex ) { throw new RuntimeException ( "Cannot return a cached RestClient" , ex ) ; } }
Builds Elastic rest client from user configuration.
Builds Elastic rest client from user configuration .
// Two lists are considered equal when all of their corresponding elements are equal // making a list of RestClient parms a suitable cache key.