From 40948644aefab4100e8c404f78955ec4f0992f90 Mon Sep 17 00:00:00 2001 From: Tatsuya Kawakami <43780506+hogesako@users.noreply.github.com> Date: Tue, 3 Dec 2024 05:36:17 +0900 Subject: [PATCH] Generate CreateSnapshot(Fix CreateSnapshotResponse deserialization when wait_for_completion is false) (#1332) (#1335) * Generate CreateSnapshot Signed-off-by: Tatsuya Kawakami <43780506+hogesako@users.noreply.github.com> * add changelog Signed-off-by: Tatsuya Kawakami <43780506+hogesako@users.noreply.github.com> --------- Signed-off-by: Tatsuya Kawakami <43780506+hogesako@users.noreply.github.com> (cherry picked from commit d3509b5491c4d7caf0c842546136be92fe53022f) --- CHANGELOG.md | 1 + .../snapshot/CreateSnapshotRequest.java | 378 +++++++++--------- .../snapshot/CreateSnapshotResponse.java | 71 +++- .../client/codegen/model/RequestShape.java | 2 + 4 files changed, 255 insertions(+), 197 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 17d12dc3b3..d98cb9cad0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - Fixed `IcuCollationDecomposition`'s variants to align with those supported by OpenSearch ([#]()) - Fixed don't invoke the mapper's serialize method for the RangeQuery JsonData raw value [#1309](https://github.com/opensearch-project/opensearch-java/pull/1309) - Fixed an issue where `FieldSort` was not implementing `SortOptionsVariant` ([#1323](https://github.com/opensearch-project/opensearch-java/pull/1323)) +- Fixed `CreateSnapshotResponse` deserialization when wait_for_completion is false ([#1332](https://github.com/opensearch-project/opensearch-java/pull/1332)) ### Security diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/snapshot/CreateSnapshotRequest.java b/java-client/src/main/java/org/opensearch/client/opensearch/snapshot/CreateSnapshotRequest.java index 4a1e14baea..243541c366 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/snapshot/CreateSnapshotRequest.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/snapshot/CreateSnapshotRequest.java @@ -30,13 +30,20 @@ * 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.List; import java.util.Map; +import java.util.Objects; import java.util.function.Function; +import javax.annotation.Generated; +import javax.annotation.Nonnull; import javax.annotation.Nullable; import org.opensearch.client.json.JsonData; import org.opensearch.client.json.JsonpDeserializable; @@ -58,10 +65,15 @@ /** * Creates a snapshot in a repository. - * */ @JsonpDeserializable +@Generated("org.opensearch.client.codegen.CodeGenerator") public class CreateSnapshotRequest extends RequestBase implements PlainJsonSerializable { + + @Nullable + private final Time clusterManagerTimeout; + + @Nonnull private final List featureStates; @Nullable @@ -70,22 +82,23 @@ public class CreateSnapshotRequest extends RequestBase implements PlainJsonSeria @Nullable private final Boolean includeGlobalState; + @Nonnull private final List indices; @Deprecated @Nullable private final Time masterTimeout; - @Nullable - private final Time clusterManagerTimeout; - + @Nonnull private final Map metadata; @Nullable private final Boolean partial; + @Nonnull private final String repository; + @Nonnull private final String snapshot; @Nullable @@ -94,46 +107,54 @@ public class CreateSnapshotRequest extends RequestBase implements PlainJsonSeria // --------------------------------------------------------------------------------------------- private CreateSnapshotRequest(Builder builder) { - + this.clusterManagerTimeout = builder.clusterManagerTimeout; this.featureStates = ApiTypeHelper.unmodifiable(builder.featureStates); this.ignoreUnavailable = builder.ignoreUnavailable; this.includeGlobalState = builder.includeGlobalState; this.indices = ApiTypeHelper.unmodifiable(builder.indices); this.masterTimeout = builder.masterTimeout; - this.clusterManagerTimeout = builder.clusterManagerTimeout; this.metadata = ApiTypeHelper.unmodifiable(builder.metadata); this.partial = builder.partial; this.repository = ApiTypeHelper.requireNonNull(builder.repository, this, "repository"); this.snapshot = ApiTypeHelper.requireNonNull(builder.snapshot, this, "snapshot"); this.waitForCompletion = builder.waitForCompletion; - } - public static CreateSnapshotRequest of(Function> fn) { + public static CreateSnapshotRequest of(Function> fn) { return fn.apply(new Builder()).build(); } /** - * Feature states to include in the snapshot. Each feature state includes one or - * more system indices containing related data. You can view a list of eligible - * features using the get features API. If include_global_state is - * true, all current feature states are included by default. If - * include_global_state is false, no feature states - * are included by default. + * Operation timeout for connection to cluster-manager node. + *

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

+ */ + @Nullable + public final Time clusterManagerTimeout() { + return this.clusterManagerTimeout; + } + + /** + * Feature states to include in the snapshot. Each feature state includes one or more system indexes containing related data. You can + * view a list of eligible features using the get features API. If include_global_state is true, all current + * feature states are included by default. If include_global_state is false, no feature states are included by + * default. *

* API name: {@code feature_states} + *

*/ + @Nonnull public final List featureStates() { return this.featureStates; } /** - * If true, the request ignores data streams and indices in - * indices that are missing or closed. If false, the - * request returns an error for any data stream or index that is missing or - * closed. + * If true, the request ignores data streams and indexes in indices that are missing or closed. If + * false, the request returns an error for any data stream or index that is missing or closed. *

* API name: {@code ignore_unavailable} + *

*/ @Nullable public final Boolean ignoreUnavailable() { @@ -141,13 +162,12 @@ public final Boolean ignoreUnavailable() { } /** - * If true, the current cluster state is included in the snapshot. - * The cluster state includes persistent cluster settings, composable index - * templates, legacy index templates, ingest pipelines, and ILM policies. It - * also includes data stored in system indices, such as Watches and task records - * (configurable via feature_states). + * If true, the current cluster state is included in the snapshot. The cluster state includes persistent cluster settings, + * composable index templates, legacy index templates, ingest pipelines, and ILM policies. It also includes data stored in system + * indexes, such as Watches and task records (configurable with feature_states). *

* API name: {@code include_global_state} + *

*/ @Nullable public final Boolean includeGlobalState() { @@ -155,20 +175,19 @@ public final Boolean includeGlobalState() { } /** - * Data streams and indices to include in the snapshot. Supports multi-target - * syntax. Includes all data streams and indices by default. - *

* API name: {@code indices} */ + @Nonnull public final List indices() { return this.indices; } /** - * Period to wait for a connection to the master node. If no response is - * received before the timeout expires, the request fails and returns an error. + * Period to wait for a connection to the cluster-manager node. If no response is received before the timeout expires, the request fails + * and returns an error. *

* API name: {@code master_timeout} + *

*/ @Deprecated @Nullable @@ -177,34 +196,20 @@ public final Time masterTimeout() { } /** - * Period to wait for a connection to the cluster-manager node. If no response is - * received before the timeout expires, the request fails and returns an error. - *

- * API name: {@code cluster_manager_timeout} - */ - @Nullable - public final Time clusterManagerTimeout() { - return this.clusterManagerTimeout; - } - - /** - * Optional metadata for the snapshot. May have any contents. Must be less than - * 1024 bytes. This map is not automatically generated by OpenSearch. - *

* API name: {@code metadata} */ + @Nonnull public final Map metadata() { return this.metadata; } /** - * If true, allows restoring a partial snapshot of indices with - * unavailable shards. Only shards that were successfully included in the - * snapshot will be restored. All missing shards will be recreated as empty. If - * false, the entire restore operation will fail if one or more - * indices included in the snapshot do not have all primary shards available. + * If true, allows restoring a partial snapshot of indexes with unavailable shards. Only shards that were successfully + * included in the snapshot will be restored. All missing shards will be recreated as empty. If false, the entire restore + * operation will fail if one or more indexes included in the snapshot do not have all primary shards available. *

* API name: {@code partial} + *

*/ @Nullable public final Boolean partial() { @@ -215,7 +220,9 @@ public final Boolean partial() { * Required - Repository for the snapshot. *

* API name: {@code repository} + *

*/ + @Nonnull public final String repository() { return this.repository; } @@ -224,17 +231,19 @@ public final String repository() { * Required - Name of the snapshot. Must be unique in the repository. *

* API name: {@code snapshot} + *

*/ + @Nonnull public final String snapshot() { return this.snapshot; } /** - * If true, the request returns a response when the snapshot is - * complete. If false, the request returns a response when the - * snapshot initializes. + * If true, the request returns a response when the snapshot is complete. If false, the request returns a + * response when the snapshot initializes. *

* API name: {@code wait_for_completion} + *

*/ @Nullable public final Boolean waitForCompletion() { @@ -244,6 +253,7 @@ public final Boolean waitForCompletion() { /** * Serialize this object to JSON. */ + @Override public void serialize(JsonGenerator generator, JsonpMapper mapper) { generator.writeStartObject(); serializeInternal(generator, mapper); @@ -251,261 +261,252 @@ public void serialize(JsonGenerator generator, JsonpMapper mapper) { } protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { - if (ApiTypeHelper.isDefined(this.featureStates)) { generator.writeKey("feature_states"); generator.writeStartArray(); for (String item0 : this.featureStates) { generator.write(item0); - } generator.writeEnd(); - } + if (this.ignoreUnavailable != null) { generator.writeKey("ignore_unavailable"); generator.write(this.ignoreUnavailable); - } + if (this.includeGlobalState != null) { generator.writeKey("include_global_state"); generator.write(this.includeGlobalState); - } + if (ApiTypeHelper.isDefined(this.indices)) { generator.writeKey("indices"); generator.writeStartArray(); for (String item0 : this.indices) { generator.write(item0); - } generator.writeEnd(); - } + if (ApiTypeHelper.isDefined(this.metadata)) { generator.writeKey("metadata"); generator.writeStartObject(); for (Map.Entry item0 : this.metadata.entrySet()) { generator.writeKey(item0.getKey()); item0.getValue().serialize(generator, mapper); - } generator.writeEnd(); - } + if (this.partial != null) { generator.writeKey("partial"); generator.write(this.partial); - } - } - // --------------------------------------------------------------------------------------------- /** * Builder for {@link CreateSnapshotRequest}. */ - public static class Builder extends ObjectBuilderBase implements ObjectBuilder { + @Nullable + private Time clusterManagerTimeout; @Nullable private List featureStates; - @Nullable private Boolean ignoreUnavailable; - @Nullable private Boolean includeGlobalState; - @Nullable private List indices; - - @Deprecated @Nullable private Time masterTimeout; - - @Nullable - private Time clusterManagerTimeout; - @Nullable private Map metadata; - @Nullable private Boolean partial; - private String repository; - private String snapshot; - @Nullable private Boolean waitForCompletion; /** - * Feature states to include in the snapshot. Each feature state includes one or - * more system indices containing related data. You can view a list of eligible - * features using the get features API. If include_global_state is - * true, all current feature states are included by default. If - * include_global_state is false, no feature states - * are included by default. + * Operation timeout for connection to cluster-manager node. + *

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

+ */ + @Nonnull + 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} + *

+ */ + @Nonnull + public final Builder clusterManagerTimeout(Function> fn) { + return clusterManagerTimeout(fn.apply(new Time.Builder()).build()); + } + + /** + * Feature states to include in the snapshot. Each feature state includes one or more system indexes containing related data. You + * can view a list of eligible features using the get features API. If include_global_state is true, all + * current feature states are included by default. If include_global_state is false, no feature states are + * included by default. *

* API name: {@code feature_states} + *

+ * *

* Adds all elements of list to featureStates. + *

*/ + @Nonnull public final Builder featureStates(List list) { this.featureStates = _listAddAll(this.featureStates, list); return this; } /** - * Feature states to include in the snapshot. Each feature state includes one or - * more system indices containing related data. You can view a list of eligible - * features using the get features API. If include_global_state is - * true, all current feature states are included by default. If - * include_global_state is false, no feature states - * are included by default. + * Feature states to include in the snapshot. Each feature state includes one or more system indexes containing related data. You + * can view a list of eligible features using the get features API. If include_global_state is true, all + * current feature states are included by default. If include_global_state is false, no feature states are + * included by default. *

* API name: {@code feature_states} + *

+ * *

* Adds one or more values to featureStates. + *

*/ + @Nonnull public final Builder featureStates(String value, String... values) { this.featureStates = _listAdd(this.featureStates, value, values); return this; } /** - * If true, the request ignores data streams and indices in - * indices that are missing or closed. If false, the - * request returns an error for any data stream or index that is missing or - * closed. + * If true, the request ignores data streams and indexes in indices that are missing or closed. If + * false, the request returns an error for any data stream or index that is missing or closed. *

* API name: {@code ignore_unavailable} + *

*/ + @Nonnull public final Builder ignoreUnavailable(@Nullable Boolean value) { this.ignoreUnavailable = value; return this; } /** - * If true, the current cluster state is included in the snapshot. - * The cluster state includes persistent cluster settings, composable index - * templates, legacy index templates, ingest pipelines, and ILM policies. It - * also includes data stored in system indices, such as Watches and task records - * (configurable via feature_states). + * If true, the current cluster state is included in the snapshot. The cluster state includes persistent cluster + * settings, composable index templates, legacy index templates, ingest pipelines, and ILM policies. It also includes data stored in + * system indexes, such as Watches and task records (configurable with feature_states). *

* API name: {@code include_global_state} + *

*/ + @Nonnull public final Builder includeGlobalState(@Nullable Boolean value) { this.includeGlobalState = value; return this; } /** - * Data streams and indices to include in the snapshot. Supports multi-target - * syntax. Includes all data streams and indices by default. - *

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

* Adds all elements of list to indices. + *

*/ + @Nonnull public final Builder indices(List list) { this.indices = _listAddAll(this.indices, list); return this; } /** - * Data streams and indices to include in the snapshot. Supports multi-target - * syntax. Includes all data streams and indices by default. - *

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

* Adds one or more values to indices. + *

*/ + @Nonnull public final Builder indices(String value, String... values) { this.indices = _listAdd(this.indices, value, values); return this; } /** - * Period to wait for a connection to the master node. If no response is - * received before the timeout expires, the request fails and returns an error. + * Period to wait for a connection to the cluster-manager node. If no response is received before the timeout expires, the request + * fails and returns an error. *

* API name: {@code master_timeout} + *

*/ @Deprecated + @Nonnull public final Builder masterTimeout(@Nullable Time value) { this.masterTimeout = value; return this; } /** - * Period to wait for a connection to the master node. If no response is - * received before the timeout expires, the request fails and returns an error. + * Period to wait for a connection to the cluster-manager node. If no response is received before the timeout expires, the request + * fails and returns an error. *

* API name: {@code master_timeout} + *

*/ @Deprecated + @Nonnull public final Builder masterTimeout(Function> fn) { - return this.masterTimeout(fn.apply(new Time.Builder()).build()); - } - - /** - * Period to wait for a connection to the cluster-manager node. If no response is - * received before the timeout expires, the request fails and returns an error. - *

- * API name: {@code cluster_manager_timeout} - */ - public final Builder clusterManagerTimeout(@Nullable Time value) { - this.clusterManagerTimeout = value; - return this; + return masterTimeout(fn.apply(new Time.Builder()).build()); } /** - * Period to wait for a connection to the cluster-manager node. If no response is - * received before the timeout expires, the request fails and returns an error. - *

- * API name: {@code cluster_manager_timeout} - */ - public final Builder clusterManagerTimeout(Function> fn) { - return this.clusterManagerTimeout(fn.apply(new Time.Builder()).build()); - } - - /** - * Optional metadata for the snapshot. May have any contents. Must be less than - * 1024 bytes. This map is not automatically generated by OpenSearch. - *

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

- * Adds all entries of map to metadata. + * Adds all elements of map to metadata. + *

*/ + @Nonnull public final Builder metadata(Map map) { this.metadata = _mapPutAll(this.metadata, map); return this; } /** - * Optional metadata for the snapshot. May have any contents. Must be less than - * 1024 bytes. This map is not automatically generated by OpenSearch. - *

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

* Adds an entry to metadata. + *

*/ + @Nonnull public final Builder metadata(String key, JsonData value) { this.metadata = _mapPut(this.metadata, key, value); return this; } /** - * If true, allows restoring a partial snapshot of indices with - * unavailable shards. Only shards that were successfully included in the - * snapshot will be restored. All missing shards will be recreated as empty. If - * false, the entire restore operation will fail if one or more - * indices included in the snapshot do not have all primary shards available. + * If true, allows restoring a partial snapshot of indexes with unavailable shards. Only shards that were successfully + * included in the snapshot will be restored. All missing shards will be recreated as empty. If false, the entire + * restore operation will fail if one or more indexes included in the snapshot do not have all primary shards available. *

* API name: {@code partial} + *

*/ + @Nonnull public final Builder partial(@Nullable Boolean value) { this.partial = value; return this; @@ -515,7 +516,9 @@ public final Builder partial(@Nullable Boolean value) { * Required - Repository for the snapshot. *

* API name: {@code repository} + *

*/ + @Nonnull public final Builder repository(String value) { this.repository = value; return this; @@ -525,19 +528,22 @@ public final Builder repository(String value) { * Required - Name of the snapshot. Must be unique in the repository. *

* API name: {@code snapshot} + *

*/ + @Nonnull public final Builder snapshot(String value) { this.snapshot = value; return this; } /** - * If true, the request returns a response when the snapshot is - * complete. If false, the request returns a response when the - * snapshot initializes. + * If true, the request returns a response when the snapshot is complete. If false, the request returns a + * response when the snapshot initializes. *

* API name: {@code wait_for_completion} + *

*/ + @Nonnull public final Builder waitForCompletion(@Nullable Boolean value) { this.waitForCompletion = value; return this; @@ -546,9 +552,10 @@ public final Builder waitForCompletion(@Nullable Boolean value) { /** * Builds a {@link CreateSnapshotRequest}. * - * @throws NullPointerException - * if some of the required fields are null. + * @throws NullPointerException if some of the required fields are null. */ + @Override + @Nonnull public CreateSnapshotRequest build() { _checkSingleUse(); @@ -567,14 +574,14 @@ public CreateSnapshotRequest build() { ); protected static void setupCreateSnapshotRequestDeserializer(ObjectDeserializer op) { - op.add(Builder::featureStates, JsonpDeserializer.arrayDeserializer(JsonpDeserializer.stringDeserializer()), "feature_states"); op.add(Builder::ignoreUnavailable, JsonpDeserializer.booleanDeserializer(), "ignore_unavailable"); op.add(Builder::includeGlobalState, JsonpDeserializer.booleanDeserializer(), "include_global_state"); op.add(Builder::indices, JsonpDeserializer.arrayDeserializer(JsonpDeserializer.stringDeserializer()), "indices"); op.add(Builder::metadata, JsonpDeserializer.stringMapDeserializer(JsonData._DESERIALIZER), "metadata"); op.add(Builder::partial, JsonpDeserializer.booleanDeserializer(), "partial"); - + op.add(Builder::repository, JsonpDeserializer.stringDeserializer(), "repository"); + op.add(Builder::snapshot, JsonpDeserializer.stringDeserializer(), "snapshot"); } // --------------------------------------------------------------------------------------------- @@ -583,53 +590,68 @@ protected static void setupCreateSnapshotRequestDeserializer(ObjectDeserializer< * Endpoint "{@code snapshot.create}". */ public static final Endpoint _ENDPOINT = new SimpleEndpoint<>( - // Request method - request -> { - return "PUT"; - - }, - + request -> "PUT", // Request path request -> { - final int _repository = 1 << 0; - final int _snapshot = 1 << 1; - - int propsSet = 0; - - propsSet |= _repository; - propsSet |= _snapshot; - - if (propsSet == (_repository | _snapshot)) { - StringBuilder buf = new StringBuilder(); - buf.append("/_snapshot"); - buf.append("/"); - SimpleEndpoint.pathEncode(request.repository, buf); - buf.append("/"); - SimpleEndpoint.pathEncode(request.snapshot, 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); + 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.masterTimeout != null) { + params.put("master_timeout", request.masterTimeout._toJsonString()); + } if (request.waitForCompletion != null) { params.put("wait_for_completion", String.valueOf(request.waitForCompletion)); } return params; - }, SimpleEndpoint.emptyMap(), true, CreateSnapshotResponse._DESERIALIZER ); + + @Override + public int hashCode() { + int result = 17; + result = 31 * result + Objects.hashCode(this.clusterManagerTimeout); + result = 31 * result + Objects.hashCode(this.featureStates); + result = 31 * result + Objects.hashCode(this.ignoreUnavailable); + result = 31 * result + Objects.hashCode(this.includeGlobalState); + result = 31 * result + Objects.hashCode(this.indices); + result = 31 * result + Objects.hashCode(this.masterTimeout); + result = 31 * result + Objects.hashCode(this.metadata); + result = 31 * result + Objects.hashCode(this.partial); + result = 31 * result + this.repository.hashCode(); + result = 31 * result + this.snapshot.hashCode(); + result = 31 * result + Objects.hashCode(this.waitForCompletion); + return result; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || this.getClass() != o.getClass()) return false; + CreateSnapshotRequest other = (CreateSnapshotRequest) o; + return Objects.equals(this.clusterManagerTimeout, other.clusterManagerTimeout) + && Objects.equals(this.featureStates, other.featureStates) + && Objects.equals(this.ignoreUnavailable, other.ignoreUnavailable) + && Objects.equals(this.includeGlobalState, other.includeGlobalState) + && Objects.equals(this.indices, other.indices) + && Objects.equals(this.masterTimeout, other.masterTimeout) + && Objects.equals(this.metadata, other.metadata) + && Objects.equals(this.partial, other.partial) + && this.repository.equals(other.repository) + && this.snapshot.equals(other.snapshot) + && Objects.equals(this.waitForCompletion, other.waitForCompletion); + } } diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/snapshot/CreateSnapshotResponse.java b/java-client/src/main/java/org/opensearch/client/opensearch/snapshot/CreateSnapshotResponse.java index 301bda1d05..bb7acba744 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/snapshot/CreateSnapshotResponse.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/snapshot/CreateSnapshotResponse.java @@ -30,10 +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.Objects; import java.util.function.Function; +import javax.annotation.Generated; +import javax.annotation.Nonnull; import javax.annotation.Nullable; import org.opensearch.client.json.JsonpDeserializable; import org.opensearch.client.json.JsonpDeserializer; @@ -41,34 +48,38 @@ import org.opensearch.client.json.ObjectBuilderDeserializer; import org.opensearch.client.json.ObjectDeserializer; import org.opensearch.client.json.PlainJsonSerializable; -import org.opensearch.client.util.ApiTypeHelper; import org.opensearch.client.util.ObjectBuilder; import org.opensearch.client.util.ObjectBuilderBase; // typedef: snapshot.create.Response @JsonpDeserializable +@Generated("org.opensearch.client.codegen.CodeGenerator") public class CreateSnapshotResponse implements PlainJsonSerializable { + @Nullable private final Boolean accepted; + @Nullable private final SnapshotInfo snapshot; // --------------------------------------------------------------------------------------------- private CreateSnapshotResponse(Builder builder) { - this.accepted = builder.accepted; - this.snapshot = ApiTypeHelper.requireNonNull(builder.snapshot, this, "snapshot"); - + this.snapshot = builder.snapshot; } - public static CreateSnapshotResponse of(Function> fn) { + public static CreateSnapshotResponse of(Function> fn) { return fn.apply(new Builder()).build(); } /** + * Returns true if the snapshot was accepted. Present when the request had wait_for_completion set to + * false. + *

* API name: {@code accepted} + *

*/ @Nullable public final Boolean accepted() { @@ -76,8 +87,9 @@ public final Boolean accepted() { } /** - * Required - API name: {@code snapshot} + * API name: {@code snapshot} */ + @Nullable public final SnapshotInfo snapshot() { return this.snapshot; } @@ -85,6 +97,7 @@ public final SnapshotInfo snapshot() { /** * Serialize this object to JSON. */ + @Override public void serialize(JsonGenerator generator, JsonpMapper mapper) { generator.writeStartObject(); serializeInternal(generator, mapper); @@ -92,15 +105,15 @@ public void serialize(JsonGenerator generator, JsonpMapper mapper) { } protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { - if (this.accepted != null) { generator.writeKey("accepted"); generator.write(this.accepted); - } - generator.writeKey("snapshot"); - this.snapshot.serialize(generator, mapper); + if (this.snapshot != null) { + generator.writeKey("snapshot"); + this.snapshot.serialize(generator, mapper); + } } // --------------------------------------------------------------------------------------------- @@ -108,42 +121,49 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { /** * Builder for {@link CreateSnapshotResponse}. */ - public static class Builder extends ObjectBuilderBase implements ObjectBuilder { @Nullable private Boolean accepted; - + @Nullable private SnapshotInfo snapshot; /** + * Returns true if the snapshot was accepted. Present when the request had wait_for_completion set to + * false. + *

* API name: {@code accepted} + *

*/ + @Nonnull public final Builder accepted(@Nullable Boolean value) { this.accepted = value; return this; } /** - * Required - API name: {@code snapshot} + * API name: {@code snapshot} */ - public final Builder snapshot(SnapshotInfo value) { + @Nonnull + public final Builder snapshot(@Nullable SnapshotInfo value) { this.snapshot = value; return this; } /** - * Required - API name: {@code snapshot} + * API name: {@code snapshot} */ + @Nonnull public final Builder snapshot(Function> fn) { - return this.snapshot(fn.apply(new SnapshotInfo.Builder()).build()); + return snapshot(fn.apply(new SnapshotInfo.Builder()).build()); } /** * Builds a {@link CreateSnapshotResponse}. * - * @throws NullPointerException - * if some of the required fields are null. + * @throws NullPointerException if some of the required fields are null. */ + @Override + @Nonnull public CreateSnapshotResponse build() { _checkSingleUse(); @@ -162,10 +182,23 @@ public CreateSnapshotResponse build() { ); protected static void setupCreateSnapshotResponseDeserializer(ObjectDeserializer op) { - op.add(Builder::accepted, JsonpDeserializer.booleanDeserializer(), "accepted"); op.add(Builder::snapshot, SnapshotInfo._DESERIALIZER, "snapshot"); + } + @Override + public int hashCode() { + int result = 17; + result = 31 * result + Objects.hashCode(this.accepted); + result = 31 * result + Objects.hashCode(this.snapshot); + return result; } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || this.getClass() != o.getClass()) return false; + CreateSnapshotResponse other = (CreateSnapshotResponse) o; + return Objects.equals(this.accepted, other.accepted) && Objects.equals(this.snapshot, other.snapshot); + } } 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 0877974e78..a4f4818b34 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 @@ -202,6 +202,8 @@ private static String classBaseName(@Nonnull OperationGroup operationGroup) { return "GetIndex"; case "snapshot.clone": return "CloneSnapshot"; + case "snapshot.create": + return "CreateSnapshot"; case "tasks.get": return "GetTasks"; default: