Skip to content

Commit 6a560fa

Browse files
Use test_runner_features: capabilities in new yaml test
1 parent a05e099 commit 6a560fa

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/snapshot.get/10_basic.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,13 @@ setup:
306306

307307
---
308308
"Get snapshot using state parameter":
309+
- requires:
310+
test_runner_features: capabilities
311+
capabilities:
312+
- method: GET
313+
path: /_snapshot/{repository}/{snapshot}
314+
parameters: [ state ]
315+
reason: "state parameter was introduced in 9.1"
309316

310317
- do:
311318
indices.create:

server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestGetSnapshotsAction.java

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@
1313
import org.elasticsearch.action.admin.cluster.snapshots.get.SnapshotSortKey;
1414
import org.elasticsearch.client.internal.node.NodeClient;
1515
import org.elasticsearch.common.Strings;
16+
import org.elasticsearch.common.util.set.Sets;
17+
import org.elasticsearch.core.Assertions;
1618
import org.elasticsearch.features.NodeFeature;
1719
import org.elasticsearch.rest.BaseRestHandler;
1820
import org.elasticsearch.rest.RestRequest;
21+
import org.elasticsearch.rest.RestUtils;
1922
import org.elasticsearch.rest.Scope;
2023
import org.elasticsearch.rest.ServerlessScope;
2124
import org.elasticsearch.rest.action.RestCancellableNodeClient;
@@ -42,6 +45,30 @@
4245
@ServerlessScope(Scope.INTERNAL)
4346
public class RestGetSnapshotsAction extends BaseRestHandler {
4447

48+
private static final Set<String> SUPPORTED_RESPONSE_PARAMETERS = Set.of(
49+
INCLUDE_REPOSITORY_XCONTENT_PARAM,
50+
INDEX_DETAILS_XCONTENT_PARAM,
51+
INDEX_NAMES_XCONTENT_PARAM
52+
);
53+
54+
private static final Set<String> SUPPORTED_QUERY_PARAMETERS = Set.of(
55+
RestUtils.REST_MASTER_TIMEOUT_PARAM,
56+
"after",
57+
"from_sort_value",
58+
"ignore_unavailable",
59+
"offset",
60+
"order",
61+
"size",
62+
"slm_policy_filter",
63+
"sort",
64+
"state",
65+
"verbose"
66+
);
67+
68+
private static final Set<String> ALL_SUPPORTED_PARAMETERS = Set.copyOf(
69+
Sets.union(SUPPORTED_QUERY_PARAMETERS, SUPPORTED_RESPONSE_PARAMETERS, Set.of("repository", "snapshot"))
70+
);
71+
4572
private final Predicate<NodeFeature> clusterSupportsFeature;
4673

4774
public RestGetSnapshotsAction(Predicate<NodeFeature> clusterSupportsFeature) {
@@ -60,7 +87,17 @@ public String getName() {
6087

6188
@Override
6289
protected Set<String> responseParams() {
63-
return Set.of(INDEX_DETAILS_XCONTENT_PARAM, INCLUDE_REPOSITORY_XCONTENT_PARAM, INDEX_NAMES_XCONTENT_PARAM);
90+
return SUPPORTED_RESPONSE_PARAMETERS;
91+
}
92+
93+
@Override
94+
public Set<String> supportedQueryParameters() {
95+
return SUPPORTED_QUERY_PARAMETERS;
96+
}
97+
98+
@Override
99+
public Set<String> allSupportedParameters() {
100+
return ALL_SUPPORTED_PARAMETERS;
64101
}
65102

66103
@Override
@@ -101,6 +138,14 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC
101138
throw new IllegalStateException("[state] parameter is not supported on all nodes in the cluster");
102139
}
103140

141+
// Consume these response parameters used in SnapshotInfo now, to avoid assertion errors in BaseRestHandler for requests where they
142+
// may not get used.
143+
if (Assertions.ENABLED) {
144+
for (final var responseParameter : SUPPORTED_RESPONSE_PARAMETERS) {
145+
request.param(responseParameter);
146+
}
147+
}
148+
104149
return channel -> new RestCancellableNodeClient(client, request.getHttpChannel()).admin()
105150
.cluster()
106151
.getSnapshots(getSnapshotsRequest, new RestRefCountedChunkedToXContentListener<>(channel));

0 commit comments

Comments
 (0)