Skip to content

Commit 74cd006

Browse files
Remove redundant method for getting the remote cluster names (#130495)
This change removes RemoteClusterService.getRemoteClusterNames() since getRegisteredRemoteClusterNames() provides the same functionality. The comment in getRegisteredRemoteClusterNames() was removed since it is no longer accurate after the change in PR #47891.
1 parent 668accc commit 74cd006

File tree

2 files changed

+29
-22
lines changed

2 files changed

+29
-22
lines changed

server/src/main/java/org/elasticsearch/transport/RemoteClusterService.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -247,16 +247,16 @@ public Map<String, OriginalIndices> groupIndices(Set<String> remoteClusterNames,
247247
}
248248

249249
public Map<String, OriginalIndices> groupIndices(IndicesOptions indicesOptions, String[] indices, boolean returnLocalAll) {
250-
return groupIndices(getRemoteClusterNames(), indicesOptions, indices, returnLocalAll);
250+
return groupIndices(getRegisteredRemoteClusterNames(), indicesOptions, indices, returnLocalAll);
251251
}
252252

253253
public Map<String, OriginalIndices> groupIndices(IndicesOptions indicesOptions, String[] indices) {
254-
return groupIndices(getRemoteClusterNames(), indicesOptions, indices, true);
254+
return groupIndices(getRegisteredRemoteClusterNames(), indicesOptions, indices, true);
255255
}
256256

257257
@Override
258258
public Set<String> getConfiguredClusters() {
259-
return getRemoteClusterNames();
259+
return getRegisteredRemoteClusterNames();
260260
}
261261

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

@@ -355,10 +354,6 @@ public RemoteClusterConnection getRemoteClusterConnection(String cluster) {
355354
return connection;
356355
}
357356

358-
Set<String> getRemoteClusterNames() {
359-
return this.remoteClusters.keySet();
360-
}
361-
362357
@Override
363358
public void listenForUpdates(ClusterSettings clusterSettings) {
364359
super.listenForUpdates(clusterSettings);
@@ -648,7 +643,7 @@ public RemoteClusterClient getRemoteClusterClient(
648643
"this node does not have the " + DiscoveryNodeRole.REMOTE_CLUSTER_CLIENT_ROLE.roleName() + " role"
649644
);
650645
}
651-
if (transportService.getRemoteClusterService().getRemoteClusterNames().contains(clusterAlias) == false) {
646+
if (transportService.getRemoteClusterService().getRegisteredRemoteClusterNames().contains(clusterAlias) == false) {
652647
throw new NoSuchRemoteClusterException(clusterAlias);
653648
}
654649
return new RemoteClusterAwareClient(transportService, clusterAlias, responseExecutor, switch (disconnectedStrategy) {

server/src/test/java/org/elasticsearch/transport/RemoteClusterServiceTests.java

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ public void testGroupClusterIndices() throws IOException {
170170
assertFalse(service.isRemoteClusterRegistered("foo"));
171171
{
172172
Map<String, List<String>> perClusterIndices = service.groupClusterIndices(
173-
service.getRemoteClusterNames(),
173+
service.getRegisteredRemoteClusterNames(),
174174
new String[] {
175175
"cluster_1:bar",
176176
"cluster_2:foo:bar",
@@ -191,15 +191,15 @@ public void testGroupClusterIndices() throws IOException {
191191
expectThrows(
192192
NoSuchRemoteClusterException.class,
193193
() -> service.groupClusterIndices(
194-
service.getRemoteClusterNames(),
194+
service.getRegisteredRemoteClusterNames(),
195195
new String[] { "foo:bar", "cluster_1:bar", "cluster_2:foo:bar", "cluster_1:test", "cluster_2:foo*", "foo" }
196196
)
197197
);
198198

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

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

226-
Map<String, List<String>> perClusterIndices = service.groupClusterIndices(service.getRemoteClusterNames(), indices);
229+
Map<String, List<String>> perClusterIndices = service.groupClusterIndices(
230+
service.getRegisteredRemoteClusterNames(),
231+
indices
232+
);
227233
assertEquals(1, perClusterIndices.size());
228234

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

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

249-
Map<String, List<String>> perClusterIndices = service.groupClusterIndices(service.getRemoteClusterNames(), indices);
258+
Map<String, List<String>> perClusterIndices = service.groupClusterIndices(
259+
service.getRegisteredRemoteClusterNames(),
260+
indices
261+
);
250262
assertEquals(1, perClusterIndices.size());
251263
List<String> localIndexes = perClusterIndices.get(RemoteClusterAware.LOCAL_CLUSTER_GROUP_KEY);
252264
assertNotNull(localIndexes);
@@ -257,7 +269,7 @@ public void testGroupClusterIndices() throws IOException {
257269
IllegalArgumentException e = expectThrows(
258270
IllegalArgumentException.class,
259271
() -> service.groupClusterIndices(
260-
service.getRemoteClusterNames(),
272+
service.getRegisteredRemoteClusterNames(),
261273
// -cluster_1:foo* is not allowed, only -cluster_1:*
262274
new String[] { "cluster_1:bar", "-cluster_2:foo*", "cluster_1:test", "cluster_2:foo*", "foo" }
263275
)
@@ -271,7 +283,7 @@ public void testGroupClusterIndices() throws IOException {
271283
IllegalArgumentException e = expectThrows(
272284
IllegalArgumentException.class,
273285
() -> service.groupClusterIndices(
274-
service.getRemoteClusterNames(),
286+
service.getRegisteredRemoteClusterNames(),
275287
// -cluster_1:* will fail since cluster_1 was never included in order to qualify to be excluded
276288
new String[] { "-cluster_1:*", "cluster_2:foo*", "foo" }
277289
)
@@ -287,7 +299,7 @@ public void testGroupClusterIndices() throws IOException {
287299
{
288300
IllegalArgumentException e = expectThrows(
289301
IllegalArgumentException.class,
290-
() -> service.groupClusterIndices(service.getRemoteClusterNames(), new String[] { "-cluster_1:*" })
302+
() -> service.groupClusterIndices(service.getRegisteredRemoteClusterNames(), new String[] { "-cluster_1:*" })
291303
);
292304
assertThat(
293305
e.getMessage(),
@@ -300,7 +312,7 @@ public void testGroupClusterIndices() throws IOException {
300312
{
301313
IllegalArgumentException e = expectThrows(
302314
IllegalArgumentException.class,
303-
() -> service.groupClusterIndices(service.getRemoteClusterNames(), new String[] { "-*:*" })
315+
() -> service.groupClusterIndices(service.getRegisteredRemoteClusterNames(), new String[] { "-*:*" })
304316
);
305317
assertThat(
306318
e.getMessage(),
@@ -315,7 +327,7 @@ public void testGroupClusterIndices() throws IOException {
315327

316328
IllegalArgumentException e = expectThrows(
317329
IllegalArgumentException.class,
318-
() -> service.groupClusterIndices(service.getRemoteClusterNames(), indices)
330+
() -> service.groupClusterIndices(service.getRegisteredRemoteClusterNames(), indices)
319331
);
320332
assertThat(
321333
e.getMessage(),
@@ -394,7 +406,7 @@ public void testGroupIndices() throws IOException {
394406
expectThrows(
395407
NoSuchRemoteClusterException.class,
396408
() -> service.groupClusterIndices(
397-
service.getRemoteClusterNames(),
409+
service.getRegisteredRemoteClusterNames(),
398410
new String[] { "foo:bar", "cluster_1:bar", "cluster_2:foo:bar", "cluster_1:test", "cluster_2:foo*", "foo" }
399411
)
400412
);

0 commit comments

Comments
 (0)