Skip to content

Commit 4b818e5

Browse files
pgomulkaywangd
authored andcommitted
[Rest Api Compatibility] Licence accept_enterprise and response changes (elastic#75479)
in elastic#50067 for _license the accept_enterprise = false was no longer supported. This commit allows it under rest compatibility and is showing enterprise licenses as platinum The same change had to be applied to _xpack endpoint elastic#58217 in elastic#50735 max_resource_units was introduced to be more accurate. For v7 requests, which do not know about enterprise license we will return max_node which will be set from max_resource_units (it assumes that one resource unit is 32GB - which corresponds to 1 node) relates elastic#51816
1 parent d3a9d7d commit 4b818e5

File tree

6 files changed

+68
-26
lines changed

6 files changed

+68
-26
lines changed

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

+1-1
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;

x-pack/plugin/build.gradle

+14-16
Original file line numberDiff line numberDiff line change
@@ -139,19 +139,7 @@ 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-
]
143-
}
144-
145-
tasks.named("yamlRestCompatTest").configure {
146-
/*
147-
* We have to disable setting the number of available processors as tests in the same JVM randomize processors and will step on each
148-
* other if we allow them to set the number of available processors as it's set-once in Netty.
149-
*/
150-
systemProperty 'es.set.netty.runtime.available.processors', 'false'
151-
152-
//TODO: blacklist specific to REST API compatibility
153-
restTestBlacklist.addAll([
154-
'license/30_enterprise_license/Installing enterprise license',
142+
//rollup was an experimental feature
155143
//https://github.com/elastic/elasticsearch/pull/41227.
156144
'rollup/delete_job/Test basic delete_job',
157145
'rollup/delete_job/Test delete job twice',
@@ -160,12 +148,21 @@ tasks.named("yamlRestCompatTest").configure {
160148
'rollup/put_job/Test basic put_job',
161149
//https://github.com/elastic/elasticsearch/pull/41502
162150
'rollup/start_job/Test start job twice',
163-
// a type field was added to cat.ml_trained_models #73660, this might need some work
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)
164154
'ml/trained_model_cat_apis/Test cat trained models'
165-
] + v7compatibilityNotSupportedTests())
155+
]
156+
}
166157

158+
tasks.named("yamlRestCompatTest").configure {
159+
/*
160+
* We have to disable setting the number of available processors as tests in the same JVM randomize processors and will step on each
161+
* other if we allow them to set the number of available processors as it's set-once in Netty.
162+
*/
163+
systemProperty 'es.set.netty.runtime.available.processors', 'false'
167164

168-
systemProperty 'tests.rest.blacklist', restTestBlacklist.join(',')
165+
systemProperty 'tests.rest.blacklist', v7compatibilityNotSupportedTests().join(',')
169166
dependsOn "copyExtraResources"
170167
}
171168

