-
Notifications
You must be signed in to change notification settings - Fork 24.8k
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
Add Create Snapshot to High-Level Rest Client #31215
Changes from all commits
92acd76
77cb270
346fb6a
13144c9
77fc66b
baa4d49
5ebf689
84b6e40
a1e50d5
2a7665c
9879a28
891b2a0
04b568e
c664596
5ea58ec
226339c
760ed40
7aaaf95
3122f47
0aaa589
ffbf58d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,7 @@ | |
import org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryRequest; | ||
import org.elasticsearch.action.admin.cluster.repositories.verify.VerifyRepositoryRequest; | ||
import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest; | ||
import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotRequest; | ||
import org.elasticsearch.action.admin.cluster.snapshots.delete.DeleteSnapshotRequest; | ||
import org.elasticsearch.action.admin.cluster.storedscripts.DeleteStoredScriptRequest; | ||
import org.elasticsearch.action.admin.cluster.storedscripts.GetStoredScriptRequest; | ||
|
@@ -1988,6 +1989,28 @@ public void testVerifyRepository() { | |
assertThat(expectedParams, equalTo(request.getParameters())); | ||
} | ||
|
||
public void testCreateSnapshot() throws IOException { | ||
Map<String, String> expectedParams = new HashMap<>(); | ||
String repository = randomIndicesNames(1, 1)[0]; | ||
String snapshot = "snapshot-" + generateRandomStringArray(1, randomInt(10), false, false)[0]; | ||
String endpoint = "/_snapshot/" + repository + "/" + snapshot; | ||
|
||
CreateSnapshotRequest createSnapshotRequest = new CreateSnapshotRequest(repository, snapshot); | ||
setRandomMasterTimeout(createSnapshotRequest, expectedParams); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can u also add a set to the withWaitForCompletion There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good call, added. |
||
Boolean waitForCompletion = randomBoolean(); | ||
createSnapshotRequest.waitForCompletion(waitForCompletion); | ||
|
||
if (waitForCompletion) { | ||
expectedParams.put("wait_for_completion", waitForCompletion.toString()); | ||
} | ||
|
||
Request request = RequestConverters.createSnapshot(createSnapshotRequest); | ||
assertThat(endpoint, equalTo(request.getEndpoint())); | ||
assertThat(HttpPut.METHOD_NAME, equalTo(request.getMethod())); | ||
assertThat(expectedParams, equalTo(request.getParameters())); | ||
assertToXContentBody(createSnapshotRequest, request.getEntity()); | ||
} | ||
|
||
public void testDeleteSnapshot() { | ||
Map<String, String> expectedParams = new HashMap<>(); | ||
String repository = randomIndicesNames(1, 1)[0]; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,10 @@ | |
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.create.CreateSnapshotRequest; | ||
import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse; | ||
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; | ||
import org.elasticsearch.action.support.IndicesOptions; | ||
import org.elasticsearch.action.admin.cluster.snapshots.delete.DeleteSnapshotRequest; | ||
import org.elasticsearch.action.admin.cluster.snapshots.delete.DeleteSnapshotResponse; | ||
import org.elasticsearch.client.ESRestHighLevelClientTestCase; | ||
|
@@ -41,6 +45,7 @@ | |
import org.elasticsearch.common.unit.TimeValue; | ||
import org.elasticsearch.common.xcontent.XContentType; | ||
import org.elasticsearch.repositories.fs.FsRepository; | ||
import org.elasticsearch.rest.RestStatus; | ||
|
||
import java.io.IOException; | ||
import java.util.HashMap; | ||
|
@@ -367,6 +372,90 @@ public void onFailure(Exception e) { | |
} | ||
} | ||
|
||
public void testSnapshotCreate() throws IOException { | ||
RestHighLevelClient client = highLevelClient(); | ||
|
||
CreateIndexRequest createIndexRequest = new CreateIndexRequest("test-index0"); | ||
client.indices().create(createIndexRequest, RequestOptions.DEFAULT); | ||
createIndexRequest = new CreateIndexRequest("test-index1"); | ||
client.indices().create(createIndexRequest, RequestOptions.DEFAULT); | ||
|
||
createTestRepositories(); | ||
|
||
// tag::create-snapshot-request | ||
CreateSnapshotRequest request = new CreateSnapshotRequest(); | ||
// end::create-snapshot-request | ||
|
||
// tag::create-snapshot-request-repositoryName | ||
request.repository(repositoryName); // <1> | ||
// end::create-snapshot-request-repositoryName | ||
// tag::create-snapshot-request-snapshotName | ||
request.snapshot(snapshotName); // <1> | ||
// end::create-snapshot-request-snapshotName | ||
// tag::create-snapshot-request-indices | ||
request.indices("test-index0", "test-index1"); // <1> | ||
// end::create-snapshot-request-indices | ||
// tag::create-snapshot-request-indicesOptions | ||
request.indicesOptions(IndicesOptions.fromOptions(false, false, true, true)); // <1> | ||
// end::create-snapshot-request-indicesOptions | ||
// tag::create-snapshot-request-partial | ||
request.partial(false); // <1> | ||
// end::create-snapshot-request-partial | ||
// tag::create-snapshot-request-includeGlobalState | ||
request.includeGlobalState(true); // <1> | ||
// end::create-snapshot-request-includeGlobalState | ||
|
||
// tag::create-snapshot-request-masterTimeout | ||
request.masterNodeTimeout(TimeValue.timeValueMinutes(1)); // <1> | ||
request.masterNodeTimeout("1m"); // <2> | ||
// end::create-snapshot-request-masterTimeout | ||
// tag::create-snapshot-request-waitForCompletion | ||
request.waitForCompletion(true); // <1> | ||
// end::create-snapshot-request-waitForCompletion | ||
|
||
// tag::create-snapshot-execute | ||
CreateSnapshotResponse response = client.snapshot().createSnapshot(request, RequestOptions.DEFAULT); | ||
// end::create-snapshot-execute | ||
|
||
// tag::create-snapshot-response | ||
RestStatus status = response.status(); // <1> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jdconrad can you please expand on what can be done with the response other than looking at the status? We also return the SnapshotInfo right? That seems like an interesting thing to document for users. |
||
// end::create-snapshot-response | ||
|
||
assertEquals(RestStatus.OK, status); | ||
} | ||
|
||
public void testSnapshotCreateAsync() throws InterruptedException { | ||
RestHighLevelClient client = highLevelClient(); | ||
{ | ||
CreateSnapshotRequest request = new CreateSnapshotRequest(repositoryName, snapshotName); | ||
|
||
// tag::create-snapshot-execute-listener | ||
ActionListener<CreateSnapshotResponse> listener = | ||
new ActionListener<CreateSnapshotResponse>() { | ||
@Override | ||
public void onResponse(CreateSnapshotResponse createSnapshotResponse) { | ||
// <1> | ||
} | ||
|
||
@Override | ||
public void onFailure(Exception exception) { | ||
// <2> | ||
} | ||
}; | ||
// end::create-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::create-snapshot-execute-async | ||
client.snapshot().createSnapshotAsync(request, RequestOptions.DEFAULT, listener); // <1> | ||
// end::create-snapshot-execute-async | ||
|
||
assertTrue(latch.await(30L, TimeUnit.SECONDS)); | ||
} | ||
} | ||
|
||
public void testSnapshotDeleteSnapshot() throws IOException { | ||
RestHighLevelClient client = highLevelClient(); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a few extra options i see in the transport layer. Lets make sure we account for all these params / optional things.
https://github.com/elastic/elasticsearch/blob/master/server/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/create/TransportCreateSnapshotAction.java#L76-L82
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of these should be covered as they end up as part of the content body including partial, indices, global_state, and settings.