Add delete rollup job support to HL REST Client (#34066)
Add support for delete rollup job to HL REST Client.
This commit is contained in:
parent
d43a1fac33
commit
936faba6c4
|
@ -20,6 +20,8 @@
|
|||
package org.elasticsearch.client;
|
||||
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.client.rollup.DeleteRollupJobRequest;
|
||||
import org.elasticsearch.client.rollup.DeleteRollupJobResponse;
|
||||
import org.elasticsearch.client.rollup.GetRollupJobRequest;
|
||||
import org.elasticsearch.client.rollup.GetRollupJobResponse;
|
||||
import org.elasticsearch.client.rollup.PutRollupJobRequest;
|
||||
|
@ -76,6 +78,40 @@ public class RollupClient {
|
|||
listener, Collections.emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a rollup job from the cluster
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/rollup-delete-job.html">
|
||||
* 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 DeleteRollupJobResponse deleteRollupJob(DeleteRollupJobRequest request, RequestOptions options) throws IOException {
|
||||
return restHighLevelClient.performRequestAndParseEntity(request,
|
||||
RollupRequestConverters::deleteJob,
|
||||
options,
|
||||
DeleteRollupJobResponse::fromXContent,
|
||||
Collections.emptySet());
|
||||
}
|
||||
/**
|
||||
* Asynchronously delete a rollup job from the cluster
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/rollup-delete-job.html">
|
||||
* The docs</a> for details.
|
||||
* @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 deleteRollupJobAsync(DeleteRollupJobRequest request,
|
||||
RequestOptions options,
|
||||
ActionListener<DeleteRollupJobResponse> listener) {
|
||||
restHighLevelClient.performRequestAsyncAndParseEntity(request,
|
||||
RollupRequestConverters::deleteJob,
|
||||
options,
|
||||
DeleteRollupJobResponse::fromXContent,
|
||||
listener, Collections.emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a rollup job from the cluster.
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/rollup-put-job.html">
|
||||
|
|
|
@ -18,8 +18,10 @@
|
|||
*/
|
||||
package org.elasticsearch.client;
|
||||
|
||||
import org.apache.http.client.methods.HttpDelete;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.client.methods.HttpPut;
|
||||
import org.elasticsearch.client.rollup.DeleteRollupJobRequest;
|
||||
import org.elasticsearch.client.rollup.GetRollupJobRequest;
|
||||
import org.elasticsearch.client.rollup.PutRollupJobRequest;
|
||||
|
||||
|
@ -54,4 +56,16 @@ final class RollupRequestConverters {
|
|||
.build();
|
||||
return new Request(HttpGet.METHOD_NAME, endpoint);
|
||||
}
|
||||
|
||||
static Request deleteJob(final DeleteRollupJobRequest deleteRollupJobRequest) throws IOException {
|
||||
String endpoint = new RequestConverters.EndpointBuilder()
|
||||
.addPathPartAsIs("_xpack")
|
||||
.addPathPartAsIs("rollup")
|
||||
.addPathPartAsIs("job")
|
||||
.addPathPart(deleteRollupJobRequest.getId())
|
||||
.build();
|
||||
Request request = new Request(HttpDelete.METHOD_NAME, endpoint);
|
||||
request.setEntity(createEntity(deleteRollupJobRequest, REQUEST_BODY_CONTENT_TYPE));
|
||||
return request;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* 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.rollup;
|
||||
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.ToXContentObject;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
|
||||
public abstract class AcknowledgedResponse implements ToXContentObject {
|
||||
private final boolean acknowledged;
|
||||
|
||||
public AcknowledgedResponse(final boolean acknowledged) {
|
||||
this.acknowledged = acknowledged;
|
||||
}
|
||||
|
||||
public boolean isAcknowledged() {
|
||||
return acknowledged;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
final AcknowledgedResponse that = (AcknowledgedResponse) o;
|
||||
return isAcknowledged() == that.isAcknowledged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(acknowledged);
|
||||
}
|
||||
|
||||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException {
|
||||
builder.startObject();
|
||||
{
|
||||
builder.field("acknowledged", isAcknowledged());
|
||||
}
|
||||
builder.endObject();
|
||||
return builder;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* 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.rollup;
|
||||
|
||||
import org.elasticsearch.client.Validatable;
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
|
||||
import org.elasticsearch.common.xcontent.ToXContentObject;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
|
||||
|
||||
public class DeleteRollupJobRequest implements Validatable, ToXContentObject {
|
||||
|
||||
private static final ParseField ID_FIELD = new ParseField("id");
|
||||
private final String id;
|
||||
|
||||
|
||||
public DeleteRollupJobRequest(String id) {
|
||||
this.id = Objects.requireNonNull(id, "id parameter must not be null");
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
private static final ConstructingObjectParser<DeleteRollupJobRequest, Void> PARSER =
|
||||
new ConstructingObjectParser<>("request", a -> {
|
||||
return new DeleteRollupJobRequest((String) a[0]);
|
||||
});
|
||||
|
||||
static {
|
||||
PARSER.declareString(ConstructingObjectParser.constructorArg(), ID_FIELD);
|
||||
}
|
||||
|
||||
public static DeleteRollupJobRequest fromXContent(XContentParser parser) {
|
||||
return PARSER.apply(parser, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.startObject();
|
||||
builder.field(ID_FIELD.getPreferredName(), this.id);
|
||||
builder.endObject();
|
||||
return builder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
DeleteRollupJobRequest that = (DeleteRollupJobRequest) o;
|
||||
return Objects.equals(id, that.id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(id);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* 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.rollup;
|
||||
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.elasticsearch.common.xcontent.ConstructingObjectParser.constructorArg;
|
||||
|
||||
public class DeleteRollupJobResponse extends AcknowledgedResponse {
|
||||
|
||||
public DeleteRollupJobResponse(boolean acknowledged) {
|
||||
super(acknowledged);
|
||||
}
|
||||
|
||||
public static DeleteRollupJobResponse fromXContent(final XContentParser parser) throws IOException {
|
||||
return PARSER.parse(parser, null);
|
||||
}
|
||||
|
||||
private static final ConstructingObjectParser<DeleteRollupJobResponse, Void> PARSER
|
||||
= new ConstructingObjectParser<>("delete_rollup_job_response", true,
|
||||
args -> new DeleteRollupJobResponse((boolean) args[0]));
|
||||
static {
|
||||
PARSER.declareBoolean(constructorArg(), new ParseField("acknowledged"));
|
||||
}
|
||||
}
|
|
@ -20,52 +20,21 @@ package org.elasticsearch.client.rollup;
|
|||
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
|
||||
import org.elasticsearch.common.xcontent.ToXContentObject;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
|
||||
import static org.elasticsearch.common.xcontent.ConstructingObjectParser.constructorArg;
|
||||
|
||||
public class PutRollupJobResponse implements ToXContentObject {
|
||||
public class PutRollupJobResponse extends AcknowledgedResponse {
|
||||
|
||||
private final boolean acknowledged;
|
||||
|
||||
public PutRollupJobResponse(final boolean acknowledged) {
|
||||
this.acknowledged = acknowledged;
|
||||
public PutRollupJobResponse(boolean acknowledged) {
|
||||
super(acknowledged);
|
||||
}
|
||||
|
||||
public boolean isAcknowledged() {
|
||||
return acknowledged;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
final PutRollupJobResponse that = (PutRollupJobResponse) o;
|
||||
return isAcknowledged() == that.isAcknowledged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(acknowledged);
|
||||
}
|
||||
|
||||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.startObject();
|
||||
{
|
||||
builder.field("acknowledged", isAcknowledged());
|
||||
}
|
||||
builder.endObject();
|
||||
return builder;
|
||||
public static PutRollupJobResponse fromXContent(final XContentParser parser) throws IOException {
|
||||
return PARSER.parse(parser, null);
|
||||
}
|
||||
|
||||
private static final ConstructingObjectParser<PutRollupJobResponse, Void> PARSER
|
||||
|
@ -73,8 +42,4 @@ public class PutRollupJobResponse implements ToXContentObject {
|
|||
static {
|
||||
PARSER.declareBoolean(constructorArg(), new ParseField("acknowledged"));
|
||||
}
|
||||
|
||||
public static PutRollupJobResponse fromXContent(final XContentParser parser) throws IOException {
|
||||
return PARSER.parse(parser, null);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
*/
|
||||
package org.elasticsearch.client;
|
||||
|
||||
import org.elasticsearch.ElasticsearchStatusException;
|
||||
import org.elasticsearch.action.admin.indices.refresh.RefreshRequest;
|
||||
import org.elasticsearch.action.admin.indices.refresh.RefreshResponse;
|
||||
import org.elasticsearch.action.bulk.BulkItemResponse;
|
||||
|
@ -31,6 +32,8 @@ import org.elasticsearch.client.rollup.GetRollupJobRequest;
|
|||
import org.elasticsearch.client.rollup.GetRollupJobResponse;
|
||||
import org.elasticsearch.client.rollup.GetRollupJobResponse.IndexerState;
|
||||
import org.elasticsearch.client.rollup.GetRollupJobResponse.JobWrapper;
|
||||
import org.elasticsearch.client.rollup.DeleteRollupJobRequest;
|
||||
import org.elasticsearch.client.rollup.DeleteRollupJobResponse;
|
||||
import org.elasticsearch.client.rollup.PutRollupJobRequest;
|
||||
import org.elasticsearch.client.rollup.PutRollupJobResponse;
|
||||
import org.elasticsearch.client.rollup.job.config.DateHistogramGroupConfig;
|
||||
|
@ -46,6 +49,7 @@ import org.elasticsearch.search.aggregations.metrics.MaxAggregationBuilder;
|
|||
import org.elasticsearch.search.aggregations.metrics.MinAggregationBuilder;
|
||||
import org.elasticsearch.search.aggregations.metrics.SumAggregationBuilder;
|
||||
import org.elasticsearch.search.aggregations.metrics.ValueCountAggregationBuilder;
|
||||
import org.junit.Before;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
@ -60,19 +64,35 @@ import static org.hamcrest.Matchers.greaterThan;
|
|||
import static org.hamcrest.Matchers.hasKey;
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
import static org.hamcrest.Matchers.empty;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.lessThan;
|
||||
|
||||
public class RollupIT extends ESRestHighLevelClientTestCase {
|
||||
|
||||
private static final List<String> SUPPORTED_METRICS = Arrays.asList(MaxAggregationBuilder.NAME, MinAggregationBuilder.NAME,
|
||||
SumAggregationBuilder.NAME, AvgAggregationBuilder.NAME, ValueCountAggregationBuilder.NAME);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testPutAndGetRollupJob() throws Exception {
|
||||
double sum = 0.0d;
|
||||
int max = Integer.MIN_VALUE;
|
||||
int min = Integer.MAX_VALUE;
|
||||
private static final List<String> SUPPORTED_METRICS = Arrays.asList(MaxAggregationBuilder.NAME, MinAggregationBuilder.NAME,
|
||||
SumAggregationBuilder.NAME, AvgAggregationBuilder.NAME, ValueCountAggregationBuilder.NAME);
|
||||
|
||||
private String id;
|
||||
private String indexPattern;
|
||||
private String rollupIndex;
|
||||
private String cron;
|
||||
private int pageSize;
|
||||
private int numDocs;
|
||||
|
||||
@Before
|
||||
public void init() throws Exception {
|
||||
id = randomAlphaOfLength(10);
|
||||
indexPattern = randomFrom("docs", "d*", "doc*");
|
||||
rollupIndex = randomFrom("rollup", "test");
|
||||
cron = "*/1 * * * * ?";
|
||||
numDocs = indexDocs();
|
||||
pageSize = randomIntBetween(numDocs, numDocs * 10);
|
||||
}
|
||||
|
||||
public int indexDocs() throws Exception {
|
||||
final BulkRequest bulkRequest = new BulkRequest();
|
||||
bulkRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
|
||||
for (int minute = 0; minute < 60; minute++) {
|
||||
|
@ -112,12 +132,33 @@ public class RollupIT extends ESRestHighLevelClientTestCase {
|
|||
|
||||
RefreshResponse refreshResponse = highLevelClient().indices().refresh(new RefreshRequest("docs"), RequestOptions.DEFAULT);
|
||||
assertEquals(0, refreshResponse.getFailedShards());
|
||||
return numDocs;
|
||||
}
|
||||
|
||||
final String id = randomAlphaOfLength(10);
|
||||
final String indexPattern = randomFrom("docs", "d*", "doc*");
|
||||
final String rollupIndex = randomFrom("rollup", "test");
|
||||
final String cron = "*/1 * * * * ?";
|
||||
final int pageSize = randomIntBetween(numDocs, numDocs * 10);
|
||||
|
||||
public void testDeleteRollupJob() throws Exception {
|
||||
final GroupConfig groups = new GroupConfig(new DateHistogramGroupConfig("date", DateHistogramInterval.DAY));
|
||||
final List<MetricConfig> metrics = Collections.singletonList(new MetricConfig("value", SUPPORTED_METRICS));
|
||||
final TimeValue timeout = TimeValue.timeValueSeconds(randomIntBetween(30, 600));
|
||||
PutRollupJobRequest putRollupJobRequest =
|
||||
new PutRollupJobRequest(new RollupJobConfig(id, indexPattern, rollupIndex, cron, pageSize, groups, metrics, timeout));
|
||||
final RollupClient rollupClient = highLevelClient().rollup();
|
||||
PutRollupJobResponse response = execute(putRollupJobRequest, rollupClient::putRollupJob, rollupClient::putRollupJobAsync);
|
||||
DeleteRollupJobRequest deleteRollupJobRequest = new DeleteRollupJobRequest(id);
|
||||
DeleteRollupJobResponse deleteRollupJobResponse = highLevelClient().rollup()
|
||||
.deleteRollupJob(deleteRollupJobRequest, RequestOptions.DEFAULT);
|
||||
assertTrue(deleteRollupJobResponse.isAcknowledged());
|
||||
}
|
||||
|
||||
public void testDeleteMissingRollupJob() {
|
||||
DeleteRollupJobRequest deleteRollupJobRequest = new DeleteRollupJobRequest(randomAlphaOfLength(10));
|
||||
ElasticsearchStatusException responseException = expectThrows(ElasticsearchStatusException.class,() -> highLevelClient().rollup()
|
||||
.deleteRollupJob(deleteRollupJobRequest, RequestOptions.DEFAULT));
|
||||
assertThat(responseException.status().getStatus(), is(404));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testPutAndGetRollupJob() throws Exception {
|
||||
// TODO expand this to also test with histogram and terms?
|
||||
final GroupConfig groups = new GroupConfig(new DateHistogramGroupConfig("date", DateHistogramInterval.DAY));
|
||||
final List<MetricConfig> metrics = Collections.singletonList(new MetricConfig("value", SUPPORTED_METRICS));
|
||||
|
@ -134,9 +175,6 @@ public class RollupIT extends ESRestHighLevelClientTestCase {
|
|||
Response startResponse = client().performRequest(new Request("POST", "/_xpack/rollup/job/" + id + "/_start"));
|
||||
assertEquals(RestStatus.OK.getStatus(), startResponse.getHttpResponse().getStatusLine().getStatusCode());
|
||||
|
||||
int finalMin = min;
|
||||
int finalMax = max;
|
||||
double finalSum = sum;
|
||||
assertBusy(() -> {
|
||||
SearchResponse searchResponse = highLevelClient().search(new SearchRequest(rollupIndex), RequestOptions.DEFAULT);
|
||||
assertEquals(0, searchResponse.getFailedShards());
|
||||
|
@ -154,13 +192,13 @@ public class RollupIT extends ESRestHighLevelClientTestCase {
|
|||
for (String name : metric.getMetrics()) {
|
||||
Number value = (Number) source.get(metric.getField() + "." + name + ".value");
|
||||
if ("min".equals(name)) {
|
||||
assertEquals(finalMin, value.intValue());
|
||||
assertEquals(min, value.intValue());
|
||||
} else if ("max".equals(name)) {
|
||||
assertEquals(finalMax, value.intValue());
|
||||
assertEquals(max, value.intValue());
|
||||
} else if ("sum".equals(name)) {
|
||||
assertEquals(finalSum, value.doubleValue(), 0.0d);
|
||||
assertEquals(sum, value.doubleValue(), 0.0d);
|
||||
} else if ("avg".equals(name)) {
|
||||
assertEquals(finalSum, value.doubleValue(), 0.0d);
|
||||
assertEquals(sum, value.doubleValue(), 0.0d);
|
||||
Number avgCount = (Number) source.get(metric.getField() + "." + name + "._count");
|
||||
assertEquals(numDocs, avgCount.intValue());
|
||||
} else if ("value_count".equals(name)) {
|
||||
|
@ -191,4 +229,5 @@ public class RollupIT extends ESRestHighLevelClientTestCase {
|
|||
GetRollupJobResponse getResponse = execute(getRollupJobRequest, rollupClient::getRollupJob, rollupClient::getRollupJobAsync);
|
||||
assertThat(getResponse.getJobs(), empty());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -36,6 +36,8 @@ import org.elasticsearch.client.rollup.GetRollupJobResponse;
|
|||
import org.elasticsearch.client.rollup.GetRollupJobResponse.JobWrapper;
|
||||
import org.elasticsearch.client.rollup.GetRollupJobResponse.RollupIndexerJobStats;
|
||||
import org.elasticsearch.client.rollup.GetRollupJobResponse.RollupJobStatus;
|
||||
import org.elasticsearch.client.rollup.DeleteRollupJobRequest;
|
||||
import org.elasticsearch.client.rollup.DeleteRollupJobResponse;
|
||||
import org.elasticsearch.client.rollup.PutRollupJobRequest;
|
||||
import org.elasticsearch.client.rollup.PutRollupJobResponse;
|
||||
import org.elasticsearch.client.rollup.job.config.DateHistogramGroupConfig;
|
||||
|
@ -280,4 +282,53 @@ public class RollupDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void testDeleteRollupJob() throws Exception {
|
||||
RestHighLevelClient client = highLevelClient();
|
||||
|
||||
String id = "job_2";
|
||||
|
||||
// tag::rollup-delete-job-request
|
||||
DeleteRollupJobRequest request = new DeleteRollupJobRequest(id); // <1>
|
||||
// end::rollup-delete-job-request
|
||||
try {
|
||||
// tag::rollup-delete-job-execute
|
||||
DeleteRollupJobResponse response = client.rollup().deleteRollupJob(request, RequestOptions.DEFAULT);
|
||||
// end::rollup-delete-job-execute
|
||||
|
||||
// tag::rollup-delete-job-response
|
||||
response.isAcknowledged(); // <1>
|
||||
// end::rollup-delete-job-response
|
||||
} catch (Exception e) {
|
||||
// Swallow any exception, this test does not test actually cancelling.
|
||||
}
|
||||
|
||||
|
||||
|
||||
// tag::rollup-delete-job-execute-listener
|
||||
ActionListener<DeleteRollupJobResponse> listener = new ActionListener<DeleteRollupJobResponse>() {
|
||||
@Override
|
||||
public void onResponse(DeleteRollupJobResponse response) {
|
||||
boolean acknowledged = response.isAcknowledged(); // <1>
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Exception e) {
|
||||
// <2>
|
||||
}
|
||||
};
|
||||
// end::rollup-delete-job-execute-listener
|
||||
|
||||
// Replace the empty listener by a blocking listener in test
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
listener = new LatchedActionListener<>(listener, latch);
|
||||
|
||||
// tag::rollup-delete-job-execute-async
|
||||
client.rollup().deleteRollupJobAsync(request, RequestOptions.DEFAULT, listener); // <1>
|
||||
// end::rollup-delete-job-execute-async
|
||||
|
||||
assertTrue(latch.await(30L, TimeUnit.SECONDS));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* 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.rollup;
|
||||
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.test.AbstractXContentTestCase;
|
||||
import org.junit.Before;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class DeleteRollupJobRequestTests extends AbstractXContentTestCase<DeleteRollupJobRequest> {
|
||||
|
||||
private String jobId;
|
||||
|
||||
@Before
|
||||
public void setUpOptionalId() {
|
||||
jobId = randomAlphaOfLengthBetween(1, 10);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DeleteRollupJobRequest createTestInstance() {
|
||||
return new DeleteRollupJobRequest(jobId);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DeleteRollupJobRequest doParseInstance(final XContentParser parser) throws IOException {
|
||||
return DeleteRollupJobRequest.fromXContent(parser);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean supportsUnknownFields() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void testRequireConfiguration() {
|
||||
final NullPointerException e = expectThrows(NullPointerException.class, ()-> new DeleteRollupJobRequest(null));
|
||||
assertEquals("id parameter must not be null", e.getMessage());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* 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.rollup;
|
||||
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.test.AbstractXContentTestCase;
|
||||
import org.junit.Before;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class DeleteRollupJobResponseTests extends AbstractXContentTestCase<DeleteRollupJobResponse> {
|
||||
|
||||
private boolean acknowledged;
|
||||
|
||||
@Before
|
||||
public void setupJobID() {
|
||||
acknowledged = randomBoolean();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DeleteRollupJobResponse createTestInstance() {
|
||||
return new DeleteRollupJobResponse(acknowledged);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DeleteRollupJobResponse doParseInstance(XContentParser parser) throws IOException {
|
||||
return DeleteRollupJobResponse.fromXContent(parser);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean supportsUnknownFields() {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
--
|
||||
:api: rollup-delete-job
|
||||
:request: DeleteRollupJobRequest
|
||||
:response: DeleteRollupJobResponse
|
||||
--
|
||||
|
||||
[id="{upid}-{api}"]
|
||||
=== Delete Rollup Job API
|
||||
|
||||
|
||||
[id="{upid}-{api}-request"]
|
||||
==== Request
|
||||
|
||||
The Delete Rollup Job API allows you to delete a job by ID.
|
||||
|
||||
["source","java",subs="attributes,callouts,macros"]
|
||||
--------------------------------------------------
|
||||
include-tagged::{doc-tests-file}[{api}-request]
|
||||
--------------------------------------------------
|
||||
<1> The ID of the job to delete.
|
||||
|
||||
[id="{upid}-{api}-response"]
|
||||
==== Response
|
||||
|
||||
The returned +{response}+ indicates if the delete command was received.
|
||||
|
||||
["source","java",subs="attributes,callouts,macros"]
|
||||
--------------------------------------------------
|
||||
include-tagged::{doc-tests-file}[{api}-response]
|
||||
--------------------------------------------------
|
||||
<1> Whether or not the delete job request was received.
|
||||
|
||||
include::../execution.asciidoc[]
|
||||
|
||||
|
|
@ -289,12 +289,17 @@ include::migration/get-assistance.asciidoc[]
|
|||
|
||||
== Rollup APIs
|
||||
|
||||
:upid: {mainid}-rollup
|
||||
:doc-tests-file: {doc-tests}/RollupDocumentationIT.java
|
||||
|
||||
The Java High Level REST Client supports the following Rollup APIs:
|
||||
|
||||
* <<java-rest-high-x-pack-rollup-put-job>>
|
||||
* <<{upid}-rollup-delete-job>>
|
||||
* <<java-rest-high-x-pack-rollup-get-job>>
|
||||
|
||||
include::rollup/put_job.asciidoc[]
|
||||
include::rollup/delete_job.asciidoc[]
|
||||
include::rollup/get_job.asciidoc[]
|
||||
|
||||
== Security APIs
|
||||
|
|
Loading…
Reference in New Issue