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

HLRC: Create server agnostic request and response #32912

Merged
merged 11 commits into from
Aug 22, 2018

Conversation

hub-cap
Copy link
Contributor

@hub-cap hub-cap commented Aug 16, 2018

The HLRC has historically reused the same Request and Response classes
that the server module uses. This commit deprecates the use of any
server module Request and Response classes, and adds a small bit of
validation logic that differs from server slightly, in that it does not
assume a check for a null ValidationException class is not enough to
determine if validation failed.

The HLRC has historically reused the same Request and Response classes
that the server module uses. This commit deprecates the use of any
server module Request and Response classes, and adds a small bit of
validation logic that differs from server slightly, in that it does not
assume a check for a null ValidationException class is not enough to
determine if validation failed.
* layer has been added to the ReST client, and requests should extend
* {@link org.elasticsearch.protocol.xpack.common.ValidationException} instead of `ActionRequest`.
*/
@Deprecated
Copy link
Member

Choose a reason for hiding this comment

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

aren't we deprecating the way that all our current API are implemented?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sadly, yes, if we want to use new server agnostic classes, we have to stop using the old ActionRequest classes.

Copy link
Member

Choose a reason for hiding this comment

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

I agree with the direction, reusing classes is what got us far relatively quickly in the beginning, but as that becomes harder and harder, it makes little sense to continue doing so especially given that it gets us only to an intermediate result that still depends on server. I think as long as we don't deprecate methods that are already out, and we only deprecate what they use internally, this is ok. Do we also plan on rewriting the currently supported API with this approach sometimes soon?

