|
54 | 54 |
|
55 | 55 | import static java.util.Collections.singletonMap;
|
56 | 56 | import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
| 57 | +import static org.hamcrest.Matchers.allOf; |
57 | 58 | import static org.hamcrest.Matchers.containsString;
|
58 | 59 | import static org.hamcrest.Matchers.equalTo;
|
59 | 60 | import static org.hamcrest.Matchers.greaterThan;
|
| 61 | +import static org.hamcrest.Matchers.hasKey; |
60 | 62 | import static org.hamcrest.Matchers.not;
|
61 | 63 | import static org.hamcrest.Matchers.nullValue;
|
62 | 64 |
|
@@ -838,6 +840,45 @@ public void testCanStopILMWithPolicyUsingNonexistentPolicy() throws Exception {
|
838 | 840 | assertOK(client().performRequest(startILMReqest));
|
839 | 841 | }
|
840 | 842 |
|
| 843 | + public void testExplainFilters() throws Exception { |
| 844 | + String goodIndex = index + "-good-000001"; |
| 845 | + String errorIndex = index + "-error"; |
| 846 | + String nonexistantPolicyIndex = index + "-nonexistant-policy"; |
| 847 | + String unmanagedIndex = index + "-unmanaged"; |
| 848 | + |
| 849 | + createFullPolicy(TimeValue.ZERO); |
| 850 | + |
| 851 | + createIndexWithSettings(goodIndex, Settings.builder() |
| 852 | + .put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, "alias") |
| 853 | + .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0) |
| 854 | + .put(LifecycleSettings.LIFECYCLE_NAME, policy)); |
| 855 | + createIndexWithSettingsNoAlias(errorIndex, Settings.builder() |
| 856 | + .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0) |
| 857 | + .put(LifecycleSettings.LIFECYCLE_NAME, policy)); |
| 858 | + createIndexWithSettingsNoAlias(nonexistantPolicyIndex, Settings.builder() |
| 859 | + .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0) |
| 860 | + .put(LifecycleSettings.LIFECYCLE_NAME, randomValueOtherThan(policy, () -> randomAlphaOfLengthBetween(3,10)))); |
| 861 | + createIndexWithSettingsNoAlias(unmanagedIndex, Settings.builder() |
| 862 | + .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)); |
| 863 | + |
| 864 | + assertBusy(() -> { |
| 865 | + Map<String, Map<String, Object>> explainResponse = explain(index + "*", false, false); |
| 866 | + assertNotNull(explainResponse); |
| 867 | + assertThat(explainResponse, |
| 868 | + allOf(hasKey(goodIndex), hasKey(errorIndex), hasKey(nonexistantPolicyIndex), hasKey(unmanagedIndex))); |
| 869 | + |
| 870 | + Map<String, Map<String, Object>> onlyManagedResponse = explain(index + "*", false, true); |
| 871 | + assertNotNull(onlyManagedResponse); |
| 872 | + assertThat(onlyManagedResponse, allOf(hasKey(goodIndex), hasKey(errorIndex), hasKey(nonexistantPolicyIndex))); |
| 873 | + assertThat(onlyManagedResponse, not(hasKey(unmanagedIndex))); |
| 874 | + |
| 875 | + Map<String, Map<String, Object>> onlyErrorsResponse = explain(index + "*", true, randomBoolean()); |
| 876 | + assertNotNull(onlyErrorsResponse); |
| 877 | + assertThat(onlyErrorsResponse, allOf(hasKey(errorIndex), hasKey(nonexistantPolicyIndex))); |
| 878 | + assertThat(onlyErrorsResponse, allOf(not(hasKey(goodIndex)), not(hasKey(unmanagedIndex)))); |
| 879 | + }); |
| 880 | + } |
| 881 | + |
841 | 882 | private void createFullPolicy(TimeValue hotTime) throws IOException {
|
842 | 883 | Map<String, LifecycleAction> hotActions = new HashMap<>();
|
843 | 884 | hotActions.put(SetPriorityAction.NAME, new SetPriorityAction(100));
|
@@ -957,15 +998,21 @@ private String getReasonForIndex(String indexName) throws IOException {
|
957 | 998 | }
|
958 | 999 |
|
959 | 1000 | private Map<String, Object> explainIndex(String indexName) throws IOException {
|
960 |
| - Request explainRequest = new Request("GET", indexName + "/_ilm/explain"); |
| 1001 | + return explain(indexName, false, false).get(indexName); |
| 1002 | + } |
| 1003 | + |
| 1004 | + private Map<String, Map<String, Object>> explain(String indexPattern, boolean onlyErrors, boolean onlyManaged) throws IOException { |
| 1005 | + Request explainRequest = new Request("GET", indexPattern + "/_ilm/explain"); |
| 1006 | + explainRequest.addParameter("only_errors", Boolean.toString(onlyErrors)); |
| 1007 | + explainRequest.addParameter("only_managed", Boolean.toString(onlyManaged)); |
961 | 1008 | Response response = client().performRequest(explainRequest);
|
962 | 1009 | Map<String, Object> responseMap;
|
963 | 1010 | try (InputStream is = response.getEntity().getContent()) {
|
964 | 1011 | responseMap = XContentHelper.convertToMap(XContentType.JSON.xContent(), is, true);
|
965 | 1012 | }
|
966 | 1013 |
|
967 |
| - @SuppressWarnings("unchecked") Map<String, Object> indexResponse = ((Map<String, Map<String, Object>>) responseMap.get("indices")) |
968 |
| - .get(indexName); |
| 1014 | + @SuppressWarnings("unchecked") Map<String, Map<String, Object>> indexResponse = |
| 1015 | + ((Map<String, Map<String, Object>>) responseMap.get("indices")); |
969 | 1016 | return indexResponse;
|
970 | 1017 | }
|
971 | 1018 |
|
|
0 commit comments