Адрес должен быть разрешен, но не был - InetSocketAddress # getAddress () возвратил ноль - PullRequest
0 голосов
/ 15 сентября 2018

Когда я запускаю свое java-приложение, которое взаимодействует с ElasticSearch 5.6.10 через JavaSi-интерфейсasticsearch и в моем кластереasticsearch более 1 узла, я получаю следующее исключение:

**

**Caused by: java.lang.IllegalArgumentException: Address must be resolved but wasn't - InetSocketAddress#getAddress() returned null
              at org.elasticsearch.common.transport.InetSocketTransportAddress.<init>(InetSocketTransportAddress.java:48)
              at com.intel.mar.data.elasticsearch.client.TransportClientFactory.createTransportClient(TransportClientFactory.java:30)
              at com.intel.mar.service.config.ServiceConfig.serviceDataManager(ServiceConfig.java:81)
              at com.intel.mar.service.config.ServiceConfig$$EnhancerBySpringCGLIB$$77f6a134.CGLIB$serviceDataManager$2(<generated>)
              at com.intel.mar.service.config.ServiceConfig$$EnhancerBySpringCGLIB$$77f6a134$$FastClassBySpringCGLIB$$b506e141.invoke(<generated>)
              at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
              at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:358)
              at com.intel.mar.service.config.ServiceConfig$$EnhancerBySpringCGLIB$$77f6a134.serviceDataManager(<generated>)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
              at java.lang.reflect.Method.invoke(Method.java:498)
              at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
              ... 40 more**

**

asticsearch.yml

network.bind_host: 0.0.0.0
network.publish_host: "{{getenv "IP"}}"
path.data: /shared/el
cluster.name:  "{{  getv (print "/solutions/" (getenv "COMPONENT_NAMESPACE") "/services/mar-server/es_cluster_name")}}"
cluster.routing.allocation.awareness.attributes: aws_zone_id
node.name: "{{getenv "ID"}}"
node.master: true
node.data: true
discovery.zen.ping.unicast.hosts: [{{getv (print "/solutions/" (getenv "COMPONENT_NAMESPACE") "/services/mar-server/elastic_search_seeds")}}]
discovery.zen.minimum_master_nodes: "{{getv (print "/solutions/" (getenv "COMPONENT_NAMESPACE") "/services/mar-server/es_minimum_master_nodes")}}"
http.cors.allow-origin: "/.*/"
http.cors.enabled: true

# AWS discovery

http.enabled: true
http.port: 9200

action.auto_create_index: true

transport.tcp.port: 9300
indices.fielddata.cache.size: 25%
script.inline: true
thread_pool.bulk.queue_size: 900

Я создаю Java-клиентasticsearch следующим образом:

    public Client createTransportClient() {
        Settings settings = Settings.builder()
                .put("cluster.name", config.db().clusterName())
                .build();

    return new PreBuiltTransportClient(settings)
                    .addTransportAddress(
                            new InetSocketTransportAddress(
                                    new InetSocketAddress(
                                            config.db().getElasticSearchHost(),
                                            config.db().getElasticSearchNodePort()
                                    )
                            )
                    );
}

1 Ответ

0 голосов
/ 19 сентября 2018

Проблема заключалась в том, что config.db (). GetElasticSearchHost () возвращал список узлов главного кластера, разделенных символом ",".Решение было следующим:

Settings settings = Settings.builder()
                .put("cluster.name", config.db().clusterName())
                .build();

    PreBuiltTransportClient preBuiltTransportClient = new PreBuiltTransportClient(settings);
    String[] hosts = config.db().getElasticSearchHost().split(SPLIT_SEPARATOR);

    for(int i=0; i<hosts.length;i++){
        preBuiltTransportClient.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(hosts[i])
                ,config.db().getElasticSearchNodePort()));
    }

    return preBuiltTransportClient;
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...