1212import org .apache .http .entity .StringEntity ;
1313import org .elasticsearch .Version ;
1414import org .elasticsearch .action .admin .cluster .repositories .put .PutRepositoryRequest ;
15- import org .elasticsearch .action .admin .cluster .snapshots .get .GetSnapshotsRequest ;
1615import org .elasticsearch .action .admin .cluster .snapshots .restore .RestoreSnapshotRequest ;
17- import org .elasticsearch .action .admin .cluster .snapshots .restore .RestoreSnapshotResponse ;
18- import org .elasticsearch .action .admin .cluster .snapshots .status .SnapshotStatus ;
19- import org .elasticsearch .action .admin .cluster .snapshots .status .SnapshotsStatusRequest ;
20- import org .elasticsearch .action .admin .cluster .snapshots .status .SnapshotsStatusResponse ;
2116import org .elasticsearch .action .search .SearchRequest ;
2217import org .elasticsearch .action .search .SearchResponse ;
2318import org .elasticsearch .action .support .master .AcknowledgedResponse ;
2722import org .elasticsearch .client .RestClient ;
2823import org .elasticsearch .client .RestHighLevelClient ;
2924import org .elasticsearch .client .core .ShardsAcknowledgedResponse ;
30- import org .elasticsearch .cluster .SnapshotsInProgress ;
3125import org .elasticsearch .cluster .routing .Murmur3HashFunction ;
3226import org .elasticsearch .common .Strings ;
3327import org .elasticsearch .common .document .DocumentField ;
3428import org .elasticsearch .common .settings .SecureString ;
3529import org .elasticsearch .common .settings .Settings ;
3630import org .elasticsearch .common .util .concurrent .ThreadContext ;
37- import org .elasticsearch .common .util .set .Sets ;
3831import org .elasticsearch .core .Booleans ;
3932import org .elasticsearch .core .PathUtils ;
4033import org .elasticsearch .index .query .QueryBuilders ;
4134import org .elasticsearch .search .SearchHit ;
4235import org .elasticsearch .search .builder .SearchSourceBuilder ;
4336import org .elasticsearch .search .sort .SortBuilders ;
4437import org .elasticsearch .search .sort .SortOrder ;
45- import org .elasticsearch .snapshots .SnapshotInfo ;
4638import org .elasticsearch .snapshots .SnapshotState ;
47- import org .elasticsearch .test .hamcrest .ElasticsearchAssertions ;
4839import org .elasticsearch .test .rest .ESRestTestCase ;
4940import org .elasticsearch .test .rest .ObjectPath ;
5041import org .elasticsearch .xcontent .XContentBuilder ;
6152import java .util .Set ;
6253import java .util .stream .Collectors ;
6354
55+ import static org .hamcrest .Matchers .contains ;
6456import static org .hamcrest .Matchers .empty ;
57+ import static org .hamcrest .Matchers .equalTo ;
6558import static org .hamcrest .Matchers .greaterThan ;
6659import static org .hamcrest .Matchers .hasKey ;
67- import static org .hamcrest .Matchers .hasSize ;
6860import static org .hamcrest .Matchers .instanceOf ;
6961import static org .hamcrest .Matchers .not ;
7062import static org .hamcrest .Matchers .startsWith ;
@@ -204,58 +196,54 @@ private void beforeRestart(
204196 if (sourceOnlyRepository ) {
205197 repoSettingsBuilder .put ("delegate_type" , "fs" );
206198 }
207- ElasticsearchAssertions .assertAcked (
208- client .snapshot ()
209- .createRepository (
210- new PutRepositoryRequest (repoName ).type (sourceOnlyRepository ? "source" : "fs" ).settings (repoSettingsBuilder ),
211- RequestOptions .DEFAULT
212- )
199+ Request createRepo = new Request ("PUT" , "/_snapshot/" + repoName );
200+ createRepo .setJsonEntity (
201+ Strings .toString (new PutRepositoryRequest ().type (sourceOnlyRepository ? "source" : "fs" ).settings (repoSettingsBuilder .build ()))
213202 );
203+ assertAcknowledged (client ().performRequest (createRepo ));
214204
215205 // list snapshots on new ES
216- List <SnapshotInfo > snapshotInfos = client .snapshot ()
217- .get (new GetSnapshotsRequest (repoName ).snapshots (new String [] { "_all" }), RequestOptions .DEFAULT )
218- .getSnapshots ();
219- assertThat (snapshotInfos , hasSize (1 ));
220- SnapshotInfo snapshotInfo = snapshotInfos .get (0 );
221- assertEquals (snapshotName , snapshotInfo .snapshotId ().getName ());
222- assertEquals (repoName , snapshotInfo .repository ());
223- assertEquals (Arrays .asList (indexName ), snapshotInfo .indices ());
224- assertEquals (SnapshotState .SUCCESS , snapshotInfo .state ());
225- assertEquals (numberOfShards , snapshotInfo .successfulShards ());
226- assertEquals (numberOfShards , snapshotInfo .totalShards ());
227- assertEquals (0 , snapshotInfo .failedShards ());
228- assertEquals (oldVersion , snapshotInfo .version ());
206+ Request getSnaps = new Request ("GET" , "/_snapshot/" + repoName + "/_all" );
207+ Response getResponse = client ().performRequest (getSnaps );
208+ ObjectPath getResp = ObjectPath .createFromResponse (getResponse );
209+ assertThat (getResp .evaluate ("total" ), equalTo (1 ));
210+ assertThat (getResp .evaluate ("snapshots.0.snapshot" ), equalTo (snapshotName ));
211+ assertThat (getResp .evaluate ("snapshots.0.repository" ), equalTo (repoName ));
212+ assertThat (getResp .evaluate ("snapshots.0.indices" ), contains (indexName ));
213+ assertThat (getResp .evaluate ("snapshots.0.state" ), equalTo (SnapshotState .SUCCESS .toString ()));
214+ assertEquals (numberOfShards , (int ) getResp .evaluate ("snapshots.0.shards.successful" ));
215+ assertEquals (numberOfShards , (int ) getResp .evaluate ("snapshots.0.shards.total" ));
216+ assertEquals (0 , (int ) getResp .evaluate ("snapshots.0.shards.failed" ));
217+ assertEquals (oldVersion .toString (), getResp .evaluate ("snapshots.0.version" ));
229218
230219 // list specific snapshot on new ES
231- snapshotInfos = client .snapshot ()
232- .get (new GetSnapshotsRequest (repoName ).snapshots (new String [] { snapshotName }), RequestOptions .DEFAULT )
233- .getSnapshots ();
234- assertThat (snapshotInfos , hasSize (1 ));
235- snapshotInfo = snapshotInfos .get (0 );
236- assertEquals (snapshotName , snapshotInfo .snapshotId ().getName ());
237- assertEquals (repoName , snapshotInfo .repository ());
238- assertEquals (Arrays .asList (indexName ), snapshotInfo .indices ());
239- assertEquals (SnapshotState .SUCCESS , snapshotInfo .state ());
240- assertEquals (numberOfShards , snapshotInfo .successfulShards ());
241- assertEquals (numberOfShards , snapshotInfo .totalShards ());
242- assertEquals (0 , snapshotInfo .failedShards ());
243- assertEquals (oldVersion , snapshotInfo .version ());
220+ getSnaps = new Request ("GET" , "/_snapshot/" + repoName + "/" + snapshotName );
221+ getResponse = client ().performRequest (getSnaps );
222+ getResp = ObjectPath .createFromResponse (getResponse );
223+ assertThat (getResp .evaluate ("total" ), equalTo (1 ));
224+ assertThat (getResp .evaluate ("snapshots.0.snapshot" ), equalTo (snapshotName ));
225+ assertThat (getResp .evaluate ("snapshots.0.repository" ), equalTo (repoName ));
226+ assertThat (getResp .evaluate ("snapshots.0.indices" ), contains (indexName ));
227+ assertThat (getResp .evaluate ("snapshots.0.state" ), equalTo (SnapshotState .SUCCESS .toString ()));
228+ assertEquals (numberOfShards , (int ) getResp .evaluate ("snapshots.0.shards.successful" ));
229+ assertEquals (numberOfShards , (int ) getResp .evaluate ("snapshots.0.shards.total" ));
230+ assertEquals (0 , (int ) getResp .evaluate ("snapshots.0.shards.failed" ));
231+ assertEquals (oldVersion .toString (), getResp .evaluate ("snapshots.0.version" ));
244232
245233 // list advanced snapshot info on new ES
246- SnapshotsStatusResponse snapshotsStatusResponse = client . snapshot ()
247- . status ( new SnapshotsStatusRequest ( repoName ). snapshots ( new String [] { snapshotName }), RequestOptions . DEFAULT );
248- assertThat ( snapshotsStatusResponse . getSnapshots (), hasSize ( 1 ) );
249- SnapshotStatus snapshotStatus = snapshotsStatusResponse . getSnapshots (). get ( 0 );
250- assertEquals ( snapshotName , snapshotStatus . getSnapshot (). getSnapshotId (). getName ( ));
251- assertEquals ( repoName , snapshotStatus . getSnapshot (). getRepository ( ));
252- assertEquals ( Sets . newHashSet ( indexName ), snapshotStatus . getIndices () .keySet ());
253- assertEquals ( SnapshotsInProgress . State . SUCCESS , snapshotStatus . getState ( ));
254- assertEquals (numberOfShards , snapshotStatus . getShardsStats (). getDoneShards ( ));
255- assertEquals (numberOfShards , snapshotStatus . getShardsStats (). getTotalShards ( ));
256- assertEquals (0 , snapshotStatus . getShardsStats (). getFailedShards ( ));
257- assertThat (snapshotStatus . getStats (). getTotalSize ( ), greaterThan (0L ));
258- assertThat (snapshotStatus . getStats (). getTotalFileCount ( ), greaterThan (0 ));
234+ getSnaps = new Request ( "GET" , "/_snapshot/" + repoName + "/" + snapshotName + "/_status" );
235+ getResponse = client (). performRequest ( getSnaps );
236+ getResp = ObjectPath . createFromResponse ( getResponse );
237+ assertThat ((( List <?>) getResp . evaluate ( "snapshots" )). size (), equalTo ( 1 ) );
238+ assertThat ( getResp . evaluate ( "snapshots.0.snapshot" ), equalTo ( snapshotName ));
239+ assertThat ( getResp . evaluate ( "snapshots.0.repository" ), equalTo ( repoName ));
240+ assertThat ((( Map <?, ?>) getResp . evaluate ( "snapshots.0.indices" )) .keySet (), contains ( indexName ));
241+ assertThat ( getResp . evaluate ( "snapshots.0.state" ), equalTo ( SnapshotState . SUCCESS . toString () ));
242+ assertEquals (numberOfShards , ( int ) getResp . evaluate ( "snapshots.0.shards_stats.done" ));
243+ assertEquals (numberOfShards , ( int ) getResp . evaluate ( "snapshots.0.shards_stats.total" ));
244+ assertEquals (0 , ( int ) getResp . evaluate ( "snapshots.0.shards_stats.failed" ));
245+ assertThat (getResp . evaluate ( "snapshots.0.stats.total.size_in_bytes" ), greaterThan (0 ));
246+ assertThat (getResp . evaluate ( "snapshots.0.stats.total.file_count" ), greaterThan (0 ));
259247
260248 // restore / mount and check whether searches work
261249 restoreMountAndVerify (
@@ -271,10 +259,9 @@ private void beforeRestart(
271259 );
272260
273261 // close indices
274- RestClient llClient = client .getLowLevelClient ();
275- assertTrue (closeIndex (llClient , "restored_" + indexName ).isShardsAcknowledged ());
276- assertTrue (closeIndex (llClient , "mounted_full_copy_" + indexName ).isShardsAcknowledged ());
277- assertTrue (closeIndex (llClient , "mounted_shared_cache_" + indexName ).isShardsAcknowledged ());
262+ assertTrue (closeIndex (client (), "restored_" + indexName ).isShardsAcknowledged ());
263+ assertTrue (closeIndex (client (), "mounted_full_copy_" + indexName ).isShardsAcknowledged ());
264+ assertTrue (closeIndex (client (), "mounted_shared_cache_" + indexName ).isShardsAcknowledged ());
278265
279266 // restore / mount again
280267 restoreMountAndVerify (
@@ -311,23 +298,20 @@ private void restoreMountAndVerify(
311298 String snapshotName
312299 ) throws IOException {
313300 // restore index
314- RestoreSnapshotResponse restoreSnapshotResponse = client .snapshot ()
315- .restore (
316- new RestoreSnapshotRequest (repoName , snapshotName ).indices (indexName )
317- .renamePattern ("(.+)" )
318- .renameReplacement ("restored_$1" )
319- .waitForCompletion (true ),
320- RequestOptions .DEFAULT
321- );
322- assertNotNull (restoreSnapshotResponse .getRestoreInfo ());
323- assertEquals (numberOfShards , restoreSnapshotResponse .getRestoreInfo ().totalShards ());
324- assertEquals (numberOfShards , restoreSnapshotResponse .getRestoreInfo ().successfulShards ());
301+ Request restoreRequest = new Request ("POST" , "/_snapshot/" + repoName + "/" + snapshotName + "/_restore" );
302+ restoreRequest .setJsonEntity (
303+ Strings .toString (new RestoreSnapshotRequest ().indices (indexName ).renamePattern ("(.+)" ).renameReplacement ("restored_$1" ))
304+ );
305+ restoreRequest .addParameter ("wait_for_completion" , "true" );
306+ Response restoreResponse = client ().performRequest (restoreRequest );
307+ ObjectPath restore = ObjectPath .createFromResponse (restoreResponse );
308+ assertEquals (numberOfShards , (int ) restore .evaluate ("snapshot.shards.total" ));
309+ assertEquals (numberOfShards , (int ) restore .evaluate ("snapshot.shards.successful" ));
325310
326311 ensureGreen ("restored_" + indexName );
327312
328313 String restoredIndex = "restored_" + indexName ;
329- RestClient llClient = client .getLowLevelClient ();
330- var response = responseAsMap (llClient .performRequest (new Request ("GET" , "/" + restoredIndex + "/_mapping" )));
314+ var response = responseAsMap (client ().performRequest (new Request ("GET" , "/" + restoredIndex + "/_mapping" )));
331315 Map <?, ?> mapping = ObjectPath .evaluate (response , restoredIndex + ".mappings" );
332316 logger .info ("mapping for {}: {}" , restoredIndex , mapping );
333317 assertThat (mapping , hasKey ("_meta" ));
0 commit comments