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 35a2319dfec0d..f5f9ba23e5d0a 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 @@ -275,7 +275,6 @@ public class RestHighLevelClient implements Closeable { private final SnapshotClient snapshotClient = new SnapshotClient(this); private final SecurityClient securityClient = new SecurityClient(this); - private final TransformClient transformClient = new TransformClient(this); private final EqlClient eqlClient = new EqlClient(this); /** @@ -371,20 +370,6 @@ public SecurityClient security() { return securityClient; } - /** - * Provides methods for accessing the Elastic Licensed Data Frame APIs that - * are shipped with the Elastic Stack distribution of Elasticsearch. All of - * these APIs will 404 if run against the OSS distribution of Elasticsearch. - *

- * See the - * Transform APIs on elastic.co for more information. - * - * @return the client wrapper for making Data Frame API calls - */ - public TransformClient transform() { - return transformClient; - } - /** * Provides methods for accessing the Elastic EQL APIs that * are shipped with the Elastic Stack distribution of Elasticsearch. All of diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/TransformClient.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/TransformClient.java deleted file mode 100644 index d9c5d99e50e99..0000000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/TransformClient.java +++ /dev/null @@ -1,432 +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 - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -package org.elasticsearch.client; - -import org.elasticsearch.action.ActionListener; -import org.elasticsearch.client.core.AcknowledgedResponse; -import org.elasticsearch.client.transform.DeleteTransformRequest; -import org.elasticsearch.client.transform.GetTransformRequest; -import org.elasticsearch.client.transform.GetTransformResponse; -import org.elasticsearch.client.transform.GetTransformStatsRequest; -import org.elasticsearch.client.transform.GetTransformStatsResponse; -import org.elasticsearch.client.transform.PreviewTransformRequest; -import org.elasticsearch.client.transform.PreviewTransformResponse; -import org.elasticsearch.client.transform.PutTransformRequest; -import org.elasticsearch.client.transform.StartTransformRequest; -import org.elasticsearch.client.transform.StartTransformResponse; -import org.elasticsearch.client.transform.StopTransformRequest; -import org.elasticsearch.client.transform.StopTransformResponse; -import org.elasticsearch.client.transform.UpdateTransformRequest; -import org.elasticsearch.client.transform.UpdateTransformResponse; - -import java.io.IOException; -import java.util.Collections; - -/** - * @deprecated The High Level Rest Client is deprecated in favor of the - * - * Elasticsearch Java API Client - */ -@Deprecated(since = "7.16.0", forRemoval = true) -@SuppressWarnings("removal") -public final class TransformClient { - - private final RestHighLevelClient restHighLevelClient; - - TransformClient(RestHighLevelClient restHighLevelClient) { - this.restHighLevelClient = restHighLevelClient; - } - - /** - * Creates a new transform - *

- * For additional info - * see - * Create transform documentation - * - * @param request The PutTransformRequest containing the - * {@link org.elasticsearch.client.transform.transforms.TransformConfig}. - * @param options Additional request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized - * @return An AcknowledgedResponse object indicating request success - * @throws IOException when there is a serialization issue sending the request or receiving the response - */ - public AcknowledgedResponse putTransform(PutTransformRequest request, RequestOptions options) throws IOException { - return restHighLevelClient.performRequestAndParseEntity( - request, - TransformRequestConverters::putTransform, - options, - AcknowledgedResponse::fromXContent, - Collections.emptySet() - ); - } - - /** - * Creates a new transform asynchronously and notifies listener on completion - *

- * For additional info - * see - * Create transform documentation - * @param request The PutTransformRequest containing the - * {@link org.elasticsearch.client.transform.transforms.TransformConfig}. - * @param options Additional request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized - * @param listener Listener to be notified upon request completion - * @return cancellable that may be used to cancel the request - */ - public Cancellable putTransformAsync( - PutTransformRequest request, - RequestOptions options, - ActionListener listener - ) { - return restHighLevelClient.performRequestAsyncAndParseEntity( - request, - TransformRequestConverters::putTransform, - options, - AcknowledgedResponse::fromXContent, - listener, - Collections.emptySet() - ); - } - - /** - * Updates an existing transform - *

- * For additional info - * see - * Create transform documentation - * - * @param request The UpdateTransformRequest containing the - * {@link org.elasticsearch.client.transform.transforms.TransformConfigUpdate}. - * @param options Additional request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized - * @return An UpdateTransformResponse object containing the updated configuration - * @throws IOException when there is a serialization issue sending the request or receiving the response - */ - public UpdateTransformResponse updateTransform(UpdateTransformRequest request, RequestOptions options) throws IOException { - return restHighLevelClient.performRequestAndParseEntity( - request, - TransformRequestConverters::updateTransform, - options, - UpdateTransformResponse::fromXContent, - Collections.emptySet() - ); - } - - /** - * Updates an existing transform asynchronously and notifies listener on completion - *

- * For additional info - * see - * Create transform documentation - * @param request The UpdateTransformRequest containing the - * {@link org.elasticsearch.client.transform.transforms.TransformConfigUpdate}. - * @param options Additional request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized - * @param listener Listener to be notified upon request completion - * @return cancellable that may be used to cancel the request - */ - public Cancellable updateTransformAsync( - UpdateTransformRequest request, - RequestOptions options, - ActionListener listener - ) { - return restHighLevelClient.performRequestAsyncAndParseEntity( - request, - TransformRequestConverters::updateTransform, - options, - UpdateTransformResponse::fromXContent, - listener, - Collections.emptySet() - ); - } - - /** - * Get the running statistics of a transform - *

- * For additional info - * see - * Get transform stats documentation - * - * @param request Specifies which transforms to get the stats for - * @param options Additional request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized - * @return The transform stats - * @throws IOException when there is a serialization issue sending the request or receiving the response - */ - public GetTransformStatsResponse getTransformStats(GetTransformStatsRequest request, RequestOptions options) throws IOException { - return restHighLevelClient.performRequestAndParseEntity( - request, - TransformRequestConverters::getTransformStats, - options, - GetTransformStatsResponse::fromXContent, - Collections.emptySet() - ); - } - - /** - * Get the running statistics of a transform asynchronously and notifies listener on completion - *

- * For additional info - * see - * Get transform stats documentation - * @param request Specifies which transforms to get the stats for - * @param options Additional request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized - * @param listener Listener to be notified upon request completion - * @return cancellable that may be used to cancel the request - */ - public Cancellable getTransformStatsAsync( - GetTransformStatsRequest request, - RequestOptions options, - ActionListener listener - ) { - return restHighLevelClient.performRequestAsyncAndParseEntity( - request, - TransformRequestConverters::getTransformStats, - options, - GetTransformStatsResponse::fromXContent, - listener, - Collections.emptySet() - ); - } - - /** - * Delete a transform - *

- * For additional info - * see - * Delete transform documentation - * - * @param request The delete transform request - * @param options Additional request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized - * @return An AcknowledgedResponse object indicating request success - * @throws IOException when there is a serialization issue sending the request or receiving the response - */ - public AcknowledgedResponse deleteTransform(DeleteTransformRequest request, RequestOptions options) throws IOException { - return restHighLevelClient.performRequestAndParseEntity( - request, - TransformRequestConverters::deleteTransform, - options, - AcknowledgedResponse::fromXContent, - Collections.emptySet() - ); - } - - /** - * Delete a transform asynchronously and notifies listener on completion - *

- * For additional info - * see - * Delete transform documentation - * @param request The delete transform request - * @param options Additional request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized - * @param listener Listener to be notified upon request completion - * @return cancellable that may be used to cancel the request - */ - public Cancellable deleteTransformAsync( - DeleteTransformRequest request, - RequestOptions options, - ActionListener listener - ) { - return restHighLevelClient.performRequestAsyncAndParseEntity( - request, - TransformRequestConverters::deleteTransform, - options, - AcknowledgedResponse::fromXContent, - listener, - Collections.emptySet() - ); - } - - /** - * Preview the result of a transform - *

- * For additional info - * see - * Preview transform documentation - * - * @param request The preview transform request - * @param options Additional request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized - * @return A response containing the results of the applied transform - * @throws IOException when there is a serialization issue sending the request or receiving the response - */ - public PreviewTransformResponse previewTransform(PreviewTransformRequest request, RequestOptions options) throws IOException { - return restHighLevelClient.performRequestAndParseEntity( - request, - TransformRequestConverters::previewTransform, - options, - PreviewTransformResponse::fromXContent, - Collections.emptySet() - ); - } - - /** - * Preview the result of a transform asynchronously and notifies listener on completion - *

- * see - * Preview transform documentation - * @param request The preview transform request - * @param options Additional request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized - * @param listener Listener to be notified upon request completion - * @return cancellable that may be used to cancel the request - */ - public Cancellable previewTransformAsync( - PreviewTransformRequest request, - RequestOptions options, - ActionListener listener - ) { - return restHighLevelClient.performRequestAsyncAndParseEntity( - request, - TransformRequestConverters::previewTransform, - options, - PreviewTransformResponse::fromXContent, - listener, - Collections.emptySet() - ); - } - - /** - * Start a transform - *

- * For additional info - * see - * Start transform documentation - * - * @param request The start transform request - * @param options Additional request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized - * @return A response object indicating request success - * @throws IOException when there is a serialization issue sending the request or receiving the response - */ - public StartTransformResponse startTransform(StartTransformRequest request, RequestOptions options) throws IOException { - return restHighLevelClient.performRequestAndParseEntity( - request, - TransformRequestConverters::startTransform, - options, - StartTransformResponse::fromXContent, - Collections.emptySet() - ); - } - - /** - * Start a transform asynchronously and notifies listener on completion - *

- * For additional info - * see - * Start transform documentation - * @param request The start transform request - * @param options Additional request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized - * @param listener Listener to be notified upon request completion - * @return cancellable that may be used to cancel the request - */ - public Cancellable startTransformAsync( - StartTransformRequest request, - RequestOptions options, - ActionListener listener - ) { - return restHighLevelClient.performRequestAsyncAndParseEntity( - request, - TransformRequestConverters::startTransform, - options, - StartTransformResponse::fromXContent, - listener, - Collections.emptySet() - ); - } - - /** - * Stop a transform - *

- * For additional info - * see - * Stop transform documentation - * - * @param request The stop transform request - * @param options Additional request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized - * @return A response object indicating request success - * @throws IOException when there is a serialization issue sending the request or receiving the response - */ - public StopTransformResponse stopTransform(StopTransformRequest request, RequestOptions options) throws IOException { - return restHighLevelClient.performRequestAndParseEntity( - request, - TransformRequestConverters::stopTransform, - options, - StopTransformResponse::fromXContent, - Collections.emptySet() - ); - } - - /** - * Stop a transform asynchronously and notifies listener on completion - *

- * For additional info - * see - * Stop transform documentation - * @param request The stop transform request - * @param options Additional request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized - * @param listener Listener to be notified upon request completion - * @return cancellable that may be used to cancel the request - */ - public Cancellable stopTransformAsync( - StopTransformRequest request, - RequestOptions options, - ActionListener listener - ) { - return restHighLevelClient.performRequestAsyncAndParseEntity( - request, - TransformRequestConverters::stopTransform, - options, - StopTransformResponse::fromXContent, - listener, - Collections.emptySet() - ); - } - - /** - * Get one or more transform configurations - *

- * For additional info - * see - * Get transform documentation - * - * @param request The get transform request - * @param options Additional request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized - * @return An GetTransformResponse containing the requested transforms - * @throws IOException when there is a serialization issue sending the request or receiving the response - */ - public GetTransformResponse getTransform(GetTransformRequest request, RequestOptions options) throws IOException { - return restHighLevelClient.performRequestAndParseEntity( - request, - TransformRequestConverters::getTransform, - options, - GetTransformResponse::fromXContent, - Collections.emptySet() - ); - } - - /** - * Get one or more transform configurations asynchronously and notifies listener on completion - *

- * For additional info - * see - * Get data transform documentation - * @param request The get transform request - * @param options Additional request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized - * @param listener Listener to be notified upon request completion - * @return cancellable that may be used to cancel the request - */ - public Cancellable getTransformAsync( - GetTransformRequest request, - RequestOptions options, - ActionListener listener - ) { - return restHighLevelClient.performRequestAsyncAndParseEntity( - request, - TransformRequestConverters::getTransform, - options, - GetTransformResponse::fromXContent, - listener, - Collections.emptySet() - ); - } -} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/TransformRequestConverters.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/TransformRequestConverters.java deleted file mode 100644 index 2f27675a9efe3..0000000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/TransformRequestConverters.java +++ /dev/null @@ -1,162 +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 - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -package org.elasticsearch.client; - -import org.apache.http.client.methods.HttpDelete; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.client.methods.HttpPut; -import org.elasticsearch.client.core.PageParams; -import org.elasticsearch.client.transform.DeleteTransformRequest; -import org.elasticsearch.client.transform.GetTransformRequest; -import org.elasticsearch.client.transform.GetTransformStatsRequest; -import org.elasticsearch.client.transform.PreviewTransformRequest; -import org.elasticsearch.client.transform.PutTransformRequest; -import org.elasticsearch.client.transform.StartTransformRequest; -import org.elasticsearch.client.transform.StopTransformRequest; -import org.elasticsearch.client.transform.UpdateTransformRequest; -import org.elasticsearch.common.Strings; - -import java.io.IOException; - -import static org.elasticsearch.client.RequestConverters.REQUEST_BODY_CONTENT_TYPE; -import static org.elasticsearch.client.RequestConverters.createEntity; -import static org.elasticsearch.client.transform.DeleteTransformRequest.FORCE; -import static org.elasticsearch.client.transform.GetTransformRequest.ALLOW_NO_MATCH; -import static org.elasticsearch.client.transform.GetTransformRequest.EXCLUDE_GENERATED; -import static org.elasticsearch.client.transform.PutTransformRequest.DEFER_VALIDATION; -import static org.elasticsearch.client.transform.StopTransformRequest.WAIT_FOR_CHECKPOINT; - -final class TransformRequestConverters { - - private TransformRequestConverters() {} - - static Request putTransform(PutTransformRequest putRequest) throws IOException { - String endpoint = new RequestConverters.EndpointBuilder().addPathPartAsIs("_transform") - .addPathPart(putRequest.getConfig().getId()) - .build(); - Request request = new Request(HttpPut.METHOD_NAME, endpoint); - request.setEntity(createEntity(putRequest, REQUEST_BODY_CONTENT_TYPE)); - if (putRequest.getDeferValidation() != null) { - request.addParameter(DEFER_VALIDATION, Boolean.toString(putRequest.getDeferValidation())); - } - return request; - } - - static Request updateTransform(UpdateTransformRequest updateTransformRequest) throws IOException { - String endpoint = new RequestConverters.EndpointBuilder().addPathPartAsIs("_transform") - .addPathPart(updateTransformRequest.getId()) - .addPathPart("_update") - .build(); - Request request = new Request(HttpPost.METHOD_NAME, endpoint); - request.setEntity(createEntity(updateTransformRequest, REQUEST_BODY_CONTENT_TYPE)); - if (updateTransformRequest.getDeferValidation() != null) { - request.addParameter(DEFER_VALIDATION, Boolean.toString(updateTransformRequest.getDeferValidation())); - } - return request; - } - - static Request getTransform(GetTransformRequest getRequest) { - String endpoint = new RequestConverters.EndpointBuilder().addPathPartAsIs("_transform") - .addPathPart(Strings.collectionToCommaDelimitedString(getRequest.getId())) - .build(); - Request request = new Request(HttpGet.METHOD_NAME, endpoint); - if (getRequest.getPageParams() != null && getRequest.getPageParams().getFrom() != null) { - request.addParameter(PageParams.FROM.getPreferredName(), getRequest.getPageParams().getFrom().toString()); - } - if (getRequest.getPageParams() != null && getRequest.getPageParams().getSize() != null) { - request.addParameter(PageParams.SIZE.getPreferredName(), getRequest.getPageParams().getSize().toString()); - } - if (getRequest.getAllowNoMatch() != null) { - request.addParameter(ALLOW_NO_MATCH, getRequest.getAllowNoMatch().toString()); - } - if (getRequest.getExcludeGenerated() != null) { - request.addParameter(EXCLUDE_GENERATED, getRequest.getExcludeGenerated().toString()); - } - return request; - } - - static Request deleteTransform(DeleteTransformRequest deleteRequest) { - String endpoint = new RequestConverters.EndpointBuilder().addPathPartAsIs("_transform").addPathPart(deleteRequest.getId()).build(); - Request request = new Request(HttpDelete.METHOD_NAME, endpoint); - if (deleteRequest.getForce() != null) { - request.addParameter(FORCE, Boolean.toString(deleteRequest.getForce())); - } - return request; - } - - static Request startTransform(StartTransformRequest startRequest) { - String endpoint = new RequestConverters.EndpointBuilder().addPathPartAsIs("_transform") - .addPathPart(startRequest.getId()) - .addPathPartAsIs("_start") - .build(); - Request request = new Request(HttpPost.METHOD_NAME, endpoint); - RequestConverters.Params params = new RequestConverters.Params(); - if (startRequest.getTimeout() != null) { - params.withTimeout(startRequest.getTimeout()); - } - request.addParameters(params.asMap()); - return request; - } - - static Request stopTransform(StopTransformRequest stopRequest) { - String endpoint = new RequestConverters.EndpointBuilder().addPathPartAsIs("_transform") - .addPathPart(stopRequest.getId()) - .addPathPartAsIs("_stop") - .build(); - Request request = new Request(HttpPost.METHOD_NAME, endpoint); - RequestConverters.Params params = new RequestConverters.Params(); - if (stopRequest.getWaitForCompletion() != null) { - params.withWaitForCompletion(stopRequest.getWaitForCompletion()); - } - if (stopRequest.getTimeout() != null) { - params.withTimeout(stopRequest.getTimeout()); - } - if (stopRequest.getAllowNoMatch() != null) { - request.addParameter(ALLOW_NO_MATCH, stopRequest.getAllowNoMatch().toString()); - } - if (stopRequest.getWaitForCheckpoint() != null) { - request.addParameter(WAIT_FOR_CHECKPOINT, stopRequest.getWaitForCheckpoint().toString()); - } - request.addParameters(params.asMap()); - return request; - } - - static Request previewTransform(PreviewTransformRequest previewRequest) throws IOException { - RequestConverters.EndpointBuilder endpointBuilder = new RequestConverters.EndpointBuilder().addPathPartAsIs("_transform"); - if (previewRequest.getTransformId() != null) { - endpointBuilder.addPathPart(previewRequest.getTransformId()); - } - endpointBuilder.addPathPartAsIs("_preview"); - String endpoint = endpointBuilder.build(); - Request request = new Request(HttpPost.METHOD_NAME, endpoint); - if (previewRequest.getTransformId() == null) { - request.setEntity(createEntity(previewRequest, REQUEST_BODY_CONTENT_TYPE)); - } - return request; - } - - static Request getTransformStats(GetTransformStatsRequest statsRequest) { - String endpoint = new RequestConverters.EndpointBuilder().addPathPartAsIs("_transform") - .addPathPart(statsRequest.getId()) - .addPathPartAsIs("_stats") - .build(); - Request request = new Request(HttpGet.METHOD_NAME, endpoint); - if (statsRequest.getPageParams() != null && statsRequest.getPageParams().getFrom() != null) { - request.addParameter(PageParams.FROM.getPreferredName(), statsRequest.getPageParams().getFrom().toString()); - } - if (statsRequest.getPageParams() != null && statsRequest.getPageParams().getSize() != null) { - request.addParameter(PageParams.SIZE.getPreferredName(), statsRequest.getPageParams().getSize().toString()); - } - if (statsRequest.getAllowNoMatch() != null) { - request.addParameter(ALLOW_NO_MATCH, statsRequest.getAllowNoMatch().toString()); - } - return request; - } -} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/AcknowledgedTasksResponse.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/AcknowledgedTasksResponse.java deleted file mode 100644 index 9e83b3c4d3cd3..0000000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/AcknowledgedTasksResponse.java +++ /dev/null @@ -1,92 +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 - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -package org.elasticsearch.client.transform; - -import org.elasticsearch.ElasticsearchException; -import org.elasticsearch.action.TaskOperationFailure; -import org.elasticsearch.common.TriFunction; -import org.elasticsearch.core.Nullable; -import org.elasticsearch.xcontent.ConstructingObjectParser; -import org.elasticsearch.xcontent.ParseField; - -import java.util.Collections; -import java.util.List; -import java.util.Objects; - -import static org.elasticsearch.xcontent.ConstructingObjectParser.constructorArg; -import static org.elasticsearch.xcontent.ConstructingObjectParser.optionalConstructorArg; - -public class AcknowledgedTasksResponse { - - public static final ParseField TASK_FAILURES = new ParseField("task_failures"); - public static final ParseField NODE_FAILURES = new ParseField("node_failures"); - - @SuppressWarnings("unchecked") - protected static ConstructingObjectParser generateParser( - String name, - TriFunction, List, T> ctor, - String ackFieldName - ) { - - ConstructingObjectParser parser = new ConstructingObjectParser<>( - name, - true, - args -> ctor.apply((boolean) args[0], (List) args[1], (List) args[2]) - ); - parser.declareBoolean(constructorArg(), new ParseField(ackFieldName)); - parser.declareObjectArray(optionalConstructorArg(), (p, c) -> TaskOperationFailure.fromXContent(p), TASK_FAILURES); - parser.declareObjectArray(optionalConstructorArg(), (p, c) -> ElasticsearchException.fromXContent(p), NODE_FAILURES); - return parser; - } - - private boolean acknowledged; - private List taskFailures; - private List nodeFailures; - - public AcknowledgedTasksResponse( - boolean acknowledged, - @Nullable List taskFailures, - @Nullable List nodeFailures - ) { - this.acknowledged = acknowledged; - this.taskFailures = taskFailures == null ? Collections.emptyList() : Collections.unmodifiableList(taskFailures); - this.nodeFailures = nodeFailures == null ? Collections.emptyList() : Collections.unmodifiableList(nodeFailures); - } - - public boolean isAcknowledged() { - return acknowledged; - } - - public List getTaskFailures() { - return taskFailures; - } - - public List getNodeFailures() { - return nodeFailures; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - - if (obj == null || getClass() != obj.getClass()) { - return false; - } - - AcknowledgedTasksResponse other = (AcknowledgedTasksResponse) obj; - return acknowledged == other.acknowledged && taskFailures.equals(other.taskFailures) && nodeFailures.equals(other.nodeFailures); - } - - @Override - public int hashCode() { - return Objects.hash(acknowledged, taskFailures, nodeFailures); - } -} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/DeleteTransformRequest.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/DeleteTransformRequest.java deleted file mode 100644 index 5ae07af98aaf7..0000000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/DeleteTransformRequest.java +++ /dev/null @@ -1,71 +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 - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -package org.elasticsearch.client.transform; - -import org.elasticsearch.client.Validatable; -import org.elasticsearch.client.ValidationException; - -import java.util.Objects; -import java.util.Optional; - -/** - * Request to delete a transform - */ -public class DeleteTransformRequest implements Validatable { - - public static final String FORCE = "force"; - - private final String id; - private Boolean force; - - public DeleteTransformRequest(String id) { - this.id = id; - } - - public String getId() { - return id; - } - - public Boolean getForce() { - return force; - } - - public void setForce(boolean force) { - this.force = force; - } - - @Override - public Optional validate() { - if (id == null) { - ValidationException validationException = new ValidationException(); - validationException.addValidationError("transform id must not be null"); - return Optional.of(validationException); - } else { - return Optional.empty(); - } - } - - @Override - public int hashCode() { - return Objects.hash(id, force); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - - if (obj == null || getClass() != obj.getClass()) { - return false; - } - DeleteTransformRequest other = (DeleteTransformRequest) obj; - return Objects.equals(id, other.id) && Objects.equals(force, other.force); - } -} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/GetTransformRequest.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/GetTransformRequest.java deleted file mode 100644 index 8e8cb68bb6005..0000000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/GetTransformRequest.java +++ /dev/null @@ -1,101 +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 - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -package org.elasticsearch.client.transform; - -import org.elasticsearch.client.Validatable; -import org.elasticsearch.client.ValidationException; -import org.elasticsearch.client.core.PageParams; - -import java.util.Arrays; -import java.util.List; -import java.util.Objects; -import java.util.Optional; - -public class GetTransformRequest implements Validatable { - - public static final String EXCLUDE_GENERATED = "exclude_generated"; - public static final String ALLOW_NO_MATCH = "allow_no_match"; - - /** - * Helper method to create a request that will get ALL Transforms - * @return new {@link GetTransformRequest} object for the id "_all" - */ - public static GetTransformRequest getAllTransformRequest() { - return new GetTransformRequest("_all"); - } - - private final List ids; - private PageParams pageParams; - private Boolean allowNoMatch; - private Boolean excludeGenerated; - - public GetTransformRequest(String... ids) { - this.ids = Arrays.asList(ids); - } - - public List getId() { - return ids; - } - - public PageParams getPageParams() { - return pageParams; - } - - public void setPageParams(PageParams pageParams) { - this.pageParams = pageParams; - } - - public Boolean getAllowNoMatch() { - return allowNoMatch; - } - - public void setAllowNoMatch(Boolean allowNoMatch) { - this.allowNoMatch = allowNoMatch; - } - - public void setExcludeGenerated(boolean excludeGenerated) { - this.excludeGenerated = excludeGenerated; - } - - public Boolean getExcludeGenerated() { - return excludeGenerated; - } - - @Override - public Optional validate() { - if (ids == null || ids.isEmpty()) { - ValidationException validationException = new ValidationException(); - validationException.addValidationError("transform id must not be null"); - return Optional.of(validationException); - } else { - return Optional.empty(); - } - } - - @Override - public int hashCode() { - return Objects.hash(ids, pageParams, excludeGenerated, allowNoMatch); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - - if (obj == null || getClass() != obj.getClass()) { - return false; - } - GetTransformRequest other = (GetTransformRequest) obj; - return Objects.equals(ids, other.ids) - && Objects.equals(pageParams, other.pageParams) - && Objects.equals(excludeGenerated, other.excludeGenerated) - && Objects.equals(allowNoMatch, other.allowNoMatch); - } -} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/GetTransformResponse.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/GetTransformResponse.java deleted file mode 100644 index e927bfbb4f7c2..0000000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/GetTransformResponse.java +++ /dev/null @@ -1,134 +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 - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -package org.elasticsearch.client.transform; - -import org.elasticsearch.client.transform.transforms.TransformConfig; -import org.elasticsearch.core.Nullable; -import org.elasticsearch.xcontent.ConstructingObjectParser; -import org.elasticsearch.xcontent.ParseField; -import org.elasticsearch.xcontent.XContentParser; - -import java.util.List; -import java.util.Objects; - -import static org.elasticsearch.xcontent.ConstructingObjectParser.constructorArg; -import static org.elasticsearch.xcontent.ConstructingObjectParser.optionalConstructorArg; - -public class GetTransformResponse { - - public static final ParseField TRANSFORMS = new ParseField("transforms"); - public static final ParseField INVALID_TRANSFORMS = new ParseField("invalid_transforms"); - public static final ParseField COUNT = new ParseField("count"); - - @SuppressWarnings("unchecked") - static final ConstructingObjectParser INVALID_TRANSFORMS_PARSER = new ConstructingObjectParser<>( - "invalid_transforms", - true, - args -> new InvalidTransforms((List) args[0]) - ); - - @SuppressWarnings("unchecked") - static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>( - "get_transform", - true, - args -> new GetTransformResponse((List) args[0], (long) args[1], (InvalidTransforms) args[2]) - ); - static { - // Discard the count field which is the size of the transforms array - INVALID_TRANSFORMS_PARSER.declareLong((a, b) -> {}, COUNT); - INVALID_TRANSFORMS_PARSER.declareStringArray(constructorArg(), TRANSFORMS); - - PARSER.declareObjectArray(constructorArg(), TransformConfig.PARSER::apply, TRANSFORMS); - PARSER.declareLong(constructorArg(), COUNT); - PARSER.declareObject(optionalConstructorArg(), INVALID_TRANSFORMS_PARSER::apply, INVALID_TRANSFORMS); - } - - public static GetTransformResponse fromXContent(final XContentParser parser) { - return GetTransformResponse.PARSER.apply(parser, null); - } - - private List transformConfigurations; - private long count; - private InvalidTransforms invalidTransforms; - - public GetTransformResponse(List transformConfigurations, long count, @Nullable InvalidTransforms invalidTransforms) { - this.transformConfigurations = transformConfigurations; - this.count = count; - this.invalidTransforms = invalidTransforms; - } - - @Nullable - public InvalidTransforms getInvalidTransforms() { - return invalidTransforms; - } - - public long getCount() { - return count; - } - - public List getTransformConfigurations() { - return transformConfigurations; - } - - @Override - public int hashCode() { - return Objects.hash(transformConfigurations, count, invalidTransforms); - } - - @Override - public boolean equals(Object other) { - if (this == other) { - return true; - } - - if (other == null || getClass() != other.getClass()) { - return false; - } - - final GetTransformResponse that = (GetTransformResponse) other; - return Objects.equals(this.transformConfigurations, that.transformConfigurations) - && Objects.equals(this.count, that.count) - && Objects.equals(this.invalidTransforms, that.invalidTransforms); - } - - static class InvalidTransforms { - private final List transformIds; - - InvalidTransforms(List transformIds) { - this.transformIds = transformIds; - } - - public long getCount() { - return transformIds.size(); - } - - public List getTransformIds() { - return transformIds; - } - - @Override - public int hashCode() { - return Objects.hash(transformIds); - } - - @Override - public boolean equals(Object other) { - if (this == other) { - return true; - } - - if (other == null || getClass() != other.getClass()) { - return false; - } - - final InvalidTransforms that = (InvalidTransforms) other; - return Objects.equals(this.transformIds, that.transformIds); - } - } -} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/GetTransformStatsRequest.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/GetTransformStatsRequest.java deleted file mode 100644 index 7bdd999cb0317..0000000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/GetTransformStatsRequest.java +++ /dev/null @@ -1,77 +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 - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -package org.elasticsearch.client.transform; - -import org.elasticsearch.client.Validatable; -import org.elasticsearch.client.ValidationException; -import org.elasticsearch.client.core.PageParams; - -import java.util.Objects; -import java.util.Optional; - -public class GetTransformStatsRequest implements Validatable { - private final String id; - private PageParams pageParams; - private Boolean allowNoMatch; - - public GetTransformStatsRequest(String id) { - this.id = id; - } - - public String getId() { - return id; - } - - public PageParams getPageParams() { - return pageParams; - } - - public void setPageParams(PageParams pageParams) { - this.pageParams = pageParams; - } - - public Boolean getAllowNoMatch() { - return allowNoMatch; - } - - public void setAllowNoMatch(Boolean allowNoMatch) { - this.allowNoMatch = allowNoMatch; - } - - @Override - public Optional validate() { - if (id == null) { - ValidationException validationException = new ValidationException(); - validationException.addValidationError("transform id must not be null"); - return Optional.of(validationException); - } else { - return Optional.empty(); - } - } - - @Override - public int hashCode() { - return Objects.hash(id, pageParams, allowNoMatch); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - - if (obj == null || getClass() != obj.getClass()) { - return false; - } - GetTransformStatsRequest other = (GetTransformStatsRequest) obj; - return Objects.equals(id, other.id) - && Objects.equals(pageParams, other.pageParams) - && Objects.equals(allowNoMatch, other.allowNoMatch); - } -} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/GetTransformStatsResponse.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/GetTransformStatsResponse.java deleted file mode 100644 index d4c230e1997f2..0000000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/GetTransformStatsResponse.java +++ /dev/null @@ -1,116 +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 - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -package org.elasticsearch.client.transform; - -import org.elasticsearch.ElasticsearchException; -import org.elasticsearch.action.TaskOperationFailure; -import org.elasticsearch.client.transform.transforms.TransformStats; -import org.elasticsearch.core.Nullable; -import org.elasticsearch.xcontent.ConstructingObjectParser; -import org.elasticsearch.xcontent.ParseField; -import org.elasticsearch.xcontent.XContentParser; - -import java.util.Collections; -import java.util.List; -import java.util.Objects; - -import static org.elasticsearch.xcontent.ConstructingObjectParser.constructorArg; -import static org.elasticsearch.xcontent.ConstructingObjectParser.optionalConstructorArg; - -public class GetTransformStatsResponse { - - public static final ParseField TRANSFORMS = new ParseField("transforms"); - public static final ParseField COUNT = new ParseField("count"); - - @SuppressWarnings("unchecked") - static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>( - "get_transform_stats_response", - true, - args -> new GetTransformStatsResponse( - (List) args[0], - (long) args[1], - (List) args[2], - (List) args[3] - ) - ); - - static { - PARSER.declareObjectArray(constructorArg(), TransformStats.PARSER::apply, TRANSFORMS); - PARSER.declareLong(constructorArg(), COUNT); - PARSER.declareObjectArray( - optionalConstructorArg(), - (p, c) -> TaskOperationFailure.fromXContent(p), - AcknowledgedTasksResponse.TASK_FAILURES - ); - PARSER.declareObjectArray( - optionalConstructorArg(), - (p, c) -> ElasticsearchException.fromXContent(p), - AcknowledgedTasksResponse.NODE_FAILURES - ); - } - - public static GetTransformStatsResponse fromXContent(final XContentParser parser) { - return GetTransformStatsResponse.PARSER.apply(parser, null); - } - - private final List transformsStats; - private final long count; - private final List taskFailures; - private final List nodeFailures; - - public GetTransformStatsResponse( - List transformsStats, - long count, - @Nullable List taskFailures, - @Nullable List nodeFailures - ) { - this.transformsStats = transformsStats; - this.count = count; - this.taskFailures = taskFailures == null ? Collections.emptyList() : Collections.unmodifiableList(taskFailures); - this.nodeFailures = nodeFailures == null ? Collections.emptyList() : Collections.unmodifiableList(nodeFailures); - } - - public List getTransformsStats() { - return transformsStats; - } - - public long getCount() { - return count; - } - - public List getNodeFailures() { - return nodeFailures; - } - - public List getTaskFailures() { - return taskFailures; - } - - @Override - public int hashCode() { - return Objects.hash(transformsStats, count, nodeFailures, taskFailures); - } - - @Override - public boolean equals(Object other) { - if (this == other) { - return true; - } - - if (other == null || getClass() != other.getClass()) { - return false; - } - - final GetTransformStatsResponse that = (GetTransformStatsResponse) other; - return Objects.equals(this.transformsStats, that.transformsStats) - && Objects.equals(this.count, that.count) - && Objects.equals(this.nodeFailures, that.nodeFailures) - && Objects.equals(this.taskFailures, that.taskFailures); - } -} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/PreviewTransformRequest.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/PreviewTransformRequest.java deleted file mode 100644 index 89f6ee240459d..0000000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/PreviewTransformRequest.java +++ /dev/null @@ -1,86 +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 - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -package org.elasticsearch.client.transform; - -import org.elasticsearch.client.Validatable; -import org.elasticsearch.client.ValidationException; -import org.elasticsearch.client.transform.transforms.TransformConfig; -import org.elasticsearch.xcontent.ToXContent; -import org.elasticsearch.xcontent.ToXContentObject; -import org.elasticsearch.xcontent.XContentBuilder; - -import java.io.IOException; -import java.util.Objects; -import java.util.Optional; - -public class PreviewTransformRequest implements ToXContentObject, Validatable { - - private final String transformId; - private final TransformConfig config; - - public PreviewTransformRequest(String transformId) { - this.transformId = Objects.requireNonNull(transformId); - this.config = null; - } - - public PreviewTransformRequest(TransformConfig config) { - this.transformId = null; - this.config = Objects.requireNonNull(config); - } - - public String getTransformId() { - return transformId; - } - - public TransformConfig getConfig() { - return config; - } - - @Override - public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException { - if (this.config != null) { - return this.config.toXContent(builder, params); - } else { - return builder.startObject().field(TransformConfig.ID.getPreferredName(), this.transformId).endObject(); - } - } - - @Override - public Optional validate() { - ValidationException validationException = new ValidationException(); - if (config != null) { - if (config.getSource() == null) { - validationException.addValidationError("transform source cannot be null"); - } - } - - if (validationException.validationErrors().isEmpty()) { - return Optional.empty(); - } else { - return Optional.of(validationException); - } - } - - @Override - public int hashCode() { - return Objects.hash(transformId, config); - } - - @Override - public boolean equals(Object obj) { - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - PreviewTransformRequest other = (PreviewTransformRequest) obj; - return Objects.equals(transformId, other.transformId) && Objects.equals(config, other.config); - } -} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/PreviewTransformResponse.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/PreviewTransformResponse.java deleted file mode 100644 index 92e396b8e95b2..0000000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/PreviewTransformResponse.java +++ /dev/null @@ -1,186 +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 - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -package org.elasticsearch.client.transform; - -import org.elasticsearch.action.admin.indices.alias.Alias; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.xcontent.ConstructingObjectParser; -import org.elasticsearch.xcontent.ParseField; -import org.elasticsearch.xcontent.XContentParser; - -import java.io.IOException; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Set; - -import static org.elasticsearch.xcontent.ConstructingObjectParser.optionalConstructorArg; - -public class PreviewTransformResponse { - - public static class GeneratedDestIndexSettings { - static final ParseField MAPPINGS = new ParseField("mappings"); - private static final ParseField SETTINGS = new ParseField("settings"); - private static final ParseField ALIASES = new ParseField("aliases"); - - private final Map mappings; - private final Settings settings; - private final Set aliases; - - private static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>( - "transform_preview_generated_dest_index", - true, - args -> { - @SuppressWarnings("unchecked") - Map mappings = (Map) args[0]; - Settings settings = (Settings) args[1]; - @SuppressWarnings("unchecked") - Set aliases = (Set) args[2]; - - return new GeneratedDestIndexSettings(mappings, settings, aliases); - } - ); - - static { - PARSER.declareObject(optionalConstructorArg(), (p, c) -> p.mapOrdered(), MAPPINGS); - PARSER.declareObject(optionalConstructorArg(), (p, c) -> Settings.fromXContent(p), SETTINGS); - PARSER.declareObject(optionalConstructorArg(), (p, c) -> { - Set aliases = new HashSet<>(); - while ((p.nextToken()) != XContentParser.Token.END_OBJECT) { - aliases.add(Alias.fromXContent(p)); - } - return aliases; - }, ALIASES); - } - - public GeneratedDestIndexSettings(Map mappings, Settings settings, Set aliases) { - this.mappings = mappings == null ? Collections.emptyMap() : Collections.unmodifiableMap(mappings); - this.settings = settings == null ? Settings.EMPTY : settings; - this.aliases = aliases == null ? Collections.emptySet() : Collections.unmodifiableSet(aliases); - } - - public Map getMappings() { - return mappings; - } - - public Settings getSettings() { - return settings; - } - - public Set getAliases() { - return aliases; - } - - public static GeneratedDestIndexSettings fromXContent(final XContentParser parser) { - return PARSER.apply(parser, null); - } - - @Override - public boolean equals(Object obj) { - if (obj == this) { - return true; - } - - if (obj == null || obj.getClass() != getClass()) { - return false; - } - - GeneratedDestIndexSettings other = (GeneratedDestIndexSettings) obj; - return Objects.equals(other.mappings, mappings) - && Objects.equals(other.settings, settings) - && Objects.equals(other.aliases, aliases); - } - - @Override - public int hashCode() { - return Objects.hash(mappings, settings, aliases); - } - } - - public static final ParseField PREVIEW = new ParseField("preview"); - public static final ParseField GENERATED_DEST_INDEX_SETTINGS = new ParseField("generated_dest_index"); - - private final List> docs; - private final GeneratedDestIndexSettings generatedDestIndexSettings; - - private static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>( - "data_frame_transform_preview", - true, - args -> { - @SuppressWarnings("unchecked") - List> docs = (List>) args[0]; - GeneratedDestIndexSettings generatedDestIndex = (GeneratedDestIndexSettings) args[1]; - - // ensure generatedDestIndex is not null - if (generatedDestIndex == null) { - // BWC parsing the output from nodes < 7.7 - @SuppressWarnings("unchecked") - Map mappings = (Map) args[2]; - generatedDestIndex = new GeneratedDestIndexSettings(mappings, null, null); - } - - return new PreviewTransformResponse(docs, generatedDestIndex); - } - ); - static { - PARSER.declareObjectArray(optionalConstructorArg(), (p, c) -> p.mapOrdered(), PREVIEW); - PARSER.declareObject(optionalConstructorArg(), (p, c) -> GeneratedDestIndexSettings.fromXContent(p), GENERATED_DEST_INDEX_SETTINGS); - PARSER.declareObject(optionalConstructorArg(), (p, c) -> p.mapOrdered(), GeneratedDestIndexSettings.MAPPINGS); - } - - public PreviewTransformResponse(List> docs, GeneratedDestIndexSettings generatedDestIndexSettings) { - this.docs = docs; - this.generatedDestIndexSettings = generatedDestIndexSettings; - } - - public List> getDocs() { - return docs; - } - - public GeneratedDestIndexSettings getGeneratedDestIndexSettings() { - return generatedDestIndexSettings; - } - - public Map getMappings() { - return generatedDestIndexSettings.getMappings(); - } - - public Settings getSettings() { - return generatedDestIndexSettings.getSettings(); - } - - public Set getAliases() { - return generatedDestIndexSettings.getAliases(); - } - - @Override - public boolean equals(Object obj) { - if (obj == this) { - return true; - } - - if (obj == null || obj.getClass() != getClass()) { - return false; - } - - PreviewTransformResponse other = (PreviewTransformResponse) obj; - return Objects.equals(other.docs, docs) && Objects.equals(other.generatedDestIndexSettings, generatedDestIndexSettings); - } - - @Override - public int hashCode() { - return Objects.hash(docs, generatedDestIndexSettings); - } - - public static PreviewTransformResponse fromXContent(final XContentParser parser) throws IOException { - return PARSER.parse(parser, null); - } -} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/PutTransformRequest.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/PutTransformRequest.java deleted file mode 100644 index 1af5c96088a3e..0000000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/PutTransformRequest.java +++ /dev/null @@ -1,94 +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 - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -package org.elasticsearch.client.transform; - -import org.elasticsearch.client.Validatable; -import org.elasticsearch.client.ValidationException; -import org.elasticsearch.client.transform.transforms.TransformConfig; -import org.elasticsearch.xcontent.ToXContentObject; -import org.elasticsearch.xcontent.XContentBuilder; - -import java.io.IOException; -import java.util.Objects; -import java.util.Optional; - -public class PutTransformRequest implements ToXContentObject, Validatable { - - public static final String DEFER_VALIDATION = "defer_validation"; - private final TransformConfig config; - private Boolean deferValidation; - - public PutTransformRequest(TransformConfig config) { - this.config = config; - } - - public TransformConfig getConfig() { - return config; - } - - public Boolean getDeferValidation() { - return deferValidation; - } - - /** - * Indicates if deferrable validations should be skipped until the transform starts - * - * @param deferValidation {@code true} will cause validations to be deferred - */ - public void setDeferValidation(boolean deferValidation) { - this.deferValidation = deferValidation; - } - - @Override - public Optional validate() { - ValidationException validationException = new ValidationException(); - if (config == null) { - validationException.addValidationError("put requires a non-null transform config"); - return Optional.of(validationException); - } else { - if (config.getId() == null) { - validationException.addValidationError("transform id cannot be null"); - } - if (config.getSource() == null) { - validationException.addValidationError("transform source cannot be null"); - } - if (config.getDestination() == null) { - validationException.addValidationError("transform destination cannot be null"); - } - } - - if (validationException.validationErrors().isEmpty()) { - return Optional.empty(); - } else { - return Optional.of(validationException); - } - } - - @Override - public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { - return config.toXContent(builder, params); - } - - @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; - } - PutTransformRequest other = (PutTransformRequest) obj; - return Objects.equals(config, other.config); - } -} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/StartTransformRequest.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/StartTransformRequest.java deleted file mode 100644 index fe68ab6d4521a..0000000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/StartTransformRequest.java +++ /dev/null @@ -1,72 +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 - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -package org.elasticsearch.client.transform; - -import org.elasticsearch.client.Validatable; -import org.elasticsearch.client.ValidationException; -import org.elasticsearch.core.TimeValue; - -import java.util.Objects; -import java.util.Optional; - -public class StartTransformRequest implements Validatable { - - private final String id; - private TimeValue timeout; - - public StartTransformRequest(String id) { - this.id = id; - } - - public StartTransformRequest(String id, TimeValue timeout) { - this.id = id; - this.timeout = timeout; - } - - public String getId() { - return id; - } - - public TimeValue getTimeout() { - return timeout; - } - - public void setTimeout(TimeValue timeout) { - this.timeout = timeout; - } - - @Override - public Optional validate() { - if (id == null) { - ValidationException validationException = new ValidationException(); - validationException.addValidationError("transform id must not be null"); - return Optional.of(validationException); - } else { - return Optional.empty(); - } - } - - @Override - public int hashCode() { - return Objects.hash(id, timeout); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - - if (obj == null || getClass() != obj.getClass()) { - return false; - } - StartTransformRequest other = (StartTransformRequest) obj; - return Objects.equals(this.id, other.id) && Objects.equals(this.timeout, other.timeout); - } -} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/StartTransformResponse.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/StartTransformResponse.java deleted file mode 100644 index cc620000aec40..0000000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/StartTransformResponse.java +++ /dev/null @@ -1,42 +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 - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -package org.elasticsearch.client.transform; - -import org.elasticsearch.ElasticsearchException; -import org.elasticsearch.action.TaskOperationFailure; -import org.elasticsearch.core.Nullable; -import org.elasticsearch.xcontent.ConstructingObjectParser; -import org.elasticsearch.xcontent.XContentParser; - -import java.io.IOException; -import java.util.List; - -public class StartTransformResponse extends AcknowledgedTasksResponse { - - private static final String ACKNOWLEDGED = "acknowledged"; - - private static final ConstructingObjectParser PARSER = AcknowledgedTasksResponse.generateParser( - "start_transform_response", - StartTransformResponse::new, - ACKNOWLEDGED - ); - - public static StartTransformResponse fromXContent(final XContentParser parser) throws IOException { - return PARSER.parse(parser, null); - } - - public StartTransformResponse( - boolean acknowledged, - @Nullable List taskFailures, - @Nullable List nodeFailures - ) { - super(acknowledged, taskFailures, nodeFailures); - } - -} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/StopTransformRequest.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/StopTransformRequest.java deleted file mode 100644 index 8c7c3472a895f..0000000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/StopTransformRequest.java +++ /dev/null @@ -1,108 +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 - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -package org.elasticsearch.client.transform; - -import org.elasticsearch.client.Validatable; -import org.elasticsearch.client.ValidationException; -import org.elasticsearch.core.TimeValue; - -import java.util.Objects; -import java.util.Optional; - -public class StopTransformRequest implements Validatable { - - public static final String WAIT_FOR_CHECKPOINT = "wait_for_checkpoint"; - - private final String id; - private Boolean waitForCompletion; - private Boolean waitForCheckpoint; - private TimeValue timeout; - private Boolean allowNoMatch; - - public StopTransformRequest(String id) { - this(id, null, null, null); - } - - public StopTransformRequest(String id, Boolean waitForCompletion, TimeValue timeout, Boolean waitForCheckpoint) { - this.id = id; - this.waitForCompletion = waitForCompletion; - this.timeout = timeout; - this.waitForCheckpoint = waitForCheckpoint; - } - - public String getId() { - return id; - } - - public void setWaitForCompletion(Boolean waitForCompletion) { - this.waitForCompletion = waitForCompletion; - } - - public Boolean getWaitForCompletion() { - return waitForCompletion; - } - - public void setTimeout(TimeValue timeout) { - this.timeout = timeout; - } - - public TimeValue getTimeout() { - return timeout; - } - - public Boolean getAllowNoMatch() { - return allowNoMatch; - } - - public void setAllowNoMatch(Boolean allowNoMatch) { - this.allowNoMatch = allowNoMatch; - } - - public Boolean getWaitForCheckpoint() { - return waitForCheckpoint; - } - - public void setWaitForCheckpoint(Boolean waitForCheckpoint) { - this.waitForCheckpoint = waitForCheckpoint; - } - - @Override - public Optional validate() { - if (id == null) { - ValidationException validationException = new ValidationException(); - validationException.addValidationError("transform id must not be null"); - return Optional.of(validationException); - } else { - return Optional.empty(); - } - } - - @Override - public int hashCode() { - return Objects.hash(id, waitForCompletion, timeout, allowNoMatch, waitForCheckpoint); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - - if (obj == null || getClass() != obj.getClass()) { - return false; - } - StopTransformRequest other = (StopTransformRequest) obj; - return Objects.equals(this.id, other.id) - && Objects.equals(this.waitForCompletion, other.waitForCompletion) - && Objects.equals(this.timeout, other.timeout) - && Objects.equals(this.waitForCheckpoint, other.waitForCheckpoint) - && Objects.equals(this.allowNoMatch, other.allowNoMatch); - } - -} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/StopTransformResponse.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/StopTransformResponse.java deleted file mode 100644 index d2a27aeb41281..0000000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/StopTransformResponse.java +++ /dev/null @@ -1,42 +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 - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -package org.elasticsearch.client.transform; - -import org.elasticsearch.ElasticsearchException; -import org.elasticsearch.action.TaskOperationFailure; -import org.elasticsearch.core.Nullable; -import org.elasticsearch.xcontent.ConstructingObjectParser; -import org.elasticsearch.xcontent.XContentParser; - -import java.io.IOException; -import java.util.List; - -public class StopTransformResponse extends AcknowledgedTasksResponse { - - private static final String ACKNOWLEDGED = "acknowledged"; - - private static final ConstructingObjectParser PARSER = AcknowledgedTasksResponse.generateParser( - "stop_transform_response", - StopTransformResponse::new, - ACKNOWLEDGED - ); - - public static StopTransformResponse fromXContent(final XContentParser parser) throws IOException { - return PARSER.parse(parser, null); - } - - public StopTransformResponse( - boolean acknowledged, - @Nullable List taskFailures, - @Nullable List nodeFailures - ) { - super(acknowledged, taskFailures, nodeFailures); - } - -} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/TransformNamedXContentProvider.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/TransformNamedXContentProvider.java deleted file mode 100644 index f0a5313f527dd..0000000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/TransformNamedXContentProvider.java +++ /dev/null @@ -1,36 +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 - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -package org.elasticsearch.client.transform; - -import org.elasticsearch.client.transform.transforms.RetentionPolicyConfig; -import org.elasticsearch.client.transform.transforms.SyncConfig; -import org.elasticsearch.client.transform.transforms.TimeRetentionPolicyConfig; -import org.elasticsearch.client.transform.transforms.TimeSyncConfig; -import org.elasticsearch.plugins.spi.NamedXContentProvider; -import org.elasticsearch.xcontent.NamedXContentRegistry; -import org.elasticsearch.xcontent.ParseField; - -import java.util.Arrays; -import java.util.List; - -public class TransformNamedXContentProvider implements NamedXContentProvider { - - @Override - public List getNamedXContentParsers() { - return Arrays.asList( - new NamedXContentRegistry.Entry(SyncConfig.class, new ParseField(TimeSyncConfig.NAME), TimeSyncConfig::fromXContent), - new NamedXContentRegistry.Entry( - RetentionPolicyConfig.class, - new ParseField(TimeRetentionPolicyConfig.NAME), - TimeRetentionPolicyConfig::fromXContent - ) - ); - } - -} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/UpdateTransformRequest.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/UpdateTransformRequest.java deleted file mode 100644 index 39519bfe38cc8..0000000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/UpdateTransformRequest.java +++ /dev/null @@ -1,92 +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 - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -package org.elasticsearch.client.transform; - -import org.elasticsearch.client.Validatable; -import org.elasticsearch.client.ValidationException; -import org.elasticsearch.client.transform.transforms.TransformConfigUpdate; -import org.elasticsearch.xcontent.ToXContentObject; -import org.elasticsearch.xcontent.XContentBuilder; - -import java.io.IOException; -import java.util.Objects; -import java.util.Optional; - -public class UpdateTransformRequest implements ToXContentObject, Validatable { - - private final TransformConfigUpdate update; - private final String id; - private Boolean deferValidation; - - public UpdateTransformRequest(TransformConfigUpdate update, String id) { - this.update = update; - this.id = id; - } - - public TransformConfigUpdate getUpdate() { - return update; - } - - public Boolean getDeferValidation() { - return deferValidation; - } - - public String getId() { - return id; - } - - /** - * Indicates if deferrable validations should be skipped until the transform starts - * - * @param deferValidation {@code true} will cause validations to be deferred - */ - public void setDeferValidation(boolean deferValidation) { - this.deferValidation = deferValidation; - } - - @Override - public Optional validate() { - ValidationException validationException = new ValidationException(); - if (update == null) { - validationException.addValidationError("put requires a non-null transform config update object"); - } - if (id == null) { - validationException.addValidationError("transform id cannot be null"); - } - if (validationException.validationErrors().isEmpty()) { - return Optional.empty(); - } else { - return Optional.of(validationException); - } - } - - @Override - public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { - return update.toXContent(builder, params); - } - - @Override - public int hashCode() { - return Objects.hash(update, deferValidation, id); - } - - @Override - public boolean equals(Object obj) { - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - UpdateTransformRequest other = (UpdateTransformRequest) obj; - return Objects.equals(update, other.update) - && Objects.equals(id, other.id) - && Objects.equals(deferValidation, other.deferValidation); - } -} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/UpdateTransformResponse.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/UpdateTransformResponse.java deleted file mode 100644 index 87a6451cccbd5..0000000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/UpdateTransformResponse.java +++ /dev/null @@ -1,50 +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 - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -package org.elasticsearch.client.transform; - -import org.elasticsearch.client.transform.transforms.TransformConfig; -import org.elasticsearch.xcontent.XContentParser; - -import java.util.Objects; - -public class UpdateTransformResponse { - - public static UpdateTransformResponse fromXContent(final XContentParser parser) { - return new UpdateTransformResponse(TransformConfig.PARSER.apply(parser, null)); - } - - private TransformConfig transformConfiguration; - - public UpdateTransformResponse(TransformConfig transformConfiguration) { - this.transformConfiguration = transformConfiguration; - } - - public TransformConfig getTransformConfiguration() { - return transformConfiguration; - } - - @Override - public int hashCode() { - return Objects.hash(transformConfiguration); - } - - @Override - public boolean equals(Object other) { - if (this == other) { - return true; - } - - if (other == null || getClass() != other.getClass()) { - return false; - } - - final UpdateTransformResponse that = (UpdateTransformResponse) other; - return Objects.equals(this.transformConfiguration, that.transformConfiguration); - } -} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/UpgradeTransformsRequest.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/UpgradeTransformsRequest.java deleted file mode 100644 index 83cf60eeb22bc..0000000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/UpgradeTransformsRequest.java +++ /dev/null @@ -1,51 +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 - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -package org.elasticsearch.client.transform; - -import org.elasticsearch.client.Validatable; - -import java.util.Objects; - -public class UpgradeTransformsRequest implements Validatable { - - private Boolean dryRun; - - public UpgradeTransformsRequest() {} - - public Boolean isDryRun() { - return dryRun; - } - - /** - * Whether to only check for an upgrade without taking action - * - * @param dryRun {@code true} will only check for upgrades - */ - public void setDryRun(boolean dryRun) { - this.dryRun = dryRun; - } - - @Override - public int hashCode() { - return Objects.hash(dryRun); - } - - @Override - public boolean equals(Object obj) { - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - UpgradeTransformsRequest other = (UpgradeTransformsRequest) obj; - return Objects.equals(dryRun, other.dryRun); - } - -} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/UpgradeTransformsResponse.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/UpgradeTransformsResponse.java deleted file mode 100644 index f1c7095bd7599..0000000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/UpgradeTransformsResponse.java +++ /dev/null @@ -1,87 +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 - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -package org.elasticsearch.client.transform; - -import org.elasticsearch.xcontent.ConstructingObjectParser; -import org.elasticsearch.xcontent.ParseField; -import org.elasticsearch.xcontent.XContentParser; - -import java.util.Objects; - -import static org.elasticsearch.xcontent.ConstructingObjectParser.optionalConstructorArg; - -public class UpgradeTransformsResponse { - - public static final ParseField NO_ACTION = new ParseField("no_action"); - public static final ParseField UPDATED = new ParseField("updated"); - public static final ParseField NEEDS_UPDATE = new ParseField("needs_update"); - - private static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>( - "upgrade_transform", - true, - args -> { - long updated = args[0] == null ? 0L : (Long) args[0]; - long noAction = args[1] == null ? 0L : (Long) args[1]; - long needsUpdate = args[2] == null ? 0L : (Long) args[2]; - - return new UpgradeTransformsResponse(updated, noAction, needsUpdate); - } - ); - - static { - PARSER.declareLong(optionalConstructorArg(), UPDATED); - PARSER.declareLong(optionalConstructorArg(), NO_ACTION); - PARSER.declareLong(optionalConstructorArg(), NEEDS_UPDATE); - } - - public static UpgradeTransformsResponse fromXContent(final XContentParser parser) { - return UpgradeTransformsResponse.PARSER.apply(parser, null); - } - - private final long updated; - private final long noAction; - private final long needsUpdate; - - public UpgradeTransformsResponse(long updated, long noAction, long needsUpdate) { - this.updated = updated; - this.noAction = noAction; - this.needsUpdate = needsUpdate; - } - - @Override - public int hashCode() { - return Objects.hash(updated, noAction, needsUpdate); - } - - @Override - public boolean equals(Object other) { - if (this == other) { - return true; - } - - if (other == null || getClass() != other.getClass()) { - return false; - } - - final UpgradeTransformsResponse that = (UpgradeTransformsResponse) other; - return this.updated == that.updated && this.noAction == that.noAction && this.needsUpdate == that.needsUpdate; - } - - public long getUpdated() { - return updated; - } - - public long getNoAction() { - return noAction; - } - - public long getNeedsUpdate() { - return needsUpdate; - } -} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/transforms/DestConfig.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/transforms/DestConfig.java deleted file mode 100644 index 4941f663d7a97..0000000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/transforms/DestConfig.java +++ /dev/null @@ -1,118 +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 - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -package org.elasticsearch.client.transform.transforms; - -import org.elasticsearch.xcontent.ConstructingObjectParser; -import org.elasticsearch.xcontent.ParseField; -import org.elasticsearch.xcontent.ToXContentObject; -import org.elasticsearch.xcontent.XContentBuilder; - -import java.io.IOException; -import java.util.Objects; - -import static org.elasticsearch.xcontent.ConstructingObjectParser.constructorArg; -import static org.elasticsearch.xcontent.ConstructingObjectParser.optionalConstructorArg; - -/** - * Configuration containing the destination index for the {@link TransformConfig} - */ -public class DestConfig implements ToXContentObject { - - public static final ParseField INDEX = new ParseField("index"); - public static final ParseField PIPELINE = new ParseField("pipeline"); - - public static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>( - "transform_config_dest", - true, - args -> new DestConfig((String) args[0], (String) args[1]) - ); - - static { - PARSER.declareString(constructorArg(), INDEX); - PARSER.declareString(optionalConstructorArg(), PIPELINE); - } - - private final String index; - private final String pipeline; - - public DestConfig(String index, String pipeline) { - this.index = Objects.requireNonNull(index, INDEX.getPreferredName()); - this.pipeline = pipeline; - } - - public String getIndex() { - return index; - } - - public String getPipeline() { - return pipeline; - } - - @Override - public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { - builder.startObject(); - builder.field(INDEX.getPreferredName(), index); - if (pipeline != null) { - builder.field(PIPELINE.getPreferredName(), pipeline); - } - builder.endObject(); - return builder; - } - - @Override - public boolean equals(Object other) { - if (other == this) { - return true; - } - if (other == null || other.getClass() != getClass()) { - return false; - } - - DestConfig that = (DestConfig) other; - return Objects.equals(index, that.index) && Objects.equals(pipeline, that.pipeline); - } - - @Override - public int hashCode() { - return Objects.hash(index, pipeline); - } - - public static Builder builder() { - return new Builder(); - } - - public static class Builder { - private String index; - private String pipeline; - - /** - * Sets which index to which to write the data - * @param index where to write the data - * @return The {@link Builder} with index set - */ - public Builder setIndex(String index) { - this.index = Objects.requireNonNull(index, INDEX.getPreferredName()); - return this; - } - - /** - * Sets the pipeline through which the indexed documents should be processed - * @param pipeline The pipeline ID - * @return The {@link Builder} with pipeline set - */ - public Builder setPipeline(String pipeline) { - this.pipeline = pipeline; - return this; - } - - public DestConfig build() { - return new DestConfig(index, pipeline); - } - } -} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/transforms/NodeAttributes.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/transforms/NodeAttributes.java deleted file mode 100644 index 77e418faaf6c4..0000000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/transforms/NodeAttributes.java +++ /dev/null @@ -1,140 +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 - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ -package org.elasticsearch.client.transform.transforms; - -import org.elasticsearch.common.Strings; -import org.elasticsearch.xcontent.ConstructingObjectParser; -import org.elasticsearch.xcontent.ObjectParser; -import org.elasticsearch.xcontent.ParseField; -import org.elasticsearch.xcontent.ToXContentObject; -import org.elasticsearch.xcontent.XContentBuilder; - -import java.io.IOException; -import java.util.Collections; -import java.util.Map; -import java.util.Objects; - -/** - * A Pojo class containing an Elastic Node's attributes - */ -public class NodeAttributes implements ToXContentObject { - - public static final ParseField ID = new ParseField("id"); - public static final ParseField NAME = new ParseField("name"); - public static final ParseField EPHEMERAL_ID = new ParseField("ephemeral_id"); - public static final ParseField TRANSPORT_ADDRESS = new ParseField("transport_address"); - public static final ParseField ATTRIBUTES = new ParseField("attributes"); - - @SuppressWarnings("unchecked") - public static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>("node", true, (a) -> { - int i = 0; - String id = (String) a[i++]; - String name = (String) a[i++]; - String ephemeralId = (String) a[i++]; - String transportAddress = (String) a[i++]; - Map attributes = (Map) a[i]; - return new NodeAttributes(id, name, ephemeralId, transportAddress, attributes); - }); - - static { - PARSER.declareString(ConstructingObjectParser.constructorArg(), ID); - PARSER.declareString(ConstructingObjectParser.constructorArg(), NAME); - PARSER.declareString(ConstructingObjectParser.constructorArg(), EPHEMERAL_ID); - PARSER.declareString(ConstructingObjectParser.constructorArg(), TRANSPORT_ADDRESS); - PARSER.declareField(ConstructingObjectParser.constructorArg(), (p, c) -> p.mapStrings(), ATTRIBUTES, ObjectParser.ValueType.OBJECT); - } - - private final String id; - private final String name; - private final String ephemeralId; - private final String transportAddress; - private final Map attributes; - - public NodeAttributes(String id, String name, String ephemeralId, String transportAddress, Map attributes) { - this.id = id; - this.name = name; - this.ephemeralId = ephemeralId; - this.transportAddress = transportAddress; - this.attributes = Collections.unmodifiableMap(attributes); - } - - /** - * The unique identifier of the node. - */ - public String getId() { - return id; - } - - /** - * The node name. - */ - public String getName() { - return name; - } - - /** - * The ephemeral id of the node. - */ - public String getEphemeralId() { - return ephemeralId; - } - - /** - * The host and port where transport HTTP connections are accepted. - */ - public String getTransportAddress() { - return transportAddress; - } - - /** - * Additional attributes related to this node - */ - public Map getAttributes() { - return attributes; - } - - @Override - public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { - builder.startObject(); - builder.field(ID.getPreferredName(), id); - builder.field(NAME.getPreferredName(), name); - builder.field(EPHEMERAL_ID.getPreferredName(), ephemeralId); - builder.field(TRANSPORT_ADDRESS.getPreferredName(), transportAddress); - builder.field(ATTRIBUTES.getPreferredName(), attributes); - builder.endObject(); - return builder; - } - - @Override - public int hashCode() { - return Objects.hash(id, name, ephemeralId, transportAddress, attributes); - } - - @Override - public boolean equals(Object other) { - if (this == other) { - return true; - } - - if (other == null || getClass() != other.getClass()) { - return false; - } - - NodeAttributes that = (NodeAttributes) other; - return Objects.equals(id, that.id) - && Objects.equals(name, that.name) - && Objects.equals(ephemeralId, that.ephemeralId) - && Objects.equals(transportAddress, that.transportAddress) - && Objects.equals(attributes, that.attributes); - } - - @Override - public String toString() { - return Strings.toString(this); - } -} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/transforms/QueryConfig.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/transforms/QueryConfig.java deleted file mode 100644 index da6bdc02fd002..0000000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/transforms/QueryConfig.java +++ /dev/null @@ -1,66 +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 - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -package org.elasticsearch.client.transform.transforms; - -import org.elasticsearch.index.query.AbstractQueryBuilder; -import org.elasticsearch.index.query.QueryBuilder; -import org.elasticsearch.xcontent.ToXContentObject; -import org.elasticsearch.xcontent.XContentBuilder; -import org.elasticsearch.xcontent.XContentParser; - -import java.io.IOException; -import java.util.Objects; - -/** - * Object for encapsulating the desired Query for a Transform - */ -public class QueryConfig implements ToXContentObject { - - private final QueryBuilder query; - - public static QueryConfig fromXContent(XContentParser parser) throws IOException { - QueryBuilder query = AbstractQueryBuilder.parseInnerQueryBuilder(parser); - return new QueryConfig(query); - } - - public QueryConfig(QueryBuilder query) { - this.query = query; - } - - @Override - public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { - query.toXContent(builder, params); - return builder; - } - - public QueryBuilder getQuery() { - return query; - } - - @Override - public int hashCode() { - return Objects.hash(query); - } - - @Override - public boolean equals(Object other) { - if (this == other) { - return true; - } - - if (other == null || getClass() != other.getClass()) { - return false; - } - - final QueryConfig that = (QueryConfig) other; - - return Objects.equals(this.query, that.query); - } - -} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/transforms/RetentionPolicyConfig.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/transforms/RetentionPolicyConfig.java deleted file mode 100644 index 68b7881856a56..0000000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/transforms/RetentionPolicyConfig.java +++ /dev/null @@ -1,19 +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 - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -package org.elasticsearch.client.transform.transforms; - -import org.elasticsearch.xcontent.ToXContentObject; - -public interface RetentionPolicyConfig extends ToXContentObject { - - /** - * Returns the name of the writeable object - */ - String getName(); -} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/transforms/SettingsConfig.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/transforms/SettingsConfig.java deleted file mode 100644 index ce64cdb50fb3f..0000000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/transforms/SettingsConfig.java +++ /dev/null @@ -1,317 +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 - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -package org.elasticsearch.client.transform.transforms; - -import org.elasticsearch.xcontent.ConstructingObjectParser; -import org.elasticsearch.xcontent.ObjectParser.ValueType; -import org.elasticsearch.xcontent.ParseField; -import org.elasticsearch.xcontent.ToXContentObject; -import org.elasticsearch.xcontent.XContentBuilder; -import org.elasticsearch.xcontent.XContentParser; - -import java.io.IOException; -import java.util.Objects; - -import static org.elasticsearch.xcontent.ConstructingObjectParser.optionalConstructorArg; - -public class SettingsConfig implements ToXContentObject { - - private static final ParseField MAX_PAGE_SEARCH_SIZE = new ParseField("max_page_search_size"); - private static final ParseField DOCS_PER_SECOND = new ParseField("docs_per_second"); - private static final ParseField DATES_AS_EPOCH_MILLIS = new ParseField("dates_as_epoch_millis"); - private static final ParseField ALIGN_CHECKPOINTS = new ParseField("align_checkpoints"); - private static final ParseField USE_PIT = new ParseField("use_point_in_time"); - private static final ParseField DEDUCE_MAPPINGS = new ParseField("deduce_mappings"); - private static final int DEFAULT_MAX_PAGE_SEARCH_SIZE = -1; - private static final float DEFAULT_DOCS_PER_SECOND = -1F; - - // use an integer as we need to code 4 states: true, false, null (unchanged), default (defined server side) - private static final int DEFAULT_DATES_AS_EPOCH_MILLIS = -1; - - // use an integer as we need to code 4 states: true, false, null (unchanged), default (defined server side) - private static final int DEFAULT_ALIGN_CHECKPOINTS = -1; - - // use an integer as we need to code 4 states: true, false, null (unchanged), default (defined server side) - private static final int DEFAULT_USE_PIT = -1; - - // use an integer as we need to code 4 states: true, false, null (unchanged), default (defined server side) - private static final int DEFAULT_DEDUCE_MAPPINGS = -1; - - private final Integer maxPageSearchSize; - private final Float docsPerSecond; - private final Integer datesAsEpochMillis; - private final Integer alignCheckpoints; - private final Integer usePit; - private final Integer deduceMappings; - - private static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>( - "settings_config", - true, - args -> new SettingsConfig( - (Integer) args[0], - (Float) args[1], - (Integer) args[2], - (Integer) args[3], - (Integer) args[4], - (Integer) args[5] - ) - ); - - static { - PARSER.declareIntOrNull(optionalConstructorArg(), DEFAULT_MAX_PAGE_SEARCH_SIZE, MAX_PAGE_SEARCH_SIZE); - PARSER.declareFloatOrNull(optionalConstructorArg(), DEFAULT_DOCS_PER_SECOND, DOCS_PER_SECOND); - // this boolean requires 4 possible values: true, false, not_specified, default, therefore using a custom parser - PARSER.declareField( - optionalConstructorArg(), - p -> p.currentToken() == XContentParser.Token.VALUE_NULL ? DEFAULT_DATES_AS_EPOCH_MILLIS : p.booleanValue() ? 1 : 0, - DATES_AS_EPOCH_MILLIS, - ValueType.BOOLEAN_OR_NULL - ); - // this boolean requires 4 possible values: true, false, not_specified, default, therefore using a custom parser - PARSER.declareField( - optionalConstructorArg(), - p -> p.currentToken() == XContentParser.Token.VALUE_NULL ? DEFAULT_ALIGN_CHECKPOINTS : p.booleanValue() ? 1 : 0, - ALIGN_CHECKPOINTS, - ValueType.BOOLEAN_OR_NULL - ); - // this boolean requires 4 possible values: true, false, not_specified, default, therefore using a custom parser - PARSER.declareField( - optionalConstructorArg(), - p -> p.currentToken() == XContentParser.Token.VALUE_NULL ? DEFAULT_USE_PIT : p.booleanValue() ? 1 : 0, - USE_PIT, - ValueType.BOOLEAN_OR_NULL - ); - // this boolean requires 4 possible values: true, false, not_specified, default, therefore using a custom parser - PARSER.declareField( - optionalConstructorArg(), - p -> p.currentToken() == XContentParser.Token.VALUE_NULL ? DEFAULT_DEDUCE_MAPPINGS : p.booleanValue() ? 1 : 0, - DEDUCE_MAPPINGS, - ValueType.BOOLEAN_OR_NULL - ); - } - - public static SettingsConfig fromXContent(final XContentParser parser) { - return PARSER.apply(parser, null); - } - - SettingsConfig( - Integer maxPageSearchSize, - Float docsPerSecond, - Integer datesAsEpochMillis, - Integer alignCheckpoints, - Integer usePit, - Integer deduceMappings - ) { - this.maxPageSearchSize = maxPageSearchSize; - this.docsPerSecond = docsPerSecond; - this.datesAsEpochMillis = datesAsEpochMillis; - this.alignCheckpoints = alignCheckpoints; - this.usePit = usePit; - this.deduceMappings = deduceMappings; - } - - @Override - public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { - builder.startObject(); - if (maxPageSearchSize != null) { - if (maxPageSearchSize.equals(DEFAULT_MAX_PAGE_SEARCH_SIZE)) { - builder.field(MAX_PAGE_SEARCH_SIZE.getPreferredName(), (Integer) null); - } else { - builder.field(MAX_PAGE_SEARCH_SIZE.getPreferredName(), maxPageSearchSize); - } - } - if (docsPerSecond != null) { - if (docsPerSecond.equals(DEFAULT_DOCS_PER_SECOND)) { - builder.field(DOCS_PER_SECOND.getPreferredName(), (Float) null); - } else { - builder.field(DOCS_PER_SECOND.getPreferredName(), docsPerSecond); - } - } - if (datesAsEpochMillis != null) { - if (datesAsEpochMillis.equals(DEFAULT_DATES_AS_EPOCH_MILLIS)) { - builder.field(DATES_AS_EPOCH_MILLIS.getPreferredName(), (Boolean) null); - } else { - builder.field(DATES_AS_EPOCH_MILLIS.getPreferredName(), datesAsEpochMillis > 0 ? true : false); - } - } - if (alignCheckpoints != null) { - if (alignCheckpoints.equals(DEFAULT_ALIGN_CHECKPOINTS)) { - builder.field(ALIGN_CHECKPOINTS.getPreferredName(), (Boolean) null); - } else { - builder.field(ALIGN_CHECKPOINTS.getPreferredName(), alignCheckpoints > 0 ? true : false); - } - } - if (usePit != null) { - if (usePit.equals(DEFAULT_USE_PIT)) { - builder.field(USE_PIT.getPreferredName(), (Boolean) null); - } else { - builder.field(USE_PIT.getPreferredName(), usePit > 0 ? true : false); - } - } - if (deduceMappings != null) { - if (deduceMappings.equals(DEFAULT_DEDUCE_MAPPINGS)) { - builder.field(DEDUCE_MAPPINGS.getPreferredName(), (Boolean) null); - } else { - builder.field(DEDUCE_MAPPINGS.getPreferredName(), deduceMappings > 0 ? true : false); - } - } - builder.endObject(); - return builder; - } - - public Integer getMaxPageSearchSize() { - return maxPageSearchSize; - } - - public Float getDocsPerSecond() { - return docsPerSecond; - } - - public Boolean getDatesAsEpochMillis() { - return datesAsEpochMillis != null ? datesAsEpochMillis > 0 : null; - } - - public Boolean getAlignCheckpoints() { - return alignCheckpoints != null ? alignCheckpoints > 0 : null; - } - - public Boolean getUsePit() { - return usePit != null ? usePit > 0 : null; - } - - public Boolean getDeduceMappings() { - return deduceMappings != null ? deduceMappings > 0 : null; - } - - @Override - public boolean equals(Object other) { - if (other == this) { - return true; - } - if (other == null || other.getClass() != getClass()) { - return false; - } - - SettingsConfig that = (SettingsConfig) other; - return Objects.equals(maxPageSearchSize, that.maxPageSearchSize) - && Objects.equals(docsPerSecond, that.docsPerSecond) - && Objects.equals(datesAsEpochMillis, that.datesAsEpochMillis) - && Objects.equals(alignCheckpoints, that.alignCheckpoints) - && Objects.equals(usePit, that.usePit) - && Objects.equals(deduceMappings, that.deduceMappings); - } - - @Override - public int hashCode() { - return Objects.hash(maxPageSearchSize, docsPerSecond, datesAsEpochMillis, alignCheckpoints, usePit, deduceMappings); - } - - public static Builder builder() { - return new Builder(); - } - - public static class Builder { - private Integer maxPageSearchSize; - private Float docsPerSecond; - private Integer datesAsEpochMillis; - private Integer alignCheckpoints; - private Integer usePit; - private Integer deduceMappings; - - /** - * Sets the paging maximum paging maxPageSearchSize that transform can use when - * pulling the data from the source index. - * - * If OOM is triggered, the paging maxPageSearchSize is dynamically reduced so that the transform can continue to gather data. - * - * @param maxPageSearchSize Integer value between 10 and 10_000 - * @return the {@link Builder} with the paging maxPageSearchSize set. - */ - public Builder setMaxPageSearchSize(Integer maxPageSearchSize) { - this.maxPageSearchSize = maxPageSearchSize == null ? DEFAULT_MAX_PAGE_SEARCH_SIZE : maxPageSearchSize; - return this; - } - - /** - * Sets the docs per second that transform can use when pulling the data from the source index. - * - * This setting throttles transform by issuing queries less often, however processing still happens in - * batches. A value of 0 disables throttling (default). - * - * @param documentsPerSecond Integer value - * @return the {@link Builder} with requestsPerSecond set. - */ - public Builder setRequestsPerSecond(Float documentsPerSecond) { - this.docsPerSecond = documentsPerSecond == null ? DEFAULT_DOCS_PER_SECOND : documentsPerSecond; - return this; - } - - /** - * Whether to write the output of a date aggregation as millis since epoch or as formatted string (ISO format). - * - * Transforms created before 7.11 write dates as epoch_millis. The new default is ISO string. - * You can use this setter to configure the old style writing as epoch millis. - * - * An explicit `null` resets to default. - * - * @param datesAsEpochMillis true if dates should be written as epoch_millis. - * @return the {@link Builder} with datesAsEpochMilli set. - */ - public Builder setDatesAsEpochMillis(Boolean datesAsEpochMillis) { - this.datesAsEpochMillis = datesAsEpochMillis == null ? DEFAULT_DATES_AS_EPOCH_MILLIS : datesAsEpochMillis ? 1 : 0; - return this; - } - - /** - * Whether to align transform checkpoint ranges with date histogram interval. - * - * An explicit `null` resets to default. - * - * @param alignCheckpoints true if checkpoint ranges should be aligned with date histogram interval. - * @return the {@link Builder} with alignCheckpoints set. - */ - public Builder setAlignCheckpoints(Boolean alignCheckpoints) { - this.alignCheckpoints = alignCheckpoints == null ? DEFAULT_ALIGN_CHECKPOINTS : alignCheckpoints ? 1 : 0; - return this; - } - - /** - * Whether the point in time API should be used for search. - * Point in time is a more resource friendly way to query. It is used by default. In case of problems - * you can disable the point in time API usage with this setting. - * - * An explicit `null` resets to default. - * - * @param usePit true if the point in time API should be used. - * @return the {@link Builder} with usePit set. - */ - public Builder setUsePit(Boolean usePit) { - this.usePit = usePit == null ? DEFAULT_USE_PIT : usePit ? 1 : 0; - return this; - } - - /** - * Whether the destination index mappings should be deduced from the transform config. - * It is used per default. - * - * An explicit `null` resets to default. - * - * @param deduceMappings true if the transform should try deducing mappings from the config. - * @return the {@link Builder} with deduceMappings set. - */ - public Builder setDeduceMappings(Boolean deduceMappings) { - this.deduceMappings = deduceMappings == null ? DEFAULT_DEDUCE_MAPPINGS : deduceMappings ? 1 : 0; - return this; - } - - public SettingsConfig build() { - return new SettingsConfig(maxPageSearchSize, docsPerSecond, datesAsEpochMillis, alignCheckpoints, usePit, deduceMappings); - } - } -} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/transforms/SourceConfig.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/transforms/SourceConfig.java deleted file mode 100644 index 05b2d1d042ee8..0000000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/transforms/SourceConfig.java +++ /dev/null @@ -1,179 +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 - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -package org.elasticsearch.client.transform.transforms; - -import org.elasticsearch.index.query.QueryBuilder; -import org.elasticsearch.search.builder.SearchSourceBuilder; -import org.elasticsearch.xcontent.ConstructingObjectParser; -import org.elasticsearch.xcontent.ParseField; -import org.elasticsearch.xcontent.ToXContentObject; -import org.elasticsearch.xcontent.XContentBuilder; - -import java.io.IOException; -import java.util.Arrays; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -import static org.elasticsearch.xcontent.ConstructingObjectParser.constructorArg; -import static org.elasticsearch.xcontent.ConstructingObjectParser.optionalConstructorArg; - -/** - * Class encapsulating all options for a {@link TransformConfig} gathering data - */ -public class SourceConfig implements ToXContentObject { - - public static final ParseField QUERY = new ParseField("query"); - public static final ParseField INDEX = new ParseField("index"); - - public static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>( - "transform_config_source", - true, - args -> { - @SuppressWarnings("unchecked") - String[] index = ((List) args[0]).toArray(new String[0]); - // default handling: if the user does not specify a query, we default to match_all - QueryConfig queryConfig = (QueryConfig) args[1]; - @SuppressWarnings("unchecked") - Map runtimeMappings = (Map) args[2]; - return new SourceConfig(index, queryConfig, runtimeMappings); - } - ); - static { - PARSER.declareStringArray(constructorArg(), INDEX); - PARSER.declareObject(optionalConstructorArg(), (p, c) -> QueryConfig.fromXContent(p), QUERY); - PARSER.declareObject(optionalConstructorArg(), (p, c) -> p.map(), SearchSourceBuilder.RUNTIME_MAPPINGS_FIELD); - } - - private final String[] index; - private final QueryConfig queryConfig; - private final Map runtimeMappings; - - /** - * Create a new SourceConfig for the provided indices. - * - * {@link QueryConfig} defaults to a MatchAll query. - * - * @param index Any number of indices. At least one non-null, non-empty, index should be provided - */ - public SourceConfig(String... index) { - this(index, null, null); - } - - /** - * Create a new SourceConfig for the provided indices, from which data is gathered with the provided {@link QueryConfig} - * - * @param index Any number of indices. At least one non-null, non-empty, index should be provided - * @param queryConfig A QueryConfig object that contains the desired query. Defaults to MatchAll query. - * @param runtimeMappings Search-time runtime fields that can be used by the transform - */ - SourceConfig(String[] index, QueryConfig queryConfig, Map runtimeMappings) { - this.index = index; - this.queryConfig = queryConfig; - this.runtimeMappings = runtimeMappings; - } - - public String[] getIndex() { - return index; - } - - public QueryConfig getQueryConfig() { - return queryConfig; - } - - public Map getRuntimeMappings() { - return runtimeMappings; - } - - @Override - public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { - builder.startObject(); - if (index != null) { - builder.array(INDEX.getPreferredName(), index); - } - if (queryConfig != null) { - builder.field(QUERY.getPreferredName(), queryConfig); - } - if (runtimeMappings != null) { - builder.field(SearchSourceBuilder.RUNTIME_MAPPINGS_FIELD.getPreferredName(), runtimeMappings); - } - builder.endObject(); - return builder; - } - - @Override - public boolean equals(Object other) { - if (other == this) { - return true; - } - if (other == null || other.getClass() != getClass()) { - return false; - } - - SourceConfig that = (SourceConfig) other; - return Arrays.equals(index, that.index) - && Objects.equals(queryConfig, that.queryConfig) - && Objects.equals(runtimeMappings, that.runtimeMappings); - } - - @Override - public int hashCode() { - // Using Arrays.hashCode as Objects.hash does not deeply hash nested arrays. Since we are doing Array.equals, this is necessary - int indexArrayHash = Arrays.hashCode(index); - return Objects.hash(indexArrayHash, queryConfig, runtimeMappings); - } - - public static Builder builder() { - return new Builder(); - } - - public static class Builder { - private String[] index; - private QueryConfig queryConfig; - private Map runtimeMappings; - - /** - * Sets what indices from which to fetch data - * @param index The indices from which to fetch data - * @return The {@link Builder} with indices set - */ - public Builder setIndex(String... index) { - this.index = index; - return this; - } - - /** - * Sets the {@link QueryConfig} object that references the desired query to use when fetching the data - * @param queryConfig The {@link QueryConfig} to use when fetching data - * @return The {@link Builder} with queryConfig set - */ - public Builder setQueryConfig(QueryConfig queryConfig) { - this.queryConfig = queryConfig; - return this; - } - - /** - * Sets the query to use when fetching the data. Convenience method for {@link #setQueryConfig(QueryConfig)} - * @param query The {@link QueryBuilder} to use when fetch data (overwrites the {@link QueryConfig}) - * @return The {@link Builder} with queryConfig set - */ - public Builder setQuery(QueryBuilder query) { - return this.setQueryConfig(new QueryConfig(query)); - } - - public Builder setRuntimeMappings(Map runtimeMappings) { - this.runtimeMappings = runtimeMappings; - return this; - } - - public SourceConfig build() { - return new SourceConfig(index, queryConfig, runtimeMappings); - } - } -} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/transforms/SyncConfig.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/transforms/SyncConfig.java deleted file mode 100644 index 32768d7430029..0000000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/transforms/SyncConfig.java +++ /dev/null @@ -1,19 +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 - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -package org.elasticsearch.client.transform.transforms; - -import org.elasticsearch.xcontent.ToXContentObject; - -public interface SyncConfig extends ToXContentObject { - - /** - * Returns the name of the writeable object - */ - String getName(); -} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/transforms/TimeRetentionPolicyConfig.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/transforms/TimeRetentionPolicyConfig.java deleted file mode 100644 index c5a04f44265e1..0000000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/transforms/TimeRetentionPolicyConfig.java +++ /dev/null @@ -1,132 +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 - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -package org.elasticsearch.client.transform.transforms; - -import org.elasticsearch.core.TimeValue; -import org.elasticsearch.xcontent.ConstructingObjectParser; -import org.elasticsearch.xcontent.ObjectParser; -import org.elasticsearch.xcontent.ParseField; -import org.elasticsearch.xcontent.XContentBuilder; -import org.elasticsearch.xcontent.XContentParser; - -import java.io.IOException; -import java.util.Objects; - -import static org.elasticsearch.xcontent.ConstructingObjectParser.constructorArg; - -public class TimeRetentionPolicyConfig implements RetentionPolicyConfig { - - public static final String NAME = "time"; - - private static final ParseField FIELD = new ParseField("field"); - private static final ParseField MAX_AGE = new ParseField("max_age"); - - private final String field; - private final TimeValue maxAge; - - private static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>( - "time_retention_policy_config", - true, - args -> new TimeRetentionPolicyConfig((String) args[0], args[1] != null ? (TimeValue) args[1] : TimeValue.ZERO) - ); - - static { - PARSER.declareString(constructorArg(), FIELD); - PARSER.declareField( - constructorArg(), - (p, c) -> TimeValue.parseTimeValue(p.text(), MAX_AGE.getPreferredName()), - MAX_AGE, - ObjectParser.ValueType.STRING - ); - } - - public static TimeRetentionPolicyConfig fromXContent(XContentParser parser) { - return PARSER.apply(parser, null); - } - - TimeRetentionPolicyConfig(String field, TimeValue maxAge) { - this.field = field; - this.maxAge = maxAge; - } - - @Override - public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { - builder.startObject(); - builder.field(FIELD.getPreferredName(), field); - builder.field(MAX_AGE.getPreferredName(), maxAge.getStringRep()); - builder.endObject(); - return builder; - } - - public String getField() { - return field; - } - - public TimeValue getMaxAge() { - return maxAge; - } - - @Override - public boolean equals(Object other) { - if (this == other) { - return true; - } - - if (other == null || getClass() != other.getClass()) { - return false; - } - - final TimeRetentionPolicyConfig that = (TimeRetentionPolicyConfig) other; - - return Objects.equals(this.field, that.field) && Objects.equals(this.maxAge, that.maxAge); - } - - @Override - public int hashCode() { - return Objects.hash(field, maxAge); - } - - @Override - public String getName() { - return NAME; - } - - public static Builder builder() { - return new Builder(); - } - - public static class Builder { - private String field; - private TimeValue maxAge; - - /** - * The time field used to calculate the age of a document. - * @param field The field name to be used to execute the retention policy - * @return The {@link Builder} with the field set. - */ - public Builder setField(String field) { - this.field = field; - return this; - } - - /** - * The max age, all documents that are older will be deleted. - * @param maxAge The maximum age of a document - * @return The {@link Builder} with max age set. - */ - public Builder setMaxAge(TimeValue maxAge) { - this.maxAge = maxAge; - return this; - } - - public TimeRetentionPolicyConfig build() { - return new TimeRetentionPolicyConfig(field, maxAge); - } - } -} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/transforms/TimeSyncConfig.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/transforms/TimeSyncConfig.java deleted file mode 100644 index 51fc3c1178fb0..0000000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/transforms/TimeSyncConfig.java +++ /dev/null @@ -1,138 +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 - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -package org.elasticsearch.client.transform.transforms; - -import org.elasticsearch.core.TimeValue; -import org.elasticsearch.xcontent.ConstructingObjectParser; -import org.elasticsearch.xcontent.ObjectParser; -import org.elasticsearch.xcontent.ParseField; -import org.elasticsearch.xcontent.XContentBuilder; -import org.elasticsearch.xcontent.XContentParser; - -import java.io.IOException; -import java.util.Objects; - -import static org.elasticsearch.xcontent.ConstructingObjectParser.constructorArg; -import static org.elasticsearch.xcontent.ConstructingObjectParser.optionalConstructorArg; - -public class TimeSyncConfig implements SyncConfig { - - public static final String NAME = "time"; - - private static final ParseField FIELD = new ParseField("field"); - private static final ParseField DELAY = new ParseField("delay"); - - private final String field; - private final TimeValue delay; - - private static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>( - "time_sync_config", - true, - args -> new TimeSyncConfig((String) args[0], args[1] != null ? (TimeValue) args[1] : TimeValue.ZERO) - ); - - static { - PARSER.declareString(constructorArg(), FIELD); - PARSER.declareField( - optionalConstructorArg(), - (p, c) -> TimeValue.parseTimeValue(p.textOrNull(), DELAY.getPreferredName()), - DELAY, - ObjectParser.ValueType.STRING_OR_NULL - ); - } - - public static TimeSyncConfig fromXContent(XContentParser parser) { - return PARSER.apply(parser, null); - } - - // Deprecated, the public modifier will be removed in 8.0: use the builder instead - @Deprecated - public TimeSyncConfig(String field, TimeValue delay) { - this.field = field; - this.delay = delay; - } - - @Override - public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { - builder.startObject(); - builder.field(FIELD.getPreferredName(), field); - if (delay.duration() > 0) { - builder.field(DELAY.getPreferredName(), delay.getStringRep()); - } - builder.endObject(); - return builder; - } - - public String getField() { - return field; - } - - public TimeValue getDelay() { - return delay; - } - - @Override - public boolean equals(Object other) { - if (this == other) { - return true; - } - - if (other == null || getClass() != other.getClass()) { - return false; - } - - final TimeSyncConfig that = (TimeSyncConfig) other; - - return Objects.equals(this.field, that.field) && Objects.equals(this.delay, that.delay); - } - - @Override - public int hashCode() { - return Objects.hash(field, delay); - } - - @Override - public String getName() { - return NAME; - } - - public static Builder builder() { - return new Builder(); - } - - public static class Builder { - private String field; - private TimeValue delay = TimeValue.ZERO; - - /** - * The date field that is used to identify new documents in the source. - * @param field The field name of the timestamp field used for synchronizing - * @return The {@link Builder} with the field set. - */ - public Builder setField(String field) { - this.field = field; - return this; - } - - /** - * The time delay between the current time and the latest input data time. - * The default value is 60s. - * @param delay the delay to use when checking for changes - * @return The {@link Builder} with delay set. - */ - public Builder setDelay(TimeValue delay) { - this.delay = delay; - return this; - } - - public TimeSyncConfig build() { - return new TimeSyncConfig(field, delay); - } - } -} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/transforms/TransformCheckpointStats.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/transforms/TransformCheckpointStats.java deleted file mode 100644 index 1494e8fb10085..0000000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/transforms/TransformCheckpointStats.java +++ /dev/null @@ -1,119 +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 - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -package org.elasticsearch.client.transform.transforms; - -import org.elasticsearch.xcontent.ConstructingObjectParser; -import org.elasticsearch.xcontent.ParseField; -import org.elasticsearch.xcontent.XContentParser; - -import java.io.IOException; -import java.util.Objects; - -import static org.elasticsearch.xcontent.ConstructingObjectParser.optionalConstructorArg; - -public class TransformCheckpointStats { - - public static final ParseField CHECKPOINT = new ParseField("checkpoint"); - public static final ParseField POSITION = new ParseField("position"); - public static final ParseField CHECKPOINT_PROGRESS = new ParseField("checkpoint_progress"); - public static final ParseField TIMESTAMP_MILLIS = new ParseField("timestamp_millis"); - public static final ParseField TIME_UPPER_BOUND_MILLIS = new ParseField("time_upper_bound_millis"); - - public static final TransformCheckpointStats EMPTY = new TransformCheckpointStats(0L, null, null, 0L, 0L); - - private final long checkpoint; - private final TransformIndexerPosition position; - private final TransformProgress checkpointProgress; - private final long timestampMillis; - private final long timeUpperBoundMillis; - - public static final ConstructingObjectParser LENIENT_PARSER = new ConstructingObjectParser<>( - "transform_checkpoint_stats", - true, - args -> { - long checkpoint = args[0] == null ? 0L : (Long) args[0]; - TransformIndexerPosition position = (TransformIndexerPosition) args[1]; - TransformProgress checkpointProgress = (TransformProgress) args[2]; - long timestamp = args[3] == null ? 0L : (Long) args[3]; - long timeUpperBound = args[4] == null ? 0L : (Long) args[4]; - - return new TransformCheckpointStats(checkpoint, position, checkpointProgress, timestamp, timeUpperBound); - } - ); - - static { - LENIENT_PARSER.declareLong(optionalConstructorArg(), CHECKPOINT); - LENIENT_PARSER.declareObject(optionalConstructorArg(), TransformIndexerPosition.PARSER, POSITION); - LENIENT_PARSER.declareObject(optionalConstructorArg(), TransformProgress.PARSER, CHECKPOINT_PROGRESS); - LENIENT_PARSER.declareLong(optionalConstructorArg(), TIMESTAMP_MILLIS); - LENIENT_PARSER.declareLong(optionalConstructorArg(), TIME_UPPER_BOUND_MILLIS); - } - - public static TransformCheckpointStats fromXContent(XContentParser parser) throws IOException { - return LENIENT_PARSER.parse(parser, null); - } - - public TransformCheckpointStats( - final long checkpoint, - final TransformIndexerPosition position, - final TransformProgress checkpointProgress, - final long timestampMillis, - final long timeUpperBoundMillis - ) { - this.checkpoint = checkpoint; - this.position = position; - this.checkpointProgress = checkpointProgress; - this.timestampMillis = timestampMillis; - this.timeUpperBoundMillis = timeUpperBoundMillis; - } - - public long getCheckpoint() { - return checkpoint; - } - - public TransformIndexerPosition getPosition() { - return position; - } - - public TransformProgress getCheckpointProgress() { - return checkpointProgress; - } - - public long getTimestampMillis() { - return timestampMillis; - } - - public long getTimeUpperBoundMillis() { - return timeUpperBoundMillis; - } - - @Override - public int hashCode() { - return Objects.hash(checkpoint, position, checkpointProgress, timestampMillis, timeUpperBoundMillis); - } - - @Override - public boolean equals(Object other) { - if (this == other) { - return true; - } - - if (other == null || getClass() != other.getClass()) { - return false; - } - - TransformCheckpointStats that = (TransformCheckpointStats) other; - - return this.checkpoint == that.checkpoint - && Objects.equals(this.position, that.position) - && Objects.equals(this.checkpointProgress, that.checkpointProgress) - && this.timestampMillis == that.timestampMillis - && this.timeUpperBoundMillis == that.timeUpperBoundMillis; - } -} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/transforms/TransformCheckpointingInfo.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/transforms/TransformCheckpointingInfo.java deleted file mode 100644 index bf55e9a373d0c..0000000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/transforms/TransformCheckpointingInfo.java +++ /dev/null @@ -1,142 +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 - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -package org.elasticsearch.client.transform.transforms; - -import org.elasticsearch.client.common.TimeUtil; -import org.elasticsearch.core.Nullable; -import org.elasticsearch.xcontent.ConstructingObjectParser; -import org.elasticsearch.xcontent.ObjectParser; -import org.elasticsearch.xcontent.ParseField; -import org.elasticsearch.xcontent.XContentParser; - -import java.time.Instant; -import java.util.Objects; - -public class TransformCheckpointingInfo { - - public static final ParseField LAST_CHECKPOINT = new ParseField("last", "current"); - public static final ParseField NEXT_CHECKPOINT = new ParseField("next", "in_progress"); - public static final ParseField OPERATIONS_BEHIND = new ParseField("operations_behind"); - public static final ParseField CHANGES_LAST_DETECTED_AT = new ParseField("changes_last_detected_at"); - public static final ParseField LAST_SEARCH_TIME = new ParseField("last_search_time"); - - private final TransformCheckpointStats last; - private final TransformCheckpointStats next; - private final long operationsBehind; - private final Instant changesLastDetectedAt; - private final Instant lastSearchTime; - - private static final ConstructingObjectParser LENIENT_PARSER = new ConstructingObjectParser<>( - "transform_checkpointing_info", - true, - a -> { - long behind = a[2] == null ? 0L : (Long) a[2]; - Instant changesLastDetectedAt = (Instant) a[3]; - Instant lastSearchTime = (Instant) a[4]; - return new TransformCheckpointingInfo( - a[0] == null ? TransformCheckpointStats.EMPTY : (TransformCheckpointStats) a[0], - a[1] == null ? TransformCheckpointStats.EMPTY : (TransformCheckpointStats) a[1], - behind, - changesLastDetectedAt, - lastSearchTime - ); - } - ); - - static { - LENIENT_PARSER.declareObject( - ConstructingObjectParser.optionalConstructorArg(), - (p, c) -> TransformCheckpointStats.fromXContent(p), - LAST_CHECKPOINT - ); - LENIENT_PARSER.declareObject( - ConstructingObjectParser.optionalConstructorArg(), - (p, c) -> TransformCheckpointStats.fromXContent(p), - NEXT_CHECKPOINT - ); - LENIENT_PARSER.declareLong(ConstructingObjectParser.optionalConstructorArg(), OPERATIONS_BEHIND); - LENIENT_PARSER.declareField( - ConstructingObjectParser.optionalConstructorArg(), - p -> TimeUtil.parseTimeFieldToInstant(p, CHANGES_LAST_DETECTED_AT.getPreferredName()), - CHANGES_LAST_DETECTED_AT, - ObjectParser.ValueType.VALUE - ); - LENIENT_PARSER.declareField( - ConstructingObjectParser.optionalConstructorArg(), - p -> TimeUtil.parseTimeFieldToInstant(p, LAST_SEARCH_TIME.getPreferredName()), - LAST_SEARCH_TIME, - ObjectParser.ValueType.VALUE - ); - } - - public TransformCheckpointingInfo( - TransformCheckpointStats last, - TransformCheckpointStats next, - long operationsBehind, - Instant changesLastDetectedAt, - Instant lastSearchTime - ) { - this.last = Objects.requireNonNull(last); - this.next = Objects.requireNonNull(next); - this.operationsBehind = operationsBehind; - this.changesLastDetectedAt = changesLastDetectedAt; - this.lastSearchTime = lastSearchTime; - } - - public TransformCheckpointStats getLast() { - return last; - } - - public TransformCheckpointStats getNext() { - return next; - } - - public long getOperationsBehind() { - return operationsBehind; - } - - @Nullable - public Instant getChangesLastDetectedAt() { - return changesLastDetectedAt; - } - - @Nullable - public Instant getLastSearchTime() { - return lastSearchTime; - } - - public static TransformCheckpointingInfo fromXContent(XContentParser p) { - return LENIENT_PARSER.apply(p, null); - } - - @Override - public int hashCode() { - return Objects.hash(last, next, operationsBehind, changesLastDetectedAt, lastSearchTime); - } - - @Override - public boolean equals(Object other) { - if (this == other) { - return true; - } - - if (other == null || getClass() != other.getClass()) { - return false; - } - - TransformCheckpointingInfo that = (TransformCheckpointingInfo) other; - - return Objects.equals(this.last, that.last) - && Objects.equals(this.next, that.next) - && this.operationsBehind == that.operationsBehind - && Objects.equals(this.changesLastDetectedAt, that.changesLastDetectedAt) - && Objects.equals(this.lastSearchTime, that.lastSearchTime); - } - -} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/transforms/TransformConfig.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/transforms/TransformConfig.java deleted file mode 100644 index 9edd8cc747cd1..0000000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/transforms/TransformConfig.java +++ /dev/null @@ -1,442 +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 - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -package org.elasticsearch.client.transform.transforms; - -import org.elasticsearch.Version; -import org.elasticsearch.client.common.TimeUtil; -import org.elasticsearch.client.transform.transforms.latest.LatestConfig; -import org.elasticsearch.client.transform.transforms.pivot.PivotConfig; -import org.elasticsearch.common.Strings; -import org.elasticsearch.core.Nullable; -import org.elasticsearch.core.TimeValue; -import org.elasticsearch.xcontent.ConstructingObjectParser; -import org.elasticsearch.xcontent.ObjectParser; -import org.elasticsearch.xcontent.ParseField; -import org.elasticsearch.xcontent.ToXContentObject; -import org.elasticsearch.xcontent.XContentBuilder; -import org.elasticsearch.xcontent.XContentParser; - -import java.io.IOException; -import java.time.Instant; -import java.util.Map; -import java.util.Objects; - -import static org.elasticsearch.xcontent.ConstructingObjectParser.constructorArg; -import static org.elasticsearch.xcontent.ConstructingObjectParser.optionalConstructorArg; - -public class TransformConfig implements ToXContentObject { - - public static final ParseField ID = new ParseField("id"); - public static final ParseField SOURCE = new ParseField("source"); - public static final ParseField DEST = new ParseField("dest"); - public static final ParseField FREQUENCY = new ParseField("frequency"); - public static final ParseField DESCRIPTION = new ParseField("description"); - public static final ParseField SYNC = new ParseField("sync"); - public static final ParseField SETTINGS = new ParseField("settings"); - public static final ParseField METADATA = new ParseField("_meta"); - public static final ParseField VERSION = new ParseField("version"); - public static final ParseField CREATE_TIME = new ParseField("create_time"); - public static final ParseField RETENTION_POLICY = new ParseField("retention_policy"); - // types of transforms - public static final ParseField PIVOT_TRANSFORM = new ParseField("pivot"); - public static final ParseField LATEST_TRANSFORM = new ParseField("latest"); - - private final String id; - private final SourceConfig source; - private final DestConfig dest; - private final TimeValue frequency; - private final SyncConfig syncConfig; - private final SettingsConfig settings; - private final Map metadata; - private final PivotConfig pivotConfig; - private final LatestConfig latestConfig; - private final String description; - private final RetentionPolicyConfig retentionPolicyConfig; - private final Version transformVersion; - private final Instant createTime; - - public static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>( - "transform", - true, - (args) -> { - String id = (String) args[0]; - SourceConfig source = (SourceConfig) args[1]; - DestConfig dest = (DestConfig) args[2]; - TimeValue frequency = (TimeValue) args[3]; - SyncConfig syncConfig = (SyncConfig) args[4]; - PivotConfig pivotConfig = (PivotConfig) args[5]; - LatestConfig latestConfig = (LatestConfig) args[6]; - String description = (String) args[7]; - SettingsConfig settings = (SettingsConfig) args[8]; - @SuppressWarnings("unchecked") - Map metadata = (Map) args[9]; - RetentionPolicyConfig retentionPolicyConfig = (RetentionPolicyConfig) args[10]; - Instant createTime = (Instant) args[11]; - String transformVersion = (String) args[12]; - return new TransformConfig( - id, - source, - dest, - frequency, - syncConfig, - pivotConfig, - latestConfig, - description, - settings, - metadata, - retentionPolicyConfig, - createTime, - transformVersion - ); - } - ); - - static { - PARSER.declareString(constructorArg(), ID); - PARSER.declareObject(constructorArg(), (p, c) -> SourceConfig.PARSER.apply(p, null), SOURCE); - PARSER.declareObject(constructorArg(), (p, c) -> DestConfig.PARSER.apply(p, null), DEST); - PARSER.declareField( - optionalConstructorArg(), - p -> TimeValue.parseTimeValue(p.text(), FREQUENCY.getPreferredName()), - FREQUENCY, - ObjectParser.ValueType.STRING - ); - PARSER.declareNamedObject(optionalConstructorArg(), (p, c, n) -> p.namedObject(SyncConfig.class, n, c), SYNC); - PARSER.declareObject(optionalConstructorArg(), (p, c) -> PivotConfig.fromXContent(p), PIVOT_TRANSFORM); - PARSER.declareObject(optionalConstructorArg(), (p, c) -> LatestConfig.fromXContent(p), LATEST_TRANSFORM); - PARSER.declareString(optionalConstructorArg(), DESCRIPTION); - PARSER.declareObject(optionalConstructorArg(), (p, c) -> SettingsConfig.fromXContent(p), SETTINGS); - PARSER.declareObject(optionalConstructorArg(), (p, c) -> p.mapOrdered(), METADATA); - PARSER.declareNamedObject( - optionalConstructorArg(), - (p, c, n) -> p.namedObject(RetentionPolicyConfig.class, n, c), - RETENTION_POLICY - ); - PARSER.declareField( - optionalConstructorArg(), - p -> TimeUtil.parseTimeFieldToInstant(p, CREATE_TIME.getPreferredName()), - CREATE_TIME, - ObjectParser.ValueType.VALUE - ); - PARSER.declareString(optionalConstructorArg(), VERSION); - } - - public static TransformConfig fromXContent(final XContentParser parser) { - return PARSER.apply(parser, null); - } - - /** - * Helper method for previewing a transform configuration - * - * The TransformConfig returned from this method should only be used for previewing the resulting data. - * - * A new, valid, TransformConfig with an appropriate destination and ID will have to be constructed to create - * the transform. - * @param source Source configuration for gathering the data - * @param pivotConfig Config to preview - * @return A TransformConfig to preview, NOTE it will have a {@code null} id, destination and index. - */ - public static TransformConfig forPreview(final SourceConfig source, final PivotConfig pivotConfig) { - return new TransformConfig(null, source, null, null, null, pivotConfig, null, null, null, null, null, null, null); - } - - /** - * Helper method for previewing a transform configuration - * - * The TransformConfig returned from this method should only be used for previewing the resulting data. - * - * A new, valid, TransformConfig with an appropriate destination and ID will have to be constructed to create - * the transform. - * @param source Source configuration for gathering the data - * @param latestConfig Config to preview - * @return A TransformConfig to preview, NOTE it will have a {@code null} id, destination and index. - */ - public static TransformConfig forPreview(final SourceConfig source, final LatestConfig latestConfig) { - return new TransformConfig(null, source, null, null, null, null, latestConfig, null, null, null, null, null, null); - } - - TransformConfig( - final String id, - final SourceConfig source, - final DestConfig dest, - final TimeValue frequency, - final SyncConfig syncConfig, - final PivotConfig pivotConfig, - final LatestConfig latestConfig, - final String description, - final SettingsConfig settings, - final Map metadata, - final RetentionPolicyConfig retentionPolicyConfig, - final Instant createTime, - final String version - ) { - this.id = id; - this.source = source; - this.dest = dest; - this.frequency = frequency; - this.syncConfig = syncConfig; - this.pivotConfig = pivotConfig; - this.latestConfig = latestConfig; - this.description = description; - this.settings = settings; - this.metadata = metadata; - this.retentionPolicyConfig = retentionPolicyConfig; - this.createTime = createTime == null ? null : Instant.ofEpochMilli(createTime.toEpochMilli()); - this.transformVersion = version == null ? null : Version.fromString(version); - } - - public String getId() { - return id; - } - - public SourceConfig getSource() { - return source; - } - - public DestConfig getDestination() { - return dest; - } - - public TimeValue getFrequency() { - return frequency; - } - - public SyncConfig getSyncConfig() { - return syncConfig; - } - - public PivotConfig getPivotConfig() { - return pivotConfig; - } - - public LatestConfig getLatestConfig() { - return latestConfig; - } - - public Version getVersion() { - return transformVersion; - } - - public Instant getCreateTime() { - return createTime; - } - - @Nullable - public String getDescription() { - return description; - } - - @Nullable - public SettingsConfig getSettings() { - return settings; - } - - @Nullable - public Map getMetadata() { - return metadata; - } - - @Nullable - public RetentionPolicyConfig getRetentionPolicyConfig() { - return retentionPolicyConfig; - } - - @Override - public XContentBuilder toXContent(final XContentBuilder builder, final Params params) throws IOException { - builder.startObject(); - if (id != null) { - builder.field(ID.getPreferredName(), id); - } - if (source != null) { - builder.field(SOURCE.getPreferredName(), source); - } - if (dest != null) { - builder.field(DEST.getPreferredName(), dest); - } - if (frequency != null) { - builder.field(FREQUENCY.getPreferredName(), frequency.getStringRep()); - } - if (syncConfig != null) { - builder.startObject(SYNC.getPreferredName()); - builder.field(syncConfig.getName(), syncConfig); - builder.endObject(); - } - if (pivotConfig != null) { - builder.field(PIVOT_TRANSFORM.getPreferredName(), pivotConfig); - } - if (latestConfig != null) { - builder.field(LATEST_TRANSFORM.getPreferredName(), latestConfig); - } - if (description != null) { - builder.field(DESCRIPTION.getPreferredName(), description); - } - if (settings != null) { - builder.field(SETTINGS.getPreferredName(), settings); - } - if (metadata != null) { - builder.field(METADATA.getPreferredName(), metadata); - } - if (retentionPolicyConfig != null) { - builder.startObject(RETENTION_POLICY.getPreferredName()); - builder.field(retentionPolicyConfig.getName(), retentionPolicyConfig); - builder.endObject(); - } - if (createTime != null) { - builder.timeField(CREATE_TIME.getPreferredName(), CREATE_TIME.getPreferredName() + "_string", createTime.toEpochMilli()); - } - if (transformVersion != null) { - builder.field(VERSION.getPreferredName(), transformVersion); - } - builder.endObject(); - return builder; - } - - @Override - public boolean equals(Object other) { - if (this == other) { - return true; - } - - if (other == null || getClass() != other.getClass()) { - return false; - } - - final TransformConfig that = (TransformConfig) other; - - return Objects.equals(this.id, that.id) - && Objects.equals(this.source, that.source) - && Objects.equals(this.dest, that.dest) - && Objects.equals(this.frequency, that.frequency) - && Objects.equals(this.description, that.description) - && Objects.equals(this.syncConfig, that.syncConfig) - && Objects.equals(this.transformVersion, that.transformVersion) - && Objects.equals(this.settings, that.settings) - && Objects.equals(this.metadata, that.metadata) - && Objects.equals(this.createTime, that.createTime) - && Objects.equals(this.pivotConfig, that.pivotConfig) - && Objects.equals(this.latestConfig, that.latestConfig) - && Objects.equals(this.retentionPolicyConfig, that.retentionPolicyConfig); - } - - @Override - public int hashCode() { - return Objects.hash( - id, - source, - dest, - frequency, - syncConfig, - settings, - metadata, - createTime, - transformVersion, - pivotConfig, - latestConfig, - description, - retentionPolicyConfig - ); - } - - @Override - public String toString() { - return Strings.toString(this, true, true); - } - - public static Builder builder() { - return new Builder(); - } - - public static class Builder { - - private String id; - private SourceConfig source; - private DestConfig dest; - private TimeValue frequency; - private SyncConfig syncConfig; - private PivotConfig pivotConfig; - private LatestConfig latestConfig; - private SettingsConfig settings; - private Map metadata; - private String description; - private RetentionPolicyConfig retentionPolicyConfig; - - public Builder setId(String id) { - this.id = id; - return this; - } - - public Builder setSource(SourceConfig source) { - this.source = source; - return this; - } - - public Builder setDest(DestConfig dest) { - this.dest = dest; - return this; - } - - public Builder setFrequency(TimeValue frequency) { - this.frequency = frequency; - return this; - } - - public Builder setSyncConfig(SyncConfig syncConfig) { - this.syncConfig = syncConfig; - return this; - } - - public Builder setPivotConfig(PivotConfig pivotConfig) { - this.pivotConfig = pivotConfig; - return this; - } - - public Builder setLatestConfig(LatestConfig latestConfig) { - this.latestConfig = latestConfig; - return this; - } - - public Builder setDescription(String description) { - this.description = description; - return this; - } - - public Builder setSettings(SettingsConfig settings) { - this.settings = settings; - return this; - } - - public Builder setMetadata(Map metadata) { - this.metadata = metadata; - return this; - } - - public Builder setRetentionPolicyConfig(RetentionPolicyConfig retentionPolicyConfig) { - this.retentionPolicyConfig = retentionPolicyConfig; - return this; - } - - public TransformConfig build() { - return new TransformConfig( - id, - source, - dest, - frequency, - syncConfig, - pivotConfig, - latestConfig, - description, - settings, - metadata, - retentionPolicyConfig, - null, - null - ); - } - } -} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/transforms/TransformConfigUpdate.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/transforms/TransformConfigUpdate.java deleted file mode 100644 index 24ee4ee21172a..0000000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/transforms/TransformConfigUpdate.java +++ /dev/null @@ -1,248 +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 - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -package org.elasticsearch.client.transform.transforms; - -import org.elasticsearch.common.Strings; -import org.elasticsearch.core.Nullable; -import org.elasticsearch.core.TimeValue; -import org.elasticsearch.xcontent.ConstructingObjectParser; -import org.elasticsearch.xcontent.ToXContentObject; -import org.elasticsearch.xcontent.XContentBuilder; -import org.elasticsearch.xcontent.XContentParser; - -import java.io.IOException; -import java.util.Map; -import java.util.Objects; - -import static org.elasticsearch.xcontent.ConstructingObjectParser.optionalConstructorArg; - -/** - * This class holds the mutable configuration items for a transform - */ -public class TransformConfigUpdate implements ToXContentObject { - - public static final String NAME = "transform_config_update"; - private static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>( - NAME, - false, - (args) -> { - SourceConfig source = (SourceConfig) args[0]; - DestConfig dest = (DestConfig) args[1]; - TimeValue frequency = args[2] == null - ? null - : TimeValue.parseTimeValue((String) args[2], TransformConfig.FREQUENCY.getPreferredName()); - SyncConfig syncConfig = (SyncConfig) args[3]; - String description = (String) args[4]; - SettingsConfig settings = (SettingsConfig) args[5]; - @SuppressWarnings("unchecked") - Map metadata = (Map) args[6]; - RetentionPolicyConfig retentionPolicyConfig = (RetentionPolicyConfig) args[7]; - return new TransformConfigUpdate(source, dest, frequency, syncConfig, description, settings, metadata, retentionPolicyConfig); - } - ); - - static { - PARSER.declareObject(optionalConstructorArg(), (p, c) -> SourceConfig.PARSER.apply(p, null), TransformConfig.SOURCE); - PARSER.declareObject(optionalConstructorArg(), (p, c) -> DestConfig.PARSER.apply(p, null), TransformConfig.DEST); - PARSER.declareString(optionalConstructorArg(), TransformConfig.FREQUENCY); - PARSER.declareNamedObject(optionalConstructorArg(), (p, c, n) -> p.namedObject(SyncConfig.class, n, c), TransformConfig.SYNC); - PARSER.declareString(optionalConstructorArg(), TransformConfig.DESCRIPTION); - PARSER.declareObject(optionalConstructorArg(), (p, c) -> SettingsConfig.fromXContent(p), TransformConfig.SETTINGS); - PARSER.declareObject(optionalConstructorArg(), (p, c) -> p.mapOrdered(), TransformConfig.METADATA); - PARSER.declareNamedObject( - optionalConstructorArg(), - (p, c, n) -> p.namedObject(RetentionPolicyConfig.class, n, c), - TransformConfig.RETENTION_POLICY - ); - } - - private final SourceConfig source; - private final DestConfig dest; - private final TimeValue frequency; - private final SyncConfig syncConfig; - private final String description; - private final SettingsConfig settings; - private final Map metadata; - - public TransformConfigUpdate( - final SourceConfig source, - final DestConfig dest, - final TimeValue frequency, - final SyncConfig syncConfig, - final String description, - final SettingsConfig settings, - final Map metadata, - final RetentionPolicyConfig retentionPolicyConfig - ) { - this.source = source; - this.dest = dest; - this.frequency = frequency; - this.syncConfig = syncConfig; - this.description = description; - this.settings = settings; - this.metadata = metadata; - } - - public SourceConfig getSource() { - return source; - } - - public DestConfig getDestination() { - return dest; - } - - public TimeValue getFrequency() { - return frequency; - } - - public SyncConfig getSyncConfig() { - return syncConfig; - } - - @Nullable - public String getDescription() { - return description; - } - - @Nullable - public SettingsConfig getSettings() { - return settings; - } - - @Nullable - public Map getMetadata() { - return metadata; - } - - @Override - public XContentBuilder toXContent(final XContentBuilder builder, final Params params) throws IOException { - builder.startObject(); - if (source != null) { - builder.field(TransformConfig.SOURCE.getPreferredName(), source); - } - if (dest != null) { - builder.field(TransformConfig.DEST.getPreferredName(), dest); - } - if (frequency != null) { - builder.field(TransformConfig.FREQUENCY.getPreferredName(), frequency.getStringRep()); - } - if (syncConfig != null) { - builder.startObject(TransformConfig.SYNC.getPreferredName()); - builder.field(syncConfig.getName(), syncConfig); - builder.endObject(); - } - if (description != null) { - builder.field(TransformConfig.DESCRIPTION.getPreferredName(), description); - } - if (settings != null) { - builder.field(TransformConfig.SETTINGS.getPreferredName(), settings); - } - if (metadata != null) { - builder.field(TransformConfig.METADATA.getPreferredName(), metadata); - } - - builder.endObject(); - return builder; - } - - @Override - public boolean equals(Object other) { - if (this == other) { - return true; - } - - if (other == null || getClass() != other.getClass()) { - return false; - } - - final TransformConfigUpdate that = (TransformConfigUpdate) other; - - return Objects.equals(this.source, that.source) - && Objects.equals(this.dest, that.dest) - && Objects.equals(this.frequency, that.frequency) - && Objects.equals(this.syncConfig, that.syncConfig) - && Objects.equals(this.description, that.description) - && Objects.equals(this.settings, that.settings) - && Objects.equals(this.metadata, that.metadata); - } - - @Override - public int hashCode() { - return Objects.hash(source, dest, frequency, syncConfig, description, settings, metadata); - } - - @Override - public String toString() { - return Strings.toString(this, true, true); - } - - public static Builder builder() { - return new Builder(); - } - - public static TransformConfigUpdate fromXContent(final XContentParser parser) { - return PARSER.apply(parser, null); - } - - public static class Builder { - - private SourceConfig source; - private DestConfig dest; - private TimeValue frequency; - private SyncConfig syncConfig; - private String description; - private SettingsConfig settings; - private Map metdata; - private RetentionPolicyConfig retentionPolicyConfig; - - public Builder setSource(SourceConfig source) { - this.source = source; - return this; - } - - public Builder setDest(DestConfig dest) { - this.dest = dest; - return this; - } - - public Builder setFrequency(TimeValue frequency) { - this.frequency = frequency; - return this; - } - - public Builder setSyncConfig(SyncConfig syncConfig) { - this.syncConfig = syncConfig; - return this; - } - - public Builder setDescription(String description) { - this.description = description; - return this; - } - - public Builder setSettings(SettingsConfig settings) { - this.settings = settings; - return this; - } - - public Builder setMetadata(Map metadata) { - this.metdata = metdata; - return this; - } - - public Builder setRetentionPolicyConfig(RetentionPolicyConfig retentionPolicyConfig) { - this.retentionPolicyConfig = retentionPolicyConfig; - return this; - } - - public TransformConfigUpdate build() { - return new TransformConfigUpdate(source, dest, frequency, syncConfig, description, settings, metdata, retentionPolicyConfig); - } - } -} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/transforms/TransformIndexerPosition.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/transforms/TransformIndexerPosition.java deleted file mode 100644 index c1f940b281815..0000000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/transforms/TransformIndexerPosition.java +++ /dev/null @@ -1,88 +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 - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -package org.elasticsearch.client.transform.transforms; - -import org.elasticsearch.xcontent.ConstructingObjectParser; -import org.elasticsearch.xcontent.ObjectParser.ValueType; -import org.elasticsearch.xcontent.ParseField; -import org.elasticsearch.xcontent.XContentParser; - -import java.io.IOException; -import java.util.Collections; -import java.util.Map; -import java.util.Objects; - -import static org.elasticsearch.xcontent.ConstructingObjectParser.optionalConstructorArg; - -/** - * Holds state of the cursors: - * - * indexer_position: the position of the indexer querying the source - * bucket_position: the position used for identifying changes - */ -public class TransformIndexerPosition { - public static final ParseField INDEXER_POSITION = new ParseField("indexer_position"); - public static final ParseField BUCKET_POSITION = new ParseField("bucket_position"); - - private final Map indexerPosition; - private final Map bucketPosition; - - @SuppressWarnings("unchecked") - public static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>( - "transform_indexer_position", - true, - args -> new TransformIndexerPosition((Map) args[0], (Map) args[1]) - ); - - static { - PARSER.declareField(optionalConstructorArg(), XContentParser::mapOrdered, INDEXER_POSITION, ValueType.OBJECT); - PARSER.declareField(optionalConstructorArg(), XContentParser::mapOrdered, BUCKET_POSITION, ValueType.OBJECT); - } - - public TransformIndexerPosition(Map indexerPosition, Map bucketPosition) { - this.indexerPosition = indexerPosition == null ? null : Collections.unmodifiableMap(indexerPosition); - this.bucketPosition = bucketPosition == null ? null : Collections.unmodifiableMap(bucketPosition); - } - - public Map getIndexerPosition() { - return indexerPosition; - } - - public Map getBucketsPosition() { - return bucketPosition; - } - - @Override - public boolean equals(Object other) { - if (this == other) { - return true; - } - - if (other == null || getClass() != other.getClass()) { - return false; - } - - TransformIndexerPosition that = (TransformIndexerPosition) other; - - return Objects.equals(this.indexerPosition, that.indexerPosition) && Objects.equals(this.bucketPosition, that.bucketPosition); - } - - @Override - public int hashCode() { - return Objects.hash(indexerPosition, bucketPosition); - } - - public static TransformIndexerPosition fromXContent(XContentParser parser) { - try { - return PARSER.parse(parser, null); - } catch (IOException e) { - throw new RuntimeException(e); - } - } -} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/transforms/TransformIndexerStats.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/transforms/TransformIndexerStats.java deleted file mode 100644 index 027f8eb89affd..0000000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/transforms/TransformIndexerStats.java +++ /dev/null @@ -1,354 +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 - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -package org.elasticsearch.client.transform.transforms; - -import org.elasticsearch.xcontent.ConstructingObjectParser; -import org.elasticsearch.xcontent.ParseField; -import org.elasticsearch.xcontent.XContentParser; - -import java.io.IOException; -import java.util.Objects; - -import static org.elasticsearch.xcontent.ConstructingObjectParser.optionalConstructorArg; - -public class TransformIndexerStats { - public static final String NAME = "transform_indexer_stats"; - - static ParseField EXPONENTIAL_AVG_CHECKPOINT_DURATION_MS = new ParseField("exponential_avg_checkpoint_duration_ms"); - static ParseField EXPONENTIAL_AVG_DOCUMENTS_INDEXED = new ParseField("exponential_avg_documents_indexed"); - static ParseField EXPONENTIAL_AVG_DOCUMENTS_PROCESSED = new ParseField("exponential_avg_documents_processed"); - static ParseField PAGES_PROCESSED = new ParseField("pages_processed"); - static ParseField DOCUMENTS_PROCESSED = new ParseField("documents_processed"); - static ParseField DOCUMENTS_INDEXED = new ParseField("documents_indexed"); - static ParseField DOCUMENTS_DELETED = new ParseField("documents_deleted"); - static ParseField TRIGGER_COUNT = new ParseField("trigger_count"); - static ParseField INDEX_TIME_IN_MS = new ParseField("index_time_in_ms"); - static ParseField SEARCH_TIME_IN_MS = new ParseField("search_time_in_ms"); - static ParseField PROCESSING_TIME_IN_MS = new ParseField("processing_time_in_ms"); - static ParseField DELETE_TIME_IN_MS = new ParseField("delete_time_in_ms"); - static ParseField INDEX_TOTAL = new ParseField("index_total"); - static ParseField SEARCH_TOTAL = new ParseField("search_total"); - static ParseField PROCESSING_TOTAL = new ParseField("processing_total"); - static ParseField SEARCH_FAILURES = new ParseField("search_failures"); - static ParseField INDEX_FAILURES = new ParseField("index_failures"); - - public static final ConstructingObjectParser LENIENT_PARSER = new ConstructingObjectParser<>( - NAME, - true, - args -> new TransformIndexerStats( - unboxSafe(args[0], 0L), - unboxSafe(args[1], 0L), - unboxSafe(args[2], 0L), - unboxSafe(args[3], 0L), - unboxSafe(args[4], 0L), - unboxSafe(args[5], 0L), - unboxSafe(args[6], 0L), - unboxSafe(args[7], 0L), - unboxSafe(args[8], 0L), - unboxSafe(args[9], 0L), - unboxSafe(args[10], 0L), - unboxSafe(args[11], 0L), - unboxSafe(args[12], 0L), - unboxSafe(args[13], 0L), - unboxSafe(args[14], 0.0), - unboxSafe(args[15], 0.0), - unboxSafe(args[16], 0.0) - ) - ); - - static { - LENIENT_PARSER.declareLong(optionalConstructorArg(), PAGES_PROCESSED); - LENIENT_PARSER.declareLong(optionalConstructorArg(), DOCUMENTS_PROCESSED); - LENIENT_PARSER.declareLong(optionalConstructorArg(), DOCUMENTS_INDEXED); - LENIENT_PARSER.declareLong(optionalConstructorArg(), DOCUMENTS_DELETED); - LENIENT_PARSER.declareLong(optionalConstructorArg(), TRIGGER_COUNT); - LENIENT_PARSER.declareLong(optionalConstructorArg(), INDEX_TIME_IN_MS); - LENIENT_PARSER.declareLong(optionalConstructorArg(), SEARCH_TIME_IN_MS); - LENIENT_PARSER.declareLong(optionalConstructorArg(), PROCESSING_TIME_IN_MS); - LENIENT_PARSER.declareLong(optionalConstructorArg(), DELETE_TIME_IN_MS); - LENIENT_PARSER.declareLong(optionalConstructorArg(), INDEX_TOTAL); - LENIENT_PARSER.declareLong(optionalConstructorArg(), SEARCH_TOTAL); - LENIENT_PARSER.declareLong(optionalConstructorArg(), PROCESSING_TOTAL); - LENIENT_PARSER.declareLong(optionalConstructorArg(), INDEX_FAILURES); - LENIENT_PARSER.declareLong(optionalConstructorArg(), SEARCH_FAILURES); - LENIENT_PARSER.declareDouble(optionalConstructorArg(), EXPONENTIAL_AVG_CHECKPOINT_DURATION_MS); - LENIENT_PARSER.declareDouble(optionalConstructorArg(), EXPONENTIAL_AVG_DOCUMENTS_INDEXED); - LENIENT_PARSER.declareDouble(optionalConstructorArg(), EXPONENTIAL_AVG_DOCUMENTS_PROCESSED); - } - - public static TransformIndexerStats fromXContent(XContentParser parser) throws IOException { - return LENIENT_PARSER.parse(parser, null); - } - - private final double expAvgCheckpointDurationMs; - private final double expAvgDocumentsIndexed; - private final double expAvgDocumentsProcessed; - private final long pagesProcessed; - private final long documentsProcessed; - private final long documentsIndexed; - private final long documentsDeleted; - private final long triggerCount; - private final long indexTime; - private final long indexTotal; - private final long searchTime; - private final long searchTotal; - private final long processingTime; - private final long deleteTime; - private final long processingTotal; - private final long indexFailures; - private final long searchFailures; - - public TransformIndexerStats( - long pagesProcessed, - long documentsProcessed, - long documentsIndexed, - long documentsDeleted, - long triggerCount, - long indexTime, - long searchTime, - long processingTime, - long deleteTime, - long indexTotal, - long searchTotal, - long processingTotal, - long indexFailures, - long searchFailures, - double expAvgCheckpointDurationMs, - double expAvgDocumentsIndexed, - double expAvgDocumentsProcessed - ) { - this.pagesProcessed = pagesProcessed; - this.documentsProcessed = documentsProcessed; - this.documentsIndexed = documentsIndexed; - this.documentsDeleted = documentsDeleted; - this.triggerCount = triggerCount; - this.indexTime = indexTime; - this.indexTotal = indexTotal; - this.searchTime = searchTime; - this.deleteTime = deleteTime; - this.searchTotal = searchTotal; - this.processingTime = processingTime; - this.processingTotal = processingTotal; - this.indexFailures = indexFailures; - this.searchFailures = searchFailures; - this.expAvgCheckpointDurationMs = expAvgCheckpointDurationMs; - this.expAvgDocumentsIndexed = expAvgDocumentsIndexed; - this.expAvgDocumentsProcessed = expAvgDocumentsProcessed; - } - - public double getExpAvgCheckpointDurationMs() { - return expAvgCheckpointDurationMs; - } - - public double getExpAvgDocumentsIndexed() { - return expAvgDocumentsIndexed; - } - - public double getExpAvgDocumentsProcessed() { - return expAvgDocumentsProcessed; - } - - /** - * The number of pages read from the input indices - */ - public long getPagesProcessed() { - return pagesProcessed; - } - - /** - * The number of documents read from the input indices - */ - public long getDocumentsProcessed() { - return documentsProcessed; - } - - /** - * Number of times that the job woke up to write documents - */ - public long getTriggerCount() { - return triggerCount; - } - - /** - * Number of documents written - */ - public long getDocumentsIndexed() { - return documentsIndexed; - } - - /** - * The number of pages read from the input indices - * Deprecated, use {@link TransformIndexerStats#getPagesProcessed()} instead - */ - @Deprecated - public long getNumPages() { - return getPagesProcessed(); - } - - /** - * The number of documents read from the input indices - * Deprecated, use {@link TransformIndexerStats#getDocumentsProcessed()} instead - */ - @Deprecated - public long getNumDocuments() { - return getDocumentsProcessed(); - } - - /** - * Number of times that the job woke up to write documents - * Deprecated, use {@link TransformIndexerStats#getTriggerCount()} instead - */ - @Deprecated - public long getNumInvocations() { - return getTriggerCount(); - } - - /** - * Number of documents written - * Deprecated, use {@link TransformIndexerStats#getDocumentsIndexed()} instead - */ - @Deprecated - public long getOutputDocuments() { - return getDocumentsIndexed(); - } - - /** - * Number of documents deleted - */ - public long getDocumentsDeleted() { - return documentsDeleted; - } - - /** - * Number of index failures that have occurred - */ - public long getIndexFailures() { - return indexFailures; - } - - /** - * Number of failures that have occurred - */ - public long getSearchFailures() { - return searchFailures; - } - - /** - * Returns the time spent indexing (cumulative) in milliseconds - */ - public long getIndexTime() { - return indexTime; - } - - /** - * Returns the time spent searching (cumulative) in milliseconds - */ - public long getSearchTime() { - return searchTime; - } - - /** - * Returns the time spent processing (cumulative) in milliseconds - */ - public long getProcessingTime() { - return processingTime; - } - - /** - * Returns the time spent deleting (cumulative) in milliseconds - */ - public long getDeleteTime() { - return deleteTime; - } - - /** - * Returns the total number of indexing requests that have been processed - * (Note: this is not the number of _documents_ that have been indexed) - */ - public long getIndexTotal() { - return indexTotal; - } - - /** - * Returns the total number of search requests that have been made - */ - public long getSearchTotal() { - return searchTotal; - } - - /** - * Returns the total number of processing runs that have been made - */ - public long getProcessingTotal() { - return processingTotal; - } - - @Override - public boolean equals(Object other) { - if (this == other) { - return true; - } - - if (other == null || getClass() != other.getClass()) { - return false; - } - - TransformIndexerStats that = (TransformIndexerStats) other; - - return Objects.equals(this.pagesProcessed, that.pagesProcessed) - && Objects.equals(this.documentsProcessed, that.documentsProcessed) - && Objects.equals(this.documentsIndexed, that.documentsIndexed) - && Objects.equals(this.documentsDeleted, that.documentsDeleted) - && Objects.equals(this.triggerCount, that.triggerCount) - && Objects.equals(this.indexTime, that.indexTime) - && Objects.equals(this.searchTime, that.searchTime) - && Objects.equals(this.processingTime, that.processingTime) - && Objects.equals(this.deleteTime, that.deleteTime) - && Objects.equals(this.indexFailures, that.indexFailures) - && Objects.equals(this.searchFailures, that.searchFailures) - && Objects.equals(this.indexTotal, that.indexTotal) - && Objects.equals(this.searchTotal, that.searchTotal) - && Objects.equals(this.processingTotal, that.processingTotal) - && Objects.equals(this.expAvgCheckpointDurationMs, that.expAvgCheckpointDurationMs) - && Objects.equals(this.expAvgDocumentsIndexed, that.expAvgDocumentsIndexed) - && Objects.equals(this.expAvgDocumentsProcessed, that.expAvgDocumentsProcessed); - } - - @Override - public int hashCode() { - return Objects.hash( - pagesProcessed, - documentsProcessed, - documentsIndexed, - documentsDeleted, - triggerCount, - indexTime, - searchTime, - processingTime, - deleteTime, - indexFailures, - searchFailures, - indexTotal, - searchTotal, - processingTotal, - expAvgCheckpointDurationMs, - expAvgDocumentsIndexed, - expAvgDocumentsProcessed - ); - } - - @SuppressWarnings("unchecked") - private static T unboxSafe(Object l, T default_value) { - if (l == null) { - return default_value; - } else { - return (T) l; - } - } -} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/transforms/TransformProgress.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/transforms/TransformProgress.java deleted file mode 100644 index c50c7f41296e3..0000000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/transforms/TransformProgress.java +++ /dev/null @@ -1,105 +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 - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -package org.elasticsearch.client.transform.transforms; - -import org.elasticsearch.core.Nullable; -import org.elasticsearch.xcontent.ConstructingObjectParser; -import org.elasticsearch.xcontent.ParseField; -import org.elasticsearch.xcontent.XContentParser; - -import java.util.Objects; - -import static org.elasticsearch.xcontent.ConstructingObjectParser.optionalConstructorArg; - -public class TransformProgress { - - public static final ParseField TOTAL_DOCS = new ParseField("total_docs"); - public static final ParseField DOCS_REMAINING = new ParseField("docs_remaining"); - public static final ParseField PERCENT_COMPLETE = new ParseField("percent_complete"); - public static final ParseField DOCS_PROCESSED = new ParseField("docs_processed"); - public static final ParseField DOCS_INDEXED = new ParseField("docs_indexed"); - - public static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>( - "transform_progress", - true, - a -> new TransformProgress((Long) a[0], (Long) a[1], (Double) a[2], (Long) a[3], (Long) a[4]) - ); - - static { - PARSER.declareLong(optionalConstructorArg(), TOTAL_DOCS); - PARSER.declareLong(optionalConstructorArg(), DOCS_REMAINING); - PARSER.declareDouble(optionalConstructorArg(), PERCENT_COMPLETE); - PARSER.declareLong(optionalConstructorArg(), DOCS_PROCESSED); - PARSER.declareLong(optionalConstructorArg(), DOCS_INDEXED); - } - - public static TransformProgress fromXContent(XContentParser parser) { - return PARSER.apply(parser, null); - } - - private final Long totalDocs; - private final Long remainingDocs; - private final Double percentComplete; - private final long documentsProcessed; - private final long documentsIndexed; - - public TransformProgress(Long totalDocs, Long remainingDocs, Double percentComplete, Long documentsProcessed, Long documentsIndexed) { - this.totalDocs = totalDocs; - this.remainingDocs = remainingDocs == null ? totalDocs : remainingDocs; - this.percentComplete = percentComplete; - this.documentsProcessed = documentsProcessed == null ? 0 : documentsProcessed; - this.documentsIndexed = documentsIndexed == null ? 0 : documentsIndexed; - } - - @Nullable - public Double getPercentComplete() { - return percentComplete; - } - - @Nullable - public Long getTotalDocs() { - return totalDocs; - } - - @Nullable - public Long getRemainingDocs() { - return remainingDocs; - } - - public long getDocumentsProcessed() { - return documentsProcessed; - } - - public long getDocumentsIndexed() { - return documentsIndexed; - } - - @Override - public boolean equals(Object other) { - if (other == this) { - return true; - } - - if (other == null || other.getClass() != getClass()) { - return false; - } - - TransformProgress that = (TransformProgress) other; - return Objects.equals(this.remainingDocs, that.remainingDocs) - && Objects.equals(this.totalDocs, that.totalDocs) - && Objects.equals(this.percentComplete, that.percentComplete) - && Objects.equals(this.documentsIndexed, that.documentsIndexed) - && Objects.equals(this.documentsProcessed, that.documentsProcessed); - } - - @Override - public int hashCode() { - return Objects.hash(remainingDocs, totalDocs, percentComplete, documentsIndexed, documentsProcessed); - } -} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/transforms/TransformStats.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/transforms/TransformStats.java deleted file mode 100644 index 6426283eaee7e..0000000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/transforms/TransformStats.java +++ /dev/null @@ -1,148 +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 - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -package org.elasticsearch.client.transform.transforms; - -import org.elasticsearch.xcontent.ConstructingObjectParser; -import org.elasticsearch.xcontent.ObjectParser; -import org.elasticsearch.xcontent.ParseField; -import org.elasticsearch.xcontent.XContentParser; - -import java.io.IOException; -import java.util.Locale; -import java.util.Objects; - -import static org.elasticsearch.xcontent.ConstructingObjectParser.constructorArg; -import static org.elasticsearch.xcontent.ConstructingObjectParser.optionalConstructorArg; - -public class TransformStats { - - public static final ParseField ID = new ParseField("id"); - public static final ParseField STATE_FIELD = new ParseField("state"); - public static final ParseField REASON_FIELD = new ParseField("reason"); - public static final ParseField NODE_FIELD = new ParseField("node"); - public static final ParseField STATS_FIELD = new ParseField("stats"); - public static final ParseField CHECKPOINTING_INFO_FIELD = new ParseField("checkpointing"); - - public static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>( - "data_frame_transform_state_and_stats_info", - true, - a -> new TransformStats( - (String) a[0], - (State) a[1], - (String) a[2], - (NodeAttributes) a[3], - (TransformIndexerStats) a[4], - (TransformCheckpointingInfo) a[5] - ) - ); - - static { - PARSER.declareString(constructorArg(), ID); - PARSER.declareField(optionalConstructorArg(), p -> State.fromString(p.text()), STATE_FIELD, ObjectParser.ValueType.STRING); - PARSER.declareString(optionalConstructorArg(), REASON_FIELD); - PARSER.declareField(optionalConstructorArg(), NodeAttributes.PARSER::apply, NODE_FIELD, ObjectParser.ValueType.OBJECT); - PARSER.declareObject(constructorArg(), (p, c) -> TransformIndexerStats.fromXContent(p), STATS_FIELD); - PARSER.declareObject(optionalConstructorArg(), (p, c) -> TransformCheckpointingInfo.fromXContent(p), CHECKPOINTING_INFO_FIELD); - } - - public static TransformStats fromXContent(XContentParser parser) throws IOException { - return PARSER.parse(parser, null); - } - - private final String id; - private final String reason; - private final State state; - private final NodeAttributes node; - private final TransformIndexerStats indexerStats; - private final TransformCheckpointingInfo checkpointingInfo; - - public TransformStats( - String id, - State state, - String reason, - NodeAttributes node, - TransformIndexerStats stats, - TransformCheckpointingInfo checkpointingInfo - ) { - this.id = id; - this.state = state; - this.reason = reason; - this.node = node; - this.indexerStats = stats; - this.checkpointingInfo = checkpointingInfo; - } - - public String getId() { - return id; - } - - public State getState() { - return state; - } - - public String getReason() { - return reason; - } - - public NodeAttributes getNode() { - return node; - } - - public TransformIndexerStats getIndexerStats() { - return indexerStats; - } - - public TransformCheckpointingInfo getCheckpointingInfo() { - return checkpointingInfo; - } - - @Override - public int hashCode() { - return Objects.hash(id, state, reason, node, indexerStats, checkpointingInfo); - } - - @Override - public boolean equals(Object other) { - if (this == other) { - return true; - } - - if (other == null || getClass() != other.getClass()) { - return false; - } - - TransformStats that = (TransformStats) other; - - return Objects.equals(this.id, that.id) - && Objects.equals(this.state, that.state) - && Objects.equals(this.reason, that.reason) - && Objects.equals(this.node, that.node) - && Objects.equals(this.indexerStats, that.indexerStats) - && Objects.equals(this.checkpointingInfo, that.checkpointingInfo); - } - - public enum State { - - STARTED, - INDEXING, - ABORTING, - STOPPING, - STOPPED, - FAILED, - WAITING; - - public static State fromString(String name) { - return valueOf(name.trim().toUpperCase(Locale.ROOT)); - } - - public String value() { - return name().toLowerCase(Locale.ROOT); - } - } -} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/transforms/latest/LatestConfig.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/transforms/latest/LatestConfig.java deleted file mode 100644 index 5c1c868d62143..0000000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/transforms/latest/LatestConfig.java +++ /dev/null @@ -1,123 +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 - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -package org.elasticsearch.client.transform.transforms.latest; - -import org.elasticsearch.xcontent.ConstructingObjectParser; -import org.elasticsearch.xcontent.ParseField; -import org.elasticsearch.xcontent.ToXContentObject; -import org.elasticsearch.xcontent.XContentBuilder; -import org.elasticsearch.xcontent.XContentParser; - -import java.io.IOException; -import java.util.Arrays; -import java.util.List; -import java.util.Objects; - -import static org.elasticsearch.xcontent.ConstructingObjectParser.constructorArg; - -/** - * Class describing how to compute latest doc for every unique key - */ -public class LatestConfig implements ToXContentObject { - - private static final String NAME = "latest_config"; - - private static final ParseField UNIQUE_KEY = new ParseField("unique_key"); - private static final ParseField SORT = new ParseField("sort"); - - private final List uniqueKey; - private final String sort; - - @SuppressWarnings("unchecked") - private static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>( - NAME, - true, - args -> new LatestConfig((List) args[0], (String) args[1]) - ); - - static { - PARSER.declareStringArray(constructorArg(), UNIQUE_KEY); - PARSER.declareString(constructorArg(), SORT); - } - - public static LatestConfig fromXContent(final XContentParser parser) { - return PARSER.apply(parser, null); - } - - LatestConfig(List uniqueKey, String sort) { - this.uniqueKey = uniqueKey; - this.sort = sort; - } - - @Override - public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { - builder.startObject(); - builder.field(UNIQUE_KEY.getPreferredName(), uniqueKey); - builder.field(SORT.getPreferredName(), sort); - builder.endObject(); - return builder; - } - - public List getUniqueKey() { - return uniqueKey; - } - - public String getSort() { - return sort; - } - - @Override - public boolean equals(Object other) { - if (this == other) { - return true; - } - if (other == null || getClass() != other.getClass()) { - return false; - } - LatestConfig that = (LatestConfig) other; - return Objects.equals(this.uniqueKey, that.uniqueKey) && Objects.equals(this.sort, that.sort); - } - - @Override - public int hashCode() { - return Objects.hash(uniqueKey, sort); - } - - public static Builder builder() { - return new Builder(); - } - - public static class Builder { - private List uniqueKey; - private String sort; - - /** - * Set how to group the source data - * @param uniqueKey The configuration describing how to group the source data - * @return the {@link Builder} with the unique key set. - */ - public Builder setUniqueKey(String... uniqueKey) { - return setUniqueKey(Arrays.asList(uniqueKey)); - } - - public Builder setUniqueKey(List uniqueKey) { - this.uniqueKey = uniqueKey; - return this; - } - - public Builder setSort(String sort) { - this.sort = sort; - return this; - } - - public LatestConfig build() { - return new LatestConfig(uniqueKey, sort); - } - } -} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/transforms/pivot/AggregationConfig.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/transforms/pivot/AggregationConfig.java deleted file mode 100644 index 79155bb40abff..0000000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/transforms/pivot/AggregationConfig.java +++ /dev/null @@ -1,66 +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 - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -package org.elasticsearch.client.transform.transforms.pivot; - -import org.elasticsearch.search.aggregations.AggregationBuilder; -import org.elasticsearch.search.aggregations.AggregatorFactories; -import org.elasticsearch.xcontent.ToXContentObject; -import org.elasticsearch.xcontent.XContentBuilder; -import org.elasticsearch.xcontent.XContentParser; - -import java.io.IOException; -import java.util.Collection; -import java.util.Objects; - -public class AggregationConfig implements ToXContentObject { - private final AggregatorFactories.Builder aggregations; - - public static AggregationConfig fromXContent(XContentParser parser) throws IOException { - if (parser.currentToken() == null) { - parser.nextToken(); - } - AggregatorFactories.Builder aggregations = AggregatorFactories.parseAggregators(parser); - return new AggregationConfig(aggregations); - } - - public AggregationConfig(AggregatorFactories.Builder aggregations) { - this.aggregations = aggregations; - } - - @Override - public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { - aggregations.toXContent(builder, params); - return builder; - } - - public Collection getAggregatorFactories() { - return aggregations.getAggregatorFactories(); - } - - @Override - public int hashCode() { - return Objects.hash(aggregations); - } - - @Override - public boolean equals(Object other) { - if (this == other) { - return true; - } - - if (other == null || getClass() != other.getClass()) { - return false; - } - - final AggregationConfig that = (AggregationConfig) other; - - return Objects.equals(this.aggregations, that.aggregations); - } - -} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/transforms/pivot/DateHistogramGroupSource.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/transforms/pivot/DateHistogramGroupSource.java deleted file mode 100644 index 5cadd22b5bcd7..0000000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/transforms/pivot/DateHistogramGroupSource.java +++ /dev/null @@ -1,354 +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 - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -package org.elasticsearch.client.transform.transforms.pivot; - -import org.elasticsearch.common.Strings; -import org.elasticsearch.script.Script; -import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval; -import org.elasticsearch.xcontent.ConstructingObjectParser; -import org.elasticsearch.xcontent.ObjectParser; -import org.elasticsearch.xcontent.ParseField; -import org.elasticsearch.xcontent.ToXContentFragment; -import org.elasticsearch.xcontent.ToXContentObject; -import org.elasticsearch.xcontent.XContentBuilder; -import org.elasticsearch.xcontent.XContentParser; - -import java.io.IOException; -import java.time.ZoneId; -import java.time.ZoneOffset; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashSet; -import java.util.Objects; -import java.util.Set; - -import static org.elasticsearch.xcontent.ConstructingObjectParser.optionalConstructorArg; - -/** - * A grouping via a date histogram aggregation referencing a timefield - */ -public class DateHistogramGroupSource extends SingleGroupSource implements ToXContentObject { - - private static final ParseField TIME_ZONE = new ParseField("time_zone"); - - // From DateHistogramAggregationBuilder in core, transplanted and modified to a set - // so we don't need to import a dependency on the class - private static final Set DATE_FIELD_UNITS = Collections.unmodifiableSet( - new HashSet<>( - Arrays.asList( - "year", - "1y", - "quarter", - "1q", - "month", - "1M", - "week", - "1w", - "day", - "1d", - "hour", - "1h", - "minute", - "1m", - "second", - "1s" - ) - ) - ); - - /** - * Interval can be specified in 2 ways: - * - * fixed_interval fixed intervals like 1h, 1m, 1d - * calendar_interval calendar aware intervals like 1M, 1Y, ... - * - * Note: transform does not support the deprecated interval option - */ - public interface Interval extends ToXContentFragment { - String getName(); - - DateHistogramInterval getInterval(); - } - - public static class FixedInterval implements Interval { - private static final String NAME = "fixed_interval"; - private final DateHistogramInterval interval; - - public FixedInterval(DateHistogramInterval interval) { - this.interval = interval; - } - - @Override - public String getName() { - return NAME; - } - - @Override - public DateHistogramInterval getInterval() { - return interval; - } - - @Override - public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { - builder.field(NAME); - interval.toXContent(builder, params); - return builder; - } - - @Override - public boolean equals(Object other) { - if (this == other) { - return true; - } - - if (other == null || getClass() != other.getClass()) { - return false; - } - - final FixedInterval that = (FixedInterval) other; - return Objects.equals(this.interval, that.interval); - } - - @Override - public int hashCode() { - return Objects.hash(interval); - } - } - - public static class CalendarInterval implements Interval { - private static final String NAME = "calendar_interval"; - private final DateHistogramInterval interval; - - public CalendarInterval(DateHistogramInterval interval) { - this.interval = interval; - if (DATE_FIELD_UNITS.contains(interval.toString()) == false) { - throw new IllegalArgumentException( - "The supplied interval [" + interval + "] could not be parsed " + "as a calendar interval." - ); - } - } - - @Override - public String getName() { - return NAME; - } - - @Override - public DateHistogramInterval getInterval() { - return interval; - } - - @Override - public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { - builder.field(NAME); - interval.toXContent(builder, params); - return builder; - } - - @Override - public boolean equals(Object other) { - if (this == other) { - return true; - } - - if (other == null || getClass() != other.getClass()) { - return false; - } - - final CalendarInterval that = (CalendarInterval) other; - return Objects.equals(this.interval, that.interval); - } - - @Override - public int hashCode() { - return Objects.hash(interval); - } - } - - private static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>( - "date_histogram_group_source", - true, - (args) -> { - String field = (String) args[0]; - Script script = (Script) args[1]; - boolean missingBucket = args[2] == null ? false : (boolean) args[2]; - String fixedInterval = (String) args[3]; - String calendarInterval = (String) args[4]; - ZoneId zoneId = (ZoneId) args[5]; - - Interval interval = null; - - if (fixedInterval != null && calendarInterval != null) { - throw new IllegalArgumentException("You must specify either fixed_interval or calendar_interval, found both"); - } else if (fixedInterval != null) { - interval = new FixedInterval(new DateHistogramInterval(fixedInterval)); - } else if (calendarInterval != null) { - interval = new CalendarInterval(new DateHistogramInterval(calendarInterval)); - } else { - throw new IllegalArgumentException("You must specify either fixed_interval or calendar_interval, found none"); - } - - return new DateHistogramGroupSource(field, script, missingBucket, interval, zoneId); - } - ); - - static { - PARSER.declareString(optionalConstructorArg(), FIELD); - Script.declareScript(PARSER, optionalConstructorArg(), SCRIPT); - PARSER.declareBoolean(optionalConstructorArg(), MISSING_BUCKET); - PARSER.declareString(optionalConstructorArg(), new ParseField(FixedInterval.NAME)); - PARSER.declareString(optionalConstructorArg(), new ParseField(CalendarInterval.NAME)); - - PARSER.declareField(optionalConstructorArg(), p -> { - if (p.currentToken() == XContentParser.Token.VALUE_STRING) { - return ZoneId.of(p.text()); - } else { - return ZoneOffset.ofHours(p.intValue()); - } - }, TIME_ZONE, ObjectParser.ValueType.LONG); - } - - public static DateHistogramGroupSource fromXContent(final XContentParser parser) { - return PARSER.apply(parser, null); - } - - private final Interval interval; - private final ZoneId timeZone; - - DateHistogramGroupSource(String field, Script script, Interval interval, ZoneId timeZone) { - this(field, script, false, interval, timeZone); - } - - DateHistogramGroupSource(String field, Script script, boolean missingBucket, Interval interval, ZoneId timeZone) { - super(field, script, missingBucket); - this.interval = interval; - this.timeZone = timeZone; - } - - @Override - public Type getType() { - return Type.DATE_HISTOGRAM; - } - - public Interval getInterval() { - return interval; - } - - public ZoneId getTimeZone() { - return timeZone; - } - - @Override - public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { - builder.startObject(); - super.innerXContent(builder, params); - interval.toXContent(builder, params); - if (timeZone != null) { - builder.field(TIME_ZONE.getPreferredName(), timeZone.toString()); - } - builder.endObject(); - return builder; - } - - @Override - public boolean equals(Object other) { - if (this == other) { - return true; - } - - if (other == null || getClass() != other.getClass()) { - return false; - } - - final DateHistogramGroupSource that = (DateHistogramGroupSource) other; - - return this.missingBucket == that.missingBucket - && Objects.equals(this.field, that.field) - && Objects.equals(this.script, that.script) - && Objects.equals(this.interval, that.interval) - && Objects.equals(this.timeZone, that.timeZone); - } - - @Override - public int hashCode() { - return Objects.hash(field, script, missingBucket, interval, timeZone); - } - - @Override - public String toString() { - return Strings.toString(this, true, true); - } - - public static Builder builder() { - return new Builder(); - } - - public static class Builder { - - private String field; - private Script script; - private Interval interval; - private ZoneId timeZone; - private boolean missingBucket; - - /** - * The field with which to construct the date histogram grouping - * @param field The field name - * @return The {@link Builder} with the field set. - */ - public Builder setField(String field) { - this.field = field; - return this; - } - - /** - * The script with which to construct the date histogram grouping - * @param script The script - * @return The {@link Builder} with the script set. - */ - public Builder setScript(Script script) { - this.script = script; - return this; - } - - /** - * Set the interval for the DateHistogram grouping - * @param interval a fixed or calendar interval - * @return the {@link Builder} with the interval set. - */ - public Builder setInterval(Interval interval) { - this.interval = interval; - return this; - } - - /** - * Sets the time zone to use for this aggregation - * @param timeZone The zoneId for the timeZone - * @return The {@link Builder} with the timeZone set. - */ - public Builder setTimeZone(ZoneId timeZone) { - this.timeZone = timeZone; - return this; - } - - /** - * Sets the value of "missing_bucket" - * @param missingBucket value of "missing_bucket" to be set - * @return The {@link Builder} with "missing_bucket" set. - */ - public Builder setMissingBucket(boolean missingBucket) { - this.missingBucket = missingBucket; - return this; - } - - public DateHistogramGroupSource build() { - return new DateHistogramGroupSource(field, script, missingBucket, interval, timeZone); - } - } -} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/transforms/pivot/GeoTileGroupSource.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/transforms/pivot/GeoTileGroupSource.java deleted file mode 100644 index 38f0dabb1b8a6..0000000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/transforms/pivot/GeoTileGroupSource.java +++ /dev/null @@ -1,175 +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 - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -package org.elasticsearch.client.transform.transforms.pivot; - -import org.elasticsearch.common.geo.GeoBoundingBox; -import org.elasticsearch.search.aggregations.bucket.geogrid.GeoTileUtils; -import org.elasticsearch.xcontent.ConstructingObjectParser; -import org.elasticsearch.xcontent.ObjectParser; -import org.elasticsearch.xcontent.ParseField; -import org.elasticsearch.xcontent.ToXContentObject; -import org.elasticsearch.xcontent.XContentBuilder; -import org.elasticsearch.xcontent.XContentParser; - -import java.io.IOException; -import java.util.Objects; - -import static org.elasticsearch.xcontent.ConstructingObjectParser.optionalConstructorArg; - -/* - * A geotile_grid aggregation source for group_by - */ -public class GeoTileGroupSource extends SingleGroupSource implements ToXContentObject { - private static final String NAME = "transform_geo_tile_group"; - - private static final ParseField PRECISION = new ParseField("precision"); - private static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>(NAME, true, (args) -> { - String field = (String) args[0]; - boolean missingBucket = args[1] == null ? false : (boolean) args[1]; - Integer precision = (Integer) args[2]; - GeoBoundingBox boundingBox = (GeoBoundingBox) args[3]; - - return new GeoTileGroupSource(field, missingBucket, precision, boundingBox); - }); - - static { - PARSER.declareString(optionalConstructorArg(), FIELD); - PARSER.declareBoolean(optionalConstructorArg(), MISSING_BUCKET); - PARSER.declareInt(optionalConstructorArg(), PRECISION); - PARSER.declareField( - optionalConstructorArg(), - (p, context) -> GeoBoundingBox.parseBoundingBox(p), - GeoBoundingBox.BOUNDS_FIELD, - ObjectParser.ValueType.OBJECT - ); - } - private final Integer precision; - private final GeoBoundingBox geoBoundingBox; - - public GeoTileGroupSource(final String field, final Integer precision, final GeoBoundingBox boundingBox) { - this(field, false, precision, boundingBox); - } - - public GeoTileGroupSource(final String field, final boolean missingBucket, final Integer precision, final GeoBoundingBox boundingBox) { - super(field, null, missingBucket); - if (precision != null) { - GeoTileUtils.checkPrecisionRange(precision); - } - this.precision = precision; - this.geoBoundingBox = boundingBox; - } - - @Override - public Type getType() { - return Type.GEOTILE_GRID; - } - - public Integer getPrecision() { - return precision; - } - - public GeoBoundingBox getGeoBoundingBox() { - return geoBoundingBox; - } - - public static GeoTileGroupSource fromXContent(final XContentParser parser) { - return PARSER.apply(parser, null); - } - - @Override - public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { - builder.startObject(); - super.innerXContent(builder, params); - if (precision != null) { - builder.field(PRECISION.getPreferredName(), precision); - } - if (geoBoundingBox != null) { - builder.startObject(GeoBoundingBox.BOUNDS_FIELD.getPreferredName()); - geoBoundingBox.toXContentFragment(builder, true); - builder.endObject(); - } - builder.endObject(); - return builder; - } - - @Override - public boolean equals(Object other) { - if (this == other) { - return true; - } - - if (other == null || getClass() != other.getClass()) { - return false; - } - - final GeoTileGroupSource that = (GeoTileGroupSource) other; - - return this.missingBucket == that.missingBucket - && Objects.equals(this.field, that.field) - && Objects.equals(this.precision, that.precision) - && Objects.equals(this.geoBoundingBox, that.geoBoundingBox); - } - - @Override - public int hashCode() { - return Objects.hash(field, missingBucket, precision, geoBoundingBox); - } - - public static class Builder { - - private String field; - private boolean missingBucket; - private Integer precision; - private GeoBoundingBox boundingBox; - - /** - * The field with which to construct the geo tile grouping - * @param field The field name - * @return The {@link Builder} with the field set. - */ - public Builder setField(String field) { - this.field = field; - return this; - } - - /** - * Sets the value of "missing_bucket" - * @param missingBucket value of "missing_bucket" to be set - * @return The {@link Builder} with "missing_bucket" set. - */ - public Builder setMissingBucket(boolean missingBucket) { - this.missingBucket = missingBucket; - return this; - } - - /** - * The precision with which to construct the geo tile grouping - * @param precision The precision - * @return The {@link Builder} with the precision set. - */ - public Builder setPrecision(Integer precision) { - this.precision = precision; - return this; - } - - /** - * Set the bounding box for the geo tile grouping - * @param boundingBox The bounding box - * @return the {@link Builder} with the bounding box set. - */ - public Builder setBoundingBox(GeoBoundingBox boundingBox) { - this.boundingBox = boundingBox; - return this; - } - - public GeoTileGroupSource build() { - return new GeoTileGroupSource(field, missingBucket, precision, boundingBox); - } - } -} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/transforms/pivot/GroupConfig.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/transforms/pivot/GroupConfig.java deleted file mode 100644 index 1a6b8c1a4751d..0000000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/transforms/pivot/GroupConfig.java +++ /dev/null @@ -1,185 +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 - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -package org.elasticsearch.client.transform.transforms.pivot; - -import org.elasticsearch.common.ParsingException; -import org.elasticsearch.common.Strings; -import org.elasticsearch.xcontent.ToXContentObject; -import org.elasticsearch.xcontent.XContentBuilder; -import org.elasticsearch.xcontent.XContentParser; - -import java.io.IOException; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.Objects; - -import static org.elasticsearch.common.xcontent.XContentParserUtils.ensureExpectedToken; - -/** - * Class describing how to group data - */ -public class GroupConfig implements ToXContentObject { - - private final Map groups; - - /** - * Leniently parse a {@code GroupConfig}. - * Parsing is lenient in that unknown fields in the root of the - * object are ignored. Unknown group types {@link SingleGroupSource.Type} - * will cause a parsing error. - * - * @param parser The XContent parser - * @return The parsed object - * @throws IOException On parsing error - */ - public static GroupConfig fromXContent(final XContentParser parser) throws IOException { - LinkedHashMap groups = new LinkedHashMap<>(); - - // be parsing friendly, whether the token needs to be advanced or not (similar to what ObjectParser does) - XContentParser.Token token; - if (parser.currentToken() != XContentParser.Token.START_OBJECT) { - token = parser.nextToken(); - if (token != XContentParser.Token.START_OBJECT) { - throw new ParsingException(parser.getTokenLocation(), "Failed to parse object: Expected START_OBJECT but was: " + token); - } - } - - while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { - ensureExpectedToken(XContentParser.Token.FIELD_NAME, token, parser); - token = parser.nextToken(); - if (token != XContentParser.Token.START_OBJECT) { - // leniently skip over key-value and array fields in the root of the object - if (token == XContentParser.Token.START_ARRAY) { - parser.skipChildren(); - } - continue; - } - - String destinationFieldName = parser.currentName(); - ensureExpectedToken(XContentParser.Token.START_OBJECT, token, parser); - token = parser.nextToken(); - ensureExpectedToken(XContentParser.Token.FIELD_NAME, token, parser); - String groupType = parser.currentName(); - - token = parser.nextToken(); - if (token != XContentParser.Token.START_OBJECT) { - // need to consume up to dest field end obj - consumeUntilEndObject(parser, 1); - continue; - } - - SingleGroupSource groupSource = switch (groupType) { - case "terms" -> TermsGroupSource.fromXContent(parser); - case "histogram" -> HistogramGroupSource.fromXContent(parser); - case "date_histogram" -> DateHistogramGroupSource.fromXContent(parser); - case "geotile_grid" -> GeoTileGroupSource.fromXContent(parser); - default -> { - // not a valid group source. Consume up to the dest field end object - consumeUntilEndObject(parser, 2); - yield null; - } - }; - - if (groupSource != null) { - groups.put(destinationFieldName, groupSource); - // destination field end_object - parser.nextToken(); - } - } - return new GroupConfig(groups); - } - - /** - * Consume tokens from the parser until {@code endObjectCount} of end object - * tokens have been read. Nested objects that start and end inside the current - * field are skipped and do contribute to the end object count. - * @param parser The XContent parser - * @param endObjectCount Number of end object tokens to consume - * @throws IOException On parsing error - */ - private static void consumeUntilEndObject(XContentParser parser, int endObjectCount) throws IOException { - do { - XContentParser.Token token = parser.nextToken(); - if (token == XContentParser.Token.START_OBJECT) { - endObjectCount++; - } else if (token == XContentParser.Token.END_OBJECT) { - endObjectCount--; - } - } while (endObjectCount != 0); - } - - GroupConfig(Map groups) { - this.groups = groups; - } - - public Map getGroups() { - return groups; - } - - @Override - public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { - builder.startObject(); - for (Map.Entry entry : groups.entrySet()) { - builder.startObject(entry.getKey()); - builder.field(entry.getValue().getType().value(), entry.getValue()); - builder.endObject(); - } - builder.endObject(); - return builder; - } - - @Override - public boolean equals(Object other) { - if (this == other) { - return true; - } - - if (other == null || getClass() != other.getClass()) { - return false; - } - - final GroupConfig that = (GroupConfig) other; - - return Objects.equals(this.groups, that.groups); - } - - @Override - public int hashCode() { - return Objects.hash(groups); - } - - @Override - public String toString() { - return Strings.toString(this, true, true); - } - - public static Builder builder() { - return new Builder(); - } - - public static class Builder { - private final Map groups = new HashMap<>(); - - /** - * Add a new grouping to the builder - * @param name The name of the resulting grouped field - * @param group The type of grouping referenced - * @return The {@link Builder} with a new grouping entry added - */ - public Builder groupBy(String name, SingleGroupSource group) { - groups.put(name, group); - return this; - } - - public GroupConfig build() { - return new GroupConfig(groups); - } - } -} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/transforms/pivot/HistogramGroupSource.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/transforms/pivot/HistogramGroupSource.java deleted file mode 100644 index 5ab4000064787..0000000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/transforms/pivot/HistogramGroupSource.java +++ /dev/null @@ -1,157 +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 - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -package org.elasticsearch.client.transform.transforms.pivot; - -import org.elasticsearch.script.Script; -import org.elasticsearch.xcontent.ConstructingObjectParser; -import org.elasticsearch.xcontent.ParseField; -import org.elasticsearch.xcontent.ToXContent; -import org.elasticsearch.xcontent.ToXContentObject; -import org.elasticsearch.xcontent.XContentBuilder; -import org.elasticsearch.xcontent.XContentParser; - -import java.io.IOException; -import java.util.Objects; - -import static org.elasticsearch.xcontent.ConstructingObjectParser.optionalConstructorArg; - -/** - * A grouping via a histogram aggregation referencing a numeric field - */ -public class HistogramGroupSource extends SingleGroupSource implements ToXContentObject { - - protected static final ParseField INTERVAL = new ParseField("interval"); - private static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>( - "histogram_group_source", - true, - args -> new HistogramGroupSource((String) args[0], (Script) args[1], args[2] == null ? false : (boolean) args[2], (double) args[3]) - ); - - static { - PARSER.declareString(optionalConstructorArg(), FIELD); - Script.declareScript(PARSER, optionalConstructorArg(), SCRIPT); - PARSER.declareBoolean(optionalConstructorArg(), MISSING_BUCKET); - PARSER.declareDouble(optionalConstructorArg(), INTERVAL); - } - - public static HistogramGroupSource fromXContent(final XContentParser parser) { - return PARSER.apply(parser, null); - } - - private final double interval; - - HistogramGroupSource(String field, Script script, double interval) { - this(field, script, false, interval); - } - - HistogramGroupSource(String field, Script script, boolean missingBucket, double interval) { - super(field, script, missingBucket); - if (interval <= 0) { - throw new IllegalArgumentException("[interval] must be greater than 0."); - } - this.interval = interval; - } - - @Override - public Type getType() { - return Type.HISTOGRAM; - } - - public double getInterval() { - return interval; - } - - @Override - public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException { - builder.startObject(); - super.innerXContent(builder, params); - builder.field(INTERVAL.getPreferredName(), interval); - builder.endObject(); - return builder; - } - - @Override - public boolean equals(Object other) { - if (this == other) { - return true; - } - - if (other == null || getClass() != other.getClass()) { - return false; - } - - final HistogramGroupSource that = (HistogramGroupSource) other; - - return this.missingBucket == that.missingBucket - && Objects.equals(this.field, that.field) - && Objects.equals(this.script, that.script) - && Objects.equals(this.interval, that.interval); - } - - @Override - public int hashCode() { - return Objects.hash(field, script, interval, missingBucket); - } - - public static Builder builder() { - return new Builder(); - } - - public static class Builder { - - private String field; - private Script script; - private boolean missingBucket; - private double interval; - - /** - * The field to reference in the histogram grouping - * @param field The numeric field name to use in the histogram grouping - * @return The {@link Builder} with the field set. - */ - public Builder setField(String field) { - this.field = field; - return this; - } - - /** - * Set the interval for the histogram grouping - * @param interval The numeric interval for the histogram grouping - * @return The {@link Builder} with the interval set. - */ - public Builder setInterval(double interval) { - this.interval = interval; - return this; - } - - /** - * The script with which to construct the histogram grouping - * @param script The script - * @return The {@link Builder} with the script set. - */ - public Builder setScript(Script script) { - this.script = script; - return this; - } - - /** - * Sets the value of "missing_bucket" - * @param missingBucket value of "missing_bucket" to be set - * @return The {@link Builder} with "missing_bucket" set. - */ - public Builder setMissingBucket(boolean missingBucket) { - this.missingBucket = missingBucket; - return this; - } - - public HistogramGroupSource build() { - return new HistogramGroupSource(field, script, missingBucket, interval); - } - } -} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/transforms/pivot/PivotConfig.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/transforms/pivot/PivotConfig.java deleted file mode 100644 index 378a0f0346fdf..0000000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/transforms/pivot/PivotConfig.java +++ /dev/null @@ -1,164 +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 - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -package org.elasticsearch.client.transform.transforms.pivot; - -import org.elasticsearch.search.aggregations.AggregatorFactories; -import org.elasticsearch.xcontent.ConstructingObjectParser; -import org.elasticsearch.xcontent.ParseField; -import org.elasticsearch.xcontent.ToXContentObject; -import org.elasticsearch.xcontent.XContentBuilder; -import org.elasticsearch.xcontent.XContentParser; - -import java.io.IOException; -import java.util.Objects; - -import static org.elasticsearch.xcontent.ConstructingObjectParser.constructorArg; -import static org.elasticsearch.xcontent.ConstructingObjectParser.optionalConstructorArg; - -/** - * Class describing how to pivot data via {@link GroupConfig} and {@link AggregationConfig} objects - */ -public class PivotConfig implements ToXContentObject { - - private static final ParseField GROUP_BY = new ParseField("group_by"); - private static final ParseField AGGREGATIONS = new ParseField("aggregations"); - private static final ParseField MAX_PAGE_SEARCH_SIZE = new ParseField("max_page_search_size"); - - private final GroupConfig groups; - private final AggregationConfig aggregationConfig; - private final Integer maxPageSearchSize; - - private static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>( - "pivot_config", - true, - args -> new PivotConfig((GroupConfig) args[0], (AggregationConfig) args[1], (Integer) args[2]) - ); - - static { - PARSER.declareObject(constructorArg(), (p, c) -> (GroupConfig.fromXContent(p)), GROUP_BY); - PARSER.declareObject(optionalConstructorArg(), (p, c) -> AggregationConfig.fromXContent(p), AGGREGATIONS); - PARSER.declareInt(optionalConstructorArg(), MAX_PAGE_SEARCH_SIZE); - } - - public static PivotConfig fromXContent(final XContentParser parser) { - return PARSER.apply(parser, null); - } - - PivotConfig(GroupConfig groups, final AggregationConfig aggregationConfig, Integer maxPageSearchSize) { - this.groups = groups; - this.aggregationConfig = aggregationConfig; - this.maxPageSearchSize = maxPageSearchSize; - } - - @Override - public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { - builder.startObject(); - builder.field(GROUP_BY.getPreferredName(), groups); - builder.field(AGGREGATIONS.getPreferredName(), aggregationConfig); - if (maxPageSearchSize != null) { - builder.field(MAX_PAGE_SEARCH_SIZE.getPreferredName(), maxPageSearchSize); - } - builder.endObject(); - return builder; - } - - public AggregationConfig getAggregationConfig() { - return aggregationConfig; - } - - public GroupConfig getGroupConfig() { - return groups; - } - - @Deprecated - public Integer getMaxPageSearchSize() { - return maxPageSearchSize; - } - - @Override - public boolean equals(Object other) { - if (this == other) { - return true; - } - - if (other == null || getClass() != other.getClass()) { - return false; - } - - final PivotConfig that = (PivotConfig) other; - - return Objects.equals(this.groups, that.groups) - && Objects.equals(this.aggregationConfig, that.aggregationConfig) - && Objects.equals(this.maxPageSearchSize, that.maxPageSearchSize); - } - - @Override - public int hashCode() { - return Objects.hash(groups, aggregationConfig, maxPageSearchSize); - } - - public static Builder builder() { - return new Builder(); - } - - public static class Builder { - private GroupConfig groups; - private AggregationConfig aggregationConfig; - private Integer maxPageSearchSize; - - /** - * Set how to group the source data - * @param groups The configuration describing how to group and pivot the source data - * @return the {@link Builder} with the interval set. - */ - public Builder setGroups(GroupConfig groups) { - this.groups = groups; - return this; - } - - /** - * Set the aggregated fields to include in the pivot config - * @param aggregationConfig The configuration describing the aggregated fields - * @return the {@link Builder} with the aggregations set. - */ - public Builder setAggregationConfig(AggregationConfig aggregationConfig) { - this.aggregationConfig = aggregationConfig; - return this; - } - - /** - * Set the aggregated fields to include in the pivot config - * @param aggregations The aggregated field builders - * @return the {@link Builder} with the aggregations set. - */ - public Builder setAggregations(AggregatorFactories.Builder aggregations) { - this.aggregationConfig = new AggregationConfig(aggregations); - return this; - } - - /** - * Sets the paging maximum paging maxPageSearchSize that date frame transform can use when - * pulling the data from the source index. - * - * If OOM is triggered, the paging maxPageSearchSize is dynamically reduced so that the transform can continue to gather data. - * Deprecated, use {@link org.elasticsearch.client.transform.transforms.SettingsConfig.Builder#setMaxPageSearchSize} instead - * @param maxPageSearchSize Integer value between 10 and 10_000 - * @return the {@link Builder} with the paging maxPageSearchSize set. - */ - @Deprecated - public Builder setMaxPageSearchSize(Integer maxPageSearchSize) { - this.maxPageSearchSize = maxPageSearchSize; - return this; - } - - public PivotConfig build() { - return new PivotConfig(groups, aggregationConfig, maxPageSearchSize); - } - } -} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/transforms/pivot/SingleGroupSource.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/transforms/pivot/SingleGroupSource.java deleted file mode 100644 index e73eb6d77c11e..0000000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/transforms/pivot/SingleGroupSource.java +++ /dev/null @@ -1,94 +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 - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -package org.elasticsearch.client.transform.transforms.pivot; - -import org.elasticsearch.script.Script; -import org.elasticsearch.xcontent.ParseField; -import org.elasticsearch.xcontent.ToXContentObject; -import org.elasticsearch.xcontent.XContentBuilder; - -import java.io.IOException; -import java.util.Locale; -import java.util.Objects; - -public abstract class SingleGroupSource implements ToXContentObject { - - protected static final ParseField FIELD = new ParseField("field"); - protected static final ParseField SCRIPT = new ParseField("script"); - protected static final ParseField MISSING_BUCKET = new ParseField("missing_bucket"); - - public enum Type { - TERMS, - HISTOGRAM, - DATE_HISTOGRAM, - GEOTILE_GRID; - - public String value() { - return name().toLowerCase(Locale.ROOT); - } - } - - protected final String field; - protected final Script script; - protected final boolean missingBucket; - - public SingleGroupSource(final String field, final Script script, final boolean missingBucket) { - this.field = field; - this.script = script; - this.missingBucket = missingBucket; - } - - public abstract Type getType(); - - public String getField() { - return field; - } - - public Script getScript() { - return script; - } - - public boolean getMissingBucket() { - return missingBucket; - } - - protected void innerXContent(XContentBuilder builder, Params params) throws IOException { - if (field != null) { - builder.field(FIELD.getPreferredName(), field); - } - if (script != null) { - builder.field(SCRIPT.getPreferredName(), script); - } - if (missingBucket) { - builder.field(MISSING_BUCKET.getPreferredName(), missingBucket); - } - } - - @Override - public boolean equals(Object other) { - if (this == other) { - return true; - } - - if (other instanceof SingleGroupSource == false) { - return false; - } - - final SingleGroupSource that = (SingleGroupSource) other; - - return this.missingBucket == that.missingBucket - && Objects.equals(this.field, that.field) - && Objects.equals(this.script, that.script); - } - - @Override - public int hashCode() { - return Objects.hash(field, script, missingBucket); - } -} diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/transforms/pivot/TermsGroupSource.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/transforms/pivot/TermsGroupSource.java deleted file mode 100644 index 9b5de5fb41022..0000000000000 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/transform/transforms/pivot/TermsGroupSource.java +++ /dev/null @@ -1,105 +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 - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -package org.elasticsearch.client.transform.transforms.pivot; - -import org.elasticsearch.script.Script; -import org.elasticsearch.xcontent.ConstructingObjectParser; -import org.elasticsearch.xcontent.ToXContent; -import org.elasticsearch.xcontent.ToXContentObject; -import org.elasticsearch.xcontent.XContentBuilder; -import org.elasticsearch.xcontent.XContentParser; - -import java.io.IOException; - -import static org.elasticsearch.xcontent.ConstructingObjectParser.optionalConstructorArg; - -public class TermsGroupSource extends SingleGroupSource implements ToXContentObject { - - private static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>( - "terms_group_source", - true, - args -> new TermsGroupSource((String) args[0], (Script) args[1], args[2] == null ? false : (boolean) args[2]) - ); - - static { - PARSER.declareString(optionalConstructorArg(), FIELD); - Script.declareScript(PARSER, optionalConstructorArg(), SCRIPT); - PARSER.declareBoolean(optionalConstructorArg(), MISSING_BUCKET); - } - - public static TermsGroupSource fromXContent(final XContentParser parser) { - return PARSER.apply(parser, null); - } - - TermsGroupSource(final String field, final Script script) { - this(field, script, false); - } - - TermsGroupSource(final String field, final Script script, final boolean missingBucket) { - super(field, script, missingBucket); - } - - @Override - public Type getType() { - return Type.TERMS; - } - - @Override - public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException { - builder.startObject(); - super.innerXContent(builder, params); - builder.endObject(); - return builder; - } - - public static Builder builder() { - return new Builder(); - } - - public static class Builder { - - private String field; - private Script script; - private boolean missingBucket; - - /** - * The field with which to construct the terms grouping - * @param field The field name - * @return The {@link Builder} with the field set. - */ - public Builder setField(String field) { - this.field = field; - return this; - } - - /** - * The script with which to construct the terms grouping - * @param script The script - * @return The {@link Builder} with the script set. - */ - public Builder setScript(Script script) { - this.script = script; - return this; - } - - /** - * Sets the value of "missing_bucket" - * @param missingBucket value of "missing_bucket" to be set - * @return The {@link Builder} with "missing_bucket" set. - */ - public Builder setMissingBucket(boolean missingBucket) { - this.missingBucket = missingBucket; - return this; - } - - public TermsGroupSource build() { - return new TermsGroupSource(field, script, missingBucket); - } - } -} diff --git a/client/rest-high-level/src/main/resources/META-INF/services/org.elasticsearch.plugins.spi.NamedXContentProvider b/client/rest-high-level/src/main/resources/META-INF/services/org.elasticsearch.plugins.spi.NamedXContentProvider index 20b144ef1c562..4e49f704561dd 100644 --- a/client/rest-high-level/src/main/resources/META-INF/services/org.elasticsearch.plugins.spi.NamedXContentProvider +++ b/client/rest-high-level/src/main/resources/META-INF/services/org.elasticsearch.plugins.spi.NamedXContentProvider @@ -1,2 +1 @@ org.elasticsearch.client.ilm.IndexLifecycleNamedXContentProvider -org.elasticsearch.client.transform.TransformNamedXContentProvider