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:
parent
4f47e1f169
commit
7ac647c365
|
@ -204,7 +204,7 @@ final class IndexLifecycleRequestConverters {
|
||||||
}
|
}
|
||||||
|
|
||||||
static Request executeSnapshotLifecyclePolicy(ExecuteSnapshotLifecyclePolicyRequest executeSnapshotLifecyclePolicyRequest) {
|
static Request executeSnapshotLifecyclePolicy(ExecuteSnapshotLifecyclePolicyRequest executeSnapshotLifecyclePolicyRequest) {
|
||||||
Request request = new Request(HttpPut.METHOD_NAME,
|
Request request = new Request(HttpPost.METHOD_NAME,
|
||||||
new RequestConverters.EndpointBuilder()
|
new RequestConverters.EndpointBuilder()
|
||||||
.addPathPartAsIs("_slm/policy")
|
.addPathPartAsIs("_slm/policy")
|
||||||
.addPathPartAsIs(executeSnapshotLifecyclePolicyRequest.getPolicyId())
|
.addPathPartAsIs(executeSnapshotLifecyclePolicyRequest.getPolicyId())
|
||||||
|
|
|
@ -185,7 +185,7 @@ To take an immediate snapshot using a policy, use the following
|
||||||
|
|
||||||
[source,console]
|
[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]
|
// 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]
|
[source,console]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
PUT /_slm/policy/daily-snapshots/_execute
|
POST /_slm/policy/daily-snapshots/_execute
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
// TEST[skip:we can't handle snapshots in docs tests]
|
// TEST[skip:we can't handle snapshots in docs tests]
|
||||||
|
|
||||||
|
|
|
@ -132,7 +132,7 @@ as using the configuration from our policy right now instead of waiting for
|
||||||
|
|
||||||
[source,console]
|
[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]
|
// TEST[skip:we can't easily handle snapshots from docs tests]
|
||||||
|
|
||||||
|
|
|
@ -207,7 +207,7 @@ public class SnapshotLifecycleRestIT extends ESRestTestCase {
|
||||||
createSnapshotPolicy(policyName, "snap", "1 2 3 4 5 ?", repoId, indexName, true);
|
createSnapshotPolicy(policyName, "snap", "1 2 3 4 5 ?", repoId, indexName, true);
|
||||||
|
|
||||||
ResponseException badResp = expectThrows(ResponseException.class,
|
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()),
|
assertThat(EntityUtils.toString(badResp.getResponse().getEntity()),
|
||||||
containsString("no such snapshot lifecycle policy [" + policyName + "-bad]"));
|
containsString("no such snapshot lifecycle policy [" + policyName + "-bad]"));
|
||||||
|
|
||||||
|
@ -335,7 +335,7 @@ public class SnapshotLifecycleRestIT extends ESRestTestCase {
|
||||||
*/
|
*/
|
||||||
private String executePolicy(String policyId) {
|
private String executePolicy(String policyId) {
|
||||||
try {
|
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,
|
try (XContentParser parser = JsonXContent.jsonXContent.createParser(NamedXContentRegistry.EMPTY,
|
||||||
DeprecationHandler.THROW_UNSUPPORTED_OPERATION, EntityUtils.toByteArray(executeRepsonse.getEntity()))) {
|
DeprecationHandler.THROW_UNSUPPORTED_OPERATION, EntityUtils.toByteArray(executeRepsonse.getEntity()))) {
|
||||||
return parser.mapStrings().get("snapshot_name");
|
return parser.mapStrings().get("snapshot_name");
|
||||||
|
|
|
@ -17,6 +17,7 @@ public class RestExecuteSnapshotLifecycleAction extends BaseRestHandler {
|
||||||
|
|
||||||
public RestExecuteSnapshotLifecycleAction(RestController controller) {
|
public RestExecuteSnapshotLifecycleAction(RestController controller) {
|
||||||
controller.registerHandler(RestRequest.Method.PUT, "/_slm/policy/{name}/_execute", this);
|
controller.registerHandler(RestRequest.Method.PUT, "/_slm/policy/{name}/_execute", this);
|
||||||
|
controller.registerHandler(RestRequest.Method.POST, "/_slm/policy/{name}/_execute", this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue