From 08b42c0b70aed19b847d05bcf9a13d704a5e8007 Mon Sep 17 00:00:00 2001 From: Gordon Brown Date: Wed, 25 Sep 2019 11:32:44 -0600 Subject: [PATCH] Add support for POST requests to SLM Execute API (#47061) This commit adds support for POST requests to the SLM `_execute` API, because POST is a more appropriate HTTP verb for this action as it is not idempotent. The docs are also changed to favor POST over PUT, although PUT is not removed or officially deprecated. --- .../elasticsearch/client/IndexLifecycleRequestConverters.java | 2 +- docs/reference/ilm/apis/slm-api.asciidoc | 4 ++-- docs/reference/ilm/getting-started-slm.asciidoc | 2 +- .../org/elasticsearch/xpack/slm/SnapshotLifecycleRestIT.java | 4 ++-- .../xpack/slm/action/RestExecuteSnapshotLifecycleAction.java | 1 + 5 files changed, 7 insertions(+), 6 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 fb5db72cbc95d..5589d6367fd6c 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 @@ -204,7 +204,7 @@ static Request deleteSnapshotLifecyclePolicy(DeleteSnapshotLifecyclePolicyReques } static Request executeSnapshotLifecyclePolicy(ExecuteSnapshotLifecyclePolicyRequest executeSnapshotLifecyclePolicyRequest) { - Request request = new Request(HttpPut.METHOD_NAME, + Request request = new Request(HttpPost.METHOD_NAME, new RequestConverters.EndpointBuilder() .addPathPartAsIs("_slm/policy") .addPathPartAsIs(executeSnapshotLifecyclePolicyRequest.getPolicyId()) diff --git a/docs/reference/ilm/apis/slm-api.asciidoc b/docs/reference/ilm/apis/slm-api.asciidoc index cd9d2364e69af..013225f9696da 100644 --- a/docs/reference/ilm/apis/slm-api.asciidoc +++ b/docs/reference/ilm/apis/slm-api.asciidoc @@ -185,7 +185,7 @@ To take an immediate snapshot using a policy, use the following [source,console] -------------------------------------------------- -PUT /_slm/policy/daily-snapshots/_execute +POST /_slm/policy/daily-snapshots/_execute -------------------------------------------------- // TEST[skip:we can't easily handle snapshots from docs tests] @@ -279,7 +279,7 @@ Another snapshot can immediately be executed to ensure the new policy works: [source,console] -------------------------------------------------- -PUT /_slm/policy/daily-snapshots/_execute +POST /_slm/policy/daily-snapshots/_execute -------------------------------------------------- // TEST[skip:we can't handle snapshots in docs tests] diff --git a/docs/reference/ilm/getting-started-slm.asciidoc b/docs/reference/ilm/getting-started-slm.asciidoc index 32a5c5ef4d891..e6f7dff2749c4 100644 --- a/docs/reference/ilm/getting-started-slm.asciidoc +++ b/docs/reference/ilm/getting-started-slm.asciidoc @@ -132,7 +132,7 @@ as using the configuration from our policy right now instead of waiting for [source,console] -------------------------------------------------- -PUT /_slm/policy/nightly-snapshots/_execute +POST /_slm/policy/nightly-snapshots/_execute -------------------------------------------------- // TEST[skip:we can't easily handle snapshots from docs tests] diff --git a/x-pack/plugin/ilm/qa/multi-node/src/test/java/org/elasticsearch/xpack/slm/SnapshotLifecycleRestIT.java b/x-pack/plugin/ilm/qa/multi-node/src/test/java/org/elasticsearch/xpack/slm/SnapshotLifecycleRestIT.java index 2383e07227206..cfe5b2f0e061d 100644 --- a/x-pack/plugin/ilm/qa/multi-node/src/test/java/org/elasticsearch/xpack/slm/SnapshotLifecycleRestIT.java +++ b/x-pack/plugin/ilm/qa/multi-node/src/test/java/org/elasticsearch/xpack/slm/SnapshotLifecycleRestIT.java @@ -207,7 +207,7 @@ public void testPolicyManualExecution() throws Exception { createSnapshotPolicy(policyName, "snap", "1 2 3 4 5 ?", repoId, indexName, true); ResponseException badResp = expectThrows(ResponseException.class, - () -> client().performRequest(new Request("PUT", "/_slm/policy/" + policyName + "-bad/_execute"))); + () -> client().performRequest(new Request("POST", "/_slm/policy/" + policyName + "-bad/_execute"))); assertThat(EntityUtils.toString(badResp.getResponse().getEntity()), containsString("no such snapshot lifecycle policy [" + policyName + "-bad]")); @@ -335,7 +335,7 @@ public void testBasicTimeBasedRetenion() throws Exception { */ private String executePolicy(String policyId) { try { - Response executeRepsonse = client().performRequest(new Request("PUT", "/_slm/policy/" + policyId + "/_execute")); + Response executeRepsonse = client().performRequest(new Request("POST", "/_slm/policy/" + policyId + "/_execute")); try (XContentParser parser = JsonXContent.jsonXContent.createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, EntityUtils.toByteArray(executeRepsonse.getEntity()))) { return parser.mapStrings().get("snapshot_name"); diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/RestExecuteSnapshotLifecycleAction.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/RestExecuteSnapshotLifecycleAction.java index a644df789d015..72eceee0f8ecc 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/RestExecuteSnapshotLifecycleAction.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/RestExecuteSnapshotLifecycleAction.java @@ -17,6 +17,7 @@ public class RestExecuteSnapshotLifecycleAction extends BaseRestHandler { public RestExecuteSnapshotLifecycleAction(RestController controller) { controller.registerHandler(RestRequest.Method.PUT, "/_slm/policy/{name}/_execute", this); + controller.registerHandler(RestRequest.Method.POST, "/_slm/policy/{name}/_execute", this); } @Override