-
Notifications
You must be signed in to change notification settings - Fork 25.2k
HLRC: Create server agnostic request and response #32912
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
d5353cb
HLRC: Create server agnostic request and response
hub-cap d0ca91c
Move into hlrc and fix comment
hub-cap c23fdb5
Merge remote-tracking branch 'upstream/master' into hlrc_new_req
hub-cap c44fb3f
Merge remote-tracking branch 'upstream/master' into hlrc_new_req
hub-cap ea52a83
Merge remote-tracking branch 'upstream/master' into hlrc_new_req
hub-cap 110854d
Merge remote-tracking branch 'upstream/master' into hlrc_new_req
hub-cap 2582d02
Merge remote-tracking branch 'upstream/master' into hlrc_new_req
hub-cap 89cce56
Empty validation exception
hub-cap 8fac65d
throw if method is called
hub-cap 33c28bb
Fix javadoc link
hub-cap 0a26cdf
Merge remote-tracking branch 'upstream/master' into hlrc_new_req
hub-cap File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
client/rest-high-level/src/main/java/org/elasticsearch/client/Validatable.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.elasticsearch.client; | ||
|
||
/** | ||
* Defines a validation layer for Requests. | ||
*/ | ||
public interface Validatable { | ||
ValidationException EMPTY_VALIDATION = new ValidationException() { | ||
@Override | ||
public void addValidationError(String error) { | ||
throw new UnsupportedOperationException("Validation messages should not be added to the empty validation"); | ||
} | ||
}; | ||
|
||
/** | ||
* Perform validation. This method does not have to be overridden in the event that no validation needs to be done. | ||
* | ||
* @return potentially null, in the event of older actions, an empty {@link ValidationException} in newer actions, or finally a | ||
* {@link ValidationException} that contains a list of all failed validation. | ||
*/ | ||
default ValidationException validate() { | ||
return EMPTY_VALIDATION; | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
client/rest-high-level/src/main/java/org/elasticsearch/client/ValidationException.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.elasticsearch.client; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* Encapsulates an accumulation of validation errors | ||
*/ | ||
public class ValidationException extends IllegalArgumentException { | ||
private final List<String> validationErrors = new ArrayList<>(); | ||
|
||
/** | ||
* Add a new validation error to the accumulating validation errors | ||
* @param error the error to add | ||
*/ | ||
public void addValidationError(String error) { | ||
validationErrors.add(error); | ||
} | ||
|
||
/** | ||
* Returns the validation errors accumulated | ||
*/ | ||
public final List<String> validationErrors() { | ||
return validationErrors; | ||
} | ||
|
||
@Override | ||
public final String getMessage() { | ||
StringBuilder sb = new StringBuilder(); | ||
sb.append("Validation Failed: "); | ||
int index = 0; | ||
for (String error : validationErrors) { | ||
sb.append(++index).append(": ").append(error).append(";"); | ||
} | ||
return sb.toString(); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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'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.
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.
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.