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.
This commit is contained in:
Gordon Brown 2019-09-25 16:15:10 -06:00 committed by GitHub
parent 4f47e1f169
commit 7ac647c365
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 7 additions and 6 deletions

View File

@ -204,7 +204,7 @@ final class IndexLifecycleRequestConverters {
}
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())

View File

@ -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]

View File

@ -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]

View File

@ -207,7 +207,7 @@ public class SnapshotLifecycleRestIT extends ESRestTestCase {
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 class SnapshotLifecycleRestIT extends ESRestTestCase {
*/
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");

View File

@ -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