-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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
Conversation
Pinging @elastic/es-distributed |
Pinging @elastic/es-core-infra |
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.
great work! i hope we can add some more tests to the new functionality. Small changes in the review.
@@ -816,6 +817,19 @@ static Request verifyRepository(VerifyRepositoryRequest verifyRepositoryRequest) | |||
return request; | |||
} | |||
|
|||
static Request createSnapshot(CreateSnapshotRequest createSnapshotRequest) 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.
There are a few extra options i see in the transport layer. Lets make sure we account for all these params / optional things.
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.
|
||
private CreateSnapshotResponse createTestSnapshot(String repository, String snapshot) throws IOException { | ||
// assumes the repository already exists | ||
CreateSnapshotRequest request = new CreateSnapshotRequest(repository, snapshot); |
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 we should add more of the options here, randomly with some if randomBoolean()
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.
Added several random booleans for options where it made sense.
@@ -407,6 +409,28 @@ public CreateSnapshotRequest source(Map<String, Object> source) { | |||
return this; | |||
} | |||
|
|||
@Override | |||
public XContentBuilder toXContent(XContentBuilder builder, Params params) 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.
is there any test for this?
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.
Added tests.
public static CreateSnapshotResponse fromXContent(XContentParser parser) throws IOException { | ||
CreateSnapshotResponse createSnapshotResponse = new CreateSnapshotResponse(); | ||
|
||
parser.nextToken(); // '{' |
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.
This seems like we should be using a nested parser here. Similar to how this works, https://github.com/elastic/elasticsearch/blob/master/server/src/main/java/org/elasticsearch/action/admin/cluster/repositories/verify/VerifyRepositoryResponse.java#L112-L116
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.
Misread the location of this. Let me see what I can do.
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.
After reviewing the structure of the content here, I do not believe it makes sense to add a new object parser in this case since it would end up being more obfuscated for no reason since with one of the fields it's an either or and the field doesn't need to actually be parsed (it's used for user-consumable output only). This would mean additional empty methods. It's better to call fromXContent directly on SnapshotInfo. I did, however, add several checks to ensure the proper tokens are being read.
|
||
@Override | ||
public int hashCode() { | ||
|
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.
remove empty line
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.
Intellij added this automatically.
@@ -79,6 +84,170 @@ | |||
private static final Comparator<SnapshotInfo> COMPARATOR = | |||
Comparator.comparing(SnapshotInfo::startTime).thenComparing(SnapshotInfo::snapshotId); | |||
|
|||
private static final class SnapshotInfoBuilder { |
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.
is it possible to test all this new stuff?
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.
This should get full coverage from the existing SnapshotResponseTests.
@@ -448,12 +609,20 @@ private XContentBuilder toXContentSnapshot(final XContentBuilder builder, final | |||
return builder; | |||
} | |||
|
|||
public static SnapshotInfo fromXContent(final XContentParser parser) throws IOException { | |||
parser.nextToken(); |
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 validate that these tokens are thee right start_object or whatever ?
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.
Done.
} | ||
|
||
|
||
public void testCreateSnapshotRepositoryAsync() throws InterruptedException { |
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: This should probably be called testCreateSnapshotAsync()
(without "repository" in the name)
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.
Agreed.
@hub-cap Thanks for the initial review! Ready for the next round. Added requested tests and parsing checks where applicable. Also given that some of the parsing code is legacy, I do not believe adding an extra object parser made sense in this case to CreateSnapshotResponse -- left more information under that comment. |
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.
one minor nit once added
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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Good call, added.
@baz - Thanks for the follow up! Will commit as soon as CI passes. |
* elastic/master: (57 commits) HLRest: Fix test for explain API [TEST] Fix RemoteClusterConnectionTests Add Create Snapshot to High-Level Rest Client (elastic#31215) Remove legacy MetaDataStateFormat (elastic#31603) Add explain API to high-level REST client (elastic#31387) Preserve thread context when connecting to remote cluster (elastic#31574) Unify headers for full text queries Remove redundant 'minimum_should_match' JDBC driver prepared statement set* methods (elastic#31494) [TEST] call yaml client close method from test suite (elastic#31591) ingest: Add ignore_missing property to foreach filter (elastic#22147) (elastic#31578) Fix a formatting issue in the docvalue_fields documentation. (elastic#31563) reduce log level at gradle configuration time [TEST] Close additional clients created while running yaml tests (elastic#31575) Docs: Clarify sensitive fields watcher encryption (elastic#31551) Watcher: Remove never executed code (elastic#31135) Add support for switching distribution for all integration tests (elastic#30874) Improve robustness of geo shape parser for malformed shapes (elastic#31449) QA: Create xpack yaml features (elastic#31403) Improve test times for tests using `RandomObjects::addFields` (elastic#31556) ...
@jdconrad Please ping when this is back ported. It will probably work best for me to back port mine (get snapshots) after this is back ported. |
// 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 comment
The 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.
@@ -45,6 +48,10 @@ | |||
CreateSnapshotResponse() { | |||
} | |||
|
|||
void setSnapshotInfo(SnapshotInfo snapshotInfo) { |
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 we use the existing constructor in the only place where this is called (test) and remove this new method?
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.
Done.
Edit: Actually, going to have a similar method and use an ObjectParser for CreateSnapshotResponse.
|
||
parser.nextToken(); // move past 'true'/'false' | ||
} else { | ||
throw new IllegalArgumentException("unexpected token [" + parser.currentToken() + "] expected ['snapshot', 'accepted']"); |
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.
parsing here is very strict. while strictness is generally a good thing, it hinders forward compatibility in this specific case when parsing back responses in the client. That's why parsing should also be tested with supportsUnknownFields
set to true
unless there are good reasons not to do so.
What if one day we add a new field to the response, which is a perfectly backwards compatible change? The client would break with such a response, while it should ignore the additional fields till the newer client is used, which will be able to read such new field.
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.
Switched to a lenient ObjectParser.
new ObjectParser<>(SnapshotInfoBuilder.class.getName(), SnapshotInfoBuilder::new); | ||
|
||
private static final ObjectParser<ShardStatsBuilder, Void> SHARD_STATS_PARSER = | ||
new ObjectParser<>(ShardStatsBuilder.class.getName(), ShardStatsBuilder::new); |
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.
these objects parser should be made to ignore unknown fields
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.
@tbrooks8 Thanks for doing this already!
* 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)
one more thing @jdconrad can you rename the methods to just |
@javanna Sure, do you mean the methods in RequestConverters or in some of the tests? |
Added support to the high-level rest client for the create snapshot API call. This required several changes to toXContent which may need to be cleaned up in a later PR. Also added several parsers for fromXContent to be able to retrieve appropriate responses along with tests.
@tbrooks8 My backports are in. Will follow up on @javanna comments soon in a new PR. |
@jdconrad the ones in SnapshotClient, the others could be adapted but are not really exposed to users, not as much the client methods. |
* 6.x: Do not check for object existence when deleting repository index files (#31680) Remove extra check for object existence in repository-gcs read object (#31661) [Test] Clean up some repository-s3 tests (#31601) Merge AzureStorageService and AzureStorageServiceImpl and clean up tests (#31607) [Docs] Use capital letters in section headings (#31678) [DOCS] Add PQL language Plugin (#31237) [DOCS] Fix licensing API details (#31667) Fix CreateSnapshotRequestTests Failure (#31630) Add Create Snapshot to High-Level Rest Client (#31215) Add MultiSearchTemplate support to High Level Rest client (#31662) SQL: Refactor package names of sql-proto and sql-shared-proto projects (#31622) [TEST] Mute failing NamingConventionsTaskIT tests [DOCS] Replace CONFIG_DIR with ES_PATH_CONF (#31635) Add test for low-level client round-robin behaviour (#31616) HLRest: Fix test for explain API Add explain API to high-level REST client (#31387)
Added support to the high-level rest client for the create snapshot API call. This required several changes to toXContent which may need to be cleaned up in a later PR. Also added several parsers for fromXContent to be able to retrieve appropriate responses along with tests.