diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/IndexLifecycleClient.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/IndexLifecycleClient.java index 075e0302696f2..3f4845a12eb84 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/IndexLifecycleClient.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/IndexLifecycleClient.java @@ -29,6 +29,8 @@ import org.elasticsearch.client.indexlifecycle.PutLifecyclePolicyRequest; import org.elasticsearch.client.indexlifecycle.ExplainLifecycleRequest; import org.elasticsearch.client.indexlifecycle.ExplainLifecycleResponse; +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; @@ -161,6 +163,35 @@ public void setIndexLifecyclePolicyAsync(SetIndexLifecyclePolicyRequest request, SetIndexLifecyclePolicyResponse::fromXContent, listener, emptySet()); } + /** + * Remove the index lifecycle policy for an index + * See + * the docs 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 RemoveIndexLifecyclePolicyResponse removeIndexLifecyclePolicy(RemoveIndexLifecyclePolicyRequest request, + RequestOptions options) throws IOException { + return restHighLevelClient.performRequestAndParseEntity(request, RequestConverters::removeIndexLifecyclePolicy, options, + RemoveIndexLifecyclePolicyResponse::fromXContent, emptySet()); + } + + /** + * Asynchronously remove the index lifecycle policy for an index + * See + * the docs 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 removeIndexLifecyclePolicyAsync(RemoveIndexLifecyclePolicyRequest request, RequestOptions options, + ActionListener listener) { + restHighLevelClient.performRequestAsyncAndParseEntity(request, RequestConverters::removeIndexLifecyclePolicy, options, + RemoveIndexLifecyclePolicyResponse::fromXContent, listener, emptySet()); + } + /** * Start the Index Lifecycle Management feature. * See diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/RequestConverters.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/RequestConverters.java index 216024712f6d2..b203cfc2e33c8 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/RequestConverters.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/RequestConverters.java @@ -54,6 +54,7 @@ import org.elasticsearch.client.indexlifecycle.GetLifecyclePolicyRequest; import org.elasticsearch.client.indexlifecycle.LifecycleManagementStatusRequest; import org.elasticsearch.client.indexlifecycle.PutLifecyclePolicyRequest; +import org.elasticsearch.client.indexlifecycle.RemoveIndexLifecyclePolicyRequest; import org.elasticsearch.client.indexlifecycle.SetIndexLifecyclePolicyRequest; import org.elasticsearch.client.indexlifecycle.StartILMRequest; import org.elasticsearch.client.indexlifecycle.StopILMRequest; @@ -652,6 +653,20 @@ static Request setIndexLifecyclePolicy(SetIndexLifecyclePolicyRequest setPolicyR return request; } + static Request removeIndexLifecyclePolicy(RemoveIndexLifecyclePolicyRequest removePolicyRequest) { + String[] indices = removePolicyRequest.indices() == null ? + Strings.EMPTY_ARRAY : removePolicyRequest.indices().toArray(new String[] {}); + Request request = new Request(HttpDelete.METHOD_NAME, + new EndpointBuilder() + .addCommaSeparatedPathParts(indices) + .addPathPartAsIs("_ilm") + .build()); + Params params = new Params(request); + params.withIndicesOptions(removePolicyRequest.indicesOptions()); + params.withMasterTimeout(removePolicyRequest.masterNodeTimeout()); + return request; + } + static Request startILM(StartILMRequest startILMRequest) { Request request = new Request(HttpPost.METHOD_NAME, new EndpointBuilder() diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/indexlifecycle/RemoveIndexLifecyclePolicyRequest.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/indexlifecycle/RemoveIndexLifecyclePolicyRequest.java new file mode 100644 index 0000000000000..88bdf4dd6868d --- /dev/null +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/indexlifecycle/RemoveIndexLifecyclePolicyRequest.java @@ -0,0 +1,68 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.client.indexlifecycle; + +import org.elasticsearch.action.support.IndicesOptions; +import org.elasticsearch.client.TimedRequest; + +import java.util.Collections; +import java.util.List; +import java.util.Objects; + +public class RemoveIndexLifecyclePolicyRequest extends TimedRequest { + + private final List indices; + private final IndicesOptions indicesOptions; + + public RemoveIndexLifecyclePolicyRequest(List indices) { + this(indices, IndicesOptions.strictExpandOpen()); + } + + public RemoveIndexLifecyclePolicyRequest(List indices, IndicesOptions indicesOptions) { + this.indices = Collections.unmodifiableList(Objects.requireNonNull(indices)); + this.indicesOptions = Objects.requireNonNull(indicesOptions); + } + + public List indices() { + return indices; + } + + public IndicesOptions indicesOptions() { + return indicesOptions; + } + + @Override + public int hashCode() { + return Objects.hash(indices, indicesOptions); + } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + RemoveIndexLifecyclePolicyRequest other = (RemoveIndexLifecyclePolicyRequest) obj; + return Objects.deepEquals(indices, other.indices) && + Objects.equals(indicesOptions, other.indicesOptions); + } +} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/indexlifecycle/RemoveIndexLifecyclePolicyResponse.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/indexlifecycle/RemoveIndexLifecyclePolicyResponse.java new file mode 100644 index 0000000000000..3aae1537faa29 --- /dev/null +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/indexlifecycle/RemoveIndexLifecyclePolicyResponse.java @@ -0,0 +1,80 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.client.indexlifecycle; + +import org.elasticsearch.common.ParseField; +import org.elasticsearch.common.xcontent.ConstructingObjectParser; +import org.elasticsearch.common.xcontent.XContentParser; + +import java.util.Collections; +import java.util.List; +import java.util.Objects; + +public class RemoveIndexLifecyclePolicyResponse { + + public static final ParseField HAS_FAILURES_FIELD = new ParseField("has_failures"); + public static final ParseField FAILED_INDEXES_FIELD = new ParseField("failed_indexes"); + @SuppressWarnings("unchecked") + public static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>( + "change_policy_for_index_response", true, args -> new RemoveIndexLifecyclePolicyResponse((List)args[0])); + static { + PARSER.declareStringArray(ConstructingObjectParser.constructorArg(), FAILED_INDEXES_FIELD); + // Needs to be declared but not used in constructing the response object + PARSER.declareBoolean(ConstructingObjectParser.constructorArg(), HAS_FAILURES_FIELD); + } + + private final List failedIndexes; + + public RemoveIndexLifecyclePolicyResponse(List failedIndexes) { + if (failedIndexes == null) { + throw new IllegalArgumentException(FAILED_INDEXES_FIELD.getPreferredName() + " cannot be null"); + } + this.failedIndexes = Collections.unmodifiableList(failedIndexes); + } + + public List getFailedIndexes() { + return failedIndexes; + } + + public boolean hasFailures() { + return failedIndexes.isEmpty() == false; + } + + public static RemoveIndexLifecyclePolicyResponse fromXContent(XContentParser parser) { + return PARSER.apply(parser, null); + } + + @Override + public int hashCode() { + return Objects.hash(failedIndexes); + } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + RemoveIndexLifecyclePolicyResponse other = (RemoveIndexLifecyclePolicyResponse) obj; + return Objects.equals(failedIndexes, other.failedIndexes); + } +} diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/IndexLifecycleIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/IndexLifecycleIT.java index 0879413730752..9d76c19adf74c 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/IndexLifecycleIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/IndexLifecycleIT.java @@ -41,6 +41,8 @@ import org.elasticsearch.client.indexlifecycle.Phase; import org.elasticsearch.client.indexlifecycle.PhaseExecutionInfo; import org.elasticsearch.client.indexlifecycle.PutLifecyclePolicyRequest; +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; @@ -52,6 +54,7 @@ import org.hamcrest.Matchers; import java.io.IOException; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; @@ -88,6 +91,44 @@ public void testSetIndexLifecyclePolicy() throws Exception { 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)); + + GetSettingsRequest getSettingsRequest = new GetSettingsRequest().indices("foo", "baz", "rbh"); + 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)); + assertThat(settingsResponse.getSetting("rbh", "index.lifecycle.name"), equalTo(policyName)); + + List indices = new ArrayList<>(); + indices.add("foo"); + indices.add("rbh"); + RemoveIndexLifecyclePolicyRequest removeReq = new RemoveIndexLifecyclePolicyRequest(indices); + RemoveIndexLifecyclePolicyResponse removeResp = execute(removeReq, highLevelClient().indexLifecycle()::removeIndexLifecyclePolicy, + highLevelClient().indexLifecycle()::removeIndexLifecyclePolicyAsync); + assertThat(removeResp.hasFailures(), is(false)); + assertThat(removeResp.getFailedIndexes().isEmpty(), is(true)); + + getSettingsRequest = new GetSettingsRequest().indices("foo", "baz", "rbh"); + settingsResponse = highLevelClient().indices().getSettings(getSettingsRequest, RequestOptions.DEFAULT); + assertNull(settingsResponse.getSetting("foo", "index.lifecycle.name")); + assertThat(settingsResponse.getSetting("baz", "index.lifecycle.name"), equalTo(policyName)); + assertNull(settingsResponse.getSetting("rbh", "index.lifecycle.name")); + } + public void testStartStopILM() throws Exception { String policyName = randomAlphaOfLength(10); LifecyclePolicy policy = createRandomPolicy(policyName); diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/RequestConvertersTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/RequestConvertersTests.java index 89f2aa58b38b7..5569b81b6991e 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/RequestConvertersTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/RequestConvertersTests.java @@ -60,6 +60,7 @@ import org.elasticsearch.client.indexlifecycle.LifecyclePolicy; import org.elasticsearch.client.indexlifecycle.PutLifecyclePolicyRequest; import org.elasticsearch.client.indexlifecycle.DeleteLifecyclePolicyRequest; +import org.elasticsearch.client.indexlifecycle.RemoveIndexLifecyclePolicyRequest; import org.elasticsearch.common.CheckedBiConsumer; import org.elasticsearch.common.Strings; import org.elasticsearch.common.bytes.BytesArray; @@ -1527,6 +1528,20 @@ public void testSetIndexLifecyclePolicy() throws Exception { assertThat(request.getParameters(), equalTo(expectedParams)); } + public void testRemoveIndexLifecyclePolicy() { + Map expectedParams = new HashMap<>(); + String[] indices = randomIndicesNames(0, 10); + IndicesOptions indicesOptions = setRandomIndicesOptions(IndicesOptions.strictExpandOpen(), expectedParams); + RemoveIndexLifecyclePolicyRequest req = new RemoveIndexLifecyclePolicyRequest(Arrays.asList(indices), indicesOptions); + setRandomMasterTimeout(req::setMasterTimeout, TimedRequest.DEFAULT_TIMEOUT, expectedParams); + + Request request = RequestConverters.removeIndexLifecyclePolicy(req); + assertThat(request.getMethod(), equalTo(HttpDelete.METHOD_NAME)); + String idxString = Strings.arrayToCommaDelimitedString(indices); + assertThat(request.getEndpoint(), equalTo("/" + (idxString.isEmpty() ? "" : (idxString + "/")) + "_ilm")); + assertThat(request.getParameters(), equalTo(expectedParams)); + } + public void testStartILM() throws Exception { StartILMRequest req = new StartILMRequest(); Map expectedParams = new HashMap<>(); @@ -1659,6 +1674,24 @@ static void setRandomIndicesOptions(Consumer setter, Supplier expectedParams) { + if (randomBoolean()) { + indicesOptions = IndicesOptions.fromOptions(randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean()); + } + expectedParams.put("ignore_unavailable", Boolean.toString(indicesOptions.ignoreUnavailable())); + expectedParams.put("allow_no_indices", Boolean.toString(indicesOptions.allowNoIndices())); + if (indicesOptions.expandWildcardsOpen() && indicesOptions.expandWildcardsClosed()) { + expectedParams.put("expand_wildcards", "open,closed"); + } else if (indicesOptions.expandWildcardsOpen()) { + expectedParams.put("expand_wildcards", "open"); + } else if (indicesOptions.expandWildcardsClosed()) { + expectedParams.put("expand_wildcards", "closed"); + } else { + expectedParams.put("expand_wildcards", "none"); + } + return indicesOptions; + } + static void setRandomIncludeDefaults(GetIndexRequest request, Map expectedParams) { if (randomBoolean()) { boolean includeDefaults = randomBoolean(); diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/indexlifecycle/RemoveIndexLifecyclePolicyRequestTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/indexlifecycle/RemoveIndexLifecyclePolicyRequestTests.java new file mode 100644 index 0000000000000..532688c475115 --- /dev/null +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/indexlifecycle/RemoveIndexLifecyclePolicyRequestTests.java @@ -0,0 +1,80 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.client.indexlifecycle; + +import org.elasticsearch.action.support.IndicesOptions; +import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.test.EqualsHashCodeTestUtils; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; + +public class RemoveIndexLifecyclePolicyRequestTests extends ESTestCase { + + public void testNullIndices() { + expectThrows(NullPointerException.class, () -> new RemoveIndexLifecyclePolicyRequest(null)); + } + + public void testNullIndicesOptions() { + expectThrows(NullPointerException.class, () -> new RemoveIndexLifecyclePolicyRequest(Collections.emptyList(), null)); + } + + public void testValidate() { + RemoveIndexLifecyclePolicyRequest request = new RemoveIndexLifecyclePolicyRequest(Collections.emptyList()); + assertFalse(request.validate().isPresent()); + } + + protected RemoveIndexLifecyclePolicyRequest createInstance() { + if (randomBoolean()) { + return new RemoveIndexLifecyclePolicyRequest(Arrays.asList(generateRandomStringArray(20, 20, false)), + IndicesOptions.fromOptions(randomBoolean(), randomBoolean(), randomBoolean(), + randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean())); + } else { + return new RemoveIndexLifecyclePolicyRequest(Arrays.asList(generateRandomStringArray(20, 20, false))); + } + } + + private RemoveIndexLifecyclePolicyRequest copyInstance(RemoveIndexLifecyclePolicyRequest req) { + return new RemoveIndexLifecyclePolicyRequest(new ArrayList<>(req.indices()), IndicesOptions.fromOptions( + req.indicesOptions().ignoreUnavailable(), req.indicesOptions().allowNoIndices(), + req.indicesOptions().expandWildcardsOpen(), req.indicesOptions().expandWildcardsClosed(), + req.indicesOptions().allowAliasesToMultipleIndices(), req.indicesOptions().forbidClosedIndices(), + req.indicesOptions().ignoreAliases())); + } + + private RemoveIndexLifecyclePolicyRequest mutateInstance(RemoveIndexLifecyclePolicyRequest req) { + if (randomBoolean()) { + return new RemoveIndexLifecyclePolicyRequest(req.indices(), + randomValueOtherThan(req.indicesOptions(), () -> IndicesOptions.fromOptions(randomBoolean(), randomBoolean(), + randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean()))); + } else { + return new RemoveIndexLifecyclePolicyRequest( + randomValueOtherThan(req.indices(), () -> Arrays.asList(generateRandomStringArray(20, 20, false))), + req.indicesOptions()); + } + } + + public void testEqualsAndHashCode() { + for (int count = 0; count < 100; ++count) { + EqualsHashCodeTestUtils.checkEqualsAndHashCode(createInstance(), this::copyInstance, this::mutateInstance); + } + } +} diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/indexlifecycle/RemoveIndexLifecyclePolicyResponseTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/indexlifecycle/RemoveIndexLifecyclePolicyResponseTests.java new file mode 100644 index 0000000000000..1f99a2dfdfac4 --- /dev/null +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/indexlifecycle/RemoveIndexLifecyclePolicyResponseTests.java @@ -0,0 +1,93 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.client.indexlifecycle; + +import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.test.EqualsHashCodeTestUtils; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import static org.elasticsearch.test.AbstractXContentTestCase.xContentTester; + +public class RemoveIndexLifecyclePolicyResponseTests extends ESTestCase { + + private void toXContent(RemoveIndexLifecyclePolicyResponse response, XContentBuilder builder) throws IOException { + builder.startObject(); + builder.field(RemoveIndexLifecyclePolicyResponse.HAS_FAILURES_FIELD.getPreferredName(), response.hasFailures()); + builder.field(RemoveIndexLifecyclePolicyResponse.FAILED_INDEXES_FIELD.getPreferredName(), response.getFailedIndexes()); + builder.endObject(); + } + + private RemoveIndexLifecyclePolicyResponse createInstance() { + List failedIndexes = Arrays.asList(generateRandomStringArray(20, 20, false)); + return new RemoveIndexLifecyclePolicyResponse(failedIndexes); + } + + private RemoveIndexLifecyclePolicyResponse copyInstance(RemoveIndexLifecyclePolicyResponse req) { + return new RemoveIndexLifecyclePolicyResponse(new ArrayList<>(req.getFailedIndexes())); + } + + private RemoveIndexLifecyclePolicyResponse mutateInstance(RemoveIndexLifecyclePolicyResponse req) { + return new RemoveIndexLifecyclePolicyResponse(randomValueOtherThan(req.getFailedIndexes(), + () -> Arrays.asList(generateRandomStringArray(20, 20, false)))); + } + + public void testFromXContent() throws IOException { + xContentTester( + this::createParser, + this::createInstance, + this::toXContent, + RemoveIndexLifecyclePolicyResponse::fromXContent) + .supportsUnknownFields(true) + .test(); + } + + public void testNullFailedIndices() { + IllegalArgumentException exception = + expectThrows(IllegalArgumentException.class, () -> new RemoveIndexLifecyclePolicyResponse(null)); + assertEquals("failed_indexes cannot be null", exception.getMessage()); + } + + public void testHasFailures() { + RemoveIndexLifecyclePolicyResponse response = new RemoveIndexLifecyclePolicyResponse(new ArrayList<>()); + assertFalse(response.hasFailures()); + assertEquals(Collections.emptyList(), response.getFailedIndexes()); + + int size = randomIntBetween(1, 10); + List failedIndexes = new ArrayList<>(size); + for (int i = 0; i < size; i++) { + failedIndexes.add(randomAlphaOfLength(20)); + } + response = new RemoveIndexLifecyclePolicyResponse(failedIndexes); + assertTrue(response.hasFailures()); + assertEquals(failedIndexes, response.getFailedIndexes()); + } + + public void testEqualsAndHashCode() { + for (int count = 0; count < 100; ++count) { + EqualsHashCodeTestUtils.checkEqualsAndHashCode(createInstance(), this::copyInstance, this::mutateInstance); + } + } +} diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackClientPlugin.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackClientPlugin.java index 183d021cd6c36..cdae1ff235eb8 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackClientPlugin.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackClientPlugin.java @@ -58,7 +58,7 @@ import org.elasticsearch.xpack.core.indexlifecycle.action.GetLifecycleAction; import org.elasticsearch.xpack.core.indexlifecycle.action.MoveToStepAction; import org.elasticsearch.xpack.core.indexlifecycle.action.PutLifecycleAction; -import org.elasticsearch.xpack.core.indexlifecycle.action.RemovePolicyForIndexAction; +import org.elasticsearch.xpack.core.indexlifecycle.action.RemoveIndexLifecyclePolicyAction; import org.elasticsearch.xpack.core.indexlifecycle.action.RetryAction; import org.elasticsearch.xpack.core.indexlifecycle.action.SetIndexLifecyclePolicyAction; import org.elasticsearch.xpack.core.logstash.LogstashFeatureSetUsage; @@ -343,7 +343,7 @@ public List> getClientActions() { PutLifecycleAction.INSTANCE, ExplainLifecycleAction.INSTANCE, SetIndexLifecyclePolicyAction.INSTANCE, - RemovePolicyForIndexAction.INSTANCE, + RemoveIndexLifecyclePolicyAction.INSTANCE, MoveToStepAction.INSTANCE, RetryAction.INSTANCE ); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/action/RemovePolicyForIndexAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/action/RemoveIndexLifecyclePolicyAction.java similarity index 94% rename from x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/action/RemovePolicyForIndexAction.java rename to x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/action/RemoveIndexLifecyclePolicyAction.java index 8a3a47109e862..239e748e58d8a 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/action/RemovePolicyForIndexAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/action/RemoveIndexLifecyclePolicyAction.java @@ -24,16 +24,16 @@ import java.util.List; import java.util.Objects; -public class RemovePolicyForIndexAction extends Action { - public static final RemovePolicyForIndexAction INSTANCE = new RemovePolicyForIndexAction(); +public class RemoveIndexLifecyclePolicyAction extends Action { + public static final RemoveIndexLifecyclePolicyAction INSTANCE = new RemoveIndexLifecyclePolicyAction(); public static final String NAME = "indices:admin/ilm/remove_policy"; - protected RemovePolicyForIndexAction() { + protected RemoveIndexLifecyclePolicyAction() { super(NAME); } @Override - public RemovePolicyForIndexAction.Response newResponse() { + public RemoveIndexLifecyclePolicyAction.Response newResponse() { return new Response(); } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/client/ILMClient.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/client/ILMClient.java index ef842f202429b..60aee60f4fe24 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/client/ILMClient.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/client/ILMClient.java @@ -21,7 +21,7 @@ import org.elasticsearch.xpack.core.indexlifecycle.action.GetLifecycleAction; import org.elasticsearch.xpack.core.indexlifecycle.action.GetStatusAction; import org.elasticsearch.xpack.core.indexlifecycle.action.PutLifecycleAction; -import org.elasticsearch.xpack.core.indexlifecycle.action.RemovePolicyForIndexAction; +import org.elasticsearch.xpack.core.indexlifecycle.action.RemoveIndexLifecyclePolicyAction; import org.elasticsearch.xpack.core.indexlifecycle.action.RetryAction; import org.elasticsearch.xpack.core.indexlifecycle.action.SetIndexLifecyclePolicyAction; import org.elasticsearch.xpack.core.indexlifecycle.action.StartILMAction; @@ -125,16 +125,17 @@ public ActionFuture setIndexLifecyclePolicy(Set /** * Removes index lifecycle management from an index */ - public void removePolicyForIndex(RemovePolicyForIndexAction.Request request, - ActionListener listener) { - client.execute(RemovePolicyForIndexAction.INSTANCE, request, listener); + public void removeIndexLifecyclePolicy(RemoveIndexLifecyclePolicyAction.Request request, + ActionListener listener) { + client.execute(RemoveIndexLifecyclePolicyAction.INSTANCE, request, listener); } /** * Removes index lifecycle management from an index */ - public ActionFuture removePolicyForIndex(RemovePolicyForIndexAction.Request request) { - return client.execute(RemovePolicyForIndexAction.INSTANCE, request); + public ActionFuture removeIndexLifecyclePolicy( + RemoveIndexLifecyclePolicyAction.Request request) { + return client.execute(RemoveIndexLifecyclePolicyAction.INSTANCE, request); } /** diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/action/RemovePolicyForIndexRequestTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/action/RemoveIndexLifecyclePolicyRequestTests.java similarity index 93% rename from x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/action/RemovePolicyForIndexRequestTests.java rename to x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/action/RemoveIndexLifecyclePolicyRequestTests.java index b4fde97df0a5b..3f36820422614 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/action/RemovePolicyForIndexRequestTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/action/RemoveIndexLifecyclePolicyRequestTests.java @@ -8,12 +8,12 @@ import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.test.AbstractStreamableTestCase; -import org.elasticsearch.xpack.core.indexlifecycle.action.RemovePolicyForIndexAction.Request; +import org.elasticsearch.xpack.core.indexlifecycle.action.RemoveIndexLifecyclePolicyAction.Request; import java.io.IOException; import java.util.Arrays; -public class RemovePolicyForIndexRequestTests extends AbstractStreamableTestCase { +public class RemoveIndexLifecyclePolicyRequestTests extends AbstractStreamableTestCase { @Override protected Request createTestInstance() { diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/action/RemovePolicyForIndexResponseTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/action/RemoveIndexLifecyclePolicyResponseTests.java similarity index 92% rename from x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/action/RemovePolicyForIndexResponseTests.java rename to x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/action/RemoveIndexLifecyclePolicyResponseTests.java index 48c9affecd9de..a394e593e7307 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/action/RemovePolicyForIndexResponseTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/action/RemoveIndexLifecyclePolicyResponseTests.java @@ -8,7 +8,7 @@ import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.test.AbstractStreamableXContentTestCase; -import org.elasticsearch.xpack.core.indexlifecycle.action.RemovePolicyForIndexAction.Response; +import org.elasticsearch.xpack.core.indexlifecycle.action.RemoveIndexLifecyclePolicyAction.Response; import java.io.IOException; import java.util.ArrayList; @@ -16,7 +16,7 @@ import java.util.Collections; import java.util.List; -public class RemovePolicyForIndexResponseTests extends AbstractStreamableXContentTestCase { +public class RemoveIndexLifecyclePolicyResponseTests extends AbstractStreamableXContentTestCase { @Override protected Response createBlankInstance() { diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycle.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycle.java index 8179ea0db0432..8d294614ee53b 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycle.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycle.java @@ -51,7 +51,7 @@ import org.elasticsearch.xpack.core.indexlifecycle.action.GetStatusAction; import org.elasticsearch.xpack.core.indexlifecycle.action.MoveToStepAction; import org.elasticsearch.xpack.core.indexlifecycle.action.PutLifecycleAction; -import org.elasticsearch.xpack.core.indexlifecycle.action.RemovePolicyForIndexAction; +import org.elasticsearch.xpack.core.indexlifecycle.action.RemoveIndexLifecyclePolicyAction; import org.elasticsearch.xpack.core.indexlifecycle.action.RetryAction; import org.elasticsearch.xpack.core.indexlifecycle.action.SetIndexLifecyclePolicyAction; import org.elasticsearch.xpack.core.indexlifecycle.action.StartILMAction; @@ -62,7 +62,7 @@ import org.elasticsearch.xpack.indexlifecycle.action.RestGetStatusAction; import org.elasticsearch.xpack.indexlifecycle.action.RestMoveToStepAction; import org.elasticsearch.xpack.indexlifecycle.action.RestPutLifecycleAction; -import org.elasticsearch.xpack.indexlifecycle.action.RestRemovePolicyForIndexAction; +import org.elasticsearch.xpack.indexlifecycle.action.RestRemoveIndexLifecyclePolicyAction; import org.elasticsearch.xpack.indexlifecycle.action.RestRetryAction; import org.elasticsearch.xpack.indexlifecycle.action.RestSetIndexLifecyclePolicyAction; import org.elasticsearch.xpack.indexlifecycle.action.RestStartILMAction; @@ -73,7 +73,7 @@ import org.elasticsearch.xpack.indexlifecycle.action.TransportGetStatusAction; import org.elasticsearch.xpack.indexlifecycle.action.TransportMoveToStepAction; import org.elasticsearch.xpack.indexlifecycle.action.TransportPutLifecycleAction; -import org.elasticsearch.xpack.indexlifecycle.action.TransportRemovePolicyForIndexAction; +import org.elasticsearch.xpack.indexlifecycle.action.TransportRemoveIndexLifecyclePolicyAction; import org.elasticsearch.xpack.indexlifecycle.action.TransportRetryAction; import org.elasticsearch.xpack.indexlifecycle.action.TransportSetIndexLifecyclePolicyAction; import org.elasticsearch.xpack.indexlifecycle.action.TransportStartILMAction; @@ -177,7 +177,7 @@ public List getRestHandlers(Settings settings, RestController restC new RestDeleteLifecycleAction(settings, restController), new RestExplainLifecycleAction(settings, restController), new RestSetIndexLifecyclePolicyAction(settings, restController), - new RestRemovePolicyForIndexAction(settings, restController), + new RestRemoveIndexLifecyclePolicyAction(settings, restController), new RestMoveToStepAction(settings, restController), new RestRetryAction(settings, restController), new RestStopAction(settings, restController), @@ -197,7 +197,7 @@ public List getRestHandlers(Settings settings, RestController restC new ActionHandler<>(DeleteLifecycleAction.INSTANCE, TransportDeleteLifecycleAction.class), new ActionHandler<>(ExplainLifecycleAction.INSTANCE, TransportExplainLifecycleAction.class), new ActionHandler<>(SetIndexLifecyclePolicyAction.INSTANCE, TransportSetIndexLifecyclePolicyAction.class), - new ActionHandler<>(RemovePolicyForIndexAction.INSTANCE, TransportRemovePolicyForIndexAction.class), + new ActionHandler<>(RemoveIndexLifecyclePolicyAction.INSTANCE, TransportRemoveIndexLifecyclePolicyAction.class), new ActionHandler<>(MoveToStepAction.INSTANCE, TransportMoveToStepAction.class), new ActionHandler<>(RetryAction.INSTANCE, TransportRetryAction.class), new ActionHandler<>(StartILMAction.INSTANCE, TransportStartILMAction.class), diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/RestRemovePolicyForIndexAction.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/RestRemoveIndexLifecyclePolicyAction.java similarity index 66% rename from x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/RestRemovePolicyForIndexAction.java rename to x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/RestRemoveIndexLifecyclePolicyAction.java index 1a14995168aef..afa328ab8d8fe 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/RestRemovePolicyForIndexAction.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/RestRemoveIndexLifecyclePolicyAction.java @@ -6,6 +6,7 @@ package org.elasticsearch.xpack.indexlifecycle.action; +import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; import org.elasticsearch.common.settings.Settings; @@ -13,13 +14,13 @@ import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; -import org.elasticsearch.xpack.core.indexlifecycle.action.RemovePolicyForIndexAction; +import org.elasticsearch.xpack.core.indexlifecycle.action.RemoveIndexLifecyclePolicyAction; import java.io.IOException; -public class RestRemovePolicyForIndexAction extends BaseRestHandler { +public class RestRemoveIndexLifecyclePolicyAction extends BaseRestHandler { - public RestRemovePolicyForIndexAction(Settings settings, RestController controller) { + public RestRemoveIndexLifecyclePolicyAction(Settings settings, RestController controller) { super(settings); controller.registerHandler(RestRequest.Method.DELETE, "/{index}/_ilm", this); } @@ -32,9 +33,11 @@ public String getName() { @Override protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient client) throws IOException { String[] indexes = Strings.splitStringByCommaToArray(restRequest.param("index")); - RemovePolicyForIndexAction.Request changePolicyRequest = new RemovePolicyForIndexAction.Request(indexes); + RemoveIndexLifecyclePolicyAction.Request changePolicyRequest = new RemoveIndexLifecyclePolicyAction.Request(indexes); changePolicyRequest.masterNodeTimeout(restRequest.paramAsTime("master_timeout", changePolicyRequest.masterNodeTimeout())); + changePolicyRequest.indicesOptions(IndicesOptions.fromRequest(restRequest, changePolicyRequest.indicesOptions())); - return channel -> client.execute(RemovePolicyForIndexAction.INSTANCE, changePolicyRequest, new RestToXContentListener<>(channel)); + return channel -> + client.execute(RemoveIndexLifecyclePolicyAction.INSTANCE, changePolicyRequest, new RestToXContentListener<>(channel)); } } \ No newline at end of file diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/TransportRemovePolicyForIndexAction.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/TransportRemoveIndexLifecyclePolicyAction.java similarity index 86% rename from x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/TransportRemovePolicyForIndexAction.java rename to x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/TransportRemoveIndexLifecyclePolicyAction.java index 7a5428249d6f8..149921a29a3d1 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/TransportRemovePolicyForIndexAction.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/TransportRemoveIndexLifecyclePolicyAction.java @@ -20,20 +20,20 @@ import org.elasticsearch.index.Index; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.xpack.core.indexlifecycle.action.RemovePolicyForIndexAction; -import org.elasticsearch.xpack.core.indexlifecycle.action.RemovePolicyForIndexAction.Request; -import org.elasticsearch.xpack.core.indexlifecycle.action.RemovePolicyForIndexAction.Response; +import org.elasticsearch.xpack.core.indexlifecycle.action.RemoveIndexLifecyclePolicyAction; +import org.elasticsearch.xpack.core.indexlifecycle.action.RemoveIndexLifecyclePolicyAction.Request; +import org.elasticsearch.xpack.core.indexlifecycle.action.RemoveIndexLifecyclePolicyAction.Response; import org.elasticsearch.xpack.indexlifecycle.IndexLifecycleRunner; import java.util.ArrayList; import java.util.List; -public class TransportRemovePolicyForIndexAction extends TransportMasterNodeAction { +public class TransportRemoveIndexLifecyclePolicyAction extends TransportMasterNodeAction { @Inject - public TransportRemovePolicyForIndexAction(Settings settings, TransportService transportService, ClusterService clusterService, + public TransportRemoveIndexLifecyclePolicyAction(Settings settings, TransportService transportService, ClusterService clusterService, ThreadPool threadPool, ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver) { - super(settings, RemovePolicyForIndexAction.NAME, transportService, clusterService, threadPool, actionFilters, + super(settings, RemoveIndexLifecyclePolicyAction.NAME, transportService, clusterService, threadPool, actionFilters, indexNameExpressionResolver, Request::new); }