From b674827eb65a0a278187c7739e62bff8f7284753 Mon Sep 17 00:00:00 2001 From: Andy Goldstein Date: Fri, 6 Dec 2013 08:38:13 -0500 Subject: [PATCH] Add transport.publish_port setting Add transport.publish_port setting to allow users to specify the port other cluster members should use when connecting to an instance. This is needed for systems such as OpenShift, where cluster communication needs to use a publicly accessibly proxy port, because the normal port (9300) is bound to a private loopback IP address. --- .../elasticsearch/transport/netty/NettyTransport.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/elasticsearch/transport/netty/NettyTransport.java b/src/main/java/org/elasticsearch/transport/netty/NettyTransport.java index c9f513f055e..b689da9fc00 100644 --- a/src/main/java/org/elasticsearch/transport/netty/NettyTransport.java +++ b/src/main/java/org/elasticsearch/transport/netty/NettyTransport.java @@ -114,6 +114,8 @@ public class NettyTransport extends AbstractLifecycleComponent implem final String publishHost; + final int publishPort; + final boolean compress; final TimeValue connectTimeout; @@ -179,6 +181,7 @@ public class NettyTransport extends AbstractLifecycleComponent implem this.port = componentSettings.get("port", settings.get("transport.tcp.port", "9300-9400")); this.bindHost = componentSettings.get("bind_host", settings.get("transport.bind_host", settings.get("transport.host"))); this.publishHost = componentSettings.get("publish_host", settings.get("transport.publish_host", settings.get("transport.host"))); + this.publishPort = componentSettings.getAsInt("publish_port", settings.getAsInt("transport.publish_port", 0)); this.compress = settings.getAsBoolean(TransportSettings.TRANSPORT_TCP_COMPRESS, false); this.connectTimeout = componentSettings.getAsTime("connect_timeout", settings.getAsTime("transport.tcp.connect_timeout", settings.getAsTime(TCP_CONNECT_TIMEOUT, TCP_DEFAULT_CONNECT_TIMEOUT))); this.tcpNoDelay = componentSettings.getAsBoolean("tcp_no_delay", settings.getAsBoolean(TCP_NO_DELAY, true)); @@ -381,8 +384,12 @@ public class NettyTransport extends AbstractLifecycleComponent implem InetSocketAddress boundAddress = (InetSocketAddress) serverChannel.getLocalAddress(); InetSocketAddress publishAddress; + int publishPort = this.publishPort; + if (0 == publishPort) { + publishPort = boundAddress.getPort(); + } try { - publishAddress = new InetSocketAddress(networkService.resolvePublishHostAddress(publishHost), boundAddress.getPort()); + publishAddress = new InetSocketAddress(networkService.resolvePublishHostAddress(publishHost), publishPort); } catch (Exception e) { throw new BindTransportException("Failed to resolve publish address", e); }