Skip to content

Commit 29bb00a

Browse files
committed
[Rest Api Compatibility] Licence accept_enterprise and response changes
in elastic#50067 the accept_enterprise = false was no longer supported. This commit allows it under rest compatibility and ignores. in elastic#5073 there were changes when max_nodes and max_resource_units can exist. This does not require compatible changes as it feels to be behaviour change. Requires some testing transformation though relates elastic#51816
1 parent 5485d3e commit 29bb00a

File tree

8 files changed

+95
-32
lines changed

8 files changed

+95
-32
lines changed

build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/test/rest/YamlRestCompatTestPluginFuncTest.groovy

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,8 @@ class YamlRestCompatTestPluginFuncTest extends AbstractRestResourcesFuncTest {
212212
task.replaceKeyInMatch("match_.some.key_to_replace", "match_.some.key_that_was_replaced")
213213
task.replaceKeyInLength("key.in_length_to_replace", "key.in_length_that_was_replaced")
214214
task.replaceValueTextByKeyValue("keyvalue", "toreplace", "replacedkeyvalue")
215-
task.replaceValueTextByKeyValue("index", "test", "test2", "two")
215+
task.replaceValueTextByKeyValue("index", "ll", "test2", "two")
216+
task.replaceValueInLength("something", 2, "one")
216217
})
217218
// can't actually spin up test cluster from this test
218219
tasks.withType(Test).configureEach{ enabled = false }
@@ -239,6 +240,7 @@ class YamlRestCompatTestPluginFuncTest extends AbstractRestResourcesFuncTest {
239240
- is_true: "value_not_to_replace"
240241
- is_false: "value_not_to_replace"
241242
- length: { key.in_length_to_replace: 1 }
243+
- length: { "something": 1 }
242244
---
243245
"two":
244246
- do:
@@ -284,10 +286,6 @@ class YamlRestCompatTestPluginFuncTest extends AbstractRestResourcesFuncTest {
284286
---
285287
one:
286288
- do:
287-
do_.some.key_that_was_replaced:
288-
index: "test"
289-
id: 1
290-
keyvalue : replacedkeyvalue
291289
warnings:
292290
- "warning1"
293291
- "warning2"
@@ -298,6 +296,10 @@ class YamlRestCompatTestPluginFuncTest extends AbstractRestResourcesFuncTest {
298296
- "added allowed warning"
299297
allowed_warnings_regex:
300298
- "added allowed warning regex .* [0-9]"
299+
do_.some.key_that_was_replaced:
300+
index: "test"
301+
id: 1
302+
keyvalue: "replacedkeyvalue"
301303
- match:
302304
_source.values:
303305
- "z"
@@ -314,17 +316,19 @@ class YamlRestCompatTestPluginFuncTest extends AbstractRestResourcesFuncTest {
314316
- is_false: "replaced_value"
315317
- is_true: "value_not_to_replace"
316318
- is_false: "value_not_to_replace"
317-
- length: { key.in_length_that_was_replaced: 1 }
319+
- length:
320+
key.in_length_that_was_replaced: 1
321+
- length:
322+
something: 2
318323
- match:
319324
_source.added:
320325
name: "jake"
321326
likes: "cheese"
322-
323327
---
324328
two:
325329
- do:
326330
get:
327-
index: "test2"
331+
index: "test"
328332
id: 1
329333
headers:
330334
Content-Type: "application/vnd.elasticsearch+json;compatible-with=7"
@@ -347,15 +351,14 @@ class YamlRestCompatTestPluginFuncTest extends AbstractRestResourcesFuncTest {
347351
- is_true: "value_not_to_replace"
348352
- is_false: "value_not_to_replace"
349353
---
350-
"use cat with no header":
351-
- do:
352-
cat.indices:
353-
{}
354-
allowed_warnings:
355-
- "added allowed warning"
356-
allowed_warnings_regex:
357-
- "added allowed warning regex .* [0-9]"
358-
- match: {}
354+
use cat with no header:
355+
- do:
356+
cat.indices: {}
357+
allowed_warnings:
358+
- "added allowed warning"
359+
allowed_warnings_regex:
360+
- "added allowed warning regex .* [0-9]"
361+
- match: {}
359362
""".stripIndent()).readAll()
360363

361364
expectedAll.eachWithIndex{ ObjectNode expected, int i ->

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/rest/compat/RestCompatTestTransformTask.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import com.fasterxml.jackson.databind.ObjectReader;
1414
import com.fasterxml.jackson.databind.ObjectWriter;
1515
import com.fasterxml.jackson.databind.SequenceWriter;
16+
import com.fasterxml.jackson.databind.node.IntNode;
1617
import com.fasterxml.jackson.databind.node.ObjectNode;
1718
import com.fasterxml.jackson.databind.node.TextNode;
1819
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
@@ -24,6 +25,7 @@
2425
import org.elasticsearch.gradle.internal.test.rest.transform.do_.ReplaceKeyInDo;
2526
import org.elasticsearch.gradle.internal.test.rest.transform.headers.InjectHeaders;
2627
import org.elasticsearch.gradle.internal.test.rest.transform.length.ReplaceKeyInLength;
28+
import org.elasticsearch.gradle.internal.test.rest.transform.length.ReplaceValueInLength;
2729
import org.elasticsearch.gradle.internal.test.rest.transform.match.AddMatch;
2830
import org.elasticsearch.gradle.internal.test.rest.transform.match.RemoveMatch;
2931
import org.elasticsearch.gradle.internal.test.rest.transform.match.ReplaceKeyInMatch;
@@ -152,6 +154,10 @@ public void replaceKeyInLength(String oldKeyName, String newKeyName) {
152154
transformations.add(new ReplaceKeyInLength(oldKeyName, newKeyName, null));
153155
}
154156

157+
public void replaceValueInLength(String oldKeyName, int newValue, String testName) {
158+
transformations.add(new ReplaceValueInLength(oldKeyName, MAPPER.convertValue(newValue, IntNode.class), testName));
159+
}
160+
155161
/**
156162
* A transformation to replace the key in a match assertion.
157163
* @see ReplaceKeyInMatch
@@ -162,6 +168,8 @@ public void replaceKeyInMatch(String oldKeyName, String newKeyName) {
162168
transformations.add(new ReplaceKeyInMatch(oldKeyName, newKeyName, null));
163169
}
164170

171+
172+
165173
/**
166174
* Replaces all the values of a is_true assertion for all project REST tests.
167175
* For example "is_true": "value_to_replace" to "is_true": "value_replaced"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0 and the Server Side Public License, v 1; you may not use this file except
5+
* in compliance with, at your election, the Elastic License 2.0 or the Server
6+
* Side Public License, v 1.
7+
*/
8+
9+
package org.elasticsearch.gradle.internal.test.rest.transform.length;
10+
11+
import com.fasterxml.jackson.databind.JsonNode;
12+
import com.fasterxml.jackson.databind.node.ObjectNode;
13+
14+
import org.elasticsearch.gradle.internal.test.rest.transform.ReplaceByKey;
15+
import org.gradle.api.tasks.Internal;
16+
17+
/**
18+
* A transformation to replace the value in a length assertion.
19+
* For example, change from "length":{"index._type": 1} to "length":{"index._type": 2}
20+
*/
21+
public class ReplaceValueInLength extends ReplaceByKey {
22+
23+
public ReplaceValueInLength(String replaceKey, JsonNode replacementNode, String testName) {
24+
super(replaceKey, replaceKey, replacementNode, testName);
25+
}
26+
27+
@Override
28+
@Internal
29+
public String getKeyToFind() {
30+
return "length";
31+
}
32+
33+
@Override
34+
public void transformTest(ObjectNode lengthParent) {
35+
ObjectNode lengthNode = (ObjectNode) lengthParent.get(getKeyToFind());
36+
lengthNode.remove(requiredChildKey());
37+
lengthNode.set(getNewChildKey(), getReplacementNode());
38+
}
39+
}

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/test/rest/transform/text/ReplaceTextual.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import org.gradle.api.tasks.Optional;
1919

2020
/**
21-
* A transformation to replace a key/value combination.
21+
* A transformation to replace a key/value combination.
2222
*/
2323
public class ReplaceTextual implements RestTestTransformByParentObject {
2424
private final String keyToReplaceName;

modules/parent-join/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ restResources {
2222

2323
tasks.named("yamlRestCompatTest").configure {
2424
systemProperty 'tests.rest.blacklist', [
25-
'/30_inner_hits/Test two sub-queries with only one having inner_hits'
25+
// '/30_inner_hits/Test two sub-queries with only one having inner_hits'
2626
].join(',')
2727
}

x-pack/plugin/build.gradle

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,19 @@ def v7compatibilityNotSupportedTests = {
139139
'ml/datafeeds_crud/Test update datafeed to point to missing job',
140140
'ml/datafeeds_crud/Test update datafeed to point to different job',
141141
'ml/datafeeds_crud/Test update datafeed to point to job already attached to another datafeed',
142+
//rollup was an experimental feature
143+
//https://github.com/elastic/elasticsearch/pull/41227.
144+
'rollup/delete_job/Test basic delete_job',
145+
'rollup/delete_job/Test delete job twice',
146+
'rollup/delete_job/Test delete running job',
147+
'rollup/get_jobs/Test basic get_jobs',
148+
'rollup/put_job/Test basic put_job',
149+
//https://github.com/elastic/elasticsearch/pull/41502
150+
'rollup/start_job/Test start job twice',
151+
152+
// a type field was added to cat.ml_trained_models #73660, this is a backwards compatible change.
153+
// still this is a cat api, and we don't support them with rest api compatibility. (the test would be very hard to transform too)
154+
'ml/trained_model_cat_apis/Test cat trained models'
142155
]
143156
}
144157

@@ -151,17 +164,7 @@ tasks.named("yamlRestCompatTest").configure {
151164

152165
//TODO: blacklist specific to REST API compatibility
153166
restTestBlacklist.addAll([
154-
'license/30_enterprise_license/Installing enterprise license',
155-
//https://github.com/elastic/elasticsearch/pull/41227.
156-
'rollup/delete_job/Test basic delete_job',
157-
'rollup/delete_job/Test delete job twice',
158-
'rollup/delete_job/Test delete running job',
159-
'rollup/get_jobs/Test basic get_jobs',
160-
'rollup/put_job/Test basic put_job',
161-
//https://github.com/elastic/elasticsearch/pull/41502
162-
'rollup/start_job/Test start job twice',
163-
// a type field was added to cat.ml_trained_models #73660, this might need some work
164-
'ml/trained_model_cat_apis/Test cat trained models'
167+
// 'license/30_enterprise_license/Installing enterprise license',
165168
] + v7compatibilityNotSupportedTests())
166169

167170

@@ -220,4 +223,9 @@ tasks.named("precommit").configure {
220223
tasks.named("transformV7RestTests").configure({ task ->
221224
task.replaceValueInMatch("_type", "_doc")
222225
task.addAllowedWarningRegex("\\[types removal\\].*")
226+
task.replaceValueInLength("license", 12, "Installing enterprise license")
227+
task.replaceValueInMatch("license.type", "enterprise", "Installing enterprise license")
228+
task.replaceValueInMatch("license.mode", "enterprise", "Installing enterprise license")
229+
task.addAllowedWarningRegexForTest("Including \\[accept_enterprise\\] in get license.*", "Installing enterprise license")
230+
task.replaceValueInMatch("license.max_nodes", null, "Installing enterprise license")
223231
})

x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestGetLicenseAction.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.util.List;
2626
import java.util.Map;
2727

28+
import static org.elasticsearch.core.RestApiVersion.onOrAfter;
2829
import static org.elasticsearch.rest.RestRequest.Method.GET;
2930
import static org.elasticsearch.rest.RestStatus.NOT_FOUND;
3031
import static org.elasticsearch.rest.RestStatus.OK;
@@ -66,7 +67,8 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC
6667
deprecationLogger.deprecate(DeprecationCategory.API, "get_license_accept_enterprise",
6768
"Including [accept_enterprise] in get license requests is deprecated." +
6869
" The parameter will be removed in the next major version");
69-
if (request.paramAsBoolean("accept_enterprise", true) == false) {
70+
if (request.paramAsBoolean("accept_enterprise", true) == false
71+
&& request.getRestApiVersion().matches(onOrAfter(RestApiVersion.V_8))) {
7072
throw new IllegalArgumentException("The [accept_enterprise] parameters may not be false");
7173
}
7274
}

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rest/action/RestXPackInfoAction.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.elasticsearch.client.node.NodeClient;
1010
import org.elasticsearch.common.logging.DeprecationCategory;
1111
import org.elasticsearch.common.logging.DeprecationLogger;
12+
import org.elasticsearch.core.RestApiVersion;
1213
import org.elasticsearch.protocol.xpack.XPackInfoRequest;
1314
import org.elasticsearch.rest.BaseRestHandler;
1415
import org.elasticsearch.rest.RestRequest;
@@ -19,6 +20,7 @@
1920
import java.util.EnumSet;
2021
import java.util.List;
2122

23+
import static org.elasticsearch.core.RestApiVersion.onOrAfter;
2224
import static org.elasticsearch.rest.RestRequest.Method.GET;
2325
import static org.elasticsearch.rest.RestRequest.Method.HEAD;
2426

@@ -50,7 +52,8 @@ public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client
5052
deprecationLogger.deprecate(DeprecationCategory.API, "get_license_accept_enterprise",
5153
"Including [accept_enterprise] in get license requests is deprecated." +
5254
" The parameter will be removed in the next major version");
53-
if (request.paramAsBoolean("accept_enterprise", true) == false) {
55+
if (request.paramAsBoolean("accept_enterprise", true) == false
56+
&& request.getRestApiVersion().matches(onOrAfter(RestApiVersion.V_8))) {
5457
throw new IllegalArgumentException("The [accept_enterprise] parameters may not be false");
5558
}
5659
}

0 commit comments

Comments
 (0)