Skip to content

Commit cbf48e0

Browse files
Flatten Get Snapshots Response (#74451)
This PR returns the get snapshots API to the 7.x format (and transport client behavior) and enhances it for requests that ask for multiple repositories. The changes for requests that target multiple repositories are: * Add `repository` field to `SnapshotInfo` and REST response * Add `failures` map alongside `snapshots` list instead of returning just an exception response as done for single repo requests * Pagination now works across repositories instead of being per repository for multi-repository requests closes #69108 closes #43462
1 parent c37184c commit cbf48e0

File tree

71 files changed

+640
-757
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+640
-757
lines changed

client/rest-high-level/src/test/java/org/elasticsearch/client/SnapshotIT.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,14 @@
3535
import org.elasticsearch.rest.RestStatus;
3636
import org.elasticsearch.snapshots.AbstractSnapshotIntegTestCase;
3737
import org.elasticsearch.snapshots.RestoreInfo;
38+
import org.elasticsearch.snapshots.SnapshotInfo;
3839
import org.mockito.internal.util.collections.Sets;
3940

4041
import java.io.IOException;
4142
import java.util.Collections;
4243
import java.util.List;
4344
import java.util.Map;
45+
import java.util.stream.Collectors;
4446

4547
import static org.elasticsearch.snapshots.SnapshotsService.NO_FEATURE_STATES_VALUE;
4648
import static org.elasticsearch.tasks.TaskResultsService.TASKS_FEATURE_NAME;
@@ -209,14 +211,17 @@ public void testGetSnapshots() throws IOException {
209211
GetSnapshotsResponse response = execute(request, highLevelClient().snapshot()::get, highLevelClient().snapshot()::getAsync);
210212

211213
assertThat(response.isFailed(), is(false));
212-
assertThat(response.getRepositories(), equalTo(Sets.newSet(repository1, repository2)));
213-
214-
assertThat(response.getSnapshots(repository1), hasSize(1));
215-
assertThat(response.getSnapshots(repository1).get(0).snapshotId().getName(), equalTo(snapshot1));
214+
assertEquals(
215+
Sets.newSet(repository1, repository2),
216+
response.getSnapshots().stream().map(SnapshotInfo::repository).collect(Collectors.toSet())
217+
);
216218

217-
assertThat(response.getSnapshots(repository2), hasSize(1));
218-
assertThat(response.getSnapshots(repository2).get(0).snapshotId().getName(), equalTo(snapshot2));
219-
assertThat(response.getSnapshots(repository2).get(0).userMetadata(), equalTo(originalMetadata));
219+
assertThat(response.getSnapshots(), hasSize(2));
220+
assertThat(response.getSnapshots().get(0).snapshotId().getName(), equalTo(snapshot1));
221+
assertThat(response.getSnapshots().get(0).repository(), equalTo(repository1));
222+
assertThat(response.getSnapshots().get(1).snapshotId().getName(), equalTo(snapshot2));
223+
assertThat(response.getSnapshots().get(1).userMetadata(), equalTo(originalMetadata));
224+
assertThat(response.getSnapshots().get(1).repository(), equalTo(repository2));
220225
}
221226

222227

client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/ILMDocumentationIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1044,7 +1044,7 @@ private void assertSnapshotExists(final RestHighLevelClient client, final String
10441044
GetSnapshotsRequest getSnapshotsRequest = new GetSnapshotsRequest(new String[]{repo}, new String[]{snapshotName});
10451045
try {
10461046
final GetSnapshotsResponse snaps = client.snapshot().get(getSnapshotsRequest, RequestOptions.DEFAULT);
1047-
Optional<SnapshotInfo> info = snaps.getSnapshots(repo).stream().findFirst();
1047+
Optional<SnapshotInfo> info = snaps.getSnapshots().stream().findFirst();
10481048
if (info.isPresent()) {
10491049
info.ifPresent(si -> {
10501050
assertThat(si.snapshotId().getName(), equalTo(snapshotName));

client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/SnapshotClientDocumentationIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ public void testSnapshotGetSnapshots() throws IOException {
617617
// end::get-snapshots-execute
618618

619619
// tag::get-snapshots-response
620-
List<SnapshotInfo> snapshotsInfos = response.getSnapshots(repositoryName);
620+
List<SnapshotInfo> snapshotsInfos = response.getSnapshots();
621621
SnapshotInfo snapshotInfo = snapshotsInfos.get(0);
622622
RestStatus restStatus = snapshotInfo.status(); // <1>
623623
SnapshotId snapshotId = snapshotInfo.snapshotId(); // <2>

docs/reference/migration/migrate_8_0/snapshots.asciidoc

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -9,64 +9,6 @@
99

1010
// end::notable-breaking-changes[]
1111

12-
.The get snapshot API's response format has changed.
13-
[%collapsible]
14-
====
15-
*Details* +
16-
It's possible to get snapshots from multiple repositories in one go. The response format has changed
17-
and now contains separate response for each repository.
18-
19-
For example, requesting one snapshot from particular repository
20-
21-
[source,console]
22-
-----------------------------------
23-
GET _snapshot/repo1/snap1
24-
-----------------------------------
25-
// TEST[skip:no repo and snapshots are created]
26-
27-
produces the following response
28-
29-
[source,console-result]
30-
-----------------------------------
31-
{
32-
"responses": [
33-
{
34-
"repository": "repo1",
35-
"snapshots": [
36-
{
37-
"snapshot": "snap1",
38-
"uuid": "cEzdqUKxQ5G6MyrJAcYwmA",
39-
"version_id": 8000099,
40-
"version": "8.0.0",
41-
"indices": [],
42-
"include_global_state": true,
43-
"state": "SUCCESS",
44-
"start_time": "2019-05-10T17:01:57.868Z",
45-
"start_time_in_millis": 1557507717868,
46-
"end_time": "2019-05-10T17:01:57.909Z",
47-
"end_time_in_millis": 1557507717909,
48-
"duration_in_millis": 41,
49-
"failures": [],
50-
"shards": {
51-
"total": 0,
52-
"failed": 0,
53-
"successful": 0
54-
}
55-
}
56-
]
57-
}
58-
]
59-
}
60-
-----------------------------------
61-
// TESTRESPONSE[skip:no repo and snapshots are created]
62-
63-
See <<modules-snapshots>> for more information.
64-
65-
*Impact* +
66-
Update your workflow and applications to use the get snapshot API's new response
67-
format.
68-
====
69-
7012
.The `repositories.fs.compress` node-level setting has been removed.
7113
[%collapsible]
7214
====

docs/reference/snapshot-restore/apis/create-snapshot-api.asciidoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ The API returns the following response:
176176
"snapshot": {
177177
"snapshot": "snapshot_2",
178178
"uuid": "vdRctLCxSketdKb54xw67g",
179+
"repository": "my_repository",
179180
"version_id": <version_id>,
180181
"version": <version>,
181182
"indices": [],

docs/reference/snapshot-restore/apis/get-snapshot-api.asciidoc

Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -284,42 +284,38 @@ The API returns the following response:
284284
[source,console-result]
285285
----
286286
{
287-
"responses": [
287+
"snapshots": [
288288
{
289+
"snapshot": "snapshot_2",
290+
"uuid": "vdRctLCxSketdKb54xw67g",
289291
"repository": "my_repository",
290-
"snapshots": [
291-
{
292-
"snapshot": "snapshot_2",
293-
"uuid": "vdRctLCxSketdKb54xw67g",
294-
"version_id": <version_id>,
295-
"version": <version>,
296-
"indices": [],
297-
"data_streams": [],
298-
"feature_states": [],
299-
"include_global_state": true,
300-
"state": "SUCCESS",
301-
"start_time": "2020-07-06T21:55:18.129Z",
302-
"start_time_in_millis": 1593093628850,
303-
"end_time": "2020-07-06T21:55:18.129Z",
304-
"end_time_in_millis": 1593094752018,
305-
"duration_in_millis": 0,
306-
"failures": [],
307-
"shards": {
308-
"total": 0,
309-
"failed": 0,
310-
"successful": 0
311-
}
312-
}
313-
]
292+
"version_id": <version_id>,
293+
"version": <version>,
294+
"indices": [],
295+
"data_streams": [],
296+
"feature_states": [],
297+
"include_global_state": true,
298+
"state": "SUCCESS",
299+
"start_time": "2020-07-06T21:55:18.129Z",
300+
"start_time_in_millis": 1593093628850,
301+
"end_time": "2020-07-06T21:55:18.129Z",
302+
"end_time_in_millis": 1593094752018,
303+
"duration_in_millis": 0,
304+
"failures": [],
305+
"shards": {
306+
"total": 0,
307+
"failed": 0,
308+
"successful": 0
309+
}
314310
}
315311
]
316312
}
317313
----
318-
// TESTRESPONSE[s/"uuid": "vdRctLCxSketdKb54xw67g"/"uuid": $body.responses.0.snapshots.0.uuid/]
319-
// TESTRESPONSE[s/"version_id": <version_id>/"version_id": $body.responses.0.snapshots.0.version_id/]
320-
// TESTRESPONSE[s/"version": <version>/"version": $body.responses.0.snapshots.0.version/]
321-
// TESTRESPONSE[s/"start_time": "2020-07-06T21:55:18.129Z"/"start_time": $body.responses.0.snapshots.0.start_time/]
322-
// TESTRESPONSE[s/"start_time_in_millis": 1593093628850/"start_time_in_millis": $body.responses.0.snapshots.0.start_time_in_millis/]
323-
// TESTRESPONSE[s/"end_time": "2020-07-06T21:55:18.129Z"/"end_time": $body.responses.0.snapshots.0.end_time/]
324-
// TESTRESPONSE[s/"end_time_in_millis": 1593094752018/"end_time_in_millis": $body.responses.0.snapshots.0.end_time_in_millis/]
325-
// TESTRESPONSE[s/"duration_in_millis": 0/"duration_in_millis": $body.responses.0.snapshots.0.duration_in_millis/]
314+
// TESTRESPONSE[s/"uuid": "vdRctLCxSketdKb54xw67g"/"uuid": $body.snapshots.0.uuid/]
315+
// TESTRESPONSE[s/"version_id": <version_id>/"version_id": $body.snapshots.0.version_id/]
316+
// TESTRESPONSE[s/"version": <version>/"version": $body.snapshots.0.version/]
317+
// TESTRESPONSE[s/"start_time": "2020-07-06T21:55:18.129Z"/"start_time": $body.snapshots.0.start_time/]
318+
// TESTRESPONSE[s/"start_time_in_millis": 1593093628850/"start_time_in_millis": $body.snapshots.0.start_time_in_millis/]
319+
// TESTRESPONSE[s/"end_time": "2020-07-06T21:55:18.129Z"/"end_time": $body.snapshots.0.end_time/]
320+
// TESTRESPONSE[s/"end_time_in_millis": 1593094752018/"end_time_in_millis": $body.snapshots.0.end_time_in_millis/]
321+
// TESTRESPONSE[s/"duration_in_millis": 0/"duration_in_millis": $body.snapshots.0.duration_in_millis/]

docs/reference/snapshot-restore/monitor-snapshot-restore.asciidoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ PUT /_snapshot/my_fs_backup
3131
}
3232
3333
PUT /_snapshot/my_backup/snapshot_1?wait_for_completion=true
34+
35+
PUT /_snapshot/my_backup/some_other_snapshot?wait_for_completion=true
3436
-----------------------------------
3537
// TESTSETUP
3638

modules/repository-url/src/internalClusterTest/java/org/elasticsearch/repositories/url/URLSnapshotRestoreIT.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
2929
import static org.hamcrest.Matchers.equalTo;
3030
import static org.hamcrest.Matchers.greaterThan;
31-
import static org.hamcrest.Matchers.notNullValue;
3231

3332
@ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.TEST)
3433
public class URLSnapshotRestoreIT extends ESIntegTestCase {
@@ -77,7 +76,7 @@ public void testUrlRepository() throws Exception {
7776
.prepareGetSnapshots("test-repo")
7877
.setSnapshots("test-snap")
7978
.get()
80-
.getSnapshots("test-repo")
79+
.getSnapshots()
8180
.get(0)
8281
.state();
8382
assertThat(state, equalTo(SnapshotState.SUCCESS));
@@ -105,16 +104,14 @@ public void testUrlRepository() throws Exception {
105104

106105
logger.info("--> list available shapshots");
107106
GetSnapshotsResponse getSnapshotsResponse = client.admin().cluster().prepareGetSnapshots("url-repo").get();
108-
assertThat(getSnapshotsResponse.getSnapshots("url-repo"), notNullValue());
109-
assertThat(getSnapshotsResponse.getSnapshots("url-repo").size(), equalTo(1));
107+
assertThat(getSnapshotsResponse.getSnapshots().size(), equalTo(1));
110108

111109
logger.info("--> delete snapshot");
112110
AcknowledgedResponse deleteSnapshotResponse = client.admin().cluster().prepareDeleteSnapshot("test-repo", "test-snap").get();
113111
assertAcked(deleteSnapshotResponse);
114112

115113
logger.info("--> list available shapshot again, no snapshots should be returned");
116114
getSnapshotsResponse = client.admin().cluster().prepareGetSnapshots("url-repo").get();
117-
assertThat(getSnapshotsResponse.getSnapshots("url-repo"), notNullValue());
118-
assertThat(getSnapshotsResponse.getSnapshots("url-repo").size(), equalTo(0));
115+
assertThat(getSnapshotsResponse.getSnapshots().size(), equalTo(0));
119116
}
120117
}

modules/repository-url/src/yamlRestTest/resources/rest-api-spec/test/repository_url/10_basic.yml

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,6 @@ teardown:
112112

113113
---
114114
"Restore with repository-url using http://":
115-
- skip:
116-
version: " - 7.99.99"
117-
reason: "8.0 changes get snapshots response format"
118115

119116
# Ensure that the URL repository is registered
120117
- do:
@@ -129,9 +126,9 @@ teardown:
129126
repository: repository-url
130127
snapshot: snapshot-one,snapshot-two
131128

132-
- is_true: responses.0.snapshots
133-
- match: { responses.0.snapshots.0.state : SUCCESS }
134-
- match: { responses.0.snapshots.1.state : SUCCESS }
129+
- is_true: snapshots
130+
- match: { snapshots.0.state : SUCCESS }
131+
- match: { snapshots.1.state : SUCCESS }
135132

136133
# Delete the index
137134
- do:
@@ -177,9 +174,6 @@ teardown:
177174

178175
---
179176
"Restore with repository-url using file://":
180-
- skip:
181-
version: " - 7.99.99"
182-
reason: "8.0 changes get snapshots response format"
183177

184178
# Ensure that the URL repository is registered
185179
- do:
@@ -194,9 +188,9 @@ teardown:
194188
repository: repository-file
195189
snapshot: snapshot-one,snapshot-two
196190

197-
- is_true: responses.0.snapshots
198-
- match: { responses.0.snapshots.0.state : SUCCESS }
199-
- match: { responses.0.snapshots.1.state : SUCCESS }
191+
- is_true: snapshots
192+
- match: { snapshots.0.state : SUCCESS }
193+
- match: { snapshots.1.state : SUCCESS }
200194

201195
# Delete the index
202196
- do:
@@ -242,18 +236,13 @@ teardown:
242236

243237
---
244238
"Get a non existing snapshot":
245-
- skip:
246-
version: " - 7.99.99"
247-
reason: "8.0 changes get snapshots response format"
248239

249240
- do:
241+
catch: /snapshot_missing_exception/
250242
snapshot.get:
251243
repository: repository-url
252244
snapshot: missing
253245

254-
- is_true: responses.0.error
255-
- match: { responses.0.error.type: snapshot_missing_exception }
256-
257246
---
258247
"Delete a non existing snapshot":
259248

plugins/repository-azure/src/yamlRestTest/resources/rest-api-spec/test/repository_azure/20_repository.yml

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ setup:
2828

2929
---
3030
"Snapshot/Restore with repository-azure":
31-
- skip:
32-
version: " - 7.99.99"
33-
reason: "8.0 changes get snapshots response format"
3431

3532
# Get repository
3633
- do:
@@ -130,9 +127,9 @@ setup:
130127
repository: repository
131128
snapshot: snapshot-one,snapshot-two
132129

133-
- is_true: responses.0.snapshots
134-
- match: { responses.0.snapshots.0.state: SUCCESS }
135-
- match: { responses.0.snapshots.1.state: SUCCESS }
130+
- is_true: snapshots
131+
- match: { snapshots.0.state : SUCCESS }
132+
- match: { snapshots.1.state : SUCCESS }
136133

137134
# Delete the index
138135
- do:
@@ -212,18 +209,13 @@ setup:
212209

213210
---
214211
"Get a non existing snapshot":
215-
- skip:
216-
version: " - 7.99.99"
217-
reason: "8.0 changes get snapshots response format"
218212

219213
- do:
214+
catch: /snapshot_missing_exception/
220215
snapshot.get:
221216
repository: repository
222217
snapshot: missing
223218

224-
- is_true: responses.0.error
225-
- match: { responses.0.error.type: snapshot_missing_exception }
226-
227219
---
228220
"Delete a non existing snapshot":
229221

0 commit comments

Comments
 (0)