Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up snapshots where possible after each REST test #20489

Merged
merged 1 commit into from
Sep 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@ setup:
settings:
location: "test_repo_get_1_loc"

---
teardown:

- do:
snapshot.delete_repository:
repository: test_repo_get_1

---
"Get snapshot info":

Expand All @@ -39,7 +32,7 @@ teardown:
snapshot: test_snapshot

- is_true: snapshots

---
"Get missing snapshot info throws an exception":

Expand All @@ -48,7 +41,7 @@ teardown:
snapshot.get:
repository: test_repo_get_1
snapshot: test_nonexistent_snapshot

---
"Get missing snapshot info succeeds when ignoreUnavailable is true":

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@ setup:
settings:
location: "test_repo_status_1_loc"

---
teardown:

- do:
snapshot.delete_repository:
repository: test_repo_status_1

---
"Get snapshot status":

Expand All @@ -39,7 +32,7 @@ teardown:
snapshot: test_snapshot

- is_true: snapshots

---
"Get missing snapshot status throws an exception":

Expand All @@ -48,7 +41,7 @@ teardown:
snapshot.status:
repository: test_repo_status_1
snapshot: test_nonexistent_snapshot

---
"Get missing snapshot status succeeds when ignoreUnavailable is true":

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@

import javax.net.ssl.SSLContext;

import static java.util.Collections.singletonMap;
import static java.util.Collections.sort;
import static java.util.Collections.unmodifiableList;

Expand Down Expand Up @@ -151,9 +152,34 @@ private void wipeCluster() throws IOException {
// wipe index templates
adminClient().performRequest("DELETE", "_template/*");

// wipe snapshots
// Technically this deletes all repositories and leave the snapshots in the repository. OK.
adminClient().performRequest("DELETE", "_snapshot/*");
wipeSnapshots();
}

/**
* Wipe fs snapshots we created one by one and all repositories so that the next test can create the repositories fresh and they'll
* 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
* the snapshots intact in the repository.
*/
private void wipeSnapshots() throws IOException {
for (Map.Entry<String, ?> repo : entityAsMap(adminClient.performRequest("GET", "_snapshot/_all")).entrySet()) {
String repoName = repo.getKey();
Map<?, ?> repoSpec = (Map<?, ?>) repo.getValue();
String repoType = (String) repoSpec.get("type");
if (repoType.equals("fs")) {
// All other repo types we really don't have a chance of being able to iterate properly, sadly.
String url = "_snapshot/" + repoName + "/_all";
Map<String, String> params = singletonMap("ignore_unavailable", "true");
List<?> snapshots = (List<?>) entityAsMap(adminClient.performRequest("GET", url, params)).get("snapshots");
for (Object snapshot : snapshots) {
Map<?, ?> snapshotInfo = (Map<?, ?>) snapshot;
String name = (String) snapshotInfo.get("snapshot");
logger.debug("wiping snapshot [{}/{}]", repoName, name);
adminClient().performRequest("DELETE", "_snapshot/" + repoName + "/" + name);
}
}
logger.debug("wiping snapshot repository [{}]", repoName);
adminClient().performRequest("DELETE", "_snapshot/" + repoName);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @nik9000 ! @elastic/es-clients is this ok? I guess all the client runners will have to be changed accordingly.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think they'll start failing without this right away, but they should probably pick it up eventually. I'll wait to merge this until we get a response.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine with me :) I'm already wiping the repository itself after each test, so this shouldn't have much effect (I don't think).

}

/**
Expand Down