parent
84ef91529c
commit
910e97422f
|
@ -29,6 +29,7 @@ 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;
|
||||
|
@ -302,4 +303,32 @@ public class IndexLifecycleClient {
|
|||
restHighLevelClient.performRequestAsyncAndParseEntity(request, RequestConverters::explainLifecycle, options,
|
||||
ExplainLifecycleResponse::fromXContent, listener, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Retry lifecycle step for given indices
|
||||
* 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 AcknowledgedResponse retryLifecycleStep(RetryLifecyclePolicyRequest request, RequestOptions options) throws IOException {
|
||||
return restHighLevelClient.performRequestAndParseEntity(request, RequestConverters::retryLifecycle, options,
|
||||
AcknowledgedResponse::fromXContent, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Asynchronously retry the lifecycle step for given indices
|
||||
* 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 retryLifecycleStepAsync(RetryLifecyclePolicyRequest request, RequestOptions options,
|
||||
ActionListener<AcknowledgedResponse> listener) {
|
||||
restHighLevelClient.performRequestAsyncAndParseEntity(request, RequestConverters::retryLifecycle, options,
|
||||
AcknowledgedResponse::fromXContent, listener, emptySet());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
package org.elasticsearch.client;
|
||||
|
||||
import java.util.List;
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.client.methods.HttpDelete;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
|
@ -54,6 +55,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.RetryLifecyclePolicyRequest;
|
||||
import org.elasticsearch.client.indexlifecycle.RemoveIndexLifecyclePolicyRequest;
|
||||
import org.elasticsearch.client.indexlifecycle.SetIndexLifecyclePolicyRequest;
|
||||
import org.elasticsearch.client.indexlifecycle.StartILMRequest;
|
||||
|
@ -717,6 +719,19 @@ final class RequestConverters {
|
|||
return request;
|
||||
}
|
||||
|
||||
static Request retryLifecycle(RetryLifecyclePolicyRequest retryLifecyclePolicyRequest) {
|
||||
Request request = new Request(HttpPost.METHOD_NAME,
|
||||
new EndpointBuilder()
|
||||
.addCommaSeparatedPathParts(retryLifecyclePolicyRequest.getIndices())
|
||||
.addPathPartAsIs("_ilm")
|
||||
.addPathPartAsIs("retry")
|
||||
.build());
|
||||
Params params = new Params(request);
|
||||
params.withMasterTimeout(retryLifecyclePolicyRequest.masterNodeTimeout());
|
||||
params.withTimeout(retryLifecyclePolicyRequest.timeout());
|
||||
return request;
|
||||
}
|
||||
|
||||
static HttpEntity createEntity(ToXContent toXContent, XContentType xContentType) throws IOException {
|
||||
BytesRef source = XContentHelper.toXContent(toXContent, xContentType, false).toBytesRef();
|
||||
return new ByteArrayEntity(source.bytes, source.offset, source.length, createContentType(xContentType));
|
||||
|
@ -1102,7 +1117,12 @@ final class RequestConverters {
|
|||
return this;
|
||||
}
|
||||
|
||||
EndpointBuilder addPathPartAsIs(String... parts) {
|
||||
EndpointBuilder addCommaSeparatedPathParts(List<String> parts) {
|
||||
addPathPart(String.join(",", parts));
|
||||
return this;
|
||||
}
|
||||
|
||||
EndpointBuilder addPathPartAsIs(String ... parts) {
|
||||
for (String part : parts) {
|
||||
if (Strings.hasLength(part)) {
|
||||
joiner.add(part);
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* 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 java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import org.elasticsearch.client.TimedRequest;
|
||||
|
||||
public class RetryLifecyclePolicyRequest extends TimedRequest {
|
||||
|
||||
private final List<String> indices;
|
||||
|
||||
public RetryLifecyclePolicyRequest(String... indices) {
|
||||
if (indices.length == 0) {
|
||||
throw new IllegalArgumentException("Must at least specify one index to retry");
|
||||
}
|
||||
this.indices = Arrays.asList(indices);
|
||||
}
|
||||
|
||||
public List<String> getIndices() {
|
||||
return indices;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
RetryLifecyclePolicyRequest that = (RetryLifecyclePolicyRequest) o;
|
||||
return indices.size() == that.indices.size() && indices.containsAll(that.indices);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(indices);
|
||||
}
|
||||
}
|
|
@ -41,6 +41,7 @@ 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.RetryLifecyclePolicyRequest;
|
||||
import org.elasticsearch.client.indexlifecycle.RemoveIndexLifecyclePolicyRequest;
|
||||
import org.elasticsearch.client.indexlifecycle.RemoveIndexLifecyclePolicyResponse;
|
||||
import org.elasticsearch.client.indexlifecycle.RolloverAction;
|
||||
|
@ -288,4 +289,26 @@ public class IndexLifecycleIT extends ESRestHighLevelClientTestCase {
|
|||
.map(p -> ((LifecyclePolicyMetadata) p).getPolicy()).collect(Collectors.toList());
|
||||
assertThat(retrievedPolicies, hasItems(policies));
|
||||
}
|
||||
|
||||
public void testRetryLifecycleStep() throws IOException {
|
||||
String policyName = randomAlphaOfLength(10);
|
||||
LifecyclePolicy policy = createRandomPolicy(policyName);
|
||||
PutLifecyclePolicyRequest putRequest = new PutLifecyclePolicyRequest(policy);
|
||||
assertAcked(execute(putRequest, highLevelClient().indexLifecycle()::putLifecyclePolicy,
|
||||
highLevelClient().indexLifecycle()::putLifecyclePolicyAsync));
|
||||
createIndex("retry", Settings.builder().put("index.lifecycle.name", policy.getName()).build());
|
||||
RetryLifecyclePolicyRequest retryRequest = new RetryLifecyclePolicyRequest("retry");
|
||||
ElasticsearchStatusException ex = expectThrows(ElasticsearchStatusException.class,
|
||||
() -> execute(
|
||||
retryRequest, highLevelClient().indexLifecycle()::retryLifecycleStep,
|
||||
highLevelClient().indexLifecycle()::retryLifecycleStepAsync
|
||||
)
|
||||
);
|
||||
assertEquals(400, ex.status().getStatus());
|
||||
assertEquals(
|
||||
"Elasticsearch exception [type=illegal_argument_exception, reason=cannot retry an action for an index [retry]" +
|
||||
" that has not encountered an error when running a Lifecycle Policy]",
|
||||
ex.getRootCause().getMessage()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.RetryLifecyclePolicyRequest;
|
||||
import org.elasticsearch.client.indexlifecycle.RemoveIndexLifecyclePolicyRequest;
|
||||
import org.elasticsearch.common.CheckedBiConsumer;
|
||||
import org.elasticsearch.common.Strings;
|
||||
|
@ -1593,6 +1594,19 @@ public class RequestConvertersTests extends ESTestCase {
|
|||
assertThat(request.getParameters(), equalTo(expectedParams));
|
||||
}
|
||||
|
||||
public void testRetryLifecycle() throws Exception {
|
||||
String[] indices = randomIndicesNames(1, 10);
|
||||
RetryLifecyclePolicyRequest req = new RetryLifecyclePolicyRequest(indices);
|
||||
Map<String, String> expectedParams = new HashMap<>();
|
||||
setRandomMasterTimeout(req::setMasterTimeout, TimedRequest.DEFAULT_MASTER_NODE_TIMEOUT, expectedParams);
|
||||
setRandomTimeoutTimeValue(req::setTimeout, TimedRequest.DEFAULT_ACK_TIMEOUT, expectedParams);
|
||||
Request request = RequestConverters.retryLifecycle(req);
|
||||
assertThat(request.getMethod(), equalTo(HttpPost.METHOD_NAME));
|
||||
String idxString = Strings.arrayToCommaDelimitedString(indices);
|
||||
assertThat(request.getEndpoint(), equalTo("/" + (idxString.isEmpty() ? "" : (idxString + "/")) + "_ilm/retry"));
|
||||
assertThat(request.getParameters(), equalTo(expectedParams));
|
||||
}
|
||||
|
||||
/**
|
||||
* Randomize the {@link FetchSourceContext} request parameters.
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue