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 Get Snapshots High Level REST API #31537

Merged
merged 20 commits into from
Jun 28, 2018

Conversation

Tim-Brooks
Copy link
Contributor

With this commit we add the get snapshots API to the Java high level
REST client.

Relates #27205

@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra


public void testGetAllSnapshots() {
Map<String, String> expectedParams = new HashMap<>();
String repository = randomIndicesNames(1, 1)[0];
Copy link
Member

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?

Copy link
Contributor Author

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?

Copy link
Member

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.

Copy link
Contributor

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

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

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

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

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.

Copy link
Member

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

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

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

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.

@Tim-Brooks
Copy link
Contributor Author

I've modified this based on @nik9000 comments. I had to modify the fromXcontent for SnapshotShardFailure as that was the class that did not support unknown fields .

Please verify that I used the object parsers properly. This is the first time I have used them.

Copy link
Member

@nik9000 nik9000 left a 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];
Copy link
Member

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

Choose a reason for hiding this comment

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

Why not fromXContent?

Copy link
Contributor Author

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.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks!

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.

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

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

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed

@Tim-Brooks Tim-Brooks requested a review from hub-cap June 27, 2018 20:38
@Tim-Brooks
Copy link
Contributor Author

Tim-Brooks commented Jun 27, 2018

@hub-cap I made those changes

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.

u sir, are awesome. :shipit:

@Tim-Brooks Tim-Brooks merged commit 9ac81a1 into elastic:master Jun 28, 2018
Tim-Brooks added a commit that referenced this pull request Jun 28, 2018
This is related to #31537. It fixes a missing docs references in
get_snapshots.asciidoc.
Tim-Brooks added a commit to Tim-Brooks/elasticsearch that referenced this pull request Jun 28, 2018
This is related to elastic#31537. It fixes two syntax errors that are breaking
the docs build.
hub-cap pushed a commit that referenced this pull request Jun 28, 2018
This is related to #31537. It fixes two syntax errors that are breaking
the docs build.
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)

boolean verbose = randomBoolean();
getSnapshotsRequest.verbose(verbose);
expectedParams.put("verbose", Boolean.toString(verbose));
Copy link
Member

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

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

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 ?

Copy link
Contributor Author

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.

Tim-Brooks added a commit to Tim-Brooks/elasticsearch that referenced this pull request Jul 2, 2018
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.
Tim-Brooks added a commit that referenced this pull request Jul 5, 2018
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.
Tim-Brooks added a commit to Tim-Brooks/elasticsearch that referenced this pull request Jul 11, 2018
With this commit we add the get snapshots API to the Java high level
REST client.

Relates elastic#27205
Tim-Brooks added a commit to Tim-Brooks/elasticsearch that referenced this pull request Jul 11, 2018
This is related to elastic#31537. It fixes a missing docs references in
get_snapshots.asciidoc.
Tim-Brooks added a commit to Tim-Brooks/elasticsearch that referenced this pull request Jul 11, 2018
This is related to elastic#31537. It fixes two syntax errors that are breaking
the docs build.
Tim-Brooks added a commit to Tim-Brooks/elasticsearch that referenced this pull request Jul 11, 2018
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.
@Tim-Brooks Tim-Brooks deleted the rest_get_snapshot branch December 10, 2018 16:21
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.

6 participants