Skip to content

Commit

Permalink
If all remote clusters are excluded by the exclusion list, an error w…
Browse files Browse the repository at this point in the history
…ill be thrown
  • Loading branch information
quux00 committed Jul 26, 2023
1 parent ba55ed4 commit c03d07c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,13 @@ protected Map<String, List<String>> groupClusterIndices(Set<String> remoteCluste
);
throw new IllegalArgumentException(warning);
}

if (requestIndices.length > 0 && perClusterIndices.size() == 0) {
throw new IllegalArgumentException(
"The '-' exclusions in the index expression list excludes all indexes. Nothing to search. Input: ["
+ String.join(",", requestIndices)
+ "]"
);
}
return perClusterIndices;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import static org.elasticsearch.test.NodeRoles.nonMasterNode;
import static org.elasticsearch.test.NodeRoles.onlyRoles;
import static org.elasticsearch.test.NodeRoles.removeRoles;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.either;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.instanceOf;
Expand Down Expand Up @@ -294,17 +295,31 @@ public void testGroupClusterIndices() throws IOException {
)
);
}
IllegalArgumentException e = expectThrows(
IllegalArgumentException.class,
() -> service.groupClusterIndices(service.getRemoteClusterNames(), new String[] { "-*:*" })
);
assertThat(
e.getMessage(),
equalTo(
"Attempt to exclude clusters [cluster_1, cluster_2] failed as they are not included in the list of "
+ "clusters to be included: []. Input: [-*:*]"
)
);
{
IllegalArgumentException e = expectThrows(
IllegalArgumentException.class,
() -> service.groupClusterIndices(service.getRemoteClusterNames(), new String[] { "-*:*" })
);
assertThat(
e.getMessage(),
equalTo(
"Attempt to exclude clusters [cluster_1, cluster_2] failed as they are not included in the list of "
+ "clusters to be included: []. Input: [-*:*]"
)
);
}
{
String[] indices = shuffledList(List.of("cluster*:*", "*:foo", "-*:*")).toArray(new String[0]);

IllegalArgumentException e = expectThrows(
IllegalArgumentException.class,
() -> service.groupClusterIndices(service.getRemoteClusterNames(), indices)
);
assertThat(
e.getMessage(),
containsString("The '-' exclusions in the index expression list excludes all indexes. Nothing to search.")
);
}
}
}
}
Expand Down

0 comments on commit c03d07c

Please sign in to comment.