[License] Log Deprecation Warnings for old API usage
This makes use of the registerAsDeprecatedHandler method to automatically warn users when they're using deprecated functionality. This will also automatically provide a Warning header for anyone using HTTP clients (though they have to be looking for it...). - This also adds deprecated `/_licenses` variants of the endpoint. Users are consistently making that mistake, and it's easy enough to support this way. Can remove it if people disagree though. License portion only Original commit: elastic/x-pack-elasticsearch@431c871fcf
This commit is contained in:
parent
641caabdae
commit
a7c884be61
|
@ -5,29 +5,39 @@
|
|||
*/
|
||||
package org.elasticsearch.license.plugin.rest;
|
||||
|
||||
import org.elasticsearch.client.node.NodeClient;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.license.plugin.action.delete.DeleteLicenseAction;
|
||||
import org.elasticsearch.license.plugin.action.delete.DeleteLicenseRequest;
|
||||
import org.elasticsearch.rest.BaseRestHandler;
|
||||
import org.elasticsearch.rest.RestChannel;
|
||||
import org.elasticsearch.rest.RestController;
|
||||
import org.elasticsearch.rest.RestRequest;
|
||||
import org.elasticsearch.rest.action.support.AcknowledgedRestListener;
|
||||
import org.elasticsearch.xpack.XPackClient;
|
||||
import org.elasticsearch.xpack.rest.XPackRestHandler;
|
||||
|
||||
import static org.elasticsearch.rest.RestRequest.Method.DELETE;
|
||||
|
||||
public class RestDeleteLicenseAction extends BaseRestHandler {
|
||||
public class RestDeleteLicenseAction extends XPackRestHandler {
|
||||
|
||||
@Inject
|
||||
public RestDeleteLicenseAction(Settings settings, RestController controller) {
|
||||
super(settings);
|
||||
controller.registerHandler(DELETE, "/_xpack/license", this);
|
||||
// @deprecated Remove deprecations in 6.0
|
||||
controller.registerWithDeprecatedHandler(DELETE, URI_BASE + "/_license", this,
|
||||
DELETE, "/_license", deprecationLogger);
|
||||
|
||||
// Remove _licenses support entirely in 6.0
|
||||
controller.registerAsDeprecatedHandler(DELETE, "/_licenses", this,
|
||||
"[DELETE /_licenses] is deprecated! Use " +
|
||||
"[DELETE /_xpack/license] instead.",
|
||||
deprecationLogger);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final NodeClient client) {
|
||||
client.admin().cluster().execute(DeleteLicenseAction.INSTANCE, new DeleteLicenseRequest(), new AcknowledgedRestListener<>(channel));
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final XPackClient client) {
|
||||
client.es().admin().cluster().execute(DeleteLicenseAction.INSTANCE,
|
||||
new DeleteLicenseRequest(),
|
||||
new AcknowledgedRestListener<>(channel));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
*/
|
||||
package org.elasticsearch.license.plugin.rest;
|
||||
|
||||
import org.elasticsearch.client.node.NodeClient;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
|
@ -14,13 +13,14 @@ import org.elasticsearch.license.core.License;
|
|||
import org.elasticsearch.license.plugin.action.get.GetLicenseAction;
|
||||
import org.elasticsearch.license.plugin.action.get.GetLicenseRequest;
|
||||
import org.elasticsearch.license.plugin.action.get.GetLicenseResponse;
|
||||
import org.elasticsearch.rest.BaseRestHandler;
|
||||
import org.elasticsearch.rest.BytesRestResponse;
|
||||
import org.elasticsearch.rest.RestChannel;
|
||||
import org.elasticsearch.rest.RestController;
|
||||
import org.elasticsearch.rest.RestRequest;
|
||||
import org.elasticsearch.rest.RestResponse;
|
||||
import org.elasticsearch.rest.action.support.RestBuilderListener;
|
||||
import org.elasticsearch.xpack.XPackClient;
|
||||
import org.elasticsearch.xpack.rest.XPackRestHandler;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
@ -29,12 +29,20 @@ import static org.elasticsearch.rest.RestRequest.Method.GET;
|
|||
import static org.elasticsearch.rest.RestStatus.NOT_FOUND;
|
||||
import static org.elasticsearch.rest.RestStatus.OK;
|
||||
|
||||
public class RestGetLicenseAction extends BaseRestHandler {
|
||||
public class RestGetLicenseAction extends XPackRestHandler {
|
||||
|
||||
@Inject
|
||||
public RestGetLicenseAction(Settings settings, RestController controller) {
|
||||
super(settings);
|
||||
controller.registerHandler(GET, "/_xpack/license", this);
|
||||
// @deprecated Remove deprecations in 6.0
|
||||
controller.registerWithDeprecatedHandler(GET, URI_BASE + "/_license", this,
|
||||
GET, "/_license", deprecationLogger);
|
||||
|
||||
// Remove _licenses support entirely in 6.0
|
||||
controller.registerAsDeprecatedHandler(GET, "/_licenses", this,
|
||||
"[GET /_licenses] is deprecated! Use " +
|
||||
"[GET /_xpack/license] instead.",
|
||||
deprecationLogger);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -44,14 +52,14 @@ public class RestGetLicenseAction extends BaseRestHandler {
|
|||
* The licenses are sorted by latest issue_date
|
||||
*/
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final NodeClient client) {
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final XPackClient client) {
|
||||
final Map<String, String> overrideParams = new HashMap<>(2);
|
||||
overrideParams.put(License.REST_VIEW_MODE, "true");
|
||||
overrideParams.put(License.LICENSE_VERSION_MODE, String.valueOf(License.VERSION_CURRENT));
|
||||
final ToXContent.Params params = new ToXContent.DelegatingMapParams(overrideParams, request);
|
||||
GetLicenseRequest getLicenseRequest = new GetLicenseRequest();
|
||||
getLicenseRequest.local(request.paramAsBoolean("local", getLicenseRequest.local()));
|
||||
client.admin().cluster().execute(GetLicenseAction.INSTANCE, getLicenseRequest,
|
||||
client.es().admin().cluster().execute(GetLicenseAction.INSTANCE, getLicenseRequest,
|
||||
new RestBuilderListener<GetLicenseResponse>(channel) {
|
||||
@Override
|
||||
public RestResponse buildResponse(GetLicenseResponse response, XContentBuilder builder) throws Exception {
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
*/
|
||||
package org.elasticsearch.license.plugin.rest;
|
||||
|
||||
import org.elasticsearch.client.node.NodeClient;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
|
@ -13,7 +12,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
|
|||
import org.elasticsearch.license.plugin.action.put.PutLicenseAction;
|
||||
import org.elasticsearch.license.plugin.action.put.PutLicenseRequest;
|
||||
import org.elasticsearch.license.plugin.action.put.PutLicenseResponse;
|
||||
import org.elasticsearch.rest.BaseRestHandler;
|
||||
import org.elasticsearch.rest.BytesRestResponse;
|
||||
import org.elasticsearch.rest.RestChannel;
|
||||
import org.elasticsearch.rest.RestController;
|
||||
|
@ -21,25 +19,40 @@ import org.elasticsearch.rest.RestRequest;
|
|||
import org.elasticsearch.rest.RestResponse;
|
||||
import org.elasticsearch.rest.RestStatus;
|
||||
import org.elasticsearch.rest.action.support.RestBuilderListener;
|
||||
import org.elasticsearch.xpack.XPackClient;
|
||||
import org.elasticsearch.xpack.rest.XPackRestHandler;
|
||||
|
||||
import static org.elasticsearch.rest.RestRequest.Method.POST;
|
||||
import static org.elasticsearch.rest.RestRequest.Method.PUT;
|
||||
|
||||
public class RestPutLicenseAction extends BaseRestHandler {
|
||||
public class RestPutLicenseAction extends XPackRestHandler {
|
||||
|
||||
@Inject
|
||||
public RestPutLicenseAction(Settings settings, RestController controller) {
|
||||
super(settings);
|
||||
controller.registerHandler(PUT, "/_xpack/license", this);
|
||||
controller.registerHandler(POST, "/_xpack/license", this);
|
||||
// @deprecated Remove deprecations in 6.0
|
||||
controller.registerWithDeprecatedHandler(POST, URI_BASE + "/_license", this,
|
||||
POST, "/_license", deprecationLogger);
|
||||
controller.registerWithDeprecatedHandler(PUT, URI_BASE + "/_license", this,
|
||||
PUT, "/_license", deprecationLogger);
|
||||
|
||||
// Remove _licenses support entirely in 6.0
|
||||
controller.registerAsDeprecatedHandler(POST, "/_licenses", this,
|
||||
"[POST /_licenses] is deprecated! Use " +
|
||||
"[POST /_xpack/license] instead.",
|
||||
deprecationLogger);
|
||||
controller.registerAsDeprecatedHandler(PUT, "/_licenses", this,
|
||||
"[PUT /_licenses] is deprecated! Use " +
|
||||
"[PUT /_xpack/license] instead.",
|
||||
deprecationLogger);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final NodeClient client) {
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final XPackClient client) {
|
||||
PutLicenseRequest putLicenseRequest = new PutLicenseRequest();
|
||||
putLicenseRequest.license(request.content().utf8ToString());
|
||||
putLicenseRequest.acknowledge(request.paramAsBoolean("acknowledge", false));
|
||||
client.admin().cluster().execute(PutLicenseAction.INSTANCE, putLicenseRequest,
|
||||
client.es().admin().cluster().execute(PutLicenseAction.INSTANCE, putLicenseRequest,
|
||||
new RestBuilderListener<PutLicenseResponse>(channel) {
|
||||
@Override
|
||||
public RestResponse buildResponse(PutLicenseResponse response, XContentBuilder builder) throws Exception {
|
||||
|
|
Loading…
Reference in New Issue