HLRC: Add remove index lifecycle policy (#34204)
This change adds the command RemoveIndexLifecyclePolicy to the HLRC. This uses the new TimeRequest as a base class for RemoveIndexLifecyclePolicyRequest on the client side.
This commit is contained in:
parent
0b42eda0e3
commit
80474e138f
|
@ -29,6 +29,8 @@ 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.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 class IndexLifecycleClient {
|
|||
SetIndexLifecyclePolicyResponse::fromXContent, listener, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove 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 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 <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 removeIndexLifecyclePolicyAsync(RemoveIndexLifecyclePolicyRequest request, RequestOptions options,
|
||||
ActionListener<RemoveIndexLifecyclePolicyResponse> listener) {
|
||||
restHighLevelClient.performRequestAsyncAndParseEntity(request, RequestConverters::removeIndexLifecyclePolicy, options,
|
||||
RemoveIndexLifecyclePolicyResponse::fromXContent, listener, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Start the Index Lifecycle Management feature.
|
||||
* See <a href="https://fix-me-when-we-have-docs.com">
|
||||
|
|
|
@ -54,6 +54,7 @@ import org.elasticsearch.client.indexlifecycle.ExplainLifecycleRequest;
|
|||
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 @@ final class RequestConverters {
|
|||
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()
|
||||
|
|
|
@ -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<String> indices;
|
||||
private final IndicesOptions indicesOptions;
|
||||
|
||||
public RemoveIndexLifecyclePolicyRequest(List<String> indices) {
|
||||
this(indices, IndicesOptions.strictExpandOpen());
|
||||
}
|
||||
|
||||
public RemoveIndexLifecyclePolicyRequest(List<String> indices, IndicesOptions indicesOptions) {
|
||||
this.indices = Collections.unmodifiableList(Objects.requireNonNull(indices));
|
||||
this.indicesOptions = Objects.requireNonNull(indicesOptions);
|
||||
}
|
||||
|
||||
public List<String> 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);
|
||||
}
|
||||
}
|
|
@ -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<RemoveIndexLifecyclePolicyResponse, Void> PARSER = new ConstructingObjectParser<>(
|
||||
"change_policy_for_index_response", true, args -> new RemoveIndexLifecyclePolicyResponse((List<String>)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<String> failedIndexes;
|
||||
|
||||
public RemoveIndexLifecyclePolicyResponse(List<String> failedIndexes) {
|
||||
if (failedIndexes == null) {
|
||||
throw new IllegalArgumentException(FAILED_INDEXES_FIELD.getPreferredName() + " cannot be null");
|
||||
}
|
||||
this.failedIndexes = Collections.unmodifiableList(failedIndexes);
|
||||
}
|
||||
|
||||
public List<String> 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);
|
||||
}
|
||||
}
|
|
@ -41,6 +41,8 @@ import org.elasticsearch.client.indexlifecycle.OperationMode;
|
|||
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.elasticsearch.common.unit.TimeValue;
|
|||
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 class IndexLifecycleIT extends ESRestHighLevelClientTestCase {
|
|||
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<String> 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);
|
||||
|
|
|
@ -60,6 +60,7 @@ import org.elasticsearch.client.indexlifecycle.LifecycleManagementStatusRequest;
|
|||
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 class RequestConvertersTests extends ESTestCase {
|
|||
assertThat(request.getParameters(), equalTo(expectedParams));
|
||||
}
|
||||
|
||||
public void testRemoveIndexLifecyclePolicy() {
|
||||
Map<String, String> 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<String, String> expectedParams = new HashMap<>();
|
||||
|
@ -1659,6 +1674,24 @@ public class RequestConvertersTests extends ESTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
static IndicesOptions setRandomIndicesOptions(IndicesOptions indicesOptions, Map<String, String> 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<String, String> expectedParams) {
|
||||
if (randomBoolean()) {
|
||||
boolean includeDefaults = randomBoolean();
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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<String> 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<String> 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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -58,7 +58,7 @@ import org.elasticsearch.xpack.core.indexlifecycle.action.ExplainLifecycleAction
|
|||
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 class XPackClientPlugin extends Plugin implements ActionPlugin, NetworkPl
|
|||
PutLifecycleAction.INSTANCE,
|
||||
ExplainLifecycleAction.INSTANCE,
|
||||
SetIndexLifecyclePolicyAction.INSTANCE,
|
||||
RemovePolicyForIndexAction.INSTANCE,
|
||||
RemoveIndexLifecyclePolicyAction.INSTANCE,
|
||||
MoveToStepAction.INSTANCE,
|
||||
RetryAction.INSTANCE
|
||||
);
|
||||
|
|
|
@ -24,16 +24,16 @@ import java.util.Arrays;
|
|||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class RemovePolicyForIndexAction extends Action<RemovePolicyForIndexAction.Response> {
|
||||
public static final RemovePolicyForIndexAction INSTANCE = new RemovePolicyForIndexAction();
|
||||
public class RemoveIndexLifecyclePolicyAction extends Action<RemoveIndexLifecyclePolicyAction.Response> {
|
||||
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();
|
||||
}
|
||||
|
|
@ -21,7 +21,7 @@ import org.elasticsearch.xpack.core.indexlifecycle.action.ExplainLifecycleAction
|
|||
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 class ILMClient {
|
|||
/**
|
||||
* Removes index lifecycle management from an index
|
||||
*/
|
||||
public void removePolicyForIndex(RemovePolicyForIndexAction.Request request,
|
||||
ActionListener<RemovePolicyForIndexAction.Response> listener) {
|
||||
client.execute(RemovePolicyForIndexAction.INSTANCE, request, listener);
|
||||
public void removeIndexLifecyclePolicy(RemoveIndexLifecyclePolicyAction.Request request,
|
||||
ActionListener<RemoveIndexLifecyclePolicyAction.Response> listener) {
|
||||
client.execute(RemoveIndexLifecyclePolicyAction.INSTANCE, request, listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes index lifecycle management from an index
|
||||
*/
|
||||
public ActionFuture<RemovePolicyForIndexAction.Response> removePolicyForIndex(RemovePolicyForIndexAction.Request request) {
|
||||
return client.execute(RemovePolicyForIndexAction.INSTANCE, request);
|
||||
public ActionFuture<RemoveIndexLifecyclePolicyAction.Response> removeIndexLifecyclePolicy(
|
||||
RemoveIndexLifecyclePolicyAction.Request request) {
|
||||
return client.execute(RemoveIndexLifecyclePolicyAction.INSTANCE, request);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -8,12 +8,12 @@ package org.elasticsearch.xpack.core.indexlifecycle.action;
|
|||
|
||||
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<RemovePolicyForIndexAction.Request> {
|
||||
public class RemoveIndexLifecyclePolicyRequestTests extends AbstractStreamableTestCase<RemoveIndexLifecyclePolicyAction.Request> {
|
||||
|
||||
@Override
|
||||
protected Request createTestInstance() {
|
|
@ -8,7 +8,7 @@ package org.elasticsearch.xpack.core.indexlifecycle.action;
|
|||
|
||||
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.Arrays;
|
|||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class RemovePolicyForIndexResponseTests extends AbstractStreamableXContentTestCase<RemovePolicyForIndexAction.Response> {
|
||||
public class RemoveIndexLifecyclePolicyResponseTests extends AbstractStreamableXContentTestCase<RemoveIndexLifecyclePolicyAction.Response> {
|
||||
|
||||
@Override
|
||||
protected Response createBlankInstance() {
|
|
@ -51,7 +51,7 @@ import org.elasticsearch.xpack.core.indexlifecycle.action.GetLifecycleAction;
|
|||
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.RestGetLifecycleAction;
|
|||
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.TransportGetLifecycleAction
|
|||
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 class IndexLifecycle extends Plugin implements ActionPlugin {
|
|||
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 class IndexLifecycle extends Plugin implements ActionPlugin {
|
|||
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),
|
||||
|
|
|
@ -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.BaseRestHandler;
|
|||
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 class RestRemovePolicyForIndexAction extends BaseRestHandler {
|
|||
@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));
|
||||
}
|
||||
}
|
|
@ -20,20 +20,20 @@ import org.elasticsearch.common.settings.Settings;
|
|||
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<Request, Response> {
|
||||
public class TransportRemoveIndexLifecyclePolicyAction extends TransportMasterNodeAction<Request, Response> {
|
||||
|
||||
@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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue