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 79758ec709c63..3be10ce41a0fe 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 @@ public class ProxyModeInfo implements RemoteConnectionInfo.ModeInfo { static final String NAME = "proxy"; static final String PROXY_ADDRESS = "proxy_address"; + static final String SERVER_NAME = "server_name"; static final String NUM_PROXY_SOCKETS_CONNECTED = "num_proxy_sockets_connected"; static final String MAX_PROXY_SOCKET_CONNECTIONS = "max_proxy_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 String getAddress() { return address; } + public String getServerName() { + return serverName; + } + public int getMaxSocketConnections() { return maxSocketConnections; } @@ -65,11 +72,12 @@ public boolean equals(Object o) { 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 474b991cd434a..cb0fb726297a1 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.PROXY_ADDRESS)); + PARSER.declareString(optionalConstructorArg(), new ParseField(ProxyModeInfo.SERVER_NAME)); PARSER.declareInt(optionalConstructorArg(), new ParseField(ProxyModeInfo.MAX_PROXY_SOCKET_CONNECTIONS)); PARSER.declareInt(optionalConstructorArg(), new ParseField(ProxyModeInfo.NUM_PROXY_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 88f8f6f533e1d..0d5171eb310bb 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 @@ protected void assertInstances(org.elasticsearch.action.admin.cluster.remote.Rem ProxyConnectionStrategy.ProxyModeInfo serverModeInfo = (ProxyConnectionStrategy.ProxyModeInfo) serverRemoteInfo.getModeInfo(); assertThat(clientModeInfo.getAddress(), equalTo(serverModeInfo.getAddress())); + assertThat(clientModeInfo.getServerName(), equalTo(serverModeInfo.getServerName())); assertThat(clientModeInfo.getMaxSocketConnections(), equalTo(serverModeInfo.getMaxSocketConnections())); assertThat(clientModeInfo.getNumSocketsConnected(), equalTo(serverModeInfo.getNumSocketsConnected())); } else { @@ -95,9 +96,10 @@ private static RemoteConnectionInfo createRandomRemoteConnectionInfo() { RemoteConnectionInfo.ModeInfo modeInfo; if (randomBoolean()) { String address = randomAlphaOfLength(8); + String serverName = randomAlphaOfLength(8); int maxSocketConnections = randomInt(5); int numSocketsConnected = randomInt(5); - modeInfo = new ProxyConnectionStrategy.ProxyModeInfo(address, maxSocketConnections, numSocketsConnected); + modeInfo = new ProxyConnectionStrategy.ProxyModeInfo(address, serverName, maxSocketConnections, numSocketsConnected); } else { List 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 2d314a591b57a..fa4d227ece76f 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 @@ protected void connectImpl(ActionListener listener) { @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 @@ private static TransportAddress resolveAddress(String address) { 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_8_0_0)) { + serverName = input.readString(); + } else { + serverName = null; + } maxSocketConnections = input.readVInt(); numSocketsConnected = input.readVInt(); } @@ -273,6 +280,7 @@ private ProxyModeInfo(StreamInput input) throws IOException { @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.field("proxy_address", address); + builder.field("server_name", serverName); builder.field("num_proxy_sockets_connected", numSocketsConnected); builder.field("max_proxy_socket_connections", maxSocketConnections); return builder; @@ -281,6 +289,9 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws @Override public void writeTo(StreamOutput out) throws IOException { out.writeString(address); + if (out.getVersion().onOrAfter(Version.V_8_0_0)) { + out.writeString(serverName); + } out.writeVInt(maxSocketConnections); out.writeVInt(numSocketsConnected); } @@ -299,6 +310,10 @@ public String getAddress() { return address; } + public String getServerName() { + return serverName; + } + public int getMaxSocketConnections() { return maxSocketConnections; } @@ -319,12 +334,13 @@ public boolean equals(Object o) { 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 2e3102cb7e926..088f14ef36c1a 100644 --- a/server/src/test/java/org/elasticsearch/transport/RemoteClusterConnectionTests.java +++ b/server/src/test/java/org/elasticsearch/transport/RemoteClusterConnectionTests.java @@ -346,6 +346,7 @@ public void testGetConnectionInfo() throws Exception { public void testRemoteConnectionInfo() throws IOException { List remoteAddresses = Collections.singletonList("seed:1"); + String serverName = "the_server_name"; RemoteConnectionInfo.ModeInfo modeInfo1; RemoteConnectionInfo.ModeInfo modeInfo2; @@ -354,8 +355,8 @@ public void testRemoteConnectionInfo() throws IOException { 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 = @@ -395,6 +396,7 @@ private static RemoteConnectionInfo assertSerialization(RemoteConnectionInfo inf public void testRenderConnectionInfoXContent() throws IOException { List remoteAddresses = Arrays.asList("seed:1", "seed:2"); + String serverName = "the_server_name"; RemoteConnectionInfo.ModeInfo modeInfo; @@ -402,7 +404,7 @@ public void testRenderConnectionInfoXContent() throws IOException { 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); @@ -418,8 +420,8 @@ public void testRenderConnectionInfoXContent() throws IOException { "\"skip_unavailable\":true}}", Strings.toString(builder)); } else { assertEquals("{\"test_cluster\":{\"connected\":true,\"mode\":\"proxy\",\"proxy_address\":\"seed:1\"," + - "\"num_proxy_sockets_connected\":16,\"max_proxy_socket_connections\":18,\"initial_connect_timeout\":\"30m\"," + - "\"skip_unavailable\":true}}", Strings.toString(builder)); + "\"server_name\":\"the_server_name\",\"num_proxy_sockets_connected\":16,\"max_proxy_socket_connections\":18,"+ + "\"initial_connect_timeout\":\"30m\",\"skip_unavailable\":true}}", Strings.toString(builder)); } }