|
10 | 10 | import org.elasticsearch.client.Request;
|
11 | 11 | import org.elasticsearch.client.Response;
|
12 | 12 | import org.elasticsearch.client.ResponseException;
|
| 13 | +import org.elasticsearch.common.Strings; |
13 | 14 | import org.elasticsearch.common.settings.Settings;
|
14 | 15 | import org.elasticsearch.common.util.concurrent.ThreadContext;
|
| 16 | +import org.elasticsearch.common.xcontent.DeprecationHandler; |
| 17 | +import org.elasticsearch.common.xcontent.NamedXContentRegistry; |
15 | 18 | import org.elasticsearch.common.xcontent.ObjectPath;
|
| 19 | +import org.elasticsearch.common.xcontent.XContentBuilder; |
| 20 | +import org.elasticsearch.common.xcontent.XContentParser; |
| 21 | +import org.elasticsearch.common.xcontent.XContentType; |
| 22 | +import org.elasticsearch.common.xcontent.json.JsonXContent; |
16 | 23 | import org.elasticsearch.common.xcontent.support.XContentMapValues;
|
17 | 24 | import org.elasticsearch.rest.RestStatus;
|
18 | 25 | import org.elasticsearch.rest.action.document.RestGetAction;
|
|
21 | 28 | import org.elasticsearch.test.StreamsUtils;
|
22 | 29 | import org.elasticsearch.test.rest.ESRestTestCase;
|
23 | 30 | import org.elasticsearch.upgrades.AbstractFullClusterRestartTestCase;
|
| 31 | +import org.elasticsearch.xpack.core.slm.SnapshotLifecyclePolicy; |
| 32 | +import org.elasticsearch.xpack.slm.SnapshotLifecycleStats; |
24 | 33 | import org.hamcrest.Matcher;
|
25 | 34 | import org.junit.Before;
|
26 | 35 |
|
27 | 36 | import java.io.IOException;
|
28 | 37 | import java.nio.charset.StandardCharsets;
|
29 | 38 | import java.util.ArrayList;
|
30 | 39 | import java.util.Base64;
|
| 40 | +import java.util.Collections; |
31 | 41 | import java.util.List;
|
32 | 42 | import java.util.Locale;
|
33 | 43 | import java.util.Map;
|
@@ -293,6 +303,39 @@ public void testRollupAfterRestart() throws Exception {
|
293 | 303 | assertRollUpJob("rollup-job-test");
|
294 | 304 | }
|
295 | 305 | }
|
| 306 | + |
| 307 | + public void testSlmStats() throws IOException { |
| 308 | + SnapshotLifecyclePolicy slmPolicy = new SnapshotLifecyclePolicy("test-policy", "test-policy", "* * * 31 FEB ? *", "test-repo", |
| 309 | + Collections.singletonMap("indices", Collections.singletonList("*")), null); |
| 310 | + if (isRunningAgainstOldCluster() && getOldClusterVersion().onOrAfter(Version.V_7_4_0)) { |
| 311 | + Request createRepoRequest = new Request("PUT", "_snapshot/test-repo"); |
| 312 | + String repoCreateJson = "{" + |
| 313 | + " \"type\": \"fs\"," + |
| 314 | + " \"settings\": {" + |
| 315 | + " \"location\": \"test-repo\"" + |
| 316 | + " }" + |
| 317 | + "}"; |
| 318 | + createRepoRequest.setJsonEntity(repoCreateJson); |
| 319 | + Request createSlmPolicyRequest = new Request("PUT", "_slm/policy/test-policy"); |
| 320 | + try (XContentBuilder builder = JsonXContent.contentBuilder()) { |
| 321 | + String createSlmPolicyJson = Strings.toString(slmPolicy.toXContent(builder, null)); |
| 322 | + createSlmPolicyRequest.setJsonEntity(createSlmPolicyJson); |
| 323 | + } |
| 324 | + |
| 325 | + client().performRequest(createRepoRequest); |
| 326 | + client().performRequest(createSlmPolicyRequest); |
| 327 | + } |
| 328 | + |
| 329 | + if (isRunningAgainstOldCluster() == false || getOldClusterVersion().onOrAfter(Version.V_7_5_0)) { |
| 330 | + Response response = client().performRequest(new Request("GET", "_slm/stats")); |
| 331 | + XContentType xContentType = XContentType.fromMediaTypeOrFormat(response.getEntity().getContentType().getValue()); |
| 332 | + try (XContentParser parser = xContentType.xContent().createParser(NamedXContentRegistry.EMPTY, |
| 333 | + DeprecationHandler.THROW_UNSUPPORTED_OPERATION, response.getEntity().getContent())) { |
| 334 | + assertEquals(new SnapshotLifecycleStats(), SnapshotLifecycleStats.parse(parser)); |
| 335 | + } |
| 336 | + } |
| 337 | + |
| 338 | + } |
296 | 339 |
|
297 | 340 | public void testRollupIDSchemeAfterRestart() throws Exception {
|
298 | 341 | assumeTrue("Rollup can be tested with 6.3.0 and onwards", getOldClusterVersion().onOrAfter(Version.V_6_3_0));
|
|
0 commit comments