Skip to content
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

Merged
merged 21 commits into from
Jun 27, 2018

Conversation

jdconrad
Copy link
Contributor

@jdconrad jdconrad commented Jun 8, 2018

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.

@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-distributed

@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra

@hub-cap hub-cap added >enhancement and removed :Distributed/Snapshot/Restore Anything directly related to the `_snapshot/*` APIs labels Jun 8, 2018
Copy link
Contributor

@hub-cap hub-cap left a 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 {
Copy link
Contributor

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.

https://github.com/elastic/elasticsearch/blob/master/server/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/create/TransportCreateSnapshotAction.java#L76-L82

Copy link
Contributor Author

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);
Copy link
Contributor

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()

Copy link
Contributor Author

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 {
Copy link
Contributor

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?

Copy link
Contributor Author

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(); // '{'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

@jdconrad jdconrad Jun 26, 2018

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.

Copy link
Contributor Author

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() {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove empty line

Copy link
Contributor Author

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 {
Copy link
Contributor

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?

Copy link
Contributor Author

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();
Copy link
Contributor

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 ?

Copy link
Contributor Author

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 {
Copy link
Member

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed.

@jdconrad
Copy link
Contributor Author

@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.

@jdconrad jdconrad removed the request for review from javanna June 26, 2018 23:42
Copy link
Contributor

@hub-cap hub-cap left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one minor nit :shipit: once added

String endpoint = "/_snapshot/" + repository + "/" + snapshot;

CreateSnapshotRequest createSnapshotRequest = new CreateSnapshotRequest(repository, snapshot);
setRandomMasterTimeout(createSnapshotRequest, expectedParams);
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, added.

@jdconrad
Copy link
Contributor Author

@baz - Thanks for the follow up! Will commit as soon as CI passes.

@jdconrad jdconrad merged commit 61eefc8 into elastic:master Jun 27, 2018
jasontedor added a commit to majormoses/elasticsearch that referenced this pull request Jun 27, 2018
* 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)
  ...
@Tim-Brooks
Copy link
Contributor

@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>
Copy link
Member

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) {
Copy link
Member

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?

Copy link
Contributor Author

@jdconrad jdconrad Jul 3, 2018

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']");
Copy link
Member

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.

Copy link
Contributor Author

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);
Copy link
Member

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

Copy link
Contributor Author

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!

dnhatn added a commit that referenced this pull request Jun 28, 2018
* 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)
@jdconrad
Copy link
Contributor Author

@tbrooks8 Will let you know. I need to fix some tests before I can backport this specific change (#31630)
@javanna Will follow up. Thanks for the review!

@javanna
Copy link
Member

javanna commented Jun 28, 2018

one more thing @jdconrad can you rename the methods to just create. That's how it is defined in our REST spec.

@jdconrad
Copy link
Contributor Author

@javanna Sure, do you mean the methods in RequestConverters or in some of the tests?

jdconrad added a commit that referenced this pull request Jun 28, 2018
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.
@jdconrad
Copy link
Contributor Author

jdconrad commented Jun 28, 2018

@tbrooks8 My backports are in. Will follow up on @javanna comments soon in a new PR.

@javanna
Copy link
Member

javanna commented Jun 28, 2018

@jdconrad the ones in SnapshotClient, the others could be adapted but are not really exposed to users, not as much the client methods.

dnhatn added a commit that referenced this pull request Jun 29, 2018
* 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants