From 206cd63c3b2dd47fe8bb1d7c2b79d01efcbe2045 Mon Sep 17 00:00:00 2001 From: Harsha Vamsi Kalluri Date: Mon, 24 Apr 2023 12:16:44 -0700 Subject: [PATCH] Adds point in time APIs Signed-off-by: Harsha Vamsi Kalluri --- CHANGELOG.md | 1 + USER_GUIDE.md | 43 +++ .../opensearch/OpenSearchAsyncClient.java | 84 +++++ .../client/opensearch/OpenSearchClient.java | 83 +++++ .../cat/OpenSearchCatAsyncClient.java | 14 + .../opensearch/cat/OpenSearchCatClient.java | 41 +++ .../cat/PointInTimeSegmentsRequest.java | 109 ++++++ .../client/opensearch/core/SearchRequest.java | 31 ++ .../CreatePointInTimeRequest.java | 341 ++++++++++++++++++ .../CreatePointInTimeResponse.java | 158 ++++++++ .../DeletePointInTimeRecord.java | 128 +++++++ .../DeletePointInTimeRequest.java | 135 +++++++ .../DeletePointInTimeResponse.java | 125 +++++++ .../ListAllPointInTimeRequest.java | 44 +++ .../ListAllPointInTimeResponse.java | 125 +++++++ .../core/point_in_time/PointInTimeRecord.java | 154 ++++++++ .../opensearch/core/search/PointInTime.java | 127 +++++++ .../integTest/AbstractCatClientIT.java | 48 ++- .../integTest/AbstractRequestIT.java | 56 +++ 19 files changed, 1839 insertions(+), 8 deletions(-) create mode 100644 java-client/src/main/java/org/opensearch/client/opensearch/cat/PointInTimeSegmentsRequest.java create mode 100644 java-client/src/main/java/org/opensearch/client/opensearch/core/point_in_time/CreatePointInTimeRequest.java create mode 100644 java-client/src/main/java/org/opensearch/client/opensearch/core/point_in_time/CreatePointInTimeResponse.java create mode 100644 java-client/src/main/java/org/opensearch/client/opensearch/core/point_in_time/DeletePointInTimeRecord.java create mode 100644 java-client/src/main/java/org/opensearch/client/opensearch/core/point_in_time/DeletePointInTimeRequest.java create mode 100644 java-client/src/main/java/org/opensearch/client/opensearch/core/point_in_time/DeletePointInTimeResponse.java create mode 100644 java-client/src/main/java/org/opensearch/client/opensearch/core/point_in_time/ListAllPointInTimeRequest.java create mode 100644 java-client/src/main/java/org/opensearch/client/opensearch/core/point_in_time/ListAllPointInTimeResponse.java create mode 100644 java-client/src/main/java/org/opensearch/client/opensearch/core/point_in_time/PointInTimeRecord.java create mode 100644 java-client/src/main/java/org/opensearch/client/opensearch/core/search/PointInTime.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 664ac086d2..e1329a207c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ### Added - Document HTTP/2 support ([#330](https://github.com/opensearch-project/opensearch-java/pull/330)) +- Added Point-In-Time APIs ([#461](https://github.com/opensearch-project/opensearch-java/pull/461)) ### Dependencies diff --git a/USER_GUIDE.md b/USER_GUIDE.md index 92f9fe70d2..256edd5e58 100644 --- a/USER_GUIDE.md +++ b/USER_GUIDE.md @@ -266,6 +266,42 @@ DeleteDataStreamRequest deleteDataStreamRequest = new DeleteDataStreamRequest.Bu DeleteDataStreamResponse deleteDataStreamResponse = javaClient().indices().deleteDataStream(deleteDataStreamRequest); ``` +## Point-In-Time API + +### Creating a point in time + +Creates a PIT. The keep_alive query parameter is required; it specifies how long to keep a PIT. + +```java +CreatePointInTimeRequest createPointInTimeRequest = new CreatePointInTimeRequest.Builder() + .targetIndexes(Collections.singletonList(index)) + .keepAlive(new Time.Builder().time("100m").build()).build(); + +CreatePointInTimeResponse createPointInTimeResponse = javaClient() + .createPointInTime(createPointInTimeRequest); +``` + +### List all point in time + +Returns all PITs in the OpenSearch cluster. + +```java +ListAllPointInTimeResponse listAllPointInTimeResponse = javaClient().listAllPointInTime(); +``` + +### Delete point in time + +Deletes one, several, or all PITs. PITs are automatically deleted when the keep_alive time period elapses. However, to deallocate resources, you can delete a PIT using the Delete PIT API. The Delete PIT API supports deleting a list of PITs by ID or deleting all PITs at once. + +```java +DeletePointInTimeRequest deletePointInTimeRequest = new DeletePointInTimeRequest.Builder() + .pitId(Collections.singletonList("pit_id")).build(); + +DeletePointInTimeResponse deletePointInTimeResponse = javaClient() + .deletePointInTime(deletePointInTimeRequest); +``` + + ## Cat API ### Cat Indices @@ -291,6 +327,13 @@ The following sample code cat nodes sorted by cpu NodesResponse nodesResponse = javaClient().cat().nodes(r -> r.sort("cpu")); ``` +### Cat point in time segments +Similarly to the CAT Segments API, the PIT Segments API provides low-level information about the disk utilization of a PIT by describing its Lucene segments. +```java +SegmentsResponse pointInTimeSegmentsResponse = javaClient().cat() + .pointInTimeSegments(r -> r.headers("index,shard,id,segment,size")); +``` + # Using different transport options ## Amazon OpenSearch Service diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/OpenSearchAsyncClient.java b/java-client/src/main/java/org/opensearch/client/opensearch/OpenSearchAsyncClient.java index 56979730b1..bb3891a826 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/OpenSearchAsyncClient.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/OpenSearchAsyncClient.java @@ -116,6 +116,12 @@ import org.opensearch.client.opensearch.core.UpdateByQueryRethrottleResponse; import org.opensearch.client.opensearch.core.UpdateRequest; import org.opensearch.client.opensearch.core.UpdateResponse; +import org.opensearch.client.opensearch.core.point_in_time.CreatePointInTimeRequest; +import org.opensearch.client.opensearch.core.point_in_time.CreatePointInTimeResponse; +import org.opensearch.client.opensearch.core.point_in_time.DeletePointInTimeRequest; +import org.opensearch.client.opensearch.core.point_in_time.DeletePointInTimeResponse; +import org.opensearch.client.opensearch.core.point_in_time.ListAllPointInTimeRequest; +import org.opensearch.client.opensearch.core.point_in_time.ListAllPointInTimeResponse; import org.opensearch.client.opensearch.dangling_indices.OpenSearchDanglingIndicesAsyncClient; import org.opensearch.client.opensearch.features.OpenSearchFeaturesAsyncClient; import org.opensearch.client.opensearch.indices.OpenSearchIndicesAsyncClient; @@ -362,6 +368,39 @@ public final CompletableFuture create( return create(fn.apply(new CreateRequest.Builder()).build()); } + // ----- Endpoint: create_point_in_time + + /** + * Provides low-level information about the disk utilization of a PIT by + * describing its Lucene segments. + * + * + */ + + public CompletableFuture createPointInTime(CreatePointInTimeRequest request) + throws IOException, OpenSearchException { + @SuppressWarnings("unchecked") + JsonEndpoint endpoint = (JsonEndpoint) CreatePointInTimeRequest._ENDPOINT; + + return this.transport.performRequestAsync(request, endpoint, this.transportOptions); + } + + /** + * Provides low-level information about the disk utilization of a PIT by + * describing its Lucene segments. + * + * @param fn + * a function that initializes a builder to create the + * {@link CreatePointInTimeRequest} + * + */ + + public final CompletableFuture createPointInTime( + Function> fn) + throws IOException, OpenSearchException { + return createPointInTime(fn.apply(new CreatePointInTimeRequest.Builder()).build()); + } + // ----- Endpoint: delete /** @@ -393,6 +432,37 @@ public final CompletableFuture delete( return delete(fn.apply(new DeleteRequest.Builder()).build()); } + // ----- Endpoint: delete_point_in_time + + /** + * Delete Point In Time + * + * + */ + + public CompletableFuture DeletePointInTime(DeletePointInTimeRequest request) + throws IOException, OpenSearchException { + @SuppressWarnings("unchecked") + JsonEndpoint endpoint = (JsonEndpoint) DeletePointInTimeRequest._ENDPOINT; + + return this.transport.performRequestAsync(request, endpoint, this.transportOptions); + } + + /** + * Delete Point In Time + * + * @param fn + * a function that initializes a builder to create the + * {@link DeletePointInTimeRequest} + * + */ + + public final CompletableFuture DeletePointInTime( + Function> fn) + throws IOException, OpenSearchException { + return DeletePointInTime(fn.apply(new DeletePointInTimeRequest.Builder()).build()); + } + // ----- Endpoint: delete_by_query /** @@ -801,6 +871,20 @@ public CompletableFuture info() throws IOException, OpenSearchExce return this.transport.performRequestAsync(InfoRequest._INSTANCE, InfoRequest._ENDPOINT, this.transportOptions); } + // ----- Endpoint: list_point_in_time + + /** + * List all Point In Time + * + * + */ + + public CompletableFuture listAllPointInTime() + throws IOException, OpenSearchException { + return this.transport.performRequestAsync(ListAllPointInTimeRequest._INSTANCE, ListAllPointInTimeRequest._ENDPOINT, + this.transportOptions); + } + // ----- Endpoint: mget /** diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/OpenSearchClient.java b/java-client/src/main/java/org/opensearch/client/opensearch/OpenSearchClient.java index 56ef79d5b1..31016f537f 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/OpenSearchClient.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/OpenSearchClient.java @@ -116,6 +116,12 @@ import org.opensearch.client.opensearch.core.UpdateByQueryRethrottleResponse; import org.opensearch.client.opensearch.core.UpdateRequest; import org.opensearch.client.opensearch.core.UpdateResponse; +import org.opensearch.client.opensearch.core.point_in_time.CreatePointInTimeRequest; +import org.opensearch.client.opensearch.core.point_in_time.CreatePointInTimeResponse; +import org.opensearch.client.opensearch.core.point_in_time.DeletePointInTimeRequest; +import org.opensearch.client.opensearch.core.point_in_time.DeletePointInTimeResponse; +import org.opensearch.client.opensearch.core.point_in_time.ListAllPointInTimeRequest; +import org.opensearch.client.opensearch.core.point_in_time.ListAllPointInTimeResponse; import org.opensearch.client.opensearch.dangling_indices.OpenSearchDanglingIndicesClient; import org.opensearch.client.opensearch.features.OpenSearchFeaturesClient; import org.opensearch.client.opensearch.indices.OpenSearchIndicesClient; @@ -359,6 +365,39 @@ public final CreateResponse create( return create(fn.apply(new CreateRequest.Builder()).build()); } + // ----- Endpoint: create_point_in_time + + /** + * Provides low-level information about the disk utilization of a PIT by + * describing its Lucene segments. + * + * + */ + + public CreatePointInTimeResponse createPointInTime(CreatePointInTimeRequest request) + throws IOException, OpenSearchException { + @SuppressWarnings("unchecked") + JsonEndpoint endpoint = (JsonEndpoint) CreatePointInTimeRequest._ENDPOINT; + + return this.transport.performRequest(request, endpoint, this.transportOptions); + } + + /** + * Provides low-level information about the disk utilization of a PIT by + * describing its Lucene segments. + * + * @param fn + * a function that initializes a builder to create the + * {@link CreatePointInTimeRequest} + * + */ + + public final CreatePointInTimeResponse createPointInTime( + Function> fn) + throws IOException, OpenSearchException { + return createPointInTime(fn.apply(new CreatePointInTimeRequest.Builder()).build()); + } + // ----- Endpoint: delete /** @@ -389,6 +428,37 @@ public final DeleteResponse delete(Function endpoint = (JsonEndpoint) DeletePointInTimeRequest._ENDPOINT; + + return this.transport.performRequest(request, endpoint, this.transportOptions); + } + + /** + * Delete Point In Time + * + * @param fn + * a function that initializes a builder to create the + * {@link DeletePointInTimeRequest} + * + */ + + public final DeletePointInTimeResponse deletePointInTime( + Function> fn) + throws IOException, OpenSearchException { + return deletePointInTime(fn.apply(new DeletePointInTimeRequest.Builder()).build()); + } + // ----- Endpoint: delete_by_query /** @@ -790,6 +860,19 @@ public InfoResponse info() throws IOException, OpenSearchException { return this.transport.performRequest(InfoRequest._INSTANCE, InfoRequest._ENDPOINT, this.transportOptions); } + // ----- Endpoint: list_point_in_time + + /** + * List all Point In Time + * + * + */ + + public ListAllPointInTimeResponse listAllPointInTime() + throws IOException, OpenSearchException { + return this.transport.performRequest(ListAllPointInTimeRequest._INSTANCE, ListAllPointInTimeRequest._ENDPOINT, this.transportOptions); + } + // ----- Endpoint: mget /** diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/cat/OpenSearchCatAsyncClient.java b/java-client/src/main/java/org/opensearch/client/opensearch/cat/OpenSearchCatAsyncClient.java index 98af262630..b01f021951 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/cat/OpenSearchCatAsyncClient.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/cat/OpenSearchCatAsyncClient.java @@ -426,6 +426,20 @@ public CompletableFuture nodes() throws IOException, OpenSearchEx this.transportOptions); } + // ----- Endpoint: cat.point_in_time_segments + + /** + * Provides low-level information about the disk utilization of a PIT by + * describing its Lucene segments. + * + * + */ + public CompletableFuture pointInTimeSegments() throws IOException, OpenSearchException { + return this.transport.performRequestAsync(new PointInTimeSegmentsRequest.Builder().build(), + PointInTimeSegmentsRequest._ENDPOINT, + this.transportOptions); + } + // ----- Endpoint: cat.pending_tasks /** diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/cat/OpenSearchCatClient.java b/java-client/src/main/java/org/opensearch/client/opensearch/cat/OpenSearchCatClient.java index d714f411b1..58058c1cdc 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/cat/OpenSearchCatClient.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/cat/OpenSearchCatClient.java @@ -414,6 +414,47 @@ public NodesResponse nodes() throws IOException, OpenSearchException { this.transportOptions); } + // ----- Endpoint: cat.point_in_time_segments + + /** + * Provides low-level information about the disk utilization of a PIT by + * describing its Lucene segments. + * + * + */ + public SegmentsResponse pointInTimeSegments(PointInTimeSegmentsRequest request) + throws IOException, OpenSearchException { + @SuppressWarnings("unchecked") + JsonEndpoint endpoint = (JsonEndpoint) PointInTimeSegmentsRequest._ENDPOINT; + + return this.transport.performRequest(request, endpoint, this.transportOptions); + } + + /** + * Provides low-level information about the disk utilization of a PIT by + * describing its Lucene segments. + * + * * @param fn + * a function that initializes a builder to create the + * {@link PointInTimeSegmentsRequest} + */ + + public final SegmentsResponse pointInTimeSegments(Function> fn) + throws IOException, OpenSearchException { + return pointInTimeSegments(fn.apply(new PointInTimeSegmentsRequest.Builder()).build()); + } + + /** + * Provides low-level information about the disk utilization of a PIT by + * describing its Lucene segments. + * + */ + public SegmentsResponse pointInTimeSegments() throws IOException, OpenSearchException { + return this.transport.performRequest(new PointInTimeSegmentsRequest.Builder().build(), + PointInTimeSegmentsRequest._ENDPOINT, + this.transportOptions); + } + // ----- Endpoint: cat.pending_tasks /** diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/cat/PointInTimeSegmentsRequest.java b/java-client/src/main/java/org/opensearch/client/opensearch/cat/PointInTimeSegmentsRequest.java new file mode 100644 index 0000000000..f8cc89e49a --- /dev/null +++ b/java-client/src/main/java/org/opensearch/client/opensearch/cat/PointInTimeSegmentsRequest.java @@ -0,0 +1,109 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.client.opensearch.cat; + +import java.util.List; +import java.util.function.Function; + +import javax.annotation.Nullable; + +import org.opensearch.client.opensearch._types.ErrorResponse; +import org.opensearch.client.transport.Endpoint; +import org.opensearch.client.transport.endpoints.SimpleEndpoint; +import org.opensearch.client.util.ObjectBuilder; + +// typedef: cat.point_in_time_segments.Request + +/** + * Provides low-level information about the disk utilization of a PIT by + * describing its Lucene segments + * + */ +public class PointInTimeSegmentsRequest extends CatRequestBase { + + @Nullable + private List pitId; + + public PointInTimeSegmentsRequest(Builder builder) { + this.pitId = builder.pitId; + } + + public static PointInTimeSegmentsRequest of(Function> fn) { + return fn.apply(new Builder()).build(); + } + + /** + * A list of Pit IDs to get segments + *

