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

Bump compatible rest api version to 9/8 #113151

Merged
merged 23 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
4 changes: 4 additions & 0 deletions modules/dot-prefix-validation/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ restResources {
tasks.named('yamlRestTest') {
usesDefaultDistribution()
}

tasks.named('yamlRestCompatTest') {
usesDefaultDistribution()
}

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