From 9669ce2a6ddd0863ebe8e3e70cb4e8886d97df4d Mon Sep 17 00:00:00 2001 From: Andre Kurait Date: Tue, 10 Dec 2024 13:34:01 -0600 Subject: [PATCH] Simplify ClusterOperations Signed-off-by: Andre Kurait --- .../bulkload/http/ClusterOperations.java | 53 ------------------- 1 file changed, 53 deletions(-) diff --git a/RFS/src/testFixtures/java/org/opensearch/migrations/bulkload/http/ClusterOperations.java b/RFS/src/testFixtures/java/org/opensearch/migrations/bulkload/http/ClusterOperations.java index 63048f695..e0a97d805 100644 --- a/RFS/src/testFixtures/java/org/opensearch/migrations/bulkload/http/ClusterOperations.java +++ b/RFS/src/testFixtures/java/org/opensearch/migrations/bulkload/http/ClusterOperations.java @@ -2,13 +2,9 @@ import java.io.IOException; import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.List; import java.util.Map; import java.util.Optional; -import org.opensearch.migrations.bulkload.framework.SearchClusterContainer; - import lombok.SneakyThrows; import org.apache.hc.client5.http.classic.methods.HttpDelete; import org.apache.hc.client5.http.classic.methods.HttpGet; @@ -57,55 +53,6 @@ public void createSnapshotRepository(final String repoPath, final String repoNam } } - @SneakyThrows - public void deleteAllSnapshotsAndRepository(final String repoName) throws IOException { - // Get all snapshots in the repository - HttpGet getSnapshotsRequest = new HttpGet(clusterUrl + "/_snapshot/" + repoName + "/_all"); - getSnapshotsRequest.setHeader("Content-Type", "application/json"); - - List snapshotNames = new ArrayList<>(); - try (var response = httpClient.execute(getSnapshotsRequest)) { - if (response.getCode() == 200) { - String responseBody = EntityUtils.toString(response.getEntity()); - // Extract snapshot names from the response - int index = 0; - while ((index = responseBody.indexOf("\"snapshot\":\"", index)) != -1) { - index += "\"snapshot\":\"".length(); - int endIndex = responseBody.indexOf("\"", index); - if (endIndex == -1) break; - String snapshotName = responseBody.substring(index, endIndex); - snapshotNames.add(snapshotName); - } - } else if (response.getCode() == 404) { - // Repository does not exist or no snapshots - return; - } else { - throw new IOException("Failed to list snapshots for repository " + repoName + ", status code: " + response.getCode()); - } - } - - // Delete each snapshot - for (String snapshot : snapshotNames) { - HttpDelete deleteSnapshotRequest = new HttpDelete(clusterUrl + "/_snapshot/" + repoName + "/" + snapshot); - deleteSnapshotRequest.setHeader("Content-Type", "application/json"); - try (var response = httpClient.execute(deleteSnapshotRequest)) { - assertThat(response.getCode(), anyOf(equalTo(200), equalTo(202))); - } - } - - // Delete the repository - HttpDelete deleteRepoRequest = new HttpDelete(clusterUrl + "/_snapshot/" + repoName); - deleteRepoRequest.setHeader("Content-Type", "application/json"); - try (var response = httpClient.execute(deleteRepoRequest)) { - assertThat(response.getCode(), equalTo(200)); - } - } - - @SneakyThrows - public static void deleteSnapshotDir(SearchClusterContainer container) { - container.execInContainer("sh", "-c", "rm -rf " + SearchClusterContainer.CLUSTER_SNAPSHOT_DIR + "/*"); - } - @SneakyThrows public void restoreSnapshot(final String repository, final String snapshotName) { var restoreRequest = new HttpPost(clusterUrl + "/_snapshot/" + repository + "/" + snapshotName + "/_restore"+ "?wait_for_completion=true");