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 ;
@@ -468,6 +470,8 @@ private void wipeCluster() throws Exception {
468
470
waitForPendingRollupTasks ();
469
471
}
470
472
473
+ final Map <String , List <Map <?,?>>> inProgressSnapshots = wipeSnapshots ();
474
+
471
475
if (preserveIndicesUponCompletion () == false ) {
472
476
// wipe indices
473
477
try {
@@ -508,8 +512,6 @@ private void wipeCluster() throws Exception {
508
512
}
509
513
}
510
514
511
- wipeSnapshots ();
512
-
513
515
// wipe cluster settings
514
516
if (preserveClusterSettings () == false ) {
515
517
wipeClusterSettings ();
@@ -518,14 +520,18 @@ private void wipeCluster() throws Exception {
518
520
if (hasXPack && false == preserveILMPoliciesUponCompletion ()) {
519
521
deleteAllPolicies ();
520
522
}
523
+
524
+ assertTrue ("Found in progress snapshots [" + inProgressSnapshots + "]." , inProgressSnapshots .isEmpty ());
521
525
}
522
526
523
527
/**
524
528
* Wipe fs snapshots we created one by one and all repositories so that the next test can create the repositories fresh and they'll
525
529
* 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
526
530
* the snapshots intact in the repository.
531
+ * @return Map of repository name to list of snapshots found in unfinished state
527
532
*/
528
- private void wipeSnapshots () throws IOException {
533
+ private Map <String , List <Map <?, ?>>> wipeSnapshots () throws IOException {
534
+ final Map <String , List <Map <?, ?>>> inProgressSnapshots = new HashMap <>();
529
535
for (Map .Entry <String , ?> repo : entityAsMap (adminClient .performRequest (new Request ("GET" , "/_snapshot/_all" ))).entrySet ()) {
530
536
String repoName = repo .getKey ();
531
537
Map <?, ?> repoSpec = (Map <?, ?>) repo .getValue ();
@@ -538,6 +544,9 @@ private void wipeSnapshots() throws IOException {
538
544
for (Object snapshot : snapshots ) {
539
545
Map <?, ?> snapshotInfo = (Map <?, ?>) snapshot ;
540
546
String name = (String ) snapshotInfo .get ("snapshot" );
547
+ if (SnapshotsInProgress .State .valueOf ((String ) snapshotInfo .get ("state" )).completed () == false ) {
548
+ inProgressSnapshots .computeIfAbsent (repoName , key -> new ArrayList <>()).add (snapshotInfo );
549
+ }
541
550
logger .debug ("wiping snapshot [{}/{}]" , repoName , name );
542
551
adminClient ().performRequest (new Request ("DELETE" , "/_snapshot/" + repoName + "/" + name ));
543
552
}
@@ -547,6 +556,7 @@ private void wipeSnapshots() throws IOException {
547
556
adminClient ().performRequest (new Request ("DELETE" , "_snapshot/" + repoName ));
548
557
}
549
558
}
559
+ return inProgressSnapshots ;
550
560
}
551
561
552
562
/**
0 commit comments