From a85b4f42ca3965e1c94f621948b3b48fa66611fb Mon Sep 17 00:00:00 2001 From: Tal Levy Date: Tue, 6 Nov 2018 07:46:25 -0800 Subject: [PATCH] [ILM] change remove-policy-from-index http method from DELETE to POST (#35268) The remove-ilm-from-index API was using the DELETE http method to signify that something is being removed. Although, metadata about ILM for the index is being deleted, no entity/resource is being deleted during this operation. POST is more in line with what this API is actually doing, it is modifying the metadata for an index. As part of this change, `remove` is also appended to the path to be more explicit about its actions. --- .../client/IndexLifecycleRequestConverters.java | 4 ++-- .../client/IndexLifecycleRequestConvertersTests.java | 4 ++-- docs/reference/ilm/apis/remove-policy.asciidoc | 4 ++-- .../action/RestRemoveIndexLifecyclePolicyAction.java | 4 ++-- .../test/resources/rest-api-spec/api/ilm.remove_policy.json | 6 +++--- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/IndexLifecycleRequestConverters.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/IndexLifecycleRequestConverters.java index 5e185866f8a..0ca4f22edf2 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/IndexLifecycleRequestConverters.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/IndexLifecycleRequestConverters.java @@ -78,10 +78,10 @@ final class IndexLifecycleRequestConverters { static Request removeIndexLifecyclePolicy(RemoveIndexLifecyclePolicyRequest removePolicyRequest) { String[] indices = removePolicyRequest.indices() == null ? Strings.EMPTY_ARRAY : removePolicyRequest.indices().toArray(new String[] {}); - Request request = new Request(HttpDelete.METHOD_NAME, + Request request = new Request(HttpPost.METHOD_NAME, new RequestConverters.EndpointBuilder() .addCommaSeparatedPathParts(indices) - .addPathPartAsIs("_ilm") + .addPathPartAsIs("_ilm", "remove") .build()); RequestConverters.Params params = new RequestConverters.Params(request); params.withIndicesOptions(removePolicyRequest.indicesOptions()); diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/IndexLifecycleRequestConvertersTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/IndexLifecycleRequestConvertersTests.java index 0030fd0773a..1af29701bc7 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/IndexLifecycleRequestConvertersTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/IndexLifecycleRequestConvertersTests.java @@ -99,9 +99,9 @@ public class IndexLifecycleRequestConvertersTests extends ESTestCase { setRandomMasterTimeout(req::setMasterTimeout, TimedRequest.DEFAULT_MASTER_NODE_TIMEOUT, expectedParams); Request request = IndexLifecycleRequestConverters.removeIndexLifecyclePolicy(req); - assertThat(request.getMethod(), equalTo(HttpDelete.METHOD_NAME)); + assertThat(request.getMethod(), equalTo(HttpPost.METHOD_NAME)); String idxString = Strings.arrayToCommaDelimitedString(indices); - assertThat(request.getEndpoint(), equalTo("/" + (idxString.isEmpty() ? "" : (idxString + "/")) + "_ilm")); + assertThat(request.getEndpoint(), equalTo("/" + (idxString.isEmpty() ? "" : (idxString + "/")) + "_ilm/remove")); assertThat(request.getParameters(), equalTo(expectedParams)); } diff --git a/docs/reference/ilm/apis/remove-policy.asciidoc b/docs/reference/ilm/apis/remove-policy.asciidoc index 8ee313f4e30..f37ac9a715d 100644 --- a/docs/reference/ilm/apis/remove-policy.asciidoc +++ b/docs/reference/ilm/apis/remove-policy.asciidoc @@ -10,7 +10,7 @@ Unassigns a policy from a specified index pattern ==== Request -`DELETE /_ilm` +`POST /_ilm/remove` ==== Description @@ -80,7 +80,7 @@ PUT my_index [source,js] -------------------------------------------------- -DELETE my_index/_ilm +POST my_index/_ilm/remove -------------------------------------------------- // CONSOLE // TEST[continued] diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/RestRemoveIndexLifecyclePolicyAction.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/RestRemoveIndexLifecyclePolicyAction.java index afa328ab8d8..d077b732341 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/RestRemoveIndexLifecyclePolicyAction.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/RestRemoveIndexLifecyclePolicyAction.java @@ -22,7 +22,7 @@ public class RestRemoveIndexLifecyclePolicyAction extends BaseRestHandler { public RestRemoveIndexLifecyclePolicyAction(Settings settings, RestController controller) { super(settings); - controller.registerHandler(RestRequest.Method.DELETE, "/{index}/_ilm", this); + controller.registerHandler(RestRequest.Method.POST, "/{index}/_ilm/remove", this); } @Override @@ -40,4 +40,4 @@ public class RestRemoveIndexLifecyclePolicyAction extends BaseRestHandler { return channel -> client.execute(RemoveIndexLifecyclePolicyAction.INSTANCE, changePolicyRequest, new RestToXContentListener<>(channel)); } -} \ No newline at end of file +} diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/api/ilm.remove_policy.json b/x-pack/plugin/src/test/resources/rest-api-spec/api/ilm.remove_policy.json index 72834eb380d..e05cd5df022 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/api/ilm.remove_policy.json +++ b/x-pack/plugin/src/test/resources/rest-api-spec/api/ilm.remove_policy.json @@ -1,10 +1,10 @@ { "ilm.remove_policy": { "documentation": "http://www.elastic.co/guide/en/index_lifecycle/current/index_lifecycle.html", - "methods": [ "DELETE" ], + "methods": [ "POST" ], "url": { - "path": "/{index}/_ilm", - "paths": ["/{index}/_ilm", "/_ilm"], + "path": "/{index}/_ilm/remove", + "paths": ["/{index}/_ilm/remove", "/_ilm/remove"], "parts": { "index": { "type" : "string",