Skip to content

Commit

Permalink
Bump compatible rest api version to 9/8 (elastic#113151)
Browse files Browse the repository at this point in the history
This commit bumps the REST API version from 8 to 9. This effectively removes all support for REST API 
compatibility with version 7 (though earlier commits already chipped away at some v7 support).

This also enables REST API compatibility support for version 8, providing support for v8 compatibility headers, 
i.e. "application/vnd.elasticsearch+json;compatible-with=8" and no-op support (no errors) to accept v9 
compatibility headers i.e. "application/vnd.elasticsearch+json;compatible-with=9".

see additional context in the GH PR elastic#113151
  • Loading branch information
jakelandis authored Sep 26, 2024
1 parent 1b5d75f commit 8881886
Show file tree
Hide file tree
Showing 52 changed files with 293 additions and 1,515 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ public class InjectHeaderTests extends InjectFeatureTests {

private static final Map<String, String> headers = Map.of(
"Content-Type",
"application/vnd.elasticsearch+json;compatible-with=7",
"application/vnd.elasticsearch+json;compatible-with=8",
"Accept",
"application/vnd.elasticsearch+json;compatible-with=7"
"application/vnd.elasticsearch+json;compatible-with=8"
);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,13 @@ public enum RestApiVersion {

V_8(8),

@UpdateForV9 // remove all references to V_7 then delete this annotation
V_7(7);

public final byte major;

@UpdateForV9
// We need to bump current and previous to V_9 and V_8, respectively
private static final RestApiVersion CURRENT = V_8;
private static final RestApiVersion PREVIOUS = V_7;
private static final RestApiVersion CURRENT = V_9;
private static final RestApiVersion PREVIOUS = V_8;

RestApiVersion(int major) {
this.major = (byte) major;
Expand Down Expand Up @@ -67,8 +66,6 @@ public static Predicate<RestApiVersion> onOrAfter(RestApiVersion restApiVersion)
};
}

@UpdateForV9
// Right now we return api version 8 for major version 9 until we bump the api version above
public static RestApiVersion forMajor(int major) {
switch (major) {
case 7 -> {
Expand All @@ -78,7 +75,7 @@ public static RestApiVersion forMajor(int major) {
return V_8;
}
case 9 -> {
return V_8;
return V_9;
}
default -> throw new IllegalArgumentException("Unknown REST API version " + major);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
* A MediaType can have only one query parameter representation.
* For example "json" (case insensitive) maps back to a JSON media type.
*
* Additionally, a http header may optionally have parameters. For example "application/vnd.elasticsearch+json; compatible-with=7".
* Additionally, a http header may optionally have parameters. For example "application/vnd.elasticsearch+json; compatible-with=8".
* This class also allows to define a regular expression for valid values of charset.
*/
public class MediaTypeRegistry<T extends MediaType> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,19 @@ public void testCanonicalParsing() {
assertThat(ParsedMediaType.parseMediaType("application/cbor").toMediaType(mediaTypeRegistry), equalTo(XContentType.CBOR));

assertThat(
ParsedMediaType.parseMediaType("application/vnd.elasticsearch+json;compatible-with=7").toMediaType(mediaTypeRegistry),
ParsedMediaType.parseMediaType("application/vnd.elasticsearch+json;compatible-with=8").toMediaType(mediaTypeRegistry),
equalTo(XContentType.VND_JSON)
);
assertThat(
ParsedMediaType.parseMediaType("application/vnd.elasticsearch+yaml;compatible-with=7").toMediaType(mediaTypeRegistry),
ParsedMediaType.parseMediaType("application/vnd.elasticsearch+yaml;compatible-with=8").toMediaType(mediaTypeRegistry),
equalTo(XContentType.VND_YAML)
);
assertThat(
ParsedMediaType.parseMediaType("application/vnd.elasticsearch+smile;compatible-with=7").toMediaType(mediaTypeRegistry),
ParsedMediaType.parseMediaType("application/vnd.elasticsearch+smile;compatible-with=8").toMediaType(mediaTypeRegistry),
equalTo(XContentType.VND_SMILE)
);
assertThat(
ParsedMediaType.parseMediaType("application/vnd.elasticsearch+cbor;compatible-with=7").toMediaType(mediaTypeRegistry),
ParsedMediaType.parseMediaType("application/vnd.elasticsearch+cbor;compatible-with=8").toMediaType(mediaTypeRegistry),
equalTo(XContentType.VND_CBOR)
);
}
Expand Down Expand Up @@ -179,19 +179,19 @@ public void testParseMediaTypeFromXContentType() {
);

assertThat(
ParsedMediaType.parseMediaType(XContentType.VND_JSON, Map.of("compatible-with", "7")).toMediaType(mediaTypeRegistry),
ParsedMediaType.parseMediaType(XContentType.VND_JSON, Map.of("compatible-with", "8")).toMediaType(mediaTypeRegistry),
equalTo(XContentType.VND_JSON)
);
assertThat(
ParsedMediaType.parseMediaType(XContentType.VND_YAML, Map.of("compatible-with", "7")).toMediaType(mediaTypeRegistry),
ParsedMediaType.parseMediaType(XContentType.VND_YAML, Map.of("compatible-with", "8")).toMediaType(mediaTypeRegistry),
equalTo(XContentType.VND_YAML)
);
assertThat(
ParsedMediaType.parseMediaType(XContentType.VND_SMILE, Map.of("compatible-with", "7")).toMediaType(mediaTypeRegistry),
ParsedMediaType.parseMediaType(XContentType.VND_SMILE, Map.of("compatible-with", "8")).toMediaType(mediaTypeRegistry),
equalTo(XContentType.VND_SMILE)
);
assertThat(
ParsedMediaType.parseMediaType(XContentType.VND_CBOR, Map.of("compatible-with", "7")).toMediaType(mediaTypeRegistry),
ParsedMediaType.parseMediaType(XContentType.VND_CBOR, Map.of("compatible-with", "8")).toMediaType(mediaTypeRegistry),
equalTo(XContentType.VND_CBOR)
);
}
Expand All @@ -215,20 +215,20 @@ public void testResponseContentTypeHeader() {
);

assertThat(
ParsedMediaType.parseMediaType(XContentType.VND_JSON, Map.of("compatible-with", "7")).responseContentTypeHeader(),
equalTo("application/vnd.elasticsearch+json;compatible-with=7")
ParsedMediaType.parseMediaType(XContentType.VND_JSON, Map.of("compatible-with", "8")).responseContentTypeHeader(),
equalTo("application/vnd.elasticsearch+json;compatible-with=8")
);
assertThat(
ParsedMediaType.parseMediaType(XContentType.VND_YAML, Map.of("compatible-with", "7")).responseContentTypeHeader(),
equalTo("application/vnd.elasticsearch+yaml;compatible-with=7")
ParsedMediaType.parseMediaType(XContentType.VND_YAML, Map.of("compatible-with", "8")).responseContentTypeHeader(),
equalTo("application/vnd.elasticsearch+yaml;compatible-with=8")
);
assertThat(
ParsedMediaType.parseMediaType(XContentType.VND_SMILE, Map.of("compatible-with", "7")).responseContentTypeHeader(),
equalTo("application/vnd.elasticsearch+smile;compatible-with=7")
ParsedMediaType.parseMediaType(XContentType.VND_SMILE, Map.of("compatible-with", "8")).responseContentTypeHeader(),
equalTo("application/vnd.elasticsearch+smile;compatible-with=8")
);
assertThat(
ParsedMediaType.parseMediaType(XContentType.VND_CBOR, Map.of("compatible-with", "7")).responseContentTypeHeader(),
equalTo("application/vnd.elasticsearch+cbor;compatible-with=7")
ParsedMediaType.parseMediaType(XContentType.VND_CBOR, Map.of("compatible-with", "8")).responseContentTypeHeader(),
equalTo("application/vnd.elasticsearch+cbor;compatible-with=8")
);

assertThat(
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.elasticsearch.common.compress.CompressedXContent;
import org.elasticsearch.common.io.stream.BytesStreamOutput;
import org.elasticsearch.common.lucene.uid.Versions;
import org.elasticsearch.core.RestApiVersion;
import org.elasticsearch.index.get.GetResult;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.index.query.QueryBuilder;
Expand All @@ -32,9 +31,7 @@
import org.elasticsearch.test.AbstractQueryTestCase;
import org.elasticsearch.xcontent.XContentBuilder;
import org.elasticsearch.xcontent.XContentFactory;
import org.elasticsearch.xcontent.XContentParser;
import org.elasticsearch.xcontent.XContentType;
import org.elasticsearch.xcontent.json.JsonXContent;
import org.hamcrest.Matchers;

import java.io.IOException;
Expand Down Expand Up @@ -379,31 +376,4 @@ public void testDisallowExpensiveQueries() {
ElasticsearchException e = expectThrows(ElasticsearchException.class, () -> queryBuilder.toQuery(searchExecutionContext));
assertEquals("[percolate] queries cannot be executed when 'search.allow_expensive_queries' is set to false.", e.getMessage());
}

public void testFromJsonWithDocumentType() throws IOException {
SearchExecutionContext searchExecutionContext = createSearchExecutionContext();
String queryAsString = Strings.format("""
{"percolate" : { "document": {}, "document_type":"%s", "field":"%s"}}
""", docType, queryField);
XContentParser parser = createParserWithCompatibilityFor(JsonXContent.jsonXContent, queryAsString, RestApiVersion.V_7);
QueryBuilder queryBuilder = parseQuery(parser);
queryBuilder.toQuery(searchExecutionContext);
assertCriticalWarnings(PercolateQueryBuilder.DOCUMENT_TYPE_DEPRECATION_MESSAGE);
}

public void testFromJsonWithType() throws IOException {
indexedDocumentIndex = randomAlphaOfLength(4);
indexedDocumentId = randomAlphaOfLength(4);
indexedDocumentVersion = Versions.MATCH_ANY;
documentSource = Collections.singletonList(randomSource(new HashSet<>()));
SearchExecutionContext searchExecutionContext = createSearchExecutionContext();

String queryAsString = Strings.format("""
{"percolate" : { "index": "%s", "type": "_doc", "id": "%s", "field":"%s"}}
""", indexedDocumentIndex, indexedDocumentId, queryField);
XContentParser parser = createParserWithCompatibilityFor(JsonXContent.jsonXContent, queryAsString, RestApiVersion.V_7);
QueryBuilder queryBuilder = parseQuery(parser);
rewriteAndFetch(queryBuilder, searchExecutionContext).toQuery(searchExecutionContext);
assertCriticalWarnings(PercolateQueryBuilder.TYPE_DEPRECATION_MESSAGE);
}
}

This file was deleted.

Loading

0 comments on commit 8881886

Please sign in to comment.