Skip to content

Commit

Permalink
Add support for POST requests to SLM Execute API (#47061)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gwbrown authored Sep 25, 2019
1 parent 6328558 commit b42923f
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
4 changes: 2 additions & 2 deletions docs/reference/ilm/apis/slm-api.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down Expand Up @@ -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]

Expand Down
2 changes: 1 addition & 1 deletion docs/reference/ilm/getting-started-slm.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,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]"));

Expand Down Expand Up @@ -338,7 +338,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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b42923f

Please sign in to comment.