From 936faba6c4319ad5972ae974681b5882e3cc8448 Mon Sep 17 00:00:00 2001 From: Paul Sanwald Date: Tue, 16 Oct 2018 09:02:29 -0400 Subject: [PATCH] Add delete rollup job support to HL REST Client (#34066) Add support for delete rollup job to HL REST Client. --- .../elasticsearch/client/RollupClient.java | 36 +++++++++ .../client/RollupRequestConverters.java | 14 ++++ .../client/rollup/AcknowledgedResponse.java | 67 ++++++++++++++++ .../client/rollup/DeleteRollupJobRequest.java | 79 +++++++++++++++++++ .../rollup/DeleteRollupJobResponse.java | 46 +++++++++++ .../client/rollup/PutRollupJobResponse.java | 45 ++--------- .../org/elasticsearch/client/RollupIT.java | 73 +++++++++++++---- .../documentation/RollupDocumentationIT.java | 51 ++++++++++++ .../rollup/DeleteRollupJobRequestTests.java | 56 +++++++++++++ .../rollup/DeleteRollupJobResponseTests.java | 51 ++++++++++++ .../high-level/rollup/delete_job.asciidoc | 35 ++++++++ .../high-level/supported-apis.asciidoc | 5 ++ 12 files changed, 501 insertions(+), 57 deletions(-) create mode 100644 client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/AcknowledgedResponse.java create mode 100644 client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/DeleteRollupJobRequest.java create mode 100644 client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/DeleteRollupJobResponse.java create mode 100644 client/rest-high-level/src/test/java/org/elasticsearch/client/rollup/DeleteRollupJobRequestTests.java create mode 100644 client/rest-high-level/src/test/java/org/elasticsearch/client/rollup/DeleteRollupJobResponseTests.java create mode 100644 docs/java-rest/high-level/rollup/delete_job.asciidoc diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/RollupClient.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/RollupClient.java index 3059eb46065..148dbee223e 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/RollupClient.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/RollupClient.java @@ -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 + * 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 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 + * The docs 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 listener) { + restHighLevelClient.performRequestAsyncAndParseEntity(request, + RollupRequestConverters::deleteJob, + options, + DeleteRollupJobResponse::fromXContent, + listener, Collections.emptySet()); + } + /** * Get a rollup job from the cluster. * See diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/RollupRequestConverters.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/RollupRequestConverters.java index 261467fa268..2c2025837cd 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/RollupRequestConverters.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/RollupRequestConverters.java @@ -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; + } } diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/AcknowledgedResponse.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/AcknowledgedResponse.java new file mode 100644 index 00000000000..29cd1787c70 --- /dev/null +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/AcknowledgedResponse.java @@ -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; + } + +} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/DeleteRollupJobRequest.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/DeleteRollupJobRequest.java new file mode 100644 index 00000000000..9b7a322b238 --- /dev/null +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/DeleteRollupJobRequest.java @@ -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 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); + } +} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/DeleteRollupJobResponse.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/DeleteRollupJobResponse.java new file mode 100644 index 00000000000..f9d3025d38a --- /dev/null +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/DeleteRollupJobResponse.java @@ -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 PARSER + = new ConstructingObjectParser<>("delete_rollup_job_response", true, + args -> new DeleteRollupJobResponse((boolean) args[0])); + static { + PARSER.declareBoolean(constructorArg(), new ParseField("acknowledged")); + } +} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/PutRollupJobResponse.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/PutRollupJobResponse.java index 0c55bd419cb..d991313bb5e 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/PutRollupJobResponse.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/PutRollupJobResponse.java @@ -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 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); - } } diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/RollupIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/RollupIT.java index 9898dc971f9..b7f85aa3acf 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/RollupIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/RollupIT.java @@ -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 { + double sum = 0.0d; + int max = Integer.MIN_VALUE; + int min = Integer.MAX_VALUE; private static final List 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 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 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 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()); } + } diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/RollupDocumentationIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/RollupDocumentationIT.java index 46b89d86824..06308fc2117 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/RollupDocumentationIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/RollupDocumentationIT.java @@ -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 listener = new ActionListener() { + @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)); + + } + } diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/rollup/DeleteRollupJobRequestTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/rollup/DeleteRollupJobRequestTests.java new file mode 100644 index 00000000000..c1271207d41 --- /dev/null +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/rollup/DeleteRollupJobRequestTests.java @@ -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 { + + 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()); + } + +} diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/rollup/DeleteRollupJobResponseTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/rollup/DeleteRollupJobResponseTests.java new file mode 100644 index 00000000000..1dc02ff386d --- /dev/null +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/rollup/DeleteRollupJobResponseTests.java @@ -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 { + + 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; + } + +} diff --git a/docs/java-rest/high-level/rollup/delete_job.asciidoc b/docs/java-rest/high-level/rollup/delete_job.asciidoc new file mode 100644 index 00000000000..c98a6fb7326 --- /dev/null +++ b/docs/java-rest/high-level/rollup/delete_job.asciidoc @@ -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[] + + diff --git a/docs/java-rest/high-level/supported-apis.asciidoc b/docs/java-rest/high-level/supported-apis.asciidoc index 850a9049fb6..7ee39ac861c 100644 --- a/docs/java-rest/high-level/supported-apis.asciidoc +++ b/docs/java-rest/high-level/supported-apis.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: * <> +* <<{upid}-rollup-delete-job>> * <> include::rollup/put_job.asciidoc[] +include::rollup/delete_job.asciidoc[] include::rollup/get_job.asciidoc[] == Security APIs