-
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 all 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 |
---|---|---|
|
@@ -39,6 +39,7 @@ | |
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.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; | ||
|
@@ -2011,6 +2012,58 @@ public void testCreateSnapshot() throws IOException { | |
assertToXContentBody(createSnapshotRequest, request.getEntity()); | ||
} | ||
|
||
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); | ||
|
||
boolean ignoreUnavailable = randomBoolean(); | ||
getSnapshotsRequest.ignoreUnavailable(ignoreUnavailable); | ||
expectedParams.put("ignore_unavailable", Boolean.toString(ignoreUnavailable)); | ||
|
||
boolean verbose = randomBoolean(); | ||
getSnapshotsRequest.verbose(verbose); | ||
expectedParams.put("verbose", Boolean.toString(verbose)); | ||
|
||
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]; | ||
|
||
String endpoint = String.format(Locale.ROOT, "/_snapshot/%s/_all", repository); | ||
|
||
GetSnapshotsRequest getSnapshotsRequest = new GetSnapshotsRequest(repository); | ||
setRandomMasterTimeout(getSnapshotsRequest, expectedParams); | ||
|
||
boolean ignoreUnavailable = randomBoolean(); | ||
getSnapshotsRequest.ignoreUnavailable(ignoreUnavailable); | ||
expectedParams.put("ignore_unavailable", Boolean.toString(ignoreUnavailable)); | ||
|
||
boolean verbose = randomBoolean(); | ||
getSnapshotsRequest.verbose(verbose); | ||
expectedParams.put("verbose", Boolean.toString(verbose)); | ||
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. nit: it is slightly better to set a value only randomly, that way you also test that we do the right when the value is not set (this can be applied also to ignoreUnavailable above:
|
||
|
||
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.create.CreateSnapshotRequest; | ||
import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse; | ||
import org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsRequest; | ||
import org.elasticsearch.action.admin.cluster.snapshots.get.GetSnapshotsResponse; | ||
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; | ||
import org.elasticsearch.action.support.IndicesOptions; | ||
import org.elasticsearch.action.admin.cluster.snapshots.delete.DeleteSnapshotRequest; | ||
|
@@ -46,6 +48,7 @@ | |
import org.elasticsearch.common.xcontent.XContentType; | ||
import org.elasticsearch.repositories.fs.FsRepository; | ||
import org.elasticsearch.rest.RestStatus; | ||
import org.elasticsearch.snapshots.SnapshotInfo; | ||
|
||
import java.io.IOException; | ||
import java.util.HashMap; | ||
|
@@ -456,6 +459,76 @@ public void onFailure(Exception exception) { | |
} | ||
} | ||
|
||
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.
Why not
randomAlphaOfLength(5)
or something?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.
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 comment
The 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 comment
The 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.