/**
* @deprecated If creating a new HLRC ReST API call, consider creating new actions instead of reusing server actions. The Validation
* layer has been added to the ReST client, and requests should extend
* {@link org.elasticsearch.protocol.xpack.common.ValidationException} instead of `ActionRequest`.
Copy link
Member

Choose a reason for hiding this comment

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

the new recommended way requires using classes that sit under xpack packages?

Copy link
Contributor

Choose a reason for hiding this comment

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

@hub-cap seems that currently, we have only a protocol project for xpack request/responses, if we want rest client to be independent from server, we need to have protocol project for non-xpack classes or probably we can have both xpack and non-xpack classes under the same protocol project.

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 catch, i should be moving these to a non xpack, common place. Ill fix that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@andrershov this point makes me wonder if we should do away with protocol altogether once we fix the existing x-pack classes, and just put all of these request/responses directly in the HLRC. Thoughts cc @javanna ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

looking at this more, I think it probably makes sense to just move them now to HLRC so we can also put the new Validatable in HLRC too. this way its not only x-pack classes.

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 that anything that is not under xpack packages is fine, I don't mind whether that's a new oss library or within the high-level client directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For now Im going to move them into the same jar. If we find a need to put them into a new jar, we can always go that route. Id rather stick to simpler and then do it when we need it. Ive done this in d0ca91c

@hub-cap
Copy link
Contributor Author

hub-cap commented Aug 16, 2018

@elasticmachine test this please

/**
* @deprecated If creating a new HLRC ReST API call, consider creating new actions instead of reusing server actions. The Validation
* layer has been added to the ReST client, and requests should extend
* {@link org.elasticsearch.protocol.xpack.common.ValidationException} instead of `ActionRequest`.
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this link to ... Validatable not ... ValidationException. Same with the other comments

Copy link
Contributor Author

Choose a reason for hiding this comment

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

DOH!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed in d0ca91c

Copy link
Contributor

@andrershov andrershov left a comment

Choose a reason for hiding this comment

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

I've left one comment about naming, but overall looks good to me

/**
* Defines a validation layer for Requests.
*/
public interface Validatable {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure that Validatable is a good name for the base class of client requests. Probably we can name it ClientRequest, so that in the future if we decide that we need to add new methods to client request we would not need to rename it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yea but its not about it being a base request. its just the fact that the HLRC does some validation before sending it. Honestly, this is the only thing that ties it to any sort of class hierarchy. Like the response, which has no class hierarchy.

@hub-cap
Copy link
Contributor Author

hub-cap commented Aug 17, 2018

In a subsequent PR I will be moving Validat* back in to protocol, but the plan is to move protocol under the hlrc, rather than in x-pack.

@hub-cap
Copy link
Contributor Author

hub-cap commented Aug 20, 2018

ok, WRT the Valid* I think the plan is to remove protocol altogether and just put everything in hlrc. It will be in a subsequent PR.

Copy link
Member

@jasontedor jasontedor left a comment

Choose a reason for hiding this comment

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

I left a question.

* {@link ValidationException} that contains a list of all failed validation.
*/
default ValidationException validate() {
return new ValidationException();
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure about creating a new instance on every invocation of validate. Can we share an empty instance and expect overriding implementations to create an instance if needed?

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

pls note I had to remove final in order to facilitate overriding
in the ifc and allowing me to not add anything to the list of msgs
Copy link
Member

@jasontedor jasontedor left a comment

Choose a reason for hiding this comment

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

I left another comment.

public interface Validatable {
ValidationException EMPTY_VALIDATION = new ValidationException() {
@Override
public void addValidationError(String error) { }
Copy link
Member

Choose a reason for hiding this comment

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

That’s dangerous! Maybe throw unsupported?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

duh, what a rookie mistake :)

fixed in 8fac65d

Copy link
Member

@jasontedor jasontedor left a comment

Choose a reason for hiding this comment

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

I left one more comment. Please address one way or the other before merging, but no need for another round.

@@ -949,6 +949,11 @@ public final void fieldCapsAsync(FieldCapabilitiesRequest fieldCapabilitiesReque
FieldCapabilitiesResponse::fromXContent, listener, emptySet());
}

/**
* @deprecated If creating a new HLRC ReST API call, consider creating new actions instead of reusing server actions. The Validation
* layer has been added to the ReST client, and requests should extend {@link Validatable} instead of `ActionRequest`.
Copy link
Member

Choose a reason for hiding this comment

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

Why backticks in the Javadoc instead of using {@link} or {@code}? I would tend to the user former here, it will resolve as long as ActionRequest is on the class `path and then when we reach that glorious day when it isn't, our Javadocs will fail to build and we will know it's time to remove this Javadoc!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

rgr, will fix and then merge, ty for the review.


/**
* @deprecated If creating a new HLRC ReST API call, consider creating new actions instead of reusing server actions. The Validation
* layer has been added to the ReST client, and requests should extend {@link Validatable} instead of `ActionRequest`.
Copy link
Member

Choose a reason for hiding this comment

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

See my comment about the backticks.

@hub-cap hub-cap merged commit e991208 into elastic:master Aug 22, 2018
hub-cap added a commit that referenced this pull request Aug 27, 2018
The HLRC has historically reused the same Request and Response classes
that the server module uses. This commit deprecates the use of any
server module Request and Response classes, and adds a small bit of
validation logic that differs from server slightly, in that it does not
assume a check for a null ValidationException class is not enough to
determine if validation failed.
jasontedor added a commit that referenced this pull request Aug 27, 2018
* 6.x:
  Introduce mapping version to index metadata (#33147)
  Move non duplicated actions back into xpack core (#32952)
  HLRC: Create server agnostic request and response (#32912)
  Build: forked compiler max memory matches jvmArgs (#33138)
  * Added breaking change section for GROUP BY behavior: now it considers null or empty values as a separate group/bucket. Previously, they were ignored. * This is part of backporting of #32832
  SQL: Enable aggregations to create a separate bucket for missing values (#32832)
  [TEST] version guard for reload rest-api-spec
  Fix grammar in contributing docs
  APM server monitoring (#32515)
  Support only string `format` in date, root object & date range (#28117)
  [Rollup] Move toBuilders() methods out of rollup config objects (#32585)
  Accept Gradle build scan agreement (#30645)
  Fix forbiddenapis on java 11  (#33116)
  Run forbidden api checks with runtimeJavaVersion (#32947)
  Apply publishing to genreate pom (#33094)
  Fix a mappings update test (#33146)
  Reload Secure Settings REST specs & docs (#32990)
  Refactor CachingUsernamePassword realm (#32646)
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