Skip to content

Commit a3186e4

Browse files
authored
Deprecate X-Pack centric license endpoints (#35959)
This commit is part of our plan to deprecate and ultimately remove the use of _xpack in the REST APIs.
1 parent 78ac12d commit a3186e4

File tree

29 files changed

+150
-85
lines changed

29 files changed

+150
-85
lines changed

client/rest-high-level/src/main/java/org/elasticsearch/client/LicenseRequestConverters.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ final class LicenseRequestConverters {
3434
private LicenseRequestConverters() {}
3535

3636
static Request putLicense(PutLicenseRequest putLicenseRequest) {
37-
String endpoint = new RequestConverters.EndpointBuilder().addPathPartAsIs("_xpack", "license").build();
37+
String endpoint = new RequestConverters.EndpointBuilder().addPathPartAsIs("_license").build();
3838
Request request = new Request(HttpPut.METHOD_NAME, endpoint);
3939
RequestConverters.Params parameters = new RequestConverters.Params(request);
4040
parameters.withTimeout(putLicenseRequest.timeout());
@@ -47,15 +47,15 @@ static Request putLicense(PutLicenseRequest putLicenseRequest) {
4747
}
4848

4949
static Request getLicense(GetLicenseRequest getLicenseRequest) {
50-
String endpoint = new RequestConverters.EndpointBuilder().addPathPartAsIs("_xpack", "license").build();
50+
String endpoint = new RequestConverters.EndpointBuilder().addPathPartAsIs("_license").build();
5151
Request request = new Request(HttpGet.METHOD_NAME, endpoint);
5252
RequestConverters.Params parameters = new RequestConverters.Params(request);
5353
parameters.withLocal(getLicenseRequest.isLocal());
5454
return request;
5555
}
5656

5757
static Request deleteLicense(DeleteLicenseRequest deleteLicenseRequest) {
58-
String endpoint = new RequestConverters.EndpointBuilder().addPathPartAsIs("_xpack", "license").build();
58+
String endpoint = new RequestConverters.EndpointBuilder().addPathPartAsIs("_license").build();
5959
Request request = new Request(HttpDelete.METHOD_NAME, endpoint);
6060
RequestConverters.Params parameters = new RequestConverters.Params(request);
6161
parameters.withTimeout(deleteLicenseRequest.timeout());
@@ -64,7 +64,7 @@ static Request deleteLicense(DeleteLicenseRequest deleteLicenseRequest) {
6464
}
6565

6666
static Request startTrial(StartTrialRequest startTrialRequest) {
67-
final String endpoint = new RequestConverters.EndpointBuilder().addPathPartAsIs("_xpack", "license", "start_trial").build();
67+
final String endpoint = new RequestConverters.EndpointBuilder().addPathPartAsIs("_license", "start_trial").build();
6868
final Request request = new Request(HttpPost.METHOD_NAME, endpoint);
6969

7070
RequestConverters.Params parameters = new RequestConverters.Params(request);
@@ -77,7 +77,7 @@ static Request startTrial(StartTrialRequest startTrialRequest) {
7777

7878
static Request startBasic(StartBasicRequest startBasicRequest) {
7979
String endpoint = new RequestConverters.EndpointBuilder()
80-
.addPathPartAsIs("_xpack", "license", "start_basic")
80+
.addPathPartAsIs("_license", "start_basic")
8181
.build();
8282
Request request = new Request(HttpPost.METHOD_NAME, endpoint);
8383
RequestConverters.Params parameters = new RequestConverters.Params(request);
@@ -90,10 +90,11 @@ static Request startBasic(StartBasicRequest startBasicRequest) {
9090
}
9191

9292
static Request getLicenseTrialStatus() {
93-
return new Request(HttpGet.METHOD_NAME, "/_xpack/license/trial_status");
93+
return new Request(HttpGet.METHOD_NAME, "/_license/trial_status");
9494
}
9595

9696
static Request getLicenseBasicStatus() {
97-
return new Request(HttpGet.METHOD_NAME, "/_xpack/license/basic_status");
97+
return new Request(HttpGet.METHOD_NAME, "/_license/basic_status");
9898
}
99+
99100
}

client/rest-high-level/src/test/java/org/elasticsearch/client/LicenseRequestConvertersTests.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public void testGetLicense() {
5454

5555
Request request = LicenseRequestConverters.getLicense(getLicenseRequest);
5656
assertThat(request.getMethod(), equalTo(HttpGet.METHOD_NAME));
57-
assertThat(request.getEndpoint(), equalTo("/_xpack/license"));
57+
assertThat(request.getEndpoint(), equalTo("/_license"));
5858
assertThat(request.getParameters(), equalTo(expectedParams));
5959
assertThat(request.getEntity(), is(nullValue()));
6060
}
@@ -72,7 +72,7 @@ public void testPutLicense() {
7272

7373
Request request = LicenseRequestConverters.putLicense(putLicenseRequest);
7474
assertThat(request.getMethod(), equalTo(HttpPut.METHOD_NAME));
75-
assertThat(request.getEndpoint(), equalTo("/_xpack/license"));
75+
assertThat(request.getEndpoint(), equalTo("/_license"));
7676
assertThat(request.getParameters(), equalTo(expectedParams));
7777
assertThat(request.getEntity(), is(nullValue()));
7878
}
@@ -85,7 +85,7 @@ public void testDeleteLicense() {
8585

8686
Request request = LicenseRequestConverters.deleteLicense(deleteLicenseRequest);
8787
assertThat(request.getMethod(), equalTo(HttpDelete.METHOD_NAME));
88-
assertThat(request.getEndpoint(), equalTo("/_xpack/license"));
88+
assertThat(request.getEndpoint(), equalTo("/_license"));
8989
assertThat(request.getParameters(), equalTo(expectedParams));
9090
assertThat(request.getEntity(), is(nullValue()));
9191
}
@@ -106,7 +106,7 @@ public void testStartTrial() {
106106
final Request restRequest = LicenseRequestConverters.startTrial(hlrcRequest);
107107

108108
assertThat(restRequest.getMethod(), equalTo(HttpPost.METHOD_NAME));
109-
assertThat(restRequest.getEndpoint(), equalTo("/_xpack/license/start_trial"));
109+
assertThat(restRequest.getEndpoint(), equalTo("/_license/start_trial"));
110110
assertThat(restRequest.getParameters(), equalTo(expectedParams));
111111
assertThat(restRequest.getEntity(), nullValue());
112112
}
@@ -124,23 +124,23 @@ public void testStartBasic() {
124124
Request request = LicenseRequestConverters.startBasic(startBasicRequest);
125125

126126
assertThat(request.getMethod(), equalTo(HttpPost.METHOD_NAME));
127-
assertThat(request.getEndpoint(), equalTo("/_xpack/license/start_basic"));
127+
assertThat(request.getEndpoint(), equalTo("/_license/start_basic"));
128128
assertThat(request.getParameters(), equalTo(expectedParams));
129129
assertThat(request.getEntity(), is(nullValue()));
130130
}
131131

132132
public void testGetLicenseTrialStatus() {
133133
Request request = LicenseRequestConverters.getLicenseTrialStatus();
134134
assertEquals(HttpGet.METHOD_NAME, request.getMethod());
135-
assertEquals("/_xpack/license/trial_status", request.getEndpoint());
135+
assertEquals("/_license/trial_status", request.getEndpoint());
136136
assertEquals(request.getParameters().size(), 0);
137137
assertNull(request.getEntity());
138138
}
139139

140140
public void testGetLicenseBasicStatus() {
141141
Request request = LicenseRequestConverters.getLicenseBasicStatus();
142142
assertEquals(HttpGet.METHOD_NAME, request.getMethod());
143-
assertEquals("/_xpack/license/basic_status", request.getEndpoint());
143+
assertEquals("/_license/basic_status", request.getEndpoint());
144144
assertEquals(request.getParameters().size(), 0);
145145
assertNull(request.getEntity());
146146
}

docs/reference/licensing/delete-license.asciidoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This API enables you to delete licensing information.
88
[float]
99
==== Request
1010

11-
`DELETE /_xpack/license`
11+
`DELETE /_license`
1212

1313
[float]
1414
==== Description
@@ -30,7 +30,7 @@ The following example queries the info API:
3030

3131
[source,js]
3232
------------------------------------------------------------
33-
DELETE _xpack/license
33+
DELETE /_license
3434
------------------------------------------------------------
3535
// CONSOLE
3636
// TEST[skip:license testing issues]

docs/reference/licensing/get-basic-status.asciidoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This API enables you to check the status of your basic license.
88
[float]
99
==== Request
1010

11-
`GET _xpack/license/basic_status`
11+
`GET /_license/basic_status`
1212

1313
[float]
1414
==== Description
@@ -32,7 +32,7 @@ The following example checks whether you are eligible to start a basic:
3232

3333
[source,js]
3434
------------------------------------------------------------
35-
GET _xpack/license/basic_status
35+
GET /_license/basic_status
3636
------------------------------------------------------------
3737
// CONSOLE
3838

docs/reference/licensing/get-license.asciidoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This API enables you to retrieve licensing information.
88
[float]
99
==== Request
1010

11-
`GET /_xpack/license`
11+
`GET /_license`
1212

1313
[float]
1414
==== Description
@@ -43,7 +43,7 @@ The following example provides information about a trial license:
4343

4444
[source,js]
4545
--------------------------------------------------
46-
GET _xpack/license
46+
GET /_license
4747
--------------------------------------------------
4848
// CONSOLE
4949

docs/reference/licensing/get-trial-status.asciidoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This API enables you to check the status of your trial license.
88
[float]
99
==== Request
1010

11-
`GET _xpack/license/trial_status`
11+
`GET /_license/trial_status`
1212

1313
[float]
1414
==== Description
@@ -38,7 +38,7 @@ The following example checks whether you are eligible to start a trial:
3838

3939
[source,js]
4040
------------------------------------------------------------
41-
GET _xpack/license/trial_status
41+
GET /_license/trial_status
4242
------------------------------------------------------------
4343
// CONSOLE
4444

docs/reference/licensing/start-basic.asciidoc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This API starts an indefinite basic license.
88
[float]
99
==== Request
1010

11-
`POST _xpack/license/start_basic`
11+
`POST /_license/start_basic`
1212

1313
[float]
1414
==== Description
@@ -38,7 +38,7 @@ The following example starts a basic license if you do not currently have a lice
3838

3939
[source,js]
4040
------------------------------------------------------------
41-
POST _xpack/license/start_basic
41+
POST /_license/start_basic
4242
------------------------------------------------------------
4343
// CONSOLE
4444
// TEST[skip:license testing issues]
@@ -59,7 +59,7 @@ parameter:
5959

6060
[source,js]
6161
------------------------------------------------------------
62-
POST _xpack/license/start_basic?acknowledge=true
62+
POST /_license/start_basic?acknowledge=true
6363
------------------------------------------------------------
6464
// CONSOLE
6565
// TEST[skip:license testing issues]

docs/reference/licensing/start-trial.asciidoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This API starts a 30-day trial license.
88
[float]
99
==== Request
1010

11-
`POST _xpack/license/start_trial`
11+
`POST /_license/start_trial`
1212

1313
[float]
1414
==== Description
@@ -42,7 +42,7 @@ parameter is required as you are initiating a license that will expire.
4242

4343
[source,js]
4444
------------------------------------------------------------
45-
POST _xpack/license/start_trial?acknowledge=true
45+
POST /_license/start_trial?acknowledge=true
4646
------------------------------------------------------------
4747
// CONSOLE
4848
// TEST[skip:license testing issues]

docs/reference/licensing/update-license.asciidoc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This API enables you to update your license.
88
[float]
99
==== Request
1010

11-
`PUT _xpack/license`
11+
`PUT /_license`
1212

1313
[float]
1414
==== Description
@@ -54,7 +54,7 @@ The following example updates to a basic license:
5454

5555
[source,js]
5656
------------------------------------------------------------
57-
POST _xpack/license
57+
POST /_license
5858
{
5959
"licenses": [
6060
{
@@ -81,15 +81,15 @@ You can alternatively use a `curl` command, for example:
8181
[source,js]
8282
[source,shell]
8383
------------------------------------------------------------
84-
curl -XPUT -u <user> 'http://<host>:<port>/_xpack/license' -H "Content-Type: application/json" -d @license.json
84+
curl -XPUT -u <user> 'http://<host>:<port>/_license' -H "Content-Type: application/json" -d @license.json
8585
------------------------------------------------------------
8686
// NOTCONSOLE
8787

8888
On Windows machine, use the following command:
8989

9090
[source,shell]
9191
------------------------------------------------------------
92-
gc .\license.json | Invoke-WebRequest -uri http://<host>:<port>/_xpack/license -Credential elastic -Method Put -ContentType "application/json"
92+
gc .\license.json | Invoke-WebRequest -uri http://<host>:<port>/_license -Credential elastic -Method Put -ContentType "application/json"
9393
------------------------------------------------------------
9494

9595
In these examples,
@@ -131,7 +131,7 @@ To complete the update, you must re-submit the API request and set the
131131

132132
[source,js]
133133
------------------------------------------------------------
134-
POST _xpack/license?acknowledge=true
134+
POST /_license?acknowledge=true
135135
{
136136
"licenses": [
137137
{
@@ -154,7 +154,7 @@ Alternatively:
154154

155155
[source,sh]
156156
------------------------------------------------------------
157-
curl -XPUT -u elastic 'http://<host>:<port>/_xpack/license?acknowledge=true' -H "Content-Type: application/json" -d @license.json
157+
curl -XPUT -u elastic 'http://<host>:<port>/_license?acknowledge=true' -H "Content-Type: application/json" -d @license.json
158158
------------------------------------------------------------
159159
// NOTCONSOLE
160160

qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/XPackIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public void testBasicFeature() throws IOException {
7878
* trial license a little bit to make sure that it works.
7979
*/
8080
public void testTrialLicense() throws IOException {
81-
Request startTrial = new Request("POST", "/_xpack/license/start_trial");
81+
Request startTrial = new Request("POST", "/_license/start_trial");
8282
startTrial.addParameter("acknowledge", "true");
8383
client().performRequest(startTrial);
8484

x-pack/plugin/ccr/qa/multi-cluster-downgraded-to-basic-license/src/test/java/org/elasticsearch/xpack/ccr/FollowIndexIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public void testDowngradeRemoteClusterToBasic() throws Exception {
5050

5151
String index2 = "logs-20190102";
5252
try (RestClient leaderClient = buildLeaderClient()) {
53-
Request request = new Request("POST", "/_xpack/license/start_basic");
53+
Request request = new Request("POST", "/_license/start_basic");
5454
request.addParameter("acknowledge", "true");
5555
Map<?, ?> response = toMap(leaderClient.performRequest(request));
5656
assertThat(response.get("basic_was_started"), is(true));

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
* or more contributor license agreements. Licensed under the Elastic License;
44
* you may not use this file except in compliance with the Elastic License.
55
*/
6+
67
package org.elasticsearch.license;
78

9+
import org.apache.logging.log4j.LogManager;
10+
import org.elasticsearch.common.logging.DeprecationLogger;
811
import org.elasticsearch.common.settings.Settings;
912
import org.elasticsearch.protocol.xpack.license.DeleteLicenseRequest;
1013
import org.elasticsearch.rest.RestController;
@@ -18,14 +21,20 @@
1821
import static org.elasticsearch.rest.RestRequest.Method.DELETE;
1922

2023
public class RestDeleteLicenseAction extends XPackRestHandler {
21-
public RestDeleteLicenseAction(Settings settings, RestController controller) {
24+
25+
private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestDeleteLicenseAction.class));
26+
27+
RestDeleteLicenseAction(Settings settings, RestController controller) {
2228
super(settings);
23-
controller.registerHandler(DELETE, URI_BASE + "/license", this);
29+
// TODO: remove deprecated endpoint in 8.0.0
30+
controller.registerWithDeprecatedHandler(
31+
DELETE, "/_license", this,
32+
DELETE, URI_BASE + "/license", deprecationLogger);
2433
}
2534

2635
@Override
2736
public String getName() {
28-
return "xpack_delete_license_action";
37+
return "delete_license";
2938
}
3039

3140
@Override

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
* or more contributor license agreements. Licensed under the Elastic License;
44
* you may not use this file except in compliance with the Elastic License.
55
*/
6+
67
package org.elasticsearch.license;
78

9+
import org.apache.logging.log4j.LogManager;
10+
import org.elasticsearch.common.logging.DeprecationLogger;
811
import org.elasticsearch.common.settings.Settings;
912
import org.elasticsearch.rest.RestController;
1013
import org.elasticsearch.rest.RestRequest;
@@ -16,9 +19,14 @@
1619

1720
public class RestGetBasicStatus extends XPackRestHandler {
1821

22+
private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestGetBasicStatus.class));
23+
1924
RestGetBasicStatus(Settings settings, RestController controller) {
2025
super(settings);
21-
controller.registerHandler(GET, URI_BASE + "/license/basic_status", this);
26+
// TODO: remove deprecated endpoint in 8.0.0
27+
controller.registerWithDeprecatedHandler(
28+
GET, "/_license/basic_status", this,
29+
GET, URI_BASE + "/license/basic_status", deprecationLogger);
2230
}
2331

2432
@Override
@@ -28,6 +36,7 @@ protected RestChannelConsumer doPrepareRequest(RestRequest request, XPackClient
2836

2937
@Override
3038
public String getName() {
31-
return "xpack_basic_status_action";
39+
return "get_basic_status";
3240
}
41+
3342
}

0 commit comments

Comments
 (0)