Skip to content

Commit

Permalink
Fix documentation test
Browse files Browse the repository at this point in the history
  • Loading branch information
gwbrown committed Jan 23, 2019
1 parent 755acfe commit 7a42638
Showing 1 changed file with 56 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.apache.http.util.EntityUtils;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.LatchedActionListener;
import org.elasticsearch.action.admin.indices.alias.Alias;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
import org.elasticsearch.client.ESRestHighLevelClientTestCase;
import org.elasticsearch.client.RequestOptions;
Expand All @@ -39,17 +40,17 @@
import org.elasticsearch.client.indexlifecycle.LifecycleManagementStatusRequest;
import org.elasticsearch.client.indexlifecycle.LifecycleManagementStatusResponse;
import org.elasticsearch.client.indexlifecycle.LifecyclePolicy;
import org.elasticsearch.client.indexlifecycle.OperationMode;
import org.elasticsearch.client.indexlifecycle.LifecyclePolicyMetadata;
import org.elasticsearch.client.indexlifecycle.OperationMode;
import org.elasticsearch.client.indexlifecycle.Phase;
import org.elasticsearch.client.indexlifecycle.PutLifecyclePolicyRequest;
import org.elasticsearch.client.indexlifecycle.RemoveIndexLifecyclePolicyRequest;
import org.elasticsearch.client.indexlifecycle.RemoveIndexLifecyclePolicyResponse;
import org.elasticsearch.client.indexlifecycle.RetryLifecyclePolicyRequest;
import org.elasticsearch.client.indexlifecycle.RolloverAction;
import org.elasticsearch.client.indexlifecycle.ShrinkAction;
import org.elasticsearch.client.indexlifecycle.StartILMRequest;
import org.elasticsearch.client.indexlifecycle.StopILMRequest;
import org.elasticsearch.client.indexlifecycle.ShrinkAction;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.collect.ImmutableOpenMap;
Expand Down Expand Up @@ -337,11 +338,13 @@ public void testExplainLifecycle() throws Exception {
new PutLifecyclePolicyRequest(policy);
client.indexLifecycle().putLifecyclePolicy(putRequest, RequestOptions.DEFAULT);

CreateIndexRequest createIndexRequest = new CreateIndexRequest("my_index",
CreateIndexRequest createIndexRequest = new CreateIndexRequest("my_index-1",
Settings.builder()
.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
.put("index.lifecycle.name", "my_policy")
.put("index.lifecycle.rollover_alias", "my_alias")
.build());
createIndexRequest.alias(new Alias("my_alias").writeIndex(true));
client.indices().create(createIndexRequest, RequestOptions.DEFAULT);
CreateIndexRequest createOtherIndexRequest = new CreateIndexRequest("other_index",
Settings.builder()
Expand All @@ -352,58 +355,62 @@ public void testExplainLifecycle() throws Exception {

// wait for the policy to become active
assertBusy(() -> assertNotNull(client.indexLifecycle()
.explainLifecycle(new ExplainLifecycleRequest("my_index"), RequestOptions.DEFAULT)
.getIndexResponses().get("my_index").getAction()));
.explainLifecycle(new ExplainLifecycleRequest("my_index-1"), RequestOptions.DEFAULT)
.getIndexResponses().get("my_index-1").getAction()));
}

// tag::ilm-explain-lifecycle-request
ExplainLifecycleRequest request =
new ExplainLifecycleRequest("my_index", "other_index"); // <1>
new ExplainLifecycleRequest("my_index-1", "other_index"); // <1>
// end::ilm-explain-lifecycle-request

// tag::ilm-explain-lifecycle-execute
ExplainLifecycleResponse response = client.indexLifecycle()
.explainLifecycle(request, RequestOptions.DEFAULT);
// end::ilm-explain-lifecycle-execute
assertNotNull(response);

// tag::ilm-explain-lifecycle-response
Map<String, IndexLifecycleExplainResponse> indices =
response.getIndexResponses();
IndexLifecycleExplainResponse myIndex = indices.get("my_index");
String policyName = myIndex.getPolicyName(); // <1>
boolean isManaged = myIndex.managedByILM(); // <2>

String phase = myIndex.getPhase(); // <3>
long phaseTime = myIndex.getPhaseTime(); // <4>
String action = myIndex.getAction(); // <5>
long actionTime = myIndex.getActionTime();
String step = myIndex.getStep(); // <6>
long stepTime = myIndex.getStepTime();

String failedStep = myIndex.getFailedStep(); // <7>
// end::ilm-explain-lifecycle-response
assertEquals("my_policy", policyName);
assertTrue(isManaged);

assertEquals("hot", phase);
assertNotEquals(0, phaseTime);
assertEquals("rollover", action);
assertNotEquals(0, actionTime);
assertEquals("check-rollover-ready", step);
assertNotEquals(0, stepTime);

assertNull(failedStep);

IndexLifecycleExplainResponse otherIndex = indices.get("other_index");
assertFalse(otherIndex.managedByILM());
assertNull(otherIndex.getPolicyName());
assertNull(otherIndex.getPhase());
assertNull(otherIndex.getAction());
assertNull(otherIndex.getStep());
assertNull(otherIndex.getFailedStep());
assertNull(otherIndex.getPhaseExecutionInfo());
assertNull(otherIndex.getStepInfo());

assertBusy(() -> {
// tag::ilm-explain-lifecycle-execute
ExplainLifecycleResponse response = client.indexLifecycle()
.explainLifecycle(request, RequestOptions.DEFAULT);
// end::ilm-explain-lifecycle-execute
assertNotNull(response);

// tag::ilm-explain-lifecycle-response
Map<String, IndexLifecycleExplainResponse> indices =
response.getIndexResponses();
IndexLifecycleExplainResponse myIndex = indices.get("my_index-1");
String policyName = myIndex.getPolicyName(); // <1>
boolean isManaged = myIndex.managedByILM(); // <2>

String phase = myIndex.getPhase(); // <3>
long phaseTime = myIndex.getPhaseTime(); // <4>
String action = myIndex.getAction(); // <5>
long actionTime = myIndex.getActionTime();
String step = myIndex.getStep(); // <6>
long stepTime = myIndex.getStepTime();

String failedStep = myIndex.getFailedStep(); // <7>
// end::ilm-explain-lifecycle-response

assertEquals("my_policy", policyName);
assertTrue(isManaged);

assertEquals("hot", phase);
assertNotEquals(0, phaseTime);
assertEquals("rollover", action);
assertNotEquals(0, actionTime);
assertEquals("check-rollover-ready", step);
assertNotEquals(0, stepTime);

assertNull(failedStep);

IndexLifecycleExplainResponse otherIndex = indices.get("other_index");
assertFalse(otherIndex.managedByILM());
assertNull(otherIndex.getPolicyName());
assertNull(otherIndex.getPhase());
assertNull(otherIndex.getAction());
assertNull(otherIndex.getStep());
assertNull(otherIndex.getFailedStep());
assertNull(otherIndex.getPhaseExecutionInfo());
assertNull(otherIndex.getStepInfo());
});

// tag::ilm-explain-lifecycle-execute-listener
ActionListener<ExplainLifecycleResponse> listener =
Expand Down

0 comments on commit 7a42638

Please sign in to comment.