Skip to content

Commit

Permalink
Add HLRC docs for Delete Lifecycle Policy (#35664)
Browse files Browse the repository at this point in the history
Adds documenatation for the Delete Lifecycle Policy API to the HLRC
documentation.
  • Loading branch information
gwbrown authored Nov 20, 2018
1 parent 89cf4a7 commit 17780ce
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,80 @@ public void onFailure(Exception e) {

}

public void testDeletePolicy() throws IOException, InterruptedException {
RestHighLevelClient client = highLevelClient();

// Set up a policy so we have something to delete
PutLifecyclePolicyRequest putRequest;
{
Map<String, Phase> phases = new HashMap<>();
Map<String, LifecycleAction> 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<String, LifecycleAction> 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<AcknowledgedResponse> listener =
new ActionListener<AcknowledgedResponse>() {
@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();

Expand Down
36 changes: 36 additions & 0 deletions docs/java-rest/high-level/ilm/delete_lifecycle_policy.asciidoc
Original file line number Diff line number Diff line change
@@ -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[]


2 changes: 2 additions & 0 deletions docs/java-rest/high-level/supported-apis.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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>>
Expand All @@ -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[]
Expand Down

0 comments on commit 17780ce

Please sign in to comment.