HLRC: Add parameters to stopRollupJob API (#35545)
With #34811 the API for stopping rollup jobs got two new url parameters "wait_for_completion" and "timeout". This change adds these to the HLRC APIs as well. Relates to #34811
This commit is contained in:
parent
8e2c84ad8b
commit
bc5b1afb55
|
@ -50,6 +50,7 @@ import org.elasticsearch.action.support.IndicesOptions;
|
|||
import org.elasticsearch.action.support.WriteRequest;
|
||||
import org.elasticsearch.action.update.UpdateRequest;
|
||||
import org.elasticsearch.client.core.CountRequest;
|
||||
import org.elasticsearch.client.core.TermVectorsRequest;
|
||||
import org.elasticsearch.client.security.RefreshPolicy;
|
||||
import org.elasticsearch.cluster.health.ClusterHealthStatus;
|
||||
import org.elasticsearch.common.Nullable;
|
||||
|
@ -78,7 +79,6 @@ import org.elasticsearch.script.mustache.MultiSearchTemplateRequest;
|
|||
import org.elasticsearch.script.mustache.SearchTemplateRequest;
|
||||
import org.elasticsearch.search.fetch.subphase.FetchSourceContext;
|
||||
import org.elasticsearch.tasks.TaskId;
|
||||
import org.elasticsearch.client.core.TermVectorsRequest;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
|
@ -264,7 +264,7 @@ final class RequestConverters {
|
|||
|
||||
return request;
|
||||
}
|
||||
|
||||
|
||||
static Request sourceExists(GetRequest getRequest) {
|
||||
Request request = new Request(HttpHead.METHOD_NAME, endpoint(getRequest.index(), getRequest.type(), getRequest.id(), "_source"));
|
||||
|
||||
|
@ -275,7 +275,7 @@ final class RequestConverters {
|
|||
parameters.withRealtime(getRequest.realtime());
|
||||
// Version params are not currently supported by the source exists API so are not passed
|
||||
return request;
|
||||
}
|
||||
}
|
||||
|
||||
static Request multiGet(MultiGetRequest multiGetRequest) throws IOException {
|
||||
Request request = new Request(HttpPost.METHOD_NAME, "/_mget");
|
||||
|
|
|
@ -65,7 +65,14 @@ final class RollupRequestConverters {
|
|||
.addPathPart(stopRollupJobRequest.getJobId())
|
||||
.addPathPartAsIs("_stop")
|
||||
.build();
|
||||
return new Request(HttpPost.METHOD_NAME, endpoint);
|
||||
|
||||
Request request = new Request(HttpPost.METHOD_NAME, endpoint);
|
||||
RequestConverters.Params parameters = new RequestConverters.Params(request);
|
||||
parameters.withTimeout(stopRollupJobRequest.timeout());
|
||||
if (stopRollupJobRequest.waitForCompletion() != null) {
|
||||
parameters.withWaitForCompletion(stopRollupJobRequest.waitForCompletion());
|
||||
}
|
||||
return request;
|
||||
}
|
||||
|
||||
static Request getJob(final GetRollupJobRequest getRollupJobRequest) {
|
||||
|
|
|
@ -19,12 +19,15 @@
|
|||
package org.elasticsearch.client.rollup;
|
||||
|
||||
import org.elasticsearch.client.Validatable;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class StopRollupJobRequest implements Validatable {
|
||||
|
||||
private final String jobId;
|
||||
private TimeValue timeout;
|
||||
private Boolean waitForCompletion;
|
||||
|
||||
public StopRollupJobRequest(final String jobId) {
|
||||
this.jobId = Objects.requireNonNull(jobId, "id parameter must not be null");
|
||||
|
@ -46,4 +49,26 @@ public class StopRollupJobRequest implements Validatable {
|
|||
public int hashCode() {
|
||||
return Objects.hash(jobId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the requests optional "timeout" parameter.
|
||||
*/
|
||||
public void timeout(TimeValue timeout) {
|
||||
this.timeout = timeout;
|
||||
}
|
||||
|
||||
public TimeValue timeout() {
|
||||
return this.timeout;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the requests optional "wait_for_completion".
|
||||
*/
|
||||
public void waitForCompletion(boolean waitForCompletion) {
|
||||
this.waitForCompletion = waitForCompletion;
|
||||
}
|
||||
|
||||
public Boolean waitForCompletion() {
|
||||
return this.waitForCompletion;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -235,8 +235,14 @@ public class RollupIT extends ESRestHighLevelClientTestCase {
|
|||
|
||||
// stop the job
|
||||
StopRollupJobRequest stopRequest = new StopRollupJobRequest(id);
|
||||
stopRequest.waitForCompletion(randomBoolean());
|
||||
StopRollupJobResponse stopResponse = execute(stopRequest, rollupClient::stopRollupJob, rollupClient::stopRollupJobAsync);
|
||||
assertTrue(stopResponse.isAcknowledged());
|
||||
if (stopRequest.waitForCompletion()) {
|
||||
getResponse = execute(new GetRollupJobRequest(id), rollupClient::getRollupJob, rollupClient::getRollupJobAsync);
|
||||
assertThat(getResponse.getJobs(), hasSize(1));
|
||||
assertThat(getResponse.getJobs().get(0).getStatus().getState(), equalTo(IndexerState.STOPPED));
|
||||
}
|
||||
}
|
||||
|
||||
public void testGetMissingRollupJob() throws Exception {
|
||||
|
|
|
@ -28,6 +28,7 @@ import org.elasticsearch.client.rollup.StartRollupJobRequest;
|
|||
import org.elasticsearch.client.rollup.StopRollupJobRequest;
|
||||
import org.elasticsearch.client.rollup.job.config.RollupJobConfig;
|
||||
import org.elasticsearch.client.rollup.job.config.RollupJobConfigTests;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -64,13 +65,27 @@ public class RollupRequestConvertersTests extends ESTestCase {
|
|||
|
||||
public void testStopJob() throws IOException {
|
||||
String jobId = randomAlphaOfLength(5);
|
||||
|
||||
StopRollupJobRequest stopJob = new StopRollupJobRequest(jobId);
|
||||
String expectedTimeOutString = null;
|
||||
String expectedWaitForCompletion = null;
|
||||
int expectedParameters = 0;
|
||||
if (randomBoolean()) {
|
||||
stopJob.timeout(TimeValue.parseTimeValue(randomPositiveTimeValue(), "timeout"));
|
||||
expectedTimeOutString = stopJob.timeout().getStringRep();
|
||||
expectedParameters++;
|
||||
}
|
||||
if (randomBoolean()) {
|
||||
stopJob.waitForCompletion(randomBoolean());
|
||||
expectedWaitForCompletion = stopJob.waitForCompletion().toString();
|
||||
expectedParameters++;
|
||||
}
|
||||
|
||||
Request request = RollupRequestConverters.stopJob(stopJob);
|
||||
assertThat(request.getEndpoint(), equalTo("/_xpack/rollup/job/" + jobId + "/_stop"));
|
||||
assertThat(HttpPost.METHOD_NAME, equalTo(request.getMethod()));
|
||||
assertThat(request.getParameters().keySet(), empty());
|
||||
assertThat(request.getParameters().keySet().size(), equalTo(expectedParameters));
|
||||
assertThat(request.getParameters().get("timeout"), equalTo(expectedTimeOutString));
|
||||
assertThat(request.getParameters().get("wait_for_completion"), equalTo(expectedWaitForCompletion));
|
||||
assertNull(request.getEntity());
|
||||
}
|
||||
|
||||
|
|
|
@ -288,6 +288,8 @@ public class RollupDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
String id = "job_1";
|
||||
// tag::rollup-stop-job-request
|
||||
StopRollupJobRequest request = new StopRollupJobRequest(id); // <1>
|
||||
request.waitForCompletion(true); // <2>
|
||||
request.timeout(TimeValue.timeValueSeconds(10)); // <3>
|
||||
// end::rollup-stop-job-request
|
||||
|
||||
|
||||
|
|
|
@ -17,6 +17,11 @@ The Stop Rollup Job API allows you to stop a job by ID.
|
|||
include-tagged::{doc-tests-file}[{api}-request]
|
||||
--------------------------------------------------
|
||||
<1> The ID of the job to stop.
|
||||
<2> Whether the request should wait that the stop operation has completed
|
||||
before returning (optional, defaults to `false`)
|
||||
<3> If `wait_for_completion=true`, this parameter controls how long to wait
|
||||
before giving up and throwing an error (optional, defaults to 30 seconds).
|
||||
|
||||
|
||||
[id="{upid}-{api}-response"]
|
||||
==== Response
|
||||
|
|
Loading…
Reference in New Issue