Skip to content

Commit

Permalink
Add support for POST requests to SLM Execute API (elastic#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 committed Sep 25, 2019
1 parent a46eef9 commit 08b42c0
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 @@ -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]"));

Expand Down Expand Up @@ -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");
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 08b42c0

Please sign in to comment.