Skip to content

Commit b631b0e

Browse files
committed
Add support for POST requests to SLM Execute API
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.
1 parent 3035cd3 commit b631b0e

File tree

4 files changed

+6
-5
lines changed

4 files changed

+6
-5
lines changed

docs/reference/ilm/apis/slm-api.asciidoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ To take an immediate snapshot using a policy, use the following
185185

186186
[source,console]
187187
--------------------------------------------------
188-
PUT /_slm/policy/daily-snapshots/_execute
188+
POST /_slm/policy/daily-snapshots/_execute
189189
--------------------------------------------------
190190
// TEST[skip:we can't easily handle snapshots from docs tests]
191191

@@ -279,7 +279,7 @@ Another snapshot can immediately be executed to ensure the new policy works:
279279

280280
[source,console]
281281
--------------------------------------------------
282-
PUT /_slm/policy/daily-snapshots/_execute
282+
POST /_slm/policy/daily-snapshots/_execute
283283
--------------------------------------------------
284284
// TEST[skip:we can't handle snapshots in docs tests]
285285

docs/reference/ilm/getting-started-slm.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ as using the configuration from our policy right now instead of waiting for
132132

133133
[source,console]
134134
--------------------------------------------------
135-
PUT /_slm/policy/nightly-snapshots/_execute
135+
POST /_slm/policy/nightly-snapshots/_execute
136136
--------------------------------------------------
137137
// TEST[skip:we can't easily handle snapshots from docs tests]
138138

x-pack/plugin/ilm/qa/multi-node/src/test/java/org/elasticsearch/xpack/slm/SnapshotLifecycleRestIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ public void testPolicyManualExecution() throws Exception {
210210
createSnapshotPolicy(policyName, "snap", "1 2 3 4 5 ?", repoId, indexName, true);
211211

212212
ResponseException badResp = expectThrows(ResponseException.class,
213-
() -> client().performRequest(new Request("PUT", "/_slm/policy/" + policyName + "-bad/_execute")));
213+
() -> client().performRequest(new Request("POST", "/_slm/policy/" + policyName + "-bad/_execute")));
214214
assertThat(EntityUtils.toString(badResp.getResponse().getEntity()),
215215
containsString("no such snapshot lifecycle policy [" + policyName + "-bad]"));
216216

@@ -338,7 +338,7 @@ public void testBasicTimeBasedRetenion() throws Exception {
338338
*/
339339
private String executePolicy(String policyId) {
340340
try {
341-
Response executeRepsonse = client().performRequest(new Request("PUT", "/_slm/policy/" + policyId + "/_execute"));
341+
Response executeRepsonse = client().performRequest(new Request("POST", "/_slm/policy/" + policyId + "/_execute"));
342342
try (XContentParser parser = JsonXContent.jsonXContent.createParser(NamedXContentRegistry.EMPTY,
343343
DeprecationHandler.THROW_UNSUPPORTED_OPERATION, EntityUtils.toByteArray(executeRepsonse.getEntity()))) {
344344
return parser.mapStrings().get("snapshot_name");

x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/RestExecuteSnapshotLifecycleAction.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public class RestExecuteSnapshotLifecycleAction extends BaseRestHandler {
1717

1818
public RestExecuteSnapshotLifecycleAction(RestController controller) {
1919
controller.registerHandler(RestRequest.Method.PUT, "/_slm/policy/{name}/_execute", this);
20+
controller.registerHandler(RestRequest.Method.POST, "/_slm/policy/{name}/_execute", this);
2021
}
2122

2223
@Override

0 commit comments

Comments
 (0)