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:
Paul Sanwald 2018-10-16 09:02:29 -04:00 committed by GitHub
parent d43a1fac33
commit 936faba6c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 501 additions and 57 deletions

View File

@ -20,6 +20,8 @@
package org.elasticsearch.client; package org.elasticsearch.client;
import org.elasticsearch.action.ActionListener; 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.GetRollupJobRequest;
import org.elasticsearch.client.rollup.GetRollupJobResponse; import org.elasticsearch.client.rollup.GetRollupJobResponse;
import org.elasticsearch.client.rollup.PutRollupJobRequest; import org.elasticsearch.client.rollup.PutRollupJobRequest;
@ -76,6 +78,40 @@ public class RollupClient {
listener, Collections.emptySet()); 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. * Get a rollup job from the cluster.
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/rollup-put-job.html"> * See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/rollup-put-job.html">

View File

@ -18,8 +18,10 @@
*/ */
package org.elasticsearch.client; package org.elasticsearch.client;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPut; import org.apache.http.client.methods.HttpPut;
import org.elasticsearch.client.rollup.DeleteRollupJobRequest;
import org.elasticsearch.client.rollup.GetRollupJobRequest; import org.elasticsearch.client.rollup.GetRollupJobRequest;
import org.elasticsearch.client.rollup.PutRollupJobRequest; import org.elasticsearch.client.rollup.PutRollupJobRequest;
@ -54,4 +56,16 @@ final class RollupRequestConverters {
.build(); .build();
return new Request(HttpGet.METHOD_NAME, endpoint); 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;
}
} }

View File

@ -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;
}
}

View File

@ -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);
}
}

View File

@ -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"));
}
}

View File

@ -20,52 +20,21 @@ package org.elasticsearch.client.rollup;
import org.elasticsearch.common.ParseField; import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.xcontent.ConstructingObjectParser; 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 org.elasticsearch.common.xcontent.XContentParser;
import java.io.IOException; import java.io.IOException;
import java.util.Objects;
import static org.elasticsearch.common.xcontent.ConstructingObjectParser.constructorArg; 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) { public PutRollupJobResponse(boolean acknowledged) {
this.acknowledged = acknowledged; super(acknowledged);
} }
public boolean isAcknowledged() { public static PutRollupJobResponse fromXContent(final XContentParser parser) throws IOException {
return acknowledged; return PARSER.parse(parser, null);
}
@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;
} }
private static final ConstructingObjectParser<PutRollupJobResponse, Void> PARSER private static final ConstructingObjectParser<PutRollupJobResponse, Void> PARSER
@ -73,8 +42,4 @@ public class PutRollupJobResponse implements ToXContentObject {
static { static {
PARSER.declareBoolean(constructorArg(), new ParseField("acknowledged")); PARSER.declareBoolean(constructorArg(), new ParseField("acknowledged"));
} }
public static PutRollupJobResponse fromXContent(final XContentParser parser) throws IOException {
return PARSER.parse(parser, null);
}
} }

View File

