-
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 Get Snapshots High Level REST API #31537
Changes from 14 commits
0f8f9c4
70f79da
95fde3d
093a684
df63a24
2915a38
50a26e1
d385f5c
45f54e7
3d8c689
9875290
2f16ff0
1479487
429f9ac
5c61d10
8e20773
0058c83
8cb968b
4a63364
0edd796
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 |
---|---|---|
|
@@ -38,6 +38,7 @@ | |
import org.elasticsearch.action.admin.cluster.repositories.verify.VerifyRepositoryRequest; | ||
import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest; | ||
import org.elasticsearch.action.admin.cluster.snapshots.delete.DeleteSnapshotRequest; | ||
import org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest; | ||
import org.elasticsearch.action.admin.cluster.storedscripts.DeleteStoredScriptRequest; | ||
import org.elasticsearch.action.admin.cluster.storedscripts.GetStoredScriptRequest; | ||
import org.elasticsearch.action.admin.indices.alias.Alias; | ||
|
@@ -1943,6 +1944,58 @@ public void testVerifyRepository() { | |
assertThat(expectedParams, equalTo(request.getParameters())); | ||
} | ||
|
||
public void testGetSnapshots() { | ||
Map<String, String> expectedParams = new HashMap<>(); | ||
String repository = randomIndicesNames(1, 1)[0]; | ||
String snapshot1 = "snapshot1-" + randomAlphaOfLengthBetween(2, 5).toLowerCase(Locale.ROOT); | ||
String snapshot2 = "snapshot2-" + randomAlphaOfLengthBetween(2, 5).toLowerCase(Locale.ROOT); | ||
|
||
String endpoint = String.format(Locale.ROOT, "/_snapshot/%s/%s,%s", repository, snapshot1, snapshot2); | ||
|
||
GetSnapshotsRequest getSnapshotsRequest = new GetSnapshotsRequest(); | ||
getSnapshotsRequest.repository(repository); | ||
getSnapshotsRequest.snapshots(Arrays.asList(snapshot1, snapshot2).toArray(new String[0])); | ||
setRandomMasterTimeout(getSnapshotsRequest, expectedParams); | ||
if (randomBoolean()) { | ||
getSnapshotsRequest.ignoreUnavailable(true); | ||
expectedParams.put("ignore_unavailable", Boolean.TRUE.toString()); | ||
} | ||
if (randomBoolean()) { | ||
getSnapshotsRequest.verbose(false); | ||
expectedParams.put("verbose", Boolean.FALSE.toString()); | ||
} | ||
|
||
Request request = RequestConverters.getSnapshots(getSnapshotsRequest); | ||
assertThat(endpoint, equalTo(request.getEndpoint())); | ||
assertThat(HttpGet.METHOD_NAME, equalTo(request.getMethod())); | ||
assertThat(expectedParams, equalTo(request.getParameters())); | ||
assertNull(request.getEntity()); | ||
} | ||
|
||
public void testGetAllSnapshots() { | ||
Map<String, String> expectedParams = new HashMap<>(); | ||
String repository = randomIndicesNames(1, 1)[0]; | ||
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. Why not 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. That is just how all tests in the class does it? It labels it as an index in the name. Maybe for debugging? 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. Weird. When in Rome, I guess. 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. Its cuz when i did it, i had no idea that other thing existed. Would be a nice fixup PR after all these Snapshots related PRs got finished. |
||
|
||
String endpoint = String.format(Locale.ROOT, "/_snapshot/%s/_all", repository); | ||
|
||
GetSnapshotsRequest getSnapshotsRequest = new GetSnapshotsRequest(repository); | ||
setRandomMasterTimeout(getSnapshotsRequest, expectedParams); | ||
if (randomBoolean()) { | ||
getSnapshotsRequest.ignoreUnavailable(true); | ||
expectedParams.put("ignore_unavailable", Boolean.TRUE.toString()); | ||
} | ||
if (randomBoolean()) { | ||
getSnapshotsRequest.verbose(false); | ||
expectedParams.put("verbose", Boolean.FALSE.toString()); | ||
} | ||
|
||
Request request = RequestConverters.getSnapshots(getSnapshotsRequest); | ||
assertThat(endpoint, equalTo(request.getEndpoint())); | ||
assertThat(HttpGet.METHOD_NAME, equalTo(request.getMethod())); | ||
assertThat(expectedParams, equalTo(request.getParameters())); | ||
assertNull(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 |
---|---|---|
|
@@ -31,6 +31,8 @@ | |
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.action.admin.cluster.snapshots.get.GetSnapshotsRequest; | ||
import org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse; | ||
import org.elasticsearch.client.ESRestHighLevelClientTestCase; | ||
import org.elasticsearch.client.Request; | ||
import org.elasticsearch.client.RequestOptions; | ||
|
@@ -41,6 +43,7 @@ | |
import org.elasticsearch.common.unit.TimeValue; | ||
import org.elasticsearch.common.xcontent.XContentType; | ||
import org.elasticsearch.repositories.fs.FsRepository; | ||
import org.elasticsearch.snapshots.SnapshotInfo; | ||
|
||
import java.io.IOException; | ||
import java.util.HashMap; | ||
|
@@ -367,6 +370,76 @@ public void onFailure(Exception e) { | |
} | ||
} | ||
|
||
public void testSnapshotGetSnapshots() throws IOException { | ||
RestHighLevelClient client = highLevelClient(); | ||
|
||
createTestRepositories(); | ||
createTestSnapshots(); | ||
|
||
// tag::get-snapshots-request | ||
GetSnapshotsRequest request = new GetSnapshotsRequest(repositoryName); | ||
// end::get-snapshots-request | ||
|
||
// tag::get-snapshots-request-snapshots | ||
String[] snapshots = { snapshotName }; | ||
request.snapshots(snapshots); // <1> | ||
// end::get-snapshots-request-snapshots | ||
|
||
// tag::get-snapshots-request-masterTimeout | ||
request.masterNodeTimeout(TimeValue.timeValueMinutes(1)); // <1> | ||
request.masterNodeTimeout("1m"); // <2> | ||
// end::get-snapshots-request-masterTimeout | ||
|
||
// tag::get-snapshots-request-verbose | ||
request.verbose(true); // <1> | ||
// end::get-snapshots-request-verbose | ||
|
||
// tag::get-snapshots-request-ignore-unavailable | ||
request.ignoreUnavailable(false); // <1> | ||
// end::get-snapshots-request-ignore-unavailable | ||
|
||
// tag::get-snapshots-execute | ||
GetSnapshotsResponse response = client.snapshot().get(request, RequestOptions.DEFAULT); | ||
// end::get-snapshots-execute | ||
|
||
// tag::get-snapshots-response | ||
List<SnapshotInfo> snapshotsInfos = response.getSnapshots(); // <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. can you expand on what can be retrieved from the SnapshotInfo? |
||
// end::get-snapshots-response | ||
assertEquals(1, snapshotsInfos.size()); | ||
} | ||
|
||
public void testSnapshotGetSnapshotsAsync() throws InterruptedException { | ||
RestHighLevelClient client = highLevelClient(); | ||
{ | ||
GetSnapshotsRequest request = new GetSnapshotsRequest(); | ||
|
||
// tag::get-snapshots-execute-listener | ||
ActionListener<GetSnapshotsResponse> listener = | ||
new ActionListener<GetSnapshotsResponse>() { | ||
@Override | ||
public void onResponse(GetSnapshotsResponse deleteSnapshotResponse) { | ||
// <1> | ||
} | ||
|
||
@Override | ||
public void onFailure(Exception e) { | ||
// <2> | ||
} | ||
}; | ||
// end::get-snapshots-execute-listener | ||
|
||
// Replace the empty listener by a blocking listener in test | ||
final CountDownLatch latch = new CountDownLatch(1); | ||
listener = new LatchedActionListener<>(listener, latch); | ||
|
||
// tag::get-snapshots-execute-async | ||
client.snapshot().getAsync(request, RequestOptions.DEFAULT, listener); // <1> | ||
// end::get-snapshots-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.
maybe just simplify these by setting it to the value of the
randomBoolean()
and usingBoolean.valueOf
? Not super necessary, just a nit.