23
23
import org .elasticsearch .action .admin .cluster .repositories .put .PutRepositoryRequest ;
24
24
import org .elasticsearch .action .admin .cluster .snapshots .create .CreateSnapshotRequest ;
25
25
import org .elasticsearch .action .admin .cluster .snapshots .delete .DeleteSnapshotRequest ;
26
- import org .elasticsearch .action .admin .cluster .snapshots .restore .RestoreSnapshotRequest ;
27
26
import org .elasticsearch .action .admin .cluster .snapshots .status .SnapshotStatus ;
28
27
import org .elasticsearch .action .admin .cluster .snapshots .status .SnapshotsStatusRequest ;
29
28
import org .elasticsearch .action .admin .cluster .snapshots .status .SnapshotsStatusResponse ;
38
37
import org .elasticsearch .common .xcontent .DeprecationHandler ;
39
38
import org .elasticsearch .common .xcontent .XContentParser ;
40
39
import org .elasticsearch .common .xcontent .json .JsonXContent ;
41
- import org .elasticsearch .snapshots .RestoreInfo ;
42
40
import org .elasticsearch .snapshots .SnapshotsService ;
43
41
import org .elasticsearch .test .rest .ESRestTestCase ;
44
42
50
48
import java .util .Map ;
51
49
import java .util .stream .Collectors ;
52
50
53
- import static org .hamcrest .Matchers .equalTo ;
54
51
import static org .hamcrest .Matchers .hasItem ;
55
52
import static org .hamcrest .Matchers .hasSize ;
56
53
import static org .hamcrest .Matchers .is ;
@@ -146,10 +143,10 @@ public void testCreateAndRestoreSnapshot() throws IOException {
146
143
break ;
147
144
}
148
145
if (TEST_STEP == TestStep .STEP3_OLD_CLUSTER ) {
149
- ensureSnapshotRestoreWorks (client , repoName , "snapshot-" + TestStep .STEP1_OLD_CLUSTER , shards );
146
+ ensureSnapshotRestoreWorks (repoName , "snapshot-" + TestStep .STEP1_OLD_CLUSTER , shards );
150
147
} else if (TEST_STEP == TestStep .STEP4_NEW_CLUSTER ) {
151
148
for (TestStep value : TestStep .values ()) {
152
- ensureSnapshotRestoreWorks (client , repoName , "snapshot-" + value , shards );
149
+ ensureSnapshotRestoreWorks (repoName , "snapshot-" + value , shards );
153
150
}
154
151
}
155
152
} finally {
@@ -185,10 +182,10 @@ public void testReadOnlyRepo() throws IOException {
185
182
"snapshot-" + TestStep .STEP1_OLD_CLUSTER , "snapshot-" + TestStep .STEP2_NEW_CLUSTER );
186
183
}
187
184
if (TEST_STEP == TestStep .STEP3_OLD_CLUSTER ) {
188
- ensureSnapshotRestoreWorks (client , repoName , "snapshot-" + TestStep .STEP1_OLD_CLUSTER , shards );
185
+ ensureSnapshotRestoreWorks (repoName , "snapshot-" + TestStep .STEP1_OLD_CLUSTER , shards );
189
186
} else if (TEST_STEP == TestStep .STEP4_NEW_CLUSTER ) {
190
- ensureSnapshotRestoreWorks (client , repoName , "snapshot-" + TestStep .STEP1_OLD_CLUSTER , shards );
191
- ensureSnapshotRestoreWorks (client , repoName , "snapshot-" + TestStep .STEP2_NEW_CLUSTER , shards );
187
+ ensureSnapshotRestoreWorks (repoName , "snapshot-" + TestStep .STEP1_OLD_CLUSTER , shards );
188
+ ensureSnapshotRestoreWorks (repoName , "snapshot-" + TestStep .STEP2_NEW_CLUSTER , shards );
192
189
}
193
190
}
194
191
}
@@ -208,15 +205,15 @@ public void testUpgradeMovesRepoToNewMetaVersion() throws IOException {
208
205
assertSnapshotStatusSuccessful (client , repoName ,
209
206
snapshots .stream ().map (sn -> (String ) sn .get ("snapshot" )).toArray (String []::new ));
210
207
if (TEST_STEP == TestStep .STEP1_OLD_CLUSTER ) {
211
- ensureSnapshotRestoreWorks (client , repoName , "snapshot-" + TestStep .STEP1_OLD_CLUSTER , shards );
208
+ ensureSnapshotRestoreWorks (repoName , "snapshot-" + TestStep .STEP1_OLD_CLUSTER , shards );
212
209
} else {
213
210
deleteSnapshot (client , repoName , "snapshot-" + TestStep .STEP1_OLD_CLUSTER );
214
- ensureSnapshotRestoreWorks (client , repoName , "snapshot-" + TestStep .STEP2_NEW_CLUSTER , shards );
211
+ ensureSnapshotRestoreWorks (repoName , "snapshot-" + TestStep .STEP2_NEW_CLUSTER , shards );
215
212
createSnapshot (client , repoName , "snapshot-1" );
216
- ensureSnapshotRestoreWorks (client , repoName , "snapshot-1" , shards );
213
+ ensureSnapshotRestoreWorks (repoName , "snapshot-1" , shards );
217
214
deleteSnapshot (client , repoName , "snapshot-" + TestStep .STEP2_NEW_CLUSTER );
218
215
createSnapshot (client , repoName , "snapshot-2" );
219
- ensureSnapshotRestoreWorks (client , repoName , "snapshot-2" , shards );
216
+ ensureSnapshotRestoreWorks (repoName , "snapshot-2" , shards );
220
217
}
221
218
} else {
222
219
if (minimumNodeVersion ().before (SnapshotsService .SHARD_GEN_IN_REPO_DATA_VERSION )) {
@@ -230,8 +227,8 @@ public void testUpgradeMovesRepoToNewMetaVersion() throws IOException {
230
227
} else {
231
228
assertThat (listSnapshots (repoName ), hasSize (2 ));
232
229
if (TEST_STEP == TestStep .STEP4_NEW_CLUSTER ) {
233
- ensureSnapshotRestoreWorks (client , repoName , "snapshot-1" , shards );
234
- ensureSnapshotRestoreWorks (client , repoName , "snapshot-2" , shards );
230
+ ensureSnapshotRestoreWorks (repoName , "snapshot-1" , shards );
231
+ ensureSnapshotRestoreWorks (repoName , "snapshot-2" , shards );
235
232
}
236
233
}
237
234
}
@@ -269,14 +266,20 @@ private List<Map<String, Object>> listSnapshots(String repoName) throws IOExcept
269
266
}
270
267
}
271
268
272
- private static void ensureSnapshotRestoreWorks ( RestHighLevelClient client , String repoName , String name ,
273
- int shards ) throws IOException {
269
+ @ SuppressWarnings ( "unchecked" )
270
+ private void ensureSnapshotRestoreWorks ( String repoName , String name , int shards ) throws IOException {
274
271
wipeAllIndices ();
275
- final RestoreInfo restoreInfo =
276
- client .snapshot ().restore (new RestoreSnapshotRequest ().repository (repoName ).snapshot (name ).waitForCompletion (true ),
277
- RequestOptions .DEFAULT ).getRestoreInfo ();
278
- assertThat (restoreInfo .failedShards (), is (0 ));
279
- assertThat (restoreInfo .successfulShards (), equalTo (shards ));
272
+ try (InputStream entity = client ().performRequest (
273
+ new Request ("POST" , "/_snapshot/" + repoName + "/" + name + "/_restore?wait_for_completion=true" )).getEntity ().getContent ();
274
+ XContentParser parser = JsonXContent .jsonXContent .createParser (
275
+ xContentRegistry (), DeprecationHandler .THROW_UNSUPPORTED_OPERATION , entity )) {
276
+ final Map <String , Object > raw = parser .map ();
277
+ logger .error (raw );
278
+ final Map <String , Object > snapshot = (Map <String , Object >) raw .get ("snapshot" );
279
+ final Map <String , Object > shardStats = (Map <String , Object >) snapshot .get ("shards" );
280
+ assertThat (shardStats .get ("successful" ), is (shards ));
281
+ assertThat (shardStats .get ("failed" ), is (0 ));
282
+ }
280
283
}
281
284
282
285
private static void createRepository (RestHighLevelClient client , String repoName , boolean readOnly ) throws IOException {
0 commit comments