@ -18,6 +18,7 @@
*/ */
package org.elasticsearch.client; package org.elasticsearch.client;
import org.elasticsearch.ElasticsearchStatusException;
import org.elasticsearch.action.admin.indices.refresh.RefreshRequest; import org.elasticsearch.action.admin.indices.refresh.RefreshRequest;
import org.elasticsearch.action.admin.indices.refresh.RefreshResponse; import org.elasticsearch.action.admin.indices.refresh.RefreshResponse;
import org.elasticsearch.action.bulk.BulkItemResponse; 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;
import org.elasticsearch.client.rollup.GetRollupJobResponse.IndexerState; import org.elasticsearch.client.rollup.GetRollupJobResponse.IndexerState;
import org.elasticsearch.client.rollup.GetRollupJobResponse.JobWrapper; 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.PutRollupJobRequest;
import org.elasticsearch.client.rollup.PutRollupJobResponse; import org.elasticsearch.client.rollup.PutRollupJobResponse;
import org.elasticsearch.client.rollup.job.config.DateHistogramGroupConfig; 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.MinAggregationBuilder;
import org.elasticsearch.search.aggregations.metrics.SumAggregationBuilder; import org.elasticsearch.search.aggregations.metrics.SumAggregationBuilder;
import org.elasticsearch.search.aggregations.metrics.ValueCountAggregationBuilder; import org.elasticsearch.search.aggregations.metrics.ValueCountAggregationBuilder;
import org.junit.Before;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; 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.hasKey;
import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.lessThan; import static org.hamcrest.Matchers.lessThan;
public class RollupIT extends ESRestHighLevelClientTestCase { 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; double sum = 0.0d;
int max = Integer.MIN_VALUE; int max = Integer.MIN_VALUE;
int min = Integer.MAX_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(); final BulkRequest bulkRequest = new BulkRequest();
bulkRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE); bulkRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
for (int minute = 0; minute < 60; minute++) { 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); RefreshResponse refreshResponse = highLevelClient().indices().refresh(new RefreshRequest("docs"), RequestOptions.DEFAULT);
assertEquals(0, refreshResponse.getFailedShards()); assertEquals(0, refreshResponse.getFailedShards());
return numDocs;
}
final String id = randomAlphaOfLength(10);
final String indexPattern = randomFrom("docs", "d*", "doc*"); public void testDeleteRollupJob() throws Exception {
final String rollupIndex = randomFrom("rollup", "test"); final GroupConfig groups = new GroupConfig(new DateHistogramGroupConfig("date", DateHistogramInterval.DAY));
final String cron = "*/1 * * * * ?"; final List<MetricConfig> metrics = Collections.singletonList(new MetricConfig("value", SUPPORTED_METRICS));
final int pageSize = randomIntBetween(numDocs, numDocs * 10); 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? // TODO expand this to also test with histogram and terms?
final GroupConfig groups = new GroupConfig(new DateHistogramGroupConfig("date", DateHistogramInterval.DAY)); final GroupConfig groups = new GroupConfig(new DateHistogramGroupConfig("date", DateHistogramInterval.DAY));
final List<MetricConfig> metrics = Collections.singletonList(new MetricConfig("value", SUPPORTED_METRICS)); 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")); Response startResponse = client().performRequest(new Request("POST", "/_xpack/rollup/job/" + id + "/_start"));
assertEquals(RestStatus.OK.getStatus(), startResponse.getHttpResponse().getStatusLine().getStatusCode()); assertEquals(RestStatus.OK.getStatus(), startResponse.getHttpResponse().getStatusLine().getStatusCode());
int finalMin = min;
int finalMax = max;
double finalSum = sum;
assertBusy(() -> { assertBusy(() -> {
SearchResponse searchResponse = highLevelClient().search(new SearchRequest(rollupIndex), RequestOptions.DEFAULT); SearchResponse searchResponse = highLevelClient().search(new SearchRequest(rollupIndex), RequestOptions.DEFAULT);
assertEquals(0, searchResponse.getFailedShards()); assertEquals(0, searchResponse.getFailedShards());
@ -154,13 +192,13 @@ public class RollupIT extends ESRestHighLevelClientTestCase {
for (String name : metric.getMetrics()) { for (String name : metric.getMetrics()) {
Number value = (Number) source.get(metric.getField() + "." + name + ".value"); Number value = (Number) source.get(metric.getField() + "." + name + ".value");
if ("min".equals(name)) { if ("min".equals(name)) {
assertEquals(finalMin, value.intValue()); assertEquals(min, value.intValue());
} else if ("max".equals(name)) { } else if ("max".equals(name)) {
assertEquals(finalMax, value.intValue()); assertEquals(max, value.intValue());
} else if ("sum".equals(name)) { } else if ("sum".equals(name)) {
assertEquals(finalSum, value.doubleValue(), 0.0d); assertEquals(sum, value.doubleValue(), 0.0d);
} else if ("avg".equals(name)) { } 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"); Number avgCount = (Number) source.get(metric.getField() + "." + name + "._count");
assertEquals(numDocs, avgCount.intValue()); assertEquals(numDocs, avgCount.intValue());
} else if ("value_count".equals(name)) { } else if ("value_count".equals(name)) {
@ -191,4 +229,5 @@ public class RollupIT extends ESRestHighLevelClientTestCase {
GetRollupJobResponse getResponse = execute(getRollupJobRequest, rollupClient::getRollupJob, rollupClient::getRollupJobAsync); GetRollupJobResponse getResponse = execute(getRollupJobRequest, rollupClient::getRollupJob, rollupClient::getRollupJobAsync);
assertThat(getResponse.getJobs(), empty()); assertThat(getResponse.getJobs(), empty());
} }
} }

View File

@ -36,6 +36,8 @@ import org.elasticsearch.client.rollup.GetRollupJobResponse;
import org.elasticsearch.client.rollup.GetRollupJobResponse.JobWrapper; import org.elasticsearch.client.rollup.GetRollupJobResponse.JobWrapper;
import org.elasticsearch.client.rollup.GetRollupJobResponse.RollupIndexerJobStats; import org.elasticsearch.client.rollup.GetRollupJobResponse.RollupIndexerJobStats;
import org.elasticsearch.client.rollup.GetRollupJobResponse.RollupJobStatus; 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.PutRollupJobRequest;
import org.elasticsearch.client.rollup.PutRollupJobResponse; import org.elasticsearch.client.rollup.PutRollupJobResponse;
import org.elasticsearch.client.rollup.job.config.DateHistogramGroupConfig; 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));
}
} }

View File

@ -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());
}
}

View File

@ -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;
}
}

View File

@ -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[]

View File

@ -289,12 +289,17 @@ include::migration/get-assistance.asciidoc[]
== Rollup APIs == Rollup APIs
:upid: {mainid}-rollup
:doc-tests-file: {doc-tests}/RollupDocumentationIT.java
The Java High Level REST Client supports the following Rollup APIs: The Java High Level REST Client supports the following Rollup APIs:
* <<java-rest-high-x-pack-rollup-put-job>> * <<java-rest-high-x-pack-rollup-put-job>>
* <<{upid}-rollup-delete-job>>
* <<java-rest-high-x-pack-rollup-get-job>> * <<java-rest-high-x-pack-rollup-get-job>>
include::rollup/put_job.asciidoc[] include::rollup/put_job.asciidoc[]
include::rollup/delete_job.asciidoc[]
include::rollup/get_job.asciidoc[] include::rollup/get_job.asciidoc[]
== Security APIs == Security APIs