From 088c27c3bb6c5e560c68dc8459635ef7c7468f2f Mon Sep 17 00:00:00 2001 From: Thomas Farr Date: Tue, 24 Sep 2024 15:34:49 +1200 Subject: [PATCH] Generate snapshot.clone Signed-off-by: Thomas Farr --- UPGRADING.md | 5 +- .../snapshot/CloneSnapshotRequest.java | 191 +++++++----------- .../snapshot/CloneSnapshotResponse.java | 16 +- .../OpenSearchSnapshotAsyncClientBase.java | 20 ++ .../OpenSearchSnapshotClientBase.java | 19 ++ .../OpenSearchSnapshotAsyncClient.java | 35 ---- .../snapshot/OpenSearchSnapshotClient.java | 34 ---- .../client/codegen/CodeGenerator.java | 2 +- .../client/codegen/model/RequestShape.java | 2 + 9 files changed, 125 insertions(+), 199 deletions(-) rename java-client/src/{main => generated}/java/org/opensearch/client/opensearch/snapshot/CloneSnapshotRequest.java (79%) rename java-client/src/{main => generated}/java/org/opensearch/client/opensearch/snapshot/CloneSnapshotResponse.java (87%) diff --git a/UPGRADING.md b/UPGRADING.md index 58a72fe589..4556772bea 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -48,4 +48,7 @@ After: - The `name` field, getter and builder method have been renamed to `repository`. ### CleanupRepositoryRequest property naming -- The `name` field, getter and builder method have been renamed to `repository`. \ No newline at end of file +- The `name` field, getter and builder method have been renamed to `repository`. + +### CloneSnapshotRequest timeout removal +- The `timeout` field, getter and builder method have been removed from `CloneSnapshotRequest` as it is not supported by OpenSearch. \ No newline at end of file diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/snapshot/CloneSnapshotRequest.java b/java-client/src/generated/java/org/opensearch/client/opensearch/snapshot/CloneSnapshotRequest.java similarity index 79% rename from java-client/src/main/java/org/opensearch/client/opensearch/snapshot/CloneSnapshotRequest.java rename to java-client/src/generated/java/org/opensearch/client/opensearch/snapshot/CloneSnapshotRequest.java index b6e03de864..464881269c 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/snapshot/CloneSnapshotRequest.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/snapshot/CloneSnapshotRequest.java @@ -30,12 +30,17 @@ * GitHub history for details. */ +//---------------------------------------------------- +// THIS CODE IS GENERATED. MANUAL EDITS WILL BE LOST. +//---------------------------------------------------- + package org.opensearch.client.opensearch.snapshot; import jakarta.json.stream.JsonGenerator; import java.util.HashMap; import java.util.Map; import java.util.function.Function; +import javax.annotation.Generated; import javax.annotation.Nullable; import org.opensearch.client.json.JsonpDeserializable; import org.opensearch.client.json.JsonpDeserializer; @@ -55,47 +60,53 @@ // typedef: snapshot.clone.Request /** - * Clones indices from one snapshot into another snapshot in the same - * repository. + * Clones indices from one snapshot into another snapshot in the same repository. */ @JsonpDeserializable +@Generated("org.opensearch.client.codegen.CodeGenerator") public class CloneSnapshotRequest extends RequestBase implements PlainJsonSerializable { + + @Nullable + private final Time clusterManagerTimeout; + private final String indices; @Deprecated @Nullable private final Time masterTimeout; - @Nullable - private final Time clusterManagerTimeout; - private final String repository; private final String snapshot; private final String targetSnapshot; - @Nullable - private final Time timeout; - // --------------------------------------------------------------------------------------------- private CloneSnapshotRequest(Builder builder) { - + this.clusterManagerTimeout = builder.clusterManagerTimeout; this.indices = ApiTypeHelper.requireNonNull(builder.indices, this, "indices"); this.masterTimeout = builder.masterTimeout; - this.clusterManagerTimeout = builder.clusterManagerTimeout; this.repository = ApiTypeHelper.requireNonNull(builder.repository, this, "repository"); this.snapshot = ApiTypeHelper.requireNonNull(builder.snapshot, this, "snapshot"); this.targetSnapshot = ApiTypeHelper.requireNonNull(builder.targetSnapshot, this, "targetSnapshot"); - this.timeout = builder.timeout; - } - public static CloneSnapshotRequest of(Function> fn) { + public static CloneSnapshotRequest of(Function> fn) { return fn.apply(new Builder()).build(); } + /** + * Operation timeout for connection to cluster-manager node. + *

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

