diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/cluster/ProxyModeInfo.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/cluster/ProxyModeInfo.java index 0fc4f240eb8..7d81753ec2a 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/cluster/ProxyModeInfo.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/cluster/ProxyModeInfo.java @@ -24,14 +24,17 @@ import java.util.Objects; public class ProxyModeInfo implements RemoteConnectionInfo.ModeInfo { static final String NAME = "proxy"; static final String ADDRESS = "address"; + static final String SERVER_NAME = "server_name"; static final String NUM_SOCKETS_CONNECTED = "num_sockets_connected"; static final String MAX_SOCKET_CONNECTIONS = "max_socket_connections"; private final String address; + private final String serverName; private final int maxSocketConnections; private final int numSocketsConnected; - ProxyModeInfo(String address, int maxSocketConnections, int numSocketsConnected) { + ProxyModeInfo(String address, String serverName, int maxSocketConnections, int numSocketsConnected) { this.address = address; + this.serverName = serverName; this.maxSocketConnections = maxSocketConnections; this.numSocketsConnected = numSocketsConnected; } @@ -50,6 +53,10 @@ public class ProxyModeInfo implements RemoteConnectionInfo.ModeInfo { return address; } + public String getServerName() { + return serverName; + } + public int getMaxSocketConnections() { return maxSocketConnections; } @@ -65,11 +72,12 @@ public class ProxyModeInfo implements RemoteConnectionInfo.ModeInfo { ProxyModeInfo otherProxy = (ProxyModeInfo) o; return maxSocketConnections == otherProxy.maxSocketConnections && numSocketsConnected == otherProxy.numSocketsConnected && - Objects.equals(address, otherProxy.address); + Objects.equals(address, otherProxy.address) && + Objects.equals(serverName, otherProxy.serverName); } @Override public int hashCode() { - return Objects.hash(address, maxSocketConnections, numSocketsConnected); + return Objects.hash(address, serverName, maxSocketConnections, numSocketsConnected); } } diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/cluster/RemoteConnectionInfo.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/cluster/RemoteConnectionInfo.java index 2bf99c61085..3bd52dcbbe0 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/cluster/RemoteConnectionInfo.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/cluster/RemoteConnectionInfo.java @@ -48,9 +48,9 @@ public final class RemoteConnectionInfo { String mode = (String) args[1]; ModeInfo modeInfo; if (mode.equals(ProxyModeInfo.NAME)) { - modeInfo = new ProxyModeInfo((String) args[4], (int) args[5], (int) args[6]); + modeInfo = new ProxyModeInfo((String) args[4], (String) args[5], (int) args[6], (int) args[7]); } else if (mode.equals(SniffModeInfo.NAME)) { - modeInfo = new SniffModeInfo((List) args[7], (int) args[8], (int) args[9]); + modeInfo = new SniffModeInfo((List) args[8], (int) args[9], (int) args[10]); } else { throw new IllegalArgumentException("mode cannot be " + mode); } @@ -67,6 +67,7 @@ public final class RemoteConnectionInfo { PARSER.declareBoolean(constructorArg(), new ParseField(SKIP_UNAVAILABLE)); PARSER.declareString(optionalConstructorArg(), new ParseField(ProxyModeInfo.ADDRESS)); + PARSER.declareString(optionalConstructorArg(), new ParseField(ProxyModeInfo.SERVER_NAME)); PARSER.declareInt(optionalConstructorArg(), new ParseField(ProxyModeInfo.MAX_SOCKET_CONNECTIONS)); PARSER.declareInt(optionalConstructorArg(), new ParseField(ProxyModeInfo.NUM_SOCKETS_CONNECTED)); diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/cluster/RemoteInfoResponseTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/cluster/RemoteInfoResponseTests.java index 88f8f6f533e..0d5171eb310 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/cluster/RemoteInfoResponseTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/cluster/RemoteInfoResponseTests.java @@ -83,6 +83,7 @@ public class RemoteInfoResponseTests extends AbstractResponseTestCase seedNodes = randomList(randomInt(8), () -> randomAlphaOfLength(8)); int maxConnectionsPerCluster = randomInt(5); diff --git a/server/src/main/java/org/elasticsearch/transport/ProxyConnectionStrategy.java b/server/src/main/java/org/elasticsearch/transport/ProxyConnectionStrategy.java index 6e2fab5a11e..ede6fe35f7c 100644 --- a/server/src/main/java/org/elasticsearch/transport/ProxyConnectionStrategy.java +++ b/server/src/main/java/org/elasticsearch/transport/ProxyConnectionStrategy.java @@ -172,7 +172,7 @@ public class ProxyConnectionStrategy extends RemoteConnectionStrategy { @Override public RemoteConnectionInfo.ModeInfo getModeInfo() { - return new ProxyModeInfo(configuredAddress, maxNumConnections, connectionManager.size()); + return new ProxyModeInfo(configuredAddress, configuredServerName, maxNumConnections, connectionManager.size()); } private void performProxyConnectionProcess(ActionListener listener) { @@ -255,17 +255,24 @@ public class ProxyConnectionStrategy extends RemoteConnectionStrategy { public static class ProxyModeInfo implements RemoteConnectionInfo.ModeInfo { private final String address; + private final String serverName; private final int maxSocketConnections; private final int numSocketsConnected; - public ProxyModeInfo(String address, int maxSocketConnections, int numSocketsConnected) { + public ProxyModeInfo(String address, String serverName, int maxSocketConnections, int numSocketsConnected) { this.address = address; + this.serverName = serverName; this.maxSocketConnections = maxSocketConnections; this.numSocketsConnected = numSocketsConnected; } private ProxyModeInfo(StreamInput input) throws IOException { address = input.readString(); + if (input.getVersion().onOrAfter(Version.V_7_7_0)) { + serverName = input.readString(); + } else { + serverName = null; + } maxSocketConnections = input.readVInt(); numSocketsConnected = input.readVInt(); } @@ -273,6 +280,7 @@ public class ProxyConnectionStrategy extends RemoteConnectionStrategy { @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.field("address", address); + builder.field("server_name", serverName); builder.field("num_sockets_connected", numSocketsConnected); builder.field("max_socket_connections", maxSocketConnections); return builder; @@ -281,6 +289,9 @@ public class ProxyConnectionStrategy extends RemoteConnectionStrategy { @Override public void writeTo(StreamOutput out) throws IOException { out.writeString(address); + if (out.getVersion().onOrAfter(Version.V_7_7_0)) { + out.writeString(serverName); + } out.writeVInt(maxSocketConnections); out.writeVInt(numSocketsConnected); } @@ -299,6 +310,10 @@ public class ProxyConnectionStrategy extends RemoteConnectionStrategy { return address; } + public String getServerName() { + return serverName; + } + public int getMaxSocketConnections() { return maxSocketConnections; } @@ -319,12 +334,13 @@ public class ProxyConnectionStrategy extends RemoteConnectionStrategy { ProxyModeInfo otherProxy = (ProxyModeInfo) o; return maxSocketConnections == otherProxy.maxSocketConnections && numSocketsConnected == otherProxy.numSocketsConnected && - Objects.equals(address, otherProxy.address); + Objects.equals(address, otherProxy.address) && + Objects.equals(serverName, otherProxy.serverName); } @Override public int hashCode() { - return Objects.hash(address, maxSocketConnections, numSocketsConnected); + return Objects.hash(address, serverName, maxSocketConnections, numSocketsConnected); } } } diff --git a/server/src/test/java/org/elasticsearch/transport/RemoteClusterConnectionTests.java b/server/src/test/java/org/elasticsearch/transport/RemoteClusterConnectionTests.java index 2b8f9e331d6..42f4c7d674f 100644 --- a/server/src/test/java/org/elasticsearch/transport/RemoteClusterConnectionTests.java +++ b/server/src/test/java/org/elasticsearch/transport/RemoteClusterConnectionTests.java @@ -348,6 +348,7 @@ public class RemoteClusterConnectionTests extends ESTestCase { public void testRemoteConnectionInfo() throws IOException { List remoteAddresses = Collections.singletonList("seed:1"); + String serverName = "the_server_name"; RemoteConnectionInfo.ModeInfo modeInfo1; RemoteConnectionInfo.ModeInfo modeInfo2; @@ -356,8 +357,8 @@ public class RemoteClusterConnectionTests extends ESTestCase { modeInfo1 = new SniffConnectionStrategy.SniffModeInfo(remoteAddresses, 4, 4); modeInfo2 = new SniffConnectionStrategy.SniffModeInfo(remoteAddresses, 4, 3); } else { - modeInfo1 = new ProxyConnectionStrategy.ProxyModeInfo(remoteAddresses.get(0), 18, 18); - modeInfo2 = new ProxyConnectionStrategy.ProxyModeInfo(remoteAddresses.get(0), 18, 17); + modeInfo1 = new ProxyConnectionStrategy.ProxyModeInfo(remoteAddresses.get(0), serverName, 18, 18); + modeInfo2 = new ProxyConnectionStrategy.ProxyModeInfo(remoteAddresses.get(0), serverName,18, 17); } RemoteConnectionInfo stats = @@ -425,6 +426,7 @@ public class RemoteClusterConnectionTests extends ESTestCase { public void testRenderConnectionInfoXContent() throws IOException { List remoteAddresses = Arrays.asList("seed:1", "seed:2"); + String serverName = "the_server_name"; RemoteConnectionInfo.ModeInfo modeInfo; @@ -432,7 +434,7 @@ public class RemoteClusterConnectionTests extends ESTestCase { if (sniff) { modeInfo = new SniffConnectionStrategy.SniffModeInfo(remoteAddresses, 3, 2); } else { - modeInfo = new ProxyConnectionStrategy.ProxyModeInfo(remoteAddresses.get(0), 18, 16); + modeInfo = new ProxyConnectionStrategy.ProxyModeInfo(remoteAddresses.get(0), serverName,18, 16); } RemoteConnectionInfo stats = new RemoteConnectionInfo("test_cluster", modeInfo, TimeValue.timeValueMinutes(30), true); @@ -448,8 +450,8 @@ public class RemoteClusterConnectionTests extends ESTestCase { "\"skip_unavailable\":true}}", Strings.toString(builder)); } else { assertEquals("{\"test_cluster\":{\"connected\":true,\"mode\":\"proxy\",\"address\":\"seed:1\"," + - "\"num_sockets_connected\":16,\"max_socket_connections\":18,\"initial_connect_timeout\":\"30m\"," + - "\"skip_unavailable\":true}}", Strings.toString(builder)); + "\"server_name\":\"the_server_name\",\"num_sockets_connected\":16,\"max_socket_connections\":18," + +"\"initial_connect_timeout\":\"30m\",\"skip_unavailable\":true}}", Strings.toString(builder)); } }