From 17780ce07e4c709ce2e9ced6f00e6919e3c75334 Mon Sep 17 00:00:00 2001 From: Gordon Brown Date: Tue, 20 Nov 2018 11:32:41 -0700 Subject: [PATCH] Add HLRC docs for Delete Lifecycle Policy (#35664) Adds documenatation for the Delete Lifecycle Policy API to the HLRC documentation. --- .../documentation/ILMDocumentationIT.java | 74 +++++++++++++++++++ .../ilm/delete_lifecycle_policy.asciidoc | 36 +++++++++ .../high-level/supported-apis.asciidoc | 2 + 3 files changed, 112 insertions(+) create mode 100644 docs/java-rest/high-level/ilm/delete_lifecycle_policy.asciidoc diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/ILMDocumentationIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/ILMDocumentationIT.java index f17ed3154ca..712944219ac 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/ILMDocumentationIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/ILMDocumentationIT.java @@ -137,6 +137,80 @@ public class ILMDocumentationIT extends ESRestHighLevelClientTestCase { } + public void testDeletePolicy() throws IOException, InterruptedException { + RestHighLevelClient client = highLevelClient(); + + // Set up a policy so we have something to delete + PutLifecyclePolicyRequest putRequest; + { + Map phases = new HashMap<>(); + Map hotActions = new HashMap<>(); + hotActions.put(RolloverAction.NAME, new RolloverAction( + new ByteSizeValue(50, ByteSizeUnit.GB), null, null)); + phases.put("hot", new Phase("hot", TimeValue.ZERO, hotActions)); + Map deleteActions = + Collections.singletonMap(DeleteAction.NAME, + new DeleteAction()); + phases.put("delete", + new Phase("delete", + new TimeValue(90, TimeUnit.DAYS), deleteActions)); + LifecyclePolicy myPolicy = new LifecyclePolicy("my_policy", phases); + putRequest = new PutLifecyclePolicyRequest(myPolicy); + AcknowledgedResponse putResponse = client.indexLifecycle(). + putLifecyclePolicy(putRequest, RequestOptions.DEFAULT); + assertTrue(putResponse.isAcknowledged()); + } + + // tag::ilm-delete-lifecycle-policy-request + DeleteLifecyclePolicyRequest request = + new DeleteLifecyclePolicyRequest("my_policy"); // <1> + // end::ilm-delete-lifecycle-policy-request + + // tag::ilm-delete-lifecycle-policy-execute + AcknowledgedResponse response = client.indexLifecycle() + .deleteLifecyclePolicy(request, RequestOptions.DEFAULT); + // end::ilm-delete-lifecycle-policy-execute + + // tag::ilm-delete-lifecycle-policy-response + boolean acknowledged = response.isAcknowledged(); // <1> + // end::ilm-delete-lifecycle-policy-response + + assertTrue(acknowledged); + + // Put the policy again so we can delete it again + { + AcknowledgedResponse putResponse = client.indexLifecycle(). + putLifecyclePolicy(putRequest, RequestOptions.DEFAULT); + assertTrue(putResponse.isAcknowledged()); + } + + // tag::ilm-delete-lifecycle-policy-execute-listener + ActionListener listener = + new ActionListener() { + @Override + public void onResponse(AcknowledgedResponse response) { + boolean acknowledged = response.isAcknowledged(); // <1> + } + + @Override + public void onFailure(Exception e) { + // <2> + } + }; + // end::ilm-delete-lifecycle-policy-execute-listener + + // Replace the empty listener by a blocking listener in test + final CountDownLatch latch = new CountDownLatch(1); + listener = new LatchedActionListener<>(listener, latch); + + // tag::ilm-delete-lifecycle-policy-execute-async + client.indexLifecycle().deleteLifecyclePolicyAsync(request, + RequestOptions.DEFAULT, listener); // <1> + // end::ilm-delete-lifecycle-policy-execute-async + + assertTrue(latch.await(30L, TimeUnit.SECONDS)); + } + public void testGetLifecyclePolicy() throws IOException, InterruptedException { RestHighLevelClient client = highLevelClient(); diff --git a/docs/java-rest/high-level/ilm/delete_lifecycle_policy.asciidoc b/docs/java-rest/high-level/ilm/delete_lifecycle_policy.asciidoc new file mode 100644 index 00000000000..e6f100294ae --- /dev/null +++ b/docs/java-rest/high-level/ilm/delete_lifecycle_policy.asciidoc @@ -0,0 +1,36 @@ +-- +:api: ilm-delete-lifecycle-policy +:request: DeleteLifecyclePolicyRequest +:response: AcknowledgedResponse +-- + +[id="{upid}-{api}"] +=== Delete Lifecycle Policy API + + +[id="{upid}-{api}-request"] +==== Request + +The Delete Lifecycle Policy API allows you to delete an Index Lifecycle +Management Policy from the cluster. + +["source","java",subs="attributes,callouts,macros"] +-------------------------------------------------- +include-tagged::{doc-tests-file}[{api}-request] +-------------------------------------------------- +<1> The policy named `my_policy` will be deleted. + +[id="{upid}-{api}-response"] +==== Response + +The returned +{response}+ indicates if the delete lifecycle policy request was received. + +["source","java",subs="attributes,callouts,macros"] +-------------------------------------------------- +include-tagged::{doc-tests-file}[{api}-response] +-------------------------------------------------- +<1> Whether or not the delete lifecycle policy request was acknowledged. + +include::../execution.asciidoc[] + + diff --git a/docs/java-rest/high-level/supported-apis.asciidoc b/docs/java-rest/high-level/supported-apis.asciidoc index c7420ee9b6e..0ca9fbf6b37 100644 --- a/docs/java-rest/high-level/supported-apis.asciidoc +++ b/docs/java-rest/high-level/supported-apis.asciidoc @@ -457,6 +457,7 @@ The Java High Level REST Client supports the following Index Lifecycle Management APIs: * <<{upid}-ilm-put-lifecycle-policy>> +* <<{upid}-ilm-delete-lifecycle-policy>> * <<{upid}-ilm-get-lifecycle-policy>> * <<{upid}-ilm-start-ilm>> * <<{upid}-ilm-stop-ilm>> @@ -465,6 +466,7 @@ Management APIs: include::ilm/put_lifecycle_policy.asciidoc[] +include::ilm/delete_lifecycle_policy.asciidoc[] include::ilm/get_lifecycle_policy.asciidoc[] include::ilm/start_lifecycle_management.asciidoc[] include::ilm/stop_lifecycle_management.asciidoc[]