Skip to content

Remove redundant method for getting the remote cluster names #130495

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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 @@ -247,16 +247,16 @@ public Map<String, OriginalIndices> groupIndices(Set<String> remoteClusterNames,
}

public Map<String, OriginalIndices> groupIndices(IndicesOptions indicesOptions, String[] indices, boolean returnLocalAll) {
return groupIndices(getRemoteClusterNames(), indicesOptions, indices, returnLocalAll);
return groupIndices(getRegisteredRemoteClusterNames(), indicesOptions, indices, returnLocalAll);
}

public Map<String, OriginalIndices> groupIndices(IndicesOptions indicesOptions, String[] indices) {
return groupIndices(getRemoteClusterNames(), indicesOptions, indices, true);
return groupIndices(getRegisteredRemoteClusterNames(), indicesOptions, indices, true);
}

@Override
public Set<String> getConfiguredClusters() {
return getRemoteClusterNames();
return getRegisteredRemoteClusterNames();
}

/**
Expand All @@ -270,7 +270,6 @@ boolean isRemoteClusterRegistered(String clusterName) {
* Returns the registered remote cluster names.
*/
public Set<String> getRegisteredRemoteClusterNames() {
// remoteClusters is unmodifiable so its key set will be unmodifiable too
return remoteClusters.keySet();
}

Expand Down Expand Up @@ -355,10 +354,6 @@ public RemoteClusterConnection getRemoteClusterConnection(String cluster) {
return connection;
}

Set<String> getRemoteClusterNames() {
return this.remoteClusters.keySet();
}