@@ -220,4 +217,5 @@ tasks.named("precommit").configure {
220217
tasks.named("transformV7RestTests").configure({ task ->
221218
task.replaceValueInMatch("_type", "_doc")
222219
task.addAllowedWarningRegex("\\[types removal\\].*")
220+
task.addAllowedWarningRegexForTest("Including \\[accept_enterprise\\] in get license.*", "Installing enterprise license")
223221
})

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

+13-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.elasticsearch.common.xcontent.XContentFactory;
2222
import org.elasticsearch.common.xcontent.XContentParser;
2323
import org.elasticsearch.common.xcontent.XContentType;
24+
import org.elasticsearch.core.RestApiVersion;
2425
import org.elasticsearch.protocol.xpack.license.LicenseStatus;
2526

2627
import java.io.IOException;
@@ -146,6 +147,12 @@ static boolean isEnterprise(String typeName) {
146147
* to a specific license version
147148
*/
148149
public static final String LICENSE_VERSION_MODE = "license_version";
150+
/**
151+
* Set for {@link RestApiVersion#V_7} requests only
152+
* XContent param name to map the "enterprise" license type to "platinum"
153+
* for backwards compatibility with older clients
154+
*/
155+
public static final String XCONTENT_HIDE_ENTERPRISE = "hide_enterprise";
149156

150157
public static final Comparator<License> LATEST_ISSUE_DATE_FIRST = Comparator.comparing(License::issueDate).reversed();
151158

@@ -516,6 +523,8 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
516523
public XContentBuilder toInnerXContent(XContentBuilder builder, Params params) throws IOException {
517524
boolean licenseSpecMode = params.paramAsBoolean(LICENSE_SPEC_VIEW_MODE, false);
518525
boolean restViewMode = params.paramAsBoolean(REST_VIEW_MODE, false);
526+
boolean hideEnterprise = params.paramAsBoolean(XCONTENT_HIDE_ENTERPRISE, false);
527+
519528
boolean previouslyHumanReadable = builder.humanReadable();
520529
if (licenseSpecMode && restViewMode) {
521530
throw new IllegalArgumentException("can have either " + REST_VIEW_MODE + " or " + LICENSE_SPEC_VIEW_MODE);
@@ -534,7 +543,8 @@ public XContentBuilder toInnerXContent(XContentBuilder builder, Params params) t
534543
builder.field(Fields.STATUS, status().label());
535544
}
536545
builder.field(Fields.UID, uid);
537-
builder.field(Fields.TYPE, type);
546+
final String bwcType = hideEnterprise && LicenseType.isEnterprise(type) ? LicenseType.PLATINUM.getTypeName() : type;
547+
builder.field(Fields.TYPE, bwcType);
538548
if (version == VERSION_START) {
539549
builder.field(Fields.SUBSCRIPTION_TYPE, subscriptionType);
540550
}
@@ -550,6 +560,8 @@ public XContentBuilder toInnerXContent(XContentBuilder builder, Params params) t
550560
if (version >= VERSION_ENTERPRISE) {
551561
builder.field(Fields.MAX_NODES, maxNodes == -1 ? null : maxNodes);
552562
builder.field(Fields.MAX_RESOURCE_UNITS, maxResourceUnits == -1 ? null : maxResourceUnits);
563+
} else if (hideEnterprise && maxNodes == -1) {
564+
builder.field(Fields.MAX_NODES, maxResourceUnits);
553565
} else {
554566
builder.field(Fields.MAX_NODES, maxNodes);
555567
}

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

+13-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
import java.util.List;
2626
import java.util.Map;
2727

28+
import static org.elasticsearch.core.RestApiVersion.V_7;
29+
import static org.elasticsearch.core.RestApiVersion.V_8;
30+
import static org.elasticsearch.core.RestApiVersion.onOrAfter;
2831
import static org.elasticsearch.rest.RestRequest.Method.GET;
2932
import static org.elasticsearch.rest.RestStatus.NOT_FOUND;
3033
import static org.elasticsearch.rest.RestStatus.OK;
@@ -60,13 +63,21 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC
6063
overrideParams.put(License.REST_VIEW_MODE, "true");
6164
overrideParams.put(License.LICENSE_VERSION_MODE, String.valueOf(License.VERSION_CURRENT));
6265

66+
if (request.getRestApiVersion() == V_7) {
67+
// Hide enterprise licenses by default, there is an opt-in flag to show them
68+
final boolean hideEnterprise = request.paramAsBoolean("accept_enterprise", false) == false;
69+
final int licenseVersion = hideEnterprise ? License.VERSION_CRYPTO_ALGORITHMS : License.VERSION_CURRENT;
70+
overrideParams.put(License.LICENSE_VERSION_MODE, String.valueOf(licenseVersion));
71+
overrideParams.put(License.XCONTENT_HIDE_ENTERPRISE, String.valueOf(hideEnterprise));
72+
}
6373
// In 7.x, there was an opt-in flag to show "enterprise" licenses. In 8.0 the flag is deprecated and can only be true
6474
// TODO Remove this from 9.0
6575
if (request.hasParam("accept_enterprise")) {
6676
deprecationLogger.deprecate(DeprecationCategory.API, "get_license_accept_enterprise",
6777
"Including [accept_enterprise] in get license requests is deprecated." +
68-
" The parameter will be removed in the next major version");
69-
if (request.paramAsBoolean("accept_enterprise", true) == false) {
78+
" The parameter will be removed in the next major version");
79+
if (request.paramAsBoolean("accept_enterprise", true) == false
80+
&& request.getRestApiVersion().matches(onOrAfter(V_8))) {
7081
throw new IllegalArgumentException("The [accept_enterprise] parameters may not be false");
7182
}
7283
}

x-pack/plugin/core/src/main/java/org/elasticsearch/protocol/xpack/XPackInfoResponse.java

+23-5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
1818
import org.elasticsearch.common.xcontent.ToXContentObject;
1919
import org.elasticsearch.common.xcontent.XContentBuilder;
20+
import org.elasticsearch.core.RestApiVersion;
21+
import org.elasticsearch.license.License;
2022
import org.elasticsearch.protocol.xpack.license.LicenseStatus;
2123

2224
import java.io.IOException;
@@ -203,11 +205,27 @@ public int hashCode() {
203205

204206
@Override
205207
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
206-
builder.startObject()
207-
.field("uid", uid)
208-
.field("type", type)
209-
.field("mode", mode)
210-
.field("status", status.label());
208+
builder.startObject();
209+
builder.field("uid", uid);
210+
211+
if (builder.getRestApiVersion() == RestApiVersion.V_7 && params.paramAsBoolean("accept_enterprise", false) == false) {
212+
if (License.LicenseType.ENTERPRISE.getTypeName().equals(type)) {
213+
builder.field("type", License.LicenseType.PLATINUM.getTypeName());
214+
} else {
215+
builder.field("type", type);
216+
}
217+
218+
if (License.OperationMode.ENTERPRISE.description().equals(mode)) {
219+
builder.field("mode", License.OperationMode.PLATINUM.description());
220+
} else {
221+
builder.field("mode", mode);
222+
}
223+
} else {
224+
builder.field("type", type);
225+
builder.field("mode", mode);
226+
}
227+
228+
builder.field("status", status.label());
211229
if (expiryDate != BASIC_SELF_GENERATED_LICENSE_EXPIRATION_MILLIS) {
212230
builder.timeField("expiry_date_in_millis", "expiry_date", expiryDate);
213231
}

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

+4-1
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)