36
36
import org .elasticsearch .client .RestClient ;
37
37
import org .elasticsearch .client .RestClientBuilder ;
38
38
import org .elasticsearch .client .WarningsHandler ;
39
+ import org .elasticsearch .cluster .SnapshotsInProgress ;
39
40
import org .elasticsearch .common .CheckedRunnable ;
40
41
import org .elasticsearch .common .Strings ;
41
42
import org .elasticsearch .common .io .PathUtils ;
72
73
import java .security .cert .CertificateException ;
73
74
import java .util .ArrayList ;
74
75
import java .util .Arrays ;
76
+ import java .util .HashMap ;
75
77
import java .util .HashSet ;
76
78
import java .util .List ;
77
79
import java .util .Map ;
@@ -449,6 +451,8 @@ private void wipeCluster() throws Exception {
449
451
waitForPendingRollupTasks ();
450
452
}
451
453
454
+ final Map <String , List <Map <?,?>>> inProgressSnapshots = wipeSnapshots ();
455
+
452
456
if (preserveIndicesUponCompletion () == false ) {
453
457
// wipe indices
454
458
try {
@@ -489,8 +493,6 @@ private void wipeCluster() throws Exception {
489
493
}
490
494
}
491
495
492
- wipeSnapshots ();
493
-
494
496
// wipe cluster settings
495
497
if (preserveClusterSettings () == false ) {
496
498
wipeClusterSettings ();
@@ -499,14 +501,18 @@ private void wipeCluster() throws Exception {
499
501
if (hasXPack && false == preserveILMPoliciesUponCompletion ()) {
500
502
deleteAllPolicies ();
501
503
}
504
+
505
+ assertTrue ("Found in progress snapshots [" + inProgressSnapshots + "]." , inProgressSnapshots .isEmpty ());
502
506
}
503
507
504
508
/**
505
509
* Wipe fs snapshots we created one by one and all repositories so that the next test can create the repositories fresh and they'll
506
510
* start empty. There isn't an API to delete all snapshots. There is an API to delete all snapshot repositories but that leaves all of
507
511
* the snapshots intact in the repository.
512
+ * @return Map of repository name to list of snapshots found in unfinished state
508
513
*/
509
- private void wipeSnapshots () throws IOException {
514
+ private Map <String , List <Map <?, ?>>> wipeSnapshots () throws IOException {
515
+ final Map <String , List <Map <?, ?>>> inProgressSnapshots = new HashMap <>();
510
516
for (Map .Entry <String , ?> repo : entityAsMap (adminClient .performRequest (new Request ("GET" , "/_snapshot/_all" ))).entrySet ()) {
511
517
String repoName = repo .getKey ();
512
518
Map <?, ?> repoSpec = (Map <?, ?>) repo .getValue ();
@@ -519,6 +525,9 @@ private void wipeSnapshots() throws IOException {
519
525
for (Object snapshot : snapshots ) {
520
526
Map <?, ?> snapshotInfo = (Map <?, ?>) snapshot ;
521
527
String name = (String ) snapshotInfo .get ("snapshot" );
528
+ if (SnapshotsInProgress .State .valueOf ((String ) snapshotInfo .get ("state" )).completed () == false ) {
529
+ inProgressSnapshots .computeIfAbsent (repoName , key -> new ArrayList <>()).add (snapshotInfo );
530
+ }
522
531
logger .debug ("wiping snapshot [{}/{}]" , repoName , name );
523
532
adminClient ().performRequest (new Request ("DELETE" , "/_snapshot/" + repoName + "/" + name ));
524
533
}
@@ -528,6 +537,7 @@ private void wipeSnapshots() throws IOException {
528
537
adminClient ().performRequest (new Request ("DELETE" , "_snapshot/" + repoName ));
529
538
}
530
539
}
540
+ return inProgressSnapshots ;
531
541
}
532
542
533
543
/**
0 commit comments