-
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
Conversation
Pinging @elastic/es-core-infra |
|
||
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 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.
getSnapshotsRequest.ignoreUnavailable(true); | ||
expectedParams.put("ignore_unavailable", Boolean.TRUE.toString()); | ||
} | ||
if (randomBoolean() == false) { |
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.
I don't know that == false
is worth it here.
if (randomBoolean()) { | ||
request = new GetSnapshotsRequest(repository); | ||
} else if (randomBoolean()) { | ||
request = new GetSnapshotsRequest(repository, Collections.singletonList("_all").toArray(new String[0])); |
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 new String[] {"_all"}
?
request = new GetSnapshotsRequest(repository, Collections.singletonList("_all").toArray(new String[0])); | ||
|
||
} else { | ||
request = new GetSnapshotsRequest(repository, Arrays.asList(snapshot1, snapshot2).toArray(new String[0])); |
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 new String[] {snapshot1, snapshot2}
?
@@ -0,0 +1,103 @@ | |||
[[java-rest-high-snapshot-get-snapshots]] | |||
=== Get Snapshots API |
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.
I believe you have to add this to supported-apis.asciidoc.
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.
Twice, actually.
String currentFieldName = parser.currentName(); | ||
token = parser.nextToken(); | ||
if (token.isValue()) { | ||
if (SNAPSHOT.equals(currentFieldName)) { |
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.
I think this one is a fine candidate for ObjectParser
.
successfulShards, | ||
shardFailures, | ||
includeGlobalState); | ||
indices, |
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.
Either format is fine with me. It looks like you aren't actually changing the list, though, right? In that case I'd probably not change the format.
|
||
@Override | ||
protected boolean supportsUnknownFields() { | ||
return false; |
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.
I think it ought to support unknown fields, right? I think that is what we want from the client.
I've modified this based on @nik9000 comments. I had to modify the Please verify that I used the object parsers properly. This is the first time I have used them. |
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.
Left two minor things, otherwise LGTM.
|
||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Weird. When in Rome, I guess.
@@ -453,7 +518,7 @@ private XContentBuilder toXContentSnapshot(final XContentBuilder builder, final | |||
* handle x-content written with the external version as external x-content | |||
* is only for display purposes and does not need to be parsed. | |||
*/ | |||
public static SnapshotInfo fromXContent(final XContentParser parser) throws IOException { | |||
public static SnapshotInfo fromXContentSnapshot(final XContentParser parser) throws IOException { |
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 fromXContent
?
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.
it is fromXContent
.
public static SnapshotInfo fromXContent(final XContentParser parser) throws IOException {
return SNAPSHOT_INFO_PARSER.parse(parser, null);
}
You're looking at the method that deserializes the internal SnapshotInfo x-content. I had to add a different method that deserializes the external x-content. And I renamed the existing method to match the name of the method that serializes the internal x-content. Based on your comment, I added a comment to ensure that is clear.
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.
Thanks!
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.
im only requesting changes to get a question answered. Ill gladly remove my -1 once the question about object parsers is answered.
if (randomBoolean()) { | ||
getSnapshotsRequest.verbose(false); | ||
expectedParams.put("verbose", Boolean.FALSE.toString()); | ||
} |
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 using Boolean.valueOf
? Not super necessary, just a nit.
@@ -87,4 +91,40 @@ public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params par | |||
return builder; | |||
} | |||
|
|||
public static GetSnapshotsResponse fromXContent(XContentParser parser) throws IOException { |
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.
any reason that an object parser was not used here?
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.
Changed
@hub-cap I made those changes |
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.
u sir, are awesome.
This is related to #31537. It fixes a missing docs references in get_snapshots.asciidoc.
This is related to elastic#31537. It fixes two syntax errors that are breaking the docs build.
This is related to #31537. It fixes two syntax errors that are breaking the docs build.
* master: Docs: Remove duplicate test setup Print output when the name checker IT fails (#31660) Fix syntax errors in get-snapshots docs (#31656) Docs: Fix description of percentile ranks example example (#31652) Add MultiSearchTemplate support to High Level Rest client (#30836) Add test for low-level client round-robin behaviour (#31616) SQL: Refactor package names of sql-proto and sql-shared-proto projects (#31622) Remove deprecation warnings to prepare for Gradle 5 (sourceSets.main.output.classesDirs) (#30389) Correct integTest enable logic (#31646) Fix missing get-snapshots docs reference #31645 Do not check for Azure container existence (#31617) Merge AwsS3Service and InternalAwsS3Service in a S3Service class (#31580) Upgrade gradle wrapper to 4.8 (#31525) Only set vm.max_map_count if greater than default (#31512) Add Get Snapshots High Level REST API (#31537) QA: Merge query-builder-bwc to restart test (#30979) Update reindex.asciidoc (#31626) Docs: Skip xpack snippet tests if no xpack (#31619) mute CreateSnapshotRequestTests HLRest: Fix test for explain API [TEST] Fix RemoteClusterConnectionTests Add Create Snapshot to High-Level Rest Client (#31215) Remove legacy MetaDataStateFormat (#31603) Add explain API to high-level REST client (#31387) Preserve thread context when connecting to remote cluster (#31574) Unify headers for full text queries Remove redundant 'minimum_should_match' JDBC driver prepared statement set* methods (#31494) [TEST] call yaml client close method from test suite (#31591)
|
||
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 comment
The 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:
if (randomBoolean()) {
boolean verbose = randomBoolean();
getSnapshotsRequest.verbose(verbose);
expectedParams.put("verbose", Boolean.toString(verbose));
}
// 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 comment
The reason will be displayed to describe this comment to others. Learn more.
can you expand on what can be retrieved from the SnapshotInfo?
@@ -100,7 +114,7 @@ public String reason() { | |||
/** | |||
* Returns REST status corresponding to this failure | |||
* | |||
* @return REST status | |||
* @return REST STATUS |
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.
was this necessary maybe you rather want to link to RestStatus ?
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.
No I think that was just an issue with a cherry-pick merge.
This is a followup to elastic#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.
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.
With this commit we add the get snapshots API to the Java high level REST client. Relates elastic#27205
This is related to elastic#31537. It fixes a missing docs references in get_snapshots.asciidoc.
This is related to elastic#31537. It fixes two syntax errors that are breaking the docs build.
This is a followup to elastic#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.
With this commit we add the get snapshots API to the Java high level
REST client.
Relates #27205