|
@@ -29,8 +29,12 @@ import org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryRequ
|
|
|
import org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryResponse;
|
|
|
import org.elasticsearch.action.admin.cluster.repositories.verify.VerifyRepositoryRequest;
|
|
|
import org.elasticsearch.action.admin.cluster.repositories.verify.VerifyRepositoryResponse;
|
|
|
+import org.elasticsearch.action.admin.cluster.snapshots.delete.DeleteSnapshotRequest;
|
|
|
+import org.elasticsearch.action.admin.cluster.snapshots.delete.DeleteSnapshotResponse;
|
|
|
import org.elasticsearch.client.ESRestHighLevelClientTestCase;
|
|
|
+import org.elasticsearch.client.Request;
|
|
|
import org.elasticsearch.client.RequestOptions;
|
|
|
+import org.elasticsearch.client.Response;
|
|
|
import org.elasticsearch.client.RestHighLevelClient;
|
|
|
import org.elasticsearch.cluster.metadata.RepositoryMetaData;
|
|
|
import org.elasticsearch.common.settings.Settings;
|
|
@@ -41,6 +45,7 @@ import org.elasticsearch.repositories.fs.FsRepository;
|
|
|
import java.io.IOException;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Locale;
|
|
|
import java.util.Map;
|
|
|
import java.util.concurrent.CountDownLatch;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
@@ -69,6 +74,8 @@ public class SnapshotClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|
|
|
|
|
private static final String repositoryName = "test_repository";
|
|
|
|
|
|
+ private static final String snapshotName = "test_snapshot";
|
|
|
+
|
|
|
public void testSnapshotCreateRepository() throws IOException {
|
|
|
RestHighLevelClient client = highLevelClient();
|
|
|
|
|
@@ -360,10 +367,76 @@ public class SnapshotClientDocumentationIT extends ESRestHighLevelClientTestCase
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public void testSnapshotDeleteSnapshot() throws IOException {
|
|
|
+ RestHighLevelClient client = highLevelClient();
|
|
|
+
|
|
|
+ createTestRepositories();
|
|
|
+ createTestSnapshots();
|
|
|
+
|
|
|
+ // tag::delete-snapshot-request
|
|
|
+ DeleteSnapshotRequest request = new DeleteSnapshotRequest(repositoryName);
|
|
|
+ request.snapshot(snapshotName);
|
|
|
+ // end::delete-snapshot-request
|
|
|
+
|
|
|
+ // tag::delete-snapshot-request-masterTimeout
|
|
|
+ request.masterNodeTimeout(TimeValue.timeValueMinutes(1)); // <1>
|
|
|
+ request.masterNodeTimeout("1m"); // <2>
|
|
|
+ // end::delete-snapshot-request-masterTimeout
|
|
|
+
|
|
|
+ // tag::delete-snapshot-execute
|
|
|
+ DeleteSnapshotResponse response = client.snapshot().delete(request, RequestOptions.DEFAULT);
|
|
|
+ // end::delete-snapshot-execute
|
|
|
+
|
|
|
+ // tag::delete-snapshot-response
|
|
|
+ boolean acknowledged = response.isAcknowledged(); // <1>
|
|
|
+ // end::delete-snapshot-response
|
|
|
+ assertTrue(acknowledged);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void testSnapshotDeleteSnapshotAsync() throws InterruptedException {
|
|
|
+ RestHighLevelClient client = highLevelClient();
|
|
|
+ {
|
|
|
+ DeleteSnapshotRequest request = new DeleteSnapshotRequest();
|
|
|
+
|
|
|
+ // tag::delete-snapshot-execute-listener
|
|
|
+ ActionListener<DeleteSnapshotResponse> listener =
|
|
|
+ new ActionListener<DeleteSnapshotResponse>() {
|
|
|
+ @Override
|
|
|
+ public void onResponse(DeleteSnapshotResponse deleteSnapshotResponse) {
|
|
|
+ // <1>
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onFailure(Exception e) {
|
|
|
+ // <2>
|
|
|
+ }
|
|
|
+ };
|
|
|
+ // end::delete-snapshot-execute-listener
|
|
|
+
|
|
|
+ // Replace the empty listener by a blocking listener in test
|
|
|
+ final CountDownLatch latch = new CountDownLatch(1);
|
|
|
+ listener = new LatchedActionListener<>(listener, latch);
|
|
|
+
|
|
|
+ // tag::delete-snapshot-execute-async
|
|
|
+ client.snapshot().deleteAsync(request, RequestOptions.DEFAULT, listener); // <1>
|
|
|
+ // end::delete-snapshot-execute-async
|
|
|
+
|
|
|
+ assertTrue(latch.await(30L, TimeUnit.SECONDS));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private void createTestRepositories() throws IOException {
|
|
|
PutRepositoryRequest request = new PutRepositoryRequest(repositoryName);
|
|
|
request.type(FsRepository.TYPE);
|
|
|
request.settings("{\"location\": \".\"}", XContentType.JSON);
|
|
|
assertTrue(highLevelClient().snapshot().createRepository(request, RequestOptions.DEFAULT).isAcknowledged());
|
|
|
}
|
|
|
+
|
|
|
+ private void createTestSnapshots() throws IOException {
|
|
|
+ Request createSnapshot = new Request("put", String.format(Locale.ROOT, "_snapshot/%s/%s", repositoryName, snapshotName));
|
|
|
+ createSnapshot.addParameter("wait_for_completion", "true");
|
|
|
+ Response response = highLevelClient().getLowLevelClient().performRequest(createSnapshot);
|
|
|
+ // check that the request went ok without parsing JSON here. When using the high level client, check acknowledgement instead.
|
|
|
+ assertEquals(200, response.getStatusLine().getStatusCode());
|
|
|
+ }
|
|
|
}
|