|
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 |
|
@@ -829,6 +831,45 @@ public void testCanStopILMWithPolicyUsingNonexistentPolicy() throws Exception {
|
829 | 831 | assertOK(client().performRequest(startILMReqest));
|
830 | 832 | }
|
831 | 833 |
|
| 834 | + public void testExplainFilters() throws Exception { |
| 835 | + String goodIndex = index + "-good-000001"; |
| 836 | + String errorIndex = index + "-error"; |
| 837 | + String nonexistantPolicyIndex = index + "-nonexistant-policy"; |
| 838 | + String unmanagedIndex = index + "-unmanaged"; |
| 839 | + |
| 840 | + createFullPolicy(TimeValue.ZERO); |
| 841 | + |
| 842 | + createIndexWithSettings(goodIndex, Settings.builder() |
| 843 | + .put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, "alias") |
| 844 | + .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0) |
| 845 | + .put(LifecycleSettings.LIFECYCLE_NAME, policy)); |
| 846 | + createIndexWithSettingsNoAlias(errorIndex, Settings.builder() |
| 847 | + .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0) |
| 848 | + .put(LifecycleSettings.LIFECYCLE_NAME, policy)); |
| 849 | + createIndexWithSettingsNoAlias(nonexistantPolicyIndex, Settings.builder() |
| 850 | + .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0) |
| 851 | + .put(LifecycleSettings.LIFECYCLE_NAME, randomValueOtherThan(policy, () -> randomAlphaOfLengthBetween(3,10)))); |
| 852 | + createIndexWithSettingsNoAlias(unmanagedIndex, Settings.builder() |
| 853 | + .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)); |
| 854 | + |
| 855 | + assertBusy(() -> { |
| 856 | + Map<String, Map<String, Object>> explainResponse = explain(index + "*", false, false); |
| 857 | + assertNotNull(explainResponse); |
| 858 | + assertThat(explainResponse, |
| 859 | + allOf(hasKey(goodIndex), hasKey(errorIndex), hasKey(nonexistantPolicyIndex), hasKey(unmanagedIndex))); |
| 860 | + |
| 861 | + Map<String, Map<String, Object>> onlyManagedResponse = explain(index + "*", false, true); |
| 862 | + assertNotNull(onlyManagedResponse); |
| 863 | + assertThat(onlyManagedResponse, allOf(hasKey(goodIndex), hasKey(errorIndex), hasKey(nonexistantPolicyIndex))); |
| 864 | + assertThat(onlyManagedResponse, not(hasKey(unmanagedIndex))); |
| 865 | + |
| 866 | + Map<String, Map<String, Object>> onlyErrorsResponse = explain(index + "*", true, randomBoolean()); |
| 867 | + assertNotNull(onlyErrorsResponse); |
| 868 | + assertThat(onlyErrorsResponse, allOf(hasKey(errorIndex), hasKey(nonexistantPolicyIndex))); |
| 869 | + assertThat(onlyErrorsResponse, allOf(not(hasKey(goodIndex)), not(hasKey(unmanagedIndex)))); |
| 870 | + }); |
| 871 | + } |
| 872 | + |
832 | 873 | private void createFullPolicy(TimeValue hotTime) throws IOException {
|
833 | 874 | Map<String, LifecycleAction> hotActions = new HashMap<>();
|
834 | 875 | hotActions.put(SetPriorityAction.NAME, new SetPriorityAction(100));
|
@@ -948,15 +989,21 @@ private String getReasonForIndex(String indexName) throws IOException {
|
948 | 989 | }
|
949 | 990 |
|
950 | 991 | private Map<String, Object> explainIndex(String indexName) throws IOException {
|
951 |
| - Request explainRequest = new Request("GET", indexName + "/_ilm/explain"); |
| 992 | + return explain(indexName, false, false).get(indexName); |
| 993 | + } |
| 994 | + |
| 995 | + private Map<String, Map<String, Object>> explain(String indexPattern, boolean onlyErrors, boolean onlyManaged) throws IOException { |
| 996 | + Request explainRequest = new Request("GET", indexPattern + "/_ilm/explain"); |
| 997 | + explainRequest.addParameter("only_errors", Boolean.toString(onlyErrors)); |
| 998 | + explainRequest.addParameter("only_managed", Boolean.toString(onlyManaged)); |
952 | 999 | Response response = client().performRequest(explainRequest);
|
953 | 1000 | Map<String, Object> responseMap;
|
954 | 1001 | try (InputStream is = response.getEntity().getContent()) {
|
955 | 1002 | responseMap = XContentHelper.convertToMap(XContentType.JSON.xContent(), is, true);
|
956 | 1003 | }
|
957 | 1004 |
|
958 |
| - @SuppressWarnings("unchecked") Map<String, Object> indexResponse = ((Map<String, Map<String, Object>>) responseMap.get("indices")) |
959 |
| - .get(indexName); |
| 1005 | + @SuppressWarnings("unchecked") Map<String, Map<String, Object>> indexResponse = |
| 1006 | + ((Map<String, Map<String, Object>>) responseMap.get("indices")); |
960 | 1007 | return indexResponse;
|
961 | 1008 | }
|
962 | 1009 |
|
|
0 commit comments