From 38fca666d151d763fb9270a155956d7190894366 Mon Sep 17 00:00:00 2001 From: Tanguy Leroux Date: Mon, 6 Aug 2018 14:03:40 +0200 Subject: [PATCH 01/13] Add Create Rollup Job API to the high level rest client --- .../client/RequestConverters.java | 13 ++ .../client/RestHighLevelClient.java | 11 ++ .../elasticsearch/client/RollupClient.java | 71 ++++++++ .../client/RestHighLevelClientTests.java | 1 + .../org/elasticsearch/client/RollupIT.java | 158 ++++++++++++++++ .../documentation/RollupDocumentationIT.java | 163 +++++++++++++++++ .../high-level/supported-apis.asciidoc | 9 + .../high-level/x-pack/rollup/put_job.asciidoc | 172 ++++++++++++++++++ .../xpack/core/XPackClientPlugin.java | 8 +- .../rollup/action/DeleteRollupJobAction.java | 2 +- .../rollup/action/GetRollupCapsAction.java | 2 +- .../action/GetRollupIndexCapsAction.java | 2 +- .../rollup/action/GetRollupJobsAction.java | 4 +- .../rollup/action/PutRollupJobAction.java | 128 +------------ .../core/rollup/action/RollupJobCaps.java | 2 +- .../rollup/action/StartRollupJobAction.java | 2 +- .../rollup/action/StopRollupJobAction.java | 2 +- .../xpack/core/rollup/job/RollupJob.java | 1 + .../xpack/core/rollup/ConfigTestHelpers.java | 12 +- ...eHistogramGroupConfigSerializingTests.java | 2 + .../job/GroupConfigSerializingTests.java | 1 + .../HistogramGroupConfigSerializingTests.java | 3 +- .../job/MetricConfigSerializingTests.java | 1 + .../core/rollup/job/RollupJobConfigTests.java | 1 + .../job/TermsGroupConfigSerializingTests.java | 1 + .../elasticsearch/xpack/rollup/Rollup.java | 2 +- .../rollup/RollupJobIdentifierUtils.java | 4 +- .../xpack/rollup/RollupRequestTranslator.java | 4 +- .../rollup/RollupResponseTranslator.java | 2 +- .../xpack/rollup/action/RollupIndexCaps.java | 4 +- .../action/TransportGetRollupCapsAction.java | 2 +- .../action/TransportGetRollupJobAction.java | 4 +- .../action/TransportPutRollupJobAction.java | 30 +-- .../action/TransportRollupSearchAction.java | 4 +- .../xpack/rollup/job/IndexerUtils.java | 6 +- .../xpack/rollup/job/RollupIndexer.java | 8 +- .../xpack/rollup/job/RollupJobTask.java | 4 +- .../rollup/rest/RestPutRollupJobAction.java | 14 +- .../rollup/rest/RestStartRollupJobAction.java | 2 +- .../rollup/rest/RestStopRollupJobAction.java | 2 +- .../rollup/RollupJobIdentifierUtilTests.java | 12 +- .../RollupResponseTranslationTests.java | 126 ++++++------- .../GetRollupCapsActionRequestTests.java | 4 +- .../GetRollupIndexCapsActionRequestTests.java | 2 +- .../action/PutJobStateMachineTests.java | 28 +-- ...sts.java => PutRollupJobRequestTests.java} | 16 +- .../action/PutRollupJobResponseTests.java | 43 +++++ .../rollup/action/RollupIndexCapsTests.java | 2 +- .../rollup/action/SearchActionTests.java | 18 +- .../action/TransportTaskHelperTests.java | 2 +- .../xpack/rollup/config/ConfigTests.java | 10 +- .../xpack/rollup/job/IndexerUtilsTests.java | 12 +- .../job/RollupIndexerIndexingTests.java | 8 +- .../rollup/job/RollupIndexerStateTests.java | 6 +- .../xpack/rollup/job/RollupJobTaskTests.java | 2 +- .../xpack/rollup/PutRollupJobRequest.java | 129 +++++++++++++ .../xpack/rollup/PutRollupJobResponse.java | 37 ++++ .../protocol/xpack}/rollup/RollupField.java | 4 +- .../rollup/job/DateHistogramGroupConfig.java | 25 ++- .../xpack}/rollup/job/GroupConfig.java | 23 ++- .../rollup/job/HistogramGroupConfig.java | 25 ++- .../xpack}/rollup/job/MetricConfig.java | 33 +++- .../xpack}/rollup/job/RollupJobConfig.java | 26 ++- .../xpack}/rollup/job/TermsGroupConfig.java | 27 ++- .../protocol/xpack/rollup/package-info.java | 24 +++ 65 files changed, 1154 insertions(+), 354 deletions(-) create mode 100644 client/rest-high-level/src/main/java/org/elasticsearch/client/RollupClient.java create mode 100644 client/rest-high-level/src/test/java/org/elasticsearch/client/RollupIT.java create mode 100644 client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/RollupDocumentationIT.java create mode 100644 docs/java-rest/high-level/x-pack/rollup/put_job.asciidoc rename x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/{PutJobActionRequestTests.java => PutRollupJobRequestTests.java} (57%) create mode 100644 x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/PutRollupJobResponseTests.java create mode 100644 x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/PutRollupJobRequest.java create mode 100644 x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/PutRollupJobResponse.java rename x-pack/{plugin/core/src/main/java/org/elasticsearch/xpack/core => protocol/src/main/java/org/elasticsearch/protocol/xpack}/rollup/RollupField.java (98%) rename x-pack/{plugin/core/src/main/java/org/elasticsearch/xpack/core => protocol/src/main/java/org/elasticsearch/protocol/xpack}/rollup/job/DateHistogramGroupConfig.java (92%) rename x-pack/{plugin/core/src/main/java/org/elasticsearch/xpack/core => protocol/src/main/java/org/elasticsearch/protocol/xpack}/rollup/job/GroupConfig.java (87%) rename x-pack/{plugin/core/src/main/java/org/elasticsearch/xpack/core => protocol/src/main/java/org/elasticsearch/protocol/xpack}/rollup/job/HistogramGroupConfig.java (87%) rename x-pack/{plugin/core/src/main/java/org/elasticsearch/xpack/core => protocol/src/main/java/org/elasticsearch/protocol/xpack}/rollup/job/MetricConfig.java (87%) rename x-pack/{plugin/core/src/main/java/org/elasticsearch/xpack/core => protocol/src/main/java/org/elasticsearch/protocol/xpack}/rollup/job/RollupJobConfig.java (92%) rename x-pack/{plugin/core/src/main/java/org/elasticsearch/xpack/core => protocol/src/main/java/org/elasticsearch/protocol/xpack}/rollup/job/TermsGroupConfig.java (86%) create mode 100644 x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/package-info.java diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/RequestConverters.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/RequestConverters.java index 9470d44216343..c945b37ba561c 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/RequestConverters.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/RequestConverters.java @@ -112,6 +112,7 @@ import org.elasticsearch.protocol.xpack.license.PutLicenseRequest; import org.elasticsearch.protocol.xpack.migration.IndexUpgradeInfoRequest; import org.elasticsearch.protocol.xpack.ml.PutJobRequest; +import org.elasticsearch.protocol.xpack.rollup.PutRollupJobRequest; import org.elasticsearch.protocol.xpack.watcher.DeleteWatchRequest; import org.elasticsearch.protocol.xpack.watcher.PutWatchRequest; import org.elasticsearch.rest.action.search.RestSearchAction; @@ -1213,6 +1214,18 @@ static Request getMigrationAssistance(IndexUpgradeInfoRequest indexUpgradeInfoRe return request; } + static Request putRollupJob(PutRollupJobRequest putRollupJobRequest) throws IOException { + String endpoint = new EndpointBuilder() + .addPathPartAsIs("_xpack") + .addPathPartAsIs("rollup") + .addPathPartAsIs("job") + .addPathPart(putRollupJobRequest.getConfig().getId()) + .build(); + Request request = new Request(HttpPut.METHOD_NAME, endpoint); + request.setEntity(createEntity(putRollupJobRequest, REQUEST_BODY_CONTENT_TYPE)); + return request; + } + private static HttpEntity createEntity(ToXContent toXContent, XContentType xContentType) throws IOException { BytesRef source = XContentHelper.toXContent(toXContent, xContentType, false).toBytesRef(); return new ByteArrayEntity(source.bytes, source.offset, source.length, createContentType(xContentType)); 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 50d7465ae334a..1fac1f10ccedd 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 @@ -212,6 +212,7 @@ public class RestHighLevelClient implements Closeable { private final LicenseClient licenseClient = new LicenseClient(this); private final MigrationClient migrationClient = new MigrationClient(this); private final MachineLearningClient machineLearningClient = new MachineLearningClient(this); + private final RollupClient rollupClient = new RollupClient(this); /** * Creates a {@link RestHighLevelClient} given the low level {@link RestClientBuilder} that allows to build the @@ -361,6 +362,16 @@ public MachineLearningClient machineLearning() { return machineLearningClient; } + /** + * Provides methods for accessing the Elastic Licensed Rollup APIs that + * are shipped with the default distribution of Elasticsearch. All of + * these APIs will 404 if run against the OSS distribution of Elasticsearch. + *

+ * See the + * Watcher APIs on elastic.co for more information. + */ + public RollupClient rollup() { return rollupClient; } + /** * Executes a bulk request using the Bulk API. * See Bulk API on elastic.co 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 new file mode 100644 index 0000000000000..992a52811d98b --- /dev/null +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/RollupClient.java @@ -0,0 +1,71 @@ +/* + * 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; + +import org.elasticsearch.action.ActionListener; +import org.elasticsearch.protocol.xpack.rollup.PutRollupJobRequest; +import org.elasticsearch.protocol.xpack.rollup.PutRollupJobResponse; + +import java.io.IOException; + +import static java.util.Collections.emptySet; + +/** + * A wrapper for the {@link RestHighLevelClient} that provides methods for + * accessing the Elastic Rollup-related methods + *

+ * See the + * X-Pack Rollup APIs on elastic.co for more information. + */ +public class RollupClient { + + private final RestHighLevelClient restHighLevelClient; + + RollupClient(RestHighLevelClient restHighLevelClient) { + this.restHighLevelClient = restHighLevelClient; + } + + /** + * Put a rollup job into 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 PutRollupJobResponse putRollupJob(PutRollupJobRequest request, RequestOptions options) throws IOException { + return restHighLevelClient.performRequestAndParseEntity(request, RequestConverters::putRollupJob, options, + PutRollupJobResponse::fromXContent, emptySet()); + } + + /** + * Asynchronously put a rollup job into 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 + * @param listener the listener to be notified upon request completion + */ + public void putRollupJobAsync(PutRollupJobRequest request, RequestOptions options, ActionListener listener) { + restHighLevelClient.performRequestAsyncAndParseEntity(request, RequestConverters::putRollupJob, options, + PutRollupJobResponse::fromXContent, listener, emptySet()); + } +} diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/RestHighLevelClientTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/RestHighLevelClientTests.java index b5d8dbb628eb9..9213a13a6d4b5 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/RestHighLevelClientTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/RestHighLevelClientTests.java @@ -757,6 +757,7 @@ public void testApiNamingConventions() throws Exception { if (apiName.startsWith("xpack.") == false && apiName.startsWith("license.") == false && apiName.startsWith("machine_learning.") == false && + apiName.startsWith("rollup.") == false && apiName.startsWith("watcher.") == false && apiName.startsWith("migration.") == false) { apiNotFound.add(apiName); 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 new file mode 100644 index 0000000000000..3a2eef67046c6 --- /dev/null +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/RollupIT.java @@ -0,0 +1,158 @@ +/* + * 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; + +import org.elasticsearch.action.admin.indices.refresh.RefreshRequest; +import org.elasticsearch.action.admin.indices.refresh.RefreshResponse; +import org.elasticsearch.action.bulk.BulkItemResponse; +import org.elasticsearch.action.bulk.BulkRequest; +import org.elasticsearch.action.bulk.BulkResponse; +import org.elasticsearch.action.index.IndexRequest; +import org.elasticsearch.action.search.SearchRequest; +import org.elasticsearch.action.search.SearchResponse; +import org.elasticsearch.action.support.WriteRequest; +import org.elasticsearch.common.unit.TimeValue; +import org.elasticsearch.protocol.xpack.rollup.PutRollupJobRequest; +import org.elasticsearch.protocol.xpack.rollup.PutRollupJobResponse; +import org.elasticsearch.protocol.xpack.rollup.job.DateHistogramGroupConfig; +import org.elasticsearch.protocol.xpack.rollup.job.GroupConfig; +import org.elasticsearch.protocol.xpack.rollup.job.MetricConfig; +import org.elasticsearch.protocol.xpack.rollup.job.RollupJobConfig; +import org.elasticsearch.rest.RestStatus; +import org.elasticsearch.search.SearchHit; +import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval; + +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Set; + +import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; +import static org.elasticsearch.protocol.xpack.rollup.RollupField.SUPPORTED_METRICS; + +public class RollupIT extends ESRestHighLevelClientTestCase { + + @SuppressWarnings("unchecked") + public void testPutRollupJob() throws Exception { + final Set values = new HashSet<>(); + double sum = 0.0d; + int max = Integer.MIN_VALUE; + int min = Integer.MAX_VALUE; + + final BulkRequest bulkRequest = new BulkRequest(); + bulkRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE); + for (int minute = 0; minute < 60; minute++) { + for (int second = 0; second < 60; second = second + 10) { + final int value = randomIntBetween(0, 100); + + final IndexRequest indexRequest = new IndexRequest("docs", "doc"); + indexRequest.source(jsonBuilder() + .startObject() + .field("value", value) + .field("date", String.format(Locale.ROOT, "2018-01-01T00:%02d:%02dZ", minute, second)) + .endObject()); + bulkRequest.add(indexRequest); + + values.add(value); + sum += value; + if (value > max) { + max = value; + } + if (value < min) { + min = value; + } + } + } + + final int numDocs = bulkRequest.numberOfActions(); + + BulkResponse bulkResponse = highLevelClient().bulk(bulkRequest, RequestOptions.DEFAULT); + assertEquals(RestStatus.OK, bulkResponse.status()); + if (bulkResponse.hasFailures()) { + for (BulkItemResponse itemResponse : bulkResponse.getItems()) { + if (itemResponse.isFailed()) { + logger.fatal(itemResponse.getFailureMessage()); + } + } + } + assertFalse(bulkResponse.hasFailures()); + + RefreshResponse refreshResponse = highLevelClient().indices().refresh(new RefreshRequest("docs"), RequestOptions.DEFAULT); + assertEquals(0, refreshResponse.getFailedShards()); + + 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); + // 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)); + final TimeValue timeout = TimeValue.timeValueSeconds(randomIntBetween(30, 600)); + + PutRollupJobRequest putRollupJobRequest = new PutRollupJobRequest(); + putRollupJobRequest.setConfig(new RollupJobConfig(id, indexPattern, rollupIndex, cron, pageSize, groups, metrics, timeout)); + + final RollupClient rollupClient = highLevelClient().rollup(); + PutRollupJobResponse response = execute(putRollupJobRequest, rollupClient::putRollupJob, rollupClient::putRollupJobAsync); + assertTrue(response.isAcknowledged()); + + // TODO Replace this with the Rollup Start Job API + 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()); + assertEquals(1L, searchResponse.getHits().getTotalHits()); + + SearchHit searchHit = searchResponse.getHits().getAt(0); + Map source = searchHit.getSourceAsMap(); + assertNotNull(source); + + assertEquals(numDocs, source.get("date.date_histogram._count")); + assertEquals(groups.getDateHistogram().getInterval().toString(), source.get("date.date_histogram.interval")); + assertEquals(groups.getDateHistogram().getTimeZone(), source.get("date.date_histogram.time_zone")); + + for (MetricConfig metric : metrics) { + for (String name : metric.getMetrics()) { + Number value = (Number) source.get(metric.getField() + "." + name + ".value"); + if ("min".equals(name)) { + assertEquals(finalMin, value.intValue()); + } else if ("max".equals(name)) { + assertEquals(finalMax, value.intValue()); + } else if ("sum".equals(name)) { + assertEquals(finalSum, value.doubleValue(), 0.0d); + } else if ("avg".equals(name)) { + assertEquals(finalSum, value.doubleValue(), 0.0d); + Number avgCount = (Number) source.get(metric.getField() + "." + name + "._count"); + assertEquals(numDocs, avgCount.intValue()); + } else if ("value_count".equals(name)) { + assertEquals(numDocs, value.intValue()); + } + } + } + }); + } +} 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 new file mode 100644 index 0000000000000..080a52810a260 --- /dev/null +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/RollupDocumentationIT.java @@ -0,0 +1,163 @@ +/* + * 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.documentation; + +import org.elasticsearch.action.ActionListener; +import org.elasticsearch.action.LatchedActionListener; +import org.elasticsearch.action.admin.indices.refresh.RefreshRequest; +import org.elasticsearch.action.admin.indices.refresh.RefreshResponse; +import org.elasticsearch.action.bulk.BulkRequest; +import org.elasticsearch.action.bulk.BulkResponse; +import org.elasticsearch.action.index.IndexRequest; +import org.elasticsearch.action.support.WriteRequest; +import org.elasticsearch.client.ESRestHighLevelClientTestCase; +import org.elasticsearch.client.RequestOptions; +import org.elasticsearch.client.RestHighLevelClient; +import org.elasticsearch.common.unit.TimeValue; +import org.elasticsearch.protocol.xpack.rollup.PutRollupJobRequest; +import org.elasticsearch.protocol.xpack.rollup.PutRollupJobResponse; +import org.elasticsearch.protocol.xpack.rollup.job.DateHistogramGroupConfig; +import org.elasticsearch.protocol.xpack.rollup.job.GroupConfig; +import org.elasticsearch.protocol.xpack.rollup.job.HistogramGroupConfig; +import org.elasticsearch.protocol.xpack.rollup.job.MetricConfig; +import org.elasticsearch.protocol.xpack.rollup.job.RollupJobConfig; +import org.elasticsearch.protocol.xpack.rollup.job.TermsGroupConfig; +import org.elasticsearch.rest.RestStatus; +import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval; +import org.junit.Before; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Locale; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; + +public class RollupDocumentationIT extends ESRestHighLevelClientTestCase { + + @Before + public void setUpDocs() throws IOException { + final BulkRequest bulkRequest = new BulkRequest(); + bulkRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE); + for (int i = 0; i < 50; i++) { + final IndexRequest indexRequest = new IndexRequest("docs", "doc"); + indexRequest.source(jsonBuilder() + .startObject() + .field("timestamp", String.format(Locale.ROOT, "2018-01-01T00:%02d:00Z", i)) + .field("hostname", 0) + .field("datacenter", 0) + .field("temperature", 0) + .field("voltage", 0) + .field("load", 0) + .field("net_in", 0) + .field("net_out", 0) + .endObject()); + bulkRequest.add(indexRequest); + } + BulkResponse bulkResponse = highLevelClient().bulk(bulkRequest, RequestOptions.DEFAULT); + assertEquals(RestStatus.OK, bulkResponse.status()); + assertFalse(bulkResponse.hasFailures()); + + RefreshResponse refreshResponse = highLevelClient().indices().refresh(new RefreshRequest("docs"), RequestOptions.DEFAULT); + assertEquals(0, refreshResponse.getFailedShards()); + } + + public void testCreateRollupJob() throws Exception { + RestHighLevelClient client = highLevelClient(); + + final String indexPattern = "docs"; + final String rollupIndex = "rollup"; + final String cron = "*/1 * * * * ?"; + final int pageSize = 100; + final TimeValue timeout = null; + + //tag::x-pack-rollup-put-rollup-job-group-config + DateHistogramGroupConfig dateHistogram = + new DateHistogramGroupConfig("timestamp", DateHistogramInterval.HOUR, new DateHistogramInterval("7d"), "UTC"); // <1> + TermsGroupConfig terms = new TermsGroupConfig("hostname", "datacenter"); // <2> + HistogramGroupConfig histogram = new HistogramGroupConfig(5L, "load", "net_in", "net_out"); // <3> + + GroupConfig groups = new GroupConfig(dateHistogram, histogram, terms); // <4> + //end::x-pack-rollup-put-rollup-job-group-config + + //tag::x-pack-rollup-put-rollup-job-metrics-config + List metrics = new ArrayList<>(); // <1> + metrics.add(new MetricConfig("temperature", Arrays.asList("min", "max", "sum"))); // <2> + metrics.add(new MetricConfig("voltage", Arrays.asList("avg", "value_count"))); // <3> + //end::x-pack-rollup-put-rollup-job-metrics-config + { + String id = "job_1"; + + //tag::x-pack-rollup-put-rollup-job-config + RollupJobConfig config = new RollupJobConfig(id, // <1> + indexPattern, // <2> + rollupIndex, // <3> + cron, // <4> + pageSize, // <5> + groups, // <6> + metrics, // <7> + timeout); // <8> + //end::x-pack-rollup-put-rollup-job-config + + //tag::x-pack-rollup-put-rollup-job-request + PutRollupJobRequest request = new PutRollupJobRequest(config); // <1> + //end::x-pack-rollup-put-rollup-job-request + + //tag::x-pack-rollup-put-rollup-job-execute + PutRollupJobResponse response = client.rollup().putRollupJob(request, RequestOptions.DEFAULT); + //end::x-pack-rollup-put-rollup-job-execute + + //tag::x-pack-rollup-put-rollup-job-response + boolean acknowledged = response.isAcknowledged(); // <1> + //end::x-pack-rollup-put-rollup-job-response + assertTrue(acknowledged); + } + { + String id = "job_2"; + RollupJobConfig config = new RollupJobConfig(id, indexPattern, rollupIndex, cron, pageSize, groups, metrics, timeout); + PutRollupJobRequest request = new PutRollupJobRequest(config); + // tag::x-pack-rollup-put-rollup-job-execute-listener + ActionListener listener = new ActionListener() { + @Override + public void onResponse(PutRollupJobResponse response) { + // <1> + } + + @Override + public void onFailure(Exception e) { + // <2> + } + }; + // end::x-pack-rollup-put-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-put-rollup-job-execute-async + client.rollup().putRollupJobAsync(request, RequestOptions.DEFAULT, listener); // <1> + // end::x-pack-rollup-put-rollup-job-execute-async + + assertTrue(latch.await(30L, TimeUnit.SECONDS)); + } + } +} diff --git a/docs/java-rest/high-level/supported-apis.asciidoc b/docs/java-rest/high-level/supported-apis.asciidoc index 1ddee70f1e09b..3249077fae20a 100644 --- a/docs/java-rest/high-level/supported-apis.asciidoc +++ b/docs/java-rest/high-level/supported-apis.asciidoc @@ -215,3 +215,12 @@ The Java High Level REST Client supports the following Watcher APIs: include::watcher/put-watch.asciidoc[] include::watcher/delete-watch.asciidoc[] + + +== Rollup APIs + +The Java High Level REST Client supports the following Rollup APIs: + +* <> + +include::x-pack/rollup/put_job.asciidoc[] diff --git a/docs/java-rest/high-level/x-pack/rollup/put_job.asciidoc b/docs/java-rest/high-level/x-pack/rollup/put_job.asciidoc new file mode 100644 index 0000000000000..6d8f0352ef2b7 --- /dev/null +++ b/docs/java-rest/high-level/x-pack/rollup/put_job.asciidoc @@ -0,0 +1,172 @@ +[[java-rest-high-x-pack-rollup-put-job]] +=== Put Rollup Job API + +The Put 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-put-rollup-job-request]] +==== Put Rollup Job Request + +A `PutRollupJobRequest` requires the following argument: + +["source","java",subs="attributes,callouts,macros"] +-------------------------------------------------- +include-tagged::{doc-tests}/RollupDocumentationIT.java[x-pack-rollup-put-rollup-job-request] +-------------------------------------------------- +<1> The configuration of the Rollup job to create as a `RollupJobConfig` + +[[java-rest-high-x-pack-rollup-put-rollup-job-config]] +==== Rollup Job Configuration + +The `RollupJobConfig` object contains all the details about the rollup job +configuration. See <> to learn more +about the various configuration settings. + +A `RollupJobConfig` requires the following arguments: + +["source","java",subs="attributes,callouts,macros"] +-------------------------------------------------- +include-tagged::{doc-tests}/RollupDocumentationIT.java[x-pack-rollup-put-rollup-job-config] +-------------------------------------------------- +<1> The name of the Rollup job +<2> The index (or index pattern) to rollup +<3> The index to store rollup results into +<4> A cron expression which defines when the Rollup job should be executed +<5> The page size to use for the Rollup job +<6> The grouping configuration of the Rollup job as a `GroupConfig` +<7> The metrics configuration of the Rollup job as a list of `MetricConfig` +<8> The timeout value to use for the Rollup job as a `TimeValue` + + +[[java-rest-high-x-pack-rollup-put-rollup-job-group-config]] +==== Grouping Configuration + +The grouping configuration of the Rollup job is defined in the `RollupJobConfig` +using a `GroupConfig` instance. `GroupConfig` reflects all the configuration +settings that can be defined using the REST API. See <> +to learn more about these settings. + +Using the REST API, we could define this grouping configuration: + +[source,js] +-------------------------------------------------- +"groups" : { + "date_histogram": { + "field": "timestamp", + "interval": "1h", + "delay": "7d", + "time_zone": "UTC" + }, + "terms": { + "fields": ["hostname", "datacenter"] + }, + "histogram": { + "fields": ["load", "net_in", "net_out"], + "interval": 5 + } +} +-------------------------------------------------- +// NOTCONSOLE + +Using the `GroupConfig` object and the high level REST client, the same +configuration would be: + +["source","java",subs="attributes,callouts,macros"] +-------------------------------------------------- +include-tagged::{doc-tests}/RollupDocumentationIT.java[x-pack-rollup-put-rollup-job-group-config] +-------------------------------------------------- +<1> The date histogram aggregation to use to rollup up documents, as a `DateHistogramGroupConfig` +<2> The terms aggregation to use to rollup up documents, as a `TermsGroupConfig` +<3> The histogram aggregation to use to rollup up documents, as a `HistogramGroupConfig` +<4> The grouping configuration as a `GroupConfig` + + +[[java-rest-high-x-pack-rollup-put-rollup-job-metrics-config]] +==== Metrics Configuration + +After defining which groups should be generated for the data, you next configure +which metrics should be collected. The list of metrics is defined in the `RollupJobConfig` +using a `List` instance. `MetricConfig` reflects all the configuration +settings that can be defined using the REST API. See <> +to learn more about these settings. + +Using the REST API, we could define this metrics configuration: + +[source,js] +-------------------------------------------------- +"metrics": [ + { + "field": "temperature", + "metrics": ["min", "max", "sum"] + }, + { + "field": "voltage", + "metrics": ["avg", "value_count"] + } +] +-------------------------------------------------- +// NOTCONSOLE + +Using the `MetricConfig` object and the high level REST client, the same +configuration would be: + +["source","java",subs="attributes,callouts,macros"] +-------------------------------------------------- +include-tagged::{doc-tests}/RollupDocumentationIT.java[x-pack-rollup-put-rollup-job-metrics-config] +-------------------------------------------------- +<1> The list of `MetricConfig` to configure in the `RollupJobConfig` +<2> Adds the metrics to compute on the `temperature` field +<3> Adds the metrics to compute on the `voltage` field + + +[[java-rest-high-x-pack-rollup-put-rollup-job-execution]] +==== Execution + +The Put 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-put-rollup-job-execute] +-------------------------------------------------- + +[[java-rest-high-x-pack-rollup-put-rollup-job-response]] +==== Response + +The returned `PutRollupJobResponse` 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-put-rollup-job-response] +-------------------------------------------------- +<1> `acknowledged` is a boolean indicating whether the job was successfully created + +[[java-rest-high-x-pack-rollup-put-rollup-job-async]] +==== Asynchronous Execution + +This request can be executed asynchronously: + +["source","java",subs="attributes,callouts,macros"] +-------------------------------------------------- +include-tagged::{doc-tests}/RollupDocumentationIT.java[x-pack-rollup-put-rollup-job-execute-async] +-------------------------------------------------- +<1> The `PutRollupJobRequest` 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 `PutRollupJobResponse` looks like: + +["source","java",subs="attributes,callouts,macros"] +-------------------------------------------------- +include-tagged::{doc-tests}/RollupDocumentationIT.java[x-pack-rollup-put-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 diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackClientPlugin.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackClientPlugin.java index 0389ceffbc3d6..aa8b5f88d3f58 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackClientPlugin.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackClientPlugin.java @@ -33,16 +33,17 @@ import org.elasticsearch.plugins.ActionPlugin; import org.elasticsearch.plugins.NetworkPlugin; import org.elasticsearch.plugins.Plugin; +import org.elasticsearch.protocol.xpack.rollup.RollupField; import org.elasticsearch.tasks.Task; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.Transport; import org.elasticsearch.xpack.core.action.XPackInfoAction; import org.elasticsearch.xpack.core.action.XPackUsageAction; +import org.elasticsearch.xpack.core.beats.BeatsFeatureSetUsage; import org.elasticsearch.xpack.core.deprecation.DeprecationInfoAction; import org.elasticsearch.xpack.core.graph.GraphFeatureSetUsage; import org.elasticsearch.xpack.core.graph.action.GraphExploreAction; import org.elasticsearch.xpack.core.logstash.LogstashFeatureSetUsage; -import org.elasticsearch.xpack.core.beats.BeatsFeatureSetUsage; import org.elasticsearch.xpack.core.ml.MachineLearningFeatureSetUsage; import org.elasticsearch.xpack.core.ml.MlMetadata; import org.elasticsearch.xpack.core.ml.action.CloseJobAction; @@ -96,7 +97,6 @@ import org.elasticsearch.xpack.core.ml.job.config.JobTaskState; import org.elasticsearch.xpack.core.monitoring.MonitoringFeatureSetUsage; import org.elasticsearch.xpack.core.rollup.RollupFeatureSetUsage; -import org.elasticsearch.xpack.core.rollup.RollupField; import org.elasticsearch.xpack.core.rollup.action.DeleteRollupJobAction; import org.elasticsearch.xpack.core.rollup.action.GetRollupCapsAction; import org.elasticsearch.xpack.core.rollup.action.GetRollupJobsAction; @@ -133,8 +133,8 @@ import org.elasticsearch.xpack.core.security.authc.support.mapper.expressiondsl.ExceptExpression; import org.elasticsearch.xpack.core.security.authc.support.mapper.expressiondsl.FieldExpression; import org.elasticsearch.xpack.core.security.authc.support.mapper.expressiondsl.RoleMapperExpression; -import org.elasticsearch.xpack.core.security.authz.privilege.ConditionalClusterPrivileges; import org.elasticsearch.xpack.core.security.authz.privilege.ConditionalClusterPrivilege; +import org.elasticsearch.xpack.core.security.authz.privilege.ConditionalClusterPrivileges; import org.elasticsearch.xpack.core.security.transport.netty4.SecurityNetty4Transport; import org.elasticsearch.xpack.core.ssl.SSLService; import org.elasticsearch.xpack.core.ssl.action.GetCertificateInfoAction; @@ -379,7 +379,7 @@ public List getNamedXContent() { StartDatafeedAction.DatafeedParams::fromXContent), new NamedXContentRegistry.Entry(PersistentTaskParams.class, new ParseField(OpenJobAction.TASK_NAME), OpenJobAction.JobParams::fromXContent), - // ML - Task states + // ML - Task states new NamedXContentRegistry.Entry(PersistentTaskState.class, new ParseField(DatafeedState.NAME), DatafeedState::fromXContent), new NamedXContentRegistry.Entry(PersistentTaskState.class, new ParseField(JobTaskState.NAME), JobTaskState::fromXContent), // watcher diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/DeleteRollupJobAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/DeleteRollupJobAction.java index e59c6738d86b1..dec250a748f8e 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/DeleteRollupJobAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/DeleteRollupJobAction.java @@ -16,8 +16,8 @@ import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.protocol.xpack.rollup.RollupField; import org.elasticsearch.xpack.core.ml.utils.ExceptionsHelper; -import org.elasticsearch.xpack.core.rollup.RollupField; import java.io.IOException; import java.util.Objects; diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/GetRollupCapsAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/GetRollupCapsAction.java index 128874a6c8c87..73cade8150d3b 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/GetRollupCapsAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/GetRollupCapsAction.java @@ -21,7 +21,7 @@ import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContentObject; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.xpack.core.rollup.RollupField; +import org.elasticsearch.protocol.xpack.rollup.RollupField; import java.io.IOException; import java.util.Collections; diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/GetRollupIndexCapsAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/GetRollupIndexCapsAction.java index 4f95919c4986b..d3f856ac0d55d 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/GetRollupIndexCapsAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/GetRollupIndexCapsAction.java @@ -22,7 +22,7 @@ import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContentObject; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.xpack.core.rollup.RollupField; +import org.elasticsearch.protocol.xpack.rollup.RollupField; import java.io.IOException; import java.util.Arrays; diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/GetRollupJobsAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/GetRollupJobsAction.java index 50f7931508585..d990818225ec2 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/GetRollupJobsAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/GetRollupJobsAction.java @@ -24,9 +24,9 @@ import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContentObject; import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.protocol.xpack.rollup.job.RollupJobConfig; import org.elasticsearch.tasks.Task; -import org.elasticsearch.xpack.core.rollup.RollupField; -import org.elasticsearch.xpack.core.rollup.job.RollupJobConfig; +import org.elasticsearch.protocol.xpack.rollup.RollupField; import org.elasticsearch.xpack.core.rollup.job.RollupJobStats; import org.elasticsearch.xpack.core.rollup.job.RollupJobStatus; diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/PutRollupJobAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/PutRollupJobAction.java index 962f4cceb6af5..4acf269a771e7 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/PutRollupJobAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/PutRollupJobAction.java @@ -6,26 +6,12 @@ package org.elasticsearch.xpack.core.rollup.action; import org.elasticsearch.action.Action; -import org.elasticsearch.action.ActionRequestValidationException; -import org.elasticsearch.action.IndicesRequest; -import org.elasticsearch.action.fieldcaps.FieldCapabilities; -import org.elasticsearch.action.support.IndicesOptions; -import org.elasticsearch.action.support.master.AcknowledgedRequest; -import org.elasticsearch.action.support.master.AcknowledgedResponse; import org.elasticsearch.action.support.master.MasterNodeOperationRequestBuilder; import org.elasticsearch.client.ElasticsearchClient; -import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.xcontent.ToXContentObject; -import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.xpack.core.rollup.job.RollupJobConfig; +import org.elasticsearch.protocol.xpack.rollup.PutRollupJobRequest; +import org.elasticsearch.protocol.xpack.rollup.PutRollupJobResponse; -import java.io.IOException; -import java.util.Map; -import java.util.Objects; - -public class PutRollupJobAction extends Action { +public class PutRollupJobAction extends Action { public static final PutRollupJobAction INSTANCE = new PutRollupJobAction(); public static final String NAME = "cluster:admin/xpack/rollup/put"; @@ -35,113 +21,15 @@ private PutRollupJobAction() { } @Override - public Response newResponse() { - return new Response(); + public PutRollupJobResponse newResponse() { + return new PutRollupJobResponse(); } - public static class Request extends AcknowledgedRequest implements IndicesRequest, ToXContentObject { - - private RollupJobConfig config; - private IndicesOptions indicesOptions = IndicesOptions.fromOptions(false, false, true, false); - - public Request(RollupJobConfig config) { - this.config = config; - } - - public Request() { - - } - - public static Request fromXContent(final XContentParser parser, final String id) throws IOException { - return new Request(RollupJobConfig.fromXContent(parser, id)); - } - - public RollupJobConfig getConfig() { - return config; - } - - public void setConfig(RollupJobConfig config) { - this.config = config; - } - - @Override - public void readFrom(StreamInput in) throws IOException { - super.readFrom(in); - this.config = new RollupJobConfig(in); - } - - @Override - public void writeTo(StreamOutput out) throws IOException { - super.writeTo(out); - this.config.writeTo(out); - } - - @Override - public ActionRequestValidationException validate() { - return null; - } - - public RollupActionRequestValidationException validateMappings(Map> fieldCapsResponse) { - RollupActionRequestValidationException validationException = new RollupActionRequestValidationException(); - if (fieldCapsResponse.size() == 0) { - validationException.addValidationError("Could not find any fields in the index/index-pattern that were configured in job"); - return validationException; - } - config.validateMappings(fieldCapsResponse, validationException); - if (validationException.validationErrors().size() > 0) { - return validationException; - } - return null; - } - - @Override - public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { - return this.config.toXContent(builder, params); - } - - @Override - public String[] indices() { - return new String[]{this.config.getIndexPattern()}; - } - - @Override - public IndicesOptions indicesOptions() { - return indicesOptions; - } - - @Override - public int hashCode() { - return Objects.hash(config); - } - - @Override - public boolean equals(Object obj) { - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - Request other = (Request) obj; - return Objects.equals(config, other.config); - } - } - - public static class RequestBuilder extends MasterNodeOperationRequestBuilder { + public static class RequestBuilder + extends MasterNodeOperationRequestBuilder { protected RequestBuilder(ElasticsearchClient client, PutRollupJobAction action) { - super(client, action, new Request()); - } - } - - public static class Response extends AcknowledgedResponse { - - public Response() { - super(); - } - - public Response(boolean acknowledged) { - super(acknowledged); + super(client, action, new PutRollupJobRequest()); } } } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/RollupJobCaps.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/RollupJobCaps.java index 1b8eb736084a8..dcc34684c46fa 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/RollupJobCaps.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/RollupJobCaps.java @@ -11,7 +11,7 @@ import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.xcontent.ToXContentObject; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.xpack.core.rollup.job.RollupJobConfig; +import org.elasticsearch.protocol.xpack.rollup.job.RollupJobConfig; import java.io.IOException; import java.util.ArrayList; diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/StartRollupJobAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/StartRollupJobAction.java index e3dcb1a882f9f..b0b15aa4dd428 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/StartRollupJobAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/StartRollupJobAction.java @@ -19,7 +19,7 @@ import org.elasticsearch.common.xcontent.ToXContentObject; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.xpack.core.ml.utils.ExceptionsHelper; -import org.elasticsearch.xpack.core.rollup.RollupField; +import org.elasticsearch.protocol.xpack.rollup.RollupField; import java.io.IOException; import java.util.Collections; diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/StopRollupJobAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/StopRollupJobAction.java index eb48d640f21eb..8378dfa4cb244 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/StopRollupJobAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/StopRollupJobAction.java @@ -18,7 +18,7 @@ import org.elasticsearch.common.xcontent.ToXContentObject; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.xpack.core.ml.utils.ExceptionsHelper; -import org.elasticsearch.xpack.core.rollup.RollupField; +import org.elasticsearch.protocol.xpack.rollup.RollupField; import java.io.IOException; import java.util.Collections; diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/job/RollupJob.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/job/RollupJob.java index 94306966a34da..8e5bb34f160fc 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/job/RollupJob.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/job/RollupJob.java @@ -14,6 +14,7 @@ import org.elasticsearch.common.xcontent.ConstructingObjectParser; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.protocol.xpack.rollup.job.RollupJobConfig; import org.elasticsearch.xpack.core.XPackPlugin; import java.io.IOException; diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/rollup/ConfigTestHelpers.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/rollup/ConfigTestHelpers.java index d892eb550a17a..e43c78d5352ad 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/rollup/ConfigTestHelpers.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/rollup/ConfigTestHelpers.java @@ -7,14 +7,14 @@ import com.carrotsearch.randomizedtesting.generators.RandomNumbers; import org.elasticsearch.common.unit.TimeValue; +import org.elasticsearch.protocol.xpack.rollup.job.DateHistogramGroupConfig; +import org.elasticsearch.protocol.xpack.rollup.job.GroupConfig; +import org.elasticsearch.protocol.xpack.rollup.job.HistogramGroupConfig; +import org.elasticsearch.protocol.xpack.rollup.job.MetricConfig; +import org.elasticsearch.protocol.xpack.rollup.job.RollupJobConfig; +import org.elasticsearch.protocol.xpack.rollup.job.TermsGroupConfig; import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval; import org.elasticsearch.test.ESTestCase; -import org.elasticsearch.xpack.core.rollup.job.DateHistogramGroupConfig; -import org.elasticsearch.xpack.core.rollup.job.GroupConfig; -import org.elasticsearch.xpack.core.rollup.job.HistogramGroupConfig; -import org.elasticsearch.xpack.core.rollup.job.MetricConfig; -import org.elasticsearch.xpack.core.rollup.job.RollupJobConfig; -import org.elasticsearch.xpack.core.rollup.job.TermsGroupConfig; import java.util.ArrayList; import java.util.Arrays; diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/rollup/job/DateHistogramGroupConfigSerializingTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/rollup/job/DateHistogramGroupConfigSerializingTests.java index 6b8846def7284..fe08598eb05f3 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/rollup/job/DateHistogramGroupConfigSerializingTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/rollup/job/DateHistogramGroupConfigSerializingTests.java @@ -11,6 +11,7 @@ import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.protocol.xpack.rollup.job.DateHistogramGroupConfig; import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval; import org.elasticsearch.test.AbstractSerializingTestCase; import org.elasticsearch.xpack.core.rollup.ConfigTestHelpers; @@ -21,6 +22,7 @@ import java.util.HashMap; import java.util.Map; +import static org.apache.lucene.util.LuceneTestCase.random; import static org.elasticsearch.xpack.core.rollup.ConfigTestHelpers.randomDateHistogramGroupConfig; import static org.hamcrest.Matchers.equalTo; import static org.mockito.Mockito.mock; diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/rollup/job/GroupConfigSerializingTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/rollup/job/GroupConfigSerializingTests.java index 49ea206ded767..bff5f3ddd7f6d 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/rollup/job/GroupConfigSerializingTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/rollup/job/GroupConfigSerializingTests.java @@ -7,6 +7,7 @@ import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.protocol.xpack.rollup.job.GroupConfig; import org.elasticsearch.test.AbstractSerializingTestCase; import java.io.IOException; diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/rollup/job/HistogramGroupConfigSerializingTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/rollup/job/HistogramGroupConfigSerializingTests.java index ef81b235b1fba..8f886a7431d06 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/rollup/job/HistogramGroupConfigSerializingTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/rollup/job/HistogramGroupConfigSerializingTests.java @@ -9,8 +9,9 @@ import org.elasticsearch.action.fieldcaps.FieldCapabilities; import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.protocol.xpack.rollup.RollupField; +import org.elasticsearch.protocol.xpack.rollup.job.HistogramGroupConfig; import org.elasticsearch.test.AbstractSerializingTestCase; -import org.elasticsearch.xpack.core.rollup.RollupField; import java.io.IOException; import java.util.Collections; diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/rollup/job/MetricConfigSerializingTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/rollup/job/MetricConfigSerializingTests.java index a5b8d9afead2e..8146a64530d94 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/rollup/job/MetricConfigSerializingTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/rollup/job/MetricConfigSerializingTests.java @@ -9,6 +9,7 @@ import org.elasticsearch.action.fieldcaps.FieldCapabilities; import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.protocol.xpack.rollup.job.MetricConfig; import org.elasticsearch.test.AbstractSerializingTestCase; import org.elasticsearch.xpack.core.rollup.ConfigTestHelpers; diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/rollup/job/RollupJobConfigTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/rollup/job/RollupJobConfigTests.java index a5a82bc2bb090..7773fd70cb39b 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/rollup/job/RollupJobConfigTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/rollup/job/RollupJobConfigTests.java @@ -7,6 +7,7 @@ import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.protocol.xpack.rollup.job.RollupJobConfig; import org.elasticsearch.test.AbstractSerializingTestCase; import org.junit.Before; diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/rollup/job/TermsGroupConfigSerializingTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/rollup/job/TermsGroupConfigSerializingTests.java index ccdd616df7b51..70d61363bd3e0 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/rollup/job/TermsGroupConfigSerializingTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/rollup/job/TermsGroupConfigSerializingTests.java @@ -9,6 +9,7 @@ import org.elasticsearch.action.fieldcaps.FieldCapabilities; import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.protocol.xpack.rollup.job.TermsGroupConfig; import org.elasticsearch.search.aggregations.bucket.composite.CompositeValuesSourceBuilder; import org.elasticsearch.test.AbstractSerializingTestCase; diff --git a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/Rollup.java b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/Rollup.java index 0fc4d838f7ce8..52a4f8219ae9f 100644 --- a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/Rollup.java +++ b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/Rollup.java @@ -35,7 +35,7 @@ import org.elasticsearch.watcher.ResourceWatcherService; import org.elasticsearch.xpack.core.XPackPlugin; import org.elasticsearch.xpack.core.XPackSettings; -import org.elasticsearch.xpack.core.rollup.RollupField; +import org.elasticsearch.protocol.xpack.rollup.RollupField; import org.elasticsearch.xpack.core.rollup.action.DeleteRollupJobAction; import org.elasticsearch.xpack.core.rollup.action.GetRollupCapsAction; import org.elasticsearch.xpack.core.rollup.action.GetRollupIndexCapsAction; diff --git a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/RollupJobIdentifierUtils.java b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/RollupJobIdentifierUtils.java index d1706fd708e93..3ae8adf2ecfdb 100644 --- a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/RollupJobIdentifierUtils.java +++ b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/RollupJobIdentifierUtils.java @@ -11,9 +11,9 @@ import org.elasticsearch.search.aggregations.bucket.histogram.HistogramAggregationBuilder; import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder; import org.elasticsearch.search.aggregations.support.ValuesSourceAggregationBuilder; -import org.elasticsearch.xpack.core.rollup.RollupField; +import org.elasticsearch.protocol.xpack.rollup.RollupField; import org.elasticsearch.xpack.core.rollup.action.RollupJobCaps; -import org.elasticsearch.xpack.core.rollup.job.DateHistogramGroupConfig; +import org.elasticsearch.protocol.xpack.rollup.job.DateHistogramGroupConfig; import org.joda.time.DateTimeZone; import java.util.ArrayList; diff --git a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/RollupRequestTranslator.java b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/RollupRequestTranslator.java index 0668e7c43ad3c..076aec4ed51bc 100644 --- a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/RollupRequestTranslator.java +++ b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/RollupRequestTranslator.java @@ -12,6 +12,8 @@ import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.index.query.TermQueryBuilder; +import org.elasticsearch.protocol.xpack.rollup.RollupField; +import org.elasticsearch.protocol.xpack.rollup.job.DateHistogramGroupConfig; import org.elasticsearch.search.aggregations.AggregationBuilder; import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramAggregationBuilder; import org.elasticsearch.search.aggregations.bucket.histogram.HistogramAggregationBuilder; @@ -19,8 +21,6 @@ import org.elasticsearch.search.aggregations.metrics.avg.AvgAggregationBuilder; import org.elasticsearch.search.aggregations.metrics.sum.SumAggregationBuilder; import org.elasticsearch.search.aggregations.support.ValuesSourceAggregationBuilder; -import org.elasticsearch.xpack.core.rollup.RollupField; -import org.elasticsearch.xpack.core.rollup.job.DateHistogramGroupConfig; import org.joda.time.DateTimeZone; import java.util.ArrayList; diff --git a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/RollupResponseTranslator.java b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/RollupResponseTranslator.java index 4042e98ef93fb..c27de5164cf1d 100644 --- a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/RollupResponseTranslator.java +++ b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/RollupResponseTranslator.java @@ -34,7 +34,7 @@ import org.elasticsearch.search.aggregations.metrics.sum.InternalSum; import org.elasticsearch.search.aggregations.metrics.sum.SumAggregationBuilder; import org.elasticsearch.search.internal.InternalSearchResponse; -import org.elasticsearch.xpack.core.rollup.RollupField; +import org.elasticsearch.protocol.xpack.rollup.RollupField; import java.nio.charset.StandardCharsets; import java.util.ArrayList; diff --git a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/RollupIndexCaps.java b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/RollupIndexCaps.java index 88c2986574792..576180e06b996 100644 --- a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/RollupIndexCaps.java +++ b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/RollupIndexCaps.java @@ -19,10 +19,10 @@ import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentType; -import org.elasticsearch.xpack.core.rollup.RollupField; +import org.elasticsearch.protocol.xpack.rollup.RollupField; import org.elasticsearch.xpack.core.rollup.action.GetRollupCapsAction; import org.elasticsearch.xpack.core.rollup.action.RollupJobCaps; -import org.elasticsearch.xpack.core.rollup.job.RollupJobConfig; +import org.elasticsearch.protocol.xpack.rollup.job.RollupJobConfig; import java.io.IOException; import java.util.ArrayList; diff --git a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportGetRollupCapsAction.java b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportGetRollupCapsAction.java index 6d565e43b8644..4acd98057e7c9 100644 --- a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportGetRollupCapsAction.java +++ b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportGetRollupCapsAction.java @@ -19,7 +19,7 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.tasks.Task; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.xpack.core.rollup.RollupField; +import org.elasticsearch.protocol.xpack.rollup.RollupField; import org.elasticsearch.xpack.core.rollup.action.GetRollupCapsAction; import org.elasticsearch.xpack.core.rollup.action.RollableIndexCaps; import org.elasticsearch.xpack.core.rollup.action.RollupJobCaps; diff --git a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportGetRollupJobAction.java b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportGetRollupJobAction.java index a72dbfbe6b94f..2ca103f061dcb 100644 --- a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportGetRollupJobAction.java +++ b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportGetRollupJobAction.java @@ -23,7 +23,7 @@ import org.elasticsearch.tasks.Task; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.xpack.core.rollup.RollupField; +import org.elasticsearch.protocol.xpack.rollup.RollupField; import org.elasticsearch.xpack.core.rollup.action.GetRollupJobsAction; import org.elasticsearch.xpack.core.rollup.job.RollupJobStatus; import org.elasticsearch.xpack.rollup.job.RollupJobTask; @@ -124,4 +124,4 @@ protected GetRollupJobsAction.Response newResponse(GetRollupJobsAction.Request r protected GetRollupJobsAction.Response readTaskResponse(StreamInput in) throws IOException { return new GetRollupJobsAction.Response(in); } -} \ No newline at end of file +} diff --git a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportPutRollupJobAction.java b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportPutRollupJobAction.java index 889dfa3ac8efc..77410d5e611e7 100644 --- a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportPutRollupJobAction.java +++ b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportPutRollupJobAction.java @@ -38,22 +38,24 @@ import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.persistent.PersistentTasksCustomMetaData; import org.elasticsearch.persistent.PersistentTasksService; +import org.elasticsearch.protocol.xpack.rollup.PutRollupJobRequest; +import org.elasticsearch.protocol.xpack.rollup.PutRollupJobResponse; +import org.elasticsearch.protocol.xpack.rollup.RollupField; +import org.elasticsearch.protocol.xpack.rollup.job.RollupJobConfig; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; import org.elasticsearch.xpack.core.XPackField; import org.elasticsearch.xpack.core.XPackPlugin; -import org.elasticsearch.xpack.core.rollup.RollupField; import org.elasticsearch.xpack.core.rollup.action.PutRollupJobAction; import org.elasticsearch.xpack.core.rollup.job.RollupJob; -import org.elasticsearch.xpack.core.rollup.job.RollupJobConfig; import org.elasticsearch.xpack.rollup.Rollup; import java.util.Map; import java.util.Objects; import java.util.stream.Collectors; -public class TransportPutRollupJobAction extends TransportMasterNodeAction { +public class TransportPutRollupJobAction extends TransportMasterNodeAction { private final XPackLicenseState licenseState; private final PersistentTasksService persistentTasksService; private final Client client; @@ -64,7 +66,7 @@ public TransportPutRollupJobAction(Settings settings, TransportService transport ClusterService clusterService, XPackLicenseState licenseState, PersistentTasksService persistentTasksService, Client client) { super(settings, PutRollupJobAction.NAME, transportService, clusterService, threadPool, actionFilters, - indexNameExpressionResolver, PutRollupJobAction.Request::new); + indexNameExpressionResolver, PutRollupJobRequest::new); this.licenseState = licenseState; this.persistentTasksService = persistentTasksService; this.client = client; @@ -76,13 +78,13 @@ protected String executor() { } @Override - protected PutRollupJobAction.Response newResponse() { - return new PutRollupJobAction.Response(); + protected PutRollupJobResponse newResponse() { + return new PutRollupJobResponse(); } @Override - protected void masterOperation(PutRollupJobAction.Request request, ClusterState clusterState, - ActionListener listener) { + protected void masterOperation(PutRollupJobRequest request, ClusterState clusterState, + ActionListener listener) { if (!licenseState.isRollupAllowed()) { listener.onFailure(LicenseUtils.newComplianceException(XPackField.ROLLUP)); @@ -123,7 +125,7 @@ private static RollupJob createRollupJob(RollupJobConfig config, ThreadPool thre return new RollupJob(config, filteredHeaders); } - static void createIndex(RollupJob job, ActionListener listener, + static void createIndex(RollupJob job, ActionListener listener, PersistentTasksService persistentTasksService, Client client, Logger logger) { String jobMetadata = "\"" + job.getConfig().getId() + "\":" + job.getConfig().toJSONString(); @@ -148,7 +150,7 @@ static void createIndex(RollupJob job, ActionListener listener, + static void updateMapping(RollupJob job, ActionListener listener, PersistentTasksService persistentTasksService, Client client, Logger logger) { final String indexName = job.getConfig().getRollupIndex(); @@ -210,7 +212,7 @@ static void updateMapping(RollupJob job, ActionListener listener, + static void startPersistentTask(RollupJob job, ActionListener listener, PersistentTasksService persistentTasksService) { persistentTasksService.sendStartRequest(job.getConfig().getId(), RollupField.TASK_NAME, job, @@ -226,13 +228,13 @@ static void startPersistentTask(RollupJob job, ActionListener listener, + private static void waitForRollupStarted(RollupJob job, ActionListener listener, PersistentTasksService persistentTasksService) { persistentTasksService.waitForPersistentTaskCondition(job.getConfig().getId(), Objects::nonNull, job.getConfig().getTimeout(), new PersistentTasksService.WaitForPersistentTaskListener() { @Override public void onResponse(PersistentTasksCustomMetaData.PersistentTask task) { - listener.onResponse(new PutRollupJobAction.Response(true)); + listener.onResponse(new PutRollupJobResponse(true)); } @Override @@ -249,7 +251,7 @@ public void onTimeout(TimeValue timeout) { } @Override - protected ClusterBlockException checkBlock(PutRollupJobAction.Request request, ClusterState state) { + protected ClusterBlockException checkBlock(PutRollupJobRequest request, ClusterState state) { return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_WRITE); } } diff --git a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportRollupSearchAction.java b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportRollupSearchAction.java index c63ab96fa2595..6e1b410cee90e 100644 --- a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportRollupSearchAction.java +++ b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportRollupSearchAction.java @@ -53,10 +53,10 @@ import org.elasticsearch.transport.TransportChannel; import org.elasticsearch.transport.TransportRequestHandler; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.xpack.core.rollup.RollupField; +import org.elasticsearch.protocol.xpack.rollup.RollupField; import org.elasticsearch.xpack.core.rollup.action.RollupJobCaps; import org.elasticsearch.xpack.core.rollup.action.RollupSearchAction; -import org.elasticsearch.xpack.core.rollup.job.DateHistogramGroupConfig; +import org.elasticsearch.protocol.xpack.rollup.job.DateHistogramGroupConfig; import org.elasticsearch.xpack.rollup.Rollup; import org.elasticsearch.xpack.rollup.RollupJobIdentifierUtils; import org.elasticsearch.xpack.rollup.RollupRequestTranslator; diff --git a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/job/IndexerUtils.java b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/job/IndexerUtils.java index 9119a5445d42e..17c1f37153878 100644 --- a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/job/IndexerUtils.java +++ b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/job/IndexerUtils.java @@ -14,9 +14,9 @@ import org.elasticsearch.search.aggregations.bucket.histogram.HistogramAggregationBuilder; import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder; import org.elasticsearch.search.aggregations.metrics.InternalNumericMetricsAggregation; -import org.elasticsearch.xpack.core.rollup.RollupField; -import org.elasticsearch.xpack.core.rollup.job.DateHistogramGroupConfig; -import org.elasticsearch.xpack.core.rollup.job.GroupConfig; +import org.elasticsearch.protocol.xpack.rollup.RollupField; +import org.elasticsearch.protocol.xpack.rollup.job.DateHistogramGroupConfig; +import org.elasticsearch.protocol.xpack.rollup.job.GroupConfig; import org.elasticsearch.xpack.core.rollup.job.RollupJobStats; import org.elasticsearch.xpack.rollup.Rollup; diff --git a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/job/RollupIndexer.java b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/job/RollupIndexer.java index 87294706b3b7d..10a05477c1f69 100644 --- a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/job/RollupIndexer.java +++ b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/job/RollupIndexer.java @@ -20,12 +20,12 @@ import org.elasticsearch.search.aggregations.bucket.composite.CompositeValuesSourceBuilder; import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramAggregationBuilder; import org.elasticsearch.search.builder.SearchSourceBuilder; -import org.elasticsearch.xpack.core.rollup.RollupField; -import org.elasticsearch.xpack.core.rollup.job.DateHistogramGroupConfig; -import org.elasticsearch.xpack.core.rollup.job.GroupConfig; +import org.elasticsearch.protocol.xpack.rollup.RollupField; +import org.elasticsearch.protocol.xpack.rollup.job.DateHistogramGroupConfig; +import org.elasticsearch.protocol.xpack.rollup.job.GroupConfig; import org.elasticsearch.xpack.core.rollup.job.IndexerState; import org.elasticsearch.xpack.core.rollup.job.RollupJob; -import org.elasticsearch.xpack.core.rollup.job.RollupJobConfig; +import org.elasticsearch.protocol.xpack.rollup.job.RollupJobConfig; import org.elasticsearch.xpack.core.rollup.job.RollupJobStats; import java.util.ArrayList; diff --git a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/job/RollupJobTask.java b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/job/RollupJobTask.java index 65362f9ad9dd3..c982901ae61d3 100644 --- a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/job/RollupJobTask.java +++ b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/job/RollupJobTask.java @@ -25,12 +25,12 @@ import org.elasticsearch.tasks.TaskId; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.xpack.core.ClientHelper; -import org.elasticsearch.xpack.core.rollup.RollupField; +import org.elasticsearch.protocol.xpack.rollup.RollupField; import org.elasticsearch.xpack.core.rollup.action.StartRollupJobAction; import org.elasticsearch.xpack.core.rollup.action.StopRollupJobAction; import org.elasticsearch.xpack.core.rollup.job.IndexerState; import org.elasticsearch.xpack.core.rollup.job.RollupJob; -import org.elasticsearch.xpack.core.rollup.job.RollupJobConfig; +import org.elasticsearch.protocol.xpack.rollup.job.RollupJobConfig; import org.elasticsearch.xpack.core.rollup.job.RollupJobStats; import org.elasticsearch.xpack.core.rollup.job.RollupJobStatus; import org.elasticsearch.xpack.core.scheduler.SchedulerEngine; diff --git a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestPutRollupJobAction.java b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestPutRollupJobAction.java index 231e382827e8a..16febafb1f483 100644 --- a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestPutRollupJobAction.java +++ b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestPutRollupJobAction.java @@ -7,9 +7,8 @@ import org.elasticsearch.client.node.NodeClient; -import org.elasticsearch.common.ParseField; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.protocol.xpack.rollup.PutRollupJobRequest; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; @@ -20,7 +19,6 @@ import java.io.IOException; public class RestPutRollupJobAction extends BaseRestHandler { - public static final ParseField ID = new ParseField("id"); public RestPutRollupJobAction(Settings settings, RestController controller) { super(settings); @@ -28,13 +26,9 @@ public RestPutRollupJobAction(Settings settings, RestController controller) { } @Override - protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient client) throws IOException { - String id = restRequest.param(ID.getPreferredName()); - XContentParser parser = restRequest.contentParser(); - - PutRollupJobAction.Request request = PutRollupJobAction.Request.fromXContent(parser, id); - - return channel -> client.execute(PutRollupJobAction.INSTANCE, request, new RestToXContentListener<>(channel)); + protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException { + final PutRollupJobRequest putRollupJobRequest = PutRollupJobRequest.fromXContent(request.contentParser(), request.param("id")); + return channel -> client.execute(PutRollupJobAction.INSTANCE, putRollupJobRequest, new RestToXContentListener<>(channel)); } @Override diff --git a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestStartRollupJobAction.java b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestStartRollupJobAction.java index dfa5c977f2a5f..1127bdaea5348 100644 --- a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestStartRollupJobAction.java +++ b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestStartRollupJobAction.java @@ -11,7 +11,7 @@ import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; -import org.elasticsearch.xpack.core.rollup.RollupField; +import org.elasticsearch.protocol.xpack.rollup.RollupField; import org.elasticsearch.xpack.rollup.Rollup; import org.elasticsearch.xpack.core.rollup.action.StartRollupJobAction; diff --git a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestStopRollupJobAction.java b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestStopRollupJobAction.java index f51952b7f6143..8ced1db8a6a1e 100644 --- a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestStopRollupJobAction.java +++ b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestStopRollupJobAction.java @@ -11,7 +11,7 @@ import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; -import org.elasticsearch.xpack.core.rollup.RollupField; +import org.elasticsearch.protocol.xpack.rollup.RollupField; import org.elasticsearch.xpack.rollup.Rollup; import org.elasticsearch.xpack.core.rollup.action.StopRollupJobAction; diff --git a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/RollupJobIdentifierUtilTests.java b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/RollupJobIdentifierUtilTests.java index 3235d0c39e256..115db849b7549 100644 --- a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/RollupJobIdentifierUtilTests.java +++ b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/RollupJobIdentifierUtilTests.java @@ -16,12 +16,12 @@ import org.elasticsearch.search.aggregations.support.ValueType; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.xpack.core.rollup.action.RollupJobCaps; -import org.elasticsearch.xpack.core.rollup.job.DateHistogramGroupConfig; -import org.elasticsearch.xpack.core.rollup.job.GroupConfig; -import org.elasticsearch.xpack.core.rollup.job.HistogramGroupConfig; -import org.elasticsearch.xpack.core.rollup.job.MetricConfig; -import org.elasticsearch.xpack.core.rollup.job.RollupJobConfig; -import org.elasticsearch.xpack.core.rollup.job.TermsGroupConfig; +import org.elasticsearch.protocol.xpack.rollup.job.DateHistogramGroupConfig; +import org.elasticsearch.protocol.xpack.rollup.job.GroupConfig; +import org.elasticsearch.protocol.xpack.rollup.job.HistogramGroupConfig; +import org.elasticsearch.protocol.xpack.rollup.job.MetricConfig; +import org.elasticsearch.protocol.xpack.rollup.job.RollupJobConfig; +import org.elasticsearch.protocol.xpack.rollup.job.TermsGroupConfig; import org.joda.time.DateTimeZone; import java.util.Arrays; diff --git a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/RollupResponseTranslationTests.java b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/RollupResponseTranslationTests.java index 35d9f0d133a3d..bdfc4d908fefc 100644 --- a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/RollupResponseTranslationTests.java +++ b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/RollupResponseTranslationTests.java @@ -66,7 +66,7 @@ import org.elasticsearch.search.aggregations.metrics.sum.SumAggregationBuilder; import org.elasticsearch.search.aggregations.support.ValueType; import org.elasticsearch.search.internal.InternalSearchResponse; -import org.elasticsearch.xpack.core.rollup.RollupField; +import org.elasticsearch.protocol.xpack.rollup.RollupField; import java.io.IOException; import java.util.ArrayList; @@ -76,7 +76,7 @@ import java.util.Map; import static java.util.Collections.singleton; -import static org.elasticsearch.xpack.core.rollup.RollupField.COUNT_FIELD; +import static org.elasticsearch.protocol.xpack.rollup.RollupField.COUNT_FIELD; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.not; import static org.hamcrest.core.IsEqual.equalTo; @@ -156,7 +156,7 @@ public void testMissingLiveIndex() { InternalSum count = mock(InternalSum.class); when(count.getValue()).thenReturn(2.0); when(count.value()).thenReturn(2.0); - when(count.getName()).thenReturn("foo." + RollupField.COUNT_FIELD); + when(count.getName()).thenReturn("foo." + COUNT_FIELD); when(count.getMetaData()).thenReturn(null); when(count.getType()).thenReturn(SumAggregationBuilder.NAME); subaggs.add(count); @@ -254,7 +254,7 @@ public void testTranslateRollup() { InternalSum count = mock(InternalSum.class); when(count.getValue()).thenReturn(2.0); when(count.value()).thenReturn(2.0); - when(count.getName()).thenReturn("foo." + RollupField.COUNT_FIELD); + when(count.getName()).thenReturn("foo." + COUNT_FIELD); when(count.getMetaData()).thenReturn(null); when(count.getType()).thenReturn(SumAggregationBuilder.NAME); subaggs.add(count); @@ -379,7 +379,7 @@ public void testSimpleReduction() { InternalSum count = mock(InternalSum.class); when(count.getValue()).thenReturn(2.0); when(count.value()).thenReturn(2.0); - when(count.getName()).thenReturn("foo." + RollupField.COUNT_FIELD); + when(count.getName()).thenReturn("foo." + COUNT_FIELD); when(count.getMetaData()).thenReturn(null); when(count.getType()).thenReturn(SumAggregationBuilder.NAME); subaggs.add(count); @@ -523,8 +523,8 @@ public void testDateHisto() throws IOException { DateHistogramAggregationBuilder rollupHisto = new DateHistogramAggregationBuilder("histo") .field("timestamp.date_histogram." + RollupField.TIMESTAMP) .interval(100) - .subAggregation(new SumAggregationBuilder("histo." + RollupField.COUNT_FIELD) - .field("timestamp.date_histogram." + RollupField.COUNT_FIELD)); + .subAggregation(new SumAggregationBuilder("histo." + COUNT_FIELD) + .field("timestamp.date_histogram." + COUNT_FIELD)); DateFieldMapper.Builder nrBuilder = new DateFieldMapper.Builder("histo"); DateFieldMapper.DateFieldType nrFTtimestamp = nrBuilder.fieldType(); @@ -536,11 +536,11 @@ public void testDateHisto() throws IOException { rFTtimestamp.setHasDocValues(true); rFTtimestamp.setName(rollupHisto.field()); - NumberFieldMapper.Builder valueBuilder = new NumberFieldMapper.Builder("histo." + RollupField.COUNT_FIELD, + NumberFieldMapper.Builder valueBuilder = new NumberFieldMapper.Builder("histo." + COUNT_FIELD, NumberFieldMapper.NumberType.LONG); MappedFieldType rFTvalue = valueBuilder.fieldType(); rFTvalue.setHasDocValues(true); - rFTvalue.setName("timestamp.date_histogram." + RollupField.COUNT_FIELD); + rFTvalue.setName("timestamp.date_histogram." + COUNT_FIELD); List responses = doQueries(new MatchAllDocsQuery(), iw -> { @@ -569,8 +569,8 @@ public void testDateHistoWithGap() throws IOException { .field("timestamp.date_histogram." + RollupField.TIMESTAMP) .interval(100) .minDocCount(0) - .subAggregation(new SumAggregationBuilder("histo." + RollupField.COUNT_FIELD) - .field("timestamp.date_histogram." + RollupField.COUNT_FIELD)); + .subAggregation(new SumAggregationBuilder("histo." + COUNT_FIELD) + .field("timestamp.date_histogram." + COUNT_FIELD)); DateFieldMapper.Builder nrBuilder = new DateFieldMapper.Builder("histo"); DateFieldMapper.DateFieldType nrFTtimestamp = nrBuilder.fieldType(); @@ -582,11 +582,11 @@ public void testDateHistoWithGap() throws IOException { rFTtimestamp.setHasDocValues(true); rFTtimestamp.setName(rollupHisto.field()); - NumberFieldMapper.Builder valueBuilder = new NumberFieldMapper.Builder("histo." + RollupField.COUNT_FIELD, + NumberFieldMapper.Builder valueBuilder = new NumberFieldMapper.Builder("histo." + COUNT_FIELD, NumberFieldMapper.NumberType.LONG); MappedFieldType rFTvalue = valueBuilder.fieldType(); rFTvalue.setHasDocValues(true); - rFTvalue.setName("timestamp.date_histogram." + RollupField.COUNT_FIELD); + rFTvalue.setName("timestamp.date_histogram." + COUNT_FIELD); List responses = doQueries(new MatchAllDocsQuery(), iw -> { @@ -626,8 +626,8 @@ public void testNonMatchingPartition() throws IOException { .field("timestamp.date_histogram." + RollupField.TIMESTAMP) .interval(100) .minDocCount(0) - .subAggregation(new SumAggregationBuilder("histo." + RollupField.COUNT_FIELD) - .field("timestamp.date_histogram." + RollupField.COUNT_FIELD)); + .subAggregation(new SumAggregationBuilder("histo." + COUNT_FIELD) + .field("timestamp.date_histogram." + COUNT_FIELD)); DateFieldMapper.Builder nrBuilder = new DateFieldMapper.Builder("histo"); DateFieldMapper.DateFieldType nrFTtimestamp = nrBuilder.fieldType(); @@ -639,11 +639,11 @@ public void testNonMatchingPartition() throws IOException { rFTtimestamp.setHasDocValues(true); rFTtimestamp.setName(rollupHisto.field()); - NumberFieldMapper.Builder valueBuilder = new NumberFieldMapper.Builder("histo." + RollupField.COUNT_FIELD, + NumberFieldMapper.Builder valueBuilder = new NumberFieldMapper.Builder("histo." + COUNT_FIELD, NumberFieldMapper.NumberType.LONG); MappedFieldType rFTvalue = valueBuilder.fieldType(); rFTvalue.setHasDocValues(true); - rFTvalue.setName("timestamp.date_histogram." + RollupField.COUNT_FIELD); + rFTvalue.setName("timestamp.date_histogram." + COUNT_FIELD); KeywordFieldMapper.Builder nrKeywordBuilder = new KeywordFieldMapper.Builder("partition"); KeywordFieldMapper.KeywordFieldType nrKeywordFT = nrKeywordBuilder.fieldType(); @@ -690,33 +690,33 @@ public void testNonMatchingPartition() throws IOException { // Time 100: Two "a" documents, one "b" doc Document doc = new Document(); doc.add(new SortedNumericDocValuesField("timestamp.date_histogram." + RollupField.TIMESTAMP, 100)); - doc.add(new SortedNumericDocValuesField("timestamp.date_histogram." + RollupField.COUNT_FIELD, 2)); + doc.add(new SortedNumericDocValuesField("timestamp.date_histogram." + COUNT_FIELD, 2)); doc.add(new SortedNumericDocValuesField("timestamp.date_histogram." + RollupField.INTERVAL, 1)); doc.add(new TextField("partition.terms." + RollupField.VALUE, "a", Field.Store.NO)); - doc.add(new SortedNumericDocValuesField("partition.terms." + RollupField.COUNT_FIELD, 2)); + doc.add(new SortedNumericDocValuesField("partition.terms." + COUNT_FIELD, 2)); iw.addDocument(doc); doc = new Document(); doc.add(new SortedNumericDocValuesField("timestamp.date_histogram." + RollupField.TIMESTAMP, 100)); - doc.add(new SortedNumericDocValuesField("timestamp.date_histogram." + RollupField.COUNT_FIELD, 1)); + doc.add(new SortedNumericDocValuesField("timestamp.date_histogram." + COUNT_FIELD, 1)); doc.add(new SortedNumericDocValuesField("timestamp.date_histogram." + RollupField.INTERVAL, 1)); doc.add(new TextField("partition.terms." + RollupField.VALUE, "b", Field.Store.NO)); - doc.add(new SortedNumericDocValuesField("partition.terms." + RollupField.COUNT_FIELD, 1)); + doc.add(new SortedNumericDocValuesField("partition.terms." + COUNT_FIELD, 1)); iw.addDocument(doc); // Time 200: one "a" document, one "b" doc doc = new Document(); doc.add(new SortedNumericDocValuesField("timestamp.date_histogram." + RollupField.TIMESTAMP, 200)); - doc.add(new SortedNumericDocValuesField("timestamp.date_histogram." + RollupField.COUNT_FIELD, 1)); + doc.add(new SortedNumericDocValuesField("timestamp.date_histogram." + COUNT_FIELD, 1)); doc.add(new SortedNumericDocValuesField("timestamp.date_histogram." + RollupField.INTERVAL, 1)); doc.add(new TextField("partition.terms." + RollupField.VALUE, "a", Field.Store.NO)); - doc.add(new SortedNumericDocValuesField("partition.terms." + RollupField.COUNT_FIELD, 1)); + doc.add(new SortedNumericDocValuesField("partition.terms." + COUNT_FIELD, 1)); iw.addDocument(doc); doc = new Document(); doc.add(new SortedNumericDocValuesField("timestamp.date_histogram." + RollupField.TIMESTAMP, 200)); - doc.add(new SortedNumericDocValuesField("timestamp.date_histogram." + RollupField.COUNT_FIELD, 1)); + doc.add(new SortedNumericDocValuesField("timestamp.date_histogram." + COUNT_FIELD, 1)); doc.add(new SortedNumericDocValuesField("timestamp.date_histogram." + RollupField.INTERVAL, 1)); doc.add(new TextField("partition.terms." + RollupField.VALUE, "b", Field.Store.NO)); - doc.add(new SortedNumericDocValuesField("partition.terms." + RollupField.COUNT_FIELD, 1)); + doc.add(new SortedNumericDocValuesField("partition.terms." + COUNT_FIELD, 1)); iw.addDocument(doc); }, rollupHisto, new MappedFieldType[]{rFTtimestamp, rFTvalue, rKeywordFT})); @@ -737,8 +737,8 @@ public void testDateHistoOverlappingAggTrees() throws IOException { DateHistogramAggregationBuilder rollupHisto = new DateHistogramAggregationBuilder("histo") .field("timestamp.date_histogram." + RollupField.TIMESTAMP) .interval(100) - .subAggregation(new SumAggregationBuilder("histo." + RollupField.COUNT_FIELD) - .field("timestamp.date_histogram." + RollupField.COUNT_FIELD)); + .subAggregation(new SumAggregationBuilder("histo." + COUNT_FIELD) + .field("timestamp.date_histogram." + COUNT_FIELD)); DateFieldMapper.Builder nrBuilder = new DateFieldMapper.Builder("histo"); DateFieldMapper.DateFieldType nrFTtimestamp = nrBuilder.fieldType(); @@ -750,11 +750,11 @@ public void testDateHistoOverlappingAggTrees() throws IOException { rFTtimestamp.setHasDocValues(true); rFTtimestamp.setName(rollupHisto.field()); - NumberFieldMapper.Builder valueBuilder = new NumberFieldMapper.Builder("histo." + RollupField.COUNT_FIELD, + NumberFieldMapper.Builder valueBuilder = new NumberFieldMapper.Builder("histo." + COUNT_FIELD, NumberFieldMapper.NumberType.LONG); MappedFieldType rFTvalue = valueBuilder.fieldType(); rFTvalue.setHasDocValues(true); - rFTvalue.setName("timestamp.date_histogram." + RollupField.COUNT_FIELD); + rFTvalue.setName("timestamp.date_histogram." + COUNT_FIELD); List responses = doQueries(new MatchAllDocsQuery(), iw -> { @@ -798,8 +798,8 @@ public void testDateHistoOverlappingMergeRealIntoZero() throws IOException { DateHistogramAggregationBuilder rollupHisto = new DateHistogramAggregationBuilder("histo") .field("timestamp.date_histogram." + RollupField.TIMESTAMP) .interval(100) - .subAggregation(new SumAggregationBuilder("histo." + RollupField.COUNT_FIELD) - .field("timestamp.date_histogram." + RollupField.COUNT_FIELD)); + .subAggregation(new SumAggregationBuilder("histo." + COUNT_FIELD) + .field("timestamp.date_histogram." + COUNT_FIELD)); DateFieldMapper.Builder nrBuilder = new DateFieldMapper.Builder("histo"); DateFieldMapper.DateFieldType nrFTtimestamp = nrBuilder.fieldType(); @@ -811,11 +811,11 @@ public void testDateHistoOverlappingMergeRealIntoZero() throws IOException { rFTtimestamp.setHasDocValues(true); rFTtimestamp.setName(rollupHisto.field()); - NumberFieldMapper.Builder valueBuilder = new NumberFieldMapper.Builder("histo." + RollupField.COUNT_FIELD, + NumberFieldMapper.Builder valueBuilder = new NumberFieldMapper.Builder("histo." + COUNT_FIELD, NumberFieldMapper.NumberType.LONG); MappedFieldType rFTvalue = valueBuilder.fieldType(); rFTvalue.setHasDocValues(true); - rFTvalue.setName("timestamp.date_histogram." + RollupField.COUNT_FIELD); + rFTvalue.setName("timestamp.date_histogram." + COUNT_FIELD); List responses = doQueries(new MatchAllDocsQuery(), iw -> { @@ -834,13 +834,13 @@ public void testDateHistoOverlappingMergeRealIntoZero() throws IOException { iw -> { Document doc = new Document(); doc.add(new SortedNumericDocValuesField("timestamp.date_histogram." + RollupField.TIMESTAMP, 100)); - doc.add(new SortedNumericDocValuesField("timestamp.date_histogram." + RollupField.COUNT_FIELD, 0)); + doc.add(new SortedNumericDocValuesField("timestamp.date_histogram." + COUNT_FIELD, 0)); doc.add(new SortedNumericDocValuesField("timestamp.date_histogram." + RollupField.INTERVAL, 1)); iw.addDocument(doc); Document doc2 = new Document(); doc2.add(new SortedNumericDocValuesField("timestamp.date_histogram." + RollupField.TIMESTAMP, 200)); - doc2.add(new SortedNumericDocValuesField("timestamp.date_histogram." + RollupField.COUNT_FIELD, 0)); + doc2.add(new SortedNumericDocValuesField("timestamp.date_histogram." + COUNT_FIELD, 0)); doc2.add(new SortedNumericDocValuesField("timestamp.date_histogram." + RollupField.INTERVAL, 1)); iw.addDocument(doc2); @@ -866,8 +866,8 @@ public void testDateHistoOverlappingMergeZeroIntoReal() throws IOException { .field("timestamp.date_histogram." + RollupField.TIMESTAMP) .interval(100) .minDocCount(0) - .subAggregation(new SumAggregationBuilder("histo." + RollupField.COUNT_FIELD) - .field("timestamp.date_histogram." + RollupField.COUNT_FIELD)); + .subAggregation(new SumAggregationBuilder("histo." + COUNT_FIELD) + .field("timestamp.date_histogram." + COUNT_FIELD)); DateFieldMapper.Builder nrBuilder = new DateFieldMapper.Builder("histo"); DateFieldMapper.DateFieldType nrFTtimestamp = nrBuilder.fieldType(); @@ -879,11 +879,11 @@ public void testDateHistoOverlappingMergeZeroIntoReal() throws IOException { rFTtimestamp.setHasDocValues(true); rFTtimestamp.setName(rollupHisto.field()); - NumberFieldMapper.Builder valueBuilder = new NumberFieldMapper.Builder("histo." + RollupField.COUNT_FIELD, + NumberFieldMapper.Builder valueBuilder = new NumberFieldMapper.Builder("histo." + COUNT_FIELD, NumberFieldMapper.NumberType.LONG); MappedFieldType rFTvalue = valueBuilder.fieldType(); rFTvalue.setHasDocValues(true); - rFTvalue.setName("timestamp.date_histogram." + RollupField.COUNT_FIELD); + rFTvalue.setName("timestamp.date_histogram." + COUNT_FIELD); InternalAggregation currentTree = doQuery(new MatchAllDocsQuery(), iw -> { @@ -896,13 +896,13 @@ public void testDateHistoOverlappingMergeZeroIntoReal() throws IOException { iw -> { Document doc = new Document(); doc.add(new SortedNumericDocValuesField("timestamp.date_histogram." + RollupField.TIMESTAMP, 100)); - doc.add(new SortedNumericDocValuesField("timestamp.date_histogram." + RollupField.COUNT_FIELD, 0)); + doc.add(new SortedNumericDocValuesField("timestamp.date_histogram." + COUNT_FIELD, 0)); doc.add(new SortedNumericDocValuesField("timestamp.date_histogram." + RollupField.INTERVAL, 1)); iw.addDocument(doc); Document doc2 = new Document(); doc2.add(new SortedNumericDocValuesField("timestamp.date_histogram." + RollupField.TIMESTAMP, 200)); - doc2.add(new SortedNumericDocValuesField("timestamp.date_histogram." + RollupField.COUNT_FIELD, 0)); + doc2.add(new SortedNumericDocValuesField("timestamp.date_histogram." + COUNT_FIELD, 0)); doc2.add(new SortedNumericDocValuesField("timestamp.date_histogram." + RollupField.INTERVAL, 1)); iw.addDocument(doc2); @@ -1050,7 +1050,7 @@ public void testStringTerms() throws IOException { TermsAggregationBuilder rollupTerms = new TermsAggregationBuilder("terms", ValueType.STRING) .field("stringfield.terms." + RollupField.VALUE) .subAggregation(new SumAggregationBuilder("terms." + COUNT_FIELD) - .field("stringfield.terms." + RollupField.COUNT_FIELD)); + .field("stringfield.terms." + COUNT_FIELD)); KeywordFieldMapper.Builder nrBuilder = new KeywordFieldMapper.Builder("terms"); KeywordFieldMapper.KeywordFieldType nrFTterm = nrBuilder.fieldType(); @@ -1062,11 +1062,11 @@ public void testStringTerms() throws IOException { rFTterm.setHasDocValues(true); rFTterm.setName(rollupTerms.field()); - NumberFieldMapper.Builder valueBuilder = new NumberFieldMapper.Builder("terms." + RollupField.COUNT_FIELD, + NumberFieldMapper.Builder valueBuilder = new NumberFieldMapper.Builder("terms." + COUNT_FIELD, NumberFieldMapper.NumberType.LONG); MappedFieldType rFTvalue = valueBuilder.fieldType(); rFTvalue.setHasDocValues(true); - rFTvalue.setName("stringfield.terms." + RollupField.COUNT_FIELD); + rFTvalue.setName("stringfield.terms." + COUNT_FIELD); List responses = doQueries(new MatchAllDocsQuery(), iw -> { @@ -1091,7 +1091,7 @@ public void testStringTermsNullValue() throws IOException { TermsAggregationBuilder rollupTerms = new TermsAggregationBuilder("terms", ValueType.STRING) .field("stringfield.terms." + RollupField.VALUE) .subAggregation(new SumAggregationBuilder("terms." + COUNT_FIELD) - .field("stringfield.terms." + RollupField.COUNT_FIELD)); + .field("stringfield.terms." + COUNT_FIELD)); KeywordFieldMapper.Builder nrBuilder = new KeywordFieldMapper.Builder("terms"); KeywordFieldMapper.KeywordFieldType nrFTterm = nrBuilder.fieldType(); @@ -1103,11 +1103,11 @@ public void testStringTermsNullValue() throws IOException { rFTterm.setHasDocValues(true); rFTterm.setName(rollupTerms.field()); - NumberFieldMapper.Builder valueBuilder = new NumberFieldMapper.Builder("terms." + RollupField.COUNT_FIELD, + NumberFieldMapper.Builder valueBuilder = new NumberFieldMapper.Builder("terms." + COUNT_FIELD, NumberFieldMapper.NumberType.LONG); MappedFieldType rFTvalue = valueBuilder.fieldType(); rFTvalue.setHasDocValues(true); - rFTvalue.setName("stringfield.terms." + RollupField.COUNT_FIELD); + rFTvalue.setName("stringfield.terms." + COUNT_FIELD); List responses = doQueries(new MatchAllDocsQuery(), iw -> { @@ -1139,7 +1139,7 @@ public void testLongTerms() throws IOException { TermsAggregationBuilder rollupTerms = new TermsAggregationBuilder("terms", ValueType.LONG) .field("longfield.terms." + RollupField.VALUE) .subAggregation(new SumAggregationBuilder("terms." + COUNT_FIELD) - .field("longfield.terms." + RollupField.COUNT_FIELD)); + .field("longfield.terms." + COUNT_FIELD)); NumberFieldMapper.Builder nrBuilder = new NumberFieldMapper.Builder("terms", NumberFieldMapper.NumberType.LONG); MappedFieldType nrFTterm = nrBuilder.fieldType(); @@ -1151,11 +1151,11 @@ public void testLongTerms() throws IOException { rFTterm.setHasDocValues(true); rFTterm.setName(rollupTerms.field()); - NumberFieldMapper.Builder valueBuilder = new NumberFieldMapper.Builder("terms." + RollupField.COUNT_FIELD, + NumberFieldMapper.Builder valueBuilder = new NumberFieldMapper.Builder("terms." + COUNT_FIELD, NumberFieldMapper.NumberType.LONG); MappedFieldType rFTvalue = valueBuilder.fieldType(); rFTvalue.setHasDocValues(true); - rFTvalue.setName("longfield.terms." + RollupField.COUNT_FIELD); + rFTvalue.setName("longfield.terms." + COUNT_FIELD); List responses = doQueries(new MatchAllDocsQuery(), iw -> { @@ -1180,8 +1180,8 @@ public void testHisto() throws IOException { HistogramAggregationBuilder rollupHisto = new HistogramAggregationBuilder("histo") .field("bar.histogram." + RollupField.VALUE) .interval(100) - .subAggregation(new SumAggregationBuilder("histo." + RollupField.COUNT_FIELD) - .field("bar.histogram." + RollupField.COUNT_FIELD)); + .subAggregation(new SumAggregationBuilder("histo." + COUNT_FIELD) + .field("bar.histogram." + COUNT_FIELD)); NumberFieldMapper.Builder nrBuilder = new NumberFieldMapper.Builder("histo", NumberFieldMapper.NumberType.LONG); MappedFieldType nrFTbar = nrBuilder.fieldType(); @@ -1193,11 +1193,11 @@ public void testHisto() throws IOException { rFTbar.setHasDocValues(true); rFTbar.setName(rollupHisto.field()); - NumberFieldMapper.Builder valueBuilder = new NumberFieldMapper.Builder("histo." + RollupField.COUNT_FIELD, + NumberFieldMapper.Builder valueBuilder = new NumberFieldMapper.Builder("histo." + COUNT_FIELD, NumberFieldMapper.NumberType.LONG); MappedFieldType rFTvalue = valueBuilder.fieldType(); rFTvalue.setHasDocValues(true); - rFTvalue.setName("bar.histogram." + RollupField.COUNT_FIELD); + rFTvalue.setName("bar.histogram." + COUNT_FIELD); List responses = doQueries(new MatchAllDocsQuery(), iw -> { @@ -1224,8 +1224,8 @@ public void testOverlappingBuckets() throws IOException { DateHistogramAggregationBuilder rollupHisto = new DateHistogramAggregationBuilder("histo") .field("timestamp.date_histogram." + RollupField.TIMESTAMP) .interval(100) - .subAggregation(new SumAggregationBuilder("histo." + RollupField.COUNT_FIELD) - .field("timestamp.date_histogram." + RollupField.COUNT_FIELD)); + .subAggregation(new SumAggregationBuilder("histo." + COUNT_FIELD) + .field("timestamp.date_histogram." + COUNT_FIELD)); DateFieldMapper.Builder nrBuilder = new DateFieldMapper.Builder("histo"); DateFieldMapper.DateFieldType nrFTtimestamp = nrBuilder.fieldType(); @@ -1237,11 +1237,11 @@ public void testOverlappingBuckets() throws IOException { rFTtimestamp.setHasDocValues(true); rFTtimestamp.setName(rollupHisto.field()); - NumberFieldMapper.Builder valueBuilder = new NumberFieldMapper.Builder("histo." + RollupField.COUNT_FIELD, + NumberFieldMapper.Builder valueBuilder = new NumberFieldMapper.Builder("histo." + COUNT_FIELD, NumberFieldMapper.NumberType.LONG); MappedFieldType rFTvalue = valueBuilder.fieldType(); rFTvalue.setHasDocValues(true); - rFTvalue.setName("timestamp.date_histogram." + RollupField.COUNT_FIELD); + rFTvalue.setName("timestamp.date_histogram." + COUNT_FIELD); List responses = doQueries(new MatchAllDocsQuery(), iw -> { @@ -1277,15 +1277,15 @@ private Document timestampedValueDoc(long timestamp, long value) { private Document timestampedValueRollupDoc(long timestamp, long value) { Document doc = new Document(); doc.add(new SortedNumericDocValuesField("timestamp.date_histogram." + RollupField.TIMESTAMP, timestamp)); - doc.add(new SortedNumericDocValuesField("timestamp.date_histogram." + RollupField.COUNT_FIELD, 1)); + doc.add(new SortedNumericDocValuesField("timestamp.date_histogram." + COUNT_FIELD, 1)); doc.add(new SortedNumericDocValuesField("timestamp.date_histogram." + RollupField.INTERVAL, 1)); doc.add(new SortedNumericDocValuesField("foo.avg." + RollupField.VALUE, value)); - doc.add(new SortedNumericDocValuesField("foo.avg." + RollupField.COUNT_FIELD, 3)); + doc.add(new SortedNumericDocValuesField("foo.avg." + COUNT_FIELD, 3)); doc.add(new SortedNumericDocValuesField("foo.min." + RollupField.VALUE, value)); doc.add(new SortedNumericDocValuesField("foo.max." + RollupField.VALUE, value)); doc.add(new SortedNumericDocValuesField("foo.sum." + RollupField.VALUE, value)); doc.add(new SortedNumericDocValuesField("bar.histogram." + RollupField.VALUE, value)); - doc.add(new SortedNumericDocValuesField("bar.histogram." + RollupField.COUNT_FIELD, 1)); + doc.add(new SortedNumericDocValuesField("bar.histogram." + COUNT_FIELD, 1)); doc.add(new SortedNumericDocValuesField("bar.histogram." + RollupField.INTERVAL, 1)); return doc; } @@ -1299,7 +1299,7 @@ private Document stringValueDoc(String stringValue) { private Document stringValueRollupDoc(String stringValue, long docCount) { Document doc = new Document(); doc.add(new SortedSetDocValuesField("stringfield.terms." + RollupField.VALUE, new BytesRef(stringValue))); - doc.add(new SortedNumericDocValuesField("stringfield.terms." + RollupField.COUNT_FIELD, docCount)); + doc.add(new SortedNumericDocValuesField("stringfield.terms." + COUNT_FIELD, docCount)); return doc; } @@ -1312,7 +1312,7 @@ private Document longValueDoc(Long longValue) { private Document longValueRollupDoc(Long longValue, long docCount) { Document doc = new Document(); doc.add(new SortedNumericDocValuesField("longfield.terms." + RollupField.VALUE, longValue)); - doc.add(new SortedNumericDocValuesField("longfield.terms." + RollupField.COUNT_FIELD, docCount)); + doc.add(new SortedNumericDocValuesField("longfield.terms." + COUNT_FIELD, docCount)); return doc; } diff --git a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/GetRollupCapsActionRequestTests.java b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/GetRollupCapsActionRequestTests.java index 9068bcfce36a4..f7c5b303edc91 100644 --- a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/GetRollupCapsActionRequestTests.java +++ b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/GetRollupCapsActionRequestTests.java @@ -12,10 +12,10 @@ import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.test.AbstractStreamableTestCase; import org.elasticsearch.xpack.core.rollup.ConfigTestHelpers; -import org.elasticsearch.xpack.core.rollup.RollupField; +import org.elasticsearch.protocol.xpack.rollup.RollupField; import org.elasticsearch.xpack.core.rollup.action.GetRollupCapsAction; import org.elasticsearch.xpack.core.rollup.action.RollableIndexCaps; -import org.elasticsearch.xpack.core.rollup.job.RollupJobConfig; +import org.elasticsearch.protocol.xpack.rollup.job.RollupJobConfig; import org.mockito.Mockito; import java.io.IOException; diff --git a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/GetRollupIndexCapsActionRequestTests.java b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/GetRollupIndexCapsActionRequestTests.java index e9d5d6153b18c..c2cc770ab7e9b 100644 --- a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/GetRollupIndexCapsActionRequestTests.java +++ b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/GetRollupIndexCapsActionRequestTests.java @@ -12,7 +12,7 @@ import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.test.AbstractStreamableTestCase; import org.elasticsearch.xpack.core.rollup.ConfigTestHelpers; -import org.elasticsearch.xpack.core.rollup.RollupField; +import org.elasticsearch.protocol.xpack.rollup.RollupField; import org.elasticsearch.xpack.core.rollup.action.GetRollupIndexCapsAction; import org.elasticsearch.xpack.core.rollup.action.RollableIndexCaps; import org.mockito.Mockito; diff --git a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/PutJobStateMachineTests.java b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/PutJobStateMachineTests.java index d9caad5147d41..ff9b5ce867ec2 100644 --- a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/PutJobStateMachineTests.java +++ b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/PutJobStateMachineTests.java @@ -22,12 +22,12 @@ import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.persistent.PersistentTasksCustomMetaData; import org.elasticsearch.persistent.PersistentTasksService; +import org.elasticsearch.protocol.xpack.rollup.PutRollupJobResponse; +import org.elasticsearch.protocol.xpack.rollup.RollupField; +import org.elasticsearch.protocol.xpack.rollup.job.RollupJobConfig; import org.elasticsearch.test.ESTestCase; -import org.elasticsearch.xpack.core.rollup.RollupField; -import org.elasticsearch.xpack.core.rollup.action.PutRollupJobAction; -import org.elasticsearch.xpack.core.rollup.job.RollupJob; -import org.elasticsearch.xpack.core.rollup.job.RollupJobConfig; import org.elasticsearch.xpack.core.rollup.ConfigTestHelpers; +import org.elasticsearch.xpack.core.rollup.job.RollupJob; import org.elasticsearch.xpack.rollup.Rollup; import org.mockito.ArgumentCaptor; @@ -52,7 +52,7 @@ public class PutJobStateMachineTests extends ESTestCase { public void testCreateIndexException() { RollupJob job = new RollupJob(ConfigTestHelpers.randomRollupJobConfig(random(), "foo"), Collections.emptyMap()); - ActionListener testListener = ActionListener.wrap(response -> { + ActionListener testListener = ActionListener.wrap(response -> { fail("Listener success should not have been triggered."); }, e -> { assertThat(e.getMessage(), equalTo("Could not create index for rollup job [foo]")); @@ -78,7 +78,7 @@ public void testCreateIndexException() { public void testIndexAlreadyExists() { RollupJob job = new RollupJob(ConfigTestHelpers.randomRollupJobConfig(random()), Collections.emptyMap()); - ActionListener testListener = ActionListener.wrap(response -> { + ActionListener testListener = ActionListener.wrap(response -> { fail("Listener success should not have been triggered."); }, e -> { assertThat(e.getCause().getMessage(), equalTo("Ending")); @@ -110,7 +110,7 @@ public void testIndexAlreadyExists() { public void testIndexMetaData() throws InterruptedException { RollupJob job = new RollupJob(ConfigTestHelpers.randomRollupJobConfig(random()), Collections.emptyMap()); - ActionListener testListener = ActionListener.wrap(response -> { + ActionListener testListener = ActionListener.wrap(response -> { fail("Listener success should not have been triggered."); }, e -> { assertThat(e.getCause().getMessage(), equalTo("Ending")); @@ -153,7 +153,7 @@ public void testIndexMetaData() throws InterruptedException { public void testGetMappingFails() { RollupJob job = new RollupJob(ConfigTestHelpers.randomRollupJobConfig(random(), "foo"), Collections.emptyMap()); - ActionListener testListener = ActionListener.wrap(response -> { + ActionListener testListener = ActionListener.wrap(response -> { fail("Listener success should not have been triggered."); }, e -> { assertThat(e.getMessage(), equalTo("Could not update mappings for rollup job [foo]")); @@ -177,7 +177,7 @@ public void testGetMappingFails() { public void testNoMetadataInMapping() { RollupJob job = new RollupJob(ConfigTestHelpers.randomRollupJobConfig(random()), Collections.emptyMap()); - ActionListener testListener = ActionListener.wrap(response -> { + ActionListener testListener = ActionListener.wrap(response -> { fail("Listener success should not have been triggered."); }, e -> { assertThat(e.getMessage(), equalTo("Expected to find _meta key in mapping of rollup index [" @@ -210,7 +210,7 @@ public void testNoMetadataInMapping() { public void testNoMappingVersion() { RollupJob job = new RollupJob(ConfigTestHelpers.randomRollupJobConfig(random()), Collections.emptyMap()); - ActionListener testListener = ActionListener.wrap(response -> { + ActionListener testListener = ActionListener.wrap(response -> { fail("Listener success should not have been triggered."); }, e -> { assertThat(e.getMessage(), equalTo("Could not determine version of existing rollup metadata for index [" @@ -247,7 +247,7 @@ public void testNoMappingVersion() { public void testJobAlreadyInMapping() { RollupJob job = new RollupJob(ConfigTestHelpers.randomRollupJobConfig(random(), "foo"), Collections.emptyMap()); - ActionListener testListener = ActionListener.wrap(response -> { + ActionListener testListener = ActionListener.wrap(response -> { fail("Listener success should not have been triggered."); }, e -> { assertThat(e.getMessage(), equalTo("Cannot create rollup job [foo] because job was previously created (existing metadata).")); @@ -288,7 +288,7 @@ public void testAddJobToMapping() { final RollupJobConfig config = ConfigTestHelpers.randomRollupJobConfig(random(), ESTestCase.randomAlphaOfLength(10), "foo", "rollup_index_foo"); RollupJob job = new RollupJob(config, Collections.emptyMap()); - ActionListener testListener = ActionListener.wrap(response -> { + ActionListener testListener = ActionListener.wrap(response -> { fail("Listener success should not have been triggered."); }, e -> { assertThat(e.getMessage(), equalTo("Ending")); @@ -333,7 +333,7 @@ public void testAddJobToMapping() { public void testTaskAlreadyExists() { RollupJob job = new RollupJob(ConfigTestHelpers.randomRollupJobConfig(random(), "foo"), Collections.emptyMap()); - ActionListener testListener = ActionListener.wrap(response -> { + ActionListener testListener = ActionListener.wrap(response -> { fail("Listener success should not have been triggered."); }, e -> { assertThat(e.getMessage(), equalTo("Cannot create job [foo] because it has already been created (task exists)")); @@ -356,7 +356,7 @@ public void testTaskAlreadyExists() { public void testStartTask() { RollupJob job = new RollupJob(ConfigTestHelpers.randomRollupJobConfig(random()), Collections.emptyMap()); - ActionListener testListener = ActionListener.wrap(response -> { + ActionListener testListener = ActionListener.wrap(response -> { fail("Listener success should not have been triggered."); }, e -> { assertThat(e.getMessage(), equalTo("Ending")); diff --git a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/PutJobActionRequestTests.java b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/PutRollupJobRequestTests.java similarity index 57% rename from x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/PutJobActionRequestTests.java rename to x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/PutRollupJobRequestTests.java index 848bd5f13dd9e..8108f94a00f65 100644 --- a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/PutJobActionRequestTests.java +++ b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/PutRollupJobRequestTests.java @@ -7,14 +7,14 @@ import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.protocol.xpack.rollup.PutRollupJobRequest; import org.elasticsearch.test.AbstractStreamableXContentTestCase; -import org.elasticsearch.xpack.core.rollup.action.PutRollupJobAction.Request; import org.elasticsearch.xpack.core.rollup.ConfigTestHelpers; import org.junit.Before; import java.io.IOException; -public class PutJobActionRequestTests extends AbstractStreamableXContentTestCase { +public class PutRollupJobRequestTests extends AbstractStreamableXContentTestCase { private String jobId; @@ -24,8 +24,8 @@ public void setupJobID() { } @Override - protected Request createTestInstance() { - return new Request(ConfigTestHelpers.randomRollupJobConfig(random(), jobId)); + protected PutRollupJobRequest createTestInstance() { + return new PutRollupJobRequest(ConfigTestHelpers.randomRollupJobConfig(random(), jobId)); } @Override @@ -34,13 +34,13 @@ protected boolean supportsUnknownFields() { } @Override - protected Request createBlankInstance() { - return new Request(); + protected PutRollupJobRequest createBlankInstance() { + return new PutRollupJobRequest(); } @Override - protected Request doParseInstance(final XContentParser parser) throws IOException { - return Request.fromXContent(parser, jobId); + protected PutRollupJobRequest doParseInstance(final XContentParser parser) throws IOException { + return PutRollupJobRequest.fromXContent(parser, jobId); } } diff --git a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/PutRollupJobResponseTests.java b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/PutRollupJobResponseTests.java new file mode 100644 index 0000000000000..77666fd057c7c --- /dev/null +++ b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/PutRollupJobResponseTests.java @@ -0,0 +1,43 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ +package org.elasticsearch.xpack.rollup.action; + + +import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.protocol.xpack.rollup.PutRollupJobResponse; +import org.elasticsearch.test.AbstractStreamableXContentTestCase; +import org.junit.Before; + +public class PutRollupJobResponseTests extends AbstractStreamableXContentTestCase { + + private boolean acknowledged; + + @Before + public void setupJobID() { + acknowledged = randomBoolean(); + } + + @Override + protected PutRollupJobResponse createTestInstance() { + return new PutRollupJobResponse(acknowledged); + } + + @Override + protected boolean supportsUnknownFields() { + return false; + } + + @Override + protected PutRollupJobResponse createBlankInstance() { + return new PutRollupJobResponse(); + } + + @Override + protected PutRollupJobResponse doParseInstance(final XContentParser parser) { + return PutRollupJobResponse.fromXContent(parser); + } + +} diff --git a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/RollupIndexCapsTests.java b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/RollupIndexCapsTests.java index 78b1e1e0d2d0c..ef8480bae3bdc 100644 --- a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/RollupIndexCapsTests.java +++ b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/RollupIndexCapsTests.java @@ -9,7 +9,7 @@ import org.elasticsearch.test.ESTestCase; import org.elasticsearch.xpack.core.rollup.ConfigTestHelpers; import org.elasticsearch.xpack.core.rollup.action.RollupJobCaps; -import org.elasticsearch.xpack.core.rollup.job.RollupJobConfig; +import org.elasticsearch.protocol.xpack.rollup.job.RollupJobConfig; import java.util.ArrayList; import java.util.Collections; diff --git a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/SearchActionTests.java b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/SearchActionTests.java index 069e23e4093de..26142f9c83bdf 100644 --- a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/SearchActionTests.java +++ b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/SearchActionTests.java @@ -27,6 +27,8 @@ import org.elasticsearch.index.query.TermQueryBuilder; import org.elasticsearch.index.query.TermsQueryBuilder; import org.elasticsearch.indices.IndicesModule; +import org.elasticsearch.protocol.xpack.rollup.job.MetricConfig; +import org.elasticsearch.protocol.xpack.rollup.job.TermsGroupConfig; import org.elasticsearch.search.DocValueFormat; import org.elasticsearch.search.SearchModule; import org.elasticsearch.search.aggregations.Aggregations; @@ -45,13 +47,11 @@ import org.elasticsearch.search.suggest.SuggestBuilder; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.xpack.core.rollup.ConfigTestHelpers; -import org.elasticsearch.xpack.core.rollup.RollupField; +import org.elasticsearch.protocol.xpack.rollup.RollupField; import org.elasticsearch.xpack.core.rollup.action.RollupJobCaps; -import org.elasticsearch.xpack.core.rollup.job.DateHistogramGroupConfig; -import org.elasticsearch.xpack.core.rollup.job.GroupConfig; -import org.elasticsearch.xpack.core.rollup.job.MetricConfig; -import org.elasticsearch.xpack.core.rollup.job.RollupJobConfig; -import org.elasticsearch.xpack.core.rollup.job.TermsGroupConfig; +import org.elasticsearch.protocol.xpack.rollup.job.DateHistogramGroupConfig; +import org.elasticsearch.protocol.xpack.rollup.job.GroupConfig; +import org.elasticsearch.protocol.xpack.rollup.job.RollupJobConfig; import org.elasticsearch.xpack.rollup.Rollup; import org.hamcrest.core.IsEqual; import org.joda.time.DateTimeZone; @@ -70,8 +70,8 @@ import static java.util.Collections.emptyList; import static java.util.Collections.singleton; +import static org.elasticsearch.protocol.xpack.rollup.RollupField.COUNT_FIELD; import static org.elasticsearch.xpack.core.rollup.ConfigTestHelpers.randomHistogramGroupConfig; -import static org.elasticsearch.xpack.core.rollup.RollupField.COUNT_FIELD; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.instanceOf; import static org.mockito.Mockito.mock; @@ -641,7 +641,7 @@ public void testRollupOnly() throws IOException { InternalSum count = mock(InternalSum.class); when(count.getValue()).thenReturn(2.0); when(count.value()).thenReturn(2.0); - when(count.getName()).thenReturn("foo." + RollupField.COUNT_FIELD); + when(count.getName()).thenReturn("foo." + COUNT_FIELD); when(count.getMetaData()).thenReturn(null); when(count.getType()).thenReturn(SumAggregationBuilder.NAME); subaggs.add(count); @@ -758,7 +758,7 @@ public void testBoth() throws IOException { InternalSum count = mock(InternalSum.class); when(count.getValue()).thenReturn(2.0); when(count.value()).thenReturn(2.0); - when(count.getName()).thenReturn("foo." + RollupField.COUNT_FIELD); + when(count.getName()).thenReturn("foo." + COUNT_FIELD); when(count.getMetaData()).thenReturn(null); when(count.getType()).thenReturn(SumAggregationBuilder.NAME); subaggs.add(count); diff --git a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/TransportTaskHelperTests.java b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/TransportTaskHelperTests.java index a156585b609a7..ca0d66e2a309e 100644 --- a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/TransportTaskHelperTests.java +++ b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/TransportTaskHelperTests.java @@ -9,7 +9,7 @@ import org.elasticsearch.tasks.TaskId; import org.elasticsearch.tasks.TaskManager; import org.elasticsearch.test.ESTestCase; -import org.elasticsearch.xpack.core.rollup.job.RollupJobConfig; +import org.elasticsearch.protocol.xpack.rollup.job.RollupJobConfig; import org.elasticsearch.xpack.rollup.job.RollupJobTask; import java.util.Collections; diff --git a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/config/ConfigTests.java b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/config/ConfigTests.java index 86891eda669fa..8b10273f37289 100644 --- a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/config/ConfigTests.java +++ b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/config/ConfigTests.java @@ -5,14 +5,14 @@ */ package org.elasticsearch.xpack.rollup.config; +import org.elasticsearch.protocol.xpack.rollup.job.HistogramGroupConfig; +import org.elasticsearch.protocol.xpack.rollup.job.MetricConfig; +import org.elasticsearch.protocol.xpack.rollup.job.TermsGroupConfig; import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval; import org.elasticsearch.test.ESTestCase; -import org.elasticsearch.xpack.core.rollup.job.DateHistogramGroupConfig; -import org.elasticsearch.xpack.core.rollup.job.GroupConfig; -import org.elasticsearch.xpack.core.rollup.job.HistogramGroupConfig; -import org.elasticsearch.xpack.core.rollup.job.MetricConfig; +import org.elasticsearch.protocol.xpack.rollup.job.DateHistogramGroupConfig; +import org.elasticsearch.protocol.xpack.rollup.job.GroupConfig; import org.elasticsearch.xpack.core.rollup.job.RollupJob; -import org.elasticsearch.xpack.core.rollup.job.TermsGroupConfig; import org.joda.time.DateTimeZone; import java.util.HashMap; diff --git a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/job/IndexerUtilsTests.java b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/job/IndexerUtilsTests.java index e8c66f7e8c118..0d1a04fda30e3 100644 --- a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/job/IndexerUtilsTests.java +++ b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/job/IndexerUtilsTests.java @@ -35,13 +35,13 @@ import org.elasticsearch.search.aggregations.metrics.avg.AvgAggregationBuilder; import org.elasticsearch.search.aggregations.metrics.max.MaxAggregationBuilder; import org.elasticsearch.search.aggregations.metrics.sum.SumAggregationBuilder; -import org.elasticsearch.xpack.core.rollup.RollupField; -import org.elasticsearch.xpack.core.rollup.job.DateHistogramGroupConfig; -import org.elasticsearch.xpack.core.rollup.job.GroupConfig; -import org.elasticsearch.xpack.core.rollup.job.HistogramGroupConfig; -import org.elasticsearch.xpack.core.rollup.job.MetricConfig; +import org.elasticsearch.protocol.xpack.rollup.RollupField; +import org.elasticsearch.protocol.xpack.rollup.job.DateHistogramGroupConfig; +import org.elasticsearch.protocol.xpack.rollup.job.GroupConfig; +import org.elasticsearch.protocol.xpack.rollup.job.HistogramGroupConfig; +import org.elasticsearch.protocol.xpack.rollup.job.MetricConfig; import org.elasticsearch.xpack.core.rollup.job.RollupJobStats; -import org.elasticsearch.xpack.core.rollup.job.TermsGroupConfig; +import org.elasticsearch.protocol.xpack.rollup.job.TermsGroupConfig; import org.joda.time.DateTime; import org.mockito.stubbing.Answer; diff --git a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/job/RollupIndexerIndexingTests.java b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/job/RollupIndexerIndexingTests.java index 6d29ee9f9ba6d..af37856ea56e5 100644 --- a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/job/RollupIndexerIndexingTests.java +++ b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/job/RollupIndexerIndexingTests.java @@ -48,12 +48,12 @@ import org.elasticsearch.search.aggregations.bucket.composite.CompositeAggregationBuilder; import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval; import org.elasticsearch.xpack.core.rollup.ConfigTestHelpers; -import org.elasticsearch.xpack.core.rollup.job.DateHistogramGroupConfig; -import org.elasticsearch.xpack.core.rollup.job.GroupConfig; +import org.elasticsearch.protocol.xpack.rollup.job.DateHistogramGroupConfig; +import org.elasticsearch.protocol.xpack.rollup.job.GroupConfig; import org.elasticsearch.xpack.core.rollup.job.IndexerState; -import org.elasticsearch.xpack.core.rollup.job.MetricConfig; +import org.elasticsearch.protocol.xpack.rollup.job.MetricConfig; import org.elasticsearch.xpack.core.rollup.job.RollupJob; -import org.elasticsearch.xpack.core.rollup.job.RollupJobConfig; +import org.elasticsearch.protocol.xpack.rollup.job.RollupJobConfig; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; import org.junit.Before; diff --git a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/job/RollupIndexerStateTests.java b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/job/RollupIndexerStateTests.java index 955dcbc2beb48..3a73621d30d48 100644 --- a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/job/RollupIndexerStateTests.java +++ b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/job/RollupIndexerStateTests.java @@ -21,11 +21,11 @@ import org.elasticsearch.search.aggregations.bucket.composite.CompositeAggregation; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.xpack.core.rollup.ConfigTestHelpers; -import org.elasticsearch.xpack.core.rollup.RollupField; -import org.elasticsearch.xpack.core.rollup.job.GroupConfig; +import org.elasticsearch.protocol.xpack.rollup.RollupField; +import org.elasticsearch.protocol.xpack.rollup.job.GroupConfig; import org.elasticsearch.xpack.core.rollup.job.IndexerState; import org.elasticsearch.xpack.core.rollup.job.RollupJob; -import org.elasticsearch.xpack.core.rollup.job.RollupJobConfig; +import org.elasticsearch.protocol.xpack.rollup.job.RollupJobConfig; import org.mockito.stubbing.Answer; import java.io.IOException; diff --git a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/job/RollupJobTaskTests.java b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/job/RollupJobTaskTests.java index 13290f09e8eb8..c892188e30507 100644 --- a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/job/RollupJobTaskTests.java +++ b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/job/RollupJobTaskTests.java @@ -20,7 +20,7 @@ import org.elasticsearch.threadpool.TestThreadPool; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.xpack.core.rollup.ConfigTestHelpers; -import org.elasticsearch.xpack.core.rollup.RollupField; +import org.elasticsearch.protocol.xpack.rollup.RollupField; import org.elasticsearch.xpack.core.rollup.action.StartRollupJobAction; import org.elasticsearch.xpack.core.rollup.action.StopRollupJobAction; import org.elasticsearch.xpack.core.rollup.job.IndexerState; diff --git a/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/PutRollupJobRequest.java b/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/PutRollupJobRequest.java new file mode 100644 index 0000000000000..4527706429f23 --- /dev/null +++ b/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/PutRollupJobRequest.java @@ -0,0 +1,129 @@ +/* + * 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.protocol.xpack.rollup; + +import org.elasticsearch.action.ActionRequestValidationException; +import org.elasticsearch.action.IndicesRequest; +import org.elasticsearch.action.fieldcaps.FieldCapabilities; +import org.elasticsearch.action.support.IndicesOptions; +import org.elasticsearch.action.support.master.AcknowledgedRequest; +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.common.xcontent.ToXContentObject; +import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.protocol.xpack.rollup.job.RollupJobConfig; + +import java.io.IOException; +import java.util.Map; +import java.util.Objects; + +public class PutRollupJobRequest extends AcknowledgedRequest implements IndicesRequest, ToXContentObject { + + private RollupJobConfig config; + private IndicesOptions indicesOptions = IndicesOptions.fromOptions(false, false, true, false); + + public PutRollupJobRequest(final RollupJobConfig config) { + this.config = config; + } + + public PutRollupJobRequest() { + } + + /** + * @return the configuration of the rollup job to create + */ + public RollupJobConfig getConfig() { + return config; + } + + /** + * Sets the configuration of the rollup job to create + * @param config the {@link RollupJobConfig} + */ + public void setConfig(final RollupJobConfig config) { + this.config = config; + } + + @Override + public void readFrom(StreamInput in) throws IOException { + super.readFrom(in); + this.config = new RollupJobConfig(in); + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); + this.config.writeTo(out); + } + + @Override + public ActionRequestValidationException validate() { + return null; + } + + public ActionRequestValidationException validateMappings(final Map> fieldCapsResponse) { + final ActionRequestValidationException validationException = new ActionRequestValidationException(); + if (fieldCapsResponse.size() == 0) { + validationException.addValidationError("Could not find any fields in the index/index-pattern that were configured in job"); + return validationException; + } + config.validateMappings(fieldCapsResponse, validationException); + if (validationException.validationErrors().size() > 0) { + return validationException; + } + return null; + } + + @Override + public XContentBuilder toXContent(final XContentBuilder builder, final Params params) throws IOException { + return config.toXContent(builder, params); + } + + @Override + public String[] indices() { + return new String[]{this.config.getIndexPattern()}; + } + + @Override + public IndicesOptions indicesOptions() { + return indicesOptions; + } + + @Override + public int hashCode() { + return Objects.hash(config, indicesOptions, timeout); + } + + @Override + public boolean equals(final Object obj) { + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final PutRollupJobRequest other = (PutRollupJobRequest) obj; + return Objects.equals(config, other.config); + } + + public static PutRollupJobRequest fromXContent(final XContentParser parser, final String id) throws IOException { + return new PutRollupJobRequest(RollupJobConfig.fromXContent(parser, id)); + } +} diff --git a/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/PutRollupJobResponse.java b/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/PutRollupJobResponse.java new file mode 100644 index 0000000000000..a298cb20919c4 --- /dev/null +++ b/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/PutRollupJobResponse.java @@ -0,0 +1,37 @@ +/* + * 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.protocol.xpack.rollup; + +import org.elasticsearch.action.support.master.AcknowledgedResponse; +import org.elasticsearch.common.xcontent.XContentParser; + +public class PutRollupJobResponse extends AcknowledgedResponse { + + public PutRollupJobResponse() { + super(); + } + + public PutRollupJobResponse(final boolean acknowledged) { + super(acknowledged); + } + + public static PutRollupJobResponse fromXContent(final XContentParser parser) { + return new PutRollupJobResponse(parseAcknowledged(parser)); + } +} diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/RollupField.java b/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/RollupField.java similarity index 98% rename from x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/RollupField.java rename to x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/RollupField.java index 134ce6c87b3f7..3affd8394c121 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/RollupField.java +++ b/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/RollupField.java @@ -3,7 +3,7 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.xpack.core.rollup; +package org.elasticsearch.protocol.xpack.rollup; import org.elasticsearch.common.ParseField; import org.elasticsearch.index.mapper.NumberFieldMapper; @@ -54,7 +54,7 @@ public class RollupField { * @param extra The type of value this field is (VALUE, INTERVAL, etc) * @return formatted field name */ - public static String formatFieldName(ValuesSourceAggregationBuilder source, String extra) { + public static String formatFieldName(ValuesSourceAggregationBuilder source, String extra) { return source.field() + "." + source.getType() + "." + extra; } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/job/DateHistogramGroupConfig.java b/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/job/DateHistogramGroupConfig.java similarity index 92% rename from x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/job/DateHistogramGroupConfig.java rename to x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/job/DateHistogramGroupConfig.java index 77dfa1cbbb1c3..08dfb07e26dfb 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/job/DateHistogramGroupConfig.java +++ b/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/job/DateHistogramGroupConfig.java @@ -1,9 +1,22 @@ /* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. + * 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.xpack.core.rollup.job; +package org.elasticsearch.protocol.xpack.rollup.job; import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.action.fieldcaps.FieldCapabilities; @@ -20,11 +33,11 @@ import org.elasticsearch.common.xcontent.ToXContentObject; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.protocol.xpack.rollup.RollupField; import org.elasticsearch.search.aggregations.bucket.composite.CompositeValuesSourceBuilder; import org.elasticsearch.search.aggregations.bucket.composite.DateHistogramValuesSourceBuilder; import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramAggregationBuilder; import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval; -import org.elasticsearch.xpack.core.rollup.RollupField; import org.joda.time.DateTimeZone; import java.io.IOException; @@ -119,7 +132,7 @@ public DateHistogramGroupConfig(final String field, } } - DateHistogramGroupConfig(final StreamInput in) throws IOException { + public DateHistogramGroupConfig(final StreamInput in) throws IOException { interval = new DateHistogramInterval(in); field = in.readString(); delay = in.readOptionalWriteable(DateHistogramInterval::new); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/job/GroupConfig.java b/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/job/GroupConfig.java similarity index 87% rename from x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/job/GroupConfig.java rename to x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/job/GroupConfig.java index f7685f4e6143b..df267f8f89d96 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/job/GroupConfig.java +++ b/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/job/GroupConfig.java @@ -1,9 +1,22 @@ /* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. + * 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.xpack.core.rollup.job; +package org.elasticsearch.protocol.xpack.rollup.job; import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.action.fieldcaps.FieldCapabilities; @@ -75,7 +88,7 @@ public GroupConfig(final DateHistogramGroupConfig dateHistogram, this.terms = terms; } - GroupConfig(final StreamInput in) throws IOException { + public GroupConfig(final StreamInput in) throws IOException { dateHistogram = new DateHistogramGroupConfig(in); histogram = in.readOptionalWriteable(HistogramGroupConfig::new); terms = in.readOptionalWriteable(TermsGroupConfig::new); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/job/HistogramGroupConfig.java b/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/job/HistogramGroupConfig.java similarity index 87% rename from x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/job/HistogramGroupConfig.java rename to x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/job/HistogramGroupConfig.java index 0480050bf52f0..9d76b2bd52e04 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/job/HistogramGroupConfig.java +++ b/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/job/HistogramGroupConfig.java @@ -1,9 +1,22 @@ /* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. + * 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.xpack.core.rollup.job; +package org.elasticsearch.protocol.xpack.rollup.job; import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.action.fieldcaps.FieldCapabilities; @@ -16,10 +29,10 @@ import org.elasticsearch.common.xcontent.ToXContentObject; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.protocol.xpack.rollup.RollupField; import org.elasticsearch.search.aggregations.bucket.composite.CompositeValuesSourceBuilder; import org.elasticsearch.search.aggregations.bucket.composite.HistogramValuesSourceBuilder; import org.elasticsearch.search.aggregations.bucket.histogram.HistogramAggregationBuilder; -import org.elasticsearch.xpack.core.rollup.RollupField; import java.io.IOException; import java.util.Arrays; @@ -73,7 +86,7 @@ public HistogramGroupConfig(final long interval, final String... fields) { this.fields = fields; } - HistogramGroupConfig(final StreamInput in) throws IOException { + public HistogramGroupConfig(final StreamInput in) throws IOException { interval = in.readVLong(); fields = in.readStringArray(); } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/job/MetricConfig.java b/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/job/MetricConfig.java similarity index 87% rename from x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/job/MetricConfig.java rename to x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/job/MetricConfig.java index cc673c4ed0d35..c5790b267d86d 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/job/MetricConfig.java +++ b/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/job/MetricConfig.java @@ -1,9 +1,22 @@ /* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. + * 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.xpack.core.rollup.job; +package org.elasticsearch.protocol.xpack.rollup.job; import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.action.fieldcaps.FieldCapabilities; @@ -16,6 +29,7 @@ import org.elasticsearch.common.xcontent.ToXContentObject; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.protocol.xpack.rollup.RollupField; import org.elasticsearch.search.aggregations.metrics.avg.AvgAggregationBuilder; import org.elasticsearch.search.aggregations.metrics.max.MaxAggregationBuilder; import org.elasticsearch.search.aggregations.metrics.min.MinAggregationBuilder; @@ -23,7 +37,6 @@ import org.elasticsearch.search.aggregations.metrics.valuecount.ValueCountAggregationBuilder; import org.elasticsearch.search.aggregations.support.ValueType; import org.elasticsearch.search.aggregations.support.ValuesSourceAggregationBuilder; -import org.elasticsearch.xpack.core.rollup.RollupField; import java.io.IOException; import java.util.ArrayList; @@ -93,7 +106,7 @@ public MetricConfig(final String field, final List metrics) { this.metrics = metrics; } - MetricConfig(final StreamInput in) throws IOException { + public MetricConfig(final StreamInput in) throws IOException { field = in.readString(); metrics = in.readList(StreamInput::readString); } @@ -116,14 +129,14 @@ public List getMetrics() { * This returns a set of aggregation builders which represent the configured * set of metrics. Used by the rollup indexer to iterate over historical data */ - public List toBuilders() { + public List> toBuilders() { if (metrics.size() == 0) { return Collections.emptyList(); } - List aggs = new ArrayList<>(metrics.size()); + List> aggs = new ArrayList<>(metrics.size()); for (String metric : metrics) { - ValuesSourceAggregationBuilder.LeafOnly newBuilder; + ValuesSourceAggregationBuilder.LeafOnly newBuilder; if (metric.equals(MIN.getPreferredName())) { newBuilder = new MinAggregationBuilder(RollupField.formatFieldName(field, MinAggregationBuilder.NAME, RollupField.VALUE)); } else if (metric.equals(MAX.getPreferredName())) { @@ -131,7 +144,7 @@ public List toBuilders() { } else if (metric.equals(AVG.getPreferredName())) { // Avgs are sum + count newBuilder = new SumAggregationBuilder(RollupField.formatFieldName(field, AvgAggregationBuilder.NAME, RollupField.VALUE)); - ValuesSourceAggregationBuilder.LeafOnly countBuilder + ValuesSourceAggregationBuilder.LeafOnly countBuilder = new ValueCountAggregationBuilder( RollupField.formatFieldName(field, AvgAggregationBuilder.NAME, RollupField.COUNT_FIELD), ValueType.NUMERIC); countBuilder.field(field); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/job/RollupJobConfig.java b/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/job/RollupJobConfig.java similarity index 92% rename from x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/job/RollupJobConfig.java rename to x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/job/RollupJobConfig.java index 27461c62b6724..0758b62ce7eea 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/job/RollupJobConfig.java +++ b/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/job/RollupJobConfig.java @@ -1,9 +1,22 @@ /* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. + * 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.xpack.core.rollup.job; +package org.elasticsearch.protocol.xpack.rollup.job; import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.action.fieldcaps.FieldCapabilities; @@ -20,7 +33,6 @@ import org.elasticsearch.common.xcontent.ToXContentObject; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.xpack.core.scheduler.Cron; import java.io.IOException; import java.util.Collections; @@ -119,7 +131,7 @@ public RollupJobConfig(final String id, // Cron doesn't have a parse helper method to see if the cron is valid, // so just construct a temporary cron object and if the cron is bad, it'll // throw an exception - Cron testCron = new Cron(cron); + //Cron testCron = new Cron(cron); if (groupConfig == null && (metricsConfig == null || metricsConfig.isEmpty())) { throw new IllegalArgumentException("At least one grouping or metric must be configured"); } @@ -222,7 +234,7 @@ public XContentBuilder toXContent(final XContentBuilder builder, final Params pa builder.endArray(); } if (timeout != null) { - builder.field(TIMEOUT, timeout); + builder.field(TIMEOUT, timeout.getStringRep()); } builder.field(PAGE_SIZE, pageSize); } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/job/TermsGroupConfig.java b/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/job/TermsGroupConfig.java similarity index 86% rename from x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/job/TermsGroupConfig.java rename to x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/job/TermsGroupConfig.java index 32507d57f32b0..9ac640a087566 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/job/TermsGroupConfig.java +++ b/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/job/TermsGroupConfig.java @@ -1,9 +1,22 @@ /* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. + * 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.xpack.core.rollup.job; +package org.elasticsearch.protocol.xpack.rollup.job; import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.action.fieldcaps.FieldCapabilities; @@ -18,10 +31,10 @@ import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.mapper.KeywordFieldMapper; import org.elasticsearch.index.mapper.TextFieldMapper; +import org.elasticsearch.protocol.xpack.rollup.RollupField; import org.elasticsearch.search.aggregations.bucket.composite.CompositeValuesSourceBuilder; import org.elasticsearch.search.aggregations.bucket.composite.TermsValuesSourceBuilder; import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder; -import org.elasticsearch.xpack.core.rollup.RollupField; import java.io.IOException; import java.util.Arrays; @@ -69,7 +82,7 @@ public TermsGroupConfig(final String... fields) { this.fields = fields; } - TermsGroupConfig(StreamInput in) throws IOException { + public TermsGroupConfig(StreamInput in) throws IOException { fields = in.readStringArray(); } @@ -87,7 +100,7 @@ public String[] getFields() { public List> toBuilders() { return Arrays.stream(fields).map(f -> { TermsValuesSourceBuilder vsBuilder - = new TermsValuesSourceBuilder(RollupField.formatIndexerAggName(f, TermsAggregationBuilder.NAME)); + = new TermsValuesSourceBuilder(RollupField.formatIndexerAggName(f, TermsAggregationBuilder.NAME)); vsBuilder.field(f); vsBuilder.missingBucket(true); return vsBuilder; diff --git a/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/package-info.java b/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/package-info.java new file mode 100644 index 0000000000000..e3c42fa876b25 --- /dev/null +++ b/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/package-info.java @@ -0,0 +1,24 @@ +/* + * 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. + */ + +/** + * Request and Response objects for the default distribution's Rollup + * APIs. + */ +package org.elasticsearch.protocol.xpack.rollup; From 7667ed92a3f90a3d978f038deec51f1f3290248b Mon Sep 17 00:00:00 2001 From: Tanguy Leroux Date: Tue, 7 Aug 2018 13:18:25 +0200 Subject: [PATCH 02/13] Fix license --- .../protocol/xpack/rollup/RollupField.java | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/RollupField.java b/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/RollupField.java index 3affd8394c121..5f1958c7d6f02 100644 --- a/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/RollupField.java +++ b/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/RollupField.java @@ -1,7 +1,20 @@ /* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. + * 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.protocol.xpack.rollup; From 2f340ddeadfd39d6df5eac708f9faf7edae90887 Mon Sep 17 00:00:00 2001 From: Tanguy Leroux Date: Mon, 13 Aug 2018 20:12:55 +0200 Subject: [PATCH 03/13] Add Cron validation --- .../org/elasticsearch/client/RollupIT.java | 4 ++-- .../core/rollup/job/RollupJobConfigTests.java | 9 ------- .../action/TransportPutRollupJobAction.java | 9 +++++++ .../TransportPutRollupJobActionTests.java | 24 +++++++++++++++++++ .../xpack/rollup/job/RollupJobConfig.java | 4 ---- 5 files changed, 35 insertions(+), 15 deletions(-) create mode 100644 x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/TransportPutRollupJobActionTests.java 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 3a2eef67046c6..17995eba2ce49 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 @@ -108,8 +108,8 @@ public void testPutRollupJob() throws Exception { final List metrics = Collections.singletonList(new MetricConfig("value", SUPPORTED_METRICS)); final TimeValue timeout = TimeValue.timeValueSeconds(randomIntBetween(30, 600)); - PutRollupJobRequest putRollupJobRequest = new PutRollupJobRequest(); - putRollupJobRequest.setConfig(new RollupJobConfig(id, indexPattern, rollupIndex, cron, pageSize, groups, metrics, timeout)); + 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); diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/rollup/job/RollupJobConfigTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/rollup/job/RollupJobConfigTests.java index 7773fd70cb39b..6086132fd03c0 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/rollup/job/RollupJobConfigTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/rollup/job/RollupJobConfigTests.java @@ -88,15 +88,6 @@ public void testEmptyID() { assertThat(e.getMessage(), equalTo("Id must be a non-null, non-empty string")); } - public void testBadCron() { - final RollupJobConfig sample = randomRollupJobConfig(random()); - - Exception e = expectThrows(IllegalArgumentException.class, () -> - new RollupJobConfig(sample.getId(), sample.getIndexPattern(), sample.getRollupIndex(), "0 * * *", sample.getPageSize(), - sample.getGroupConfig(), sample.getMetricsConfig(), sample.getTimeout())); - assertThat(e.getMessage(), equalTo("invalid cron expression [0 * * *]")); - } - public void testMatchAllIndexPattern() { final RollupJobConfig sample = randomRollupJobConfig(random()); diff --git a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportPutRollupJobAction.java b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportPutRollupJobAction.java index 77410d5e611e7..1592f9b538adf 100644 --- a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportPutRollupJobAction.java +++ b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportPutRollupJobAction.java @@ -49,6 +49,7 @@ import org.elasticsearch.xpack.core.XPackPlugin; import org.elasticsearch.xpack.core.rollup.action.PutRollupJobAction; import org.elasticsearch.xpack.core.rollup.job.RollupJob; +import org.elasticsearch.xpack.core.scheduler.Cron; import org.elasticsearch.xpack.rollup.Rollup; import java.util.Map; @@ -91,6 +92,7 @@ protected void masterOperation(PutRollupJobRequest request, ClusterState cluster return; } + validate(request); XPackPlugin.checkReadyForXPackCustomMetadata(clusterState); FieldCapabilitiesRequest fieldCapsRequest = new FieldCapabilitiesRequest() @@ -117,6 +119,13 @@ public void onFailure(Exception e) { }); } + static void validate(final PutRollupJobRequest request) { + final RollupJobConfig rollupJobConfig = request.getConfig(); + if (rollupJobConfig != null) { + Cron.validate(rollupJobConfig.getCron()); + } + } + private static RollupJob createRollupJob(RollupJobConfig config, ThreadPool threadPool) { // ensure we only filter for the allowed headers Map filteredHeaders = threadPool.getThreadContext().getHeaders().entrySet().stream() diff --git a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/TransportPutRollupJobActionTests.java b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/TransportPutRollupJobActionTests.java new file mode 100644 index 0000000000000..53aa0f2e63eee --- /dev/null +++ b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/TransportPutRollupJobActionTests.java @@ -0,0 +1,24 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ +package org.elasticsearch.xpack.rollup.action; + +import org.elasticsearch.protocol.xpack.rollup.PutRollupJobRequest; +import org.elasticsearch.protocol.xpack.rollup.job.RollupJobConfig; +import org.elasticsearch.test.ESTestCase; + +import static org.elasticsearch.xpack.core.rollup.ConfigTestHelpers.randomGroupConfig; +import static org.hamcrest.Matchers.equalTo; + +public class TransportPutRollupJobActionTests extends ESTestCase { + + public void testBadCron() { + final PutRollupJobRequest putRollupJobRequest = + new PutRollupJobRequest(new RollupJobConfig("_id", "index", "rollup", "0 * * *", 100, randomGroupConfig(random()), null, null)); + + Exception e = expectThrows(IllegalArgumentException.class, () -> TransportPutRollupJobAction.validate(putRollupJobRequest)); + assertThat(e.getMessage(), equalTo("invalid cron expression [0 * * *]")); + } +} diff --git a/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/job/RollupJobConfig.java b/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/job/RollupJobConfig.java index 0758b62ce7eea..20669533189e9 100644 --- a/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/job/RollupJobConfig.java +++ b/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/job/RollupJobConfig.java @@ -128,10 +128,6 @@ public RollupJobConfig(final String id, if (pageSize <= 0) { throw new IllegalArgumentException("Page size is mandatory and must be a positive long"); } - // Cron doesn't have a parse helper method to see if the cron is valid, - // so just construct a temporary cron object and if the cron is bad, it'll - // throw an exception - //Cron testCron = new Cron(cron); if (groupConfig == null && (metricsConfig == null || metricsConfig.isEmpty())) { throw new IllegalArgumentException("At least one grouping or metric must be configured"); } From 310e690e7b3c53a4779efa240cf8d0160994574f Mon Sep 17 00:00:00 2001 From: Zachary Tong Date: Mon, 13 Aug 2018 16:38:57 -0400 Subject: [PATCH 04/13] Add GetRollupCaps API to the High Level Rest Client Related #29827 --- .../client/RequestConverters.java | 13 ++ .../elasticsearch/client/RollupClient.java | 30 ++++ .../org/elasticsearch/client/RollupIT.java | 118 ++++++++++++++ .../documentation/RollupDocumentationIT.java | 116 ++++++++++++++ .../high-level/supported-apis.asciidoc | 1 + .../x-pack/rollup/get_rollup_caps.asciidoc | 77 +++++++++ .../rollup/action/GetRollupCapsAction.java | 147 +----------------- .../action/GetRollupIndexCapsAction.java | 1 + .../rollup/RollupJobIdentifierUtils.java | 6 +- .../xpack/rollup/action/RollupIndexCaps.java | 4 +- .../action/TransportGetRollupCapsAction.java | 33 ++-- .../TransportGetRollupIndexCapsAction.java | 20 ++- .../action/TransportRollupSearchAction.java | 2 +- .../rollup/rest/RestGetRollupCapsAction.java | 3 +- .../rollup/RollupJobIdentifierUtilTests.java | 2 +- ...ts.java => GetRollupCapsRequestTests.java} | 20 +-- .../action/GetRollupCapsResponseTests.java | 63 ++++++++ .../GetRollupIndexCapsActionRequestTests.java | 2 +- .../rollup/action/RollupIndexCapsTests.java | 2 +- .../rollup/action/SearchActionTests.java | 2 +- .../xpack/rollup/GetRollupCapsRequest.java | 89 +++++++++++ .../xpack/rollup/GetRollupCapsResponse.java | 109 +++++++++++++ .../xpack/rollup}/RollableIndexCaps.java | 53 +++++-- .../protocol/xpack/rollup}/RollupJobCaps.java | 146 ++++++++++++----- 24 files changed, 823 insertions(+), 236 deletions(-) create mode 100644 docs/java-rest/high-level/x-pack/rollup/get_rollup_caps.asciidoc rename x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/{GetRollupCapsActionRequestTests.java => GetRollupCapsRequestTests.java} (94%) create mode 100644 x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/GetRollupCapsResponseTests.java create mode 100644 x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/GetRollupCapsRequest.java create mode 100644 x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/GetRollupCapsResponse.java rename x-pack/{plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action => protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup}/RollableIndexCaps.java (51%) rename x-pack/{plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action => protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup}/RollupJobCaps.java (50%) diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/RequestConverters.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/RequestConverters.java index c945b37ba561c..89776c32a008d 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/RequestConverters.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/RequestConverters.java @@ -112,6 +112,7 @@ import org.elasticsearch.protocol.xpack.license.PutLicenseRequest; import org.elasticsearch.protocol.xpack.migration.IndexUpgradeInfoRequest; import org.elasticsearch.protocol.xpack.ml.PutJobRequest; +import org.elasticsearch.protocol.xpack.rollup.GetRollupCapsRequest; import org.elasticsearch.protocol.xpack.rollup.PutRollupJobRequest; import org.elasticsearch.protocol.xpack.watcher.DeleteWatchRequest; import org.elasticsearch.protocol.xpack.watcher.PutWatchRequest; @@ -1226,6 +1227,18 @@ static Request putRollupJob(PutRollupJobRequest putRollupJobRequest) throws IOEx return request; } + static Request getRollupCaps(GetRollupCapsRequest getRollupCapsRequest) throws IOException { + String endpoint = new EndpointBuilder() + .addPathPartAsIs("_xpack") + .addPathPartAsIs("rollup") + .addPathPartAsIs("data") + .addPathPart(getRollupCapsRequest.getIndexPattern()) + .build(); + Request request = new Request(HttpGet.METHOD_NAME, endpoint); + request.setEntity(createEntity(getRollupCapsRequest, REQUEST_BODY_CONTENT_TYPE)); + return request; + } + private static HttpEntity createEntity(ToXContent toXContent, XContentType xContentType) throws IOException { BytesRef source = XContentHelper.toXContent(toXContent, xContentType, false).toBytesRef(); return new ByteArrayEntity(source.bytes, source.offset, source.length, createContentType(xContentType)); 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 992a52811d98b..cce339b5b5a49 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.protocol.xpack.rollup.GetRollupCapsRequest; +import org.elasticsearch.protocol.xpack.rollup.GetRollupCapsResponse; import org.elasticsearch.protocol.xpack.rollup.PutRollupJobRequest; import org.elasticsearch.protocol.xpack.rollup.PutRollupJobResponse; @@ -68,4 +70,32 @@ public void putRollupJobAsync(PutRollupJobRequest request, RequestOptions option restHighLevelClient.performRequestAsyncAndParseEntity(request, RequestConverters::putRollupJob, options, PutRollupJobResponse::fromXContent, listener, emptySet()); } + + /** + * Get the Rollup Capabilities of a target (non-rollup) index or pattern + * 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 GetRollupCapsResponse getRollupCapabilities(GetRollupCapsRequest request, RequestOptions options) throws IOException { + return restHighLevelClient.performRequestAndParseEntity(request, RequestConverters::getRollupCaps, options, + GetRollupCapsResponse::fromXContent, emptySet()); + } + + /** + * Asynchronously put a rollup job into 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 + * @param listener the listener to be notified upon request completion + */ + public void getRollupCapabilitiesAsync(GetRollupCapsRequest request, RequestOptions options, + ActionListener listener) { + restHighLevelClient.performRequestAsyncAndParseEntity(request, RequestConverters::getRollupCaps, options, + GetRollupCapsResponse::fromXContent, listener, emptySet()); + } } 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 17995eba2ce49..79d6ccf5c422d 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.action.admin.cluster.health.ClusterHealthRequest; import org.elasticsearch.action.admin.indices.refresh.RefreshRequest; import org.elasticsearch.action.admin.indices.refresh.RefreshResponse; import org.elasticsearch.action.bulk.BulkItemResponse; @@ -28,8 +29,12 @@ import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.support.WriteRequest; import org.elasticsearch.common.unit.TimeValue; +import org.elasticsearch.protocol.xpack.rollup.GetRollupCapsRequest; +import org.elasticsearch.protocol.xpack.rollup.GetRollupCapsResponse; import org.elasticsearch.protocol.xpack.rollup.PutRollupJobRequest; import org.elasticsearch.protocol.xpack.rollup.PutRollupJobResponse; +import org.elasticsearch.protocol.xpack.rollup.RollableIndexCaps; +import org.elasticsearch.protocol.xpack.rollup.RollupJobCaps; import org.elasticsearch.protocol.xpack.rollup.job.DateHistogramGroupConfig; import org.elasticsearch.protocol.xpack.rollup.job.GroupConfig; import org.elasticsearch.protocol.xpack.rollup.job.MetricConfig; @@ -47,6 +52,7 @@ import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; import static org.elasticsearch.protocol.xpack.rollup.RollupField.SUPPORTED_METRICS; +import static org.hamcrest.Matchers.equalTo; public class RollupIT extends ESRestHighLevelClientTestCase { @@ -155,4 +161,116 @@ public void testPutRollupJob() throws Exception { } }); } + + public void testGetRollupCaps() throws Exception { + final Set values = new HashSet<>(); + double sum = 0.0d; + int max = Integer.MIN_VALUE; + int min = Integer.MAX_VALUE; + + final BulkRequest bulkRequest = new BulkRequest(); + bulkRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE); + for (int minute = 0; minute < 60; minute++) { + for (int second = 0; second < 60; second = second + 10) { + final int value = randomIntBetween(0, 100); + + final IndexRequest indexRequest = new IndexRequest("docs", "doc"); + indexRequest.source(jsonBuilder() + .startObject() + .field("value", value) + .field("date", String.format(Locale.ROOT, "2018-01-01T00:%02d:%02dZ", minute, second)) + .endObject()); + bulkRequest.add(indexRequest); + + values.add(value); + sum += value; + if (value > max) { + max = value; + } + if (value < min) { + min = value; + } + } + } + + final int numDocs = bulkRequest.numberOfActions(); + + BulkResponse bulkResponse = highLevelClient().bulk(bulkRequest, RequestOptions.DEFAULT); + assertEquals(RestStatus.OK, bulkResponse.status()); + if (bulkResponse.hasFailures()) { + for (BulkItemResponse itemResponse : bulkResponse.getItems()) { + if (itemResponse.isFailed()) { + logger.fatal(itemResponse.getFailureMessage()); + } + } + } + assertFalse(bulkResponse.hasFailures()); + + RefreshResponse refreshResponse = highLevelClient().indices().refresh(new RefreshRequest("docs"), RequestOptions.DEFAULT); + assertEquals(0, refreshResponse.getFailedShards()); + + 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); + // 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)); + 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); + assertTrue(response.isAcknowledged()); + + // wait for the PutJob api to create the index w/ metadata + highLevelClient().cluster().health(new ClusterHealthRequest(rollupIndex).waitForYellowStatus(), RequestOptions.DEFAULT); + + GetRollupCapsRequest getRollupCapsRequest = new GetRollupCapsRequest(indexPattern); + GetRollupCapsResponse capsResponse = highLevelClient().rollup() + .getRollupCapabilities(getRollupCapsRequest, RequestOptions.DEFAULT); + + assertNotNull(capsResponse); + Map rolledPatterns = capsResponse.getJobs(); + assertThat(rolledPatterns.size(), equalTo(1)); + + RollableIndexCaps docsPattern = rolledPatterns.get(indexPattern); + assertThat(docsPattern.getIndexName(), equalTo(indexPattern)); + + List rollupJobs = docsPattern.getJobCaps(); + assertThat(rollupJobs.size(), equalTo(1)); + + RollupJobCaps jobCaps = rollupJobs.get(0); + assertThat(jobCaps.getJobID(), equalTo(id)); + assertThat(jobCaps.getRollupIndex(), equalTo(rollupIndex)); + assertThat(jobCaps.getIndexPattern(), equalTo(indexPattern)); + + Map fieldCaps = jobCaps.getFieldCaps(); + + List> timestampCaps = fieldCaps.get("date").getAggs(); + for (Map.Entry entry : timestampCaps.get(0).entrySet()) { + switch (entry.getKey()) { + case "agg": + assertThat(entry.getValue(), equalTo("date_histogram")); + break; + case "delay": + assertThat(entry.getValue(), equalTo("foo")); + break; + case "interval": + assertThat(entry.getValue(), equalTo("1d")); + break; + case "time_zone": + assertThat(entry.getValue(), equalTo("UTC")); + break; + default: + fail("Unknown field cap: [" + entry.getKey() + "]"); + } + } + + List> valueCaps = fieldCaps.get("value").getAggs(); + assertThat(valueCaps.size(), equalTo(SUPPORTED_METRICS.size())); + } } 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 080a52810a260..4f00d52bf181e 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 @@ -30,8 +30,12 @@ import org.elasticsearch.client.RequestOptions; import org.elasticsearch.client.RestHighLevelClient; import org.elasticsearch.common.unit.TimeValue; +import org.elasticsearch.protocol.xpack.rollup.GetRollupCapsRequest; +import org.elasticsearch.protocol.xpack.rollup.GetRollupCapsResponse; import org.elasticsearch.protocol.xpack.rollup.PutRollupJobRequest; import org.elasticsearch.protocol.xpack.rollup.PutRollupJobResponse; +import org.elasticsearch.protocol.xpack.rollup.RollableIndexCaps; +import org.elasticsearch.protocol.xpack.rollup.RollupJobCaps; import org.elasticsearch.protocol.xpack.rollup.job.DateHistogramGroupConfig; import org.elasticsearch.protocol.xpack.rollup.job.GroupConfig; import org.elasticsearch.protocol.xpack.rollup.job.HistogramGroupConfig; @@ -47,10 +51,12 @@ import java.util.Arrays; import java.util.List; import java.util.Locale; +import java.util.Map; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; +import static org.hamcrest.Matchers.equalTo; public class RollupDocumentationIT extends ESRestHighLevelClientTestCase { @@ -160,4 +166,114 @@ public void onFailure(Exception e) { assertTrue(latch.await(30L, TimeUnit.SECONDS)); } } + + public void testGetRollupCaps() throws Exception { + RestHighLevelClient client = highLevelClient(); + + + DateHistogramGroupConfig dateHistogram = + new DateHistogramGroupConfig("timestamp", DateHistogramInterval.HOUR, new DateHistogramInterval("7d"), "UTC"); // <1> + TermsGroupConfig terms = new TermsGroupConfig("hostname", "datacenter"); + HistogramGroupConfig histogram = new HistogramGroupConfig(5L, "load", "net_in", "net_out"); + GroupConfig groups = new GroupConfig(dateHistogram, histogram, terms); + List metrics = new ArrayList<>(); // <1> + metrics.add(new MetricConfig("temperature", Arrays.asList("min", "max", "sum"))); + metrics.add(new MetricConfig("voltage", Arrays.asList("avg", "value_count"))); + + //tag::x-pack-rollup-get-rollup-caps-setup + final String indexPattern = "docs"; + final String rollupIndexName = "rollup"; + final String cron = "*/1 * * * * ?"; + final int pageSize = 100; + final TimeValue timeout = null; + + String id = "job_1"; + RollupJobConfig config = new RollupJobConfig(id, indexPattern, rollupIndexName, cron, + pageSize, groups, metrics, timeout); + + PutRollupJobRequest request = new PutRollupJobRequest(config); + PutRollupJobResponse response = client.rollup().putRollupJob(request, RequestOptions.DEFAULT); + + boolean acknowledged = response.isAcknowledged(); + //end::x-pack-rollup-get-rollup-caps-setup + assertTrue(acknowledged); + + // Now that the job is created, we should have a rollup index with metadata. + // We can test out the caps API now. + + //tag::x-pack-rollup-get-rollup-caps-request + GetRollupCapsRequest getRollupCapsRequest = new GetRollupCapsRequest("docs"); + //end::x-pack-rollup-get-rollup-caps-request + + //tag::x-pack-rollup-get-rollup-caps-execute + GetRollupCapsResponse capsResponse = client.rollup().getRollupCapabilities(getRollupCapsRequest, RequestOptions.DEFAULT); + //end::x-pack-rollup-get-rollup-caps-execute + + //tag::x-pack-rollup-get-rollup-caps-response + Map rolledPatterns = capsResponse.getJobs(); + + RollableIndexCaps docsPattern = rolledPatterns.get("docs"); + + // indexName will be "docs" in this case... the index pattern that we rolled up + String indexName = docsPattern.getIndexName(); + + // Each index pattern can have multiple jobs that rolled it up, so `getJobCaps()` + // returns a list of jobs that rolled up the pattern + List rollupJobs = docsPattern.getJobCaps(); + RollupJobCaps jobCaps = rollupJobs.get(0); + + // jobID is the identifier we used when we created the job (e.g. `job1`) + String jobID = jobCaps.getJobID(); + + // rollupIndex is the location that the job stored it's rollup docs (e.g. `rollup`) + String rollupIndex = jobCaps.getRollupIndex(); + + // indexPattern is the same as the indexName that we retrieved earlier, redundant info + assert jobCaps.getIndexPattern().equals(indexName); + + // Finally, fieldCaps are the capabilities of individual fields in the config + // The key is the field name, and the value is a RollupFieldCaps object which + // provides more info. + Map fieldCaps = jobCaps.getFieldCaps(); + + // If we retrieve the "timestamp" field, it returns a list of maps. Each list + // item represents a different aggregation that can be run against the "timestamp" + // field, and any additional details specific to that agg (interval, etc) + List> timestampCaps = fieldCaps.get("timestamp").getAggs(); + assert timestampCaps.get(0).toString().equals("{agg=date_histogram, delay=7d, interval=1h, time_zone=UTC}"); + + // In contrast to the timestamp field, the temperature field has multiple aggs configured + List> temperatureCaps = fieldCaps.get("temperature").getAggs(); + assert temperatureCaps.toString().equals("[{agg=min}, {agg=max}, {agg=sum}]"); + //end::x-pack-rollup-get-rollup-caps-response + + assertThat(indexName, equalTo("docs")); + assertThat(jobID, equalTo("job_1")); + assertThat(rollupIndex, equalTo("rollup")); + assertThat(fieldCaps.size(), equalTo(8)); + + // tag::x-pack-rollup-get-rollup-caps-execute-listener + ActionListener listener = new ActionListener() { + @Override + public void onResponse(GetRollupCapsResponse response) { + // <1> + } + + @Override + public void onFailure(Exception e) { + // <2> + } + }; + // end::x-pack-rollup-get-rollup-caps-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-get-rollup-caps-execute-async + client.rollup().getRollupCapabilitiesAsync(getRollupCapsRequest, RequestOptions.DEFAULT, listener); // <1> + // end::x-pack-rollup-get-rollup-caps-execute-async + + assertTrue(latch.await(30L, TimeUnit.SECONDS)); + } } diff --git a/docs/java-rest/high-level/supported-apis.asciidoc b/docs/java-rest/high-level/supported-apis.asciidoc index 3249077fae20a..c0dd4605871a1 100644 --- a/docs/java-rest/high-level/supported-apis.asciidoc +++ b/docs/java-rest/high-level/supported-apis.asciidoc @@ -224,3 +224,4 @@ The Java High Level REST Client supports the following Rollup APIs: * <> include::x-pack/rollup/put_job.asciidoc[] +include::x-pack/rollup/get_rollup_caps.asciidoc[] \ No newline at end of file diff --git a/docs/java-rest/high-level/x-pack/rollup/get_rollup_caps.asciidoc b/docs/java-rest/high-level/x-pack/rollup/get_rollup_caps.asciidoc new file mode 100644 index 0000000000000..bb8b0d3c3a16f --- /dev/null +++ b/docs/java-rest/high-level/x-pack/rollup/get_rollup_caps.asciidoc @@ -0,0 +1,77 @@ +[[java-rest-high-x-pack-rollup-get-rollup-caps]] +=== Get Rollup Capabilities Rollup Job API + +The Get Rollup Capabilities API allows the user to query a target index pattern (`logstash-*`, etc) +and determine if there are any rollup jobs that are/were configured to rollup that pattern. +The API accepts a `GetRollupCapsRequest` object as a request and returns a `GetRollupCapsResponse`. + +[[java-rest-high-x-pack-rollup-get-rollup-caps-request]] +==== Get Rollup Capabilities Request + +A `GetRollupCapsRequest` requires a single parameter: the target index or index pattern (e.g. `logstash-*`): + +["source","java",subs="attributes,callouts,macros"] +-------------------------------------------------- +include-tagged::{doc-tests}/RollupDocumentationIT.java[x-pack-rollup-get-rollup-caps-request] +-------------------------------------------------- + +[[java-rest-high-x-pack-rollup-get-rollup-caps-execution]] +==== Execution + +The Get Rollup Capabilities 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-put-rollup-job-execute] +-------------------------------------------------- + +[[java-rest-high-x-pack-rollup-get-rollup-caps-response]] +==== Response + +The returned `GetRollupCapsResponse` holds lists and maps of values which correspond to the capabilities +of the target index/index pattern (what jobs were configured for the pattern, where the data is stored, what +aggregations are available, etc). It provides essentially the same data as the original job configuration, +just presented in a different manner. + +For example, if we had created a job with the following config: + +["source","java",subs="attributes,callouts,macros"] +-------------------------------------------------- +include-tagged::{doc-tests}/RollupDocumentationIT.java[x-pack-rollup-get-rollup-caps-setup] +-------------------------------------------------- + +The `GetRollupCapsResponse` object would contain the same information, laid out in a slightly different manner: + +["source","java",subs="attributes,callouts,macros"] +-------------------------------------------------- +include-tagged::{doc-tests}/RollupDocumentationIT.java[x-pack-rollup-get-rollup-caps-response] +-------------------------------------------------- + +[[java-rest-high-x-pack-rollup-put-rollup-job-async]] +==== Asynchronous Execution + +This request can be executed asynchronously: + +["source","java",subs="attributes,callouts,macros"] +-------------------------------------------------- +include-tagged::{doc-tests}/RollupDocumentationIT.java[x-pack-rollup-get-rollup-caps-execute-async] +-------------------------------------------------- +<1> The `GetRollupCapsRequest` 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 `GetRollupCapsResponse` looks like: + +["source","java",subs="attributes,callouts,macros"] +-------------------------------------------------- +include-tagged::{doc-tests}/RollupDocumentationIT.java[x-pack-rollup-get-rollup-caps-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 diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/GetRollupCapsAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/GetRollupCapsAction.java index 73cade8150d3b..9ff8eb9570000 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/GetRollupCapsAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/GetRollupCapsAction.java @@ -5,30 +5,14 @@ */ package org.elasticsearch.xpack.core.rollup.action; - import org.elasticsearch.action.Action; -import org.elasticsearch.action.ActionRequest; import org.elasticsearch.action.ActionRequestBuilder; -import org.elasticsearch.action.ActionRequestValidationException; -import org.elasticsearch.action.ActionResponse; import org.elasticsearch.client.ElasticsearchClient; -import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.common.ParseField; -import org.elasticsearch.common.Strings; -import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.io.stream.Writeable; -import org.elasticsearch.common.xcontent.ToXContent; -import org.elasticsearch.common.xcontent.ToXContentObject; -import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.protocol.xpack.rollup.RollupField; - -import java.io.IOException; -import java.util.Collections; -import java.util.Map; -import java.util.Objects; +import org.elasticsearch.protocol.xpack.rollup.GetRollupCapsRequest; +import org.elasticsearch.protocol.xpack.rollup.GetRollupCapsResponse; -public class GetRollupCapsAction extends Action { +public class GetRollupCapsAction extends Action { public static final GetRollupCapsAction INSTANCE = new GetRollupCapsAction(); public static final String NAME = "cluster:monitor/xpack/rollup/get/caps"; @@ -40,131 +24,14 @@ private GetRollupCapsAction() { } @Override - public Response newResponse() { - return new Response(); - } - - public static class Request extends ActionRequest implements ToXContent { - private String indexPattern; - - public Request(String indexPattern) { - if (Strings.isNullOrEmpty(indexPattern) || indexPattern.equals("*")) { - this.indexPattern = MetaData.ALL; - } else { - this.indexPattern = indexPattern; - } - } - - public Request() {} - - public String getIndexPattern() { - return indexPattern; - } - - @Override - public void readFrom(StreamInput in) throws IOException { - super.readFrom(in); - this.indexPattern = in.readString(); - } - - @Override - public void writeTo(StreamOutput out) throws IOException { - super.writeTo(out); - out.writeString(indexPattern); - } - - @Override - public ActionRequestValidationException validate() { - return null; - } - - @Override - public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { - builder.field(RollupField.ID.getPreferredName(), indexPattern); - return builder; - } - - @Override - public int hashCode() { - return Objects.hash(indexPattern); - } - - @Override - public boolean equals(Object obj) { - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - Request other = (Request) obj; - return Objects.equals(indexPattern, other.indexPattern); - } + public GetRollupCapsResponse newResponse() { + return new GetRollupCapsResponse(); } - public static class RequestBuilder extends ActionRequestBuilder { + public static class RequestBuilder extends ActionRequestBuilder { protected RequestBuilder(ElasticsearchClient client, GetRollupCapsAction action) { - super(client, action, new Request()); - } - } - - public static class Response extends ActionResponse implements Writeable, ToXContentObject { - - private Map jobs = Collections.emptyMap(); - - public Response() { - - } - - public Response(Map jobs) { - this.jobs = Objects.requireNonNull(jobs); - } - - Response(StreamInput in) throws IOException { - jobs = in.readMap(StreamInput::readString, RollableIndexCaps::new); - } - - public Map getJobs() { - return jobs; - } - - @Override - public void writeTo(StreamOutput out) throws IOException { - super.writeTo(out); - out.writeMap(jobs, StreamOutput::writeString, (out1, value) -> value.writeTo(out1)); - } - - @Override - public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { - builder.startObject(); - for (Map.Entry entry : jobs.entrySet()) { - entry.getValue().toXContent(builder, params); - } - builder.endObject(); - return builder; - } - - @Override - public int hashCode() { - return Objects.hash(jobs); - } - - @Override - public boolean equals(Object obj) { - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - Response other = (Response) obj; - return Objects.equals(jobs, other.jobs); - } - - @Override - public final String toString() { - return Strings.toString(this); + super(client, action, new GetRollupCapsRequest()); } } } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/GetRollupIndexCapsAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/GetRollupIndexCapsAction.java index d3f856ac0d55d..361bf27c1e637 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/GetRollupIndexCapsAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/GetRollupIndexCapsAction.java @@ -22,6 +22,7 @@ import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContentObject; import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.protocol.xpack.rollup.RollableIndexCaps; import org.elasticsearch.protocol.xpack.rollup.RollupField; import java.io.IOException; diff --git a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/RollupJobIdentifierUtils.java b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/RollupJobIdentifierUtils.java index 3ae8adf2ecfdb..23cb038d767bb 100644 --- a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/RollupJobIdentifierUtils.java +++ b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/RollupJobIdentifierUtils.java @@ -6,14 +6,14 @@ package org.elasticsearch.xpack.rollup; import org.elasticsearch.common.unit.TimeValue; +import org.elasticsearch.protocol.xpack.rollup.RollupField; +import org.elasticsearch.protocol.xpack.rollup.RollupJobCaps; +import org.elasticsearch.protocol.xpack.rollup.job.DateHistogramGroupConfig; import org.elasticsearch.search.aggregations.AggregationBuilder; import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramAggregationBuilder; import org.elasticsearch.search.aggregations.bucket.histogram.HistogramAggregationBuilder; import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder; import org.elasticsearch.search.aggregations.support.ValuesSourceAggregationBuilder; -import org.elasticsearch.protocol.xpack.rollup.RollupField; -import org.elasticsearch.xpack.core.rollup.action.RollupJobCaps; -import org.elasticsearch.protocol.xpack.rollup.job.DateHistogramGroupConfig; import org.joda.time.DateTimeZone; import java.util.ArrayList; diff --git a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/RollupIndexCaps.java b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/RollupIndexCaps.java index 576180e06b996..cd8b6a8d777ae 100644 --- a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/RollupIndexCaps.java +++ b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/RollupIndexCaps.java @@ -20,9 +20,9 @@ import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.protocol.xpack.rollup.RollupField; -import org.elasticsearch.xpack.core.rollup.action.GetRollupCapsAction; -import org.elasticsearch.xpack.core.rollup.action.RollupJobCaps; +import org.elasticsearch.protocol.xpack.rollup.RollupJobCaps; import org.elasticsearch.protocol.xpack.rollup.job.RollupJobConfig; +import org.elasticsearch.xpack.core.rollup.action.GetRollupCapsAction; import java.io.IOException; import java.util.ArrayList; diff --git a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportGetRollupCapsAction.java b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportGetRollupCapsAction.java index 4acd98057e7c9..d0e2d1a3ccd09 100644 --- a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportGetRollupCapsAction.java +++ b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportGetRollupCapsAction.java @@ -17,20 +17,24 @@ import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.protocol.xpack.rollup.GetRollupCapsRequest; +import org.elasticsearch.protocol.xpack.rollup.GetRollupCapsResponse; +import org.elasticsearch.protocol.xpack.rollup.RollableIndexCaps; +import org.elasticsearch.protocol.xpack.rollup.RollupField; +import org.elasticsearch.protocol.xpack.rollup.RollupJobCaps; import org.elasticsearch.tasks.Task; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.protocol.xpack.rollup.RollupField; import org.elasticsearch.xpack.core.rollup.action.GetRollupCapsAction; -import org.elasticsearch.xpack.core.rollup.action.RollableIndexCaps; -import org.elasticsearch.xpack.core.rollup.action.RollupJobCaps; +import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Optional; import java.util.TreeMap; import java.util.function.Supplier; +import java.util.stream.Collectors; -public class TransportGetRollupCapsAction extends HandledTransportAction { +public class TransportGetRollupCapsAction extends HandledTransportAction { private final ClusterService clusterService; @@ -38,18 +42,18 @@ public class TransportGetRollupCapsAction extends HandledTransportAction) GetRollupCapsAction.Request::new); + (Supplier) GetRollupCapsRequest::new); this.clusterService = clusterService; } @Override - protected void doExecute(Task task, GetRollupCapsAction.Request request, ActionListener listener) { + protected void doExecute(Task task, GetRollupCapsRequest request, ActionListener listener) { Map allCaps = getCaps(request.getIndexPattern(), clusterService.state().getMetaData().indices()); - listener.onResponse(new GetRollupCapsAction.Response(allCaps)); + listener.onResponse(new GetRollupCapsResponse(allCaps)); } static Map getCaps(String indexPattern, ImmutableOpenMap indices) { - Map allCaps = new TreeMap<>(); + Map > allCaps = new TreeMap<>(); for (ObjectObjectCursor entry : indices) { // Does this index have rollup metadata? @@ -69,16 +73,21 @@ static Map getCaps(String indexPattern, ImmutableOpen ? jobCap.getIndexPattern() : indexPattern; // Do we already have an entry for this index pattern? - RollableIndexCaps indexCaps = allCaps.get(pattern); + List indexCaps = allCaps.get(pattern); if (indexCaps == null) { - indexCaps = new RollableIndexCaps(pattern); + indexCaps = new ArrayList<>(); } - indexCaps.addJobCap(jobCap); + indexCaps.add(jobCap); allCaps.put(pattern, indexCaps); }); }); } - return allCaps; + + // Convert the mutable lists into the RollableIndexCaps + return allCaps.entrySet() + .stream() + .collect(Collectors.toMap(Map.Entry::getKey, + e -> new RollableIndexCaps(e.getKey(), e.getValue()))); } static Optional findRollupIndexCaps(String indexName, IndexMetaData indexMetaData) { diff --git a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportGetRollupIndexCapsAction.java b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportGetRollupIndexCapsAction.java index 5d81f4046ebd8..02615bc088cc1 100644 --- a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportGetRollupIndexCapsAction.java +++ b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportGetRollupIndexCapsAction.java @@ -14,16 +14,19 @@ import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.protocol.xpack.rollup.RollableIndexCaps; +import org.elasticsearch.protocol.xpack.rollup.RollupJobCaps; import org.elasticsearch.tasks.Task; import org.elasticsearch.transport.TransportService; import org.elasticsearch.xpack.core.rollup.action.GetRollupIndexCapsAction; -import org.elasticsearch.xpack.core.rollup.action.RollableIndexCaps; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.TreeMap; import java.util.function.Supplier; +import java.util.stream.Collectors; import java.util.stream.StreamSupport; public class TransportGetRollupIndexCapsAction extends HandledTransportAction getCapsByRollupIndex(List resolvedIndexNames, ImmutableOpenMap indices) { - Map allCaps = new TreeMap<>(); + Map > allCaps = new TreeMap<>(); StreamSupport.stream(indices.spliterator(), false) .filter(entry -> resolvedIndexNames.contains(entry.key)) @@ -63,17 +66,20 @@ static Map getCapsByRollupIndex(List resolved .ifPresent(cap -> { cap.getJobCaps().forEach(jobCap -> { // Do we already have an entry for this index? - RollableIndexCaps indexCaps = allCaps.get(jobCap.getRollupIndex()); + List indexCaps = allCaps.get(jobCap.getRollupIndex()); if (indexCaps == null) { - indexCaps = new RollableIndexCaps(jobCap.getRollupIndex()); + indexCaps = new ArrayList<>(); } - indexCaps.addJobCap(jobCap); + indexCaps.add(jobCap); allCaps.put(jobCap.getRollupIndex(), indexCaps); }); }); }); - - return allCaps; + // Convert the mutable lists into the RollableIndexCaps + return allCaps.entrySet() + .stream() + .collect(Collectors.toMap(Map.Entry::getKey, + e -> new RollableIndexCaps(e.getKey(), e.getValue()))); } } diff --git a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportRollupSearchAction.java b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportRollupSearchAction.java index 6e1b410cee90e..f8a16d33803f9 100644 --- a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportRollupSearchAction.java +++ b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportRollupSearchAction.java @@ -39,6 +39,7 @@ import org.elasticsearch.index.query.RangeQueryBuilder; import org.elasticsearch.index.query.TermQueryBuilder; import org.elasticsearch.index.query.TermsQueryBuilder; +import org.elasticsearch.protocol.xpack.rollup.RollupJobCaps; import org.elasticsearch.script.ScriptService; import org.elasticsearch.search.aggregations.AggregationBuilder; import org.elasticsearch.search.aggregations.AggregatorFactories; @@ -54,7 +55,6 @@ import org.elasticsearch.transport.TransportRequestHandler; import org.elasticsearch.transport.TransportService; import org.elasticsearch.protocol.xpack.rollup.RollupField; -import org.elasticsearch.xpack.core.rollup.action.RollupJobCaps; import org.elasticsearch.xpack.core.rollup.action.RollupSearchAction; import org.elasticsearch.protocol.xpack.rollup.job.DateHistogramGroupConfig; import org.elasticsearch.xpack.rollup.Rollup; diff --git a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestGetRollupCapsAction.java b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestGetRollupCapsAction.java index dfda4d0e9e15b..3cc3093fdfcf0 100644 --- a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestGetRollupCapsAction.java +++ b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestGetRollupCapsAction.java @@ -8,6 +8,7 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.ParseField; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.protocol.xpack.rollup.GetRollupCapsRequest; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; @@ -28,7 +29,7 @@ public RestGetRollupCapsAction(Settings settings, RestController controller) { @Override protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient client) throws IOException { String id = restRequest.param(ID.getPreferredName()); - GetRollupCapsAction.Request request = new GetRollupCapsAction.Request(id); + GetRollupCapsRequest request = new GetRollupCapsRequest(id); return channel -> client.execute(GetRollupCapsAction.INSTANCE, request, new RestToXContentListener<>(channel)); } diff --git a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/RollupJobIdentifierUtilTests.java b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/RollupJobIdentifierUtilTests.java index 115db849b7549..fd797582b04f5 100644 --- a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/RollupJobIdentifierUtilTests.java +++ b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/RollupJobIdentifierUtilTests.java @@ -5,6 +5,7 @@ */ package org.elasticsearch.xpack.rollup; +import org.elasticsearch.protocol.xpack.rollup.RollupJobCaps; import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramAggregationBuilder; import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval; import org.elasticsearch.search.aggregations.bucket.histogram.HistogramAggregationBuilder; @@ -15,7 +16,6 @@ import org.elasticsearch.search.aggregations.metrics.sum.SumAggregationBuilder; import org.elasticsearch.search.aggregations.support.ValueType; import org.elasticsearch.test.ESTestCase; -import org.elasticsearch.xpack.core.rollup.action.RollupJobCaps; import org.elasticsearch.protocol.xpack.rollup.job.DateHistogramGroupConfig; import org.elasticsearch.protocol.xpack.rollup.job.GroupConfig; import org.elasticsearch.protocol.xpack.rollup.job.HistogramGroupConfig; diff --git a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/GetRollupCapsActionRequestTests.java b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/GetRollupCapsRequestTests.java similarity index 94% rename from x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/GetRollupCapsActionRequestTests.java rename to x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/GetRollupCapsRequestTests.java index f7c5b303edc91..f7f300e686a96 100644 --- a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/GetRollupCapsActionRequestTests.java +++ b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/GetRollupCapsRequestTests.java @@ -10,12 +10,12 @@ import org.elasticsearch.cluster.metadata.MappingMetaData; import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.common.collect.ImmutableOpenMap; -import org.elasticsearch.test.AbstractStreamableTestCase; -import org.elasticsearch.xpack.core.rollup.ConfigTestHelpers; +import org.elasticsearch.protocol.xpack.rollup.GetRollupCapsRequest; +import org.elasticsearch.protocol.xpack.rollup.RollableIndexCaps; import org.elasticsearch.protocol.xpack.rollup.RollupField; -import org.elasticsearch.xpack.core.rollup.action.GetRollupCapsAction; -import org.elasticsearch.xpack.core.rollup.action.RollableIndexCaps; import org.elasticsearch.protocol.xpack.rollup.job.RollupJobConfig; +import org.elasticsearch.test.AbstractStreamableTestCase; +import org.elasticsearch.xpack.core.rollup.ConfigTestHelpers; import org.mockito.Mockito; import java.io.IOException; @@ -27,19 +27,19 @@ import static org.hamcrest.Matchers.equalTo; -public class GetRollupCapsActionRequestTests extends AbstractStreamableTestCase { +public class GetRollupCapsRequestTests extends AbstractStreamableTestCase { @Override - protected GetRollupCapsAction.Request createTestInstance() { + protected GetRollupCapsRequest createTestInstance() { if (randomBoolean()) { - return new GetRollupCapsAction.Request(MetaData.ALL); + return new GetRollupCapsRequest(MetaData.ALL); } - return new GetRollupCapsAction.Request(randomAlphaOfLengthBetween(1, 20)); + return new GetRollupCapsRequest(randomAlphaOfLengthBetween(1, 20)); } @Override - protected GetRollupCapsAction.Request createBlankInstance() { - return new GetRollupCapsAction.Request(); + protected GetRollupCapsRequest createBlankInstance() { + return new GetRollupCapsRequest(); } public void testNoIndexMetaData() { diff --git a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/GetRollupCapsResponseTests.java b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/GetRollupCapsResponseTests.java new file mode 100644 index 0000000000000..df2791891e188 --- /dev/null +++ b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/GetRollupCapsResponseTests.java @@ -0,0 +1,63 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ +package org.elasticsearch.xpack.rollup.action; + +import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.protocol.xpack.rollup.GetRollupCapsResponse; +import org.elasticsearch.protocol.xpack.rollup.RollableIndexCaps; +import org.elasticsearch.protocol.xpack.rollup.RollupJobCaps; +import org.elasticsearch.test.AbstractStreamableXContentTestCase; +import org.elasticsearch.xpack.core.rollup.ConfigTestHelpers; +import org.junit.Before; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class GetRollupCapsResponseTests extends AbstractStreamableXContentTestCase { + + private Map indices; + + @Before + private void setupIndices() { + int numIndices = randomIntBetween(1,5); + indices = new HashMap<>(numIndices); + for (int i = 0; i < numIndices; i++) { + String indexName = "index_" + randomAlphaOfLength(10); + int numJobs = randomIntBetween(1,5); + List jobs = new ArrayList<>(numJobs); + for (int j = 0; j < numJobs; j++) { + jobs.add(new RollupJobCaps(ConfigTestHelpers.randomRollupJobConfig(random()))); + } + RollableIndexCaps cap = new RollableIndexCaps(indexName, jobs); + indices.put(indexName, cap); + } + } + + @Override + protected GetRollupCapsResponse createTestInstance() { + return new GetRollupCapsResponse(indices); + } + + @Override + protected boolean supportsUnknownFields() { + return false; + } + + @Override + protected GetRollupCapsResponse createBlankInstance() { + return new GetRollupCapsResponse(); + } + + @Override + protected GetRollupCapsResponse doParseInstance(final XContentParser parser) throws IOException { + return GetRollupCapsResponse.fromXContent(parser); + } + + +} diff --git a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/GetRollupIndexCapsActionRequestTests.java b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/GetRollupIndexCapsActionRequestTests.java index c2cc770ab7e9b..80257389edf1a 100644 --- a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/GetRollupIndexCapsActionRequestTests.java +++ b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/GetRollupIndexCapsActionRequestTests.java @@ -10,11 +10,11 @@ import org.elasticsearch.cluster.metadata.MappingMetaData; import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.common.collect.ImmutableOpenMap; +import org.elasticsearch.protocol.xpack.rollup.RollableIndexCaps; import org.elasticsearch.test.AbstractStreamableTestCase; import org.elasticsearch.xpack.core.rollup.ConfigTestHelpers; import org.elasticsearch.protocol.xpack.rollup.RollupField; import org.elasticsearch.xpack.core.rollup.action.GetRollupIndexCapsAction; -import org.elasticsearch.xpack.core.rollup.action.RollableIndexCaps; import org.mockito.Mockito; import java.io.IOException; diff --git a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/RollupIndexCapsTests.java b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/RollupIndexCapsTests.java index ef8480bae3bdc..cb31a7d493d82 100644 --- a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/RollupIndexCapsTests.java +++ b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/RollupIndexCapsTests.java @@ -6,9 +6,9 @@ package org.elasticsearch.xpack.rollup.action; import org.elasticsearch.cluster.metadata.MetaData; +import org.elasticsearch.protocol.xpack.rollup.RollupJobCaps; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.xpack.core.rollup.ConfigTestHelpers; -import org.elasticsearch.xpack.core.rollup.action.RollupJobCaps; import org.elasticsearch.protocol.xpack.rollup.job.RollupJobConfig; import java.util.ArrayList; diff --git a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/SearchActionTests.java b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/SearchActionTests.java index 26142f9c83bdf..bc36a1bbc0a2c 100644 --- a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/SearchActionTests.java +++ b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/SearchActionTests.java @@ -27,6 +27,7 @@ import org.elasticsearch.index.query.TermQueryBuilder; import org.elasticsearch.index.query.TermsQueryBuilder; import org.elasticsearch.indices.IndicesModule; +import org.elasticsearch.protocol.xpack.rollup.RollupJobCaps; import org.elasticsearch.protocol.xpack.rollup.job.MetricConfig; import org.elasticsearch.protocol.xpack.rollup.job.TermsGroupConfig; import org.elasticsearch.search.DocValueFormat; @@ -48,7 +49,6 @@ import org.elasticsearch.test.ESTestCase; import org.elasticsearch.xpack.core.rollup.ConfigTestHelpers; import org.elasticsearch.protocol.xpack.rollup.RollupField; -import org.elasticsearch.xpack.core.rollup.action.RollupJobCaps; import org.elasticsearch.protocol.xpack.rollup.job.DateHistogramGroupConfig; import org.elasticsearch.protocol.xpack.rollup.job.GroupConfig; import org.elasticsearch.protocol.xpack.rollup.job.RollupJobConfig; diff --git a/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/GetRollupCapsRequest.java b/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/GetRollupCapsRequest.java new file mode 100644 index 0000000000000..da3805c6c5fe6 --- /dev/null +++ b/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/GetRollupCapsRequest.java @@ -0,0 +1,89 @@ +/* + * 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.protocol.xpack.rollup; + +import org.elasticsearch.action.ActionRequest; +import org.elasticsearch.action.ActionRequestValidationException; +import org.elasticsearch.cluster.metadata.MetaData; +import org.elasticsearch.common.Strings; +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.common.xcontent.ToXContent; +import org.elasticsearch.common.xcontent.XContentBuilder; + +import java.io.IOException; +import java.util.Objects; + +public class GetRollupCapsRequest extends ActionRequest implements ToXContent { + private String indexPattern; + + public GetRollupCapsRequest(String indexPattern) { + if (Strings.isNullOrEmpty(indexPattern) || indexPattern.equals("*")) { + this.indexPattern = MetaData.ALL; + } else { + this.indexPattern = indexPattern; + } + } + + public GetRollupCapsRequest() {} + + public String getIndexPattern() { + return indexPattern; + } + + @Override + public void readFrom(StreamInput in) throws IOException { + super.readFrom(in); + this.indexPattern = in.readString(); + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); + out.writeString(indexPattern); + } + + @Override + public ActionRequestValidationException validate() { + return null; + } + + @Override + public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { + builder.field(RollupField.ID.getPreferredName(), indexPattern); + return builder; + } + + @Override + public int hashCode() { + return Objects.hash(indexPattern); + } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + GetRollupCapsRequest other = (GetRollupCapsRequest) obj; + return Objects.equals(indexPattern, other.indexPattern); + } +} diff --git a/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/GetRollupCapsResponse.java b/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/GetRollupCapsResponse.java new file mode 100644 index 0000000000000..35c02267b371b --- /dev/null +++ b/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/GetRollupCapsResponse.java @@ -0,0 +1,109 @@ +/* + * 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.protocol.xpack.rollup; + +import org.elasticsearch.action.ActionResponse; +import org.elasticsearch.common.Strings; +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.common.io.stream.Writeable; +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.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; + +public class GetRollupCapsResponse extends ActionResponse implements Writeable, ToXContentObject { + + private Map jobs = Collections.emptyMap(); + + public GetRollupCapsResponse() {} + + public GetRollupCapsResponse(Map jobs) { + this.jobs = Collections.unmodifiableMap(Objects.requireNonNull(jobs)); + } + + public Map getJobs() { + return jobs; + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); + out.writeMap(jobs, StreamOutput::writeString, (out1, value) -> value.writeTo(out1)); + } + + @Override + public void readFrom(StreamInput in) throws IOException { + super.readFrom(in); + jobs = in.readMap(StreamInput::readString, RollableIndexCaps::new); + } + + @Override + public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { + builder.startObject(); + for (Map.Entry entry : jobs.entrySet()) { + entry.getValue().toXContent(builder, params); + } + builder.endObject(); + return builder; + } + + public static GetRollupCapsResponse fromXContent(final XContentParser parser) throws IOException { + Map jobs = new HashMap<>(); + XContentParser.Token token = parser.nextToken(); + if (token.equals(XContentParser.Token.START_OBJECT)) { + while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { + if (token.equals(XContentParser.Token.FIELD_NAME)) { + String pattern = parser.currentName(); + + RollableIndexCaps cap = RollableIndexCaps.PARSER.apply(pattern).apply(parser, null); + jobs.put(pattern, cap); + } + } + } + return new GetRollupCapsResponse(jobs); + } + + @Override + public int hashCode() { + return Objects.hash(jobs); + } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + GetRollupCapsResponse other = (GetRollupCapsResponse) obj; + return Objects.equals(jobs, other.jobs); + } + + @Override + public final String toString() { + return Strings.toString(this); + } +} diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/RollableIndexCaps.java b/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/RollableIndexCaps.java similarity index 51% rename from x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/RollableIndexCaps.java rename to x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/RollableIndexCaps.java index 91f581f1c09e0..14b13e86e1dd3 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/RollableIndexCaps.java +++ b/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/RollableIndexCaps.java @@ -1,22 +1,37 @@ /* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. + * 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.xpack.core.rollup.action; +package org.elasticsearch.protocol.xpack.rollup; import org.elasticsearch.common.ParseField; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Writeable; +import org.elasticsearch.common.xcontent.ConstructingObjectParser; import org.elasticsearch.common.xcontent.ToXContentFragment; import org.elasticsearch.common.xcontent.XContentBuilder; import java.io.IOException; -import java.util.ArrayList; +import java.util.Collections; import java.util.Comparator; import java.util.List; import java.util.Objects; +import java.util.function.Function; /** * Represents the rollup capabilities of a non-rollup index. E.g. what values/aggregations @@ -26,14 +41,27 @@ * The index name can either be a single index, or an index pattern (logstash-*) */ public class RollableIndexCaps implements Writeable, ToXContentFragment { - static ParseField ROLLUP_JOBS = new ParseField("rollup_jobs"); + private static final ParseField ROLLUP_JOBS = new ParseField("rollup_jobs"); + + public static final Function> PARSER = indexName -> { + @SuppressWarnings("unchecked") + ConstructingObjectParser p + = new ConstructingObjectParser<>(indexName, + a -> new RollableIndexCaps(indexName, (List) a[0])); + + p.declareObjectArray(ConstructingObjectParser.constructorArg(), RollupJobCaps.PARSER::apply, + ROLLUP_JOBS); + return p; + }; private String indexName; private List jobCaps; - public RollableIndexCaps(String indexName) { + public RollableIndexCaps(String indexName, List caps) { this.indexName = indexName; - this.jobCaps = new ArrayList<>(); + this.jobCaps = Objects.requireNonNull(caps); + this.jobCaps.sort(Comparator.comparing(RollupJobCaps::getJobID)); + this.jobCaps = Collections.unmodifiableList(jobCaps); } public RollableIndexCaps(StreamInput in) throws IOException { @@ -41,10 +69,6 @@ public RollableIndexCaps(StreamInput in) throws IOException { this.jobCaps = in.readList(RollupJobCaps::new); } - public void addJobCap(RollupJobCaps jobCap) { - jobCaps.add(jobCap); - } - public String getIndexName() { return indexName; } @@ -62,7 +86,6 @@ public void writeTo(StreamOutput out) throws IOException { @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(indexName); - jobCaps.sort(Comparator.comparing(RollupJobCaps::getJobID)); builder.field(ROLLUP_JOBS.getPreferredName(), jobCaps); builder.endObject(); return builder; @@ -80,8 +103,8 @@ public boolean equals(Object other) { RollableIndexCaps that = (RollableIndexCaps) other; - return Objects.equals(this.jobCaps, that.jobCaps) - && Objects.equals(this.indexName, that.indexName); + return Objects.deepEquals(this.jobCaps, that.jobCaps) + && Objects.equals(this.indexName, that.indexName); } @Override diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/RollupJobCaps.java b/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/RollupJobCaps.java similarity index 50% rename from x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/RollupJobCaps.java rename to x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/RollupJobCaps.java index dcc34684c46fa..78b0cc58ca036 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/RollupJobCaps.java +++ b/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/RollupJobCaps.java @@ -1,25 +1,44 @@ /* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. + * 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.xpack.core.rollup.action; +package org.elasticsearch.protocol.xpack.rollup; import org.elasticsearch.common.ParseField; +import org.elasticsearch.common.collect.Tuple; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Writeable; +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.protocol.xpack.rollup.job.RollupJobConfig; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.function.Function; +import java.util.stream.Collectors; /** * Represents the Rollup capabilities for a specific job on a single rollup index @@ -29,49 +48,63 @@ public class RollupJobCaps implements Writeable, ToXContentObject { private static ParseField ROLLUP_INDEX = new ParseField("rollup_index"); private static ParseField INDEX_PATTERN = new ParseField("index_pattern"); private static ParseField FIELDS = new ParseField("fields"); + private static final String NAME = "rollup_job_caps"; + + public static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>(NAME, + a -> { + @SuppressWarnings("unchecked") + List> caps = (List>) a[3]; + if (caps.isEmpty()) { + return new RollupJobCaps((String) a[0], (String) a[1], (String) a[2], Collections.emptyMap()); + } + Map mapCaps = new HashMap<>(caps.size()); + caps.forEach(c -> mapCaps.put(c.v1(), c.v2())); + return new RollupJobCaps((String) a[0], (String) a[1], (String) a[2], mapCaps); + }); + + static { + PARSER.declareString(ConstructingObjectParser.constructorArg(), JOB_ID); + PARSER.declareString(ConstructingObjectParser.constructorArg(), ROLLUP_INDEX); + PARSER.declareString(ConstructingObjectParser.constructorArg(), INDEX_PATTERN); + PARSER.declareNamedObjects(ConstructingObjectParser.constructorArg(), + (p, c, name) -> new Tuple<>(name, RollupFieldCaps.fromXContent(p)), FIELDS); + } private String jobID; private String rollupIndex; private String indexPattern; - private Map fieldCapLookup = new HashMap<>(); + private Map fieldCapLookup; // TODO now that these rollup caps are being used more widely (e.g. search), perhaps we should // store the RollupJob and translate into FieldCaps on demand for json output. Would make working with // it internally a lot easier public RollupJobCaps(RollupJobConfig job) { + Map>> tempFieldCaps = new HashMap<>(); + jobID = job.getId(); rollupIndex = job.getRollupIndex(); indexPattern = job.getIndexPattern(); Map dateHistoAggCap = job.getGroupConfig().getDateHistogram().toAggCap(); String dateField = job.getGroupConfig().getDateHistogram().getField(); - RollupFieldCaps fieldCaps = fieldCapLookup.get(dateField); - if (fieldCaps == null) { - fieldCaps = new RollupFieldCaps(); - } - fieldCaps.addAgg(dateHistoAggCap); - fieldCapLookup.put(dateField, fieldCaps); + List> fieldCaps = tempFieldCaps.getOrDefault(dateField, new ArrayList<>()); + fieldCaps.add(dateHistoAggCap); + tempFieldCaps.put(dateField, fieldCaps); if (job.getGroupConfig().getHistogram() != null) { Map histoAggCap = job.getGroupConfig().getHistogram().toAggCap(); Arrays.stream(job.getGroupConfig().getHistogram().getFields()).forEach(field -> { - RollupFieldCaps caps = fieldCapLookup.get(field); - if (caps == null) { - caps = new RollupFieldCaps(); - } - caps.addAgg(histoAggCap); - fieldCapLookup.put(field, caps); + List> caps = tempFieldCaps.getOrDefault(field, new ArrayList<>()); + caps.add(histoAggCap); + tempFieldCaps.put(field, caps); }); } if (job.getGroupConfig().getTerms() != null) { - Map histoAggCap = job.getGroupConfig().getTerms().toAggCap(); + Map termsAggCap = job.getGroupConfig().getTerms().toAggCap(); Arrays.stream(job.getGroupConfig().getTerms().getFields()).forEach(field -> { - RollupFieldCaps caps = fieldCapLookup.get(field); - if (caps == null) { - caps = new RollupFieldCaps(); - } - caps.addAgg(histoAggCap); - fieldCapLookup.put(field, caps); + List> caps = tempFieldCaps.getOrDefault(field, new ArrayList<>()); + caps.add(termsAggCap); + tempFieldCaps.put(field, caps); }); } @@ -79,22 +112,33 @@ public RollupJobCaps(RollupJobConfig job) { job.getMetricsConfig().forEach(metricConfig -> { List> metrics = metricConfig.toAggCap(); metrics.forEach(m -> { - RollupFieldCaps caps = fieldCapLookup.get(metricConfig.getField()); - if (caps == null) { - caps = new RollupFieldCaps(); - } - caps.addAgg(m); - fieldCapLookup.put(metricConfig.getField(), caps); + List> caps = tempFieldCaps + .getOrDefault(metricConfig.getField(), new ArrayList<>()); + caps.add(m); + tempFieldCaps.put(metricConfig.getField(), caps); }); }); } + + // Convert the temp lists into RollupFieldCaps + this.fieldCapLookup = Collections.unmodifiableMap(tempFieldCaps.entrySet() + .stream() + .collect(Collectors.toMap(Map.Entry::getKey, + e -> new RollupFieldCaps(e.getValue())))); + } + + public RollupJobCaps(String jobID, String rollupIndex, String indexPattern, Map fieldCapLookup) { + this.jobID = jobID; + this.rollupIndex = rollupIndex; + this.indexPattern = indexPattern; + this.fieldCapLookup = Collections.unmodifiableMap(Objects.requireNonNull(fieldCapLookup)); } public RollupJobCaps(StreamInput in) throws IOException { this.jobID = in.readString(); this.rollupIndex = in.readString(); this.indexPattern = in.readString(); - this.fieldCapLookup = in.readMap(StreamInput::readString, RollupFieldCaps::new); + this.fieldCapLookup = Collections.unmodifiableMap(in.readMap(StreamInput::readString, RollupFieldCaps::new)); } public Map getFieldCaps() { @@ -149,8 +193,9 @@ public boolean equals(Object other) { RollupJobCaps that = (RollupJobCaps) other; return Objects.equals(this.jobID, that.jobID) - && Objects.equals(this.rollupIndex, that.rollupIndex) - && Objects.equals(this.fieldCapLookup, that.fieldCapLookup); + && Objects.equals(this.indexPattern, that.indexPattern) + && Objects.equals(this.rollupIndex, that.rollupIndex) + && Objects.deepEquals(this.fieldCapLookup, that.fieldCapLookup); } @Override @@ -159,20 +204,40 @@ public int hashCode() { } public static class RollupFieldCaps implements Writeable, ToXContentObject { - private List> aggs = new ArrayList<>(); - - RollupFieldCaps() { } + private List> aggs; + private static final String NAME = "rollup_field_caps"; + + public static final Function> PARSER = fieldName -> { + @SuppressWarnings("unchecked") + ConstructingObjectParser parser + = new ConstructingObjectParser<>(NAME, a -> new RollupFieldCaps((List>) a[0])); + + parser.declareObjectArray(ConstructingObjectParser.constructorArg(), + (p, c) -> p.map(), new ParseField(fieldName)); + return parser; + }; + + public static RollupFieldCaps fromXContent(XContentParser parser) throws IOException { + List> aggs = new ArrayList<>(); + if (parser.nextToken().equals(XContentParser.Token.START_ARRAY)) { + while (parser.nextToken().equals(XContentParser.Token.START_OBJECT)) { + aggs.add(Collections.unmodifiableMap(parser.map())); + } + } + return new RollupFieldCaps(Collections.unmodifiableList(aggs)); + } RollupFieldCaps(StreamInput in) throws IOException { int size = in.readInt(); aggs = new ArrayList<>(size); for (int i = 0; i < size; i++) { - aggs.add(in.readMap()); + aggs.add(Collections.unmodifiableMap(in.readMap())); } + aggs = Collections.unmodifiableList(aggs); } - void addAgg(Map agg) { - aggs.add(agg); + RollupFieldCaps(List> aggs) { + this.aggs = Collections.unmodifiableList(Objects.requireNonNull(aggs)); } public List> getAggs() { @@ -206,8 +271,7 @@ public boolean equals(Object other) { } RollupFieldCaps that = (RollupFieldCaps) other; - - return Objects.equals(this.aggs, that.aggs); + return Objects.deepEquals(this.aggs, that.aggs); } @Override From a38379a703c400ea8da734e62521ac3a68049e1d Mon Sep 17 00:00:00 2001 From: Zachary Tong Date: Thu, 20 Sep 2018 17:08:44 -0400 Subject: [PATCH 05/13] HLRC Refactor --- .../elasticsearch/client/RollupClient.java | 10 +- .../client/RollupRequestConverters.java | 14 ++ .../client}/rollup/GetRollupCapsRequest.java | 9 +- .../client}/rollup/GetRollupCapsResponse.java | 2 +- .../client}/rollup/RollableIndexCaps.java | 2 +- .../client}/rollup/RollupJobCaps.java | 59 +------ .../org/elasticsearch/client/RollupIT.java | 8 + .../documentation/RollupDocumentationIT.java | 6 + .../rollup/GetRollupCapsRequestTests.java | 28 ++-- .../rollup/GetRollupCapsResponseTests.java | 157 ++++++++++++++++++ .../xpack/core}/rollup/RollupField.java | 21 +-- .../rollup/action/DeleteRollupJobAction.java | 2 +- .../rollup/action/GetRollupCapsAction.java | 146 +++++++++++++++- .../action/GetRollupIndexCapsAction.java | 3 +- .../core/rollup/action/RollableIndexCaps.java | 88 ++++++++++ .../core/rollup/action/RollupJobCaps.java | 79 ++++----- .../rollup/action/StartRollupJobAction.java | 2 +- .../rollup/action/StopRollupJobAction.java | 2 +- .../rollup/job/DateHistogramGroupConfig.java | 0 .../xpack/core}/rollup/job/GroupConfig.java | 21 +-- .../rollup/job/HistogramGroupConfig.java | 0 .../xpack/core}/rollup/job/MetricConfig.java | 0 .../xpack/core/rollup/job/RollupJob.java | 1 - .../core}/rollup/job/RollupJobConfig.java | 21 +-- .../core}/rollup/job/TermsGroupConfig.java | 0 .../xpack/core/rollup/ConfigTestHelpers.java | 12 +- ...eHistogramGroupConfigSerializingTests.java | 2 - .../job/GroupConfigSerializingTests.java | 1 - .../HistogramGroupConfigSerializingTests.java | 3 +- .../job/MetricConfigSerializingTests.java | 1 - .../core/rollup/job/RollupJobConfigTests.java | 1 - .../job/TermsGroupConfigSerializingTests.java | 4 +- .../elasticsearch/xpack/rollup/Rollup.java | 2 +- .../rollup/RollupJobIdentifierUtils.java | 6 +- .../xpack/rollup/RollupRequestTranslator.java | 4 +- .../rollup/RollupResponseTranslator.java | 4 +- .../xpack/rollup/action/RollupIndexCaps.java | 6 +- .../action/TransportGetRollupCapsAction.java | 16 +- .../TransportGetRollupIndexCapsAction.java | 4 +- .../action/TransportGetRollupJobAction.java | 2 +- .../action/TransportRollupSearchAction.java | 6 +- .../rollup/rest/RestGetRollupCapsAction.java | 5 +- .../rollup/rest/RestStartRollupJobAction.java | 4 +- .../rollup/rest/RestStopRollupJobAction.java | 4 +- .../RollupResponseTranslationTests.java | 141 ++++++++-------- ...a => GetRollupCapsActionRequestTests.java} | 50 +++--- .../action/GetRollupCapsResponseTests.java | 63 ------- .../GetRollupIndexCapsActionRequestTests.java | 4 +- ...sts.java => PutJobActionRequestTests.java} | 17 +- .../action/PutRollupJobResponseTests.java | 43 ----- .../rollup/action/RollupIndexCapsTests.java | 4 +- .../rollup/action/SearchActionTests.java | 23 ++- .../TransportPutRollupJobActionTests.java | 24 --- .../action/TransportTaskHelperTests.java | 2 +- .../xpack/rollup/config/ConfigTests.java | 10 +- .../xpack/rollup/job/RollupJobTaskTests.java | 2 +- .../xpack/rollup/PutRollupJobRequest.java | 129 -------------- .../protocol/xpack/rollup/package-info.java | 24 --- 58 files changed, 663 insertions(+), 641 deletions(-) rename {x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack => client/rest-high-level/src/main/java/org/elasticsearch/client}/rollup/GetRollupCapsRequest.java (92%) rename {x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack => client/rest-high-level/src/main/java/org/elasticsearch/client}/rollup/GetRollupCapsResponse.java (98%) rename {x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack => client/rest-high-level/src/main/java/org/elasticsearch/client}/rollup/RollableIndexCaps.java (98%) rename {x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack => client/rest-high-level/src/main/java/org/elasticsearch/client}/rollup/RollupJobCaps.java (74%) rename x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/PutRollupJobResponse.java => client/rest-high-level/src/test/java/org/elasticsearch/client/rollup/GetRollupCapsRequestTests.java (56%) create mode 100644 client/rest-high-level/src/test/java/org/elasticsearch/client/rollup/GetRollupCapsResponseTests.java rename x-pack/{protocol/src/main/java/org/elasticsearch/protocol/xpack => plugin/core/src/main/java/org/elasticsearch/xpack/core}/rollup/RollupField.java (84%) create mode 100644 x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/RollableIndexCaps.java rename x-pack/{protocol/src/main/java/org/elasticsearch/protocol/xpack => plugin/core/src/main/java/org/elasticsearch/xpack/core}/rollup/job/DateHistogramGroupConfig.java (100%) rename x-pack/{protocol/src/main/java/org/elasticsearch/protocol/xpack => plugin/core/src/main/java/org/elasticsearch/xpack/core}/rollup/job/GroupConfig.java (88%) rename x-pack/{protocol/src/main/java/org/elasticsearch/protocol/xpack => plugin/core/src/main/java/org/elasticsearch/xpack/core}/rollup/job/HistogramGroupConfig.java (100%) rename x-pack/{protocol/src/main/java/org/elasticsearch/protocol/xpack => plugin/core/src/main/java/org/elasticsearch/xpack/core}/rollup/job/MetricConfig.java (100%) rename x-pack/{protocol/src/main/java/org/elasticsearch/protocol/xpack => plugin/core/src/main/java/org/elasticsearch/xpack/core}/rollup/job/RollupJobConfig.java (92%) rename x-pack/{protocol/src/main/java/org/elasticsearch/protocol/xpack => plugin/core/src/main/java/org/elasticsearch/xpack/core}/rollup/job/TermsGroupConfig.java (100%) rename x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/{GetRollupCapsRequestTests.java => GetRollupCapsActionRequestTests.java} (84%) delete mode 100644 x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/GetRollupCapsResponseTests.java rename x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/{PutRollupJobRequestTests.java => PutJobActionRequestTests.java} (57%) delete mode 100644 x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/PutRollupJobResponseTests.java delete mode 100644 x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/TransportPutRollupJobActionTests.java delete mode 100644 x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/PutRollupJobRequest.java delete mode 100644 x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/package-info.java 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 0421a603a1f79..7c525dffd1b4a 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.GetRollupCapsRequest; +import org.elasticsearch.client.rollup.GetRollupCapsResponse; import org.elasticsearch.client.rollup.PutRollupJobRequest; import org.elasticsearch.client.rollup.PutRollupJobResponse; @@ -84,8 +86,8 @@ public void putRollupJobAsync(PutRollupJobRequest request, RequestOptions option * @throws IOException in case there is a problem sending the request or parsing back the response */ public GetRollupCapsResponse getRollupCapabilities(GetRollupCapsRequest request, RequestOptions options) throws IOException { - return restHighLevelClient.performRequestAndParseEntity(request, RequestConverters::getRollupCaps, options, - GetRollupCapsResponse::fromXContent, emptySet()); + return restHighLevelClient.performRequestAndParseEntity(request, RollupRequestConverters::getRollupCaps, options, + GetRollupCapsResponse::fromXContent, Collections.emptySet()); } /** @@ -98,7 +100,7 @@ public GetRollupCapsResponse getRollupCapabilities(GetRollupCapsRequest request, */ public void getRollupCapabilitiesAsync(GetRollupCapsRequest request, RequestOptions options, ActionListener listener) { - restHighLevelClient.performRequestAsyncAndParseEntity(request, RequestConverters::getRollupCaps, options, - GetRollupCapsResponse::fromXContent, listener, emptySet()); + restHighLevelClient.performRequestAsyncAndParseEntity(request, RollupRequestConverters::getRollupCaps, options, + GetRollupCapsResponse::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..1198764261f72 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,7 +18,9 @@ */ package org.elasticsearch.client; +import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPut; +import org.elasticsearch.client.rollup.GetRollupCapsRequest; import org.elasticsearch.client.rollup.PutRollupJobRequest; import java.io.IOException; @@ -42,4 +44,16 @@ static Request putJob(final PutRollupJobRequest putRollupJobRequest) throws IOEx request.setEntity(createEntity(putRollupJobRequest, REQUEST_BODY_CONTENT_TYPE)); return request; } + + static Request getRollupCaps(GetRollupCapsRequest getRollupCapsRequest) throws IOException { + String endpoint = new RequestConverters.EndpointBuilder() + .addPathPartAsIs("_xpack") + .addPathPartAsIs("rollup") + .addPathPartAsIs("data") + .addPathPart(getRollupCapsRequest.getIndexPattern()) + .build(); + Request request = new Request(HttpGet.METHOD_NAME, endpoint); + request.setEntity(createEntity(getRollupCapsRequest, REQUEST_BODY_CONTENT_TYPE)); + return request; + } } diff --git a/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/GetRollupCapsRequest.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/GetRollupCapsRequest.java similarity index 92% rename from x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/GetRollupCapsRequest.java rename to client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/GetRollupCapsRequest.java index da3805c6c5fe6..180bce036983a 100644 --- a/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/GetRollupCapsRequest.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/GetRollupCapsRequest.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.elasticsearch.protocol.xpack.rollup; +package org.elasticsearch.client.rollup; import org.elasticsearch.action.ActionRequest; import org.elasticsearch.action.ActionRequestValidationException; @@ -24,14 +24,15 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; -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 class GetRollupCapsRequest extends ActionRequest implements ToXContent { +public class GetRollupCapsRequest extends ActionRequest implements ToXContentObject { private String indexPattern; + private static final String ID = "id"; public GetRollupCapsRequest(String indexPattern) { if (Strings.isNullOrEmpty(indexPattern) || indexPattern.equals("*")) { @@ -66,7 +67,7 @@ public ActionRequestValidationException validate() { @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { - builder.field(RollupField.ID.getPreferredName(), indexPattern); + builder.field(ID, indexPattern); return builder; } diff --git a/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/GetRollupCapsResponse.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/GetRollupCapsResponse.java similarity index 98% rename from x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/GetRollupCapsResponse.java rename to client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/GetRollupCapsResponse.java index 35c02267b371b..d2896de64924a 100644 --- a/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/GetRollupCapsResponse.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/GetRollupCapsResponse.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.elasticsearch.protocol.xpack.rollup; +package org.elasticsearch.client.rollup; import org.elasticsearch.action.ActionResponse; import org.elasticsearch.common.Strings; diff --git a/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/RollableIndexCaps.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/RollableIndexCaps.java similarity index 98% rename from x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/RollableIndexCaps.java rename to client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/RollableIndexCaps.java index 14b13e86e1dd3..5e0a41ee9d61b 100644 --- a/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/RollableIndexCaps.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/RollableIndexCaps.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.elasticsearch.protocol.xpack.rollup; +package org.elasticsearch.client.rollup; import org.elasticsearch.common.ParseField; import org.elasticsearch.common.io.stream.StreamInput; diff --git a/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/RollupJobCaps.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/RollupJobCaps.java similarity index 74% rename from x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/RollupJobCaps.java rename to client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/RollupJobCaps.java index 78b0cc58ca036..f037d33b6e86e 100644 --- a/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/RollupJobCaps.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/RollupJobCaps.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.elasticsearch.protocol.xpack.rollup; +package org.elasticsearch.client.rollup; import org.elasticsearch.common.ParseField; import org.elasticsearch.common.collect.Tuple; @@ -27,18 +27,15 @@ import org.elasticsearch.common.xcontent.ToXContentObject; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.protocol.xpack.rollup.job.RollupJobConfig; import java.io.IOException; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.function.Function; -import java.util.stream.Collectors; /** * Represents the Rollup capabilities for a specific job on a single rollup index @@ -75,59 +72,7 @@ public class RollupJobCaps implements Writeable, ToXContentObject { private String indexPattern; private Map fieldCapLookup; - // TODO now that these rollup caps are being used more widely (e.g. search), perhaps we should - // store the RollupJob and translate into FieldCaps on demand for json output. Would make working with - // it internally a lot easier - public RollupJobCaps(RollupJobConfig job) { - Map>> tempFieldCaps = new HashMap<>(); - - jobID = job.getId(); - rollupIndex = job.getRollupIndex(); - indexPattern = job.getIndexPattern(); - Map dateHistoAggCap = job.getGroupConfig().getDateHistogram().toAggCap(); - String dateField = job.getGroupConfig().getDateHistogram().getField(); - List> fieldCaps = tempFieldCaps.getOrDefault(dateField, new ArrayList<>()); - fieldCaps.add(dateHistoAggCap); - tempFieldCaps.put(dateField, fieldCaps); - - if (job.getGroupConfig().getHistogram() != null) { - Map histoAggCap = job.getGroupConfig().getHistogram().toAggCap(); - Arrays.stream(job.getGroupConfig().getHistogram().getFields()).forEach(field -> { - List> caps = tempFieldCaps.getOrDefault(field, new ArrayList<>()); - caps.add(histoAggCap); - tempFieldCaps.put(field, caps); - }); - } - - if (job.getGroupConfig().getTerms() != null) { - Map termsAggCap = job.getGroupConfig().getTerms().toAggCap(); - Arrays.stream(job.getGroupConfig().getTerms().getFields()).forEach(field -> { - List> caps = tempFieldCaps.getOrDefault(field, new ArrayList<>()); - caps.add(termsAggCap); - tempFieldCaps.put(field, caps); - }); - } - - if (job.getMetricsConfig().size() > 0) { - job.getMetricsConfig().forEach(metricConfig -> { - List> metrics = metricConfig.toAggCap(); - metrics.forEach(m -> { - List> caps = tempFieldCaps - .getOrDefault(metricConfig.getField(), new ArrayList<>()); - caps.add(m); - tempFieldCaps.put(metricConfig.getField(), caps); - }); - }); - } - - // Convert the temp lists into RollupFieldCaps - this.fieldCapLookup = Collections.unmodifiableMap(tempFieldCaps.entrySet() - .stream() - .collect(Collectors.toMap(Map.Entry::getKey, - e -> new RollupFieldCaps(e.getValue())))); - } - - public RollupJobCaps(String jobID, String rollupIndex, String indexPattern, Map fieldCapLookup) { + RollupJobCaps(String jobID, String rollupIndex, String indexPattern, Map fieldCapLookup) { this.jobID = jobID; this.rollupIndex = rollupIndex; this.indexPattern = indexPattern; 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 7049fab7f0457..69c052f4f1c5b 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.action.admin.cluster.health.ClusterHealthRequest; import org.elasticsearch.action.admin.indices.refresh.RefreshRequest; import org.elasticsearch.action.admin.indices.refresh.RefreshResponse; import org.elasticsearch.action.bulk.BulkItemResponse; @@ -27,8 +28,12 @@ import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.support.WriteRequest; +import org.elasticsearch.client.rollup.GetRollupCapsRequest; +import org.elasticsearch.client.rollup.GetRollupCapsResponse; import org.elasticsearch.client.rollup.PutRollupJobRequest; import org.elasticsearch.client.rollup.PutRollupJobResponse; +import org.elasticsearch.client.rollup.RollableIndexCaps; +import org.elasticsearch.client.rollup.RollupJobCaps; import org.elasticsearch.client.rollup.job.config.DateHistogramGroupConfig; import org.elasticsearch.client.rollup.job.config.GroupConfig; import org.elasticsearch.client.rollup.job.config.MetricConfig; @@ -45,11 +50,14 @@ import java.util.Arrays; import java.util.Collections; +import java.util.HashSet; import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.Set; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; +import static org.hamcrest.Matchers.equalTo; public class RollupIT extends ESRestHighLevelClientTestCase { 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 63fb02c0080c3..ae3567634e851 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,8 +29,12 @@ import org.elasticsearch.client.ESRestHighLevelClientTestCase; import org.elasticsearch.client.RequestOptions; import org.elasticsearch.client.RestHighLevelClient; +import org.elasticsearch.client.rollup.GetRollupCapsRequest; +import org.elasticsearch.client.rollup.GetRollupCapsResponse; import org.elasticsearch.client.rollup.PutRollupJobRequest; import org.elasticsearch.client.rollup.PutRollupJobResponse; +import org.elasticsearch.client.rollup.RollableIndexCaps; +import org.elasticsearch.client.rollup.RollupJobCaps; import org.elasticsearch.client.rollup.job.config.DateHistogramGroupConfig; import org.elasticsearch.client.rollup.job.config.GroupConfig; import org.elasticsearch.client.rollup.job.config.HistogramGroupConfig; @@ -47,10 +51,12 @@ import java.util.Arrays; import java.util.List; import java.util.Locale; +import java.util.Map; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; +import static org.hamcrest.Matchers.equalTo; public class RollupDocumentationIT extends ESRestHighLevelClientTestCase { diff --git a/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/PutRollupJobResponse.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/rollup/GetRollupCapsRequestTests.java similarity index 56% rename from x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/PutRollupJobResponse.java rename to client/rest-high-level/src/test/java/org/elasticsearch/client/rollup/GetRollupCapsRequestTests.java index a298cb20919c4..1e6afaffd5e8c 100644 --- a/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/PutRollupJobResponse.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/rollup/GetRollupCapsRequestTests.java @@ -16,22 +16,28 @@ * specific language governing permissions and limitations * under the License. */ -package org.elasticsearch.protocol.xpack.rollup; +package org.elasticsearch.client.rollup; -import org.elasticsearch.action.support.master.AcknowledgedResponse; -import org.elasticsearch.common.xcontent.XContentParser; -public class PutRollupJobResponse extends AcknowledgedResponse { +import org.elasticsearch.cluster.metadata.MetaData; +import org.elasticsearch.test.AbstractStreamableTestCase; - public PutRollupJobResponse() { - super(); - } - public PutRollupJobResponse(final boolean acknowledged) { - super(acknowledged); +public class GetRollupCapsRequestTests extends AbstractStreamableTestCase { + + @Override + protected GetRollupCapsRequest createTestInstance() { + if (randomBoolean()) { + return new GetRollupCapsRequest(MetaData.ALL); + } + return new GetRollupCapsRequest(randomAlphaOfLengthBetween(1, 20)); } - public static PutRollupJobResponse fromXContent(final XContentParser parser) { - return new PutRollupJobResponse(parseAcknowledged(parser)); + @Override + protected GetRollupCapsRequest createBlankInstance() { + return new GetRollupCapsRequest(); } + } + + diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/rollup/GetRollupCapsResponseTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/rollup/GetRollupCapsResponseTests.java new file mode 100644 index 0000000000000..b64957783a30f --- /dev/null +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/rollup/GetRollupCapsResponseTests.java @@ -0,0 +1,157 @@ +/* + * 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.rollup.job.config.DateHistogramGroupConfig; +import org.elasticsearch.client.rollup.job.config.GroupConfig; +import org.elasticsearch.client.rollup.job.config.HistogramGroupConfig; +import org.elasticsearch.client.rollup.job.config.MetricConfig; +import org.elasticsearch.client.rollup.job.config.RollupJobConfig; +import org.elasticsearch.client.rollup.job.config.RollupJobConfigTests; +import org.elasticsearch.client.rollup.job.config.TermsGroupConfig; +import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramAggregationBuilder; +import org.elasticsearch.search.aggregations.bucket.histogram.HistogramAggregationBuilder; +import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder; +import org.elasticsearch.test.AbstractStreamableXContentTestCase; +import org.junit.Before; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import static java.util.Collections.singletonMap; + +public class GetRollupCapsResponseTests extends AbstractStreamableXContentTestCase { + + private Map indices; + + @Before + private void setupIndices() throws IOException { + int numIndices = randomIntBetween(1,5); + indices = new HashMap<>(numIndices); + for (int i = 0; i < numIndices; i++) { + String indexName = "index_" + randomAlphaOfLength(10); + int numJobs = randomIntBetween(1,5); + List jobs = new ArrayList<>(numJobs); + for (int j = 0; j < numJobs; j++) { + RollupJobConfig config = RollupJobConfigTests.randomRollupJobConfig(randomAlphaOfLength(10)); + jobs.add(new RollupJobCaps(config.getId(), config.getIndexPattern(), + config.getRollupIndex(), createRollupFieldCaps(config))); + } + RollableIndexCaps cap = new RollableIndexCaps(indexName, jobs); + indices.put(indexName, cap); + } + } + + @Override + protected GetRollupCapsResponse createTestInstance() { + return new GetRollupCapsResponse(indices); + } + + @Override + protected boolean supportsUnknownFields() { + return false; + } + + @Override + protected GetRollupCapsResponse createBlankInstance() { + return new GetRollupCapsResponse(); + } + + @Override + protected GetRollupCapsResponse doParseInstance(final XContentParser parser) throws IOException { + return GetRollupCapsResponse.fromXContent(parser); + } + + /** + * Lifted from core's RollupJobCaps, so that we can test without having to include this actual logic in the request + */ + private static Map createRollupFieldCaps(final RollupJobConfig rollupJobConfig) { + final Map>> tempFieldCaps = new HashMap<>(); + + final GroupConfig groupConfig = rollupJobConfig.getGroupConfig(); + if (groupConfig != null) { + // Create RollupFieldCaps for the date histogram + final DateHistogramGroupConfig dateHistogram = groupConfig.getDateHistogram(); + final Map dateHistogramAggCap = new HashMap<>(); + dateHistogramAggCap.put("agg", DateHistogramAggregationBuilder.NAME); + dateHistogramAggCap.put("interval", dateHistogram.getInterval().toString()); + if (dateHistogram.getDelay() != null) { + dateHistogramAggCap.put("delay", dateHistogram.getDelay().toString()); + } + dateHistogramAggCap.put("time_zone", dateHistogram.getTimeZone()); + + List> dateAggCaps = tempFieldCaps.getOrDefault(dateHistogram.getField(), new ArrayList<>()); + dateAggCaps.add(dateHistogramAggCap); + tempFieldCaps.put(dateHistogram.getField(), dateAggCaps); + + // Create RollupFieldCaps for the histogram + final HistogramGroupConfig histogram = groupConfig.getHistogram(); + if (histogram != null) { + final Map histogramAggCap = new HashMap<>(); + histogramAggCap.put("agg", HistogramAggregationBuilder.NAME); + histogramAggCap.put("interval", histogram.getInterval()); + Arrays.stream(rollupJobConfig.getGroupConfig().getHistogram().getFields()).forEach(field -> { + List> caps = tempFieldCaps.getOrDefault(field, new ArrayList<>()); + caps.add(histogramAggCap); + tempFieldCaps.put(field, caps); + }); + } + + // Create RollupFieldCaps for the term + final TermsGroupConfig terms = groupConfig.getTerms(); + if (terms != null) { + final Map termsAggCap = singletonMap("agg", TermsAggregationBuilder.NAME); + Arrays.stream(rollupJobConfig.getGroupConfig().getTerms().getFields()).forEach(field -> { + List> caps = tempFieldCaps.getOrDefault(field, new ArrayList<>()); + caps.add(termsAggCap); + tempFieldCaps.put(field, caps); + }); + } + } + + // Create RollupFieldCaps for the metrics + final List metricsConfig = rollupJobConfig.getMetricsConfig(); + if (metricsConfig.size() > 0) { + rollupJobConfig.getMetricsConfig().forEach(metricConfig -> { + final List> metrics = metricConfig.getMetrics().stream() + .map(metric -> singletonMap("agg", (Object) metric)) + .collect(Collectors.toList()); + metrics.forEach(m -> { + List> caps = tempFieldCaps + .getOrDefault(metricConfig.getField(), new ArrayList<>()); + caps.add(m); + tempFieldCaps.put(metricConfig.getField(), caps); + }); + }); + } + + return Collections.unmodifiableMap(tempFieldCaps.entrySet() + .stream() + .collect(Collectors.toMap(Map.Entry::getKey, + e -> new RollupJobCaps.RollupFieldCaps(e.getValue())))); + } + +} diff --git a/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/RollupField.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/RollupField.java similarity index 84% rename from x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/RollupField.java rename to x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/RollupField.java index 35556f6343c2e..8b23a0cfff39c 100644 --- a/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/RollupField.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/RollupField.java @@ -1,22 +1,9 @@ /* - * 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. + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.protocol.xpack.rollup; +package org.elasticsearch.xpack.core.rollup; import org.elasticsearch.common.ParseField; import org.elasticsearch.index.mapper.NumberFieldMapper; diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/DeleteRollupJobAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/DeleteRollupJobAction.java index 4c80f2ad99e12..df2c70c76539e 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/DeleteRollupJobAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/DeleteRollupJobAction.java @@ -16,8 +16,8 @@ import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.protocol.xpack.rollup.RollupField; import org.elasticsearch.xpack.core.ml.utils.ExceptionsHelper; +import org.elasticsearch.xpack.core.rollup.RollupField; import java.io.IOException; import java.util.Objects; diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/GetRollupCapsAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/GetRollupCapsAction.java index 9ff8eb9570000..28db1bfaf4941 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/GetRollupCapsAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/GetRollupCapsAction.java @@ -6,13 +6,28 @@ package org.elasticsearch.xpack.core.rollup.action; import org.elasticsearch.action.Action; +import org.elasticsearch.action.ActionRequest; import org.elasticsearch.action.ActionRequestBuilder; +import org.elasticsearch.action.ActionRequestValidationException; +import org.elasticsearch.action.ActionResponse; import org.elasticsearch.client.ElasticsearchClient; +import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.common.ParseField; -import org.elasticsearch.protocol.xpack.rollup.GetRollupCapsRequest; -import org.elasticsearch.protocol.xpack.rollup.GetRollupCapsResponse; +import org.elasticsearch.common.Strings; +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.common.io.stream.Writeable; +import org.elasticsearch.common.xcontent.ToXContent; +import org.elasticsearch.common.xcontent.ToXContentObject; +import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.xpack.core.rollup.RollupField; -public class GetRollupCapsAction extends Action { +import java.io.IOException; +import java.util.Collections; +import java.util.Map; +import java.util.Objects; + +public class GetRollupCapsAction extends Action { public static final GetRollupCapsAction INSTANCE = new GetRollupCapsAction(); public static final String NAME = "cluster:monitor/xpack/rollup/get/caps"; @@ -24,14 +39,131 @@ private GetRollupCapsAction() { } @Override - public GetRollupCapsResponse newResponse() { - return new GetRollupCapsResponse(); + public Response newResponse() { + return new Response(); } - public static class RequestBuilder extends ActionRequestBuilder { + public static class Request extends ActionRequest implements ToXContent { + private String indexPattern; + + public Request(String indexPattern) { + if (Strings.isNullOrEmpty(indexPattern) || indexPattern.equals("*")) { + this.indexPattern = MetaData.ALL; + } else { + this.indexPattern = indexPattern; + } + } + + public Request() {} + + public String getIndexPattern() { + return indexPattern; + } + + @Override + public void readFrom(StreamInput in) throws IOException { + super.readFrom(in); + this.indexPattern = in.readString(); + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); + out.writeString(indexPattern); + } + + @Override + public ActionRequestValidationException validate() { + return null; + } + + @Override + public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { + builder.field(RollupField.ID.getPreferredName(), indexPattern); + return builder; + } + + @Override + public int hashCode() { + return Objects.hash(indexPattern); + } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + Request other = (Request) obj; + return Objects.equals(indexPattern, other.indexPattern); + } + } + + public static class RequestBuilder extends ActionRequestBuilder { protected RequestBuilder(ElasticsearchClient client, GetRollupCapsAction action) { - super(client, action, new GetRollupCapsRequest()); + super(client, action, new Request()); + } + } + + public static class Response extends ActionResponse implements Writeable, ToXContentObject { + + private Map jobs = Collections.emptyMap(); + + public Response() { + + } + + public Response(Map jobs) { + this.jobs = Objects.requireNonNull(jobs); + } + + Response(StreamInput in) throws IOException { + jobs = in.readMap(StreamInput::readString, RollableIndexCaps::new); + } + + public Map getJobs() { + return jobs; + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); + out.writeMap(jobs, StreamOutput::writeString, (out1, value) -> value.writeTo(out1)); + } + + @Override + public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { + builder.startObject(); + for (Map.Entry entry : jobs.entrySet()) { + entry.getValue().toXContent(builder, params); + } + builder.endObject(); + return builder; + } + + @Override + public int hashCode() { + return Objects.hash(jobs); + } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + Response other = (Response) obj; + return Objects.equals(jobs, other.jobs); + } + + @Override + public final String toString() { + return Strings.toString(this); } } } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/GetRollupIndexCapsAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/GetRollupIndexCapsAction.java index 361bf27c1e637..4f95919c4986b 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/GetRollupIndexCapsAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/GetRollupIndexCapsAction.java @@ -22,8 +22,7 @@ import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContentObject; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.protocol.xpack.rollup.RollableIndexCaps; -import org.elasticsearch.protocol.xpack.rollup.RollupField; +import org.elasticsearch.xpack.core.rollup.RollupField; import java.io.IOException; import java.util.Arrays; diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/RollableIndexCaps.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/RollableIndexCaps.java new file mode 100644 index 0000000000000..5ecf721eec916 --- /dev/null +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/RollableIndexCaps.java @@ -0,0 +1,88 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ +package org.elasticsearch.xpack.core.rollup.action; + +import org.elasticsearch.common.ParseField; +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.common.io.stream.Writeable; +import org.elasticsearch.common.xcontent.ToXContentFragment; +import org.elasticsearch.common.xcontent.XContentBuilder; + +import java.io.IOException; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; +import java.util.Objects; + +/** + * Represents the rollup capabilities of a non-rollup index. E.g. what values/aggregations + * were rolled up for this index, in what rollup jobs that data is stored and where those + * concrete rollup indices exist + * + * The index name can either be a single index, or an index pattern (logstash-*) + */ +public class RollableIndexCaps implements Writeable, ToXContentFragment { + private static final ParseField ROLLUP_JOBS = new ParseField("rollup_jobs"); + + private String indexName; + private List jobCaps; + + public RollableIndexCaps(String indexName, List caps) { + this.indexName = indexName; + this.jobCaps = Objects.requireNonNull(caps); + this.jobCaps.sort(Comparator.comparing(RollupJobCaps::getJobID)); + this.jobCaps = Collections.unmodifiableList(jobCaps); + } + + public RollableIndexCaps(StreamInput in) throws IOException { + this.indexName = in.readString(); + this.jobCaps = in.readList(RollupJobCaps::new); + } + + public String getIndexName() { + return indexName; + } + + public List getJobCaps() { + return jobCaps; + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + out.writeString(indexName); + out.writeList(jobCaps); + } + + @Override + public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { + builder.startObject(indexName); + builder.field(ROLLUP_JOBS.getPreferredName(), jobCaps); + builder.endObject(); + return builder; + } + + @Override + public boolean equals(Object other) { + if (this == other) { + return true; + } + + if (other == null || getClass() != other.getClass()) { + return false; + } + + RollableIndexCaps that = (RollableIndexCaps) other; + + return Objects.deepEquals(this.jobCaps, that.jobCaps) + && Objects.equals(this.indexName, that.indexName); + } + + @Override + public int hashCode() { + return Objects.hash(jobCaps, indexName); + } +} diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/RollupJobCaps.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/RollupJobCaps.java index 054d08df999f3..a783ef712057f 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/RollupJobCaps.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/RollupJobCaps.java @@ -23,6 +23,7 @@ import java.io.IOException; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -56,6 +57,13 @@ public RollupJobCaps(RollupJobConfig job) { fieldCapLookup = createRollupFieldCaps(job); } + public RollupJobCaps(String jobID, String rollupIndex, String indexPattern, Map fieldCapLookup) { + this.jobID = jobID; + this.rollupIndex = rollupIndex; + this.indexPattern = indexPattern; + this.fieldCapLookup = Collections.unmodifiableMap(Objects.requireNonNull(fieldCapLookup)); + } + public RollupJobCaps(StreamInput in) throws IOException { this.jobID = in.readString(); this.rollupIndex = in.readString(); @@ -124,8 +132,8 @@ public int hashCode() { return Objects.hash(jobID, rollupIndex, fieldCapLookup); } - static Map createRollupFieldCaps(final RollupJobConfig rollupJobConfig) { - final Map fieldCapLookup = new HashMap<>(); + private static Map createRollupFieldCaps(final RollupJobConfig rollupJobConfig) { + final Map>> tempFieldCaps = new HashMap<>(); final GroupConfig groupConfig = rollupJobConfig.getGroupConfig(); if (groupConfig != null) { @@ -139,9 +147,9 @@ static Map createRollupFieldCaps(final RollupJobConfig } dateHistogramAggCap.put(DateHistogramGroupConfig.TIME_ZONE, dateHistogram.getTimeZone()); - final RollupFieldCaps dateHistogramFieldCaps = new RollupFieldCaps(); - dateHistogramFieldCaps.addAgg(dateHistogramAggCap); - fieldCapLookup.put(dateHistogram.getField(), dateHistogramFieldCaps); + List> dateAggCaps = tempFieldCaps.getOrDefault(dateHistogram.getField(), new ArrayList<>()); + dateAggCaps.add(dateHistogramAggCap); + tempFieldCaps.put(dateHistogram.getField(), dateAggCaps); // Create RollupFieldCaps for the histogram final HistogramGroupConfig histogram = groupConfig.getHistogram(); @@ -149,57 +157,50 @@ static Map createRollupFieldCaps(final RollupJobConfig final Map histogramAggCap = new HashMap<>(); histogramAggCap.put("agg", HistogramAggregationBuilder.NAME); histogramAggCap.put(HistogramGroupConfig.INTERVAL, histogram.getInterval()); - for (String field : histogram.getFields()) { - RollupFieldCaps caps = fieldCapLookup.get(field); - if (caps == null) { - caps = new RollupFieldCaps(); - } - caps.addAgg(histogramAggCap); - fieldCapLookup.put(field, caps); - } + Arrays.stream(rollupJobConfig.getGroupConfig().getHistogram().getFields()).forEach(field -> { + List> caps = tempFieldCaps.getOrDefault(field, new ArrayList<>()); + caps.add(histogramAggCap); + tempFieldCaps.put(field, caps); + }); } // Create RollupFieldCaps for the term final TermsGroupConfig terms = groupConfig.getTerms(); if (terms != null) { final Map termsAggCap = singletonMap("agg", TermsAggregationBuilder.NAME); - for (String field : terms.getFields()) { - RollupFieldCaps caps = fieldCapLookup.get(field); - if (caps == null) { - caps = new RollupFieldCaps(); - } - caps.addAgg(termsAggCap); - fieldCapLookup.put(field, caps); - } + Arrays.stream(rollupJobConfig.getGroupConfig().getTerms().getFields()).forEach(field -> { + List> caps = tempFieldCaps.getOrDefault(field, new ArrayList<>()); + caps.add(termsAggCap); + tempFieldCaps.put(field, caps); + }); } } // Create RollupFieldCaps for the metrics final List metricsConfig = rollupJobConfig.getMetricsConfig(); if (metricsConfig.size() > 0) { - metricsConfig.forEach(metricConfig -> { - final List> metrics = metricConfig.getMetrics().stream() - .map(metric -> singletonMap("agg", (Object) metric)) - .collect(Collectors.toList()); - - metrics.forEach(m -> { - RollupFieldCaps caps = fieldCapLookup.get(metricConfig.getField()); - if (caps == null) { - caps = new RollupFieldCaps(); - } - caps.addAgg(m); - fieldCapLookup.put(metricConfig.getField(), caps); + rollupJobConfig.getMetricsConfig().forEach(metricConfig -> { + final List> metrics = metricConfig.getMetrics().stream() + .map(metric -> singletonMap("agg", (Object) metric)) + .collect(Collectors.toList()); + metrics.forEach(m -> { + List> caps = tempFieldCaps + .getOrDefault(metricConfig.getField(), new ArrayList<>()); + caps.add(m); + tempFieldCaps.put(metricConfig.getField(), caps); + }); }); - }); } - return Collections.unmodifiableMap(fieldCapLookup); + + return Collections.unmodifiableMap(tempFieldCaps.entrySet() + .stream() + .collect(Collectors.toMap(Map.Entry::getKey, + e -> new RollupFieldCaps(e.getValue())))); } public static class RollupFieldCaps implements Writeable, ToXContentObject { private List> aggs = new ArrayList<>(); - RollupFieldCaps() { } - RollupFieldCaps(StreamInput in) throws IOException { int size = in.readInt(); aggs = new ArrayList<>(size); @@ -208,8 +209,8 @@ public static class RollupFieldCaps implements Writeable, ToXContentObject { } } - void addAgg(Map agg) { - aggs.add(agg); + RollupFieldCaps(List> aggs) { + this.aggs = Collections.unmodifiableList(Objects.requireNonNull(aggs)); } public List> getAggs() { diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/StartRollupJobAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/StartRollupJobAction.java index b0b15aa4dd428..e3dcb1a882f9f 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/StartRollupJobAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/StartRollupJobAction.java @@ -19,7 +19,7 @@ import org.elasticsearch.common.xcontent.ToXContentObject; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.xpack.core.ml.utils.ExceptionsHelper; -import org.elasticsearch.protocol.xpack.rollup.RollupField; +import org.elasticsearch.xpack.core.rollup.RollupField; import java.io.IOException; import java.util.Collections; diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/StopRollupJobAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/StopRollupJobAction.java index 8378dfa4cb244..eb48d640f21eb 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/StopRollupJobAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/StopRollupJobAction.java @@ -18,7 +18,7 @@ import org.elasticsearch.common.xcontent.ToXContentObject; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.xpack.core.ml.utils.ExceptionsHelper; -import org.elasticsearch.protocol.xpack.rollup.RollupField; +import org.elasticsearch.xpack.core.rollup.RollupField; import java.io.IOException; import java.util.Collections; diff --git a/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/job/DateHistogramGroupConfig.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/job/DateHistogramGroupConfig.java similarity index 100% rename from x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/job/DateHistogramGroupConfig.java rename to x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/job/DateHistogramGroupConfig.java diff --git a/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/job/GroupConfig.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/job/GroupConfig.java similarity index 88% rename from x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/job/GroupConfig.java rename to x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/job/GroupConfig.java index df267f8f89d96..b7c69ecda0ee2 100644 --- a/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/job/GroupConfig.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/job/GroupConfig.java @@ -1,22 +1,9 @@ /* - * 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. + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.protocol.xpack.rollup.job; +package org.elasticsearch.xpack.core.rollup.job; import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.action.fieldcaps.FieldCapabilities; diff --git a/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/job/HistogramGroupConfig.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/job/HistogramGroupConfig.java similarity index 100% rename from x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/job/HistogramGroupConfig.java rename to x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/job/HistogramGroupConfig.java diff --git a/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/job/MetricConfig.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/job/MetricConfig.java similarity index 100% rename from x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/job/MetricConfig.java rename to x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/job/MetricConfig.java diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/job/RollupJob.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/job/RollupJob.java index 8e5bb34f160fc..94306966a34da 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/job/RollupJob.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/job/RollupJob.java @@ -14,7 +14,6 @@ import org.elasticsearch.common.xcontent.ConstructingObjectParser; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.protocol.xpack.rollup.job.RollupJobConfig; import org.elasticsearch.xpack.core.XPackPlugin; import java.io.IOException; diff --git a/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/job/RollupJobConfig.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/job/RollupJobConfig.java similarity index 92% rename from x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/job/RollupJobConfig.java rename to x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/job/RollupJobConfig.java index 20669533189e9..51a4736e3adee 100644 --- a/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/job/RollupJobConfig.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/job/RollupJobConfig.java @@ -1,22 +1,9 @@ /* - * 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. + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. */ -package org.elasticsearch.protocol.xpack.rollup.job; +package org.elasticsearch.xpack.core.rollup.job; import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.action.fieldcaps.FieldCapabilities; diff --git a/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/job/TermsGroupConfig.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/job/TermsGroupConfig.java similarity index 100% rename from x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/job/TermsGroupConfig.java rename to x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/job/TermsGroupConfig.java diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/rollup/ConfigTestHelpers.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/rollup/ConfigTestHelpers.java index e43c78d5352ad..d892eb550a17a 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/rollup/ConfigTestHelpers.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/rollup/ConfigTestHelpers.java @@ -7,14 +7,14 @@ import com.carrotsearch.randomizedtesting.generators.RandomNumbers; import org.elasticsearch.common.unit.TimeValue; -import org.elasticsearch.protocol.xpack.rollup.job.DateHistogramGroupConfig; -import org.elasticsearch.protocol.xpack.rollup.job.GroupConfig; -import org.elasticsearch.protocol.xpack.rollup.job.HistogramGroupConfig; -import org.elasticsearch.protocol.xpack.rollup.job.MetricConfig; -import org.elasticsearch.protocol.xpack.rollup.job.RollupJobConfig; -import org.elasticsearch.protocol.xpack.rollup.job.TermsGroupConfig; import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval; import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.xpack.core.rollup.job.DateHistogramGroupConfig; +import org.elasticsearch.xpack.core.rollup.job.GroupConfig; +import org.elasticsearch.xpack.core.rollup.job.HistogramGroupConfig; +import org.elasticsearch.xpack.core.rollup.job.MetricConfig; +import org.elasticsearch.xpack.core.rollup.job.RollupJobConfig; +import org.elasticsearch.xpack.core.rollup.job.TermsGroupConfig; import java.util.ArrayList; import java.util.Arrays; diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/rollup/job/DateHistogramGroupConfigSerializingTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/rollup/job/DateHistogramGroupConfigSerializingTests.java index 7889d11268991..415e1a00a60cf 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/rollup/job/DateHistogramGroupConfigSerializingTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/rollup/job/DateHistogramGroupConfigSerializingTests.java @@ -11,7 +11,6 @@ import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.protocol.xpack.rollup.job.DateHistogramGroupConfig; import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval; import org.elasticsearch.test.AbstractSerializingTestCase; import org.elasticsearch.xpack.core.rollup.ConfigTestHelpers; @@ -22,7 +21,6 @@ import java.util.HashMap; import java.util.Map; -import static org.apache.lucene.util.LuceneTestCase.random; import static org.elasticsearch.xpack.core.rollup.ConfigTestHelpers.randomDateHistogramGroupConfig; import static org.hamcrest.Matchers.equalTo; import static org.mockito.Mockito.mock; diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/rollup/job/GroupConfigSerializingTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/rollup/job/GroupConfigSerializingTests.java index bff5f3ddd7f6d..49ea206ded767 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/rollup/job/GroupConfigSerializingTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/rollup/job/GroupConfigSerializingTests.java @@ -7,7 +7,6 @@ import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.protocol.xpack.rollup.job.GroupConfig; import org.elasticsearch.test.AbstractSerializingTestCase; import java.io.IOException; diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/rollup/job/HistogramGroupConfigSerializingTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/rollup/job/HistogramGroupConfigSerializingTests.java index 8f886a7431d06..ef81b235b1fba 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/rollup/job/HistogramGroupConfigSerializingTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/rollup/job/HistogramGroupConfigSerializingTests.java @@ -9,9 +9,8 @@ import org.elasticsearch.action.fieldcaps.FieldCapabilities; import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.protocol.xpack.rollup.RollupField; -import org.elasticsearch.protocol.xpack.rollup.job.HistogramGroupConfig; import org.elasticsearch.test.AbstractSerializingTestCase; +import org.elasticsearch.xpack.core.rollup.RollupField; import java.io.IOException; import java.util.Collections; diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/rollup/job/MetricConfigSerializingTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/rollup/job/MetricConfigSerializingTests.java index 8146a64530d94..a5b8d9afead2e 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/rollup/job/MetricConfigSerializingTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/rollup/job/MetricConfigSerializingTests.java @@ -9,7 +9,6 @@ import org.elasticsearch.action.fieldcaps.FieldCapabilities; import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.protocol.xpack.rollup.job.MetricConfig; import org.elasticsearch.test.AbstractSerializingTestCase; import org.elasticsearch.xpack.core.rollup.ConfigTestHelpers; diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/rollup/job/RollupJobConfigTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/rollup/job/RollupJobConfigTests.java index 6086132fd03c0..09d00e11fef92 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/rollup/job/RollupJobConfigTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/rollup/job/RollupJobConfigTests.java @@ -7,7 +7,6 @@ import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.protocol.xpack.rollup.job.RollupJobConfig; import org.elasticsearch.test.AbstractSerializingTestCase; import org.junit.Before; diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/rollup/job/TermsGroupConfigSerializingTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/rollup/job/TermsGroupConfigSerializingTests.java index ab65d666597d5..f817f83574070 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/rollup/job/TermsGroupConfigSerializingTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/rollup/job/TermsGroupConfigSerializingTests.java @@ -19,6 +19,7 @@ import static org.elasticsearch.xpack.core.rollup.ConfigTestHelpers.randomTermsGroupConfig; import static org.hamcrest.Matchers.equalTo; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; public class TermsGroupConfigSerializingTests extends AbstractSerializingTestCase { @@ -104,9 +105,6 @@ public void testValidateMatchingField() { if (e.validationErrors().size() != 0) { fail(e.getMessage()); } - - List> builders = config.toBuilders(); - assertThat(builders.size(), equalTo(1)); } private String getRandomType() { diff --git a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/Rollup.java b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/Rollup.java index e42d9d7b5d1be..09b2ccd079a76 100644 --- a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/Rollup.java +++ b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/Rollup.java @@ -35,7 +35,7 @@ import org.elasticsearch.watcher.ResourceWatcherService; import org.elasticsearch.xpack.core.XPackPlugin; import org.elasticsearch.xpack.core.XPackSettings; -import org.elasticsearch.protocol.xpack.rollup.RollupField; +import org.elasticsearch.xpack.core.rollup.RollupField; import org.elasticsearch.xpack.core.rollup.action.DeleteRollupJobAction; import org.elasticsearch.xpack.core.rollup.action.GetRollupCapsAction; import org.elasticsearch.xpack.core.rollup.action.GetRollupIndexCapsAction; diff --git a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/RollupJobIdentifierUtils.java b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/RollupJobIdentifierUtils.java index 912a524fc6668..232034177e87b 100644 --- a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/RollupJobIdentifierUtils.java +++ b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/RollupJobIdentifierUtils.java @@ -7,15 +7,15 @@ import org.elasticsearch.common.rounding.DateTimeUnit; import org.elasticsearch.common.unit.TimeValue; -import org.elasticsearch.protocol.xpack.rollup.RollupField; -import org.elasticsearch.protocol.xpack.rollup.RollupJobCaps; -import org.elasticsearch.protocol.xpack.rollup.job.DateHistogramGroupConfig; import org.elasticsearch.search.aggregations.AggregationBuilder; import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramAggregationBuilder; import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval; import org.elasticsearch.search.aggregations.bucket.histogram.HistogramAggregationBuilder; import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder; import org.elasticsearch.search.aggregations.support.ValuesSourceAggregationBuilder; +import org.elasticsearch.xpack.core.rollup.RollupField; +import org.elasticsearch.xpack.core.rollup.action.RollupJobCaps; +import org.elasticsearch.xpack.core.rollup.job.DateHistogramGroupConfig; import org.joda.time.DateTimeZone; import java.util.ArrayList; diff --git a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/RollupRequestTranslator.java b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/RollupRequestTranslator.java index 89940a668c65b..44e67cc619cf7 100644 --- a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/RollupRequestTranslator.java +++ b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/RollupRequestTranslator.java @@ -12,8 +12,6 @@ import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.index.query.TermQueryBuilder; -import org.elasticsearch.protocol.xpack.rollup.RollupField; -import org.elasticsearch.protocol.xpack.rollup.job.DateHistogramGroupConfig; import org.elasticsearch.search.aggregations.AggregationBuilder; import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramAggregationBuilder; import org.elasticsearch.search.aggregations.bucket.histogram.HistogramAggregationBuilder; @@ -21,6 +19,8 @@ import org.elasticsearch.search.aggregations.metrics.AvgAggregationBuilder; import org.elasticsearch.search.aggregations.metrics.SumAggregationBuilder; import org.elasticsearch.search.aggregations.support.ValuesSourceAggregationBuilder; +import org.elasticsearch.xpack.core.rollup.RollupField; +import org.elasticsearch.xpack.core.rollup.job.DateHistogramGroupConfig; import org.joda.time.DateTimeZone; import java.util.ArrayList; diff --git a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/RollupResponseTranslator.java b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/RollupResponseTranslator.java index 4eaf2e33644be..41edf220e667e 100644 --- a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/RollupResponseTranslator.java +++ b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/RollupResponseTranslator.java @@ -27,14 +27,14 @@ import org.elasticsearch.search.aggregations.bucket.histogram.InternalHistogram; import org.elasticsearch.search.aggregations.bucket.terms.LongTerms; import org.elasticsearch.search.aggregations.bucket.terms.StringTerms; -import org.elasticsearch.search.aggregations.metrics.InternalNumericMetricsAggregation.SingleValue; import org.elasticsearch.search.aggregations.metrics.InternalAvg; import org.elasticsearch.search.aggregations.metrics.InternalMax; import org.elasticsearch.search.aggregations.metrics.InternalMin; +import org.elasticsearch.search.aggregations.metrics.InternalNumericMetricsAggregation.SingleValue; import org.elasticsearch.search.aggregations.metrics.InternalSum; import org.elasticsearch.search.aggregations.metrics.SumAggregationBuilder; import org.elasticsearch.search.internal.InternalSearchResponse; -import org.elasticsearch.protocol.xpack.rollup.RollupField; +import org.elasticsearch.xpack.core.rollup.RollupField; import java.nio.charset.StandardCharsets; import java.util.ArrayList; diff --git a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/RollupIndexCaps.java b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/RollupIndexCaps.java index cd8b6a8d777ae..88c2986574792 100644 --- a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/RollupIndexCaps.java +++ b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/RollupIndexCaps.java @@ -19,10 +19,10 @@ import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentType; -import org.elasticsearch.protocol.xpack.rollup.RollupField; -import org.elasticsearch.protocol.xpack.rollup.RollupJobCaps; -import org.elasticsearch.protocol.xpack.rollup.job.RollupJobConfig; +import org.elasticsearch.xpack.core.rollup.RollupField; import org.elasticsearch.xpack.core.rollup.action.GetRollupCapsAction; +import org.elasticsearch.xpack.core.rollup.action.RollupJobCaps; +import org.elasticsearch.xpack.core.rollup.job.RollupJobConfig; import java.io.IOException; import java.util.ArrayList; diff --git a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportGetRollupCapsAction.java b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportGetRollupCapsAction.java index d0e2d1a3ccd09..af36d7bc6718c 100644 --- a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportGetRollupCapsAction.java +++ b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportGetRollupCapsAction.java @@ -17,14 +17,12 @@ import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.protocol.xpack.rollup.GetRollupCapsRequest; -import org.elasticsearch.protocol.xpack.rollup.GetRollupCapsResponse; -import org.elasticsearch.protocol.xpack.rollup.RollableIndexCaps; -import org.elasticsearch.protocol.xpack.rollup.RollupField; -import org.elasticsearch.protocol.xpack.rollup.RollupJobCaps; import org.elasticsearch.tasks.Task; import org.elasticsearch.transport.TransportService; +import org.elasticsearch.xpack.core.rollup.RollupField; import org.elasticsearch.xpack.core.rollup.action.GetRollupCapsAction; +import org.elasticsearch.xpack.core.rollup.action.RollableIndexCaps; +import org.elasticsearch.xpack.core.rollup.action.RollupJobCaps; import java.util.ArrayList; import java.util.List; @@ -34,7 +32,7 @@ import java.util.function.Supplier; import java.util.stream.Collectors; -public class TransportGetRollupCapsAction extends HandledTransportAction { +public class TransportGetRollupCapsAction extends HandledTransportAction { private final ClusterService clusterService; @@ -42,14 +40,14 @@ public class TransportGetRollupCapsAction extends HandledTransportAction) GetRollupCapsRequest::new); + (Supplier) GetRollupCapsAction.Request::new); this.clusterService = clusterService; } @Override - protected void doExecute(Task task, GetRollupCapsRequest request, ActionListener listener) { + protected void doExecute(Task task, GetRollupCapsAction.Request request, ActionListener listener) { Map allCaps = getCaps(request.getIndexPattern(), clusterService.state().getMetaData().indices()); - listener.onResponse(new GetRollupCapsResponse(allCaps)); + listener.onResponse(new GetRollupCapsAction.Response(allCaps)); } static Map getCaps(String indexPattern, ImmutableOpenMap indices) { diff --git a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportGetRollupIndexCapsAction.java b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportGetRollupIndexCapsAction.java index 02615bc088cc1..518fe7ec29f0f 100644 --- a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportGetRollupIndexCapsAction.java +++ b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportGetRollupIndexCapsAction.java @@ -14,11 +14,11 @@ import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.protocol.xpack.rollup.RollableIndexCaps; -import org.elasticsearch.protocol.xpack.rollup.RollupJobCaps; import org.elasticsearch.tasks.Task; import org.elasticsearch.transport.TransportService; import org.elasticsearch.xpack.core.rollup.action.GetRollupIndexCapsAction; +import org.elasticsearch.xpack.core.rollup.action.RollableIndexCaps; +import org.elasticsearch.xpack.core.rollup.action.RollupJobCaps; import java.util.ArrayList; import java.util.Arrays; diff --git a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportGetRollupJobAction.java b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportGetRollupJobAction.java index 2ca103f061dcb..0f684de9ea268 100644 --- a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportGetRollupJobAction.java +++ b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportGetRollupJobAction.java @@ -23,7 +23,7 @@ import org.elasticsearch.tasks.Task; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.protocol.xpack.rollup.RollupField; +import org.elasticsearch.xpack.core.rollup.RollupField; import org.elasticsearch.xpack.core.rollup.action.GetRollupJobsAction; import org.elasticsearch.xpack.core.rollup.job.RollupJobStatus; import org.elasticsearch.xpack.rollup.job.RollupJobTask; diff --git a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportRollupSearchAction.java b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportRollupSearchAction.java index 4845e3bf90482..ea0319c34328b 100644 --- a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportRollupSearchAction.java +++ b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportRollupSearchAction.java @@ -39,7 +39,6 @@ import org.elasticsearch.index.query.RangeQueryBuilder; import org.elasticsearch.index.query.TermQueryBuilder; import org.elasticsearch.index.query.TermsQueryBuilder; -import org.elasticsearch.protocol.xpack.rollup.RollupJobCaps; import org.elasticsearch.script.ScriptService; import org.elasticsearch.search.aggregations.AggregationBuilder; import org.elasticsearch.search.aggregations.AggregatorFactories; @@ -54,9 +53,10 @@ import org.elasticsearch.transport.TransportChannel; import org.elasticsearch.transport.TransportRequestHandler; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.protocol.xpack.rollup.RollupField; +import org.elasticsearch.xpack.core.rollup.RollupField; +import org.elasticsearch.xpack.core.rollup.action.RollupJobCaps; import org.elasticsearch.xpack.core.rollup.action.RollupSearchAction; -import org.elasticsearch.protocol.xpack.rollup.job.DateHistogramGroupConfig; +import org.elasticsearch.xpack.core.rollup.job.DateHistogramGroupConfig; import org.elasticsearch.xpack.rollup.Rollup; import org.elasticsearch.xpack.rollup.RollupJobIdentifierUtils; import org.elasticsearch.xpack.rollup.RollupRequestTranslator; diff --git a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestGetRollupCapsAction.java b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestGetRollupCapsAction.java index 3cc3093fdfcf0..0619666ebd1bd 100644 --- a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestGetRollupCapsAction.java +++ b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestGetRollupCapsAction.java @@ -8,13 +8,12 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.ParseField; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.protocol.xpack.rollup.GetRollupCapsRequest; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; -import org.elasticsearch.xpack.rollup.Rollup; import org.elasticsearch.xpack.core.rollup.action.GetRollupCapsAction; +import org.elasticsearch.xpack.rollup.Rollup; import java.io.IOException; @@ -29,7 +28,7 @@ public RestGetRollupCapsAction(Settings settings, RestController controller) { @Override protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient client) throws IOException { String id = restRequest.param(ID.getPreferredName()); - GetRollupCapsRequest request = new GetRollupCapsRequest(id); + GetRollupCapsAction.Request request = new GetRollupCapsAction.Request(id); return channel -> client.execute(GetRollupCapsAction.INSTANCE, request, new RestToXContentListener<>(channel)); } diff --git a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestStartRollupJobAction.java b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestStartRollupJobAction.java index 1127bdaea5348..b64d5a719d1b1 100644 --- a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestStartRollupJobAction.java +++ b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestStartRollupJobAction.java @@ -11,9 +11,9 @@ import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; -import org.elasticsearch.protocol.xpack.rollup.RollupField; -import org.elasticsearch.xpack.rollup.Rollup; +import org.elasticsearch.xpack.core.rollup.RollupField; import org.elasticsearch.xpack.core.rollup.action.StartRollupJobAction; +import org.elasticsearch.xpack.rollup.Rollup; import java.io.IOException; diff --git a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestStopRollupJobAction.java b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestStopRollupJobAction.java index 8ced1db8a6a1e..0f03cdd1ebe2c 100644 --- a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestStopRollupJobAction.java +++ b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestStopRollupJobAction.java @@ -11,9 +11,9 @@ import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; -import org.elasticsearch.protocol.xpack.rollup.RollupField; -import org.elasticsearch.xpack.rollup.Rollup; +import org.elasticsearch.xpack.core.rollup.RollupField; import org.elasticsearch.xpack.core.rollup.action.StopRollupJobAction; +import org.elasticsearch.xpack.rollup.Rollup; import java.io.IOException; diff --git a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/RollupResponseTranslationTests.java b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/RollupResponseTranslationTests.java index 7c4a8411f82f9..576f37d78440e 100644 --- a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/RollupResponseTranslationTests.java +++ b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/RollupResponseTranslationTests.java @@ -56,17 +56,17 @@ import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder; import org.elasticsearch.search.aggregations.metrics.Avg; import org.elasticsearch.search.aggregations.metrics.AvgAggregationBuilder; -import org.elasticsearch.search.aggregations.metrics.InternalAvg; import org.elasticsearch.search.aggregations.metrics.CardinalityAggregationBuilder; import org.elasticsearch.search.aggregations.metrics.GeoBoundsAggregationBuilder; +import org.elasticsearch.search.aggregations.metrics.InternalAvg; import org.elasticsearch.search.aggregations.metrics.InternalMax; +import org.elasticsearch.search.aggregations.metrics.InternalSum; import org.elasticsearch.search.aggregations.metrics.MaxAggregationBuilder; import org.elasticsearch.search.aggregations.metrics.MinAggregationBuilder; -import org.elasticsearch.search.aggregations.metrics.InternalSum; import org.elasticsearch.search.aggregations.metrics.SumAggregationBuilder; import org.elasticsearch.search.aggregations.support.ValueType; import org.elasticsearch.search.internal.InternalSearchResponse; -import org.elasticsearch.protocol.xpack.rollup.RollupField; +import org.elasticsearch.xpack.core.rollup.RollupField; import java.io.IOException; import java.util.ArrayList; @@ -76,7 +76,6 @@ import java.util.Map; import static java.util.Collections.singleton; -import static org.elasticsearch.protocol.xpack.rollup.RollupField.COUNT_FIELD; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.not; import static org.hamcrest.core.IsEqual.equalTo; @@ -144,7 +143,7 @@ public void testMissingLiveIndex() { List subaggs = new ArrayList<>(2); Map metadata = new HashMap<>(1); - metadata.put(RollupField.ROLLUP_META + "." + COUNT_FIELD, "foo." + COUNT_FIELD); + metadata.put(RollupField.ROLLUP_META + "." + RollupField.COUNT_FIELD, "foo." + RollupField.COUNT_FIELD); InternalSum sum = mock(InternalSum.class); when(sum.getValue()).thenReturn(10.0); when(sum.value()).thenReturn(10.0); @@ -156,7 +155,7 @@ public void testMissingLiveIndex() { InternalSum count = mock(InternalSum.class); when(count.getValue()).thenReturn(2.0); when(count.value()).thenReturn(2.0); - when(count.getName()).thenReturn("foo." + COUNT_FIELD); + when(count.getName()).thenReturn("foo." + RollupField.COUNT_FIELD); when(count.getMetaData()).thenReturn(null); when(count.getType()).thenReturn(SumAggregationBuilder.NAME); subaggs.add(count); @@ -243,7 +242,7 @@ public void testTranslateRollup() { List subaggs = new ArrayList<>(2); Map metadata = new HashMap<>(1); - metadata.put(RollupField.ROLLUP_META + "." + COUNT_FIELD, "foo." + COUNT_FIELD); + metadata.put(RollupField.ROLLUP_META + "." + RollupField.COUNT_FIELD, "foo." + RollupField.COUNT_FIELD); InternalSum sum = mock(InternalSum.class); when(sum.getValue()).thenReturn(10.0); when(sum.value()).thenReturn(10.0); @@ -255,7 +254,7 @@ public void testTranslateRollup() { InternalSum count = mock(InternalSum.class); when(count.getValue()).thenReturn(2.0); when(count.value()).thenReturn(2.0); - when(count.getName()).thenReturn("foo." + COUNT_FIELD); + when(count.getName()).thenReturn("foo." + RollupField.COUNT_FIELD); when(count.getMetaData()).thenReturn(null); when(count.getType()).thenReturn(SumAggregationBuilder.NAME); subaggs.add(count); @@ -368,7 +367,7 @@ public void testSimpleReduction() { List subaggs = new ArrayList<>(2); Map metadata = new HashMap<>(1); - metadata.put(RollupField.ROLLUP_META + "." + COUNT_FIELD, "foo." + COUNT_FIELD); + metadata.put(RollupField.ROLLUP_META + "." + RollupField.COUNT_FIELD, "foo." + RollupField.COUNT_FIELD); InternalSum sum = mock(InternalSum.class); when(sum.getValue()).thenReturn(10.0); when(sum.value()).thenReturn(10.0); @@ -380,7 +379,7 @@ public void testSimpleReduction() { InternalSum count = mock(InternalSum.class); when(count.getValue()).thenReturn(2.0); when(count.value()).thenReturn(2.0); - when(count.getName()).thenReturn("foo." + COUNT_FIELD); + when(count.getName()).thenReturn("foo." + RollupField.COUNT_FIELD); when(count.getMetaData()).thenReturn(null); when(count.getType()).thenReturn(SumAggregationBuilder.NAME); subaggs.add(count); @@ -524,8 +523,8 @@ public void testDateHisto() throws IOException { DateHistogramAggregationBuilder rollupHisto = new DateHistogramAggregationBuilder("histo") .field("timestamp.date_histogram." + RollupField.TIMESTAMP) .interval(100) - .subAggregation(new SumAggregationBuilder("histo." + COUNT_FIELD) - .field("timestamp.date_histogram." + COUNT_FIELD)); + .subAggregation(new SumAggregationBuilder("histo." + RollupField.COUNT_FIELD) + .field("timestamp.date_histogram." + RollupField.COUNT_FIELD)); DateFieldMapper.Builder nrBuilder = new DateFieldMapper.Builder("histo"); DateFieldMapper.DateFieldType nrFTtimestamp = nrBuilder.fieldType(); @@ -537,11 +536,11 @@ public void testDateHisto() throws IOException { rFTtimestamp.setHasDocValues(true); rFTtimestamp.setName(rollupHisto.field()); - NumberFieldMapper.Builder valueBuilder = new NumberFieldMapper.Builder("histo." + COUNT_FIELD, + NumberFieldMapper.Builder valueBuilder = new NumberFieldMapper.Builder("histo." + RollupField.COUNT_FIELD, NumberFieldMapper.NumberType.LONG); MappedFieldType rFTvalue = valueBuilder.fieldType(); rFTvalue.setHasDocValues(true); - rFTvalue.setName("timestamp.date_histogram." + COUNT_FIELD); + rFTvalue.setName("timestamp.date_histogram." + RollupField.COUNT_FIELD); List responses = doQueries(new MatchAllDocsQuery(), iw -> { @@ -570,8 +569,8 @@ public void testDateHistoWithGap() throws IOException { .field("timestamp.date_histogram." + RollupField.TIMESTAMP) .interval(100) .minDocCount(0) - .subAggregation(new SumAggregationBuilder("histo." + COUNT_FIELD) - .field("timestamp.date_histogram." + COUNT_FIELD)); + .subAggregation(new SumAggregationBuilder("histo." + RollupField.COUNT_FIELD) + .field("timestamp.date_histogram." + RollupField.COUNT_FIELD)); DateFieldMapper.Builder nrBuilder = new DateFieldMapper.Builder("histo"); DateFieldMapper.DateFieldType nrFTtimestamp = nrBuilder.fieldType(); @@ -583,11 +582,11 @@ public void testDateHistoWithGap() throws IOException { rFTtimestamp.setHasDocValues(true); rFTtimestamp.setName(rollupHisto.field()); - NumberFieldMapper.Builder valueBuilder = new NumberFieldMapper.Builder("histo." + COUNT_FIELD, + NumberFieldMapper.Builder valueBuilder = new NumberFieldMapper.Builder("histo." + RollupField.COUNT_FIELD, NumberFieldMapper.NumberType.LONG); MappedFieldType rFTvalue = valueBuilder.fieldType(); rFTvalue.setHasDocValues(true); - rFTvalue.setName("timestamp.date_histogram." + COUNT_FIELD); + rFTvalue.setName("timestamp.date_histogram." + RollupField.COUNT_FIELD); List responses = doQueries(new MatchAllDocsQuery(), iw -> { @@ -627,8 +626,8 @@ public void testNonMatchingPartition() throws IOException { .field("timestamp.date_histogram." + RollupField.TIMESTAMP) .interval(100) .minDocCount(0) - .subAggregation(new SumAggregationBuilder("histo." + COUNT_FIELD) - .field("timestamp.date_histogram." + COUNT_FIELD)); + .subAggregation(new SumAggregationBuilder("histo." + RollupField.COUNT_FIELD) + .field("timestamp.date_histogram." + RollupField.COUNT_FIELD)); DateFieldMapper.Builder nrBuilder = new DateFieldMapper.Builder("histo"); DateFieldMapper.DateFieldType nrFTtimestamp = nrBuilder.fieldType(); @@ -640,11 +639,11 @@ public void testNonMatchingPartition() throws IOException { rFTtimestamp.setHasDocValues(true); rFTtimestamp.setName(rollupHisto.field()); - NumberFieldMapper.Builder valueBuilder = new NumberFieldMapper.Builder("histo." + COUNT_FIELD, + NumberFieldMapper.Builder valueBuilder = new NumberFieldMapper.Builder("histo." + RollupField.COUNT_FIELD, NumberFieldMapper.NumberType.LONG); MappedFieldType rFTvalue = valueBuilder.fieldType(); rFTvalue.setHasDocValues(true); - rFTvalue.setName("timestamp.date_histogram." + COUNT_FIELD); + rFTvalue.setName("timestamp.date_histogram." + RollupField.COUNT_FIELD); KeywordFieldMapper.Builder nrKeywordBuilder = new KeywordFieldMapper.Builder("partition"); KeywordFieldMapper.KeywordFieldType nrKeywordFT = nrKeywordBuilder.fieldType(); @@ -691,33 +690,33 @@ public void testNonMatchingPartition() throws IOException { // Time 100: Two "a" documents, one "b" doc Document doc = new Document(); doc.add(new SortedNumericDocValuesField("timestamp.date_histogram." + RollupField.TIMESTAMP, 100)); - doc.add(new SortedNumericDocValuesField("timestamp.date_histogram." + COUNT_FIELD, 2)); + doc.add(new SortedNumericDocValuesField("timestamp.date_histogram." + RollupField.COUNT_FIELD, 2)); doc.add(new SortedNumericDocValuesField("timestamp.date_histogram." + RollupField.INTERVAL, 1)); doc.add(new TextField("partition.terms." + RollupField.VALUE, "a", Field.Store.NO)); - doc.add(new SortedNumericDocValuesField("partition.terms." + COUNT_FIELD, 2)); + doc.add(new SortedNumericDocValuesField("partition.terms." + RollupField.COUNT_FIELD, 2)); iw.addDocument(doc); doc = new Document(); doc.add(new SortedNumericDocValuesField("timestamp.date_histogram." + RollupField.TIMESTAMP, 100)); - doc.add(new SortedNumericDocValuesField("timestamp.date_histogram." + COUNT_FIELD, 1)); + doc.add(new SortedNumericDocValuesField("timestamp.date_histogram." + RollupField.COUNT_FIELD, 1)); doc.add(new SortedNumericDocValuesField("timestamp.date_histogram." + RollupField.INTERVAL, 1)); doc.add(new TextField("partition.terms." + RollupField.VALUE, "b", Field.Store.NO)); - doc.add(new SortedNumericDocValuesField("partition.terms." + COUNT_FIELD, 1)); + doc.add(new SortedNumericDocValuesField("partition.terms." + RollupField.COUNT_FIELD, 1)); iw.addDocument(doc); // Time 200: one "a" document, one "b" doc doc = new Document(); doc.add(new SortedNumericDocValuesField("timestamp.date_histogram." + RollupField.TIMESTAMP, 200)); - doc.add(new SortedNumericDocValuesField("timestamp.date_histogram." + COUNT_FIELD, 1)); + doc.add(new SortedNumericDocValuesField("timestamp.date_histogram." + RollupField.COUNT_FIELD, 1)); doc.add(new SortedNumericDocValuesField("timestamp.date_histogram." + RollupField.INTERVAL, 1)); doc.add(new TextField("partition.terms." + RollupField.VALUE, "a", Field.Store.NO)); - doc.add(new SortedNumericDocValuesField("partition.terms." + COUNT_FIELD, 1)); + doc.add(new SortedNumericDocValuesField("partition.terms." + RollupField.COUNT_FIELD, 1)); iw.addDocument(doc); doc = new Document(); doc.add(new SortedNumericDocValuesField("timestamp.date_histogram." + RollupField.TIMESTAMP, 200)); - doc.add(new SortedNumericDocValuesField("timestamp.date_histogram." + COUNT_FIELD, 1)); + doc.add(new SortedNumericDocValuesField("timestamp.date_histogram." + RollupField.COUNT_FIELD, 1)); doc.add(new SortedNumericDocValuesField("timestamp.date_histogram." + RollupField.INTERVAL, 1)); doc.add(new TextField("partition.terms." + RollupField.VALUE, "b", Field.Store.NO)); - doc.add(new SortedNumericDocValuesField("partition.terms." + COUNT_FIELD, 1)); + doc.add(new SortedNumericDocValuesField("partition.terms." + RollupField.COUNT_FIELD, 1)); iw.addDocument(doc); }, rollupHisto, new MappedFieldType[]{rFTtimestamp, rFTvalue, rKeywordFT})); @@ -738,8 +737,8 @@ public void testDateHistoOverlappingAggTrees() throws IOException { DateHistogramAggregationBuilder rollupHisto = new DateHistogramAggregationBuilder("histo") .field("timestamp.date_histogram." + RollupField.TIMESTAMP) .interval(100) - .subAggregation(new SumAggregationBuilder("histo." + COUNT_FIELD) - .field("timestamp.date_histogram." + COUNT_FIELD)); + .subAggregation(new SumAggregationBuilder("histo." + RollupField.COUNT_FIELD) + .field("timestamp.date_histogram." + RollupField.COUNT_FIELD)); DateFieldMapper.Builder nrBuilder = new DateFieldMapper.Builder("histo"); DateFieldMapper.DateFieldType nrFTtimestamp = nrBuilder.fieldType(); @@ -751,11 +750,11 @@ public void testDateHistoOverlappingAggTrees() throws IOException { rFTtimestamp.setHasDocValues(true); rFTtimestamp.setName(rollupHisto.field()); - NumberFieldMapper.Builder valueBuilder = new NumberFieldMapper.Builder("histo." + COUNT_FIELD, + NumberFieldMapper.Builder valueBuilder = new NumberFieldMapper.Builder("histo." + RollupField.COUNT_FIELD, NumberFieldMapper.NumberType.LONG); MappedFieldType rFTvalue = valueBuilder.fieldType(); rFTvalue.setHasDocValues(true); - rFTvalue.setName("timestamp.date_histogram." + COUNT_FIELD); + rFTvalue.setName("timestamp.date_histogram." + RollupField.COUNT_FIELD); List responses = doQueries(new MatchAllDocsQuery(), iw -> { @@ -799,8 +798,8 @@ public void testDateHistoOverlappingMergeRealIntoZero() throws IOException { DateHistogramAggregationBuilder rollupHisto = new DateHistogramAggregationBuilder("histo") .field("timestamp.date_histogram." + RollupField.TIMESTAMP) .interval(100) - .subAggregation(new SumAggregationBuilder("histo." + COUNT_FIELD) - .field("timestamp.date_histogram." + COUNT_FIELD)); + .subAggregation(new SumAggregationBuilder("histo." + RollupField.COUNT_FIELD) + .field("timestamp.date_histogram." + RollupField.COUNT_FIELD)); DateFieldMapper.Builder nrBuilder = new DateFieldMapper.Builder("histo"); DateFieldMapper.DateFieldType nrFTtimestamp = nrBuilder.fieldType(); @@ -812,11 +811,11 @@ public void testDateHistoOverlappingMergeRealIntoZero() throws IOException { rFTtimestamp.setHasDocValues(true); rFTtimestamp.setName(rollupHisto.field()); - NumberFieldMapper.Builder valueBuilder = new NumberFieldMapper.Builder("histo." + COUNT_FIELD, + NumberFieldMapper.Builder valueBuilder = new NumberFieldMapper.Builder("histo." + RollupField.COUNT_FIELD, NumberFieldMapper.NumberType.LONG); MappedFieldType rFTvalue = valueBuilder.fieldType(); rFTvalue.setHasDocValues(true); - rFTvalue.setName("timestamp.date_histogram." + COUNT_FIELD); + rFTvalue.setName("timestamp.date_histogram." + RollupField.COUNT_FIELD); List responses = doQueries(new MatchAllDocsQuery(), iw -> { @@ -835,13 +834,13 @@ public void testDateHistoOverlappingMergeRealIntoZero() throws IOException { iw -> { Document doc = new Document(); doc.add(new SortedNumericDocValuesField("timestamp.date_histogram." + RollupField.TIMESTAMP, 100)); - doc.add(new SortedNumericDocValuesField("timestamp.date_histogram." + COUNT_FIELD, 0)); + doc.add(new SortedNumericDocValuesField("timestamp.date_histogram." + RollupField.COUNT_FIELD, 0)); doc.add(new SortedNumericDocValuesField("timestamp.date_histogram." + RollupField.INTERVAL, 1)); iw.addDocument(doc); Document doc2 = new Document(); doc2.add(new SortedNumericDocValuesField("timestamp.date_histogram." + RollupField.TIMESTAMP, 200)); - doc2.add(new SortedNumericDocValuesField("timestamp.date_histogram." + COUNT_FIELD, 0)); + doc2.add(new SortedNumericDocValuesField("timestamp.date_histogram." + RollupField.COUNT_FIELD, 0)); doc2.add(new SortedNumericDocValuesField("timestamp.date_histogram." + RollupField.INTERVAL, 1)); iw.addDocument(doc2); @@ -867,8 +866,8 @@ public void testDateHistoOverlappingMergeZeroIntoReal() throws IOException { .field("timestamp.date_histogram." + RollupField.TIMESTAMP) .interval(100) .minDocCount(0) - .subAggregation(new SumAggregationBuilder("histo." + COUNT_FIELD) - .field("timestamp.date_histogram." + COUNT_FIELD)); + .subAggregation(new SumAggregationBuilder("histo." + RollupField.COUNT_FIELD) + .field("timestamp.date_histogram." + RollupField.COUNT_FIELD)); DateFieldMapper.Builder nrBuilder = new DateFieldMapper.Builder("histo"); DateFieldMapper.DateFieldType nrFTtimestamp = nrBuilder.fieldType(); @@ -880,11 +879,11 @@ public void testDateHistoOverlappingMergeZeroIntoReal() throws IOException { rFTtimestamp.setHasDocValues(true); rFTtimestamp.setName(rollupHisto.field()); - NumberFieldMapper.Builder valueBuilder = new NumberFieldMapper.Builder("histo." + COUNT_FIELD, + NumberFieldMapper.Builder valueBuilder = new NumberFieldMapper.Builder("histo." + RollupField.COUNT_FIELD, NumberFieldMapper.NumberType.LONG); MappedFieldType rFTvalue = valueBuilder.fieldType(); rFTvalue.setHasDocValues(true); - rFTvalue.setName("timestamp.date_histogram." + COUNT_FIELD); + rFTvalue.setName("timestamp.date_histogram." + RollupField.COUNT_FIELD); InternalAggregation currentTree = doQuery(new MatchAllDocsQuery(), iw -> { @@ -897,13 +896,13 @@ public void testDateHistoOverlappingMergeZeroIntoReal() throws IOException { iw -> { Document doc = new Document(); doc.add(new SortedNumericDocValuesField("timestamp.date_histogram." + RollupField.TIMESTAMP, 100)); - doc.add(new SortedNumericDocValuesField("timestamp.date_histogram." + COUNT_FIELD, 0)); + doc.add(new SortedNumericDocValuesField("timestamp.date_histogram." + RollupField.COUNT_FIELD, 0)); doc.add(new SortedNumericDocValuesField("timestamp.date_histogram." + RollupField.INTERVAL, 1)); iw.addDocument(doc); Document doc2 = new Document(); doc2.add(new SortedNumericDocValuesField("timestamp.date_histogram." + RollupField.TIMESTAMP, 200)); - doc2.add(new SortedNumericDocValuesField("timestamp.date_histogram." + COUNT_FIELD, 0)); + doc2.add(new SortedNumericDocValuesField("timestamp.date_histogram." + RollupField.COUNT_FIELD, 0)); doc2.add(new SortedNumericDocValuesField("timestamp.date_histogram." + RollupField.INTERVAL, 1)); iw.addDocument(doc2); @@ -1050,8 +1049,8 @@ public void testStringTerms() throws IOException { TermsAggregationBuilder rollupTerms = new TermsAggregationBuilder("terms", ValueType.STRING) .field("stringfield.terms." + RollupField.VALUE) - .subAggregation(new SumAggregationBuilder("terms." + COUNT_FIELD) - .field("stringfield.terms." + COUNT_FIELD)); + .subAggregation(new SumAggregationBuilder("terms." + RollupField.COUNT_FIELD) + .field("stringfield.terms." + RollupField.COUNT_FIELD)); KeywordFieldMapper.Builder nrBuilder = new KeywordFieldMapper.Builder("terms"); KeywordFieldMapper.KeywordFieldType nrFTterm = nrBuilder.fieldType(); @@ -1063,11 +1062,11 @@ public void testStringTerms() throws IOException { rFTterm.setHasDocValues(true); rFTterm.setName(rollupTerms.field()); - NumberFieldMapper.Builder valueBuilder = new NumberFieldMapper.Builder("terms." + COUNT_FIELD, + NumberFieldMapper.Builder valueBuilder = new NumberFieldMapper.Builder("terms." + RollupField.COUNT_FIELD, NumberFieldMapper.NumberType.LONG); MappedFieldType rFTvalue = valueBuilder.fieldType(); rFTvalue.setHasDocValues(true); - rFTvalue.setName("stringfield.terms." + COUNT_FIELD); + rFTvalue.setName("stringfield.terms." + RollupField.COUNT_FIELD); List responses = doQueries(new MatchAllDocsQuery(), iw -> { @@ -1091,8 +1090,8 @@ public void testStringTermsNullValue() throws IOException { TermsAggregationBuilder rollupTerms = new TermsAggregationBuilder("terms", ValueType.STRING) .field("stringfield.terms." + RollupField.VALUE) - .subAggregation(new SumAggregationBuilder("terms." + COUNT_FIELD) - .field("stringfield.terms." + COUNT_FIELD)); + .subAggregation(new SumAggregationBuilder("terms." + RollupField.COUNT_FIELD) + .field("stringfield.terms." + RollupField.COUNT_FIELD)); KeywordFieldMapper.Builder nrBuilder = new KeywordFieldMapper.Builder("terms"); KeywordFieldMapper.KeywordFieldType nrFTterm = nrBuilder.fieldType(); @@ -1104,11 +1103,11 @@ public void testStringTermsNullValue() throws IOException { rFTterm.setHasDocValues(true); rFTterm.setName(rollupTerms.field()); - NumberFieldMapper.Builder valueBuilder = new NumberFieldMapper.Builder("terms." + COUNT_FIELD, + NumberFieldMapper.Builder valueBuilder = new NumberFieldMapper.Builder("terms." + RollupField.COUNT_FIELD, NumberFieldMapper.NumberType.LONG); MappedFieldType rFTvalue = valueBuilder.fieldType(); rFTvalue.setHasDocValues(true); - rFTvalue.setName("stringfield.terms." + COUNT_FIELD); + rFTvalue.setName("stringfield.terms." + RollupField.COUNT_FIELD); List responses = doQueries(new MatchAllDocsQuery(), iw -> { @@ -1139,8 +1138,8 @@ public void testLongTerms() throws IOException { TermsAggregationBuilder rollupTerms = new TermsAggregationBuilder("terms", ValueType.LONG) .field("longfield.terms." + RollupField.VALUE) - .subAggregation(new SumAggregationBuilder("terms." + COUNT_FIELD) - .field("longfield.terms." + COUNT_FIELD)); + .subAggregation(new SumAggregationBuilder("terms." + RollupField.COUNT_FIELD) + .field("longfield.terms." + RollupField.COUNT_FIELD)); NumberFieldMapper.Builder nrBuilder = new NumberFieldMapper.Builder("terms", NumberFieldMapper.NumberType.LONG); MappedFieldType nrFTterm = nrBuilder.fieldType(); @@ -1152,11 +1151,11 @@ public void testLongTerms() throws IOException { rFTterm.setHasDocValues(true); rFTterm.setName(rollupTerms.field()); - NumberFieldMapper.Builder valueBuilder = new NumberFieldMapper.Builder("terms." + COUNT_FIELD, + NumberFieldMapper.Builder valueBuilder = new NumberFieldMapper.Builder("terms." + RollupField.COUNT_FIELD, NumberFieldMapper.NumberType.LONG); MappedFieldType rFTvalue = valueBuilder.fieldType(); rFTvalue.setHasDocValues(true); - rFTvalue.setName("longfield.terms." + COUNT_FIELD); + rFTvalue.setName("longfield.terms." + RollupField.COUNT_FIELD); List responses = doQueries(new MatchAllDocsQuery(), iw -> { @@ -1181,8 +1180,8 @@ public void testHisto() throws IOException { HistogramAggregationBuilder rollupHisto = new HistogramAggregationBuilder("histo") .field("bar.histogram." + RollupField.VALUE) .interval(100) - .subAggregation(new SumAggregationBuilder("histo." + COUNT_FIELD) - .field("bar.histogram." + COUNT_FIELD)); + .subAggregation(new SumAggregationBuilder("histo." + RollupField.COUNT_FIELD) + .field("bar.histogram." + RollupField.COUNT_FIELD)); NumberFieldMapper.Builder nrBuilder = new NumberFieldMapper.Builder("histo", NumberFieldMapper.NumberType.LONG); MappedFieldType nrFTbar = nrBuilder.fieldType(); @@ -1194,11 +1193,11 @@ public void testHisto() throws IOException { rFTbar.setHasDocValues(true); rFTbar.setName(rollupHisto.field()); - NumberFieldMapper.Builder valueBuilder = new NumberFieldMapper.Builder("histo." + COUNT_FIELD, + NumberFieldMapper.Builder valueBuilder = new NumberFieldMapper.Builder("histo." + RollupField.COUNT_FIELD, NumberFieldMapper.NumberType.LONG); MappedFieldType rFTvalue = valueBuilder.fieldType(); rFTvalue.setHasDocValues(true); - rFTvalue.setName("bar.histogram." + COUNT_FIELD); + rFTvalue.setName("bar.histogram." + RollupField.COUNT_FIELD); List responses = doQueries(new MatchAllDocsQuery(), iw -> { @@ -1225,8 +1224,8 @@ public void testOverlappingBuckets() throws IOException { DateHistogramAggregationBuilder rollupHisto = new DateHistogramAggregationBuilder("histo") .field("timestamp.date_histogram." + RollupField.TIMESTAMP) .interval(100) - .subAggregation(new SumAggregationBuilder("histo." + COUNT_FIELD) - .field("timestamp.date_histogram." + COUNT_FIELD)); + .subAggregation(new SumAggregationBuilder("histo." + RollupField.COUNT_FIELD) + .field("timestamp.date_histogram." + RollupField.COUNT_FIELD)); DateFieldMapper.Builder nrBuilder = new DateFieldMapper.Builder("histo"); DateFieldMapper.DateFieldType nrFTtimestamp = nrBuilder.fieldType(); @@ -1238,11 +1237,11 @@ public void testOverlappingBuckets() throws IOException { rFTtimestamp.setHasDocValues(true); rFTtimestamp.setName(rollupHisto.field()); - NumberFieldMapper.Builder valueBuilder = new NumberFieldMapper.Builder("histo." + COUNT_FIELD, + NumberFieldMapper.Builder valueBuilder = new NumberFieldMapper.Builder("histo." + RollupField.COUNT_FIELD, NumberFieldMapper.NumberType.LONG); MappedFieldType rFTvalue = valueBuilder.fieldType(); rFTvalue.setHasDocValues(true); - rFTvalue.setName("timestamp.date_histogram." + COUNT_FIELD); + rFTvalue.setName("timestamp.date_histogram." + RollupField.COUNT_FIELD); List responses = doQueries(new MatchAllDocsQuery(), iw -> { @@ -1278,15 +1277,15 @@ private Document timestampedValueDoc(long timestamp, long value) { private Document timestampedValueRollupDoc(long timestamp, long value) { Document doc = new Document(); doc.add(new SortedNumericDocValuesField("timestamp.date_histogram." + RollupField.TIMESTAMP, timestamp)); - doc.add(new SortedNumericDocValuesField("timestamp.date_histogram." + COUNT_FIELD, 1)); + doc.add(new SortedNumericDocValuesField("timestamp.date_histogram." + RollupField.COUNT_FIELD, 1)); doc.add(new SortedNumericDocValuesField("timestamp.date_histogram." + RollupField.INTERVAL, 1)); doc.add(new SortedNumericDocValuesField("foo.avg." + RollupField.VALUE, value)); - doc.add(new SortedNumericDocValuesField("foo.avg." + COUNT_FIELD, 3)); + doc.add(new SortedNumericDocValuesField("foo.avg." + RollupField.COUNT_FIELD, 3)); doc.add(new SortedNumericDocValuesField("foo.min." + RollupField.VALUE, value)); doc.add(new SortedNumericDocValuesField("foo.max." + RollupField.VALUE, value)); doc.add(new SortedNumericDocValuesField("foo.sum." + RollupField.VALUE, value)); doc.add(new SortedNumericDocValuesField("bar.histogram." + RollupField.VALUE, value)); - doc.add(new SortedNumericDocValuesField("bar.histogram." + COUNT_FIELD, 1)); + doc.add(new SortedNumericDocValuesField("bar.histogram." + RollupField.COUNT_FIELD, 1)); doc.add(new SortedNumericDocValuesField("bar.histogram." + RollupField.INTERVAL, 1)); return doc; } @@ -1300,7 +1299,7 @@ private Document stringValueDoc(String stringValue) { private Document stringValueRollupDoc(String stringValue, long docCount) { Document doc = new Document(); doc.add(new SortedSetDocValuesField("stringfield.terms." + RollupField.VALUE, new BytesRef(stringValue))); - doc.add(new SortedNumericDocValuesField("stringfield.terms." + COUNT_FIELD, docCount)); + doc.add(new SortedNumericDocValuesField("stringfield.terms." + RollupField.COUNT_FIELD, docCount)); return doc; } @@ -1313,7 +1312,7 @@ private Document longValueDoc(Long longValue) { private Document longValueRollupDoc(Long longValue, long docCount) { Document doc = new Document(); doc.add(new SortedNumericDocValuesField("longfield.terms." + RollupField.VALUE, longValue)); - doc.add(new SortedNumericDocValuesField("longfield.terms." + COUNT_FIELD, docCount)); + doc.add(new SortedNumericDocValuesField("longfield.terms." + RollupField.COUNT_FIELD, docCount)); return doc; } diff --git a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/GetRollupCapsRequestTests.java b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/GetRollupCapsActionRequestTests.java similarity index 84% rename from x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/GetRollupCapsRequestTests.java rename to x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/GetRollupCapsActionRequestTests.java index f7f300e686a96..fd0021513e814 100644 --- a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/GetRollupCapsRequestTests.java +++ b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/GetRollupCapsActionRequestTests.java @@ -10,12 +10,12 @@ import org.elasticsearch.cluster.metadata.MappingMetaData; import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.common.collect.ImmutableOpenMap; -import org.elasticsearch.protocol.xpack.rollup.GetRollupCapsRequest; -import org.elasticsearch.protocol.xpack.rollup.RollableIndexCaps; -import org.elasticsearch.protocol.xpack.rollup.RollupField; -import org.elasticsearch.protocol.xpack.rollup.job.RollupJobConfig; import org.elasticsearch.test.AbstractStreamableTestCase; import org.elasticsearch.xpack.core.rollup.ConfigTestHelpers; +import org.elasticsearch.xpack.core.rollup.RollupField; +import org.elasticsearch.xpack.core.rollup.action.GetRollupCapsAction; +import org.elasticsearch.xpack.core.rollup.action.RollableIndexCaps; +import org.elasticsearch.xpack.core.rollup.job.RollupJobConfig; import org.mockito.Mockito; import java.io.IOException; @@ -27,19 +27,19 @@ import static org.hamcrest.Matchers.equalTo; -public class GetRollupCapsRequestTests extends AbstractStreamableTestCase { +public class GetRollupCapsActionRequestTests extends AbstractStreamableTestCase { @Override - protected GetRollupCapsRequest createTestInstance() { + protected GetRollupCapsAction.Request createTestInstance() { if (randomBoolean()) { - return new GetRollupCapsRequest(MetaData.ALL); + return new GetRollupCapsAction.Request(MetaData.ALL); } - return new GetRollupCapsRequest(randomAlphaOfLengthBetween(1, 20)); + return new GetRollupCapsAction.Request(randomAlphaOfLengthBetween(1, 20)); } @Override - protected GetRollupCapsRequest createBlankInstance() { - return new GetRollupCapsRequest(); + protected GetRollupCapsAction.Request createBlankInstance() { + return new GetRollupCapsAction.Request(); } public void testNoIndexMetaData() { @@ -75,8 +75,8 @@ public void testMissingJob() throws IOException { String indexPattern = randomBoolean() ? randomAlphaOfLength(10) : randomAlphaOfLength(10) + "-*"; MappingMetaData mappingMeta = new MappingMetaData(RollupField.NAME, Collections.singletonMap(RollupField.NAME, - Collections.singletonMap("_meta", - Collections.emptyMap()))); + Collections.singletonMap("_meta", + Collections.emptyMap()))); ImmutableOpenMap.Builder mappings = ImmutableOpenMap.builder(1); mappings.put(RollupField.NAME, mappingMeta); @@ -92,10 +92,10 @@ public void testOneJob() throws IOException { RollupJobConfig job = ConfigTestHelpers.randomRollupJobConfig(random(), jobName); MappingMetaData mappingMeta = new MappingMetaData(RollupField.TYPE_NAME, - Collections.singletonMap(RollupField.TYPE_NAME, - Collections.singletonMap("_meta", - Collections.singletonMap(RollupField.ROLLUP_META, - Collections.singletonMap(jobName, job))))); + Collections.singletonMap(RollupField.TYPE_NAME, + Collections.singletonMap("_meta", + Collections.singletonMap(RollupField.ROLLUP_META, + Collections.singletonMap(jobName, job))))); ImmutableOpenMap.Builder mappings = ImmutableOpenMap.builder(1); mappings.put(RollupField.TYPE_NAME, mappingMeta); @@ -117,9 +117,9 @@ public void testMultipleJobs() throws IOException { } MappingMetaData mappingMeta = new MappingMetaData(RollupField.TYPE_NAME, - Collections.singletonMap(RollupField.TYPE_NAME, - Collections.singletonMap("_meta", - Collections.singletonMap(RollupField.ROLLUP_META, jobs)))); + Collections.singletonMap(RollupField.TYPE_NAME, + Collections.singletonMap("_meta", + Collections.singletonMap(RollupField.ROLLUP_META, jobs)))); ImmutableOpenMap.Builder mappings = ImmutableOpenMap.builder(1); mappings.put(RollupField.TYPE_NAME, mappingMeta); @@ -151,9 +151,9 @@ public void testAllIndices() throws IOException { } MappingMetaData mappingMeta = new MappingMetaData(RollupField.TYPE_NAME, - Collections.singletonMap(RollupField.TYPE_NAME, - Collections.singletonMap("_meta", - Collections.singletonMap(RollupField.ROLLUP_META, jobs)))); + Collections.singletonMap(RollupField.TYPE_NAME, + Collections.singletonMap("_meta", + Collections.singletonMap(RollupField.ROLLUP_META, jobs)))); ImmutableOpenMap.Builder mappings = ImmutableOpenMap.builder(1); mappings.put(RollupField.TYPE_NAME, mappingMeta); @@ -183,9 +183,9 @@ public void testOneIndex() throws IOException { } MappingMetaData mappingMeta = new MappingMetaData(RollupField.TYPE_NAME, - Collections.singletonMap(RollupField.TYPE_NAME, - Collections.singletonMap("_meta", - Collections.singletonMap(RollupField.ROLLUP_META, jobs)))); + Collections.singletonMap(RollupField.TYPE_NAME, + Collections.singletonMap("_meta", + Collections.singletonMap(RollupField.ROLLUP_META, jobs)))); ImmutableOpenMap.Builder mappings = ImmutableOpenMap.builder(1); mappings.put(RollupField.TYPE_NAME, mappingMeta); diff --git a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/GetRollupCapsResponseTests.java b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/GetRollupCapsResponseTests.java deleted file mode 100644 index df2791891e188..0000000000000 --- a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/GetRollupCapsResponseTests.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ -package org.elasticsearch.xpack.rollup.action; - -import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.protocol.xpack.rollup.GetRollupCapsResponse; -import org.elasticsearch.protocol.xpack.rollup.RollableIndexCaps; -import org.elasticsearch.protocol.xpack.rollup.RollupJobCaps; -import org.elasticsearch.test.AbstractStreamableXContentTestCase; -import org.elasticsearch.xpack.core.rollup.ConfigTestHelpers; -import org.junit.Before; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public class GetRollupCapsResponseTests extends AbstractStreamableXContentTestCase { - - private Map indices; - - @Before - private void setupIndices() { - int numIndices = randomIntBetween(1,5); - indices = new HashMap<>(numIndices); - for (int i = 0; i < numIndices; i++) { - String indexName = "index_" + randomAlphaOfLength(10); - int numJobs = randomIntBetween(1,5); - List jobs = new ArrayList<>(numJobs); - for (int j = 0; j < numJobs; j++) { - jobs.add(new RollupJobCaps(ConfigTestHelpers.randomRollupJobConfig(random()))); - } - RollableIndexCaps cap = new RollableIndexCaps(indexName, jobs); - indices.put(indexName, cap); - } - } - - @Override - protected GetRollupCapsResponse createTestInstance() { - return new GetRollupCapsResponse(indices); - } - - @Override - protected boolean supportsUnknownFields() { - return false; - } - - @Override - protected GetRollupCapsResponse createBlankInstance() { - return new GetRollupCapsResponse(); - } - - @Override - protected GetRollupCapsResponse doParseInstance(final XContentParser parser) throws IOException { - return GetRollupCapsResponse.fromXContent(parser); - } - - -} diff --git a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/GetRollupIndexCapsActionRequestTests.java b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/GetRollupIndexCapsActionRequestTests.java index 80257389edf1a..e9d5d6153b18c 100644 --- a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/GetRollupIndexCapsActionRequestTests.java +++ b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/GetRollupIndexCapsActionRequestTests.java @@ -10,11 +10,11 @@ import org.elasticsearch.cluster.metadata.MappingMetaData; import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.common.collect.ImmutableOpenMap; -import org.elasticsearch.protocol.xpack.rollup.RollableIndexCaps; import org.elasticsearch.test.AbstractStreamableTestCase; import org.elasticsearch.xpack.core.rollup.ConfigTestHelpers; -import org.elasticsearch.protocol.xpack.rollup.RollupField; +import org.elasticsearch.xpack.core.rollup.RollupField; import org.elasticsearch.xpack.core.rollup.action.GetRollupIndexCapsAction; +import org.elasticsearch.xpack.core.rollup.action.RollableIndexCaps; import org.mockito.Mockito; import java.io.IOException; diff --git a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/PutRollupJobRequestTests.java b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/PutJobActionRequestTests.java similarity index 57% rename from x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/PutRollupJobRequestTests.java rename to x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/PutJobActionRequestTests.java index 8108f94a00f65..2765c9ca8c1d2 100644 --- a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/PutRollupJobRequestTests.java +++ b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/PutJobActionRequestTests.java @@ -7,14 +7,14 @@ import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.protocol.xpack.rollup.PutRollupJobRequest; import org.elasticsearch.test.AbstractStreamableXContentTestCase; import org.elasticsearch.xpack.core.rollup.ConfigTestHelpers; +import org.elasticsearch.xpack.core.rollup.action.PutRollupJobAction.Request; import org.junit.Before; import java.io.IOException; -public class PutRollupJobRequestTests extends AbstractStreamableXContentTestCase { +public class PutJobActionRequestTests extends AbstractStreamableXContentTestCase { private String jobId; @@ -24,8 +24,8 @@ public void setupJobID() { } @Override - protected PutRollupJobRequest createTestInstance() { - return new PutRollupJobRequest(ConfigTestHelpers.randomRollupJobConfig(random(), jobId)); + protected Request createTestInstance() { + return new Request(ConfigTestHelpers.randomRollupJobConfig(random(), jobId)); } @Override @@ -34,13 +34,12 @@ protected boolean supportsUnknownFields() { } @Override - protected PutRollupJobRequest createBlankInstance() { - return new PutRollupJobRequest(); + protected Request createBlankInstance() { + return new Request(); } @Override - protected PutRollupJobRequest doParseInstance(final XContentParser parser) throws IOException { - return PutRollupJobRequest.fromXContent(parser, jobId); + protected Request doParseInstance(XContentParser parser) throws IOException { + return Request.fromXContent(parser, jobId); } - } diff --git a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/PutRollupJobResponseTests.java b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/PutRollupJobResponseTests.java deleted file mode 100644 index 77666fd057c7c..0000000000000 --- a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/PutRollupJobResponseTests.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ -package org.elasticsearch.xpack.rollup.action; - - -import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.protocol.xpack.rollup.PutRollupJobResponse; -import org.elasticsearch.test.AbstractStreamableXContentTestCase; -import org.junit.Before; - -public class PutRollupJobResponseTests extends AbstractStreamableXContentTestCase { - - private boolean acknowledged; - - @Before - public void setupJobID() { - acknowledged = randomBoolean(); - } - - @Override - protected PutRollupJobResponse createTestInstance() { - return new PutRollupJobResponse(acknowledged); - } - - @Override - protected boolean supportsUnknownFields() { - return false; - } - - @Override - protected PutRollupJobResponse createBlankInstance() { - return new PutRollupJobResponse(); - } - - @Override - protected PutRollupJobResponse doParseInstance(final XContentParser parser) { - return PutRollupJobResponse.fromXContent(parser); - } - -} diff --git a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/RollupIndexCapsTests.java b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/RollupIndexCapsTests.java index cb31a7d493d82..78b1e1e0d2d0c 100644 --- a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/RollupIndexCapsTests.java +++ b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/RollupIndexCapsTests.java @@ -6,10 +6,10 @@ package org.elasticsearch.xpack.rollup.action; import org.elasticsearch.cluster.metadata.MetaData; -import org.elasticsearch.protocol.xpack.rollup.RollupJobCaps; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.xpack.core.rollup.ConfigTestHelpers; -import org.elasticsearch.protocol.xpack.rollup.job.RollupJobConfig; +import org.elasticsearch.xpack.core.rollup.action.RollupJobCaps; +import org.elasticsearch.xpack.core.rollup.job.RollupJobConfig; import java.util.ArrayList; import java.util.Collections; diff --git a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/SearchActionTests.java b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/SearchActionTests.java index e4258cc1e3685..365e552176ea5 100644 --- a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/SearchActionTests.java +++ b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/SearchActionTests.java @@ -27,9 +27,6 @@ import org.elasticsearch.index.query.TermQueryBuilder; import org.elasticsearch.index.query.TermsQueryBuilder; import org.elasticsearch.indices.IndicesModule; -import org.elasticsearch.protocol.xpack.rollup.RollupJobCaps; -import org.elasticsearch.protocol.xpack.rollup.job.MetricConfig; -import org.elasticsearch.protocol.xpack.rollup.job.TermsGroupConfig; import org.elasticsearch.search.DocValueFormat; import org.elasticsearch.search.SearchModule; import org.elasticsearch.search.aggregations.Aggregations; @@ -48,10 +45,13 @@ import org.elasticsearch.search.suggest.SuggestBuilder; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.xpack.core.rollup.ConfigTestHelpers; -import org.elasticsearch.protocol.xpack.rollup.RollupField; -import org.elasticsearch.protocol.xpack.rollup.job.DateHistogramGroupConfig; -import org.elasticsearch.protocol.xpack.rollup.job.GroupConfig; -import org.elasticsearch.protocol.xpack.rollup.job.RollupJobConfig; +import org.elasticsearch.xpack.core.rollup.RollupField; +import org.elasticsearch.xpack.core.rollup.action.RollupJobCaps; +import org.elasticsearch.xpack.core.rollup.job.DateHistogramGroupConfig; +import org.elasticsearch.xpack.core.rollup.job.GroupConfig; +import org.elasticsearch.xpack.core.rollup.job.MetricConfig; +import org.elasticsearch.xpack.core.rollup.job.RollupJobConfig; +import org.elasticsearch.xpack.core.rollup.job.TermsGroupConfig; import org.elasticsearch.xpack.rollup.Rollup; import org.hamcrest.core.IsEqual; import org.joda.time.DateTimeZone; @@ -70,7 +70,6 @@ import static java.util.Collections.emptyList; import static java.util.Collections.singleton; -import static org.elasticsearch.protocol.xpack.rollup.RollupField.COUNT_FIELD; import static org.elasticsearch.xpack.core.rollup.ConfigTestHelpers.randomHistogramGroupConfig; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.instanceOf; @@ -630,7 +629,7 @@ public void testRollupOnly() throws IOException { List subaggs = new ArrayList<>(2); Map metadata = new HashMap<>(1); - metadata.put(RollupField.ROLLUP_META + "." + COUNT_FIELD, "foo." + COUNT_FIELD); + metadata.put(RollupField.ROLLUP_META + "." + RollupField.COUNT_FIELD, "foo." + RollupField.COUNT_FIELD); InternalSum sum = mock(InternalSum.class); when(sum.getValue()).thenReturn(10.0); when(sum.value()).thenReturn(10.0); @@ -642,7 +641,7 @@ public void testRollupOnly() throws IOException { InternalSum count = mock(InternalSum.class); when(count.getValue()).thenReturn(2.0); when(count.value()).thenReturn(2.0); - when(count.getName()).thenReturn("foo." + COUNT_FIELD); + when(count.getName()).thenReturn("foo." + RollupField.COUNT_FIELD); when(count.getMetaData()).thenReturn(null); when(count.getType()).thenReturn(SumAggregationBuilder.NAME); subaggs.add(count); @@ -747,7 +746,7 @@ public void testBoth() throws IOException { List subaggs = new ArrayList<>(2); Map metadata = new HashMap<>(1); - metadata.put(RollupField.ROLLUP_META + "." + COUNT_FIELD, "foo." + COUNT_FIELD); + metadata.put(RollupField.ROLLUP_META + "." + RollupField.COUNT_FIELD, "foo." + RollupField.COUNT_FIELD); InternalSum sum = mock(InternalSum.class); when(sum.getValue()).thenReturn(10.0); when(sum.value()).thenReturn(10.0); @@ -759,7 +758,7 @@ public void testBoth() throws IOException { InternalSum count = mock(InternalSum.class); when(count.getValue()).thenReturn(2.0); when(count.value()).thenReturn(2.0); - when(count.getName()).thenReturn("foo." + COUNT_FIELD); + when(count.getName()).thenReturn("foo." + RollupField.COUNT_FIELD); when(count.getMetaData()).thenReturn(null); when(count.getType()).thenReturn(SumAggregationBuilder.NAME); subaggs.add(count); diff --git a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/TransportPutRollupJobActionTests.java b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/TransportPutRollupJobActionTests.java deleted file mode 100644 index 53aa0f2e63eee..0000000000000 --- a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/TransportPutRollupJobActionTests.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ -package org.elasticsearch.xpack.rollup.action; - -import org.elasticsearch.protocol.xpack.rollup.PutRollupJobRequest; -import org.elasticsearch.protocol.xpack.rollup.job.RollupJobConfig; -import org.elasticsearch.test.ESTestCase; - -import static org.elasticsearch.xpack.core.rollup.ConfigTestHelpers.randomGroupConfig; -import static org.hamcrest.Matchers.equalTo; - -public class TransportPutRollupJobActionTests extends ESTestCase { - - public void testBadCron() { - final PutRollupJobRequest putRollupJobRequest = - new PutRollupJobRequest(new RollupJobConfig("_id", "index", "rollup", "0 * * *", 100, randomGroupConfig(random()), null, null)); - - Exception e = expectThrows(IllegalArgumentException.class, () -> TransportPutRollupJobAction.validate(putRollupJobRequest)); - assertThat(e.getMessage(), equalTo("invalid cron expression [0 * * *]")); - } -} diff --git a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/TransportTaskHelperTests.java b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/TransportTaskHelperTests.java index ca0d66e2a309e..a156585b609a7 100644 --- a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/TransportTaskHelperTests.java +++ b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/TransportTaskHelperTests.java @@ -9,7 +9,7 @@ import org.elasticsearch.tasks.TaskId; import org.elasticsearch.tasks.TaskManager; import org.elasticsearch.test.ESTestCase; -import org.elasticsearch.protocol.xpack.rollup.job.RollupJobConfig; +import org.elasticsearch.xpack.core.rollup.job.RollupJobConfig; import org.elasticsearch.xpack.rollup.job.RollupJobTask; import java.util.Collections; diff --git a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/config/ConfigTests.java b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/config/ConfigTests.java index 8b10273f37289..86891eda669fa 100644 --- a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/config/ConfigTests.java +++ b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/config/ConfigTests.java @@ -5,14 +5,14 @@ */ package org.elasticsearch.xpack.rollup.config; -import org.elasticsearch.protocol.xpack.rollup.job.HistogramGroupConfig; -import org.elasticsearch.protocol.xpack.rollup.job.MetricConfig; -import org.elasticsearch.protocol.xpack.rollup.job.TermsGroupConfig; import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval; import org.elasticsearch.test.ESTestCase; -import org.elasticsearch.protocol.xpack.rollup.job.DateHistogramGroupConfig; -import org.elasticsearch.protocol.xpack.rollup.job.GroupConfig; +import org.elasticsearch.xpack.core.rollup.job.DateHistogramGroupConfig; +import org.elasticsearch.xpack.core.rollup.job.GroupConfig; +import org.elasticsearch.xpack.core.rollup.job.HistogramGroupConfig; +import org.elasticsearch.xpack.core.rollup.job.MetricConfig; import org.elasticsearch.xpack.core.rollup.job.RollupJob; +import org.elasticsearch.xpack.core.rollup.job.TermsGroupConfig; import org.joda.time.DateTimeZone; import java.util.HashMap; diff --git a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/job/RollupJobTaskTests.java b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/job/RollupJobTaskTests.java index dfc4eb7b39aa8..a47d057b5d5b9 100644 --- a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/job/RollupJobTaskTests.java +++ b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/job/RollupJobTaskTests.java @@ -22,7 +22,7 @@ import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.xpack.core.indexing.IndexerState; import org.elasticsearch.xpack.core.rollup.ConfigTestHelpers; -import org.elasticsearch.protocol.xpack.rollup.RollupField; +import org.elasticsearch.xpack.core.rollup.RollupField; import org.elasticsearch.xpack.core.rollup.action.StartRollupJobAction; import org.elasticsearch.xpack.core.rollup.action.StopRollupJobAction; import org.elasticsearch.xpack.core.rollup.job.RollupJob; diff --git a/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/PutRollupJobRequest.java b/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/PutRollupJobRequest.java deleted file mode 100644 index 4527706429f23..0000000000000 --- a/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/PutRollupJobRequest.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * 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.protocol.xpack.rollup; - -import org.elasticsearch.action.ActionRequestValidationException; -import org.elasticsearch.action.IndicesRequest; -import org.elasticsearch.action.fieldcaps.FieldCapabilities; -import org.elasticsearch.action.support.IndicesOptions; -import org.elasticsearch.action.support.master.AcknowledgedRequest; -import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.xcontent.ToXContentObject; -import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.protocol.xpack.rollup.job.RollupJobConfig; - -import java.io.IOException; -import java.util.Map; -import java.util.Objects; - -public class PutRollupJobRequest extends AcknowledgedRequest implements IndicesRequest, ToXContentObject { - - private RollupJobConfig config; - private IndicesOptions indicesOptions = IndicesOptions.fromOptions(false, false, true, false); - - public PutRollupJobRequest(final RollupJobConfig config) { - this.config = config; - } - - public PutRollupJobRequest() { - } - - /** - * @return the configuration of the rollup job to create - */ - public RollupJobConfig getConfig() { - return config; - } - - /** - * Sets the configuration of the rollup job to create - * @param config the {@link RollupJobConfig} - */ - public void setConfig(final RollupJobConfig config) { - this.config = config; - } - - @Override - public void readFrom(StreamInput in) throws IOException { - super.readFrom(in); - this.config = new RollupJobConfig(in); - } - - @Override - public void writeTo(StreamOutput out) throws IOException { - super.writeTo(out); - this.config.writeTo(out); - } - - @Override - public ActionRequestValidationException validate() { - return null; - } - - public ActionRequestValidationException validateMappings(final Map> fieldCapsResponse) { - final ActionRequestValidationException validationException = new ActionRequestValidationException(); - if (fieldCapsResponse.size() == 0) { - validationException.addValidationError("Could not find any fields in the index/index-pattern that were configured in job"); - return validationException; - } - config.validateMappings(fieldCapsResponse, validationException); - if (validationException.validationErrors().size() > 0) { - return validationException; - } - return null; - } - - @Override - public XContentBuilder toXContent(final XContentBuilder builder, final Params params) throws IOException { - return config.toXContent(builder, params); - } - - @Override - public String[] indices() { - return new String[]{this.config.getIndexPattern()}; - } - - @Override - public IndicesOptions indicesOptions() { - return indicesOptions; - } - - @Override - public int hashCode() { - return Objects.hash(config, indicesOptions, timeout); - } - - @Override - public boolean equals(final Object obj) { - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - final PutRollupJobRequest other = (PutRollupJobRequest) obj; - return Objects.equals(config, other.config); - } - - public static PutRollupJobRequest fromXContent(final XContentParser parser, final String id) throws IOException { - return new PutRollupJobRequest(RollupJobConfig.fromXContent(parser, id)); - } -} diff --git a/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/package-info.java b/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/package-info.java deleted file mode 100644 index e3c42fa876b25..0000000000000 --- a/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/rollup/package-info.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * 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. - */ - -/** - * Request and Response objects for the default distribution's Rollup - * APIs. - */ -package org.elasticsearch.protocol.xpack.rollup; From 19cfc2c01bad15d1c86f58598456835ec0ef469b Mon Sep 17 00:00:00 2001 From: Zachary Tong Date: Mon, 24 Sep 2018 10:56:59 -0400 Subject: [PATCH 06/13] Tweak request/response objects No need to extend ActionRequest, Writeable, etc --- .../elasticsearch/client/RollupClient.java | 7 +++- .../client/rollup/GetRollupCapsRequest.java | 33 +++++----------- .../client/rollup/GetRollupCapsResponse.java | 23 ++--------- .../client/rollup/RollableIndexCaps.java | 16 +------- .../client/rollup/RollupJobCaps.java | 39 +------------------ .../rollup/GetRollupCapsRequestTests.java | 21 ++++------ .../rollup/GetRollupCapsResponseTests.java | 9 +---- 7 files changed, 29 insertions(+), 119 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 7c525dffd1b4a..991ac9713616d 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 @@ -86,8 +86,11 @@ public void putRollupJobAsync(PutRollupJobRequest request, RequestOptions option * @throws IOException in case there is a problem sending the request or parsing back the response */ public GetRollupCapsResponse getRollupCapabilities(GetRollupCapsRequest request, RequestOptions options) throws IOException { - return restHighLevelClient.performRequestAndParseEntity(request, RollupRequestConverters::getRollupCaps, options, - GetRollupCapsResponse::fromXContent, Collections.emptySet()); + return restHighLevelClient.performRequestAndParseEntity(request, + RollupRequestConverters::getRollupCaps, + options, + GetRollupCapsResponse::fromXContent, + Collections.emptySet()); } /** diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/GetRollupCapsRequest.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/GetRollupCapsRequest.java index 180bce036983a..6affc42e70897 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/GetRollupCapsRequest.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/GetRollupCapsRequest.java @@ -18,19 +18,18 @@ */ package org.elasticsearch.client.rollup; -import org.elasticsearch.action.ActionRequest; -import org.elasticsearch.action.ActionRequestValidationException; +import org.elasticsearch.client.Validatable; +import org.elasticsearch.client.ValidationException; import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.common.Strings; -import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.ToXContentObject; import org.elasticsearch.common.xcontent.XContentBuilder; import java.io.IOException; import java.util.Objects; +import java.util.Optional; -public class GetRollupCapsRequest extends ActionRequest implements ToXContentObject { +public class GetRollupCapsRequest implements Validatable, ToXContentObject { private String indexPattern; private static final String ID = "id"; @@ -42,35 +41,21 @@ public GetRollupCapsRequest(String indexPattern) { } } - public GetRollupCapsRequest() {} - public String getIndexPattern() { return indexPattern; } - @Override - public void readFrom(StreamInput in) throws IOException { - super.readFrom(in); - this.indexPattern = in.readString(); - } - - @Override - public void writeTo(StreamOutput out) throws IOException { - super.writeTo(out); - out.writeString(indexPattern); - } - - @Override - public ActionRequestValidationException validate() { - return null; - } - @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.field(ID, indexPattern); return builder; } + @Override + public Optional validate() { + return Optional.empty(); + } + @Override public int hashCode() { return Objects.hash(indexPattern); diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/GetRollupCapsResponse.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/GetRollupCapsResponse.java index d2896de64924a..49926813be4e7 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/GetRollupCapsResponse.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/GetRollupCapsResponse.java @@ -18,11 +18,8 @@ */ package org.elasticsearch.client.rollup; -import org.elasticsearch.action.ActionResponse; import org.elasticsearch.common.Strings; -import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.io.stream.Writeable; +import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContentObject; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; @@ -33,12 +30,10 @@ import java.util.Map; import java.util.Objects; -public class GetRollupCapsResponse extends ActionResponse implements Writeable, ToXContentObject { +public class GetRollupCapsResponse implements ToXContentObject { private Map jobs = Collections.emptyMap(); - public GetRollupCapsResponse() {} - public GetRollupCapsResponse(Map jobs) { this.jobs = Collections.unmodifiableMap(Objects.requireNonNull(jobs)); } @@ -48,19 +43,7 @@ public Map getJobs() { } @Override - public void writeTo(StreamOutput out) throws IOException { - super.writeTo(out); - out.writeMap(jobs, StreamOutput::writeString, (out1, value) -> value.writeTo(out1)); - } - - @Override - public void readFrom(StreamInput in) throws IOException { - super.readFrom(in); - jobs = in.readMap(StreamInput::readString, RollableIndexCaps::new); - } - - @Override - public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { + public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException { builder.startObject(); for (Map.Entry entry : jobs.entrySet()) { entry.getValue().toXContent(builder, params); diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/RollableIndexCaps.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/RollableIndexCaps.java index 5e0a41ee9d61b..c3a9ffaccfc9d 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/RollableIndexCaps.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/RollableIndexCaps.java @@ -19,9 +19,6 @@ package org.elasticsearch.client.rollup; import org.elasticsearch.common.ParseField; -import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.xcontent.ConstructingObjectParser; import org.elasticsearch.common.xcontent.ToXContentFragment; import org.elasticsearch.common.xcontent.XContentBuilder; @@ -40,7 +37,7 @@ * * The index name can either be a single index, or an index pattern (logstash-*) */ -public class RollableIndexCaps implements Writeable, ToXContentFragment { +public class RollableIndexCaps implements ToXContentFragment { private static final ParseField ROLLUP_JOBS = new ParseField("rollup_jobs"); public static final Function> PARSER = indexName -> { @@ -64,11 +61,6 @@ public RollableIndexCaps(String indexName, List caps) { this.jobCaps = Collections.unmodifiableList(jobCaps); } - public RollableIndexCaps(StreamInput in) throws IOException { - this.indexName = in.readString(); - this.jobCaps = in.readList(RollupJobCaps::new); - } - public String getIndexName() { return indexName; } @@ -77,12 +69,6 @@ public List getJobCaps() { return jobCaps; } - @Override - public void writeTo(StreamOutput out) throws IOException { - out.writeString(indexName); - out.writeList(jobCaps); - } - @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(indexName); diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/RollupJobCaps.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/RollupJobCaps.java index f037d33b6e86e..97f2f9d2e49db 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/RollupJobCaps.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/RollupJobCaps.java @@ -20,9 +20,6 @@ import org.elasticsearch.common.ParseField; import org.elasticsearch.common.collect.Tuple; -import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.xcontent.ConstructingObjectParser; import org.elasticsearch.common.xcontent.ToXContentObject; import org.elasticsearch.common.xcontent.XContentBuilder; @@ -40,7 +37,7 @@ /** * Represents the Rollup capabilities for a specific job on a single rollup index */ -public class RollupJobCaps implements Writeable, ToXContentObject { +public class RollupJobCaps implements ToXContentObject { private static ParseField JOB_ID = new ParseField("job_id"); private static ParseField ROLLUP_INDEX = new ParseField("rollup_index"); private static ParseField INDEX_PATTERN = new ParseField("index_pattern"); @@ -79,13 +76,6 @@ public class RollupJobCaps implements Writeable, ToXContentObject { this.fieldCapLookup = Collections.unmodifiableMap(Objects.requireNonNull(fieldCapLookup)); } - public RollupJobCaps(StreamInput in) throws IOException { - this.jobID = in.readString(); - this.rollupIndex = in.readString(); - this.indexPattern = in.readString(); - this.fieldCapLookup = Collections.unmodifiableMap(in.readMap(StreamInput::readString, RollupFieldCaps::new)); - } - public Map getFieldCaps() { return fieldCapLookup; } @@ -102,14 +92,6 @@ public String getJobID() { return jobID; } - @Override - public void writeTo(StreamOutput out) throws IOException { - out.writeString(jobID); - out.writeString(rollupIndex); - out.writeString(indexPattern); - out.writeMap(fieldCapLookup, StreamOutput::writeString, (o, value) -> value.writeTo(o)); - } - @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(); @@ -148,7 +130,7 @@ public int hashCode() { return Objects.hash(jobID, rollupIndex, fieldCapLookup); } - public static class RollupFieldCaps implements Writeable, ToXContentObject { + public static class RollupFieldCaps implements ToXContentObject { private List> aggs; private static final String NAME = "rollup_field_caps"; @@ -172,15 +154,6 @@ public static RollupFieldCaps fromXContent(XContentParser parser) throws IOExcep return new RollupFieldCaps(Collections.unmodifiableList(aggs)); } - RollupFieldCaps(StreamInput in) throws IOException { - int size = in.readInt(); - aggs = new ArrayList<>(size); - for (int i = 0; i < size; i++) { - aggs.add(Collections.unmodifiableMap(in.readMap())); - } - aggs = Collections.unmodifiableList(aggs); - } - RollupFieldCaps(List> aggs) { this.aggs = Collections.unmodifiableList(Objects.requireNonNull(aggs)); } @@ -189,14 +162,6 @@ public List> getAggs() { return aggs; } - @Override - public void writeTo(StreamOutput out) throws IOException { - out.writeInt(aggs.size()); - for (Map agg : aggs) { - out.writeMap(agg); - } - } - @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { for (Map agg : aggs) { diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/rollup/GetRollupCapsRequestTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/rollup/GetRollupCapsRequestTests.java index 1e6afaffd5e8c..48b55282c9aa8 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/rollup/GetRollupCapsRequestTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/rollup/GetRollupCapsRequestTests.java @@ -18,24 +18,17 @@ */ package org.elasticsearch.client.rollup; - import org.elasticsearch.cluster.metadata.MetaData; -import org.elasticsearch.test.AbstractStreamableTestCase; - +import org.elasticsearch.test.ESTestCase; -public class GetRollupCapsRequestTests extends AbstractStreamableTestCase { +import static org.hamcrest.Matchers.equalTo; - @Override - protected GetRollupCapsRequest createTestInstance() { - if (randomBoolean()) { - return new GetRollupCapsRequest(MetaData.ALL); - } - return new GetRollupCapsRequest(randomAlphaOfLengthBetween(1, 20)); - } +public class GetRollupCapsRequestTests extends ESTestCase { - @Override - protected GetRollupCapsRequest createBlankInstance() { - return new GetRollupCapsRequest(); + public void testImplicitIndexPattern() { + String pattern = randomFrom("", "*", MetaData.ALL, null); + GetRollupCapsRequest request = new GetRollupCapsRequest(pattern); + assertThat(request.getIndexPattern(), equalTo(MetaData.ALL)); } } diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/rollup/GetRollupCapsResponseTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/rollup/GetRollupCapsResponseTests.java index b64957783a30f..af595b210e9d4 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/rollup/GetRollupCapsResponseTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/rollup/GetRollupCapsResponseTests.java @@ -29,7 +29,7 @@ import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramAggregationBuilder; import org.elasticsearch.search.aggregations.bucket.histogram.HistogramAggregationBuilder; import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder; -import org.elasticsearch.test.AbstractStreamableXContentTestCase; +import org.elasticsearch.test.AbstractXContentTestCase; import org.junit.Before; import java.io.IOException; @@ -43,7 +43,7 @@ import static java.util.Collections.singletonMap; -public class GetRollupCapsResponseTests extends AbstractStreamableXContentTestCase { +public class GetRollupCapsResponseTests extends AbstractXContentTestCase { private Map indices; @@ -75,11 +75,6 @@ protected boolean supportsUnknownFields() { return false; } - @Override - protected GetRollupCapsResponse createBlankInstance() { - return new GetRollupCapsResponse(); - } - @Override protected GetRollupCapsResponse doParseInstance(final XContentParser parser) throws IOException { return GetRollupCapsResponse.fromXContent(parser); From 77548037a3b215a5271aa5622faea234f1703a6b Mon Sep 17 00:00:00 2001 From: Zachary Tong Date: Mon, 24 Sep 2018 14:07:54 -0400 Subject: [PATCH 07/13] Fix toXContent serialization of request Also pulls in the rollup cleaning from #33921 --- .../client/rollup/GetRollupCapsRequest.java | 2 + .../documentation/RollupDocumentationIT.java | 57 +++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/GetRollupCapsRequest.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/GetRollupCapsRequest.java index 6affc42e70897..247c37c29998b 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/GetRollupCapsRequest.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/GetRollupCapsRequest.java @@ -47,7 +47,9 @@ public String getIndexPattern() { @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { + builder.startObject(); builder.field(ID, indexPattern); + builder.endObject(); return builder; } 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 ae3567634e851..87cd3cbee80d5 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 @@ -27,7 +27,9 @@ import org.elasticsearch.action.index.IndexRequest; import org.elasticsearch.action.support.WriteRequest; import org.elasticsearch.client.ESRestHighLevelClientTestCase; +import org.elasticsearch.client.Request; import org.elasticsearch.client.RequestOptions; +import org.elasticsearch.client.Response; import org.elasticsearch.client.RestHighLevelClient; import org.elasticsearch.client.rollup.GetRollupCapsRequest; import org.elasticsearch.client.rollup.GetRollupCapsResponse; @@ -42,11 +44,16 @@ import org.elasticsearch.client.rollup.job.config.RollupJobConfig; import org.elasticsearch.client.rollup.job.config.TermsGroupConfig; import org.elasticsearch.common.unit.TimeValue; +import org.elasticsearch.common.xcontent.support.XContentMapValues; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval; +import org.junit.After; import org.junit.Before; +import java.io.BufferedReader; import java.io.IOException; +import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -276,4 +283,54 @@ public void onFailure(Exception e) { assertTrue(latch.await(30L, TimeUnit.SECONDS)); } + + @After + public void wipeRollup() throws Exception { + // TODO move this to ESRestTestCase + deleteRollupJobs(); + waitForPendingRollupTasks(); + } + private void deleteRollupJobs() throws Exception { + Response response = adminClient().performRequest(new Request("GET", "/_xpack/rollup/job/_all")); + Map jobs = entityAsMap(response); + @SuppressWarnings("unchecked") + List> jobConfigs = + (List>) XContentMapValues.extractValue("jobs", jobs); + if (jobConfigs == null) { + return; + } + for (Map jobConfig : jobConfigs) { + @SuppressWarnings("unchecked") + String jobId = (String) ((Map) jobConfig.get("config")).get("id"); + Request request = new Request("DELETE", "/_xpack/rollup/job/" + jobId); + request.addParameter("ignore", "404"); // Ignore 404s because they imply someone was racing us to delete this + adminClient().performRequest(request); + } + } + private void waitForPendingRollupTasks() throws Exception { + assertBusy(() -> { + try { + Request request = new Request("GET", "/_cat/tasks"); + request.addParameter("detailed", "true"); + Response response = adminClient().performRequest(request); + try (BufferedReader responseReader = new BufferedReader( + new InputStreamReader(response.getEntity().getContent(), StandardCharsets.UTF_8))) { + int activeTasks = 0; + String line; + StringBuilder tasksListString = new StringBuilder(); + while ((line = responseReader.readLine()) != null) { + // We only care about Rollup jobs, otherwise this fails too easily due to unrelated tasks + if (line.startsWith("xpack/rollup/job") == true) { + activeTasks++; + tasksListString.append(line).append('\n'); + } + } + assertEquals(activeTasks + " active tasks found:\n" + tasksListString, 0, activeTasks); + } + } catch (IOException e) { + // Throw an assertion error so we retry + throw new AssertionError("Error getting active tasks list", e); + } + }); + } } From 157db4aa9fa39cef21df3f957c45e7cd55788e70 Mon Sep 17 00:00:00 2001 From: Zachary Tong Date: Wed, 26 Sep 2018 15:06:41 -0400 Subject: [PATCH 08/13] Review cleanup --- .../elasticsearch/client/RollupClient.java | 2 +- .../client/rollup/GetRollupCapsRequest.java | 9 +-- .../client/rollup/GetRollupCapsResponse.java | 6 +- .../client/rollup/RollableIndexCaps.java | 19 ++--- .../client/rollup/RollupJobCaps.java | 69 ++++++++++--------- .../documentation/RollupDocumentationIT.java | 10 ++- .../rollup/get_rollup_caps.asciidoc | 0 .../rollup/action/GetRollupCapsAction.java | 10 +-- .../core/rollup/action/RollableIndexCaps.java | 20 +++--- .../core/rollup/action/RollupJobCaps.java | 39 ++++++----- 10 files changed, 104 insertions(+), 80 deletions(-) rename docs/java-rest/high-level/{x-pack => }/rollup/get_rollup_caps.asciidoc (100%) 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 991ac9713616d..8c9c5b223ebc0 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 @@ -94,7 +94,7 @@ public GetRollupCapsResponse getRollupCapabilities(GetRollupCapsRequest request, } /** - * Asynchronously put a rollup job into the cluster + * Asynchronously Get the Rollup Capabilities of a target (non-rollup) index or pattern * See * the docs for more. * @param request the request diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/GetRollupCapsRequest.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/GetRollupCapsRequest.java index 247c37c29998b..6791e15eeb929 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/GetRollupCapsRequest.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/GetRollupCapsRequest.java @@ -30,10 +30,10 @@ import java.util.Optional; public class GetRollupCapsRequest implements Validatable, ToXContentObject { - private String indexPattern; private static final String ID = "id"; + private final String indexPattern; - public GetRollupCapsRequest(String indexPattern) { + public GetRollupCapsRequest(final String indexPattern) { if (Strings.isNullOrEmpty(indexPattern) || indexPattern.equals("*")) { this.indexPattern = MetaData.ALL; } else { @@ -53,11 +53,6 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws return builder; } - @Override - public Optional validate() { - return Optional.empty(); - } - @Override public int hashCode() { return Objects.hash(indexPattern); diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/GetRollupCapsResponse.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/GetRollupCapsResponse.java index 49926813be4e7..8a24f20de406f 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/GetRollupCapsResponse.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/GetRollupCapsResponse.java @@ -32,9 +32,9 @@ public class GetRollupCapsResponse implements ToXContentObject { - private Map jobs = Collections.emptyMap(); + private final Map jobs; - public GetRollupCapsResponse(Map jobs) { + public GetRollupCapsResponse(final Map jobs) { this.jobs = Collections.unmodifiableMap(Objects.requireNonNull(jobs)); } @@ -65,7 +65,7 @@ public static GetRollupCapsResponse fromXContent(final XContentParser parser) th } } } - return new GetRollupCapsResponse(jobs); + return new GetRollupCapsResponse(Collections.unmodifiableMap(jobs)); } @Override diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/RollableIndexCaps.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/RollableIndexCaps.java index c3a9ffaccfc9d..0ea4dcdbf8a2e 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/RollableIndexCaps.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/RollableIndexCaps.java @@ -29,6 +29,7 @@ import java.util.List; import java.util.Objects; import java.util.function.Function; +import java.util.stream.Collectors; /** * Represents the rollup capabilities of a non-rollup index. E.g. what values/aggregations @@ -51,14 +52,15 @@ public class RollableIndexCaps implements ToXContentFragment { return p; }; - private String indexName; - private List jobCaps; + private final String indexName; + private final List jobCaps; - public RollableIndexCaps(String indexName, List caps) { + RollableIndexCaps(final String indexName, final List caps) { this.indexName = indexName; - this.jobCaps = Objects.requireNonNull(caps); - this.jobCaps.sort(Comparator.comparing(RollupJobCaps::getJobID)); - this.jobCaps = Collections.unmodifiableList(jobCaps); + this.jobCaps = Collections.unmodifiableList(Objects.requireNonNull(caps) + .stream() + .sorted(Comparator.comparing(RollupJobCaps::getJobID)) + .collect(Collectors.toList())); } public String getIndexName() { @@ -72,7 +74,9 @@ public List getJobCaps() { @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(indexName); - builder.field(ROLLUP_JOBS.getPreferredName(), jobCaps); + { + builder.field(ROLLUP_JOBS.getPreferredName(), jobCaps); + } builder.endObject(); return builder; } @@ -88,7 +92,6 @@ public boolean equals(Object other) { } RollableIndexCaps that = (RollableIndexCaps) other; - return Objects.deepEquals(this.jobCaps, that.jobCaps) && Objects.equals(this.indexName, that.indexName); } diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/RollupJobCaps.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/RollupJobCaps.java index 97f2f9d2e49db..808d4eba980c8 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/RollupJobCaps.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/RollupJobCaps.java @@ -21,6 +21,7 @@ import org.elasticsearch.common.ParseField; import org.elasticsearch.common.collect.Tuple; import org.elasticsearch.common.xcontent.ConstructingObjectParser; +import org.elasticsearch.common.xcontent.ToXContentFragment; import org.elasticsearch.common.xcontent.ToXContentObject; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; @@ -38,10 +39,10 @@ * Represents the Rollup capabilities for a specific job on a single rollup index */ public class RollupJobCaps implements ToXContentObject { - private static ParseField JOB_ID = new ParseField("job_id"); - private static ParseField ROLLUP_INDEX = new ParseField("rollup_index"); - private static ParseField INDEX_PATTERN = new ParseField("index_pattern"); - private static ParseField FIELDS = new ParseField("fields"); + private static final ParseField JOB_ID = new ParseField("job_id"); + private static final ParseField ROLLUP_INDEX = new ParseField("rollup_index"); + private static final ParseField INDEX_PATTERN = new ParseField("index_pattern"); + private static final ParseField FIELDS = new ParseField("fields"); private static final String NAME = "rollup_job_caps"; public static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>(NAME, @@ -64,12 +65,13 @@ public class RollupJobCaps implements ToXContentObject { (p, c, name) -> new Tuple<>(name, RollupFieldCaps.fromXContent(p)), FIELDS); } - private String jobID; - private String rollupIndex; - private String indexPattern; - private Map fieldCapLookup; + private final String jobID; + private final String rollupIndex; + private final String indexPattern; + private final Map fieldCapLookup; - RollupJobCaps(String jobID, String rollupIndex, String indexPattern, Map fieldCapLookup) { + RollupJobCaps(final String jobID, final String rollupIndex, + final String indexPattern, final Map fieldCapLookup) { this.jobID = jobID; this.rollupIndex = rollupIndex; this.indexPattern = indexPattern; @@ -95,15 +97,19 @@ public String getJobID() { @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(); - builder.field(JOB_ID.getPreferredName(), jobID); - builder.field(ROLLUP_INDEX.getPreferredName(), rollupIndex); - builder.field(INDEX_PATTERN.getPreferredName(), indexPattern); - builder.startObject(FIELDS.getPreferredName()); - for (Map.Entry fieldCap : fieldCapLookup.entrySet()) { - builder.array(fieldCap.getKey(), fieldCap.getValue()); + { + builder.field(JOB_ID.getPreferredName(), jobID); + builder.field(ROLLUP_INDEX.getPreferredName(), rollupIndex); + builder.field(INDEX_PATTERN.getPreferredName(), indexPattern); + builder.startObject(FIELDS.getPreferredName()); + { + for (Map.Entry fieldCap : fieldCapLookup.entrySet()) { + builder.array(fieldCap.getKey(), fieldCap.getValue()); + } + } + builder.endObject(); } builder.endObject(); - builder.endObject(); return builder; } @@ -122,17 +128,17 @@ public boolean equals(Object other) { return Objects.equals(this.jobID, that.jobID) && Objects.equals(this.indexPattern, that.indexPattern) && Objects.equals(this.rollupIndex, that.rollupIndex) - && Objects.deepEquals(this.fieldCapLookup, that.fieldCapLookup); + && Objects.equals(this.fieldCapLookup, that.fieldCapLookup); } @Override public int hashCode() { - return Objects.hash(jobID, rollupIndex, fieldCapLookup); + return Objects.hash(jobID, rollupIndex, fieldCapLookup, indexPattern); } - public static class RollupFieldCaps implements ToXContentObject { - private List> aggs; + public static class RollupFieldCaps implements ToXContentFragment { private static final String NAME = "rollup_field_caps"; + private final List> aggs; public static final Function> PARSER = fieldName -> { @SuppressWarnings("unchecked") @@ -144,17 +150,7 @@ public static class RollupFieldCaps implements ToXContentObject { return parser; }; - public static RollupFieldCaps fromXContent(XContentParser parser) throws IOException { - List> aggs = new ArrayList<>(); - if (parser.nextToken().equals(XContentParser.Token.START_ARRAY)) { - while (parser.nextToken().equals(XContentParser.Token.START_OBJECT)) { - aggs.add(Collections.unmodifiableMap(parser.map())); - } - } - return new RollupFieldCaps(Collections.unmodifiableList(aggs)); - } - - RollupFieldCaps(List> aggs) { + RollupFieldCaps(final List> aggs) { this.aggs = Collections.unmodifiableList(Objects.requireNonNull(aggs)); } @@ -170,6 +166,17 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws return builder; } + public static RollupFieldCaps fromXContent(XContentParser parser) throws IOException { + List> aggs = new ArrayList<>(); + if (parser.nextToken().equals(XContentParser.Token.START_ARRAY)) { + while (parser.nextToken().equals(XContentParser.Token.START_OBJECT)) { + aggs.add(Collections.unmodifiableMap(parser.map())); + } + } + return new RollupFieldCaps(Collections.unmodifiableList(aggs)); + } + + @Override public boolean equals(Object other) { if (this == other) { 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 87cd3cbee80d5..744822f774c6a 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 @@ -20,6 +20,8 @@ import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.LatchedActionListener; +import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest; +import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; import org.elasticsearch.action.admin.indices.refresh.RefreshRequest; import org.elasticsearch.action.admin.indices.refresh.RefreshResponse; import org.elasticsearch.action.bulk.BulkRequest; @@ -43,6 +45,7 @@ import org.elasticsearch.client.rollup.job.config.MetricConfig; import org.elasticsearch.client.rollup.job.config.RollupJobConfig; import org.elasticsearch.client.rollup.job.config.TermsGroupConfig; +import org.elasticsearch.cluster.health.ClusterHealthStatus; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.support.XContentMapValues; import org.elasticsearch.rest.RestStatus; @@ -64,6 +67,7 @@ import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.isOneOf; public class RollupDocumentationIT extends ESRestHighLevelClientTestCase { @@ -177,7 +181,6 @@ public void onFailure(Exception e) { public void testGetRollupCaps() throws Exception { RestHighLevelClient client = highLevelClient(); - DateHistogramGroupConfig dateHistogram = new DateHistogramGroupConfig("timestamp", DateHistogramInterval.HOUR, new DateHistogramInterval("7d"), "UTC"); // <1> TermsGroupConfig terms = new TermsGroupConfig("hostname", "datacenter"); @@ -205,6 +208,11 @@ public void testGetRollupCaps() throws Exception { //end::x-pack-rollup-get-rollup-caps-setup assertTrue(acknowledged); + ClusterHealthRequest healthRequest = new ClusterHealthRequest(config.getRollupIndex()).waitForYellowStatus(); + ClusterHealthResponse healthResponse = client.cluster().health(healthRequest, RequestOptions.DEFAULT); + assertFalse(healthResponse.isTimedOut()); + assertThat(healthResponse.getStatus(), isOneOf(ClusterHealthStatus.YELLOW, ClusterHealthStatus.GREEN)); + // Now that the job is created, we should have a rollup index with metadata. // We can test out the caps API now. diff --git a/docs/java-rest/high-level/x-pack/rollup/get_rollup_caps.asciidoc b/docs/java-rest/high-level/rollup/get_rollup_caps.asciidoc similarity index 100% rename from docs/java-rest/high-level/x-pack/rollup/get_rollup_caps.asciidoc rename to docs/java-rest/high-level/rollup/get_rollup_caps.asciidoc diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/GetRollupCapsAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/GetRollupCapsAction.java index 28db1bfaf4941..d28d14a0ac02d 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/GetRollupCapsAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/GetRollupCapsAction.java @@ -117,11 +117,11 @@ public Response() { } public Response(Map jobs) { - this.jobs = Objects.requireNonNull(jobs); + this.jobs = Collections.unmodifiableMap(Objects.requireNonNull(jobs)); } Response(StreamInput in) throws IOException { - jobs = in.readMap(StreamInput::readString, RollableIndexCaps::new); + jobs = Collections.unmodifiableMap(in.readMap(StreamInput::readString, RollableIndexCaps::new)); } public Map getJobs() { @@ -137,8 +137,10 @@ public void writeTo(StreamOutput out) throws IOException { @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(); - for (Map.Entry entry : jobs.entrySet()) { - entry.getValue().toXContent(builder, params); + { + for (Map.Entry entry : jobs.entrySet()) { + entry.getValue().toXContent(builder, params); + } } builder.endObject(); return builder; diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/RollableIndexCaps.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/RollableIndexCaps.java index 5ecf721eec916..d35c5a1977a1f 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/RollableIndexCaps.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/RollableIndexCaps.java @@ -9,7 +9,7 @@ import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Writeable; -import org.elasticsearch.common.xcontent.ToXContentFragment; +import org.elasticsearch.common.xcontent.ToXContentObject; import org.elasticsearch.common.xcontent.XContentBuilder; import java.io.IOException; @@ -17,6 +17,7 @@ import java.util.Comparator; import java.util.List; import java.util.Objects; +import java.util.stream.Collectors; /** * Represents the rollup capabilities of a non-rollup index. E.g. what values/aggregations @@ -25,17 +26,18 @@ * * The index name can either be a single index, or an index pattern (logstash-*) */ -public class RollableIndexCaps implements Writeable, ToXContentFragment { +public class RollableIndexCaps implements Writeable, ToXContentObject { private static final ParseField ROLLUP_JOBS = new ParseField("rollup_jobs"); - private String indexName; - private List jobCaps; + private final String indexName; + private final List jobCaps; public RollableIndexCaps(String indexName, List caps) { this.indexName = indexName; - this.jobCaps = Objects.requireNonNull(caps); - this.jobCaps.sort(Comparator.comparing(RollupJobCaps::getJobID)); - this.jobCaps = Collections.unmodifiableList(jobCaps); + this.jobCaps = Collections.unmodifiableList(Objects.requireNonNull(caps) + .stream() + .sorted(Comparator.comparing(RollupJobCaps::getJobID)) + .collect(Collectors.toList())); } public RollableIndexCaps(StreamInput in) throws IOException { @@ -60,7 +62,9 @@ public void writeTo(StreamOutput out) throws IOException { @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(indexName); - builder.field(ROLLUP_JOBS.getPreferredName(), jobCaps); + { + builder.field(ROLLUP_JOBS.getPreferredName(), jobCaps); + } builder.endObject(); return builder; } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/RollupJobCaps.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/RollupJobCaps.java index a783ef712057f..93cf0cbeeb30c 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/RollupJobCaps.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/RollupJobCaps.java @@ -9,6 +9,7 @@ import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Writeable; +import org.elasticsearch.common.xcontent.ToXContentFragment; import org.elasticsearch.common.xcontent.ToXContentObject; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramAggregationBuilder; @@ -42,10 +43,10 @@ public class RollupJobCaps implements Writeable, ToXContentObject { private static ParseField INDEX_PATTERN = new ParseField("index_pattern"); private static ParseField FIELDS = new ParseField("fields"); - private String jobID; - private String rollupIndex; - private String indexPattern; - private Map fieldCapLookup = new HashMap<>(); + private final String jobID; + private final String rollupIndex; + private final String indexPattern; + private final Map fieldCapLookup; // TODO now that these rollup caps are being used more widely (e.g. search), perhaps we should // store the RollupJob and translate into FieldCaps on demand for json output. Would make working with @@ -98,15 +99,19 @@ public void writeTo(StreamOutput out) throws IOException { @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(); - builder.field(JOB_ID.getPreferredName(), jobID); - builder.field(ROLLUP_INDEX.getPreferredName(), rollupIndex); - builder.field(INDEX_PATTERN.getPreferredName(), indexPattern); - builder.startObject(FIELDS.getPreferredName()); - for (Map.Entry fieldCap : fieldCapLookup.entrySet()) { - builder.array(fieldCap.getKey(), fieldCap.getValue()); + { + builder.field(JOB_ID.getPreferredName(), jobID); + builder.field(ROLLUP_INDEX.getPreferredName(), rollupIndex); + builder.field(INDEX_PATTERN.getPreferredName(), indexPattern); + builder.startObject(FIELDS.getPreferredName()); + { + for (Map.Entry fieldCap : fieldCapLookup.entrySet()) { + builder.array(fieldCap.getKey(), fieldCap.getValue()); + } + } + builder.endObject(); } builder.endObject(); - builder.endObject(); return builder; } @@ -129,7 +134,7 @@ public boolean equals(Object other) { @Override public int hashCode() { - return Objects.hash(jobID, rollupIndex, fieldCapLookup); + return Objects.hash(jobID, rollupIndex, fieldCapLookup, indexPattern); } private static Map createRollupFieldCaps(final RollupJobConfig rollupJobConfig) { @@ -198,15 +203,16 @@ private static Map createRollupFieldCaps(final RollupJo e -> new RollupFieldCaps(e.getValue())))); } - public static class RollupFieldCaps implements Writeable, ToXContentObject { - private List> aggs = new ArrayList<>(); + public static class RollupFieldCaps implements Writeable, ToXContentFragment { + private final List> aggs; RollupFieldCaps(StreamInput in) throws IOException { int size = in.readInt(); - aggs = new ArrayList<>(size); + List> inAggs = new ArrayList<>(size); for (int i = 0; i < size; i++) { - aggs.add(in.readMap()); + inAggs.add(in.readMap()); } + this.aggs = Collections.unmodifiableList(inAggs); } RollupFieldCaps(List> aggs) { @@ -244,7 +250,6 @@ public boolean equals(Object other) { } RollupFieldCaps that = (RollupFieldCaps) other; - return Objects.equals(this.aggs, that.aggs); } From 6dd3fd0a25b33e07f6b481e6da094265263f78bb Mon Sep 17 00:00:00 2001 From: Zachary Tong Date: Wed, 26 Sep 2018 15:08:39 -0400 Subject: [PATCH 09/13] Empty lines --- .../elasticsearch/client/rollup/GetRollupCapsRequestTests.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/rollup/GetRollupCapsRequestTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/rollup/GetRollupCapsRequestTests.java index 48b55282c9aa8..bca08f7bfc505 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/rollup/GetRollupCapsRequestTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/rollup/GetRollupCapsRequestTests.java @@ -30,7 +30,4 @@ public void testImplicitIndexPattern() { GetRollupCapsRequest request = new GetRollupCapsRequest(pattern); assertThat(request.getIndexPattern(), equalTo(MetaData.ALL)); } - } - - From dda7039f6076f0986c0edbd38eb846ccb5821620 Mon Sep 17 00:00:00 2001 From: Zachary Tong Date: Wed, 26 Sep 2018 15:25:19 -0400 Subject: [PATCH 10/13] checkstyle --- .../org/elasticsearch/client/rollup/GetRollupCapsRequest.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/GetRollupCapsRequest.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/GetRollupCapsRequest.java index 6791e15eeb929..a5e215a71b255 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/GetRollupCapsRequest.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/GetRollupCapsRequest.java @@ -19,7 +19,6 @@ package org.elasticsearch.client.rollup; import org.elasticsearch.client.Validatable; -import org.elasticsearch.client.ValidationException; import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.common.Strings; import org.elasticsearch.common.xcontent.ToXContentObject; @@ -27,7 +26,6 @@ import java.io.IOException; import java.util.Objects; -import java.util.Optional; public class GetRollupCapsRequest implements Validatable, ToXContentObject { private static final String ID = "id"; From 0dac0d074c9c46d141ddc887b95ec2435e07b150 Mon Sep 17 00:00:00 2001 From: Zachary Tong Date: Tue, 16 Oct 2018 13:59:30 -0400 Subject: [PATCH 11/13] Review Cleanup --- .../elasticsearch/client/RollupClient.java | 8 +- .../client/RollupRequestConverters.java | 2 +- .../client/rollup/GetRollupCapsResponse.java | 2 +- .../rollup/get_rollup_caps.asciidoc | 38 ++-- .../high-level/x-pack/rollup/put_job.asciidoc | 172 ------------------ 5 files changed, 30 insertions(+), 192 deletions(-) delete mode 100644 docs/java-rest/high-level/x-pack/rollup/put_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 4f592d4500cca..e5e52bd1cb6ed 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 @@ -140,7 +140,11 @@ public GetRollupCapsResponse getRollupCapabilities(GetRollupCapsRequest request, */ public void getRollupCapabilitiesAsync(GetRollupCapsRequest request, RequestOptions options, ActionListener listener) { - restHighLevelClient.performRequestAsyncAndParseEntity(request, RollupRequestConverters::getRollupCaps, options, - GetRollupCapsResponse::fromXContent, listener, Collections.emptySet()); + restHighLevelClient.performRequestAsyncAndParseEntity(request, + RollupRequestConverters::getRollupCaps, + options, + GetRollupCapsResponse::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 17b351303a6d3..0a3b9d91174f6 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 @@ -56,7 +56,7 @@ static Request getJob(final GetRollupJobRequest getRollupJobRequest) { return new Request(HttpGet.METHOD_NAME, endpoint); } - static Request getRollupCaps(GetRollupCapsRequest getRollupCapsRequest) throws IOException { + static Request getRollupCaps(final GetRollupCapsRequest getRollupCapsRequest) throws IOException { String endpoint = new RequestConverters.EndpointBuilder() .addPathPartAsIs("_xpack") .addPathPartAsIs("rollup") diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/GetRollupCapsResponse.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/GetRollupCapsResponse.java index 8a24f20de406f..872dc7440a092 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/GetRollupCapsResponse.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/GetRollupCapsResponse.java @@ -65,7 +65,7 @@ public static GetRollupCapsResponse fromXContent(final XContentParser parser) th } } } - return new GetRollupCapsResponse(Collections.unmodifiableMap(jobs)); + return new GetRollupCapsResponse(jobs); } @Override diff --git a/docs/java-rest/high-level/rollup/get_rollup_caps.asciidoc b/docs/java-rest/high-level/rollup/get_rollup_caps.asciidoc index bb8b0d3c3a16f..ba5b5e777c824 100644 --- a/docs/java-rest/high-level/rollup/get_rollup_caps.asciidoc +++ b/docs/java-rest/high-level/rollup/get_rollup_caps.asciidoc @@ -1,21 +1,27 @@ -[[java-rest-high-x-pack-rollup-get-rollup-caps]] +-- +:api: get-rollup-caps +:request: GetRollupCapsRequest +:response: GetRollupCapsResponse +-- + +[id="{upid}-{api}"] === Get Rollup Capabilities Rollup Job API The Get Rollup Capabilities API allows the user to query a target index pattern (`logstash-*`, etc) and determine if there are any rollup jobs that are/were configured to rollup that pattern. The API accepts a `GetRollupCapsRequest` object as a request and returns a `GetRollupCapsResponse`. -[[java-rest-high-x-pack-rollup-get-rollup-caps-request]] +[id="{upid}-{api}-request"] ==== Get Rollup Capabilities Request -A `GetRollupCapsRequest` requires a single parameter: the target index or index pattern (e.g. `logstash-*`): +A +{request}+ requires a single parameter: the target index or index pattern (e.g. `logstash-*`): ["source","java",subs="attributes,callouts,macros"] -------------------------------------------------- -include-tagged::{doc-tests}/RollupDocumentationIT.java[x-pack-rollup-get-rollup-caps-request] +include-tagged::{doc-tests-file}[{api}-request] -------------------------------------------------- -[[java-rest-high-x-pack-rollup-get-rollup-caps-execution]] +[id="{upid}-{api}-execution"] ==== Execution The Get Rollup Capabilities API can be executed through a `RollupClient` @@ -24,13 +30,13 @@ using the `rollup()` method: ["source","java",subs="attributes,callouts,macros"] -------------------------------------------------- -include-tagged::{doc-tests}/RollupDocumentationIT.java[x-pack-rollup-put-rollup-job-execute] +include-tagged::{doc-tests-file}[{api}-execute] -------------------------------------------------- -[[java-rest-high-x-pack-rollup-get-rollup-caps-response]] +[id="{upid}-{api}-response"] ==== Response -The returned `GetRollupCapsResponse` holds lists and maps of values which correspond to the capabilities +The returned +{response}+ holds lists and maps of values which correspond to the capabilities of the target index/index pattern (what jobs were configured for the pattern, where the data is stored, what aggregations are available, etc). It provides essentially the same data as the original job configuration, just presented in a different manner. @@ -39,26 +45,26 @@ For example, if we had created a job with the following config: ["source","java",subs="attributes,callouts,macros"] -------------------------------------------------- -include-tagged::{doc-tests}/RollupDocumentationIT.java[x-pack-rollup-get-rollup-caps-setup] +include-tagged::{doc-tests-file}[{api}-setup] -------------------------------------------------- -The `GetRollupCapsResponse` object would contain the same information, laid out in a slightly different manner: +The +{response}+ object would contain the same information, laid out in a slightly different manner: ["source","java",subs="attributes,callouts,macros"] -------------------------------------------------- -include-tagged::{doc-tests}/RollupDocumentationIT.java[x-pack-rollup-get-rollup-caps-response] +include-tagged::{doc-tests-file}[{api}-response] -------------------------------------------------- -[[java-rest-high-x-pack-rollup-put-rollup-job-async]] +[id="{upid}-{api}-async"] ==== Asynchronous Execution This request can be executed asynchronously: ["source","java",subs="attributes,callouts,macros"] -------------------------------------------------- -include-tagged::{doc-tests}/RollupDocumentationIT.java[x-pack-rollup-get-rollup-caps-execute-async] +include-tagged::{doc-tests-file}[{api}-execute-async] -------------------------------------------------- -<1> The `GetRollupCapsRequest` to execute and the `ActionListener` to use when +<1> The +{request}+ to execute and the `ActionListener` to use when the execution completes The asynchronous method does not block and returns immediately. Once it is @@ -66,11 +72,11 @@ 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 `GetRollupCapsResponse` looks like: +A typical listener for +{response}+ looks like: ["source","java",subs="attributes,callouts,macros"] -------------------------------------------------- -include-tagged::{doc-tests}/RollupDocumentationIT.java[x-pack-rollup-get-rollup-caps-execute-listener] +include-tagged::{doc-tests-file}[{api}-execute-listener] -------------------------------------------------- <1> Called when the execution is successfully completed. The response is provided as an argument diff --git a/docs/java-rest/high-level/x-pack/rollup/put_job.asciidoc b/docs/java-rest/high-level/x-pack/rollup/put_job.asciidoc deleted file mode 100644 index 6d8f0352ef2b7..0000000000000 --- a/docs/java-rest/high-level/x-pack/rollup/put_job.asciidoc +++ /dev/null @@ -1,172 +0,0 @@ -[[java-rest-high-x-pack-rollup-put-job]] -=== Put Rollup Job API - -The Put 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-put-rollup-job-request]] -==== Put Rollup Job Request - -A `PutRollupJobRequest` requires the following argument: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/RollupDocumentationIT.java[x-pack-rollup-put-rollup-job-request] --------------------------------------------------- -<1> The configuration of the Rollup job to create as a `RollupJobConfig` - -[[java-rest-high-x-pack-rollup-put-rollup-job-config]] -==== Rollup Job Configuration - -The `RollupJobConfig` object contains all the details about the rollup job -configuration. See <> to learn more -about the various configuration settings. - -A `RollupJobConfig` requires the following arguments: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/RollupDocumentationIT.java[x-pack-rollup-put-rollup-job-config] --------------------------------------------------- -<1> The name of the Rollup job -<2> The index (or index pattern) to rollup -<3> The index to store rollup results into -<4> A cron expression which defines when the Rollup job should be executed -<5> The page size to use for the Rollup job -<6> The grouping configuration of the Rollup job as a `GroupConfig` -<7> The metrics configuration of the Rollup job as a list of `MetricConfig` -<8> The timeout value to use for the Rollup job as a `TimeValue` - - -[[java-rest-high-x-pack-rollup-put-rollup-job-group-config]] -==== Grouping Configuration - -The grouping configuration of the Rollup job is defined in the `RollupJobConfig` -using a `GroupConfig` instance. `GroupConfig` reflects all the configuration -settings that can be defined using the REST API. See <> -to learn more about these settings. - -Using the REST API, we could define this grouping configuration: - -[source,js] --------------------------------------------------- -"groups" : { - "date_histogram": { - "field": "timestamp", - "interval": "1h", - "delay": "7d", - "time_zone": "UTC" - }, - "terms": { - "fields": ["hostname", "datacenter"] - }, - "histogram": { - "fields": ["load", "net_in", "net_out"], - "interval": 5 - } -} --------------------------------------------------- -// NOTCONSOLE - -Using the `GroupConfig` object and the high level REST client, the same -configuration would be: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/RollupDocumentationIT.java[x-pack-rollup-put-rollup-job-group-config] --------------------------------------------------- -<1> The date histogram aggregation to use to rollup up documents, as a `DateHistogramGroupConfig` -<2> The terms aggregation to use to rollup up documents, as a `TermsGroupConfig` -<3> The histogram aggregation to use to rollup up documents, as a `HistogramGroupConfig` -<4> The grouping configuration as a `GroupConfig` - - -[[java-rest-high-x-pack-rollup-put-rollup-job-metrics-config]] -==== Metrics Configuration - -After defining which groups should be generated for the data, you next configure -which metrics should be collected. The list of metrics is defined in the `RollupJobConfig` -using a `List` instance. `MetricConfig` reflects all the configuration -settings that can be defined using the REST API. See <> -to learn more about these settings. - -Using the REST API, we could define this metrics configuration: - -[source,js] --------------------------------------------------- -"metrics": [ - { - "field": "temperature", - "metrics": ["min", "max", "sum"] - }, - { - "field": "voltage", - "metrics": ["avg", "value_count"] - } -] --------------------------------------------------- -// NOTCONSOLE - -Using the `MetricConfig` object and the high level REST client, the same -configuration would be: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/RollupDocumentationIT.java[x-pack-rollup-put-rollup-job-metrics-config] --------------------------------------------------- -<1> The list of `MetricConfig` to configure in the `RollupJobConfig` -<2> Adds the metrics to compute on the `temperature` field -<3> Adds the metrics to compute on the `voltage` field - - -[[java-rest-high-x-pack-rollup-put-rollup-job-execution]] -==== Execution - -The Put 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-put-rollup-job-execute] --------------------------------------------------- - -[[java-rest-high-x-pack-rollup-put-rollup-job-response]] -==== Response - -The returned `PutRollupJobResponse` 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-put-rollup-job-response] --------------------------------------------------- -<1> `acknowledged` is a boolean indicating whether the job was successfully created - -[[java-rest-high-x-pack-rollup-put-rollup-job-async]] -==== Asynchronous Execution - -This request can be executed asynchronously: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/RollupDocumentationIT.java[x-pack-rollup-put-rollup-job-execute-async] --------------------------------------------------- -<1> The `PutRollupJobRequest` 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 `PutRollupJobResponse` looks like: - -["source","java",subs="attributes,callouts,macros"] --------------------------------------------------- -include-tagged::{doc-tests}/RollupDocumentationIT.java[x-pack-rollup-put-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 From 39fb7dd0ca67c726717607576486c21a9818bae1 Mon Sep 17 00:00:00 2001 From: Zachary Tong Date: Tue, 16 Oct 2018 14:36:56 -0400 Subject: [PATCH 12/13] Doc tweaks --- .../org/elasticsearch/client/RollupIT.java | 11 ++++---- .../rollup/get_rollup_caps.asciidoc | 26 +++++++++---------- .../high-level/supported-apis.asciidoc | 2 +- 3 files changed, 20 insertions(+), 19 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 b11a894e75a8a..5b77681a8895d 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 @@ -19,6 +19,7 @@ package org.elasticsearch.client; import org.elasticsearch.ElasticsearchStatusException; +import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest; import org.elasticsearch.action.admin.indices.refresh.RefreshRequest; import org.elasticsearch.action.admin.indices.refresh.RefreshResponse; import org.elasticsearch.action.bulk.BulkItemResponse; @@ -28,14 +29,14 @@ import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.support.WriteRequest; -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.GetRollupCapsRequest; import org.elasticsearch.client.rollup.GetRollupCapsResponse; +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.PutRollupJobRequest; import org.elasticsearch.client.rollup.PutRollupJobResponse; import org.elasticsearch.client.rollup.RollableIndexCaps; @@ -65,11 +66,11 @@ import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; import static org.hamcrest.Matchers.either; +import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.equalTo; 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; diff --git a/docs/java-rest/high-level/rollup/get_rollup_caps.asciidoc b/docs/java-rest/high-level/rollup/get_rollup_caps.asciidoc index ba5b5e777c824..c11f5d231b09d 100644 --- a/docs/java-rest/high-level/rollup/get_rollup_caps.asciidoc +++ b/docs/java-rest/high-level/rollup/get_rollup_caps.asciidoc @@ -1,27 +1,27 @@ -- -:api: get-rollup-caps +:api: rollup-get-rollup-caps :request: GetRollupCapsRequest :response: GetRollupCapsResponse -- -[id="{upid}-{api}"] -=== Get Rollup Capabilities Rollup Job API +[id="{upid}-x-pack-{api}"] +=== Get Rollup Capabilities API The Get Rollup Capabilities API allows the user to query a target index pattern (`logstash-*`, etc) and determine if there are any rollup jobs that are/were configured to rollup that pattern. The API accepts a `GetRollupCapsRequest` object as a request and returns a `GetRollupCapsResponse`. -[id="{upid}-{api}-request"] +[id="{upid}-x-pack-{api}-request"] ==== Get Rollup Capabilities Request A +{request}+ requires a single parameter: the target index or index pattern (e.g. `logstash-*`): ["source","java",subs="attributes,callouts,macros"] -------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-request] +include-tagged::{doc-tests-file}[x-pack-{api}-request] -------------------------------------------------- -[id="{upid}-{api}-execution"] +[id="{upid}-x-pack-{api}-execution"] ==== Execution The Get Rollup Capabilities API can be executed through a `RollupClient` @@ -30,10 +30,10 @@ using the `rollup()` method: ["source","java",subs="attributes,callouts,macros"] -------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-execute] +include-tagged::{doc-tests-file}[x-pack-{api}-execute] -------------------------------------------------- -[id="{upid}-{api}-response"] +[id="{upid}-x-pack-{api}-response"] ==== Response The returned +{response}+ holds lists and maps of values which correspond to the capabilities @@ -45,24 +45,24 @@ For example, if we had created a job with the following config: ["source","java",subs="attributes,callouts,macros"] -------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-setup] +include-tagged::{doc-tests-file}[x-pack-{api}-setup] -------------------------------------------------- The +{response}+ object would contain the same information, laid out in a slightly different manner: ["source","java",subs="attributes,callouts,macros"] -------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-response] +include-tagged::{doc-tests-file}[x-pack-{api}-response] -------------------------------------------------- -[id="{upid}-{api}-async"] +[id="{upid}-x-pack-{api}-async"] ==== Asynchronous Execution This request can be executed asynchronously: ["source","java",subs="attributes,callouts,macros"] -------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-execute-async] +include-tagged::{doc-tests-file}[x-pack-{api}-execute-async] -------------------------------------------------- <1> The +{request}+ to execute and the `ActionListener` to use when the execution completes @@ -76,7 +76,7 @@ A typical listener for +{response}+ looks like: ["source","java",subs="attributes,callouts,macros"] -------------------------------------------------- -include-tagged::{doc-tests-file}[{api}-execute-listener] +include-tagged::{doc-tests-file}[x-pack-{api}-execute-listener] -------------------------------------------------- <1> Called when the execution is successfully completed. The response is provided as an argument diff --git a/docs/java-rest/high-level/supported-apis.asciidoc b/docs/java-rest/high-level/supported-apis.asciidoc index c2081461c2e94..ae25f17b9917c 100644 --- a/docs/java-rest/high-level/supported-apis.asciidoc +++ b/docs/java-rest/high-level/supported-apis.asciidoc @@ -299,7 +299,7 @@ The Java High Level REST Client supports the following Rollup APIs: * <> * <<{upid}-rollup-delete-job>> * <> -* <> +* <<{upid}-x-pack-rollup-get-rollup-caps>> include::rollup/put_job.asciidoc[] include::rollup/delete_job.asciidoc[] From 0716c29ff2e7cbc240fc3a0a4adecc69f5d35330 Mon Sep 17 00:00:00 2001 From: Zachary Tong Date: Wed, 17 Oct 2018 11:30:47 -0400 Subject: [PATCH 13/13] Unecessary deepEquals --- .../java/org/elasticsearch/client/rollup/RollableIndexCaps.java | 2 +- .../java/org/elasticsearch/client/rollup/RollupJobCaps.java | 2 +- .../xpack/core/rollup/action/RollableIndexCaps.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/RollableIndexCaps.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/RollableIndexCaps.java index 0ea4dcdbf8a2e..cf849e38dd0b4 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/RollableIndexCaps.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/RollableIndexCaps.java @@ -92,7 +92,7 @@ public boolean equals(Object other) { } RollableIndexCaps that = (RollableIndexCaps) other; - return Objects.deepEquals(this.jobCaps, that.jobCaps) + return Objects.equals(this.jobCaps, that.jobCaps) && Objects.equals(this.indexName, that.indexName); } diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/RollupJobCaps.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/RollupJobCaps.java index 808d4eba980c8..7ba1aaa4d7c2b 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/RollupJobCaps.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/rollup/RollupJobCaps.java @@ -188,7 +188,7 @@ public boolean equals(Object other) { } RollupFieldCaps that = (RollupFieldCaps) other; - return Objects.deepEquals(this.aggs, that.aggs); + return Objects.equals(this.aggs, that.aggs); } @Override diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/RollableIndexCaps.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/RollableIndexCaps.java index d35c5a1977a1f..d844717167335 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/RollableIndexCaps.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rollup/action/RollableIndexCaps.java @@ -81,7 +81,7 @@ public boolean equals(Object other) { RollableIndexCaps that = (RollableIndexCaps) other; - return Objects.deepEquals(this.jobCaps, that.jobCaps) + return Objects.equals(this.jobCaps, that.jobCaps) && Objects.equals(this.indexName, that.indexName); }