Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,16 @@
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.support.master.AcknowledgedResponse;
import org.elasticsearch.client.indexlifecycle.DeleteLifecyclePolicyRequest;
import org.elasticsearch.client.indexlifecycle.ExplainLifecycleRequest;
import org.elasticsearch.client.indexlifecycle.ExplainLifecycleResponse;
import org.elasticsearch.client.indexlifecycle.GetLifecyclePolicyRequest;
import org.elasticsearch.client.indexlifecycle.GetLifecyclePolicyResponse;
import org.elasticsearch.client.indexlifecycle.LifecycleManagementStatusRequest;
import org.elasticsearch.client.indexlifecycle.LifecycleManagementStatusResponse;
import org.elasticsearch.client.indexlifecycle.PutLifecyclePolicyRequest;
import org.elasticsearch.client.indexlifecycle.ExplainLifecycleRequest;
import org.elasticsearch.client.indexlifecycle.ExplainLifecycleResponse;
import org.elasticsearch.client.indexlifecycle.RetryLifecyclePolicyRequest;
import org.elasticsearch.client.indexlifecycle.RemoveIndexLifecyclePolicyRequest;
import org.elasticsearch.client.indexlifecycle.RemoveIndexLifecyclePolicyResponse;
import org.elasticsearch.client.indexlifecycle.SetIndexLifecyclePolicyRequest;
import org.elasticsearch.client.indexlifecycle.SetIndexLifecyclePolicyResponse;
import org.elasticsearch.client.indexlifecycle.StartILMRequest;
import org.elasticsearch.client.indexlifecycle.StopILMRequest;

Expand Down Expand Up @@ -135,35 +133,6 @@ public void deleteLifecyclePolicyAsync(DeleteLifecyclePolicyRequest request, Req
AcknowledgedResponse::fromXContent, listener, emptySet());
}

/**
* Set the index lifecycle policy for an index
* See <a href="https://fix-me-when-we-have-docs.com">
* the docs</a> for more.
* @param request the request
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
* @return the response
* @throws IOException in case there is a problem sending the request or parsing back the response
*/
public SetIndexLifecyclePolicyResponse setIndexLifecyclePolicy(SetIndexLifecyclePolicyRequest request,
RequestOptions options) throws IOException {
return restHighLevelClient.performRequestAndParseEntity(request, RequestConverters::setIndexLifecyclePolicy, options,
SetIndexLifecyclePolicyResponse::fromXContent, emptySet());
}

/**
* Asynchronously set the index lifecycle policy for an index
* See <a href="https://fix-me-when-we-have-docs.com">
* the docs</a> for more.
* @param request the request
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
* @param listener the listener to be notified upon request completion
*/
public void setIndexLifecyclePolicyAsync(SetIndexLifecyclePolicyRequest request, RequestOptions options,
ActionListener<SetIndexLifecyclePolicyResponse> listener) {
restHighLevelClient.performRequestAsyncAndParseEntity(request, RequestConverters::setIndexLifecyclePolicy, options,
SetIndexLifecyclePolicyResponse::fromXContent, listener, emptySet());
}

