Github user nickwallen commented on a diff in the pull request:

    https://github.com/apache/metron/pull/1242#discussion_r227847716
  
    --- Diff: 
metron-platform/metron-elasticsearch/src/main/java/org/apache/metron/elasticsearch/utils/ElasticsearchUtils.java
 ---
    @@ -124,102 +129,146 @@ public static String getBaseIndexName(String 
indexName) {
       }
     
       /**
    -   * Instantiates an Elasticsearch client based on es.client.class, if 
set. Defaults to
    -   * org.elasticsearch.transport.client.PreBuiltTransportClient.
    +   * Instantiates an Elasticsearch client
        *
        * @param globalConfiguration Metron global config
    -   * @return
    +   * @return new es client
        */
    -  public static TransportClient getClient(Map<String, Object> 
globalConfiguration) {
    -    Set<String> customESSettings = new HashSet<>();
    -    customESSettings.addAll(Arrays.asList("es.client.class", 
USERNAME_CONFIG_KEY, PWD_FILE_CONFIG_KEY));
    -    Settings.Builder settingsBuilder = Settings.builder();
    -    Map<String, String> esSettings = getEsSettings(globalConfiguration);
    -    for (Map.Entry<String, String> entry : esSettings.entrySet()) {
    -      String key = entry.getKey();
    -      String value = entry.getValue();
    -      if (!customESSettings.contains(key)) {
    -        settingsBuilder.put(key, value);
    -      }
    -    }
    -    settingsBuilder.put("cluster.name", 
globalConfiguration.get("es.clustername"));
    -    settingsBuilder.put("client.transport.ping_timeout", 
esSettings.getOrDefault("client.transport.ping_timeout","500s"));
    -    setXPackSecurityOrNone(settingsBuilder, esSettings);
    -
    -    try {
    -      LOG.info("Number of available processors in Netty: {}", 
NettyRuntimeWrapper.availableProcessors());
    -      // Netty sets available processors statically and if an attempt is 
made to set it more than
    -      // once an IllegalStateException is thrown by 
NettyRuntime.setAvailableProcessors(NettyRuntime.java:87)
    -      // 
https://discuss.elastic.co/t/getting-availableprocessors-is-already-set-to-1-rejecting-1-illegalstateexception-exception/103082
    -      // 
https://discuss.elastic.co/t/elasticsearch-5-4-1-availableprocessors-is-already-set/88036
    -      System.setProperty("es.set.netty.runtime.available.processors", 
"false");
    -      TransportClient client = 
createTransportClient(settingsBuilder.build(), esSettings);
    -      for (HostnamePort hp : getIps(globalConfiguration)) {
    -        client.addTransportAddress(
    -                new 
InetSocketTransportAddress(InetAddress.getByName(hp.hostname), hp.port)
    -        );
    -      }
    -      return client;
    -    } catch (UnknownHostException exception) {
    -      throw new RuntimeException(exception);
    -    }
    +  public static ElasticsearchClient getClient(Map<String, Object> 
globalConfiguration) {
    --- End diff --
    
    I just found myself trying to instantiate a new `ElasticsearchClient` with 
no idea how to go about doing that.  Then I remember running across this method 
in your PR.  This seems really broadly useful.
    
    Could we make this functionality more discoverable somehow?  We could make 
this a static method on `ElasticsearchClient`.  Or just refer to this method in 
the javadocs for `ElasticsearchClient`?  Or some other way?


---

Reply via email to