Skip to content

Commit eb8699f

Browse files
committed
[ILM] add HLRC docs to remove-policy-from-index
This primarily introduces documentation for the HLRC remove-policy-from-index action. While working on these docs, a few other gotchyas were raised: - rename file names to be in line with documentation name of API (delete, not remove) - fix aspect of the Explain API that yields invalid responses
1 parent 927b242 commit eb8699f

File tree

5 files changed

+144
-14
lines changed

5 files changed

+144
-14
lines changed

client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/ILMDocumentationIT.java

Lines changed: 100 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,15 @@
4141
import org.elasticsearch.client.indexlifecycle.LifecyclePolicyMetadata;
4242
import org.elasticsearch.client.indexlifecycle.Phase;
4343
import org.elasticsearch.client.indexlifecycle.PutLifecyclePolicyRequest;
44+
import org.elasticsearch.client.indexlifecycle.RemoveIndexLifecyclePolicyRequest;
45+
import org.elasticsearch.client.indexlifecycle.RemoveIndexLifecyclePolicyResponse;
4446
import org.elasticsearch.client.indexlifecycle.RetryLifecyclePolicyRequest;
4547
import org.elasticsearch.client.indexlifecycle.RolloverAction;
4648
import org.elasticsearch.client.indexlifecycle.StartILMRequest;
4749
import org.elasticsearch.client.indexlifecycle.StopILMRequest;
4850
import org.elasticsearch.client.indexlifecycle.ShrinkAction;
4951
import org.elasticsearch.cluster.metadata.IndexMetaData;
52+
import org.elasticsearch.common.Strings;
5053
import org.elasticsearch.common.collect.ImmutableOpenMap;
5154
import org.elasticsearch.common.settings.Settings;
5255
import org.elasticsearch.common.unit.ByteSizeUnit;
@@ -57,8 +60,10 @@
5760
import org.hamcrest.Matchers;
5861

5962
import java.io.IOException;
63+
import java.util.ArrayList;
6064
import java.util.Collections;
6165
import java.util.HashMap;
66+
import java.util.List;
6267
import java.util.Map;
6368
import java.util.concurrent.CountDownLatch;
6469
import java.util.concurrent.TimeUnit;
@@ -161,19 +166,19 @@ public void testDeletePolicy() throws IOException, InterruptedException {
161166
assertTrue(putResponse.isAcknowledged());
162167
}
163168

164-
// tag::ilm-delete-lifecycle-policy-request
169+
// tag::ilm-remove-lifecycle-policy-request
165170
DeleteLifecyclePolicyRequest request =
166171
new DeleteLifecyclePolicyRequest("my_policy"); // <1>
167-
// end::ilm-delete-lifecycle-policy-request
172+
// end::ilm-remove-lifecycle-policy-request
168173

169-
// tag::ilm-delete-lifecycle-policy-execute
174+
// tag::ilm-remove-lifecycle-policy-execute
170175
AcknowledgedResponse response = client.indexLifecycle()
171176
.deleteLifecyclePolicy(request, RequestOptions.DEFAULT);
172-
// end::ilm-delete-lifecycle-policy-execute
177+
// end::ilm-remove-lifecycle-policy-execute
173178

174-
// tag::ilm-delete-lifecycle-policy-response
179+
// tag::ilm-remove-lifecycle-policy-response
175180
boolean acknowledged = response.isAcknowledged(); // <1>
176-
// end::ilm-delete-lifecycle-policy-response
181+
// end::ilm-remove-lifecycle-policy-response
177182

178183
assertTrue(acknowledged);
179184

@@ -184,7 +189,7 @@ public void testDeletePolicy() throws IOException, InterruptedException {
184189
assertTrue(putResponse.isAcknowledged());
185190
}
186191

187-
// tag::ilm-delete-lifecycle-policy-execute-listener
192+
// tag::ilm-remove-lifecycle-policy-execute-listener
188193
ActionListener<AcknowledgedResponse> listener =
189194
new ActionListener<AcknowledgedResponse>() {
190195
@Override
@@ -197,16 +202,16 @@ public void onFailure(Exception e) {
197202
// <2>
198203
}
199204
};
200-
// end::ilm-delete-lifecycle-policy-execute-listener
205+
// end::ilm-remove-lifecycle-policy-execute-listener
201206

