Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve cluster alias for opened remote connections #92584

Merged
merged 6 commits into from
Jan 24, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,14 @@ public void removeListener(TransportConnectionListener listener) {

@Override
public void openConnection(DiscoveryNode node, ConnectionProfile profile, ActionListener<Transport.Connection> listener) {
delegate.openConnection(node, profile, listener);
delegate.openConnection(
node,
profile,
ActionListener.wrap(
connection -> listener.onResponse(new InternalRemoteConnection(connection, clusterAlias)),
listener::onFailure
)
);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.net.InetAddress;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.ExecutionException;

import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasItems;
Expand Down Expand Up @@ -89,7 +90,7 @@ public void testGetConnection() {
assertEquals(1, versions.size());
}

public void testResolveRemoteClusterAlias() {
public void testResolveRemoteClusterAlias() throws ExecutionException, InterruptedException {
DiscoveryNode remoteNode1 = new DiscoveryNode("remote-node-1", address, Version.CURRENT);
PlainActionFuture<Void> future = PlainActionFuture.newFuture();
remoteConnectionManager.connectToRemoteClusterNode(remoteNode1, validator, future);
Expand All @@ -105,6 +106,10 @@ public void testResolveRemoteClusterAlias() {
Transport.Connection proxyConnection = remoteConnectionManager.getConnection(remoteNode2);
assertThat(proxyConnection, instanceOf(RemoteConnectionManager.ProxyConnection.class));
assertThat(RemoteConnectionManager.resolveRemoteClusterAlias(proxyConnection).get(), equalTo("remote-cluster"));

PlainActionFuture<Transport.Connection> future2 = PlainActionFuture.newFuture();
remoteConnectionManager.openConnection(remoteNode1, null, future2);
assertThat(RemoteConnectionManager.resolveRemoteClusterAlias(future2.get()).get(), equalTo("remote-cluster"));
}

private static class TestRemoteConnection extends CloseableConnection {
Expand Down