From 9f583a25e53e39ab7e472b724ca61bf954d6dc0d Mon Sep 17 00:00:00 2001 From: pgomulka Date: Thu, 7 Jan 2021 13:56:11 +0100 Subject: [PATCH 1/3] patch --- .../test/rest/YamlRestCompatTestPlugin.java | 4 +- ...ticsearch.yaml-rest-compat-test.properties | 20 +++++ modules/ingest-common/build.gradle | 11 +++ .../test/ingest/80_foreach_compat.yml | 80 +++++++++++++++++++ .../yaml/ClientYamlTestExecutionContext.java | 3 + 5 files changed, 116 insertions(+), 2 deletions(-) create mode 100644 buildSrc/src/main/resources/META-INF/gradle-plugins/elasticsearch.yaml-rest-compat-test.properties create mode 100644 modules/ingest-common/src/yamlRestCompatTest/resources/rest-api-spec/test/ingest/80_foreach_compat.yml diff --git a/buildSrc/src/main/java/org/elasticsearch/gradle/test/rest/YamlRestCompatTestPlugin.java b/buildSrc/src/main/java/org/elasticsearch/gradle/test/rest/YamlRestCompatTestPlugin.java index 2bef82660182b..9456ec2d39fbb 100644 --- a/buildSrc/src/main/java/org/elasticsearch/gradle/test/rest/YamlRestCompatTestPlugin.java +++ b/buildSrc/src/main/java/org/elasticsearch/gradle/test/rest/YamlRestCompatTestPlugin.java @@ -151,8 +151,8 @@ public void apply(Project project) { // setup IDE GradleUtils.setupIdeForTestSourceSet(project, yamlCompatTestSourceSet); - // wire this task into check - project.getTasks().named(JavaBasePlugin.CHECK_TASK_NAME).configure(check -> check.dependsOn(yamlRestCompatTestTask)); + // do not wire this task into check ... this will likely go into it's own lifecycle outside of check + // project.getTasks().named(JavaBasePlugin.CHECK_TASK_NAME).configure(check -> check.dependsOn(yamlRestCompatTestTask)); } // TODO: implement custom extension that allows us move around of the projects between major versions and still find them diff --git a/buildSrc/src/main/resources/META-INF/gradle-plugins/elasticsearch.yaml-rest-compat-test.properties b/buildSrc/src/main/resources/META-INF/gradle-plugins/elasticsearch.yaml-rest-compat-test.properties new file mode 100644 index 0000000000000..3ce63f13782cb --- /dev/null +++ b/buildSrc/src/main/resources/META-INF/gradle-plugins/elasticsearch.yaml-rest-compat-test.properties @@ -0,0 +1,20 @@ +# +# 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. +# + +implementation-class=org.elasticsearch.gradle.test.rest.YamlRestCompatTestPlugin diff --git a/modules/ingest-common/build.gradle b/modules/ingest-common/build.gradle index 888ceadc530ed..40b8c0a89de03 100644 --- a/modules/ingest-common/build.gradle +++ b/modules/ingest-common/build.gradle @@ -17,6 +17,7 @@ * under the License. */ apply plugin: 'elasticsearch.yaml-rest-test' +apply plugin: 'elasticsearch.yaml-rest-compat-test' apply plugin: 'elasticsearch.internal-cluster-test' esplugin { @@ -57,3 +58,13 @@ tasks.named("thirdPartyAudit").configure { 'org.osgi.framework.wiring.BundleWiring' ) } + +tasks.named("yamlRestCompatTest").configure { + systemProperty 'tests.rest.blacklist', ( + [ + //tests use types + 'ingest/200_dissect_processor/Test dissect processor mismatch', + 'ingest/80_foreach/Test foreach Processor' // <-- manually overridden in yamlRestCompatTest + ] + ).join(",") +} diff --git a/modules/ingest-common/src/yamlRestCompatTest/resources/rest-api-spec/test/ingest/80_foreach_compat.yml b/modules/ingest-common/src/yamlRestCompatTest/resources/rest-api-spec/test/ingest/80_foreach_compat.yml new file mode 100644 index 0000000000000..73d45fa32c5c8 --- /dev/null +++ b/modules/ingest-common/src/yamlRestCompatTest/resources/rest-api-spec/test/ingest/80_foreach_compat.yml @@ -0,0 +1,80 @@ +# copied from 7.x as-is but the compat header injected. This will not be necessary in the near future once the +# find/replace style of over ride is implemented and wired into the copy from the 7.x source. Compat header values will +# always be injected. Only specific assertions will need to be explict find/replaced and overriding an entire test +# like demonstrated here should not be needed in all but the rarest cases. +# Also note there is nothing special about the file/directory naming. just using _compat as a convention. +# The different name also avoids any hard to troubleshoot which one is actually getting used questions. +# ./gradlew ':modules:ingest-common:yamlRestCompatTest' --tests "org.elasticsearch.ingest.common.IngestCommonClientYamlTestSuiteIT.test {yaml=ingest/80_foreach_compat/Test foreach Processor}" --info +--- +setup: + - skip: + features: headers +--- +teardown: + - do: + ingest.delete_pipeline: + id: "my_pipeline" + ignore: 404 + +--- +"Test foreach Processor": + - do: + ingest.put_pipeline: + id: "my_pipeline" + body: > + { + "description": "_description", + "processors": [ + { + "foreach" : { + "field" : "values", + "processor" : { + "uppercase" : { + "field" : "_ingest._value" + } + } + } + } + ] + } + - match: { acknowledged: true } + + - do: + headers: + Content-Type: "application/vnd.elasticsearch+json;compatible-with=7" + Accept: "application/vnd.elasticsearch+json;compatible-with=7" + index: + index: test + type: test + id: 1 + pipeline: "my_pipeline" + body: > + { + "values": ["foo", "bar", "baz"] + } + + - do: + get: + index: test + type: test + id: 1 + - match: { _source.values: ["FOO", "BAR", "BAZ"] } + + #exceeds the recurse max per thread and will runs some of these on a different thread + - do: + index: + index: test + id: 1 + pipeline: "my_pipeline" + body: > + { + "values": ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", + "v", "w", "x", "y", "z"] + } + + - do: + get: + index: test + id: 1 + - match: { _source.values: ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", + "V", "W", "X", "Y", "Z"] } diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ClientYamlTestExecutionContext.java b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ClientYamlTestExecutionContext.java index b1337172a5679..78d90420b7a76 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ClientYamlTestExecutionContext.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ClientYamlTestExecutionContext.java @@ -108,6 +108,9 @@ public ClientYamlTestResponse callApi(String apiName, Map params Object responseBody = response != null ? response.getBody() : null; //we always stash the last response body stash.stashValue("body", responseBody); + if(requestHeaders.isEmpty() == false) { + stash.stashValue("request_headers", requestHeaders); + } } } From 37bef02b0f537f03f4c25e0b7787dc5829acbb33 Mon Sep 17 00:00:00 2001 From: pgomulka Date: Thu, 7 Jan 2021 15:32:21 +0100 Subject: [PATCH 2/3] index and get api --- rest-api-spec/build.gradle | 11 ++ .../rest-api-spec/test/index/10_with_id.yml | 36 +++++ .../index/11_with_id_with_types_compat.yml | 46 +++++++ .../rest-api-spec/test/index/12_result.yml | 22 +++ .../test/index/13_result_with_types.yml | 21 +++ .../test/index/15_without_id.yml | 28 ++++ .../test/index/16_without_id_with_types.yml | 26 ++++ .../rest-api-spec/test/index/20_optype.yml | 30 ++++ .../test/index/21_optype_with_types.yml | 29 ++++ .../rest-api-spec/test/index/30_cas.yml | 50 +++++++ .../test/index/35_external_version.yml | 54 ++++++++ .../test/index/36_external_gte_version.yml | 55 ++++++++ .../index/37_external_version_with_types.yml | 55 ++++++++ .../38_external_gte_version_with_types.yml | 56 ++++++++ .../rest-api-spec/test/index/40_routing.yml | 43 ++++++ .../test/index/41_routing_with_types.yml | 43 ++++++ .../rest-api-spec/test/index/60_refresh.yml | 93 +++++++++++++ .../test/index/61_refresh_with_types.yml | 83 +++++++++++ .../test/index/70_mix_typeless_typeful.yml | 102 ++++++++++++++ .../test/index/70_require_alias.yml | 29 ++++ .../test/index/80_date_nanos.yml | 36 +++++ .../action/DocWriteResponse.java | 4 + .../elasticsearch/index/get/GetResult.java | 7 + .../rest/action/document/RestIndexAction.java | 4 +- .../compat/CompatibleVersionPlugin.java | 36 ++++- .../rest/action/document/RestGetActionV7.java | 47 +++++++ .../action/document/RestIndexActionV7.java | 130 ++++++++++++++++++ .../security/rest/SecurityRestFilter.java | 6 + 28 files changed, 1179 insertions(+), 3 deletions(-) create mode 100644 rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/10_with_id.yml create mode 100644 rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/11_with_id_with_types_compat.yml create mode 100644 rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/12_result.yml create mode 100644 rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/13_result_with_types.yml create mode 100644 rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/15_without_id.yml create mode 100644 rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/16_without_id_with_types.yml create mode 100644 rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/20_optype.yml create mode 100644 rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/21_optype_with_types.yml create mode 100644 rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/30_cas.yml create mode 100644 rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/35_external_version.yml create mode 100644 rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/36_external_gte_version.yml create mode 100644 rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/37_external_version_with_types.yml create mode 100644 rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/38_external_gte_version_with_types.yml create mode 100644 rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/40_routing.yml create mode 100644 rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/41_routing_with_types.yml create mode 100644 rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/60_refresh.yml create mode 100644 rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/61_refresh_with_types.yml create mode 100644 rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/70_mix_typeless_typeful.yml create mode 100644 rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/70_require_alias.yml create mode 100644 rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/80_date_nanos.yml create mode 100644 x-pack/plugin/rest-compatibility/src/main/java/org/elasticsearch/rest/action/document/RestGetActionV7.java create mode 100644 x-pack/plugin/rest-compatibility/src/main/java/org/elasticsearch/rest/action/document/RestIndexActionV7.java diff --git a/rest-api-spec/build.gradle b/rest-api-spec/build.gradle index 8af6df35e6fa1..21de7ebf0c8a4 100644 --- a/rest-api-spec/build.gradle +++ b/rest-api-spec/build.gradle @@ -3,6 +3,7 @@ apply plugin: 'elasticsearch.publish' apply plugin: 'elasticsearch.rest-resources' apply plugin: 'elasticsearch.validate-rest-spec' apply plugin: 'elasticsearch.yaml-rest-test' +apply plugin: 'elasticsearch.yaml-rest-compat-test' restResources { restTests { @@ -21,3 +22,13 @@ testClusters.all { tasks.named("test").configure {enabled = false } tasks.named("jarHell").configure {enabled = false } + +tasks.named("yamlRestCompatTest").configure { + systemProperty 'tests.rest.blacklist', ( + [ + //tests use types + 'ingest/200_dissect_processor/Test dissect processor mismatch', + 'ingest/80_foreach/Test foreach Processor' // <-- manually overridden in yamlRestCompatTest + ] + ).join(",") +} diff --git a/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/10_with_id.yml b/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/10_with_id.yml new file mode 100644 index 0000000000000..809a91d6da8da --- /dev/null +++ b/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/10_with_id.yml @@ -0,0 +1,36 @@ + +--- +"Index with ID": + + - skip: + version: " - 6.99.99" + reason: types are required in requests before 7.0.0 + + - do: + index: + index: test-weird-index-中文 + id: 1 + body: { foo: bar } + + - match: { _index: test-weird-index-中文 } + - match: { _type: _doc } + - match: { _id: "1"} + - match: { _version: 1} + + - do: + get: + index: test-weird-index-中文 + id: 1 + + - match: { _index: test-weird-index-中文 } + - match: { _type: _doc } + - match: { _id: "1"} + - match: { _version: 1} + - match: { _source: { foo: bar }} + + - do: + catch: bad_request + index: + index: idx + id: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + body: { foo: bar } diff --git a/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/11_with_id_with_types_compat.yml b/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/11_with_id_with_types_compat.yml new file mode 100644 index 0000000000000..af69ceb7f2293 --- /dev/null +++ b/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/11_with_id_with_types_compat.yml @@ -0,0 +1,46 @@ +# ./gradlew ':rest-api-spec:yamlRestCompatTest' --tests "org.elasticsearch.test.rest.ClientYamlTestSuiteIT" -Dtests.method="test {p0=index/11_with_id_with_types_compat/*}" +--- +setup: + - skip: + features: headers + +--- +"Index with ID": + + - do: + headers: + Content-Type: "application/vnd.elasticsearch+json;compatible-with=7" + Accept: "application/vnd.elasticsearch+json;compatible-with=7" + index: + index: test-weird-index-中文 + type: weird.type + id: 1 + body: { foo: bar } + + - match: { _index: test-weird-index-中文 } + - match: { _type: _doc } + - match: { _id: "1"} + - match: { _version: 1} + + - do: + headers: + Content-Type: "application/vnd.elasticsearch+json;compatible-with=7" + Accept: "application/vnd.elasticsearch+json;compatible-with=7" + get: + index: test-weird-index-中文 + type: weird.type + id: 1 + + - match: { _index: test-weird-index-中文 } + - match: { _type: _doc } + - match: { _id: "1"} + - match: { _version: 1} + - match: { _source: { foo: bar }} + + - do: + catch: bad_request + index: + index: idx + type: type + id: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + body: { foo: bar } diff --git a/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/12_result.yml b/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/12_result.yml new file mode 100644 index 0000000000000..f8a50415a95ef --- /dev/null +++ b/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/12_result.yml @@ -0,0 +1,22 @@ +--- +"Index result field": + + - skip: + version: " - 6.99.99" + reason: types are required in requests before 7.0.0 + - do: + index: + index: test_index + id: 1 + body: { foo: bar } + + - match: { result: created } + + - do: + index: + index: test_index + id: 1 + body: { foo: bar } + op_type: index + + - match: { result: updated } diff --git a/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/13_result_with_types.yml b/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/13_result_with_types.yml new file mode 100644 index 0000000000000..45ebe0bbd3dc1 --- /dev/null +++ b/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/13_result_with_types.yml @@ -0,0 +1,21 @@ +--- +"Index result field": + + - do: + index: + index: test_index + type: test + id: 1 + body: { foo: bar } + + - match: { result: created } + + - do: + index: + index: test_index + type: test + id: 1 + body: { foo: bar } + op_type: index + + - match: { result: updated } diff --git a/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/15_without_id.yml b/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/15_without_id.yml new file mode 100644 index 0000000000000..073a4704b4ef8 --- /dev/null +++ b/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/15_without_id.yml @@ -0,0 +1,28 @@ +--- +"Index without ID": + + - skip: + version: " - 6.99.99" + reason: types are required in requests before 7.0.0 + + - do: + index: + index: test_1 + body: { foo: bar } + + - is_true: _id + - match: { _index: test_1 } + - match: { _type: _doc } + - match: { _version: 1 } + - set: { _id: id } + + - do: + get: + index: test_1 + id: '$id' + + - match: { _index: test_1 } + - match: { _type: _doc } + - match: { _id: $id } + - match: { _version: 1 } + - match: { _source: { foo: bar }} diff --git a/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/16_without_id_with_types.yml b/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/16_without_id_with_types.yml new file mode 100644 index 0000000000000..3fff0512b9602 --- /dev/null +++ b/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/16_without_id_with_types.yml @@ -0,0 +1,26 @@ +--- +"Index without ID": + + - do: + index: + index: test_1 + type: test + body: { foo: bar } + + - is_true: _id + - match: { _index: test_1 } + - match: { _type: test } + - match: { _version: 1 } + - set: { _id: id } + + - do: + get: + index: test_1 + type: test + id: '$id' + + - match: { _index: test_1 } + - match: { _type: test } + - match: { _id: $id } + - match: { _version: 1 } + - match: { _source: { foo: bar }} diff --git a/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/20_optype.yml b/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/20_optype.yml new file mode 100644 index 0000000000000..c33a86093acab --- /dev/null +++ b/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/20_optype.yml @@ -0,0 +1,30 @@ +--- +"Optype": + + - skip: + version: " - 6.99.99" + reason: types are required in requests before 7.0.0 + + - do: + index: + index: test_1 + id: 1 + op_type: create + body: { foo: bar } + + - do: + catch: conflict + index: + index: test_1 + id: 1 + op_type: create + body: { foo: bar } + + - do: + index: + index: test_1 + id: 1 + op_type: index + body: { foo: bar } + + - match: { _version: 2 } diff --git a/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/21_optype_with_types.yml b/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/21_optype_with_types.yml new file mode 100644 index 0000000000000..60ae26d46d07d --- /dev/null +++ b/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/21_optype_with_types.yml @@ -0,0 +1,29 @@ +--- +"Optype": + + - do: + index: + index: test_1 + type: test + id: 1 + op_type: create + body: { foo: bar } + + - do: + catch: conflict + index: + index: test_1 + type: test + id: 1 + op_type: create + body: { foo: bar } + + - do: + index: + index: test_1 + type: test + id: 1 + op_type: index + body: { foo: bar } + + - match: { _version: 2 } diff --git a/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/30_cas.yml b/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/30_cas.yml new file mode 100644 index 0000000000000..550582e9816eb --- /dev/null +++ b/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/30_cas.yml @@ -0,0 +1,50 @@ +--- +"Compare And Swap Sequence Numbers": + + - skip: + version: " - 6.99.99" + reason: typesless api was introduces in 7.0 + + - do: + index: + index: test_1 + id: 1 + body: { foo: bar } + - match: { _version: 1} + - set: { _seq_no: seqno } + - set: { _primary_term: primary_term } + + - do: + get: + index: test_1 + id: 1 + - match: { _seq_no: $seqno } + - match: { _primary_term: $primary_term } + + - do: + catch: conflict + index: + index: test_1 + id: 1 + if_seq_no: 10000 + if_primary_term: $primary_term + body: { foo: bar2 } + + - do: + catch: conflict + index: + index: test_1 + id: 1 + if_seq_no: $seqno + if_primary_term: 1000 + body: { foo: bar2 } + + - do: + index: + index: test_1 + id: 1 + if_seq_no: $seqno + if_primary_term: $primary_term + body: { foo: bar2 } + + - match: { _version: 2 } diff --git a/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/35_external_version.yml b/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/35_external_version.yml new file mode 100644 index 0000000000000..89aaa190af384 --- /dev/null +++ b/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/35_external_version.yml @@ -0,0 +1,54 @@ +--- +"External version": + + - skip: + version: " - 6.99.99" + reason: types are required in requests before 7.0.0 + + - do: + index: + index: test_1 + id: 1 + body: { foo: bar } + version_type: external + version: 0 + + - match: { _version: 0 } + + - do: + index: + index: test_1 + id: 1 + body: { foo: bar } + version_type: external + version: 5 + + - match: { _version: 5 } + + - do: + catch: conflict + index: + index: test_1 + id: 1 + body: { foo: bar } + version_type: external + version: 5 + + - do: + catch: conflict + index: + index: test_1 + id: 1 + body: { foo: bar } + version_type: external + version: 0 + + - do: + index: + index: test_1 + id: 1 + body: { foo: bar } + version_type: external + version: 6 + + - match: { _version: 6} diff --git a/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/36_external_gte_version.yml b/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/36_external_gte_version.yml new file mode 100644 index 0000000000000..82421227adb7f --- /dev/null +++ b/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/36_external_gte_version.yml @@ -0,0 +1,55 @@ +--- +"External GTE version": + + - skip: + version: " - 6.99.99" + reason: types are required in requests before 7.0.0 + + - do: + index: + index: test_1 + id: 1 + body: { foo: bar } + version_type: external_gte + version: 0 + + - match: { _version: 0} + + - do: + index: + index: test_1 + id: 1 + body: { foo: bar } + version_type: external_gte + version: 5 + + - match: { _version: 5} + + - do: + catch: conflict + index: + index: test_1 + id: 1 + body: { foo: bar } + version_type: external_gte + version: 0 + + - do: + index: + index: test_1 + id: 1 + body: { foo: bar2 } + version_type: external_gte + version: 5 + + - match: { _version: 5} + + - do: + index: + index: test_1 + id: 1 + body: { foo: bar2 } + version_type: external_gte + version: 6 + + - match: { _version: 6} diff --git a/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/37_external_version_with_types.yml b/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/37_external_version_with_types.yml new file mode 100644 index 0000000000000..f17e6b749319d --- /dev/null +++ b/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/37_external_version_with_types.yml @@ -0,0 +1,55 @@ +--- +"External version": + + - do: + index: + index: test_1 + type: test + id: 1 + body: { foo: bar } + version_type: external + version: 0 + + - match: { _version: 0 } + + - do: + index: + index: test_1 + type: test + id: 1 + body: { foo: bar } + version_type: external + version: 5 + + - match: { _version: 5 } + + - do: + catch: conflict + index: + index: test_1 + type: test + id: 1 + body: { foo: bar } + version_type: external + version: 5 + + - do: + catch: conflict + index: + index: test_1 + type: test + id: 1 + body: { foo: bar } + version_type: external + version: 0 + + - do: + index: + index: test_1 + type: test + id: 1 + body: { foo: bar } + version_type: external + version: 6 + + - match: { _version: 6} diff --git a/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/38_external_gte_version_with_types.yml b/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/38_external_gte_version_with_types.yml new file mode 100644 index 0000000000000..dccbe02ea1400 --- /dev/null +++ b/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/38_external_gte_version_with_types.yml @@ -0,0 +1,56 @@ +--- +"External GTE version": + + - do: + index: + index: test_1 + type: test + id: 1 + body: { foo: bar } + version_type: external_gte + version: 0 + + - match: { _version: 0} + + - do: + index: + index: test_1 + type: test + id: 1 + body: { foo: bar } + version_type: external_gte + version: 5 + + - match: { _version: 5} + + - do: + catch: conflict + index: + index: test_1 + type: test + id: 1 + body: { foo: bar } + version_type: external_gte + version: 0 + + - do: + index: + index: test_1 + type: test + id: 1 + body: { foo: bar2 } + version_type: external_gte + version: 5 + + - match: { _version: 5} + + - do: + index: + index: test_1 + type: test + id: 1 + body: { foo: bar2 } + version_type: external_gte + version: 6 + + - match: { _version: 6} diff --git a/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/40_routing.yml b/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/40_routing.yml new file mode 100644 index 0000000000000..630cf39dbe65c --- /dev/null +++ b/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/40_routing.yml @@ -0,0 +1,43 @@ +--- +"Routing": + + - skip: + version: " - 6.99.99" + reason: types are required in requests before 7.0.0 + - do: + indices.create: + index: test_1 + body: + settings: + index: + number_of_shards: 5 + number_of_routing_shards: 5 + number_of_replicas: 0 + + - do: + cluster.health: + wait_for_status: green + + - do: + index: + index: test_1 + id: 1 + routing: 5 + body: { foo: bar } + + - do: + get: + index: test_1 + id: 1 + routing: 5 + stored_fields: [_routing] + + - match: { _id: "1"} + - match: { _routing: "5"} + + - do: + catch: missing + get: + index: test_1 + id: 1 + diff --git a/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/41_routing_with_types.yml b/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/41_routing_with_types.yml new file mode 100644 index 0000000000000..5b0cf94f4236b --- /dev/null +++ b/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/41_routing_with_types.yml @@ -0,0 +1,43 @@ +--- +"Routing": + + - do: + indices.create: + index: test_1 + body: + settings: + index: + number_of_shards: 5 + number_of_routing_shards: 5 + number_of_replicas: 0 + + - do: + cluster.health: + wait_for_status: green + + - do: + index: + index: test_1 + type: test + id: 1 + routing: 5 + body: { foo: bar } + + - do: + get: + index: test_1 + type: test + id: 1 + routing: 5 + stored_fields: [_routing] + + - match: { _id: "1"} + - match: { _routing: "5"} + + - do: + catch: missing + get: + index: test_1 + type: test + id: 1 + diff --git a/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/60_refresh.yml b/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/60_refresh.yml new file mode 100644 index 0000000000000..e16602d7ac8b6 --- /dev/null +++ b/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/60_refresh.yml @@ -0,0 +1,93 @@ +--- +"Refresh": + + - skip: + version: " - 6.99.99" + reason: types are required in requests before 7.0.0 + + - do: + indices.create: + index: test_1 + body: + settings: + index.refresh_interval: -1 + number_of_replicas: 0 + + - do: + index: + index: test_1 + id: 1 + body: { foo: bar } + + - do: + search: + rest_total_hits_as_int: true + index: test_1 + body: + query: { term: { _id: 1 }} + + - match: { hits.total: 0 } + + - do: + index: + index: test_1 + id: 2 + refresh: true + body: { foo: bar } + - is_true: forced_refresh + + - do: + search: + rest_total_hits_as_int: true + index: test_1 + body: + query: { term: { _id: 2 }} + + - match: { hits.total: 1 } + +--- +"When refresh url parameter is an empty string that means \"refresh immediately\"": + + - skip: + version: " - 6.99.99" + reason: types are required in requests before 7.0.0 + + - do: + index: + index: test_1 + id: 1 + refresh: "" + body: { foo: bar } + - is_true: forced_refresh + + - do: + search: + rest_total_hits_as_int: true + index: test_1 + body: + query: { term: { _id: 1 }} + + - match: { hits.total: 1 } + +--- +"refresh=wait_for waits until changes are visible in search": + + - skip: + version: " - 6.99.99" + reason: types are required in requests before 7.0.0 + + - do: + index: + index: index_60_refresh_1 + id: index_60_refresh_id1 + body: { foo: bar } + refresh: wait_for + - is_false: forced_refresh + + - do: + search: + rest_total_hits_as_int: true + index: index_60_refresh_1 + body: + query: { term: { _id: index_60_refresh_id1 }} + - match: { hits.total: 1 } diff --git a/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/61_refresh_with_types.yml b/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/61_refresh_with_types.yml new file mode 100644 index 0000000000000..be44cafd43020 --- /dev/null +++ b/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/61_refresh_with_types.yml @@ -0,0 +1,83 @@ +--- +"Refresh": + + - do: + indices.create: + index: test_1 + body: + settings: + index.refresh_interval: -1 + number_of_replicas: 0 + + - do: + index: + index: test_1 + type: test + id: 1 + body: { foo: bar } + + - do: + search: + rest_total_hits_as_int: true + index: test_1 + body: + query: { term: { _id: 1 }} + + - match: { hits.total: 0 } + + - do: + index: + index: test_1 + type: test + id: 2 + refresh: true + body: { foo: bar } + - is_true: forced_refresh + + - do: + search: + rest_total_hits_as_int: true + index: test_1 + body: + query: { term: { _id: 2 }} + + - match: { hits.total: 1 } + +--- +"When refresh url parameter is an empty string that means \"refresh immediately\"": + - do: + index: + index: test_1 + type: test + id: 1 + refresh: "" + body: { foo: bar } + - is_true: forced_refresh + + - do: + search: + rest_total_hits_as_int: true + index: test_1 + body: + query: { term: { _id: 1 }} + + - match: { hits.total: 1 } + +--- +"refresh=wait_for waits until changes are visible in search": + - do: + index: + index: index_60_refresh_1 + type: test + id: index_60_refresh_id1 + body: { foo: bar } + refresh: wait_for + - is_false: forced_refresh + + - do: + search: + rest_total_hits_as_int: true + index: index_60_refresh_1 + body: + query: { term: { _id: index_60_refresh_id1 }} + - match: { hits.total: 1 } diff --git a/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/70_mix_typeless_typeful.yml b/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/70_mix_typeless_typeful.yml new file mode 100644 index 0000000000000..f3629fbb7cc18 --- /dev/null +++ b/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/70_mix_typeless_typeful.yml @@ -0,0 +1,102 @@ +--- +"Index with typeless API on an index that has types": + + - skip: + version: " - 6.99.99" + reason: Typeless APIs were introduced in 7.0.0 + + - do: + indices.create: # not using include_type_name: false on purpose + include_type_name: true + index: index + body: + mappings: + not_doc: + properties: + foo: + type: "keyword" + + - do: + index: + index: index + id: 1 + body: { foo: bar } + + - match: { _index: "index" } + - match: { _type: "_doc" } + - match: { _id: "1"} + - match: { _version: 1} + + - do: + get: # not using typeless API on purpose + index: index + type: not_doc + id: 1 + + - match: { _index: "index" } + - match: { _type: "not_doc" } # the important bit to check + - match: { _id: "1"} + - match: { _version: 1} + - match: { _source: { foo: bar }} + + + - do: + index: + index: index + body: { foo: bar } + + - match: { _index: "index" } + - match: { _type: "_doc" } + - match: { _version: 1} + - set: { _id: id } + + - do: + get: # using typeful API on purpose + index: index + type: not_doc + id: '$id' + + - match: { _index: "index" } + - match: { _type: "not_doc" } # the important bit to check + - match: { _id: $id} + - match: { _version: 1} + - match: { _source: { foo: bar }} + +--- +"Index call that introduces new field mappings": + + - skip: + version: " - 6.99.99" + reason: Typeless APIs were introduced in 7.0.0 + + - do: + indices.create: # not using include_type_name: false on purpose + include_type_name: true + index: index + body: + mappings: + not_doc: + properties: + foo: + type: "keyword" + - do: + index: + index: index + id: 2 + body: { new_field: value } + + - match: { _index: "index" } + - match: { _type: "_doc" } + - match: { _id: "2" } + - match: { _version: 1 } + + - do: + get: # using typeful API on purpose + index: index + type: not_doc + id: 2 + + - match: { _index: "index" } + - match: { _type: "not_doc" } + - match: { _id: "2" } + - match: { _version: 1} diff --git a/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/70_require_alias.yml b/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/70_require_alias.yml new file mode 100644 index 0000000000000..d718a5a9704de --- /dev/null +++ b/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/70_require_alias.yml @@ -0,0 +1,29 @@ +--- +"Set require_alias flag": + - skip: + version: " - 7.9.99" + reason: "require_alias flag added in 7.10" + - do: + catch: missing + index: + index: test_require_alias + require_alias: true + body: { foo: bar } + - do: + catch: missing + indices.get: + index: test_require_alias + + - do: + indices.create: + index: backing_index + body: + mappings: {} + aliases: + test_require_alias: {} + + - do: + index: + index: test_require_alias + require_alias: true + body: { foo: bar } diff --git a/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/80_date_nanos.yml b/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/80_date_nanos.yml new file mode 100644 index 0000000000000..fe9adb7e42b03 --- /dev/null +++ b/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/80_date_nanos.yml @@ -0,0 +1,36 @@ +--- +"date_nanos requires dates after 1970 and before 2262": + - skip: + version: " - 6.99.99" + reason: "Implemented in 7.0" + + - do: + indices.create: + index: date_ns + body: + settings: + number_of_shards: 3 + number_of_replicas: 0 + mappings: + properties: + date: + type: date_nanos + field: + type: long + + - do: + bulk: + refresh: true + body: + - '{ "index" : { "_index" : "date_ns", "_id" : "date_ns_1" } }' + - '{"date" : "1969-10-28T12:12:12.123456789Z" }' + - '{ "index" : { "_index" : "date_ns", "_id" : "date_ns_2" } }' + - '{"date" : "2263-10-29T12:12:12.123456789Z" }' + + - match: { errors: true } + - match: { items.0.index.status: 400 } + - match: { items.0.index.error.type: mapper_parsing_exception } + - match: { items.0.index.error.caused_by.reason: "date[1969-10-28T12:12:12.123456789Z] is before the epoch in 1970 and cannot be stored in nanosecond resolution" } + - match: { items.1.index.status: 400 } + - match: { items.1.index.error.type: mapper_parsing_exception } + - match: { items.1.index.error.caused_by.reason: "date[2263-10-29T12:12:12.123456789Z] is after 2262-04-11T23:47:16.854775807 and cannot be stored in nanosecond resolution" } diff --git a/server/src/main/java/org/elasticsearch/action/DocWriteResponse.java b/server/src/main/java/org/elasticsearch/action/DocWriteResponse.java index c30b260716dcc..be97c44cc7260 100644 --- a/server/src/main/java/org/elasticsearch/action/DocWriteResponse.java +++ b/server/src/main/java/org/elasticsearch/action/DocWriteResponse.java @@ -52,6 +52,7 @@ * A base class for the response of a write operation that involves a single doc */ public abstract class DocWriteResponse extends ReplicationResponse implements WriteResponse, StatusToXContentObject { + static final String TYPE_FIELD_NAME = "_type"; private static final String _SHARDS = "_shards"; private static final String _INDEX = "_index"; @@ -304,6 +305,9 @@ private void writeWithoutShardId(StreamOutput out) throws IOException { @Override public final XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(); + if (builder.getCompatibleMajorVersion() == Version.V_7_0_0.major) { + builder.field(TYPE_FIELD_NAME, MapperService.SINGLE_MAPPING_NAME); + } innerToXContent(builder, params); builder.endObject(); return builder; diff --git a/server/src/main/java/org/elasticsearch/index/get/GetResult.java b/server/src/main/java/org/elasticsearch/index/get/GetResult.java index 459fd67be7190..673dcd3481977 100644 --- a/server/src/main/java/org/elasticsearch/index/get/GetResult.java +++ b/server/src/main/java/org/elasticsearch/index/get/GetResult.java @@ -28,6 +28,7 @@ import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Writeable; +import org.elasticsearch.common.text.Text; import org.elasticsearch.common.xcontent.ToXContentObject; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentHelper; @@ -51,6 +52,9 @@ public class GetResult implements Writeable, Iterable, ToXContentObject { + private static final String TYPE_FIELD_NAME = "_type"; + private static final Text SINGLE_MAPPING_TYPE = new Text(MapperService.SINGLE_MAPPING_NAME); + public static final String _INDEX = "_index"; public static final String _ID = "_id"; private static final String _VERSION = "_version"; @@ -293,6 +297,9 @@ public XContentBuilder toXContentEmbedded(XContentBuilder builder, Params params public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(); builder.field(_INDEX, index); + if (builder.getCompatibleMajorVersion() == Version.V_7_0_0.major) { + builder.field(TYPE_FIELD_NAME, SINGLE_MAPPING_TYPE); + } builder.field(_ID, id); if (isExists()) { if (version != -1) { diff --git a/server/src/main/java/org/elasticsearch/rest/action/document/RestIndexAction.java b/server/src/main/java/org/elasticsearch/rest/action/document/RestIndexAction.java index b40cd1d2deb48..008f9692d91e8 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/document/RestIndexAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/document/RestIndexAction.java @@ -53,7 +53,7 @@ public String getName() { return "document_index_action"; } - public static final class CreateHandler extends RestIndexAction { + public static class CreateHandler extends RestIndexAction { @Override public String getName() { @@ -81,7 +81,7 @@ void validateOpType(String opType) { } } - public static final class AutoIdHandler extends RestIndexAction { + public static class AutoIdHandler extends RestIndexAction { private final Supplier nodesInCluster; diff --git a/x-pack/plugin/rest-compatibility/src/main/java/org/elasticsearch/compat/CompatibleVersionPlugin.java b/x-pack/plugin/rest-compatibility/src/main/java/org/elasticsearch/compat/CompatibleVersionPlugin.java index d65e014850cc5..99b78e4e2a91f 100644 --- a/x-pack/plugin/rest-compatibility/src/main/java/org/elasticsearch/compat/CompatibleVersionPlugin.java +++ b/x-pack/plugin/rest-compatibility/src/main/java/org/elasticsearch/compat/CompatibleVersionPlugin.java @@ -7,14 +7,29 @@ import org.elasticsearch.ElasticsearchStatusException; import org.elasticsearch.Version; +import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; +import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.common.Nullable; +import org.elasticsearch.common.settings.ClusterSettings; +import org.elasticsearch.common.settings.IndexScopedSettings; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.settings.SettingsFilter; import org.elasticsearch.common.xcontent.MediaType; import org.elasticsearch.common.xcontent.ParsedMediaType; +import org.elasticsearch.plugins.ActionPlugin; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.plugins.RestCompatibilityPlugin; +import org.elasticsearch.rest.RestController; +import org.elasticsearch.rest.RestHandler; import org.elasticsearch.rest.RestStatus; +import org.elasticsearch.rest.action.document.RestGetActionV7; +import org.elasticsearch.rest.action.document.RestIndexActionV7; -public class CompatibleVersionPlugin extends Plugin implements RestCompatibilityPlugin { +import java.util.Collections; +import java.util.List; +import java.util.function.Supplier; + +public class CompatibleVersionPlugin extends Plugin implements RestCompatibilityPlugin, ActionPlugin { @Override public Version getCompatibleVersion( @@ -93,4 +108,23 @@ static Byte parseVersion(ParsedMediaType parsedMediaType) { } return null; } + + @Override + public List getRestHandlers(Settings settings, + RestController restController, + ClusterSettings clusterSettings, + IndexScopedSettings indexScopedSettings, + SettingsFilter settingsFilter, + IndexNameExpressionResolver indexNameExpressionResolver, + Supplier nodesInCluster) { + if (Version.CURRENT.major == 8) { + return List.of( + new RestGetActionV7(), + new RestIndexActionV7.CompatibleRestIndexAction(), + new RestIndexActionV7.CompatibleCreateHandler(), + new RestIndexActionV7.CompatibleAutoIdHandler(nodesInCluster) + ); + } + return Collections.emptyList(); + } } diff --git a/x-pack/plugin/rest-compatibility/src/main/java/org/elasticsearch/rest/action/document/RestGetActionV7.java b/x-pack/plugin/rest-compatibility/src/main/java/org/elasticsearch/rest/action/document/RestGetActionV7.java new file mode 100644 index 0000000000000..d707f39980a08 --- /dev/null +++ b/x-pack/plugin/rest-compatibility/src/main/java/org/elasticsearch/rest/action/document/RestGetActionV7.java @@ -0,0 +1,47 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +package org.elasticsearch.rest.action.document; + +import org.elasticsearch.Version; +import org.elasticsearch.client.node.NodeClient; +import org.elasticsearch.common.logging.DeprecationLogger; +import org.elasticsearch.rest.RestRequest; + +import java.io.IOException; +import java.util.List; + +import static org.elasticsearch.rest.RestRequest.Method.GET; +import static org.elasticsearch.rest.RestRequest.Method.HEAD; + +public class RestGetActionV7 extends RestGetAction { + + private static final DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(RestGetActionV7.class); + static final String TYPES_DEPRECATION_MESSAGE = "[types removal] Specifying types in " + + "document get requests is deprecated, use the /{index}/_doc/{id} endpoint instead."; + + @Override + public String getName() { + return super.getName() + "_v7"; + } + + @Override + public List routes() { + return List.of(new Route(GET, "/{index}/{type}/{id}"), new Route(HEAD, "/{index}/{type}/{id}")); + } + + @Override + public RestChannelConsumer prepareRequest(RestRequest request, final NodeClient client) throws IOException { +// deprecationLogger.deprecate("get_with_types", TYPES_DEPRECATION_MESSAGE); + request.param("type"); + return super.prepareRequest(request, client); + } + + @Override + public Version compatibleWithVersion() { + return Version.V_7_0_0; + } +} diff --git a/x-pack/plugin/rest-compatibility/src/main/java/org/elasticsearch/rest/action/document/RestIndexActionV7.java b/x-pack/plugin/rest-compatibility/src/main/java/org/elasticsearch/rest/action/document/RestIndexActionV7.java new file mode 100644 index 0000000000000..fb733806ce757 --- /dev/null +++ b/x-pack/plugin/rest-compatibility/src/main/java/org/elasticsearch/rest/action/document/RestIndexActionV7.java @@ -0,0 +1,130 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +/* + * 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.action.document; + +import org.elasticsearch.Version; +import org.elasticsearch.client.node.NodeClient; +import org.elasticsearch.cluster.node.DiscoveryNodes; +import org.elasticsearch.common.logging.DeprecationLogger; +import org.elasticsearch.rest.RestRequest; + +import java.io.IOException; +import java.util.List; +import java.util.function.Supplier; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.POST; +import static org.elasticsearch.rest.RestRequest.Method.PUT; + +public class RestIndexActionV7 { + static final String TYPES_DEPRECATION_MESSAGE = "[types removal] Specifying types in document " + + "index requests is deprecated, use the typeless endpoints instead (/{index}/_doc/{id}, /{index}/_doc, " + + "or /{index}/_create/{id})."; + private static final DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(RestIndexActionV7.class); + + private static void logDeprecationMessage() { +// deprecationLogger.deprecate("index_with_types", TYPES_DEPRECATION_MESSAGE); + } + + public static class CompatibleRestIndexAction extends RestIndexAction { + @Override + public String getName() { + return super.getName() + "_v7"; + } + + @Override + public List routes() { + return List.of(new Route(POST, "/{index}/{type}/{id}"), new Route(PUT, "/{index}/{type}/{id}")); + } + + @Override + public RestChannelConsumer prepareRequest(RestRequest request, final NodeClient client) throws IOException { + logDeprecationMessage(); + request.param("type"); + return super.prepareRequest(request, client); + } + + @Override + public Version compatibleWithVersion() { + return Version.V_7_0_0; + } + } + + public static class CompatibleCreateHandler extends RestIndexAction.CreateHandler { + + @Override + public String getName() { + return "document_create_action_v7"; + } + + @Override + public List routes() { + return List.of(new Route(POST, "/{index}/{type}/{id}/_create"), new Route(PUT, "/{index}/{type}/{id}/_create")); + } + + @Override + public RestChannelConsumer prepareRequest(RestRequest request, final NodeClient client) throws IOException { + logDeprecationMessage(); + request.param("type"); + return super.prepareRequest(request, client); + } + + @Override + public Version compatibleWithVersion() { + return Version.V_7_0_0; + } + } + + public static final class CompatibleAutoIdHandler extends RestIndexAction.AutoIdHandler { + + public CompatibleAutoIdHandler(Supplier nodesInCluster) { + super(nodesInCluster); + } + + @Override + public String getName() { + return "document_create_action_auto_id_v7"; + } + + @Override + public List routes() { + return singletonList(new Route(POST, "/{index}/{type}")); + } + + @Override + public RestChannelConsumer prepareRequest(RestRequest request, final NodeClient client) throws IOException { + logDeprecationMessage(); + request.param("type"); + return super.prepareRequest(request, client); + } + + @Override + public Version compatibleWithVersion() { + return Version.V_7_0_0; + } + + } +} diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/SecurityRestFilter.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/SecurityRestFilter.java index 3b27d7b52061b..f63c4b36d1850 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/SecurityRestFilter.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/SecurityRestFilter.java @@ -10,6 +10,7 @@ import org.apache.logging.log4j.message.ParameterizedMessage; import org.apache.logging.log4j.util.Supplier; import org.elasticsearch.ExceptionsHelper; +import org.elasticsearch.Version; import org.elasticsearch.action.ActionListener; import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.util.Maps; @@ -159,4 +160,9 @@ private RestRequest maybeWrapRestRequest(RestRequest restRequest) throws IOExcep public MediaTypeRegistry validAcceptMediaTypes() { return restHandler.validAcceptMediaTypes(); } + + @Override + public Version compatibleWithVersion() { + return restHandler.compatibleWithVersion(); + } } From 92be086357d147293ddd9b9d11efc182c7bf8ae9 Mon Sep 17 00:00:00 2001 From: pgomulka Date: Thu, 7 Jan 2021 16:40:31 +0100 Subject: [PATCH 3/3] draft --- rest-api-spec/build.gradle | 2 +- .../test/{index => compat_index}/10_with_id.yml | 1 - .../11_with_id_with_types.yml} | 12 +++++++----- .../test/{index => compat_index}/12_result.yml | 0 .../{index => compat_index}/13_result_with_types.yml | 0 .../test/{index => compat_index}/15_without_id.yml | 0 .../16_without_id_with_types.yml | 0 .../test/{index => compat_index}/20_optype.yml | 0 .../{index => compat_index}/21_optype_with_types.yml | 0 .../test/{index => compat_index}/30_cas.yml | 0 .../{index => compat_index}/35_external_version.yml | 0 .../36_external_gte_version.yml | 0 .../37_external_version_with_types.yml | 0 .../38_external_gte_version_with_types.yml | 0 .../test/{index => compat_index}/40_routing.yml | 0 .../41_routing_with_types.yml | 0 .../test/{index => compat_index}/60_refresh.yml | 0 .../61_refresh_with_types.yml | 0 .../70_mix_typeless_typeful.yml | 0 .../{index => compat_index}/70_require_alias.yml | 0 .../test/{index => compat_index}/80_date_nanos.yml | 0 21 files changed, 8 insertions(+), 7 deletions(-) rename rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/{index => compat_index}/10_with_id.yml (99%) rename rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/{index/11_with_id_with_types_compat.yml => compat_index/11_with_id_with_types.yml} (75%) rename rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/{index => compat_index}/12_result.yml (100%) rename rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/{index => compat_index}/13_result_with_types.yml (100%) rename rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/{index => compat_index}/15_without_id.yml (100%) rename rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/{index => compat_index}/16_without_id_with_types.yml (100%) rename rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/{index => compat_index}/20_optype.yml (100%) rename rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/{index => compat_index}/21_optype_with_types.yml (100%) rename rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/{index => compat_index}/30_cas.yml (100%) rename rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/{index => compat_index}/35_external_version.yml (100%) rename rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/{index => compat_index}/36_external_gte_version.yml (100%) rename rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/{index => compat_index}/37_external_version_with_types.yml (100%) rename rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/{index => compat_index}/38_external_gte_version_with_types.yml (100%) rename rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/{index => compat_index}/40_routing.yml (100%) rename rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/{index => compat_index}/41_routing_with_types.yml (100%) rename rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/{index => compat_index}/60_refresh.yml (100%) rename rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/{index => compat_index}/61_refresh_with_types.yml (100%) rename rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/{index => compat_index}/70_mix_typeless_typeful.yml (100%) rename rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/{index => compat_index}/70_require_alias.yml (100%) rename rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/{index => compat_index}/80_date_nanos.yml (100%) diff --git a/rest-api-spec/build.gradle b/rest-api-spec/build.gradle index 21de7ebf0c8a4..f8ebdaaf97b61 100644 --- a/rest-api-spec/build.gradle +++ b/rest-api-spec/build.gradle @@ -28,7 +28,7 @@ tasks.named("yamlRestCompatTest").configure { [ //tests use types 'ingest/200_dissect_processor/Test dissect processor mismatch', - 'ingest/80_foreach/Test foreach Processor' // <-- manually overridden in yamlRestCompatTest + 'ingest/80_foreach/Test foreach rocessor' // <-- manually overridden in yamlRestCompatTest ] ).join(",") } diff --git a/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/10_with_id.yml b/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/compat_index/10_with_id.yml similarity index 99% rename from rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/10_with_id.yml rename to rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/compat_index/10_with_id.yml index 809a91d6da8da..a129dcab80d9a 100644 --- a/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/10_with_id.yml +++ b/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/compat_index/10_with_id.yml @@ -1,4 +1,3 @@ - --- "Index with ID": diff --git a/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/11_with_id_with_types_compat.yml b/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/compat_index/11_with_id_with_types.yml similarity index 75% rename from rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/11_with_id_with_types_compat.yml rename to rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/compat_index/11_with_id_with_types.yml index af69ceb7f2293..3d1beba5c5335 100644 --- a/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/11_with_id_with_types_compat.yml +++ b/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/compat_index/11_with_id_with_types.yml @@ -1,4 +1,3 @@ -# ./gradlew ':rest-api-spec:yamlRestCompatTest' --tests "org.elasticsearch.test.rest.ClientYamlTestSuiteIT" -Dtests.method="test {p0=index/11_with_id_with_types_compat/*}" --- setup: - skip: @@ -9,8 +8,8 @@ setup: - do: headers: - Content-Type: "application/vnd.elasticsearch+json;compatible-with=7" - Accept: "application/vnd.elasticsearch+json;compatible-with=7" + Content-Type: "application/vnd.elasticsearch+json;compatible-with=7" + Accept: "application/vnd.elasticsearch+json;compatible-with=7" index: index: test-weird-index-中文 type: weird.type @@ -24,8 +23,8 @@ setup: - do: headers: - Content-Type: "application/vnd.elasticsearch+json;compatible-with=7" - Accept: "application/vnd.elasticsearch+json;compatible-with=7" + Content-Type: "application/vnd.elasticsearch+json;compatible-with=7" + Accept: "application/vnd.elasticsearch+json;compatible-with=7" get: index: test-weird-index-中文 type: weird.type @@ -38,6 +37,9 @@ setup: - match: { _source: { foo: bar }} - do: + headers: + Content-Type: "application/vnd.elasticsearch+json;compatible-with=7" + Accept: "application/vnd.elasticsearch+json;compatible-with=7" catch: bad_request index: index: idx diff --git a/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/12_result.yml b/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/compat_index/12_result.yml similarity index 100% rename from rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/12_result.yml rename to rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/compat_index/12_result.yml diff --git a/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/13_result_with_types.yml b/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/compat_index/13_result_with_types.yml similarity index 100% rename from rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/13_result_with_types.yml rename to rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/compat_index/13_result_with_types.yml diff --git a/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/15_without_id.yml b/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/compat_index/15_without_id.yml similarity index 100% rename from rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/15_without_id.yml rename to rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/compat_index/15_without_id.yml diff --git a/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/16_without_id_with_types.yml b/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/compat_index/16_without_id_with_types.yml similarity index 100% rename from rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/16_without_id_with_types.yml rename to rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/compat_index/16_without_id_with_types.yml diff --git a/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/20_optype.yml b/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/compat_index/20_optype.yml similarity index 100% rename from rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/20_optype.yml rename to rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/compat_index/20_optype.yml diff --git a/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/21_optype_with_types.yml b/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/compat_index/21_optype_with_types.yml similarity index 100% rename from rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/21_optype_with_types.yml rename to rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/compat_index/21_optype_with_types.yml diff --git a/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/30_cas.yml b/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/compat_index/30_cas.yml similarity index 100% rename from rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/30_cas.yml rename to rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/compat_index/30_cas.yml diff --git a/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/35_external_version.yml b/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/compat_index/35_external_version.yml similarity index 100% rename from rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/35_external_version.yml rename to rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/compat_index/35_external_version.yml diff --git a/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/36_external_gte_version.yml b/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/compat_index/36_external_gte_version.yml similarity index 100% rename from rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/36_external_gte_version.yml rename to rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/compat_index/36_external_gte_version.yml diff --git a/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/37_external_version_with_types.yml b/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/compat_index/37_external_version_with_types.yml similarity index 100% rename from rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/37_external_version_with_types.yml rename to rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/compat_index/37_external_version_with_types.yml diff --git a/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/38_external_gte_version_with_types.yml b/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/compat_index/38_external_gte_version_with_types.yml similarity index 100% rename from rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/38_external_gte_version_with_types.yml rename to rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/compat_index/38_external_gte_version_with_types.yml diff --git a/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/40_routing.yml b/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/compat_index/40_routing.yml similarity index 100% rename from rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/40_routing.yml rename to rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/compat_index/40_routing.yml diff --git a/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/41_routing_with_types.yml b/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/compat_index/41_routing_with_types.yml similarity index 100% rename from rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/41_routing_with_types.yml rename to rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/compat_index/41_routing_with_types.yml diff --git a/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/60_refresh.yml b/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/compat_index/60_refresh.yml similarity index 100% rename from rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/60_refresh.yml rename to rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/compat_index/60_refresh.yml diff --git a/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/61_refresh_with_types.yml b/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/compat_index/61_refresh_with_types.yml similarity index 100% rename from rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/61_refresh_with_types.yml rename to rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/compat_index/61_refresh_with_types.yml diff --git a/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/70_mix_typeless_typeful.yml b/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/compat_index/70_mix_typeless_typeful.yml similarity index 100% rename from rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/70_mix_typeless_typeful.yml rename to rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/compat_index/70_mix_typeless_typeful.yml diff --git a/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/70_require_alias.yml b/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/compat_index/70_require_alias.yml similarity index 100% rename from rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/70_require_alias.yml rename to rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/compat_index/70_require_alias.yml diff --git a/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/80_date_nanos.yml b/rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/compat_index/80_date_nanos.yml similarity index 100% rename from rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/index/80_date_nanos.yml rename to rest-api-spec/src/yamlRestCompatTest/resources/rest-api-spec/test/compat_index/80_date_nanos.yml