202207
// Replace the empty listener by a blocking listener in test
203208
final CountDownLatch latch = new CountDownLatch(1);
204209
listener = new LatchedActionListener<>(listener, latch);
205210

206-
// tag::ilm-delete-lifecycle-policy-execute-async
211+
// tag::ilm-remove-lifecycle-policy-execute-async
207212
client.indexLifecycle().deleteLifecyclePolicyAsync(request,
208213
RequestOptions.DEFAULT, listener); // <1>
209-
// end::ilm-delete-lifecycle-policy-execute-async
214+
// end::ilm-remove-lifecycle-policy-execute-async
210215

211216
assertTrue(latch.await(30L, TimeUnit.SECONDS));
212217
}
@@ -530,6 +535,91 @@ public void onFailure(Exception e) {
530535
assertTrue(latch.await(30L, TimeUnit.SECONDS));
531536
}
532537

538+
public void testDeletePolicyFromIndex() throws Exception {
539+
RestHighLevelClient client = highLevelClient();
540+
541+
// setup policy for index
542+
Map<String, Phase> phases = new HashMap<>();
543+
phases.put("delete", new Phase("delete", TimeValue.timeValueHours(10L),
544+
Collections.singletonMap(DeleteAction.NAME, new DeleteAction())));
545+
LifecyclePolicy policy = new LifecyclePolicy("my_policy", phases);
546+
PutLifecyclePolicyRequest putRequest = new PutLifecyclePolicyRequest(policy);
547+
client.indexLifecycle().putLifecyclePolicy(putRequest, RequestOptions.DEFAULT);
548+
CreateIndexRequest createIndexRequest = new CreateIndexRequest("my_index",
549+
Settings.builder()
550+
.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
551+
.put("index.lifecycle.name", "my_policy")
552+
.build());
553+
client.indices().create(createIndexRequest, RequestOptions.DEFAULT);
554+
assertBusy(() -> assertTrue(client.indexLifecycle()
555+
.explainLifecycle(new ExplainLifecycleRequest().indices("my_index"), RequestOptions.DEFAULT)
556+
.getIndexResponses().get("my_index").managedByILM()));
557+
558+
// tag::ilm-remove-lifecycle-policy-from-index-request
559+
List<String> indices = new ArrayList<>();
560+
indices.add("my_index");
561+
RemoveIndexLifecyclePolicyRequest request =
562+
new RemoveIndexLifecyclePolicyRequest(indices); // <1>
563+
// end::ilm-remove-lifecycle-policy-from-index-request
564+
565+
566+
// tag::ilm-remove-lifecycle-policy-from-index-execute
567+
RemoveIndexLifecyclePolicyResponse response = client
568+
.indexLifecycle()
569+
.removeIndexLifecyclePolicy(request, RequestOptions.DEFAULT);
570+
// end::ilm-remove-lifecycle-policy-from-index-execute
571+
572+
// tag::ilm-remove-lifecycle-policy-from-index-response
573+
boolean hasFailures = response.hasFailures(); // <1>
574+
List<String> failedIndexes = response.getFailedIndexes(); // <2>
575+
// end::ilm-remove-lifecycle-policy-from-index-response
576+
577+
{
578+
assertFalse(hasFailures);
579+
Map<String, Object> indexSettings = getIndexSettings("my_index");
580+
assertTrue(Strings.isNullOrEmpty((String) indexSettings.get("index.lifecycle.name")));
581+
}
582+
583+
// re-apply policy on index
584+
updateIndexSettings("my_index", Settings.builder().put("index.lifecycle.name", "my_policy"));
585+
assertBusy(() -> assertTrue(client.indexLifecycle()
586+
.explainLifecycle(new ExplainLifecycleRequest().indices("my_index"), RequestOptions.DEFAULT)
587+
.getIndexResponses().get("my_index").managedByILM()));
588+
589+
// tag::ilm-remove-lifecycle-policy-from-index-execute-listener
590+
ActionListener<RemoveIndexLifecyclePolicyResponse> listener =
591+
new ActionListener<RemoveIndexLifecyclePolicyResponse>() {
592+
@Override
593+
public void onResponse(
594+
RemoveIndexLifecyclePolicyResponse response) {
595+
boolean hasFailures = response.hasFailures(); // <1>
596+
List<String> failedIndexes = response.getFailedIndexes();
597+
}
598+
599+
@Override
600+
public void onFailure(Exception e) {
601+
// <2>
602+
}
603+
};
604+
// end::ilm-remove-lifecycle-policy-from-index-execute-listener
605+
606+
{
607+
Map<String, Object> indexSettings = getIndexSettings("my_index");
608+
assertTrue(Strings.isNullOrEmpty((String) indexSettings.get("index.lifecycle.name")));
609+
}
610+
611+
// Replace the empty listener by a blocking listener in test
612+
final CountDownLatch latch = new CountDownLatch(1);
613+
listener = new LatchedActionListener<>(listener, latch);
614+
615+
// tag::ilm-remove-lifecycle-policy-from-index-execute-async
616+
client.indexLifecycle().removeIndexLifecyclePolicyAsync(request,
617+
RequestOptions.DEFAULT, listener); // <1>
618+
// end::ilm-remove-lifecycle-policy-from-index-execute-async
619+
620+
assertTrue(latch.await(30L, TimeUnit.SECONDS));
621+
}
622+
533623
static Map<String, Object> toMap(Response response) throws IOException {
534624
return XContentHelper.convertToMap(JsonXContent.jsonXContent, EntityUtils.toString(response.getEntity()), false);
535625
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
--
2+
:api: ilm-remove-lifecycle-policy-from-index
3+
:request:
4+
:response: AcknowledgedResponse
5+
--
6+
7+
[id="{upid}-{api}"]
8+
=== Remove Policy from Index API
9+
10+
11+
[id="{upid}-{api}-request"]
12+
==== Request
13+
14+
Removes the assigned lifecycle policy from an index.
15+
16+
["source","java",subs="attributes,callouts,macros"]
17+
--------------------------------------------------
18+
include-tagged::{doc-tests-file}[{api}-request]
19+
--------------------------------------------------
20+
<1> removes the `my_policy` policy from `my_index`
21+
22+
23+
[id="{upid}-{api}-response"]
24+
==== Response
25+
26+
The returned +{response}+ indicates if the request to remove
27+
the lifecycle policy from the index was received.
28+
29+
["source","java",subs="attributes,callouts,macros"]
30+
--------------------------------------------------
31+
include-tagged::{doc-tests-file}[{api}-response]
32+
--------------------------------------------------
33+
<1> Whether or not there were any policies failed
34+
to be removed from any indices from the request
35+
<2> A list of index names which are still managed
36+
by their policies.
37+
38+
include::../execution.asciidoc[]

docs/java-rest/high-level/supported-apis.asciidoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,7 @@ Management APIs:
475475
* <<{upid}-ilm-stop-ilm>>
476476
* <<{upid}-ilm-status>>
477477
* <<{upid}-ilm-retry-lifecycle-policy>>
478+
* <<{upid}-ilm-remove-lifecycle-policy-from-index>>
478479

479480

480481
include::ilm/put_lifecycle_policy.asciidoc[]
@@ -484,3 +485,4 @@ include::ilm/start_lifecycle_management.asciidoc[]
484485
include::ilm/stop_lifecycle_management.asciidoc[]
485486
include::ilm/lifecycle_management_status.asciidoc[]
486487
include::ilm/retry_lifecycle_policy.asciidoc[]
488+
include::ilm/remove_lifecycle_policy_from_index.asciidoc[]

docs/reference/ilm/apis/ilm-api.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ include::get-lifecycle.asciidoc[]
3535
include::delete-lifecycle.asciidoc[]
3636

3737
include::move-to-step.asciidoc[]
38-
include::remove-policy.asciidoc[]
38+
include::remove-policy-from-index.asciidoc[]
3939
include::retry-policy.asciidoc[]
4040

4141
include::get-status.asciidoc[]

docs/reference/ilm/apis/remove-policy.asciidoc renamed to docs/reference/ilm/apis/remove-policy-from-index.asciidoc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
[role="xpack"]
22
[testenv="basic"]
3-
[[ilm-delete-policy]]
4-
=== Delete Policy from Index API
3+
[[ilm-remove-policy]]
4+
=== Remove Policy from Index API
55
++++
6-
<titleabbrev>Delete Policy</titleabbrev>
6+
<titleabbrev>Remove Policy</titleabbrev>
77
++++
88

99
beta[]

0 commit comments

Comments
 (0)