Skip to content

Conversation

@nik9000
Copy link
Member

@nik9000 nik9000 commented Dec 10, 2016

Moves the last of the "easy" parser construction into
RestRequest, this time with a new method
RestRequest#contentParser. The rest of the production
code that builds XContentParser isn't "easy" because it is
exposed in the Transport Client API (a Builder) object.

Moves the last of the "easy" parser construction into
`RestRequest`, this time with a new method
`RestRequest#contentParser`. The rest of the production
code that builds `XContentParser` isn't "easy" because it is
exposed in the Transport Client API (a Builder) object.
} else if ("_source".equals(currentFieldName)) {
fetchSourceContext = FetchSourceContext.parse(parser);
XContentParser.Token token = parser.nextToken();
if (token == null) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Just indentation changed.

@nik9000
Copy link
Member Author

nik9000 commented Dec 10, 2016

@rjernst, this is another prerequisite to #22003. This one should be more obviously in line with the objective of #22003 than the last one.

My plan for the not "easy" XContentParser constructions is to do them in the API with an empty NamedXContentRegistry for 5.x and remove them in 6.0.

restoreSnapshotRequest.masterNodeTimeout(request.paramAsTime("master_timeout", restoreSnapshotRequest.masterNodeTimeout()));
restoreSnapshotRequest.waitForCompletion(request.paramAsBoolean("wait_for_completion", false));
restoreSnapshotRequest.source(request.content().utf8ToString());
if (request.hasContent()) {
Copy link
Member

Choose a reason for hiding this comment

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

maybe for usages like this one we can add a helper method on RestRequest? Like this one:

public final void applySource(Consumer<Map<String, Object>> target) throws IOException {
    if (hasContent()) {
        try (XContentParser parser = contentParser()) {
            target.accept(parser.mapOrdered());
        }
   }
}

Then this snippet can be replaced with:

request.applySource(restoreSnapshotRequest::source);

and we could have a similar helper that passes a XContentParser to an action request?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure! I'll make that change.

@nik9000
Copy link
Member Author

nik9000 commented Dec 13, 2016

@martijnvg I made the change you asked for.

Copy link
Contributor

@imotov imotov left a comment

Choose a reason for hiding this comment

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

Left a couple of comments.

return this;
}

/**
Copy link
Contributor

Choose a reason for hiding this comment

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

This is user-facing interface and removing this calls might break applications that are using transport client to create repositories. So, I think we need to start with marking this as deprecated before removing it completely. Same in other requests.

Copy link
Member Author

Choose a reason for hiding this comment

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

I thought only our builder classes were user facing? I specifically only did this to the classes that didn't pipe these through to the builders.

Copy link
Contributor

Choose a reason for hiding this comment

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

I am not totally sure about this one. I think it depends on user preferences at the moment. The transport client can be used with builders or without. All our examples are showing client.prepareBlah(...) version, but the non-builder version client.blah(...) is readily accessible to anyone who is using client and I don't remember us ever mentioning that it's internal and shouldn't be used in apps.

Copy link
Member

Choose a reason for hiding this comment

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

they are both user facing like Igor said, but not sure we have been keeping bw comp on the java api between minor versions. I think it's ok to make these changes as long as we mark breaking-java and we document what the replacement is. We generally deprecate stuff that has to do with the REST layer. I think.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've marked this as breaking-java and I'll leave a note in https://github.com/elastic/elasticsearch/blob/5.x/docs/reference/migration/migrate_5_2.asciidoc when I merge to the 5.x branch. I think that is in line with what we've done with the transport API in the past.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good.

package org.elasticsearch.rest.action.admin.indices;

import org.elasticsearch.action.admin.indices.rollover.RolloverRequest;
import org.elasticsearch.action.admin.indices.shrink.ShrinkRequest;
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpicking - unused imports were added to this and other IndexActions.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, sorry about that one.

Copy link
Contributor

@imotov imotov left a comment

Choose a reason for hiding this comment

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

LGTM

@nik9000 nik9000 merged commit 749039a into elastic:master Dec 14, 2016
@nik9000
Copy link
Member Author

nik9000 commented Dec 14, 2016

Thanks for all the reviews!

master: 749039a
5.x: a654803 + (breaking changes docs: 4f8d0a5)

nik9000 added a commit that referenced this pull request Dec 14, 2016
Moves the last of the "easy" parser construction into
`RestRequest`, this time with a new method
`RestRequest#contentParser`. The rest of the production
code that builds `XContentParser` isn't "easy" because it is
exposed in the Transport Client API (a Builder) object.
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.

5 participants