From 86a9e1f5377daf85cd187278777c4f4e89e1bba8 Mon Sep 17 00:00:00 2001 From: Paul Sanwald Date: Tue, 25 Sep 2018 18:30:46 -0400 Subject: [PATCH 01/12] Add support for delete rollup job to HL REST Client. --- .../client/RestHighLevelClient.java | 1 + .../elasticsearch/client/RollupClient.java | 18 +++++ .../client/RollupRequestConverters.java | 13 ++++ .../client/rollup/AcknowledgedResponse.java | 67 +++++++++++++++++++ .../client/rollup/DeleteRollupJobRequest.java | 61 +++++++++++++++++ .../rollup/DeleteRollupJobResponse.java | 46 +++++++++++++ .../client/rollup/PutRollupJobResponse.java | 45 ++----------- .../documentation/RollupDocumentationIT.java | 36 ++++++++++ .../rollup/DeleteRollupJobRequestTests.java | 38 +++++++++++ .../rollup/DeleteRollupJobResponseTests.java | 33 +++++++++ .../high-level/rollup/delete_job.asciidoc | 57 ++++++++++++++++ .../high-level/supported-apis.asciidoc | 1 + 12 files changed, 376 insertions(+), 40 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/RestHighLevelClient.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/RestHighLevelClient.java index 176436ce458a7..9350139725ae9 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/RestHighLevelClient.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/RestHighLevelClient.java @@ -1482,4 +1482,5 @@ static List getProvidedNamedXContents() { } return entries; } + } 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 1a766cb4923b4..2cc18c352b498 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.PutRollupJobRequest; import org.elasticsearch.client.rollup.PutRollupJobResponse; @@ -73,4 +75,20 @@ public void putRollupJobAsync(PutRollupJobRequest request, RequestOptions option PutRollupJobResponse::fromXContent, listener, 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()); + } } 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 f1c4f77ae4c9a..ba7bc62c2b339 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 @@ -19,6 +19,7 @@ package org.elasticsearch.client; import org.apache.http.client.methods.HttpPut; +import org.elasticsearch.client.rollup.DeleteRollupJobRequest; import org.elasticsearch.client.rollup.PutRollupJobRequest; import java.io.IOException; @@ -42,4 +43,16 @@ static Request putJob(final PutRollupJobRequest putRollupJobRequest) throws IOEx request.setEntity(createEntity(putRollupJobRequest, REQUEST_BODY_CONTENT_TYPE)); return request; } + + 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(HttpPut.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 0000000000000..29cd1787c704a --- /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 0000000000000..87f18abece2ca --- /dev/null +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/DeleteRollupJobRequest.java @@ -0,0 +1,61 @@ +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 final String id; + + private static final ParseField ID_FIELD = new ParseField("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 0000000000000..f9d3025d38a4f --- /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 0c55bd419cbd0..d991313bb5e62 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 @@ 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 XContentBuilder toXContent(XContentBuilder builder, Params params) throws 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/documentation/RollupDocumentationIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/RollupDocumentationIT.java index aadb0f0f2005d..078ce318c58b4 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 @@ -29,6 +29,8 @@ import org.elasticsearch.client.ESRestHighLevelClientTestCase; import org.elasticsearch.client.RequestOptions; import org.elasticsearch.client.RestHighLevelClient; +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; @@ -160,4 +162,38 @@ public void onFailure(Exception e) { assertTrue(latch.await(30L, TimeUnit.SECONDS)); } } + + public void testDeleteRollupJob() throws Exception { + RestHighLevelClient client = highLevelClient(); + + String id = "job_2"; + // tag::x-pack-rollup-delete-rollup-job-request + DeleteRollupJobRequest request = new DeleteRollupJobRequest(id); + // end::x-pack-rollup-delete-rollup-job-request + + // tag::x-pack-rollup-delete-rollup-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::x-pack-rollup-delete-rollup-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::x-pack-rollup-delete-rollup-job-execute-async + client.rollup().deleteRollupJobAsync(request, RequestOptions.DEFAULT, listener); // <1> + // end::x-pack-rollup-delete-rollup-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 0000000000000..af839ee04ca3b --- /dev/null +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/rollup/DeleteRollupJobRequestTests.java @@ -0,0 +1,38 @@ +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 0000000000000..870681d75862f --- /dev/null +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/rollup/DeleteRollupJobResponseTests.java @@ -0,0 +1,33 @@ +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 0000000000000..3deef75e514bb --- /dev/null +++ b/docs/java-rest/high-level/rollup/delete_job.asciidoc @@ -0,0 +1,57 @@ +[[java-rest-high-x-pack-rollup-delete-job]] +=== Delete Rollup Job API + +The Delete Rollup Job API can be used to create a new Rollup job +in the cluster. The API accepts a `PutRollupJobRequest` object +as a request and returns a `PutRollupJobResponse`. + +[[java-rest-high-x-pack-rollup-delete-rollup-job-request]] +==== Delete Rollup Job Request + +A `DeleteRollupJobRequest` requires the following argument: + +["source","java",subs="attributes,callouts,macros"] +-------------------------------------------------- +include-tagged::{doc-tests}/RollupDocumentationIT.java[x-pack-rollup-delete-rollup-job-request] +-------------------------------------------------- + + +[[java-rest-high-x-pack-rollup-delete-rollup-job-execution]] +==== Asynchronous Execution + +This request can be executed asynchronously: + +["source","java",subs="attributes,callouts,macros"] +-------------------------------------------------- +include-tagged::{doc-tests}/RollupDocumentationIT.java[x-pack-rollup-delete-rollup-job-execute-async] +-------------------------------------------------- +<1> The `DeleteRollupJobRequest` to execute and the `ActionListener` to use when +the execution completes + +The asynchronous method does not block and returns immediately. Once it is +completed the `ActionListener` is called back using the `onResponse` method +if the execution successfully completed or using the `onFailure` method if +it failed. + +A typical listener for `DeleteRollupJobResponse` looks like: + +["source","java",subs="attributes,callouts,macros"] +-------------------------------------------------- +include-tagged::{doc-tests}/RollupDocumentationIT.java[x-pack-rollup-delete-rollup-job-execute-listener] +-------------------------------------------------- +<1> Called when the execution is successfully completed. The response is +provided as an argument +<2> Called in case of failure. The raised exception is provided as an argument + +[[java-rest-high-x-pack-rollup-delete-rollup-job-response]] +==== Response + +The returned `DeleteRollupJobResponse` indicates if the new Rollup job +has been successfully created: + +["source","java",subs="attributes,callouts,macros"] +-------------------------------------------------- +include-tagged::{doc-tests}/RollupDocumentationIT.java[x-pack-rollup-delete-rollup-job-execute-listener] +-------------------------------------------------- +<1> `acknowledged` is a boolean indicating whether the delete command was received + diff --git a/docs/java-rest/high-level/supported-apis.asciidoc b/docs/java-rest/high-level/supported-apis.asciidoc index 90f44852c4349..1aaff611d2ff0 100644 --- a/docs/java-rest/high-level/supported-apis.asciidoc +++ b/docs/java-rest/high-level/supported-apis.asciidoc @@ -279,6 +279,7 @@ The Java High Level REST Client supports the following Rollup APIs: * <> include::rollup/put_job.asciidoc[] +include::rollup/delete_job.asciidoc[] == Security APIs From f430758f0eeff43d426e34eb828c91796d6c752b Mon Sep 17 00:00:00 2001 From: Paul Sanwald Date: Tue, 25 Sep 2018 18:33:14 -0400 Subject: [PATCH 02/12] remove accidentally adding newline --- .../main/java/org/elasticsearch/client/RestHighLevelClient.java | 1 - 1 file changed, 1 deletion(-) diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/RestHighLevelClient.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/RestHighLevelClient.java index 9350139725ae9..176436ce458a7 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/RestHighLevelClient.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/RestHighLevelClient.java @@ -1482,5 +1482,4 @@ static List getProvidedNamedXContents() { } return entries; } - } From 4649915954ba0493501bb8ed04cdc40fc61ae8b7 Mon Sep 17 00:00:00 2001 From: Paul Sanwald Date: Tue, 25 Sep 2018 18:38:12 -0400 Subject: [PATCH 03/12] add correct headers to new files --- .../client/rollup/DeleteRollupJobRequest.java | 18 ++++++++++++++++++ .../rollup/DeleteRollupJobRequestTests.java | 18 ++++++++++++++++++ .../rollup/DeleteRollupJobResponseTests.java | 18 ++++++++++++++++++ 3 files changed, 54 insertions(+) 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 index 87f18abece2ca..4f876966a0078 100644 --- 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 @@ -1,3 +1,21 @@ +/* + * 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; 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 index af839ee04ca3b..c1271207d41bc 100644 --- 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 @@ -1,3 +1,21 @@ +/* + * 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; 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 index 870681d75862f..1dc02ff386de0 100644 --- 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 @@ -1,3 +1,21 @@ +/* + * 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; From c3cf6fe81432b487d1943f09608e9cad0e5cad31 Mon Sep 17 00:00:00 2001 From: Paul Sanwald Date: Wed, 26 Sep 2018 12:05:15 -0400 Subject: [PATCH 04/12] fix checkstyle --- .../src/main/java/org/elasticsearch/client/RollupClient.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 2cc18c352b498..aea5724e0b38a 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 @@ -84,7 +84,9 @@ public void putRollupJobAsync(PutRollupJobRequest request, RequestOptions option * @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) { + public void deleteRollupJobAsync(DeleteRollupJobRequest request, + RequestOptions options, + ActionListener listener) { restHighLevelClient.performRequestAsyncAndParseEntity(request, RollupRequestConverters::deleteJob, options, From db61b82f0673bd47573d90fcc825fb5506dceeb6 Mon Sep 17 00:00:00 2001 From: Paul Sanwald Date: Thu, 27 Sep 2018 11:05:05 -0400 Subject: [PATCH 05/12] fix a bug to use correct http verb. add synchronous method --- .../elasticsearch/client/RollupClient.java | 16 ++++++++++++ .../client/RollupRequestConverters.java | 3 ++- .../documentation/RollupDocumentationIT.java | 25 ++++++++++++++++++- .../high-level/rollup/delete_job.asciidoc | 13 +++++++++- 4 files changed, 54 insertions(+), 3 deletions(-) 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 aea5724e0b38a..b48cf435c5622 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 @@ -76,6 +76,22 @@ public void putRollupJobAsync(PutRollupJobRequest request, RequestOptions option 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 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 ba7bc62c2b339..af2571b79d133 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,6 +18,7 @@ */ package org.elasticsearch.client; +import org.apache.http.client.methods.HttpDelete; import org.apache.http.client.methods.HttpPut; import org.elasticsearch.client.rollup.DeleteRollupJobRequest; import org.elasticsearch.client.rollup.PutRollupJobRequest; @@ -51,7 +52,7 @@ static Request deleteJob(final DeleteRollupJobRequest deleteRollupJobRequest) th .addPathPartAsIs("job") .addPathPart(deleteRollupJobRequest.getId()) .build(); - Request request = new Request(HttpPut.METHOD_NAME, endpoint); + 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/test/java/org/elasticsearch/client/documentation/RollupDocumentationIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/RollupDocumentationIT.java index 078ce318c58b4..66a246831402f 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 @@ -163,7 +163,7 @@ public void onFailure(Exception e) { } } - public void testDeleteRollupJob() throws Exception { + public void testDeleteRollupJobAsync() throws Exception { RestHighLevelClient client = highLevelClient(); String id = "job_2"; @@ -189,6 +189,10 @@ public void onFailure(Exception e) { final CountDownLatch latch = new CountDownLatch(1); listener = new LatchedActionListener<>(listener, latch); + // tag::x-pack-rollup-delete-rollup-job-execute + //client.rollup().deleteRollupJob(request, RequestOptions.DEFAULT); // <1> + // end::x-pack-rollup-delete-rollup-job-execute + // tag::x-pack-rollup-delete-rollup-job-execute-async client.rollup().deleteRollupJobAsync(request, RequestOptions.DEFAULT, listener); // <1> // end::x-pack-rollup-delete-rollup-job-execute-async @@ -196,4 +200,23 @@ public void onFailure(Exception e) { assertTrue(latch.await(30L, TimeUnit.SECONDS)); } + + public void testDeleteRollupJob() throws Exception { + RestHighLevelClient client = highLevelClient(); + + String id = "job_2"; + // tag::x-pack-rollup-delete-rollup-job-request + DeleteRollupJobRequest request = new DeleteRollupJobRequest(id); + // end::x-pack-rollup-delete-rollup-job-request + + try { + // tag::x-pack-rollup-delete-rollup-job-execute + client.rollup().deleteRollupJob(request, RequestOptions.DEFAULT); // <1> + // end::x-pack-rollup-delete-rollup-job-execute + } catch (Exception e) { + // Swallow any exception, this test does not test actually cancelling. + } + + + } } diff --git a/docs/java-rest/high-level/rollup/delete_job.asciidoc b/docs/java-rest/high-level/rollup/delete_job.asciidoc index 3deef75e514bb..7f7e49b3e5f69 100644 --- a/docs/java-rest/high-level/rollup/delete_job.asciidoc +++ b/docs/java-rest/high-level/rollup/delete_job.asciidoc @@ -15,8 +15,19 @@ A `DeleteRollupJobRequest` requires the following argument: include-tagged::{doc-tests}/RollupDocumentationIT.java[x-pack-rollup-delete-rollup-job-request] -------------------------------------------------- - [[java-rest-high-x-pack-rollup-delete-rollup-job-execution]] +==== Execution + +The Delete Rollup Job API can be executed through a `RollupClient` +instance. Such instance can be retrieved from a `RestHighLevelClient` +using the `rollup()` method: + +["source","java",subs="attributes,callouts,macros"] +-------------------------------------------------- +include-tagged::{doc-tests}/RollupDocumentationIT.java[x-pack-rollup-delete-rollup-job-execute] +-------------------------------------------------- + +[[java-rest-high-x-pack-rollup-delete-rollup-job-execution-async]] ==== Asynchronous Execution This request can be executed asynchronously: From b46ac1763b2804d700a9fd40011abada1d4d7f78 Mon Sep 17 00:00:00 2001 From: Paul Sanwald Date: Thu, 11 Oct 2018 18:40:47 +0100 Subject: [PATCH 06/12] add test for delete to RollupIT --- .../org/elasticsearch/client/RollupIT.java | 67 ++++++++++++++----- 1 file changed, 49 insertions(+), 18 deletions(-) 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 5d88b3f2e297b..7f86fcb5a7376 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 @@ -27,6 +27,8 @@ import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.support.WriteRequest; +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; @@ -42,6 +44,7 @@ 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; @@ -53,15 +56,30 @@ 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); + 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); + } - @SuppressWarnings("unchecked") - public void testPutRollupJob() throws Exception { - double sum = 0.0d; - int max = Integer.MIN_VALUE; - int min = Integer.MAX_VALUE; - + public int indexDocs() throws Exception { final BulkRequest bulkRequest = new BulkRequest(); bulkRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE); for (int minute = 0; minute < 60; minute++) { @@ -101,12 +119,27 @@ public void testPutRollupJob() throws Exception { 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()); + } + + + + @SuppressWarnings("unchecked") + public void testPutRollupJob() 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)); @@ -123,9 +156,6 @@ public void testPutRollupJob() throws Exception { 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()); @@ -143,13 +173,13 @@ public void testPutRollupJob() throws Exception { 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)) { @@ -159,4 +189,5 @@ public void testPutRollupJob() throws Exception { } }); } + } From 14eb004a622beab7bace3b6ad75e7f03cdeaa9b6 Mon Sep 17 00:00:00 2001 From: Paul Sanwald Date: Fri, 12 Oct 2018 08:41:37 +0100 Subject: [PATCH 07/12] address stylistic code review comments --- .../src/main/java/org/elasticsearch/client/RollupClient.java | 2 +- .../elasticsearch/client/rollup/DeleteRollupJobRequest.java | 4 ++-- .../client/documentation/RollupDocumentationIT.java | 2 -- docs/java-rest/high-level/rollup/delete_job.asciidoc | 5 ++--- 4 files changed, 5 insertions(+), 8 deletions(-) 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 07c9616c65dee..148dbee223e07 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 @@ -79,7 +79,7 @@ public void putRollupJobAsync(PutRollupJobRequest request, RequestOptions option } /** - * delete a rollup job from the cluster + * Delete a rollup job from the cluster * See * the docs for more. * @param request the request 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 index 4f876966a0078..9b7a322b23827 100644 --- 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 @@ -31,12 +31,12 @@ public class DeleteRollupJobRequest implements Validatable, ToXContentObject { + private static final ParseField ID_FIELD = new ParseField("id"); private final String id; - private static final ParseField ID_FIELD = new ParseField("id"); public DeleteRollupJobRequest(String id) { - this.id = Objects.requireNonNull(id,"id parameter must not be null"); + this.id = Objects.requireNonNull(id, "id parameter must not be null"); } public String getId() { 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 fd21e9e0ac4ae..092d58da6b81b 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 @@ -328,7 +328,6 @@ public void testDeleteRollupJob() throws Exception { // tag::x-pack-rollup-delete-rollup-job-request DeleteRollupJobRequest request = new DeleteRollupJobRequest(id); // end::x-pack-rollup-delete-rollup-job-request - try { // tag::x-pack-rollup-delete-rollup-job-execute client.rollup().deleteRollupJob(request, RequestOptions.DEFAULT); // <1> @@ -337,6 +336,5 @@ public void testDeleteRollupJob() throws Exception { // Swallow any exception, this test does not test actually cancelling. } - } } diff --git a/docs/java-rest/high-level/rollup/delete_job.asciidoc b/docs/java-rest/high-level/rollup/delete_job.asciidoc index 7f7e49b3e5f69..ab7d357687894 100644 --- a/docs/java-rest/high-level/rollup/delete_job.asciidoc +++ b/docs/java-rest/high-level/rollup/delete_job.asciidoc @@ -1,7 +1,7 @@ [[java-rest-high-x-pack-rollup-delete-job]] === Delete Rollup Job API -The Delete Rollup Job API can be used to create a new Rollup job +The Delete Rollup Job API can be used to delete an existing Rollup job in the cluster. The API accepts a `PutRollupJobRequest` object as a request and returns a `PutRollupJobResponse`. @@ -57,8 +57,7 @@ provided as an argument [[java-rest-high-x-pack-rollup-delete-rollup-job-response]] ==== Response -The returned `DeleteRollupJobResponse` indicates if the new Rollup job -has been successfully created: +The returned `DeleteRollupJobResponse` indicates if the delete command was received: ["source","java",subs="attributes,callouts,macros"] -------------------------------------------------- From 5905e1adc3a62ebcec7becc89549b329e4cfded3 Mon Sep 17 00:00:00 2001 From: Paul Sanwald Date: Fri, 12 Oct 2018 11:53:59 +0100 Subject: [PATCH 08/12] add test for deleting a job that doesn't exist. minor docs change --- .../java/org/elasticsearch/client/RollupIT.java | 13 ++++++++++++- .../java-rest/high-level/rollup/delete_job.asciidoc | 4 ++-- 2 files changed, 14 insertions(+), 3 deletions(-) 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 7531f32934fa3..6319b59fe2504 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,8 @@ */ package org.elasticsearch.client; +import org.apache.http.entity.ContentType; +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; @@ -63,6 +65,7 @@ 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 { @@ -143,10 +146,18 @@ public void testDeleteRollupJob() throws Exception { 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); + 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? diff --git a/docs/java-rest/high-level/rollup/delete_job.asciidoc b/docs/java-rest/high-level/rollup/delete_job.asciidoc index ab7d357687894..779ceebe616ff 100644 --- a/docs/java-rest/high-level/rollup/delete_job.asciidoc +++ b/docs/java-rest/high-level/rollup/delete_job.asciidoc @@ -2,8 +2,8 @@ === Delete Rollup Job API The Delete Rollup Job API can be used to delete an existing Rollup job -in the cluster. The API accepts a `PutRollupJobRequest` object -as a request and returns a `PutRollupJobResponse`. +in the cluster. The API accepts a `DeleteRollupJobRequest` object +as a request and returns a `DeleteRollupJobResponse`. [[java-rest-high-x-pack-rollup-delete-rollup-job-request]] ==== Delete Rollup Job Request From b9df762e868469bb8d35a82ecbac6d93102eb43d Mon Sep 17 00:00:00 2001 From: Paul Sanwald Date: Fri, 12 Oct 2018 12:05:42 +0100 Subject: [PATCH 09/12] remove extraneous spaces --- .../client/documentation/RollupDocumentationIT.java | 1 - 1 file changed, 1 deletion(-) 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 092d58da6b81b..85f02b78a7420 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 @@ -335,6 +335,5 @@ public void testDeleteRollupJob() throws Exception { } catch (Exception e) { // Swallow any exception, this test does not test actually cancelling. } - } } From 660e56b89beb602a8a051d9c2bad8ae955b8a610 Mon Sep 17 00:00:00 2001 From: Paul Sanwald Date: Fri, 12 Oct 2018 11:27:41 -0400 Subject: [PATCH 10/12] fix checkstyle --- .../src/test/java/org/elasticsearch/client/RollupIT.java | 1 - 1 file changed, 1 deletion(-) 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 6319b59fe2504..b7f85aa3acf10 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,7 +18,6 @@ */ package org.elasticsearch.client; -import org.apache.http.entity.ContentType; import org.elasticsearch.ElasticsearchStatusException; import org.elasticsearch.action.admin.indices.refresh.RefreshRequest; import org.elasticsearch.action.admin.indices.refresh.RefreshResponse; From eb996859ba9e2cbafd91cc20b55fadf2f86669b5 Mon Sep 17 00:00:00 2001 From: Paul Sanwald Date: Sat, 13 Oct 2018 04:28:36 -0400 Subject: [PATCH 11/12] use new execution include and api callouts for docs --- .../documentation/RollupDocumentationIT.java | 49 +++++++-------- .../high-level/rollup/delete_job.asciidoc | 60 ++++++------------- .../high-level/supported-apis.asciidoc | 4 ++ 3 files changed, 43 insertions(+), 70 deletions(-) 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 85f02b78a7420..88d12653b8dba 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 @@ -283,15 +283,29 @@ private void waitForPendingRollupTasks() throws Exception { }); } - public void testDeleteRollupJobAsync() throws Exception { + public void testDeleteRollupJob() throws Exception { RestHighLevelClient client = highLevelClient(); String id = "job_2"; - // tag::x-pack-rollup-delete-rollup-job-request - DeleteRollupJobRequest request = new DeleteRollupJobRequest(id); - // end::x-pack-rollup-delete-rollup-job-request - // tag::x-pack-rollup-delete-rollup-job-execute-listener + // 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); // <1> + // 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) { @@ -303,37 +317,18 @@ public void onFailure(Exception e) { // <2> } }; - // end::x-pack-rollup-delete-rollup-job-execute-listener + // 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::x-pack-rollup-delete-rollup-job-execute - //client.rollup().deleteRollupJob(request, RequestOptions.DEFAULT); // <1> - // end::x-pack-rollup-delete-rollup-job-execute - - // tag::x-pack-rollup-delete-rollup-job-execute-async + // tag::rollup-delete-job-execute-async client.rollup().deleteRollupJobAsync(request, RequestOptions.DEFAULT, listener); // <1> - // end::x-pack-rollup-delete-rollup-job-execute-async + // end::rollup-delete-job-execute-async assertTrue(latch.await(30L, TimeUnit.SECONDS)); } - public void testDeleteRollupJob() throws Exception { - RestHighLevelClient client = highLevelClient(); - - String id = "job_2"; - // tag::x-pack-rollup-delete-rollup-job-request - DeleteRollupJobRequest request = new DeleteRollupJobRequest(id); - // end::x-pack-rollup-delete-rollup-job-request - try { - // tag::x-pack-rollup-delete-rollup-job-execute - client.rollup().deleteRollupJob(request, RequestOptions.DEFAULT); // <1> - // end::x-pack-rollup-delete-rollup-job-execute - } catch (Exception e) { - // Swallow any exception, this test does not test actually cancelling. - } - } } diff --git a/docs/java-rest/high-level/rollup/delete_job.asciidoc b/docs/java-rest/high-level/rollup/delete_job.asciidoc index 779ceebe616ff..ebed53781119d 100644 --- a/docs/java-rest/high-level/rollup/delete_job.asciidoc +++ b/docs/java-rest/high-level/rollup/delete_job.asciidoc @@ -1,67 +1,41 @@ -[[java-rest-high-x-pack-rollup-delete-job]] +-- +:api: rollup-delete-job +:request: DeleteRollupJobRequest +:response: DeleteRollupJobResponse +-- + +[id="{upid}-{api}"] === Delete Rollup Job API The Delete Rollup Job API can be used to delete an existing Rollup job in the cluster. The API accepts a `DeleteRollupJobRequest` object as a request and returns a `DeleteRollupJobResponse`. -[[java-rest-high-x-pack-rollup-delete-rollup-job-request]] -==== Delete Rollup Job Request - -A `DeleteRollupJobRequest` requires the following argument: -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/RollupDocumentationIT.java[x-pack-rollup-delete-rollup-job-request] --------------------------------------------------- - -[[java-rest-high-x-pack-rollup-delete-rollup-job-execution]] +[id="{upid}-{api}-execution"] ==== Execution The Delete Rollup Job API can be executed through a `RollupClient` instance. Such instance can be retrieved from a `RestHighLevelClient` -using the `rollup()` method: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/RollupDocumentationIT.java[x-pack-rollup-delete-rollup-job-execute] --------------------------------------------------- - -[[java-rest-high-x-pack-rollup-delete-rollup-job-execution-async]] -==== Asynchronous Execution - -This request can be executed asynchronously: +using the `rollup()` method. ["source","java",subs="attributes,callouts,macros"] -------------------------------------------------- -include-tagged::{doc-tests}/RollupDocumentationIT.java[x-pack-rollup-delete-rollup-job-execute-async] +include-tagged::{doc-tests-file}[{api}-request] -------------------------------------------------- -<1> The `DeleteRollupJobRequest` to execute and the `ActionListener` to use when -the execution completes +<1> The ID of the job to delete. -The asynchronous method does not block and returns immediately. Once it is -completed the `ActionListener` is called back using the `onResponse` method -if the execution successfully completed or using the `onFailure` method if -it failed. +[id="{upid}-{api}-response"] +==== Response -A typical listener for `DeleteRollupJobResponse` looks like: +The returned +{response}+ indicates if the delete command was received. ["source","java",subs="attributes,callouts,macros"] -------------------------------------------------- -include-tagged::{doc-tests}/RollupDocumentationIT.java[x-pack-rollup-delete-rollup-job-execute-listener] +include-tagged::{doc-tests-file}[{api}-response] -------------------------------------------------- -<1> Called when the execution is successfully completed. The response is -provided as an argument -<2> Called in case of failure. The raised exception is provided as an argument +<1> Whether or not the delete job request was received. -[[java-rest-high-x-pack-rollup-delete-rollup-job-response]] -==== Response +include::../execution.asciidoc[] -The returned `DeleteRollupJobResponse` indicates if the delete command was received: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/RollupDocumentationIT.java[x-pack-rollup-delete-rollup-job-execute-listener] --------------------------------------------------- -<1> `acknowledged` is a boolean indicating whether the delete command was received diff --git a/docs/java-rest/high-level/supported-apis.asciidoc b/docs/java-rest/high-level/supported-apis.asciidoc index 0171c89cd7d06..719333feaccf0 100644 --- a/docs/java-rest/high-level/supported-apis.asciidoc +++ b/docs/java-rest/high-level/supported-apis.asciidoc @@ -289,9 +289,13 @@ 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[] From 1cb57e9d76d2a32e8bae939a1aaa0314dba535e7 Mon Sep 17 00:00:00 2001 From: Paul Sanwald Date: Sat, 13 Oct 2018 04:44:48 -0400 Subject: [PATCH 12/12] get callouts aligned correctly --- .../client/documentation/RollupDocumentationIT.java | 2 +- docs/java-rest/high-level/rollup/delete_job.asciidoc | 12 +++--------- 2 files changed, 4 insertions(+), 10 deletions(-) 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 88d12653b8dba..06308fc2117e9 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 @@ -293,7 +293,7 @@ public void testDeleteRollupJob() throws Exception { // end::rollup-delete-job-request try { // tag::rollup-delete-job-execute - DeleteRollupJobResponse response = client.rollup().deleteRollupJob(request, RequestOptions.DEFAULT); // <1> + DeleteRollupJobResponse response = client.rollup().deleteRollupJob(request, RequestOptions.DEFAULT); // end::rollup-delete-job-execute // tag::rollup-delete-job-response diff --git a/docs/java-rest/high-level/rollup/delete_job.asciidoc b/docs/java-rest/high-level/rollup/delete_job.asciidoc index ebed53781119d..c98a6fb732659 100644 --- a/docs/java-rest/high-level/rollup/delete_job.asciidoc +++ b/docs/java-rest/high-level/rollup/delete_job.asciidoc @@ -7,17 +7,11 @@ [id="{upid}-{api}"] === Delete Rollup Job API -The Delete Rollup Job API can be used to delete an existing Rollup job -in the cluster. The API accepts a `DeleteRollupJobRequest` object -as a request and returns a `DeleteRollupJobResponse`. +[id="{upid}-{api}-request"] +==== Request -[id="{upid}-{api}-execution"] -==== Execution - -The Delete Rollup Job API can be executed through a `RollupClient` -instance. Such instance can be retrieved from a `RestHighLevelClient` -using the `rollup()` method. +The Delete Rollup Job API allows you to delete a job by ID. ["source","java",subs="attributes,callouts,macros"] --------------------------------------------------