+ * API name - {@code pit_id} + */ + @Nullable + public final List pitId() { + return this.pitId; + } + + /** + * Builder for {@link PointInTimeSegmentsRequest} + */ + public static class Builder extends CatRequestBaseBuilder { + private List pitId; + + /** + * A list of Pit IDs to get segments + *

+ * API name - {@code pit_id} + */ + public final Builder pitId(@Nullable List pitId) { + this.pitId = pitId; + return this; + } + + /** + * Builds a {@link PointInTimeSegmentsRequest}. + * + * @throws NullPointerException if some of the required fields are null. + */ + public PointInTimeSegmentsRequest build() { + _checkSingleUse(); + return new PointInTimeSegmentsRequest(this); + } + + @Override + protected Builder self() { + return this; + } + } + + /** + * Endpoint "{@code point_in_time_segments}" + */ + public static final Endpoint _ENDPOINT = new SimpleEndpoint<>( + // Request Method + request -> { + return "GET"; + }, + + // Request Path + request -> { + final int _all = 1 << 0; + + int propsSet = 0; + + if (request.pitId() == null) { + propsSet |= _all; + } + if (propsSet == 0) { + return "/_cat/pit_segments"; + } else { + return "/_cat/pit_segments/_all"; + } + }, + SimpleEndpoint.emptyMap(), SimpleEndpoint.emptyMap(), false, SegmentsResponse._DESERIALIZER); + +} diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/core/SearchRequest.java b/java-client/src/main/java/org/opensearch/client/opensearch/core/SearchRequest.java index f7822edd3a..3e3bbff660 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/core/SearchRequest.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/core/SearchRequest.java @@ -51,6 +51,7 @@ import org.opensearch.client.opensearch._types.query_dsl.Query; import org.opensearch.client.opensearch.core.search.FieldCollapse; import org.opensearch.client.opensearch.core.search.Highlight; +import org.opensearch.client.opensearch.core.search.PointInTime; import org.opensearch.client.opensearch.core.search.Rescore; import org.opensearch.client.opensearch.core.search.SourceConfig; import org.opensearch.client.opensearch.core.search.Suggester; @@ -152,6 +153,9 @@ public class SearchRequest extends RequestBase implements JsonpSerializable { @Nullable private final Double minScore; + @Nullable + private final PointInTime pit; + @Nullable private final Query postFilter; @@ -252,6 +256,7 @@ private SearchRequest(Builder builder) { this.maxConcurrentShardRequests = builder.maxConcurrentShardRequests; this.minCompatibleShardNode = builder.minCompatibleShardNode; this.minScore = builder.minScore; + this.pit = builder.pit; this.postFilter = builder.postFilter; this.preFilterShardSize = builder.preFilterShardSize; this.preference = builder.preference; @@ -547,6 +552,14 @@ public final Double minScore() { return this.minScore; } + /** + * API name: {@code pit} + */ + @Nullable + public final PointInTime pit() { + return this.pit; + } + /** * API name: {@code post_filter} */ @@ -902,6 +915,12 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { generator.write(this.minScore); } + + if (this.pit != null) { + generator.writeKey("pit"); + this.pit.serialize(generator, mapper); + } + if (this.postFilter != null) { generator.writeKey("post_filter"); this.postFilter.serialize(generator, mapper); @@ -1119,6 +1138,9 @@ public static class Builder extends ObjectBuilderBase implements ObjectBuilder targetIndexes; + + private Time keepAlive; + + @Nullable + private String preference; + + @Nullable + private String routing; + + @Nullable + private List expandWildcards; + + @Nullable + private Boolean allowPartialPitCreation; + + private CreatePointInTimeRequest(Builder builder) { + this.targetIndexes = ApiTypeHelper.unmodifiableRequired(builder.targetIndexes, this, "targetIndexes"); + this.keepAlive = ApiTypeHelper.requireNonNull(builder.keepAlive, this, "keepAlive"); + this.preference = builder.preference; + this.routing = builder.routing; + this.expandWildcards = ApiTypeHelper.unmodifiable(builder.expandWildcards); + this.allowPartialPitCreation = builder.allowPartialPitCreation; + } + + public static CreatePointInTimeRequest of(Function> fn) { + return fn.apply(new Builder()).build(); + } + + /** + * Required - The name(s) of the target index(es) for the PIT. + * May contain a comma-separated list or a wildcard index pattern. + *

+ * API name: {@code target_indexes} + */ + public final List targetIndexes() { + return this.targetIndexes; + } + + /** + * Required - The amount of time to keep the PIT. Every time you access a PIT by + * using the + * Search API, the PIT lifetime is extended by the amount of time equal to the + * keep_alive parameter. + *

+ * API name: {@code keep_alive} + */ + public final Time keepAlive() { + return this.keepAlive; + } + + /** + * The node or the shard used to perform the search. Optional. Default is + * random. + *

+ * API name: {@code preference} + */ + @Nullable + public final String preference() { + return this.preference; + } + + /** + * Specifies to route search requests to a specific shard. Optional. Default is + * the document’s _id. + *

+ * API name: {@code routing} + */ + @Nullable + public final String routing() { + return this.routing; + } + + /** + * The type of index that can match the wildcard pattern. Supports + * comma-separated values. Valid values are the following: + * - all: Match any index or data stream, including hidden ones. + * - open: Match open, non-hidden indexes or non-hidden data streams. + * - closed: Match closed, non-hidden indexes or non-hidden data streams. + * - hidden: Match hidden indexes or data streams. Must be combined with open, + * closed or both open and closed. + * - none: No wildcard patterns are accepted. + * Optional. Default is open. + *

+ * API name: {@code expand_wildcards} + */ + @Nullable + public final List expandWildcards() { + return this.expandWildcards; + } + + /** + * Specifies whether to create a PIT with partial failures. Optional. Default is + * true. + *

+ * API name: {@code allow_partial_pit_creation} + */ + @Nullable + public final Boolean allowPartialPitCreation() { + return this.allowPartialPitCreation; + } + + /** + * Builder for {@link CreatePointInTimeRequest} + */ + public static class Builder extends ObjectBuilderBase implements ObjectBuilder { + private List targetIndexes; + + private Time keepAlive; + + @Nullable + private String preference; + + @Nullable + private String routing; + + @Nullable + private List expandWildcards; + + @Nullable + private Boolean allowPartialPitCreation; + + /** + * Required - The name(s) of the target index(es) for the PIT. + * May contain a comma-separated list or a wildcard index pattern. + *

+ * API name: {@code target_indexes} + *

+ * Adds all elements of list to targetIndexes. + */ + public final Builder targetIndexes(List list) { + this.targetIndexes = _listAddAll(this.targetIndexes, list); + return this; + } + + /** + * Required - The name(s) of the target index(es) for the PIT. + * May contain a comma-separated list or a wildcard index pattern. + *

+ * API name: {@code target_indexes} + *

+ * Adds one or more values to targetIndexes. + */ + public final Builder targetIndexes(String value, String... values) { + this.targetIndexes = _listAdd(this.targetIndexes, value, values); + return this; + } + + /** + * Required - The amount of time to keep the PIT. Every time you access a PIT by + * using the + * Search API, the PIT lifetime is extended by the amount of time equal to the + * keep_alive parameter. + *

+ * API name: {@code keep_alive} + */ + public final Builder keepAlive(Time keepAlive) { + this.keepAlive = keepAlive; + return this; + } + + /** + * Required - The amount of time to keep the PIT. Every time you access a PIT by + * using the + * Search API, the PIT lifetime is extended by the amount of time equal to the + * keep_alive parameter. + *

+ * API name: {@code keep_alive} + */ + public final Builder keepAlive(Function> fn) { + return this.keepAlive(fn.apply(new Time.Builder()).build()); + } + + /** + * The node or the shard used to perform the search. Optional. Default is + * random. + *

+ * API name: {@code preference} + */ + public final Builder preference(@Nullable String preference) { + this.preference = preference; + return this; + } + + /** + * Specifies to route search requests to a specific shard. Optional. Default is + * the document’s _id. + *

+ * API name: {@code routing} + */ + public final Builder routing(@Nullable String routing) { + this.routing = routing; + return this; + } + + /** + * The type of index that can match the wildcard pattern. Supports + * comma-separated values. Valid values are the following: + * - all: Match any index or data stream, including hidden ones. + * - open: Match open, non-hidden indexes or non-hidden data streams. + * - closed: Match closed, non-hidden indexes or non-hidden data streams. + * - hidden: Match hidden indexes or data streams. Must be combined with open, + * closed or both open and closed. + * - none: No wildcard patterns are accepted. + * Optional. Default is open. + *

+ * API name: {@code expand_wildcards} + *

+ * Adds all elements of list to expandWildcards. + */ + public final Builder expandWildcards(@Nullable List list) { + this.expandWildcards = _listAddAll(this.expandWildcards, list); + return this; + } + + /** + * The type of index that can match the wildcard pattern. Supports + * comma-separated values. Valid values are the following: + * - all: Match any index or data stream, including hidden ones. + * - open: Match open, non-hidden indexes or non-hidden data streams. + * - closed: Match closed, non-hidden indexes or non-hidden data streams. + * - hidden: Match hidden indexes or data streams. Must be combined with open, + * closed or both open and closed. + * - none: No wildcard patterns are accepted. + * Optional. Default is open. + *

+ * API name: {@code expand_wildcards} + *

+ * Adds one or more values to expandWildcards. + */ + public final Builder expandWildcards(ExpandWildcard value, ExpandWildcard... values) { + this.expandWildcards = _listAdd(this.expandWildcards, value, values); + return this; + } + + /** + * Specifies whether to create a PIT with partial failures. Optional. Default is + * true. + *

+ * API name: {@code allow_partial_pit_creation} + */ + public final Builder allowPartialPitCreation(@Nullable Boolean allowPartialPitCreation) { + this.allowPartialPitCreation = allowPartialPitCreation; + return this; + } + + /** + * Builds a {@link CreatePointInTimeRequest}. + * + * @throws NullPointerException if some of the required fields are null. + */ + public CreatePointInTimeRequest build() { + _checkSingleUse(); + return new CreatePointInTimeRequest(this); + } + } + + /** + * Endpoint "{@code create_point_in_time}" + */ + public static final Endpoint _ENDPOINT = new SimpleEndpoint<>( + // Request method + request -> { + return "POST"; + }, + + // Request Path + request -> { + + final int _targetIndexes = 1 << 0; + + int propsSet = 0; + + propsSet |= _targetIndexes; + + if (propsSet == (_targetIndexes)) { + StringBuilder buf = new StringBuilder(); + buf.append("/"); + SimpleEndpoint.pathEncode( + request.targetIndexes.stream().map(v -> v).collect(Collectors.joining(",")), buf); + buf.append("/_search/point_in_time"); + return buf.toString(); + } + throw SimpleEndpoint.noPathTemplateFound("path"); + }, request -> { + Map params = new HashMap<>(); + params.put("keep_alive", request.keepAlive._toJsonString()); + + if (request.preference != null) { + params.put("preference", request.preference); + } + if (request.routing != null) { + params.put("routing", request.routing); + } + if (ApiTypeHelper.isDefined(request.expandWildcards)) { + params.put("expand_wildcards", + request.expandWildcards.stream() + .map(v -> v.jsonValue()).collect(Collectors.joining(","))); + } + if (request.allowPartialPitCreation != null) { + params.put("allow_partial_pit_creation", String.valueOf(request.allowPartialPitCreation)); + } + return params; + }, SimpleEndpoint.emptyMap(), false, CreatePointInTimeResponse._DESERIALIZER); +} diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/core/point_in_time/CreatePointInTimeResponse.java b/java-client/src/main/java/org/opensearch/client/opensearch/core/point_in_time/CreatePointInTimeResponse.java new file mode 100644 index 0000000000..3d87230aef --- /dev/null +++ b/java-client/src/main/java/org/opensearch/client/opensearch/core/point_in_time/CreatePointInTimeResponse.java @@ -0,0 +1,158 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.client.opensearch.core.point_in_time; + +import java.util.function.Function; + +import org.opensearch.client.json.JsonpDeserializable; +import org.opensearch.client.json.JsonpDeserializer; +import org.opensearch.client.json.JsonpMapper; +import org.opensearch.client.json.JsonpSerializable; +import org.opensearch.client.json.ObjectBuilderDeserializer; +import org.opensearch.client.json.ObjectDeserializer; +import org.opensearch.client.opensearch._types.ShardStatistics; +import org.opensearch.client.util.ApiTypeHelper; +import org.opensearch.client.util.ObjectBuilder; +import org.opensearch.client.util.ObjectBuilderBase; + +import jakarta.json.stream.JsonGenerator; + +// typedef: _global.create_point_in_time.Response + +@JsonpDeserializable +public class CreatePointInTimeResponse implements JsonpSerializable { + + private final String pitId; + + private final ShardStatistics shards; + + private final Long creationTime; + + private CreatePointInTimeResponse(Builder builder) { + this.pitId = ApiTypeHelper.requireNonNull(builder.pitId, this, "pitId"); + this.shards = ApiTypeHelper.requireNonNull(builder.shards, this, "shards"); + this.creationTime = ApiTypeHelper.requireNonNull(builder.creationTime, this, "creationTime"); + } + + public static CreatePointInTimeResponse of(Function> fn) { + return fn.apply(new Builder()).build(); + } + + /** + * Required - API name: {@code pit_d} + */ + public final String pitId() { + return this.pitId; + } + + /** + * Required - API name: {@code _shards} + */ + public final ShardStatistics shards() { + return this.shards; + } + + /** + * Required - API name: {@code creation_time} + */ + public final Long creationTime() { + return this.creationTime; + } + + /** + * Serialize this object to JSON. + */ + public void serialize(JsonGenerator generator, JsonpMapper mapper) { + generator.writeStartObject(); + serializeInternal(generator, mapper); + generator.writeEnd(); + } + + protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { + + generator.writeKey("pit_id"); + generator.write(this.pitId); + + generator.writeKey("_shards"); + this.shards.serialize(generator, mapper); + + generator.writeKey("creation_time"); + generator.write(this.creationTime); + + } + + /** + * builder for {@link CreatePointInTimeResponse} + */ + public static class Builder extends ObjectBuilderBase implements ObjectBuilder { + private String pitId; + + private ShardStatistics shards; + + private Long creationTime; + + /** + * Required - API name: {@code pit_id} + */ + public final Builder pitId(String pitId) { + this.pitId = pitId; + return this; + } + + /** + * Required - API name: {@code _shards} + */ + public final Builder shards(ShardStatistics value) { + this.shards = value; + return this; + } + + /** + * Required - API name: {@code _shards} + */ + public final Builder shards(Function> fn) { + return this.shards(fn.apply(new ShardStatistics.Builder()).build()); + } + + /** + * Required - API name: {@code creation_time} + */ + public final Builder creationTime(Long creationTime) { + this.creationTime = creationTime; + return this; + } + + /** + * Builds a {@link CreatePointInTimeResponse}. + * + * @throws NullPointerException if some of the required fields are null. + */ + public CreatePointInTimeResponse build() { + _checkSingleUse(); + + return new CreatePointInTimeResponse(this); + } + } + + /** + * Json deserializer for {@link CreatePointInTimeResponse} + */ + public static final JsonpDeserializer _DESERIALIZER = ObjectBuilderDeserializer + .lazy(Builder::new, CreatePointInTimeResponse::setupCreatePointInTimeResponseDeserializer); + + protected static void setupCreatePointInTimeResponseDeserializer(ObjectDeserializer op) { + + op.add(Builder::pitId, JsonpDeserializer.stringDeserializer(), "pit_id"); + op.add(Builder::shards, + ShardStatistics._DESERIALIZER, + "_shards"); + op.add(Builder::creationTime, JsonpDeserializer.longDeserializer(), "creation_time"); + + } +} \ No newline at end of file diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/core/point_in_time/DeletePointInTimeRecord.java b/java-client/src/main/java/org/opensearch/client/opensearch/core/point_in_time/DeletePointInTimeRecord.java new file mode 100644 index 0000000000..f3dae86e9d --- /dev/null +++ b/java-client/src/main/java/org/opensearch/client/opensearch/core/point_in_time/DeletePointInTimeRecord.java @@ -0,0 +1,128 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.client.opensearch.core.point_in_time; + +import java.util.function.Function; + +import org.opensearch.client.json.JsonpDeserializable; +import org.opensearch.client.json.JsonpDeserializer; +import org.opensearch.client.json.JsonpMapper; +import org.opensearch.client.json.JsonpSerializable; +import org.opensearch.client.json.ObjectBuilderDeserializer; +import org.opensearch.client.json.ObjectDeserializer; +import org.opensearch.client.util.ObjectBuilder; +import org.opensearch.client.util.ObjectBuilderBase; + +import jakarta.json.stream.JsonGenerator; + +// typedef: _global.point_in_time.DeleteDeletePointInTimeRecord +@JsonpDeserializable +public class DeletePointInTimeRecord implements JsonpSerializable { + + private final String pitId; + + private final Boolean successful; + + private DeletePointInTimeRecord(Builder builder) { + this.pitId = builder.pitId; + this.successful = builder.successful; + } + + public static DeletePointInTimeRecord of(Function> fn) { + return fn.apply(new Builder()).build(); + } + + /** + * API name: {@code pit_id} + */ + public final String pitId() { + return this.pitId; + } + + /** + * API name: {@code successful} + */ + public final Boolean successful() { + return this.successful; + } + + /** + * Serialize this object to JSON. + */ + public void serialize(JsonGenerator generator, JsonpMapper mapper) { + generator.writeStartObject(); + serializeInternal(generator, mapper); + generator.writeEnd(); + } + + protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { + + if (this.pitId != null) { + generator.writeKey("pit_id"); + generator.write(this.pitId); + + } + if (this.successful != null) { + generator.writeKey("successful"); + generator.write(this.successful); + + } + } + + /** + * Builder for {@link DeletePointInTimeRecord}. + */ + public static class Builder extends ObjectBuilderBase implements ObjectBuilder { + private String pitId; + + private Boolean successful; + + /** + * API name: {@code pit_id} + */ + public final Builder pitId(String pitId) { + this.pitId = pitId; + return this; + } + + /** + * API name: {@code successful} + */ + public final Builder successful(Boolean successful) { + this.successful = successful; + return this; + } + + /** + * Builds a {@link DeletePointInTimeRecord}. + * + * @throws NullPointerException if some of the required fields are null. + */ + public DeletePointInTimeRecord build() { + _checkSingleUse(); + + return new DeletePointInTimeRecord(this); + } + } + + /** + * Json deserializer for {@link DeletePointInTimeRecord} + */ + public static final JsonpDeserializer _DESERIALIZER = ObjectBuilderDeserializer.lazy( + Builder::new, + DeletePointInTimeRecord::setupDeletePointInTimeRecordDeserializer); + + protected static void setupDeletePointInTimeRecordDeserializer( + ObjectDeserializer op) { + + op.add(Builder::pitId, JsonpDeserializer.stringDeserializer(), "pit_id"); + op.add(Builder::successful, JsonpDeserializer.booleanDeserializer(), "successful"); + + } +} diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/core/point_in_time/DeletePointInTimeRequest.java b/java-client/src/main/java/org/opensearch/client/opensearch/core/point_in_time/DeletePointInTimeRequest.java new file mode 100644 index 0000000000..2cff2f172b --- /dev/null +++ b/java-client/src/main/java/org/opensearch/client/opensearch/core/point_in_time/DeletePointInTimeRequest.java @@ -0,0 +1,135 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.client.opensearch.core.point_in_time; + +import java.util.List; +import java.util.function.Function; + +import javax.annotation.Nullable; + +import org.opensearch.client.json.JsonpDeserializable; +import org.opensearch.client.json.JsonpMapper; +import org.opensearch.client.json.JsonpSerializable; +import org.opensearch.client.opensearch._types.ErrorResponse; +import org.opensearch.client.opensearch._types.RequestBase; +import org.opensearch.client.transport.Endpoint; +import org.opensearch.client.transport.endpoints.SimpleEndpoint; +import org.opensearch.client.util.ApiTypeHelper; +import org.opensearch.client.util.ObjectBuilder; +import org.opensearch.client.util.ObjectBuilderBase; + +import jakarta.json.stream.JsonGenerator; + +// typedef: _global.delete_point_in_time.Request + +/** + * Deletes PITs on the OpenSearch cluster + * + */ +@JsonpDeserializable +public class DeletePointInTimeRequest extends RequestBase implements JsonpSerializable { + + @Nullable + private List pitId; + + public DeletePointInTimeRequest(Builder builder) { + this.pitId = builder.pitId; + } + + public static DeletePointInTimeRequest of(Function> fn) { + return fn.apply(new Builder()).build(); + } + + /** + * A list of Pit IDs to be deleted + *

+ * API name - {@code pit_id} + */ + @Nullable + public final List pitId() { + return this.pitId; + } + + /** + * Serialize this object to JSON. + */ + public void serialize(JsonGenerator generator, JsonpMapper mapper) { + generator.writeStartObject(); + serializeInternal(generator, mapper); + generator.writeEnd(); + } + + protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { + + if (ApiTypeHelper.isDefined(this.pitId)) { + generator.writeKey("pit_id"); + generator.writeStartArray(); + for (String item0 : this.pitId) { + generator.write(item0); + } + generator.writeEnd(); + + } + + } + + /** + * Builder for {@link DeletePointInTimeRequest} + */ + public static class Builder extends ObjectBuilderBase implements ObjectBuilder { + private List pitId; + + /** + * A list of Pit IDs to be deleted + *

+ * API name - {@code pit_id} + */ + public final Builder pitId(@Nullable List pitId) { + this.pitId = pitId; + return this; + } + + /** + * Builds a {@link DeletePointInTimeRequest}. + * + * @throws NullPointerException if some of the required fields are null. + */ + public DeletePointInTimeRequest build() { + _checkSingleUse(); + return new DeletePointInTimeRequest(this); + } + } + + /** + * Endpoint "{@code delete_point_in_time}" + */ + public static final Endpoint _ENDPOINT = new SimpleEndpoint<>( + // Request Method + request -> { + return "DELETE"; + }, + + // Request Path + request -> { + final int _all = 1 << 0; + + int propsSet = 0; + + if (request.pitId() == null) { + propsSet |= _all; + } + if (propsSet == 0) { + return "/_search/point_in_time"; + } else { + return "/_search/point_in_time/_all"; + } + }, + SimpleEndpoint.emptyMap(), SimpleEndpoint.emptyMap(), true, DeletePointInTimeResponse._DESERIALIZER); + +} diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/core/point_in_time/DeletePointInTimeResponse.java b/java-client/src/main/java/org/opensearch/client/opensearch/core/point_in_time/DeletePointInTimeResponse.java new file mode 100644 index 0000000000..8aeea37030 --- /dev/null +++ b/java-client/src/main/java/org/opensearch/client/opensearch/core/point_in_time/DeletePointInTimeResponse.java @@ -0,0 +1,125 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.client.opensearch.core.point_in_time; + +import java.util.List; +import java.util.function.Function; + +import org.opensearch.client.json.JsonpDeserializable; +import org.opensearch.client.json.JsonpDeserializer; +import org.opensearch.client.json.JsonpMapper; +import org.opensearch.client.json.JsonpSerializable; +import org.opensearch.client.json.ObjectBuilderDeserializer; +import org.opensearch.client.json.ObjectDeserializer; +import org.opensearch.client.util.ApiTypeHelper; +import org.opensearch.client.util.ObjectBuilder; +import org.opensearch.client.util.ObjectBuilderBase; + +import jakarta.json.stream.JsonGenerator; + +@JsonpDeserializable +public class DeletePointInTimeResponse implements JsonpSerializable { + private final List pits; + + private DeletePointInTimeResponse(Builder builder) { + this.pits = ApiTypeHelper.unmodifiableRequired(builder.pits, this, "pits"); + } + + public static DeletePointInTimeResponse of(Function> fn) { + return fn.apply(new Builder()).build(); + } + + /** + * Required - Response value. + *

+ * API name: {@code pits} + */ + public final List pits() { + return this.pits; + } + + /** + * Serialize this value to JSON. + */ + public void serialize(JsonGenerator generator, JsonpMapper mapper) { + generator.writeStartArray(); + for (DeletePointInTimeRecord item0 : this.pits) { + item0.serialize(generator, mapper); + + } + generator.writeEnd(); + + } + + /** + * Builder for {@link DeletePointInTimeResponse}. + */ + + public static class Builder extends ObjectBuilderBase implements ObjectBuilder { + private List pits; + + /** + * Required - Response value. + *

+ * API name: {@code pits} + *

+ * Adds all elements of list to pits. + */ + public final Builder pits(List list) { + this.pits = _listAddAll(this.pits, list); + return this; + } + + /** + * Required - Response value. + *

+ * API name: {@code pits} + *

+ * Adds one or more values to pits. + */ + public final Builder pits(DeletePointInTimeRecord value, DeletePointInTimeRecord... values) { + this.pits = _listAdd(this.pits, value, values); + return this; + } + + /** + * Required - Response value. + *

+ * API name: {@code pits} + *

+ * Adds a value to pits using a builder lambda. + */ + public final Builder pits(Function> fn) { + return pits(fn.apply(new DeletePointInTimeRecord.Builder()).build()); + } + + /** + * Builds a {@link DeletePointInTimeResponse}. + * + * @throws NullPointerException if some of the required fields are null. + */ + public DeletePointInTimeResponse build() { + _checkSingleUse(); + + return new DeletePointInTimeResponse(this); + } + } + + public static final JsonpDeserializer _DESERIALIZER = ObjectBuilderDeserializer + .lazy(Builder::new, DeletePointInTimeResponse::createDeletePointInTimeResponseDeserializer); + + protected static void createDeletePointInTimeResponseDeserializer( + ObjectDeserializer op) { + + JsonpDeserializer> valueDeserializer = JsonpDeserializer + .arrayDeserializer(DeletePointInTimeRecord._DESERIALIZER); + + op.add(Builder::pits, valueDeserializer, "pits"); + } +} diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/core/point_in_time/ListAllPointInTimeRequest.java b/java-client/src/main/java/org/opensearch/client/opensearch/core/point_in_time/ListAllPointInTimeRequest.java new file mode 100644 index 0000000000..9fbcd90581 --- /dev/null +++ b/java-client/src/main/java/org/opensearch/client/opensearch/core/point_in_time/ListAllPointInTimeRequest.java @@ -0,0 +1,44 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.client.opensearch.core.point_in_time; + +import org.opensearch.client.opensearch._types.ErrorResponse; +import org.opensearch.client.transport.Endpoint; +import org.opensearch.client.transport.endpoints.SimpleEndpoint; + +// typedef: _global.list_all_point_in_time.Request + +/** + * Lists all PITs on the OpenSearch cluster + * + */ +public class ListAllPointInTimeRequest { + public ListAllPointInTimeRequest() { + + } + + /** + * Singleton instance for {@link ListAllPointInTimeRequest}. + */ + public static final ListAllPointInTimeRequest _INSTANCE = new ListAllPointInTimeRequest(); + + /** + * Endpoint "{@code list_all_point_in_time}" + */ + public static final Endpoint _ENDPOINT = new SimpleEndpoint<>( + // Request method + request -> { + return "GET"; + }, + + // Request Path + request -> { + return "/_search/point_in_time/_all"; + }, SimpleEndpoint.emptyMap(), SimpleEndpoint.emptyMap(), false, ListAllPointInTimeResponse._DESERIALIZER); +} diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/core/point_in_time/ListAllPointInTimeResponse.java b/java-client/src/main/java/org/opensearch/client/opensearch/core/point_in_time/ListAllPointInTimeResponse.java new file mode 100644 index 0000000000..447b97a52b --- /dev/null +++ b/java-client/src/main/java/org/opensearch/client/opensearch/core/point_in_time/ListAllPointInTimeResponse.java @@ -0,0 +1,125 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.client.opensearch.core.point_in_time; + +import java.util.List; +import java.util.function.Function; + +import org.opensearch.client.json.JsonpDeserializable; +import org.opensearch.client.json.JsonpDeserializer; +import org.opensearch.client.json.JsonpMapper; +import org.opensearch.client.json.JsonpSerializable; +import org.opensearch.client.json.ObjectBuilderDeserializer; +import org.opensearch.client.json.ObjectDeserializer; +import org.opensearch.client.util.ApiTypeHelper; +import org.opensearch.client.util.ObjectBuilder; +import org.opensearch.client.util.ObjectBuilderBase; + +import jakarta.json.stream.JsonGenerator; + +@JsonpDeserializable +public class ListAllPointInTimeResponse implements JsonpSerializable { + private final List pits; + + private ListAllPointInTimeResponse(Builder builder) { + this.pits = ApiTypeHelper.unmodifiableRequired(builder.pits, this, "pits"); + } + + public static ListAllPointInTimeResponse of(Function> fn) { + return fn.apply(new Builder()).build(); + } + + /** + * Required - Response value. + *

+ * API name: {@code _value_body} + */ + public final List pits() { + return this.pits; + } + + /** + * Serialize this value to JSON. + */ + public void serialize(JsonGenerator generator, JsonpMapper mapper) { + generator.writeStartArray(); + for (PointInTimeRecord item0 : this.pits) { + item0.serialize(generator, mapper); + + } + generator.writeEnd(); + + } + + /** + * Builder for {@link ListAllPointInTimeResponse}. + */ + + public static class Builder extends ObjectBuilderBase implements ObjectBuilder { + private List pits; + + /** + * Required - Response value. + *

+ * API name: {@code _value_body} + *

+ * Adds all elements of list to pits. + */ + public final Builder pits(List list) { + this.pits = _listAddAll(this.pits, list); + return this; + } + + /** + * Required - Response value. + *

+ * API name: {@code _value_body} + *

+ * Adds one or more values to pits. + */ + public final Builder pits(PointInTimeRecord value, PointInTimeRecord... values) { + this.pits = _listAdd(this.pits, value, values); + return this; + } + + /** + * Required - Response value. + *

+ * API name: {@code _value_body} + *

+ * Adds a value to pits using a builder lambda. + */ + public final Builder pits(Function> fn) { + return pits(fn.apply(new PointInTimeRecord.Builder()).build()); + } + + /** + * Builds a {@link ListAllPointInTimeResponse}. + * + * @throws NullPointerException if some of the required fields are null. + */ + public ListAllPointInTimeResponse build() { + _checkSingleUse(); + + return new ListAllPointInTimeResponse(this); + } + } + + public static final JsonpDeserializer _DESERIALIZER = ObjectBuilderDeserializer + .lazy(Builder::new, ListAllPointInTimeResponse::createListAllPointInTimeResponseDeserializer); + + protected static void createListAllPointInTimeResponseDeserializer( + ObjectDeserializer op) { + + JsonpDeserializer> valueDeserializer = JsonpDeserializer + .arrayDeserializer(PointInTimeRecord._DESERIALIZER); + + op.add(Builder::pits, valueDeserializer, "pits"); + } +} diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/core/point_in_time/PointInTimeRecord.java b/java-client/src/main/java/org/opensearch/client/opensearch/core/point_in_time/PointInTimeRecord.java new file mode 100644 index 0000000000..11ff780350 --- /dev/null +++ b/java-client/src/main/java/org/opensearch/client/opensearch/core/point_in_time/PointInTimeRecord.java @@ -0,0 +1,154 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.client.opensearch.core.point_in_time; + +import java.util.function.Function; + +import org.opensearch.client.json.JsonpDeserializable; +import org.opensearch.client.json.JsonpDeserializer; +import org.opensearch.client.json.JsonpMapper; +import org.opensearch.client.json.JsonpSerializable; +import org.opensearch.client.json.ObjectBuilderDeserializer; +import org.opensearch.client.json.ObjectDeserializer; +import org.opensearch.client.util.ObjectBuilder; +import org.opensearch.client.util.ObjectBuilderBase; + +import jakarta.json.stream.JsonGenerator; + +// typedef: _global.point_in_time.PointInTimeRecord +@JsonpDeserializable +public class PointInTimeRecord implements JsonpSerializable { + + private final String pitId; + + private final Long creationTime; + + private final Long keepAlive; + + private PointInTimeRecord(Builder builder) { + this.pitId = builder.pitId; + this.creationTime = builder.creationTime; + this.keepAlive = builder.keepAlive; + } + + public static PointInTimeRecord of(Function> fn) { + return fn.apply(new Builder()).build(); + } + + /** + * API name: {@code pit_id} + */ + public final String pitId() { + return this.pitId; + } + + /** + * API name: {@code creation_time} + */ + public final Long creationTime() { + return this.creationTime; + } + + /** + * API name: {@code keep_alive} + */ + public final Long keepAlive() { + return this.keepAlive; + } + + /** + * Serialize this object to JSON. + */ + public void serialize(JsonGenerator generator, JsonpMapper mapper) { + generator.writeStartObject(); + serializeInternal(generator, mapper); + generator.writeEnd(); + } + + protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { + + if (this.pitId != null) { + generator.writeKey("pit_id"); + generator.write(this.pitId); + + } + if (this.creationTime != null) { + generator.writeKey("creation_time"); + generator.write(this.creationTime); + + } + if (this.keepAlive != null) { + generator.writeKey("keep_alive"); + generator.write(this.keepAlive); + + } + } + + /** + * Builder for {@link PointInTimeRecord}. + */ + public static class Builder extends ObjectBuilderBase implements ObjectBuilder { + private String pitId; + + private Long creationTime; + + private Long keepAlive; + + /** + * API name: {@code pit_id} + */ + public final Builder pitId(String pitId) { + this.pitId = pitId; + return this; + } + + /** + * API name: {@code creation_time} + */ + public final Builder creationTime(Long creationTime) { + this.creationTime = creationTime; + return this; + } + + /** + * API name: {@code keep_alive} + */ + public final Builder keepAlive(Long keepAlive) { + this.keepAlive = keepAlive; + return this; + } + + /** + * Builds a {@link PointInTimeRecord}. + * + * @throws NullPointerException if some of the required fields are null. + */ + public PointInTimeRecord build() { + _checkSingleUse(); + + return new PointInTimeRecord(this); + } + } + + /** + * Json deserializer for {@link PointInTimeRecord} + */ + public static final JsonpDeserializer _DESERIALIZER = ObjectBuilderDeserializer.lazy( + Builder::new, + PointInTimeRecord::setupPointInTimeRecordDeserializer); + + protected static void setupPointInTimeRecordDeserializer( + ObjectDeserializer op) { + + op.add(Builder::pitId, JsonpDeserializer.stringDeserializer(), "pit_id"); + op.add(Builder::creationTime, JsonpDeserializer.longDeserializer(), "creation_time"); + op.add(Builder::keepAlive, JsonpDeserializer.longDeserializer(), "keep_alive"); + + } +} diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/core/search/PointInTime.java b/java-client/src/main/java/org/opensearch/client/opensearch/core/search/PointInTime.java new file mode 100644 index 0000000000..f7b56731b1 --- /dev/null +++ b/java-client/src/main/java/org/opensearch/client/opensearch/core/search/PointInTime.java @@ -0,0 +1,127 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.client.opensearch.core.search; + +import java.util.function.Function; + +import javax.annotation.Nullable; + +import org.opensearch.client.json.JsonpDeserializable; +import org.opensearch.client.json.JsonpDeserializer; +import org.opensearch.client.json.JsonpMapper; +import org.opensearch.client.json.JsonpSerializable; +import org.opensearch.client.json.ObjectBuilderDeserializer; +import org.opensearch.client.json.ObjectDeserializer; +import org.opensearch.client.util.ApiTypeHelper; +import org.opensearch.client.util.ObjectBuilder; +import org.opensearch.client.util.ObjectBuilderBase; + +import jakarta.json.stream.JsonGenerator; + +@JsonpDeserializable +public class PointInTime implements JsonpSerializable { + private final String id; + + @Nullable + private final String keepAlive; + + private PointInTime(Builder builder) { + this.id = ApiTypeHelper.requireNonNull(builder.id, this, "id"); + this.keepAlive = builder.keepAlive; + } + + public static PointInTime of(Function> fn) { + return fn.apply(new Builder()).build(); + } + + /** + * Required - API name: {@code id} + */ + public final String id() { + return this.id; + } + + /** + * API name: {@code keep_alive} + */ + @Nullable + public final String keepAlive() { + return this.keepAlive; + } + + /** + * Serialize this object to JSON. + */ + public void serialize(JsonGenerator generator, JsonpMapper mapper) { + generator.writeStartObject(); + serializeInternal(generator, mapper); + generator.writeEnd(); + } + + protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { + generator.writeKey("id"); + generator.write(this.id); + + if (this.keepAlive != null) { + generator.writeKey("keep_alive"); + generator.write(this.keepAlive); + } + } + + /** + * Builder for {@link PointInTime}. + */ + public static class Builder extends ObjectBuilderBase implements ObjectBuilder { + + private String id; + + @Nullable + private String keepAlive; + + /** + * Required - API name: {@code id} + */ + public final Builder id(String id) { + this.id = id; + return this; + } + + /** + * API name: {@code keep_alive} + */ + public final Builder keepAlive(@Nullable String keepAlive) { + this.keepAlive = keepAlive; + return this; + } + + /** + * Builds a {@link PointInTime}. + * + * @throws NullPointerException if some of the required fields are null. + */ + public PointInTime build() { + _checkSingleUse(); + + return new PointInTime(this); + } + } + + /** + * Json deserializer for {@link PointInTime} + */ + public static final JsonpDeserializer _DESERIALIZER = ObjectBuilderDeserializer.lazy(Builder::new, + PointInTime::setupPointInTimeDeserializer); + + protected static void setupPointInTimeDeserializer(ObjectDeserializer op) { + + op.add(Builder::id, JsonpDeserializer.stringDeserializer(), "id"); + op.add(Builder::keepAlive, JsonpDeserializer.stringDeserializer(), "keep_alive"); + } + +} diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/integTest/AbstractCatClientIT.java b/java-client/src/test/java/org/opensearch/client/opensearch/integTest/AbstractCatClientIT.java index af9f9caeb0..26e8698a52 100644 --- a/java-client/src/test/java/org/opensearch/client/opensearch/integTest/AbstractCatClientIT.java +++ b/java-client/src/test/java/org/opensearch/client/opensearch/integTest/AbstractCatClientIT.java @@ -8,9 +8,16 @@ package org.opensearch.client.opensearch.integTest; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import org.junit.Test; import org.opensearch.client.opensearch._types.Bytes; import org.opensearch.client.opensearch._types.Refresh; import org.opensearch.client.opensearch._types.Result; +import org.opensearch.client.opensearch._types.Time; import org.opensearch.client.opensearch.cat.AliasesResponse; import org.opensearch.client.opensearch.cat.AllocationResponse; import org.opensearch.client.opensearch.cat.IndicesResponse; @@ -27,12 +34,9 @@ import org.opensearch.client.opensearch.cat.segments.SegmentsRecord; import org.opensearch.client.opensearch.cat.shards.ShardsRecord; import org.opensearch.client.opensearch.core.IndexResponse; +import org.opensearch.client.opensearch.core.point_in_time.CreatePointInTimeResponse; import org.opensearch.client.opensearch.indices.CreateIndexResponse; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - public abstract class AbstractCatClientIT extends OpenSearchJavaClientTestCase { public void testCatNodes() throws Exception { @@ -188,10 +192,10 @@ public void testCatSegments() throws Exception { createIndex("cat-segments-test-index"); final IndexResponse index = javaClient().index(b -> b - .index("test-cat-segments-index") - .id("id") - .refresh(Refresh.True) - .document(Map.of("test-cat-segments-key", "test-cat-segments-value"))); + .index("test-cat-segments-index") + .id("id") + .refresh(Refresh.True) + .document(Map.of("test-cat-segments-key", "test-cat-segments-value"))); assertTrue(index.result() == Result.Created); @@ -209,6 +213,27 @@ public void testCatSegments() throws Exception { assertNull(segmentsRecord.ip()); assertNull(segmentsRecord.prirep()); } + + @Test + public void testCatPointInTimeSegments() throws Exception { + createIndex("cat-pit-segments-test-index"); + + final IndexResponse index = javaClient().index(b -> b + .index("test-cat-pit-segments-index") + .id("id") + .refresh(Refresh.True) + .document(Map.of("test-cat-pit-segments-key", "test-cat-pit-segments-value"))); + + assertTrue(index.result() == Result.Created); + + createPIT("cat-pit-segments-test-index"); + + SegmentsResponse pointInTimeSegmentsResponse = javaClient().cat() + .pointInTimeSegments(r -> r.headers("index,shard,id,segment,size")); + + assertNotNull("pointInTimeSegmentsResponse.segments() is null", pointInTimeSegmentsResponse.valueBody()); + assertTrue("pointInTimeSegmentsResponse.segments().size() == 0", pointInTimeSegmentsResponse.valueBody().size() > 0); + } private void createIndex(String indexName) throws Exception { CreateIndexResponse createResponse = javaClient().indices().create(b -> b.index(indexName)); @@ -216,4 +241,11 @@ private void createIndex(String indexName) throws Exception { assertTrue(createResponse.shardsAcknowledged()); } + private void createPIT(String indexName) throws Exception { + CreatePointInTimeResponse createPointInTimeResponse = javaClient() + .createPointInTime(r -> r.targetIndexes(Collections.singletonList(indexName)).keepAlive(new Time.Builder().time("100m").build())); + assertNotNull(createPointInTimeResponse); + assertNotNull(createPointInTimeResponse.pitId()); + } + } diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/integTest/AbstractRequestIT.java b/java-client/src/test/java/org/opensearch/client/opensearch/integTest/AbstractRequestIT.java index 586abd49d9..5d85815ae0 100644 --- a/java-client/src/test/java/org/opensearch/client/opensearch/integTest/AbstractRequestIT.java +++ b/java-client/src/test/java/org/opensearch/client/opensearch/integTest/AbstractRequestIT.java @@ -38,6 +38,7 @@ import org.opensearch.client.opensearch._types.FieldValue; import org.opensearch.client.opensearch._types.OpenSearchException; import org.opensearch.client.opensearch._types.Refresh; +import org.opensearch.client.opensearch._types.Time; import org.opensearch.client.opensearch._types.aggregations.Aggregate; import org.opensearch.client.opensearch._types.aggregations.HistogramAggregate; import org.opensearch.client.opensearch._types.aggregations.TermsAggregation; @@ -55,6 +56,13 @@ import org.opensearch.client.opensearch.core.SearchResponse; import org.opensearch.client.opensearch.core.bulk.OperationType; import org.opensearch.client.opensearch.core.msearch.RequestItem; +import org.opensearch.client.opensearch.core.point_in_time.CreatePointInTimeRequest; +import org.opensearch.client.opensearch.core.point_in_time.CreatePointInTimeResponse; +import org.opensearch.client.opensearch.core.point_in_time.DeletePointInTimeRecord; +import org.opensearch.client.opensearch.core.point_in_time.DeletePointInTimeRequest; +import org.opensearch.client.opensearch.core.point_in_time.DeletePointInTimeResponse; +import org.opensearch.client.opensearch.core.point_in_time.ListAllPointInTimeResponse; +import org.opensearch.client.opensearch.core.point_in_time.PointInTimeRecord; import org.opensearch.client.opensearch.core.search.CompletionSuggester; import org.opensearch.client.opensearch.core.search.FieldSuggester; import org.opensearch.client.opensearch.core.search.FieldSuggesterBuilders; @@ -591,6 +599,54 @@ public void testCompletionSuggester() throws IOException { assertTrue(response.suggest().size() > 0); } + @Test + public void testPointInTime() throws IOException { + + String index = "test-point-in-time"; + + javaClient().indices().create(c -> c + .index(index)); + + AppData appData = new AppData(); + appData.setIntValue(1337); + appData.setMsg("foo"); + + javaClient().index(b -> b + .index(index) + .id("1") + .document(appData) + .refresh(Refresh.True)); + + CreatePointInTimeRequest createPointInTimeRequest = new CreatePointInTimeRequest.Builder() + .targetIndexes(Collections.singletonList(index)) + .keepAlive(new Time.Builder().time("100m").build()).build(); + + CreatePointInTimeResponse createPointInTimeResponse = javaClient() + .createPointInTime(createPointInTimeRequest); + + assertNotNull(createPointInTimeResponse); + assertNotNull(createPointInTimeResponse.pitId()); + assertEquals(createPointInTimeResponse.shards().total(), createPointInTimeResponse.shards().successful()); + + ListAllPointInTimeResponse listAllPointInTimeResponse = javaClient().listAllPointInTime(); + + assertNotNull(listAllPointInTimeResponse); + assertNotNull(listAllPointInTimeResponse.pits()); + assertEquals(listAllPointInTimeResponse.pits().get(0).pitId(), createPointInTimeResponse.pitId()); + assertEquals(listAllPointInTimeResponse.pits().get(0).keepAlive(), Long.valueOf(6000000L)); + + DeletePointInTimeRequest deletePointInTimeRequest = new DeletePointInTimeRequest.Builder() + .pitId(Collections.singletonList(createPointInTimeResponse.pitId())).build(); + + DeletePointInTimeResponse deletePointInTimeResponse = javaClient() + .deletePointInTime(deletePointInTimeRequest); + + assertNotNull(deletePointInTimeResponse); + assertNotNull(deletePointInTimeResponse.pits()); + assertEquals(deletePointInTimeResponse.pits().get(0).pitId(), createPointInTimeResponse.pitId()); + assertTrue(deletePointInTimeResponse.pits().get(0).successful()); + } + // @Test // public void testValueBodyResponse() throws Exception { // DiskUsageResponse resp = highLevelClient().indices().diskUsage(b -> b