+ */ + @Nullable + public final Time clusterManagerTimeout() { + return this.clusterManagerTimeout; + } + /** * Required - API name: {@code indices} */ @@ -107,26 +118,19 @@ public final String indices() { * Explicit operation timeout for connection to master node *

* API name: {@code master_timeout} + *

*/ + @Deprecated @Nullable public final Time masterTimeout() { return this.masterTimeout; } - /** - * Explicit operation timeout for connection to cluster-manager node - *

- * API name: {@code cluster_manager_timeout} - */ - @Nullable - public final Time clusterManagerTimeout() { - return this.clusterManagerTimeout; - } - /** * Required - A repository name *

* API name: {@code repository} + *

*/ public final String repository() { return this.repository; @@ -136,6 +140,7 @@ public final String repository() { * Required - The name of the snapshot to clone from *

* API name: {@code snapshot} + *

*/ public final String snapshot() { return this.snapshot; @@ -145,22 +150,16 @@ public final String snapshot() { * Required - The name of the cloned snapshot to create *

* API name: {@code target_snapshot} + *

*/ public final String targetSnapshot() { return this.targetSnapshot; } - /** - * API name: {@code timeout} - */ - @Nullable - public final Time timeout() { - return this.timeout; - } - /** * Serialize this object to JSON. */ + @Override public void serialize(JsonGenerator generator, JsonpMapper mapper) { generator.writeStartObject(); serializeInternal(generator, mapper); @@ -168,36 +167,44 @@ public void serialize(JsonGenerator generator, JsonpMapper mapper) { } protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { - generator.writeKey("indices"); generator.write(this.indices); - } - // --------------------------------------------------------------------------------------------- /** * Builder for {@link CloneSnapshotRequest}. */ - public static class Builder extends ObjectBuilderBase implements ObjectBuilder { + @Nullable + private Time clusterManagerTimeout; private String indices; - - @Deprecated @Nullable private Time masterTimeout; - - @Nullable - private Time clusterManagerTimeout; - private String repository; - private String snapshot; - private String targetSnapshot; - @Nullable - private Time timeout; + /** + * Operation timeout for connection to cluster-manager node. + *

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

+ */ + public final Builder clusterManagerTimeout(@Nullable Time value) { + this.clusterManagerTimeout = value; + return this; + } + + /** + * Operation timeout for connection to cluster-manager node. + *

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

+ */ + public final Builder clusterManagerTimeout(Function> fn) { + return clusterManagerTimeout(fn.apply(new Time.Builder()).build()); + } /** * Required - API name: {@code indices} @@ -211,6 +218,7 @@ public final Builder indices(String value) { * Explicit operation timeout for connection to master node *

* API name: {@code master_timeout} + *

*/ @Deprecated public final Builder masterTimeout(@Nullable Time value) { @@ -222,35 +230,18 @@ public final Builder masterTimeout(@Nullable Time value) { * Explicit operation timeout for connection to master node *

* API name: {@code master_timeout} + *

*/ @Deprecated public final Builder masterTimeout(Function> fn) { - return this.masterTimeout(fn.apply(new Time.Builder()).build()); - } - - /** - * Explicit operation timeout for connection to cluster-manager node - *

- * API name: {@code cluster_manager_timeout} - */ - public final Builder clusterManagerTimeout(@Nullable Time value) { - this.clusterManagerTimeout = value; - return this; - } - - /** - * Explicit operation timeout for connection to cluster-manager node - *

- * API name: {@code cluster_manager_timeout} - */ - public final Builder clusterManagerTimeout(Function> fn) { - return this.clusterManagerTimeout(fn.apply(new Time.Builder()).build()); + return masterTimeout(fn.apply(new Time.Builder()).build()); } /** * Required - A repository name *

* API name: {@code repository} + *

*/ public final Builder repository(String value) { this.repository = value; @@ -261,6 +252,7 @@ public final Builder repository(String value) { * Required - The name of the snapshot to clone from *

* API name: {@code snapshot} + *

*/ public final Builder snapshot(String value) { this.snapshot = value; @@ -271,32 +263,17 @@ public final Builder snapshot(String value) { * Required - The name of the cloned snapshot to create *

* API name: {@code target_snapshot} + *

*/ public final Builder targetSnapshot(String value) { this.targetSnapshot = value; return this; } - /** - * API name: {@code timeout} - */ - public final Builder timeout(@Nullable Time value) { - this.timeout = value; - return this; - } - - /** - * API name: {@code timeout} - */ - public final Builder timeout(Function> fn) { - return this.timeout(fn.apply(new Time.Builder()).build()); - } - /** * Builds a {@link CloneSnapshotRequest}. * - * @throws NullPointerException - * if some of the required fields are null. + * @throws NullPointerException if some of the required fields are null. */ public CloneSnapshotRequest build() { _checkSingleUse(); @@ -316,9 +293,7 @@ public CloneSnapshotRequest build() { ); protected static void setupCloneSnapshotRequestDeserializer(ObjectDeserializer op) { - op.add(Builder::indices, JsonpDeserializer.stringDeserializer(), "indices"); - } // --------------------------------------------------------------------------------------------- @@ -327,55 +302,29 @@ protected static void setupCloneSnapshotRequestDeserializer(ObjectDeserializer _ENDPOINT = new SimpleEndpoint<>( - // Request method - request -> { - return "PUT"; - - }, - + request -> "PUT", // Request path request -> { - final int _targetSnapshot = 1 << 0; - final int _repository = 1 << 1; - final int _snapshot = 1 << 2; - - int propsSet = 0; - - propsSet |= _targetSnapshot; - propsSet |= _repository; - propsSet |= _snapshot; - - if (propsSet == (_repository | _snapshot | _targetSnapshot)) { - StringBuilder buf = new StringBuilder(); - buf.append("/_snapshot"); - buf.append("/"); - SimpleEndpoint.pathEncode(request.repository, buf); - buf.append("/"); - SimpleEndpoint.pathEncode(request.snapshot, buf); - buf.append("/_clone"); - buf.append("/"); - SimpleEndpoint.pathEncode(request.targetSnapshot, buf); - return buf.toString(); - } - throw SimpleEndpoint.noPathTemplateFound("path"); - + StringBuilder buf = new StringBuilder(); + buf.append("/_snapshot/"); + SimpleEndpoint.pathEncode(request.repository, buf); + buf.append("/"); + SimpleEndpoint.pathEncode(request.snapshot, buf); + buf.append("/_clone/"); + SimpleEndpoint.pathEncode(request.targetSnapshot, buf); + return buf.toString(); }, - // Request parameters request -> { Map params = new HashMap<>(); - if (request.masterTimeout != null) { - params.put("master_timeout", request.masterTimeout._toJsonString()); - } if (request.clusterManagerTimeout != null) { params.put("cluster_manager_timeout", request.clusterManagerTimeout._toJsonString()); } - if (request.timeout != null) { - params.put("timeout", request.timeout._toJsonString()); + if (request.masterTimeout != null) { + params.put("master_timeout", request.masterTimeout._toJsonString()); } return params; - }, SimpleEndpoint.emptyMap(), true, diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/snapshot/CloneSnapshotResponse.java b/java-client/src/generated/java/org/opensearch/client/opensearch/snapshot/CloneSnapshotResponse.java similarity index 87% rename from java-client/src/main/java/org/opensearch/client/opensearch/snapshot/CloneSnapshotResponse.java rename to java-client/src/generated/java/org/opensearch/client/opensearch/snapshot/CloneSnapshotResponse.java index b41d071c45..237dc0fe9c 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/snapshot/CloneSnapshotResponse.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/snapshot/CloneSnapshotResponse.java @@ -30,9 +30,14 @@ * GitHub history for details. */ +//---------------------------------------------------- +// THIS CODE IS GENERATED. MANUAL EDITS WILL BE LOST. +//---------------------------------------------------- + package org.opensearch.client.opensearch.snapshot; import java.util.function.Function; +import javax.annotation.Generated; import org.opensearch.client.json.JsonpDeserializable; import org.opensearch.client.json.JsonpDeserializer; import org.opensearch.client.json.ObjectBuilderDeserializer; @@ -43,15 +48,16 @@ // typedef: snapshot.clone.Response @JsonpDeserializable +@Generated("org.opensearch.client.codegen.CodeGenerator") public class CloneSnapshotResponse extends AcknowledgedResponseBase { + // --------------------------------------------------------------------------------------------- private CloneSnapshotResponse(Builder builder) { super(builder); - } - public static CloneSnapshotResponse of(Function> fn) { + public static CloneSnapshotResponse of(Function> fn) { return fn.apply(new Builder()).build(); } @@ -60,7 +66,6 @@ public static CloneSnapshotResponse of(Function implements ObjectBuilder { @Override protected Builder self() { @@ -70,8 +75,7 @@ protected Builder self() { /** * Builds a {@link CloneSnapshotResponse}. * - * @throws NullPointerException - * if some of the required fields are null. + * @throws NullPointerException if some of the required fields are null. */ public CloneSnapshotResponse build() { _checkSingleUse(); @@ -92,7 +96,5 @@ public CloneSnapshotResponse build() { protected static void setupCloneSnapshotResponseDeserializer(ObjectDeserializer op) { AcknowledgedResponseBase.setupAcknowledgedResponseBaseDeserializer(op); - } - } diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/snapshot/OpenSearchSnapshotAsyncClientBase.java b/java-client/src/generated/java/org/opensearch/client/opensearch/snapshot/OpenSearchSnapshotAsyncClientBase.java index fb71989ee7..5ee841e825 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/snapshot/OpenSearchSnapshotAsyncClientBase.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/snapshot/OpenSearchSnapshotAsyncClientBase.java @@ -79,6 +79,26 @@ public final CompletableFuture cleanupRepository( return cleanupRepository(fn.apply(new CleanupRepositoryRequest.Builder()).build()); } + // ----- Endpoint: snapshot.clone + + /** + * Clones indices from one snapshot into another snapshot in the same repository. + */ + public CompletableFuture clone(CloneSnapshotRequest request) throws IOException, OpenSearchException { + return this.transport.performRequestAsync(request, CloneSnapshotRequest._ENDPOINT, this.transportOptions); + } + + /** + * Clones indices from one snapshot into another snapshot in the same repository. + * + * @param fn a function that initializes a builder to create the {@link CloneSnapshotRequest} + */ + public final CompletableFuture clone( + Function> fn + ) throws IOException, OpenSearchException { + return clone(fn.apply(new CloneSnapshotRequest.Builder()).build()); + } + // ----- Endpoint: snapshot.verify_repository /** diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/snapshot/OpenSearchSnapshotClientBase.java b/java-client/src/generated/java/org/opensearch/client/opensearch/snapshot/OpenSearchSnapshotClientBase.java index edb94f3707..27a5c47915 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/snapshot/OpenSearchSnapshotClientBase.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/snapshot/OpenSearchSnapshotClientBase.java @@ -77,6 +77,25 @@ public final CleanupRepositoryResponse cleanupRepository( return cleanupRepository(fn.apply(new CleanupRepositoryRequest.Builder()).build()); } + // ----- Endpoint: snapshot.clone + + /** + * Clones indices from one snapshot into another snapshot in the same repository. + */ + public CloneSnapshotResponse clone(CloneSnapshotRequest request) throws IOException, OpenSearchException { + return this.transport.performRequest(request, CloneSnapshotRequest._ENDPOINT, this.transportOptions); + } + + /** + * Clones indices from one snapshot into another snapshot in the same repository. + * + * @param fn a function that initializes a builder to create the {@link CloneSnapshotRequest} + */ + public final CloneSnapshotResponse clone(Function> fn) + throws IOException, OpenSearchException { + return clone(fn.apply(new CloneSnapshotRequest.Builder()).build()); + } + // ----- Endpoint: snapshot.verify_repository /** diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/snapshot/OpenSearchSnapshotAsyncClient.java b/java-client/src/main/java/org/opensearch/client/opensearch/snapshot/OpenSearchSnapshotAsyncClient.java index 1a525e8742..6e7e3997c9 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/snapshot/OpenSearchSnapshotAsyncClient.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/snapshot/OpenSearchSnapshotAsyncClient.java @@ -61,41 +61,6 @@ public OpenSearchSnapshotAsyncClient withTransportOptions(@Nullable TransportOpt return new OpenSearchSnapshotAsyncClient(this.transport, transportOptions); } - // ----- Endpoint: snapshot.clone - - /** - * Clones indices from one snapshot into another snapshot in the same - * repository. - * - * - */ - - public CompletableFuture clone(CloneSnapshotRequest request) throws IOException, OpenSearchException { - @SuppressWarnings("unchecked") - JsonEndpoint endpoint = (JsonEndpoint< - CloneSnapshotRequest, - CloneSnapshotResponse, - ErrorResponse>) CloneSnapshotRequest._ENDPOINT; - - return this.transport.performRequestAsync(request, endpoint, this.transportOptions); - } - - /** - * Clones indices from one snapshot into another snapshot in the same - * repository. - * - * @param fn - * a function that initializes a builder to create the - * {@link CloneSnapshotRequest} - * - */ - - public final CompletableFuture clone( - Function> fn - ) throws IOException, OpenSearchException { - return clone(fn.apply(new CloneSnapshotRequest.Builder()).build()); - } - // ----- Endpoint: snapshot.create /** diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/snapshot/OpenSearchSnapshotClient.java b/java-client/src/main/java/org/opensearch/client/opensearch/snapshot/OpenSearchSnapshotClient.java index 588ce9105c..29103dd89f 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/snapshot/OpenSearchSnapshotClient.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/snapshot/OpenSearchSnapshotClient.java @@ -60,40 +60,6 @@ public OpenSearchSnapshotClient withTransportOptions(@Nullable TransportOptions return new OpenSearchSnapshotClient(this.transport, transportOptions); } - // ----- Endpoint: snapshot.clone - - /** - * Clones indices from one snapshot into another snapshot in the same - * repository. - * - * - */ - - public CloneSnapshotResponse clone(CloneSnapshotRequest request) throws IOException, OpenSearchException { - @SuppressWarnings("unchecked") - JsonEndpoint endpoint = (JsonEndpoint< - CloneSnapshotRequest, - CloneSnapshotResponse, - ErrorResponse>) CloneSnapshotRequest._ENDPOINT; - - return this.transport.performRequest(request, endpoint, this.transportOptions); - } - - /** - * Clones indices from one snapshot into another snapshot in the same - * repository. - * - * @param fn - * a function that initializes a builder to create the - * {@link CloneSnapshotRequest} - * - */ - - public final CloneSnapshotResponse clone(Function> fn) - throws IOException, OpenSearchException { - return clone(fn.apply(new CloneSnapshotRequest.Builder()).build()); - } - // ----- Endpoint: snapshot.create /** diff --git a/java-codegen/src/main/java/org/opensearch/client/codegen/CodeGenerator.java b/java-codegen/src/main/java/org/opensearch/client/codegen/CodeGenerator.java index 482ddab4f3..70d12db927 100644 --- a/java-codegen/src/main/java/org/opensearch/client/codegen/CodeGenerator.java +++ b/java-codegen/src/main/java/org/opensearch/client/codegen/CodeGenerator.java @@ -44,7 +44,7 @@ public class CodeGenerator { and(namespace(""), named("info")), namespace("dangling_indices"), and(namespace("ml"), not(named("search_models"))), // TODO: search_models is complex and ideally should re-use the search structures - and(namespace("snapshot"), named("cleanup_repository", "verify_repository")), + and(namespace("snapshot"), named("cleanup_repository", "clone", "verify_repository")), and(namespace("tasks")) ); diff --git a/java-codegen/src/main/java/org/opensearch/client/codegen/model/RequestShape.java b/java-codegen/src/main/java/org/opensearch/client/codegen/model/RequestShape.java index 18facfd53e..b0d93dcea8 100644 --- a/java-codegen/src/main/java/org/opensearch/client/codegen/model/RequestShape.java +++ b/java-codegen/src/main/java/org/opensearch/client/codegen/model/RequestShape.java @@ -169,6 +169,8 @@ private static String responseClassName(@Nonnull OperationGroup operationGroup) private static String classBaseName(@Nonnull OperationGroup operationGroup) { Objects.requireNonNull(operationGroup, "operationGroup must not be null"); switch (operationGroup.toString()) { + case "snapshot.clone": + return "CloneSnapshot"; case "tasks.get": return "GetTasks"; default: