Skip to content

Commit 313bed5

Browse files
Address review comments
1 parent 07643bf commit 313bed5

File tree

4 files changed

+34
-32
lines changed

4 files changed

+34
-32
lines changed

server/src/main/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolver.java

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -479,26 +479,13 @@ private static void ensureRemoteExpressionRequireIgnoreUnavailable(IndicesOption
479479
return;
480480
}
481481
if (RemoteClusterAware.isRemoteIndexName(current)) {
482-
List<String> crossClusterIndices = getRemoteIndexExpressions(expressions);
482+
List<String> crossClusterIndices = RemoteClusterAware.getRemoteIndexExpressions(expressions);
483483
throw new IllegalArgumentException(
484484
"Cross-cluster calls are not supported in this context but remote indices were requested: " + crossClusterIndices
485485
);
486486
}
487487
}
488488

489-
/**
490-
* Extracts the list of remote index expressions from the given array of index expressions
491-
*/
492-
public static List<String> getRemoteIndexExpressions(String... expressions) {
493-
List<String> crossClusterIndices = new ArrayList<>();
494-
for (int i = 0; i < expressions.length; i++) {
495-
if (RemoteClusterAware.isRemoteIndexName(expressions[i])) {
496-
crossClusterIndices.add(expressions[i]);
497-
}
498-
}
499-
return crossClusterIndices;
500-
}
501-
502489
/**
503490
* Translates the provided index expression into actual concrete indices, properly deduplicated.
504491
*

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,19 @@ public static boolean isRemoteIndexName(String indexExpression) {
6969
return idx > 0 && isSelector == false;
7070
}
7171

72+
/**
73+
* Extracts the list of remote index expressions from the given array of index expressions
74+
*/
75+
public static List<String> getRemoteIndexExpressions(String... expressions) {
76+
List<String> crossClusterIndices = new ArrayList<>();
77+
for (int i = 0; i < expressions.length; i++) {
78+
if (isRemoteIndexName(expressions[i])) {
79+
crossClusterIndices.add(expressions[i]);
80+
}
81+
}
82+
return crossClusterIndices;
83+
}
84+
7285
/**
7386
* @param indexExpression expects a single index expression at a time (not a csv list of expression)
7487
* @return cluster alias in the index expression. If none is present, returns RemoteClusterAware.LOCAL_CLUSTER_GROUP_KEY

server/src/test/java/org/elasticsearch/cluster/metadata/IndexNameExpressionResolverTests.java

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@
7878
import static org.hamcrest.Matchers.emptyArray;
7979
import static org.hamcrest.Matchers.endsWith;
8080
import static org.hamcrest.Matchers.equalTo;
81-
import static org.hamcrest.Matchers.hasSize;
8281
import static org.hamcrest.Matchers.is;
8382
import static org.hamcrest.Matchers.notNullValue;
8483
import static org.hamcrest.Matchers.nullValue;
@@ -3487,23 +3486,6 @@ public void testResolveWriteIndexAbstractionMultipleMatches() {
34873486
);
34883487
}
34893488

3490-
public void testGetRemoteIndexExpressions() {
3491-
{
3492-
List<String> remoteIndexExpressions = IndexNameExpressionResolver.getRemoteIndexExpressions("index-1");
3493-
assertThat(remoteIndexExpressions, empty());
3494-
}
3495-
{
3496-
List<String> remoteIndexExpressions = IndexNameExpressionResolver.getRemoteIndexExpressions(
3497-
"index-1",
3498-
"remote:index-1",
3499-
"idx-*",
3500-
"remote-2:idx-5"
3501-
);
3502-
assertThat(remoteIndexExpressions, hasSize(2));
3503-
assertThat(remoteIndexExpressions, contains("remote:index-1", "remote-2:idx-5"));
3504-
}
3505-
}
3506-
35073489
public static IndexMetadata.Builder indexBuilder(String index) {
35083490
return indexBuilder(index, Settings.EMPTY);
35093491
}

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,13 @@
1616
import java.util.Map;
1717
import java.util.Set;
1818

19+
import static org.hamcrest.Matchers.contains;
1920
import static org.hamcrest.Matchers.containsInAnyOrder;
2021
import static org.hamcrest.Matchers.containsString;
22+
import static org.hamcrest.Matchers.empty;
2123
import static org.hamcrest.Matchers.equalTo;
2224
import static org.hamcrest.Matchers.hasKey;
25+
import static org.hamcrest.Matchers.hasSize;
2326
import static org.hamcrest.Matchers.not;
2427

2528
public class RemoteClusterAwareTests extends ESTestCase {
@@ -158,6 +161,23 @@ public void testGroupClusterIndicesFail() {
158161

159162
}
160163

164+
public void testGetRemoteIndexExpressions() {
165+
{
166+
List<String> remoteIndexExpressions = RemoteClusterAware.getRemoteIndexExpressions("index-1");
167+
assertThat(remoteIndexExpressions, empty());
168+
}
169+
{
170+
List<String> remoteIndexExpressions = RemoteClusterAware.getRemoteIndexExpressions(
171+
"index-1",
172+
"remote:index-1",
173+
"idx-*",
174+
"remote-2:idx-5"
175+
);
176+
assertThat(remoteIndexExpressions, hasSize(2));
177+
assertThat(remoteIndexExpressions, contains("remote:index-1", "remote-2:idx-5"));
178+
}
179+
}
180+
161181
private static class RemoteClusterAwareTest extends RemoteClusterAware {
162182
RemoteClusterAwareTest() {
163183
super(Settings.EMPTY);

0 commit comments

Comments
 (0)