@Override
public void listenForUpdates(ClusterSettings clusterSettings) {
super.listenForUpdates(clusterSettings);
Expand Down Expand Up @@ -648,7 +643,7 @@ public RemoteClusterClient getRemoteClusterClient(
"this node does not have the " + DiscoveryNodeRole.REMOTE_CLUSTER_CLIENT_ROLE.roleName() + " role"
);
}
if (transportService.getRemoteClusterService().getRemoteClusterNames().contains(clusterAlias) == false) {
if (transportService.getRemoteClusterService().getRegisteredRemoteClusterNames().contains(clusterAlias) == false) {
throw new NoSuchRemoteClusterException(clusterAlias);
}
return new RemoteClusterAwareClient(transportService, clusterAlias, responseExecutor, switch (disconnectedStrategy) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public void testGroupClusterIndices() throws IOException {
assertFalse(service.isRemoteClusterRegistered("foo"));
{
Map<String, List<String>> perClusterIndices = service.groupClusterIndices(
service.getRemoteClusterNames(),
service.getRegisteredRemoteClusterNames(),
new String[] {
"cluster_1:bar",
"cluster_2:foo:bar",
Expand All @@ -191,15 +191,15 @@ public void testGroupClusterIndices() throws IOException {
expectThrows(
NoSuchRemoteClusterException.class,
() -> service.groupClusterIndices(
service.getRemoteClusterNames(),
service.getRegisteredRemoteClusterNames(),
new String[] { "foo:bar", "cluster_1:bar", "cluster_2:foo:bar", "cluster_1:test", "cluster_2:foo*", "foo" }
)
);

expectThrows(
NoSuchRemoteClusterException.class,
() -> service.groupClusterIndices(
service.getRemoteClusterNames(),
service.getRegisteredRemoteClusterNames(),
new String[] { "cluster_1:bar", "cluster_2:foo:bar", "cluster_1:test", "cluster_2:foo*", "does_not_exist:*" }
)
);
Expand All @@ -208,7 +208,10 @@ public void testGroupClusterIndices() throws IOException {
{
String[] indices = shuffledList(List.of("cluster*:foo*", "foo", "-cluster_1:*", "*:boo")).toArray(new String[0]);

Map<String, List<String>> perClusterIndices = service.groupClusterIndices(service.getRemoteClusterNames(), indices);
Map<String, List<String>> perClusterIndices = service.groupClusterIndices(
service.getRegisteredRemoteClusterNames(),
indices
);
assertEquals(2, perClusterIndices.size());
List<String> localIndexes = perClusterIndices.get(RemoteClusterAware.LOCAL_CLUSTER_GROUP_KEY);
assertNotNull(localIndexes);
Expand All @@ -223,7 +226,10 @@ public void testGroupClusterIndices() throws IOException {
{
String[] indices = shuffledList(List.of("*:*", "-clu*_1:*", "*:boo")).toArray(new String[0]);

Map<String, List<String>> perClusterIndices = service.groupClusterIndices(service.getRemoteClusterNames(), indices);
Map<String, List<String>> perClusterIndices = service.groupClusterIndices(
service.getRegisteredRemoteClusterNames(),
indices
);
assertEquals(1, perClusterIndices.size());

List<String> cluster2 = perClusterIndices.get("cluster_2");
Expand All @@ -236,7 +242,10 @@ public void testGroupClusterIndices() throws IOException {
new String[0]
);

Map<String, List<String>> perClusterIndices = service.groupClusterIndices(service.getRemoteClusterNames(), indices);
Map<String, List<String>> perClusterIndices = service.groupClusterIndices(
service.getRegisteredRemoteClusterNames(),
indices
);
assertEquals(1, perClusterIndices.size());
List<String> localIndexes = perClusterIndices.get(RemoteClusterAware.LOCAL_CLUSTER_GROUP_KEY);
assertNotNull(localIndexes);
Expand All @@ -246,7 +255,10 @@ public void testGroupClusterIndices() throws IOException {
{
String[] indices = shuffledList(List.of("cluster*:*", "foo", "-*:*")).toArray(new String[0]);

Map<String, List<String>> perClusterIndices = service.groupClusterIndices(service.getRemoteClusterNames(), indices);
Map<String, List<String>> perClusterIndices = service.groupClusterIndices(
service.getRegisteredRemoteClusterNames(),
indices
);
assertEquals(1, perClusterIndices.size());
List<String> localIndexes = perClusterIndices.get(RemoteClusterAware.LOCAL_CLUSTER_GROUP_KEY);
assertNotNull(localIndexes);
Expand All @@ -257,7 +269,7 @@ public void testGroupClusterIndices() throws IOException {
IllegalArgumentException e = expectThrows(
IllegalArgumentException.class,
() -> service.groupClusterIndices(
service.getRemoteClusterNames(),
service.getRegisteredRemoteClusterNames(),
// -cluster_1:foo* is not allowed, only -cluster_1:*
new String[] { "cluster_1:bar", "-cluster_2:foo*", "cluster_1:test", "cluster_2:foo*", "foo" }
)
Expand All @@ -271,7 +283,7 @@ public void testGroupClusterIndices() throws IOException {
IllegalArgumentException e = expectThrows(
IllegalArgumentException.class,
() -> service.groupClusterIndices(
service.getRemoteClusterNames(),
service.getRegisteredRemoteClusterNames(),
// -cluster_1:* will fail since cluster_1 was never included in order to qualify to be excluded
new String[] { "-cluster_1:*", "cluster_2:foo*", "foo" }
)
Expand All @@ -287,7 +299,7 @@ public void testGroupClusterIndices() throws IOException {
{
IllegalArgumentException e = expectThrows(
IllegalArgumentException.class,
() -> service.groupClusterIndices(service.getRemoteClusterNames(), new String[] { "-cluster_1:*" })
() -> service.groupClusterIndices(service.getRegisteredRemoteClusterNames(), new String[] { "-cluster_1:*" })
);
assertThat(
e.getMessage(),
Expand All @@ -300,7 +312,7 @@ public void testGroupClusterIndices() throws IOException {
{
IllegalArgumentException e = expectThrows(
IllegalArgumentException.class,
() -> service.groupClusterIndices(service.getRemoteClusterNames(), new String[] { "-*:*" })
() -> service.groupClusterIndices(service.getRegisteredRemoteClusterNames(), new String[] { "-*:*" })
);
assertThat(
e.getMessage(),
Expand All @@ -315,7 +327,7 @@ public void testGroupClusterIndices() throws IOException {

IllegalArgumentException e = expectThrows(
IllegalArgumentException.class,
() -> service.groupClusterIndices(service.getRemoteClusterNames(), indices)
() -> service.groupClusterIndices(service.getRegisteredRemoteClusterNames(), indices)
);
assertThat(
e.getMessage(),
Expand Down Expand Up @@ -394,7 +406,7 @@ public void testGroupIndices() throws IOException {
expectThrows(
NoSuchRemoteClusterException.class,
() -> service.groupClusterIndices(
service.getRemoteClusterNames(),
service.getRegisteredRemoteClusterNames(),
new String[] { "foo:bar", "cluster_1:bar", "cluster_2:foo:bar", "cluster_1:test", "cluster_2:foo*", "foo" }
)
);
Expand Down