Skip to content

Commit 7ac647c

Browse files
authored
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.
1 parent 4f47e1f commit 7ac647c

File tree

5 files changed

+7
-6
lines changed

5 files changed

+7
-6
lines changed

client/rest-high-level/src/main/java/org/elasticsearch/client/IndexLifecycleRequestConverters.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ static Request deleteSnapshotLifecyclePolicy(DeleteSnapshotLifecyclePolicyReques
204204
}
205205

206206
static Request executeSnapshotLifecyclePolicy(ExecuteSnapshotLifecyclePolicyRequest executeSnapshotLifecyclePolicyRequest) {
207-
Request request = new Request(HttpPut.METHOD_NAME,
207+
Request request = new Request(HttpPost.METHOD_NAME,
208208
new RequestConverters.EndpointBuilder()
209209
.addPathPartAsIs("_slm/policy")
210210
.addPathPartAsIs(executeSnapshotLifecyclePolicyRequest.getPolicyId())

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

+2-2
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

+1-1
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

+2-2
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ public void testPolicyManualExecution() throws Exception {
207207
createSnapshotPolicy(policyName, "snap", "1 2 3 4 5 ?", repoId, indexName, true);
208208

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

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

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

+1
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)