Skip to content

Commit

Permalink
Deprecate X-Pack centric license endpoints (#35959)
Browse files Browse the repository at this point in the history
This commit is part of our plan to deprecate and ultimately remove the
use of _xpack in the REST APIs.
  • Loading branch information
jasontedor authored Nov 28, 2018
1 parent 78ac12d commit a3186e4
Show file tree
Hide file tree
Showing 29 changed files with 150 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ final class LicenseRequestConverters {
private LicenseRequestConverters() {}

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

static Request getLicense(GetLicenseRequest getLicenseRequest) {
String endpoint = new RequestConverters.EndpointBuilder().addPathPartAsIs("_xpack", "license").build();
String endpoint = new RequestConverters.EndpointBuilder().addPathPartAsIs("_license").build();
Request request = new Request(HttpGet.METHOD_NAME, endpoint);
RequestConverters.Params parameters = new RequestConverters.Params(request);
parameters.withLocal(getLicenseRequest.isLocal());
return request;
}

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

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

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

static Request startBasic(StartBasicRequest startBasicRequest) {
String endpoint = new RequestConverters.EndpointBuilder()
.addPathPartAsIs("_xpack", "license", "start_basic")
.addPathPartAsIs("_license", "start_basic")
.build();
Request request = new Request(HttpPost.METHOD_NAME, endpoint);
RequestConverters.Params parameters = new RequestConverters.Params(request);
Expand All @@ -90,10 +90,11 @@ static Request startBasic(StartBasicRequest startBasicRequest) {
}

static Request getLicenseTrialStatus() {
return new Request(HttpGet.METHOD_NAME, "/_xpack/license/trial_status");
return new Request(HttpGet.METHOD_NAME, "/_license/trial_status");
}

static Request getLicenseBasicStatus() {
return new Request(HttpGet.METHOD_NAME, "/_xpack/license/basic_status");
return new Request(HttpGet.METHOD_NAME, "/_license/basic_status");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void testGetLicense() {

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

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

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

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

assertThat(request.getMethod(), equalTo(HttpPost.METHOD_NAME));
assertThat(request.getEndpoint(), equalTo("/_xpack/license/start_basic"));
assertThat(request.getEndpoint(), equalTo("/_license/start_basic"));
assertThat(request.getParameters(), equalTo(expectedParams));
assertThat(request.getEntity(), is(nullValue()));
}

public void testGetLicenseTrialStatus() {
Request request = LicenseRequestConverters.getLicenseTrialStatus();
assertEquals(HttpGet.METHOD_NAME, request.getMethod());
assertEquals("/_xpack/license/trial_status", request.getEndpoint());
assertEquals("/_license/trial_status", request.getEndpoint());
assertEquals(request.getParameters().size(), 0);
assertNull(request.getEntity());
}

public void testGetLicenseBasicStatus() {
Request request = LicenseRequestConverters.getLicenseBasicStatus();
assertEquals(HttpGet.METHOD_NAME, request.getMethod());
assertEquals("/_xpack/license/basic_status", request.getEndpoint());
assertEquals("/_license/basic_status", request.getEndpoint());
assertEquals(request.getParameters().size(), 0);
assertNull(request.getEntity());
}
Expand Down
4 changes: 2 additions & 2 deletions docs/reference/licensing/delete-license.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This API enables you to delete licensing information.
[float]
==== Request

`DELETE /_xpack/license`
`DELETE /_license`

[float]
==== Description
Expand All @@ -30,7 +30,7 @@ The following example queries the info API:

[source,js]
------------------------------------------------------------
DELETE _xpack/license
DELETE /_license
------------------------------------------------------------
// CONSOLE
// TEST[skip:license testing issues]
Expand Down
4 changes: 2 additions & 2 deletions docs/reference/licensing/get-basic-status.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This API enables you to check the status of your basic license.
[float]
==== Request

`GET _xpack/license/basic_status`
`GET /_license/basic_status`

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

[source,js]
------------------------------------------------------------
GET _xpack/license/basic_status
GET /_license/basic_status
------------------------------------------------------------
// CONSOLE

Expand Down
4 changes: 2 additions & 2 deletions docs/reference/licensing/get-license.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This API enables you to retrieve licensing information.
[float]
==== Request

`GET /_xpack/license`
`GET /_license`

[float]
==== Description
Expand Down Expand Up @@ -43,7 +43,7 @@ The following example provides information about a trial license:

[source,js]
--------------------------------------------------
GET _xpack/license
GET /_license
--------------------------------------------------
// CONSOLE

Expand Down
4 changes: 2 additions & 2 deletions docs/reference/licensing/get-trial-status.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This API enables you to check the status of your trial license.
[float]
==== Request

`GET _xpack/license/trial_status`
`GET /_license/trial_status`

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

[source,js]
------------------------------------------------------------
GET _xpack/license/trial_status
GET /_license/trial_status
------------------------------------------------------------
// CONSOLE

Expand Down
6 changes: 3 additions & 3 deletions docs/reference/licensing/start-basic.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This API starts an indefinite basic license.
[float]
==== Request

`POST _xpack/license/start_basic`
`POST /_license/start_basic`

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

[source,js]
------------------------------------------------------------
POST _xpack/license/start_basic
POST /_license/start_basic
------------------------------------------------------------
// CONSOLE
// TEST[skip:license testing issues]
Expand All @@ -59,7 +59,7 @@ parameter:

[source,js]
------------------------------------------------------------
POST _xpack/license/start_basic?acknowledge=true
POST /_license/start_basic?acknowledge=true
------------------------------------------------------------
// CONSOLE
// TEST[skip:license testing issues]
Expand Down
4 changes: 2 additions & 2 deletions docs/reference/licensing/start-trial.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This API starts a 30-day trial license.
[float]
==== Request

`POST _xpack/license/start_trial`
`POST /_license/start_trial`

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

[source,js]
------------------------------------------------------------
POST _xpack/license/start_trial?acknowledge=true
POST /_license/start_trial?acknowledge=true
------------------------------------------------------------
// CONSOLE
// TEST[skip:license testing issues]
Expand Down
12 changes: 6 additions & 6 deletions docs/reference/licensing/update-license.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This API enables you to update your license.
[float]
==== Request

`PUT _xpack/license`
`PUT /_license`

[float]
==== Description
Expand Down Expand Up @@ -54,7 +54,7 @@ The following example updates to a basic license:

[source,js]
------------------------------------------------------------
POST _xpack/license
POST /_license
{
"licenses": [
{
Expand All @@ -81,15 +81,15 @@ You can alternatively use a `curl` command, for example:
[source,js]
[source,shell]
------------------------------------------------------------
curl -XPUT -u <user> 'http://<host>:<port>/_xpack/license' -H "Content-Type: application/json" -d @license.json
curl -XPUT -u <user> 'http://<host>:<port>/_license' -H "Content-Type: application/json" -d @license.json
------------------------------------------------------------
// NOTCONSOLE

On Windows machine, use the following command:

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

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

[source,js]
------------------------------------------------------------
POST _xpack/license?acknowledge=true
POST /_license?acknowledge=true
{
"licenses": [
{
Expand All @@ -154,7 +154,7 @@ Alternatively:

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void testBasicFeature() throws IOException {
* trial license a little bit to make sure that it works.
*/
public void testTrialLicense() throws IOException {
Request startTrial = new Request("POST", "/_xpack/license/start_trial");
Request startTrial = new Request("POST", "/_license/start_trial");
startTrial.addParameter("acknowledge", "true");
client().performRequest(startTrial);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void testDowngradeRemoteClusterToBasic() throws Exception {

String index2 = "logs-20190102";
try (RestClient leaderClient = buildLeaderClient()) {
Request request = new Request("POST", "/_xpack/license/start_basic");
Request request = new Request("POST", "/_license/start_basic");
request.addParameter("acknowledge", "true");
Map<?, ?> response = toMap(leaderClient.performRequest(request));
assertThat(response.get("basic_was_started"), is(true));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
* 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.license;

import org.apache.logging.log4j.LogManager;
import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.protocol.xpack.license.DeleteLicenseRequest;
import org.elasticsearch.rest.RestController;
Expand All @@ -18,14 +21,20 @@
import static org.elasticsearch.rest.RestRequest.Method.DELETE;

public class RestDeleteLicenseAction extends XPackRestHandler {
public RestDeleteLicenseAction(Settings settings, RestController controller) {

private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestDeleteLicenseAction.class));

RestDeleteLicenseAction(Settings settings, RestController controller) {
super(settings);
controller.registerHandler(DELETE, URI_BASE + "/license", this);
// TODO: remove deprecated endpoint in 8.0.0
controller.registerWithDeprecatedHandler(
DELETE, "/_license", this,
DELETE, URI_BASE + "/license", deprecationLogger);
}

@Override
public String getName() {
return "xpack_delete_license_action";
return "delete_license";
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
* 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.license;

import org.apache.logging.log4j.LogManager;
import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.rest.RestController;
import org.elasticsearch.rest.RestRequest;
Expand All @@ -16,9 +19,14 @@

public class RestGetBasicStatus extends XPackRestHandler {

private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestGetBasicStatus.class));

RestGetBasicStatus(Settings settings, RestController controller) {
super(settings);
controller.registerHandler(GET, URI_BASE + "/license/basic_status", this);
// TODO: remove deprecated endpoint in 8.0.0
controller.registerWithDeprecatedHandler(
GET, "/_license/basic_status", this,
GET, URI_BASE + "/license/basic_status", deprecationLogger);
}

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

@Override
public String getName() {
return "xpack_basic_status_action";
return "get_basic_status";
}

}
Loading

0 comments on commit a3186e4

Please sign in to comment.