Skip to content

Commit a5f5ea8

Browse files
authored
Get snapshot rest client cleanups (#31740)
This is a followup to #31537. It makes a number of changes requested by a review that came after the PR was merged. These are mostly cleanups and doc improvements.
1 parent c0b2ef5 commit a5f5ea8

File tree

4 files changed

+35
-12
lines changed

4 files changed

+35
-12
lines changed

client/rest-high-level/src/test/java/org/elasticsearch/client/RequestConvertersTests.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2122,13 +2122,21 @@ public void testGetSnapshots() {
21222122
getSnapshotsRequest.snapshots(Arrays.asList(snapshot1, snapshot2).toArray(new String[0]));
21232123
setRandomMasterTimeout(getSnapshotsRequest, expectedParams);
21242124

2125-
boolean ignoreUnavailable = randomBoolean();
2126-
getSnapshotsRequest.ignoreUnavailable(ignoreUnavailable);
2127-
expectedParams.put("ignore_unavailable", Boolean.toString(ignoreUnavailable));
2125+
if (randomBoolean()) {
2126+
boolean ignoreUnavailable = randomBoolean();
2127+
getSnapshotsRequest.ignoreUnavailable(ignoreUnavailable);
2128+
expectedParams.put("ignore_unavailable", Boolean.toString(ignoreUnavailable));
2129+
} else {
2130+
expectedParams.put("ignore_unavailable", Boolean.FALSE.toString());
2131+
}
21282132

2129-
boolean verbose = randomBoolean();
2130-
getSnapshotsRequest.verbose(verbose);
2131-
expectedParams.put("verbose", Boolean.toString(verbose));
2133+
if (randomBoolean()) {
2134+
boolean verbose = randomBoolean();
2135+
getSnapshotsRequest.verbose(verbose);
2136+
expectedParams.put("verbose", Boolean.toString(verbose));
2137+
} else {
2138+
expectedParams.put("verbose", Boolean.TRUE.toString());
2139+
}
21322140

21332141
Request request = RequestConverters.getSnapshots(getSnapshotsRequest);
21342142
assertThat(endpoint, equalTo(request.getEndpoint()));

client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/SnapshotClientDocumentationIT.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@
4848
import org.elasticsearch.common.xcontent.XContentType;
4949
import org.elasticsearch.repositories.fs.FsRepository;
5050
import org.elasticsearch.rest.RestStatus;
51+
import org.elasticsearch.snapshots.SnapshotId;
5152
import org.elasticsearch.snapshots.SnapshotInfo;
53+
import org.elasticsearch.snapshots.SnapshotShardFailure;
54+
import org.elasticsearch.snapshots.SnapshotState;
5255

5356
import java.io.IOException;
5457
import java.util.HashMap;
@@ -496,7 +499,14 @@ public void testSnapshotGetSnapshots() throws IOException {
496499
// end::get-snapshots-execute
497500

498501
// tag::get-snapshots-response
499-
List<SnapshotInfo> snapshotsInfos = response.getSnapshots(); // <1>
502+
List<SnapshotInfo> snapshotsInfos = response.getSnapshots();
503+
SnapshotInfo snapshotInfo = snapshotsInfos.get(0);
504+
RestStatus restStatus = snapshotInfo.status(); // <1>
505+
SnapshotId snapshotId = snapshotInfo.snapshotId(); // <2>
506+
SnapshotState snapshotState = snapshotInfo.state(); // <3>
507+
List<SnapshotShardFailure> snapshotShardFailures = snapshotInfo.shardFailures(); // <4>
508+
long startTime = snapshotInfo.startTime(); // <5>
509+
long endTime = snapshotInfo.endTime(); // <6>
500510
// end::get-snapshots-response
501511
assertEquals(1, snapshotsInfos.size());
502512
}

docs/java-rest/high-level/snapshot/get_snapshots.asciidoc

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,16 @@ argument.
9393
[[java-rest-high-snapshot-get-snapshots-response]]
9494
==== Get Snapshots Response
9595

96-
Use the `GetSnapshotsResponse` to retrieve information about the evaluated
97-
request:
96+
The returned `GetSnapshotsResponse` allows the retrieval of information about the requested
97+
snapshots:
9898

9999
["source","java",subs="attributes,callouts,macros"]
100100
--------------------------------------------------
101101
include-tagged::{doc-tests}/SnapshotClientDocumentationIT.java[get-snapshots-response]
102102
--------------------------------------------------
103-
<1> Indicates the node has started the request.
103+
<1> The REST status of a snapshot
104+
<2> The snapshot id
105+
<3> The current state of the snapshot
106+
<4> Information about failures that occurred during the shard snapshot process.
107+
<5> The snapshot start time
108+
<6> The snapshot end time

server/src/main/java/org/elasticsearch/snapshots/SnapshotShardFailure.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,9 @@ public String reason() {
112112
}
113113

114114
/**
115-
* Returns REST status corresponding to this failure
115+
* Returns {@link RestStatus} corresponding to this failure
116116
*
117-
* @return REST STATUS
117+
* @return REST status
118118
*/
119119
@Override
120120
public RestStatus status() {

0 commit comments

Comments
 (0)