/**
* Remove the index lifecycle policy for an index
* See <a href="https://fix-me-when-we-have-docs.com">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
import org.elasticsearch.client.indexlifecycle.PutLifecyclePolicyRequest;
import org.elasticsearch.client.indexlifecycle.RetryLifecyclePolicyRequest;
import org.elasticsearch.client.indexlifecycle.RemoveIndexLifecyclePolicyRequest;
import org.elasticsearch.client.indexlifecycle.SetIndexLifecyclePolicyRequest;
import org.elasticsearch.client.indexlifecycle.StartILMRequest;
import org.elasticsearch.client.indexlifecycle.StopILMRequest;
import org.elasticsearch.client.security.RefreshPolicy;
Expand Down Expand Up @@ -641,20 +640,6 @@ static Request deleteLifecyclePolicy(DeleteLifecyclePolicyRequest deleteLifecycl
return request;
}

static Request setIndexLifecyclePolicy(SetIndexLifecyclePolicyRequest setPolicyRequest) {
String[] indices = setPolicyRequest.indices() == null ? Strings.EMPTY_ARRAY : setPolicyRequest.indices();
Request request = new Request(HttpPut.METHOD_NAME,
new EndpointBuilder()
.addCommaSeparatedPathParts(indices)
.addPathPartAsIs("_ilm")
.addPathPart(setPolicyRequest.policy())
.build());
Params params = new Params(request);
params.withIndicesOptions(setPolicyRequest.indicesOptions());
params.withMasterTimeout(setPolicyRequest.masterNodeTimeout());
return request;
}

static Request removeIndexLifecyclePolicy(RemoveIndexLifecyclePolicyRequest removePolicyRequest) {
String[] indices = removePolicyRequest.indices() == null ?
Strings.EMPTY_ARRAY : removePolicyRequest.indices().toArray(new String[] {});
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@
import org.elasticsearch.client.indexlifecycle.RemoveIndexLifecyclePolicyRequest;
import org.elasticsearch.client.indexlifecycle.RemoveIndexLifecyclePolicyResponse;
import org.elasticsearch.client.indexlifecycle.RolloverAction;
import org.elasticsearch.client.indexlifecycle.SetIndexLifecyclePolicyRequest;
import org.elasticsearch.client.indexlifecycle.SetIndexLifecyclePolicyResponse;
import org.elasticsearch.client.indexlifecycle.ShrinkAction;
import org.elasticsearch.client.indexlifecycle.StartILMRequest;
import org.elasticsearch.client.indexlifecycle.StopILMRequest;
Expand All @@ -71,42 +69,16 @@

public class IndexLifecycleIT extends ESRestHighLevelClientTestCase {

public void testSetIndexLifecyclePolicy() throws Exception {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worth replacing this test case with one that makes sure changing the lifecycle policy via the settings API works as expected (i.e. actually runs the new policy)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, that was the intention of the outstanding task in the description

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad, I misread that task.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NP. My intention was to have this as a server side test rather than a test in the HLRC because its testing ILM functionality rather than the client or the API. Does that work for you or do you feel strongly this should be tested as part of the client?

Copy link
Contributor

@gwbrown gwbrown Oct 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m good with testing it server side.

String policyName = randomAlphaOfLength(10);
LifecyclePolicy policy = createRandomPolicy(policyName);
PutLifecyclePolicyRequest putRequest = new PutLifecyclePolicyRequest(policy);
assertAcked(execute(putRequest, highLevelClient().indexLifecycle()::putLifecyclePolicy,
highLevelClient().indexLifecycle()::putLifecyclePolicyAsync));

createIndex("foo", Settings.builder().put("index.lifecycle.name", "bar").build());
createIndex("baz", Settings.builder().put("index.lifecycle.name", "eggplant").build());
SetIndexLifecyclePolicyRequest req = new SetIndexLifecyclePolicyRequest(policyName, "foo", "baz");
SetIndexLifecyclePolicyResponse response = execute(req, highLevelClient().indexLifecycle()::setIndexLifecyclePolicy,
highLevelClient().indexLifecycle()::setIndexLifecyclePolicyAsync);
assertThat(response.hasFailures(), is(false));
assertThat(response.getFailedIndexes().isEmpty(), is(true));

GetSettingsRequest getSettingsRequest = new GetSettingsRequest().indices("foo", "baz");
GetSettingsResponse settingsResponse = highLevelClient().indices().getSettings(getSettingsRequest, RequestOptions.DEFAULT);
assertThat(settingsResponse.getSetting("foo", "index.lifecycle.name"), equalTo(policyName));
assertThat(settingsResponse.getSetting("baz", "index.lifecycle.name"), equalTo(policyName));
}

public void testRemoveIndexLifecyclePolicy() throws Exception {
String policyName = randomAlphaOfLength(10);
LifecyclePolicy policy = createRandomPolicy(policyName);
PutLifecyclePolicyRequest putRequest = new PutLifecyclePolicyRequest(policy);
assertAcked(execute(putRequest, highLevelClient().indexLifecycle()::putLifecyclePolicy,
highLevelClient().indexLifecycle()::putLifecyclePolicyAsync));

createIndex("foo", Settings.builder().put("index.lifecycle.name", "bar").build());
createIndex("baz", Settings.builder().put("index.lifecycle.name", "eggplant").build());
createIndex("rbh", Settings.builder().put("index.lifecycle.name", "whatisthis").build());
SetIndexLifecyclePolicyRequest setReq = new SetIndexLifecyclePolicyRequest(policyName, "foo", "baz", "rbh");
SetIndexLifecyclePolicyResponse setResp = execute(setReq, highLevelClient().indexLifecycle()::setIndexLifecyclePolicy,
highLevelClient().indexLifecycle()::setIndexLifecyclePolicyAsync);
assertThat(setResp.hasFailures(), is(false));
assertThat(setResp.getFailedIndexes().isEmpty(), is(true));
createIndex("foo", Settings.builder().put("index.lifecycle.name", policyName).build());
createIndex("baz", Settings.builder().put("index.lifecycle.name", policyName).build());
createIndex("rbh", Settings.builder().put("index.lifecycle.name", policyName).build());

GetSettingsRequest getSettingsRequest = new GetSettingsRequest().indices("foo", "baz", "rbh");
GetSettingsResponse settingsResponse = highLevelClient().indices().getSettings(getSettingsRequest, RequestOptions.DEFAULT);
Expand Down
Loading