-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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
Allow registering compatible handlers #64423
Merged
pgomulka
merged 34 commits into
elastic:master
from
pgomulka:compat/register_compatible_handlers
Nov 16, 2020
Merged
Changes from all commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
e468fdf
Introduce per endpoint media types
pgomulka 5cfa11e
Merge branch 'master' into compat/parsed_media_type
pgomulka 66224e7
allow smile and cbor to parse charset param. See ClientYamlTestExecut…
pgomulka 29b27e8
javadocs
pgomulka 4690362
fix javadoc
pgomulka e7866a9
Allow registration of compatible version-1 handlers
pgomulka 0330d97
add tests
pgomulka 78d4660
Merge branch 'master' into compat/register_compatible_handlers
pgomulka bc5de8b
pass version to xcontentbuilder
pgomulka f958cdd
Merge branch 'master' into compat/register_compatible_handlers
pgomulka 2bda74f
code review follow up
pgomulka 7779083
minor tweaks
pgomulka dd26408
Merge branch 'master' into compat/introduce_per_endpoint_media_types
pgomulka 94b4a0a
fix test after exception msg rename
pgomulka 4385591
rename to header value
pgomulka dc61731
remove charset validation
pgomulka 4a3138d
Apply suggestions from code review
pgomulka 0b565e5
javadoc
pgomulka b35ad2c
Merge branch 'master' into compat/introduce_per_endpoint_media_types
pgomulka b908bfe
Merge branch 'compat/introduce_per_endpoint_media_types' of github.co…
pgomulka 950ba7b
Merge branch 'compat/introduce_per_endpoint_media_types' into compat/…
pgomulka 310b735
Merge branch 'master' into compat/register_compatible_handlers
pgomulka afba70d
javadoc and cleanup
pgomulka 385f5a9
Merge branch 'master' into compat/register_compatible_handlers
pgomulka 836fe0f
tests and javadoc
pgomulka 8f2ea92
javadoc
pgomulka d70a071
do not set compatible version twice
pgomulka 87d762f
Merge branch 'master' into compat/register_compatible_handlers
pgomulka deff739
javadocs
pgomulka 4ecbf22
Merge remote-tracking branch 'upstream/master' into compat/register_c…
pgomulka a38ed04
Merge remote-tracking branch 'upstream/master' into compat/register_c…
pgomulka c39d0bb
Apply suggestions from code review
pgomulka 09704f3
Merge branch 'compat/register_compatible_handlers' of github.com:pgom…
pgomulka 023c8d9
xcontentbuilder has the version requested by a user
pgomulka 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 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 |
---|---|---|
|
@@ -48,6 +48,8 @@ | |
*/ | ||
public final class XContentBuilder implements Closeable, Flushable { | ||
|
||
private byte compatibleMajorVersion; | ||
|
||
/** | ||
* Create a new {@link XContentBuilder} using the given {@link XContent} content. | ||
* <p> | ||
|
@@ -1004,6 +1006,25 @@ public XContentBuilder copyCurrentStructure(XContentParser parser) throws IOExce | |
return this; | ||
} | ||
|
||
/** | ||
* Sets a version used for serialising a response compatible with a previous version. | ||
*/ | ||
public XContentBuilder withCompatibleMajorVersion(byte compatibleMajorVersion) { | ||
assert this.compatibleMajorVersion == 0 : "Compatible version has already been set"; | ||
if (compatibleMajorVersion == 0) { | ||
throw new IllegalArgumentException("Compatible major version must not be equal to 0"); | ||
} | ||
this.compatibleMajorVersion = compatibleMajorVersion; | ||
return this; | ||
} | ||
|
||
/** | ||
* Returns a version used for serialising a response compatible with a previous version. | ||
*/ | ||
public byte getCompatibleMajorVersion() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you add javadocs to this method and the one above? |
||
return compatibleMajorVersion; | ||
} | ||
|
||
@Override | ||
public void flush() throws IOException { | ||
generator.flush(); | ||
|
This file contains 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
This file contains 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
This file contains 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
35 changes: 35 additions & 0 deletions
35
server/src/main/java/org/elasticsearch/rest/CompatibleVersion.java
This file contains 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,35 @@ | ||
/* | ||
* 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.rest; | ||
|
||
import org.elasticsearch.Version; | ||
import org.elasticsearch.common.Nullable; | ||
import org.elasticsearch.common.xcontent.ParsedMediaType; | ||
|
||
/** | ||
* An interface used to specify a function that returns a compatible API version. | ||
* This function abstracts how the version calculation is provided (for instance from plugin). | ||
*/ | ||
@FunctionalInterface | ||
public interface CompatibleVersion { | ||
Version get(@Nullable ParsedMediaType acceptHeader, @Nullable ParsedMediaType contentTypeHeader, boolean hasContent); | ||
|
||
CompatibleVersion CURRENT_VERSION = (acceptHeader, contentTypeHeader, hasContent) -> Version.CURRENT; | ||
} |
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.
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.
hmm, I wonder if we should make this a
SetOnce
or add validation that if it is not some sentinel value that it cannot be changed again? I'm not sure that I like it being mutable with a builder pattern and allowing it to be set multiple timesThere 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.
with a regular builder pattern I would be ok with the field being mutable, as it is normally used within some narrow code scope.
With XContentBuilder we often pass it around so makes sense to protect against some accidental changes.
I feel like we should assert about this in testing only though.
I added
assert