From c6e61e1b559cc7e26b1e65765440c02192e44180 Mon Sep 17 00:00:00 2001 From: Thomas Farr Date: Tue, 27 Aug 2024 09:16:30 +1200 Subject: [PATCH] Generate the ml namespace (#1158) * Generate ml.register_model_group Signed-off-by: Thomas Farr * Start neural search sample Signed-off-by: Thomas Farr * Re-generate ShardStatistics Signed-off-by: Thomas Farr * Re-generate ShardFailure Signed-off-by: Thomas Farr * Re-generate Result Signed-off-by: Thomas Farr * Re-generate WriteResponseBase Signed-off-by: Thomas Farr * Generate ml.delete_model_group Signed-off-by: Thomas Farr * Generate ml.register_model Signed-off-by: Thomas Farr * Exclude legacy license from ml namespace Signed-off-by: Thomas Farr * Generate ml.get_task Signed-off-by: Thomas Farr * Generate ml.delete_task Signed-off-by: Thomas Farr * Generate ml.delete_model Signed-off-by: Thomas Farr * Generate ml.deploy_model Signed-off-by: Thomas Farr * Generate ml.undeploy_model Signed-off-by: Thomas Farr * Complete neural search sample Signed-off-by: Thomas Farr * Generate ml.get_model Signed-off-by: Thomas Farr * Add changelog entry Signed-off-by: Thomas Farr * note Signed-off-by: Thomas Farr * Fix tests Signed-off-by: Thomas Farr --------- Signed-off-by: Thomas Farr --- CHANGELOG.md | 6 +- UPGRADING.md | 6 +- .../opensearch/OpenSearchAsyncClient.java | 5 + .../client/opensearch/OpenSearchClient.java | 5 + .../client/opensearch/_types/Result.java | 16 +- .../opensearch/_types/ShardFailure.java | 33 +- .../opensearch/_types/ShardStatistics.java | 144 ++++--- .../opensearch/_types/WriteResponseBase.java | 81 ++-- .../ml/DeleteModelGroupRequest.java | 101 +++++ .../ml/DeleteModelGroupResponse.java | 75 ++++ .../opensearch/ml/DeleteModelRequest.java | 101 +++++ .../opensearch/ml/DeleteModelResponse.java | 75 ++++ .../opensearch/ml/DeleteTaskRequest.java | 101 +++++ .../opensearch/ml/DeleteTaskResponse.java | 75 ++++ .../opensearch/ml/DeployModelRequest.java | 102 +++++ .../opensearch/ml/DeployModelResponse.java | 160 +++++++ .../opensearch/ml/GetModelGroupRequest.java | 101 +++++ .../opensearch/ml/GetModelGroupResponse.java | 258 ++++++++++++ .../client/opensearch/ml/GetTaskRequest.java | 101 +++++ .../client/opensearch/ml/GetTaskResponse.java | 394 ++++++++++++++++++ .../ml/OpenSearchMlAsyncClient.java | 279 +++++++++++++ .../opensearch/ml/OpenSearchMlClient.java | 271 ++++++++++++ .../ml/RegisterModelGroupRequest.java | 296 +++++++++++++ .../ml/RegisterModelGroupResponse.java | 145 +++++++ .../opensearch/ml/RegisterModelRequest.java | 264 ++++++++++++ .../opensearch/ml/RegisterModelResponse.java | 131 ++++++ .../opensearch/ml/UndeployModelNode.java | 135 ++++++ .../opensearch/ml/UndeployModelRequest.java | 102 +++++ .../opensearch/ml/UndeployModelResponse.java | 142 +++++++ .../json/PlainJsonSerializableTest.java | 2 +- .../opensearch/model/TypedKeysTest.java | 4 +- java-codegen/build.gradle.kts | 3 + java-codegen/opensearch-openapi.yaml | 43 +- .../client/codegen/CodeGenerator.java | 10 +- .../client/codegen/model/Deprecation.java | 7 +- .../client/codegen/model/Namespace.java | 7 +- .../client/codegen/model/OperationGroup.java | 59 --- .../codegen/model/OperationGroupMatcher.java | 61 +++ .../client/codegen/model/RequestShape.java | 6 + .../client/codegen/model/Shape.java | 4 + .../client/codegen/model/SpecTransformer.java | 35 +- .../codegen/openapi/OpenApiOperation.java | 6 +- .../codegen/openapi/OpenApiParameter.java | 6 +- .../client/codegen/openapi/OpenApiSchema.java | 14 + .../client/codegen/utils/Strings.java | 12 + .../client/codegen/utils/Versions.java | 25 ++ .../templates/Partials/ClassHeader.mustache | 2 + .../client/samples/neural/NeuralSearch.java | 333 +++++++++++++++ 48 files changed, 4110 insertions(+), 234 deletions(-) rename java-client/src/{main => generated}/java/org/opensearch/client/opensearch/_types/Result.java (84%) rename java-client/src/{main => generated}/java/org/opensearch/client/opensearch/_types/ShardFailure.java (92%) rename java-client/src/{main => generated}/java/org/opensearch/client/opensearch/_types/ShardStatistics.java (79%) rename java-client/src/{main => generated}/java/org/opensearch/client/opensearch/_types/WriteResponseBase.java (94%) create mode 100644 java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeleteModelGroupRequest.java create mode 100644 java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeleteModelGroupResponse.java create mode 100644 java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeleteModelRequest.java create mode 100644 java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeleteModelResponse.java create mode 100644 java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeleteTaskRequest.java create mode 100644 java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeleteTaskResponse.java create mode 100644 java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeployModelRequest.java create mode 100644 java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeployModelResponse.java create mode 100644 java-client/src/generated/java/org/opensearch/client/opensearch/ml/GetModelGroupRequest.java create mode 100644 java-client/src/generated/java/org/opensearch/client/opensearch/ml/GetModelGroupResponse.java create mode 100644 java-client/src/generated/java/org/opensearch/client/opensearch/ml/GetTaskRequest.java create mode 100644 java-client/src/generated/java/org/opensearch/client/opensearch/ml/GetTaskResponse.java create mode 100644 java-client/src/generated/java/org/opensearch/client/opensearch/ml/OpenSearchMlAsyncClient.java create mode 100644 java-client/src/generated/java/org/opensearch/client/opensearch/ml/OpenSearchMlClient.java create mode 100644 java-client/src/generated/java/org/opensearch/client/opensearch/ml/RegisterModelGroupRequest.java create mode 100644 java-client/src/generated/java/org/opensearch/client/opensearch/ml/RegisterModelGroupResponse.java create mode 100644 java-client/src/generated/java/org/opensearch/client/opensearch/ml/RegisterModelRequest.java create mode 100644 java-client/src/generated/java/org/opensearch/client/opensearch/ml/RegisterModelResponse.java create mode 100644 java-client/src/generated/java/org/opensearch/client/opensearch/ml/UndeployModelNode.java create mode 100644 java-client/src/generated/java/org/opensearch/client/opensearch/ml/UndeployModelRequest.java create mode 100644 java-client/src/generated/java/org/opensearch/client/opensearch/ml/UndeployModelResponse.java create mode 100644 java-codegen/src/main/java/org/opensearch/client/codegen/model/OperationGroupMatcher.java create mode 100644 java-codegen/src/main/java/org/opensearch/client/codegen/utils/Versions.java create mode 100644 samples/src/main/java/org/opensearch/client/samples/neural/NeuralSearch.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 49e11a53cb..d3ec2058b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ This section is for maintaining a changelog for all breaking changes for the cli - Migrate client transports to Apache HttpClient / Core 5.x ([#246](https://github.com/opensearch-project/opensearch-java/pull/246)) - Changed SearchAfter of SearchRequest type to FieldValue instead of String ([#769](https://github.com/opensearch-project/opensearch-java/pull/769)) - Changed type of `DanglingIndex`'s `creationDateMillis` field from `String` to `long` ([#1124](https://github.com/opensearch-project/opensearch-java/pull/1124)) +- Changed type of `ShardStatistics`'s `total`, `successful`, `failed` & `skipped` fields from `Number` to `int/Integer` ([#1158](https://github.com/opensearch-project/opensearch-java/pull/1158)) ### Deprecated - Deprecate RestClientTransport ([#536](https://github.com/opensearch-project/opensearch-java/pull/536)) @@ -36,8 +37,9 @@ This section is for maintaining a changelog for all breaking changes for the cli ## [Unreleased 2.x] ### Added -- Adds `queryImage` (query_image) field to `NeuralQuery`, following definition in ([Neural Query](https://opensearch.org/docs/latest/query-dsl/specialized/neural/)) ([#1137](https://github.com/opensearch-project/opensearch-java/pull/1138)) -- Adds `cancelAfterTimeInterval` to `SearchRequest` and `MsearchRequest` ([#1147](https://github.com/opensearch-project/opensearch-java/pull/1147)) +- Added `queryImage` (query_image) field to `NeuralQuery`, following definition in ([Neural Query](https://opensearch.org/docs/latest/query-dsl/specialized/neural/)) ([#1137](https://github.com/opensearch-project/opensearch-java/pull/1138)) +- Added `cancelAfterTimeInterval` to `SearchRequest` and `MsearchRequest` ([#1147](https://github.com/opensearch-project/opensearch-java/pull/1147)) +- Added the `ml` namespace operations ([#1158](https://github.com/opensearch-project/opensearch-java/pull/1158)) ### Dependencies diff --git a/UPGRADING.md b/UPGRADING.md index 4764e323bf..194fd82ae4 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -23,4 +23,8 @@ After: ``` ### DanglingIndex creationDateMillis type -- The type of `DanglingIndex`'s `creationDateMillis` field has been corrected from a `String` to a `long`. \ No newline at end of file +- The type of `DanglingIndex`'s `creationDateMillis` field has been corrected from a `String` to a `long`. + +### ShardStatistics properties types +- The type of the `total`, `successful` and `failed` fields has been corrected from `Number` to `int`. +- The type of the `skipped` field has been corrected from `Number` to `Integer`. \ No newline at end of file diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/OpenSearchAsyncClient.java b/java-client/src/generated/java/org/opensearch/client/opensearch/OpenSearchAsyncClient.java index 3c2dbdd206..d962a97b6a 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/OpenSearchAsyncClient.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/OpenSearchAsyncClient.java @@ -44,6 +44,7 @@ import org.opensearch.client.opensearch.core.InfoRequest; import org.opensearch.client.opensearch.core.InfoResponse; import org.opensearch.client.opensearch.dangling_indices.OpenSearchDanglingIndicesAsyncClient; +import org.opensearch.client.opensearch.ml.OpenSearchMlAsyncClient; import org.opensearch.client.transport.OpenSearchTransport; import org.opensearch.client.transport.TransportOptions; @@ -71,6 +72,10 @@ public OpenSearchDanglingIndicesAsyncClient danglingIndices() { return new OpenSearchDanglingIndicesAsyncClient(this.transport, this.transportOptions); } + public OpenSearchMlAsyncClient ml() { + return new OpenSearchMlAsyncClient(this.transport, this.transportOptions); + } + // ----- Endpoint: info /** diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/OpenSearchClient.java b/java-client/src/generated/java/org/opensearch/client/opensearch/OpenSearchClient.java index d797bf2b54..84fd03d645 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/OpenSearchClient.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/OpenSearchClient.java @@ -43,6 +43,7 @@ import org.opensearch.client.opensearch.core.InfoRequest; import org.opensearch.client.opensearch.core.InfoResponse; import org.opensearch.client.opensearch.dangling_indices.OpenSearchDanglingIndicesClient; +import org.opensearch.client.opensearch.ml.OpenSearchMlClient; import org.opensearch.client.transport.OpenSearchTransport; import org.opensearch.client.transport.TransportOptions; @@ -70,6 +71,10 @@ public OpenSearchDanglingIndicesClient danglingIndices() { return new OpenSearchDanglingIndicesClient(this.transport, this.transportOptions); } + public OpenSearchMlClient ml() { + return new OpenSearchMlClient(this.transport, this.transportOptions); + } + // ----- Endpoint: info /** diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/_types/Result.java b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/Result.java similarity index 84% rename from java-client/src/main/java/org/opensearch/client/opensearch/_types/Result.java rename to java-client/src/generated/java/org/opensearch/client/opensearch/_types/Result.java index 54b408cf76..651f561ce3 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/_types/Result.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/Result.java @@ -30,24 +30,30 @@ * GitHub history for details. */ +//---------------------------------------------------- +// THIS CODE IS GENERATED. MANUAL EDITS WILL BE LOST. +//---------------------------------------------------- + package org.opensearch.client.opensearch._types; +import javax.annotation.Generated; import org.opensearch.client.json.JsonEnum; import org.opensearch.client.json.JsonpDeserializable; +// typedef: _types.Result + @JsonpDeserializable +@Generated("org.opensearch.client.codegen.CodeGenerator") public enum Result implements JsonEnum { Created("created"), - Updated("updated"), - Deleted("deleted"), - NotFound("not_found"), - NoOp("noop"), - ; + NotFound("not_found"), + + Updated("updated"); private final String jsonValue; diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/_types/ShardFailure.java b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/ShardFailure.java similarity index 92% rename from java-client/src/main/java/org/opensearch/client/opensearch/_types/ShardFailure.java rename to java-client/src/generated/java/org/opensearch/client/opensearch/_types/ShardFailure.java index cf142da1d5..76397fa257 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/_types/ShardFailure.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/ShardFailure.java @@ -30,10 +30,15 @@ * GitHub history for details. */ +//---------------------------------------------------- +// THIS CODE IS GENERATED. MANUAL EDITS WILL BE LOST. +//---------------------------------------------------- + package org.opensearch.client.opensearch._types; import jakarta.json.stream.JsonGenerator; 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; @@ -48,7 +53,9 @@ // typedef: _types.ShardFailure @JsonpDeserializable +@Generated("org.opensearch.client.codegen.CodeGenerator") public class ShardFailure implements PlainJsonSerializable { + @Nullable private final String index; @@ -65,16 +72,14 @@ public class ShardFailure implements PlainJsonSerializable { // --------------------------------------------------------------------------------------------- private ShardFailure(Builder builder) { - this.index = builder.index; this.node = builder.node; this.reason = ApiTypeHelper.requireNonNull(builder.reason, this, "reason"); this.shard = ApiTypeHelper.requireNonNull(builder.shard, this, "shard"); this.status = builder.status; - } - public static ShardFailure of(Function> fn) { + public static ShardFailure of(Function> fn) { return fn.apply(new Builder()).build(); } @@ -119,6 +124,7 @@ public final String status() { /** * Serialize this object to JSON. */ + @Override public void serialize(JsonGenerator generator, JsonpMapper mapper) { generator.writeStartObject(); serializeInternal(generator, mapper); @@ -126,17 +132,16 @@ public void serialize(JsonGenerator generator, JsonpMapper mapper) { } protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { - if (this.index != null) { generator.writeKey("index"); generator.write(this.index); - } + if (this.node != null) { generator.writeKey("node"); generator.write(this.node); - } + generator.writeKey("reason"); this.reason.serialize(generator, mapper); @@ -146,9 +151,7 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { if (this.status != null) { generator.writeKey("status"); generator.write(this.status); - } - } // --------------------------------------------------------------------------------------------- @@ -156,18 +159,13 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { /** * Builder for {@link ShardFailure}. */ - public static class Builder extends ObjectBuilderBase implements ObjectBuilder { @Nullable private String index; - @Nullable private String node; - private ErrorCause reason; - private Integer shard; - @Nullable private String status; @@ -199,7 +197,7 @@ public final Builder reason(ErrorCause value) { * Required - API name: {@code reason} */ public final Builder reason(Function> fn) { - return this.reason(fn.apply(new ErrorCause.Builder()).build()); + return reason(fn.apply(new ErrorCause.Builder()).build()); } /** @@ -221,8 +219,7 @@ public final Builder status(@Nullable String value) { /** * Builds a {@link ShardFailure}. * - * @throws NullPointerException - * if some of the required fields are null. + * @throws NullPointerException if some of the required fields are null. */ public ShardFailure build() { _checkSingleUse(); @@ -230,7 +227,6 @@ public ShardFailure build() { return new ShardFailure(this); } } - // --------------------------------------------------------------------------------------------- /** @@ -242,13 +238,10 @@ public ShardFailure build() { ); protected static void setupShardFailureDeserializer(ObjectDeserializer op) { - op.add(Builder::index, JsonpDeserializer.stringDeserializer(), "index"); op.add(Builder::node, JsonpDeserializer.stringDeserializer(), "node"); op.add(Builder::reason, ErrorCause._DESERIALIZER, "reason"); op.add(Builder::shard, JsonpDeserializer.integerDeserializer(), "shard"); op.add(Builder::status, JsonpDeserializer.stringDeserializer(), "status"); - } - } diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/_types/ShardStatistics.java b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/ShardStatistics.java similarity index 79% rename from java-client/src/main/java/org/opensearch/client/opensearch/_types/ShardStatistics.java rename to java-client/src/generated/java/org/opensearch/client/opensearch/_types/ShardStatistics.java index 5a335c7a83..04e9e5f14a 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/_types/ShardStatistics.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/ShardStatistics.java @@ -30,11 +30,16 @@ * GitHub history for details. */ +//---------------------------------------------------- +// THIS CODE IS GENERATED. MANUAL EDITS WILL BE LOST. +//---------------------------------------------------- + package org.opensearch.client.opensearch._types; import jakarta.json.stream.JsonGenerator; import java.util.List; 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; @@ -49,73 +54,74 @@ // typedef: _types.ShardStatistics @JsonpDeserializable +@Generated("org.opensearch.client.codegen.CodeGenerator") public class ShardStatistics implements PlainJsonSerializable { - private final Number failed; - - private final Number successful; - private final Number total; + private final int failed; private final List failures; @Nullable - private final Number skipped; + private final Integer skipped; + + private final int successful; + + private final int total; // --------------------------------------------------------------------------------------------- private ShardStatistics(Builder builder) { - this.failed = ApiTypeHelper.requireNonNull(builder.failed, this, "failed"); - this.successful = ApiTypeHelper.requireNonNull(builder.successful, this, "successful"); - this.total = ApiTypeHelper.requireNonNull(builder.total, this, "total"); this.failures = ApiTypeHelper.unmodifiable(builder.failures); this.skipped = builder.skipped; - + this.successful = ApiTypeHelper.requireNonNull(builder.successful, this, "successful"); + this.total = ApiTypeHelper.requireNonNull(builder.total, this, "total"); } - public static ShardStatistics of(Function> fn) { + public static ShardStatistics of(Function> fn) { return fn.apply(new Builder()).build(); } /** * Required - API name: {@code failed} */ - public final Number failed() { + public final int failed() { return this.failed; } /** - * Required - API name: {@code successful} + * API name: {@code failures} */ - public final Number successful() { - return this.successful; + public final List failures() { + return this.failures; } /** - * Required - API name: {@code total} + * API name: {@code skipped} */ - public final Number total() { - return this.total; + @Nullable + public final Integer skipped() { + return this.skipped; } /** - * API name: {@code failures} + * Required - API name: {@code successful} */ - public final List failures() { - return this.failures; + public final int successful() { + return this.successful; } /** - * API name: {@code skipped} + * Required - API name: {@code total} */ - @Nullable - public final Number skipped() { - return this.skipped; + public final int total() { + return this.total; } /** * Serialize this object to JSON. */ + @Override public void serialize(JsonGenerator generator, JsonpMapper mapper) { generator.writeStartObject(); serializeInternal(generator, mapper); @@ -123,32 +129,28 @@ public void serialize(JsonGenerator generator, JsonpMapper mapper) { } protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { - generator.writeKey("failed"); - generator.write(this.failed.doubleValue()); - - generator.writeKey("successful"); - generator.write(this.successful.doubleValue()); - - generator.writeKey("total"); - generator.write(this.total.doubleValue()); + generator.write(this.failed); if (ApiTypeHelper.isDefined(this.failures)) { generator.writeKey("failures"); generator.writeStartArray(); for (ShardFailure item0 : this.failures) { item0.serialize(generator, mapper); - } generator.writeEnd(); - } + if (this.skipped != null) { generator.writeKey("skipped"); - generator.write(this.skipped.doubleValue()); - + generator.write(this.skipped); } + generator.writeKey("successful"); + generator.write(this.successful); + + generator.writeKey("total"); + generator.write(this.total); } // --------------------------------------------------------------------------------------------- @@ -156,48 +158,29 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { /** * Builder for {@link ShardStatistics}. */ - public static class Builder extends ObjectBuilderBase implements ObjectBuilder { - private Number failed; - - private Number successful; - - private Number total; - + private Integer failed; @Nullable private List failures; - @Nullable - private Number skipped; + private Integer skipped; + private Integer successful; + private Integer total; /** * Required - API name: {@code failed} */ - public final Builder failed(Number value) { + public final Builder failed(int value) { this.failed = value; return this; } - /** - * Required - API name: {@code successful} - */ - public final Builder successful(Number value) { - this.successful = value; - return this; - } - - /** - * Required - API name: {@code total} - */ - public final Builder total(Number value) { - this.total = value; - return this; - } - /** * API name: {@code failures} + * *

* Adds all elements of list to failures. + *

*/ public final Builder failures(List list) { this.failures = _listAddAll(this.failures, list); @@ -206,8 +189,10 @@ public final Builder failures(List list) { /** * API name: {@code failures} + * *

* Adds one or more values to failures. + *

*/ public final Builder failures(ShardFailure value, ShardFailure... values) { this.failures = _listAdd(this.failures, value, values); @@ -216,8 +201,10 @@ public final Builder failures(ShardFailure value, ShardFailure... values) { /** * API name: {@code failures} + * *

* Adds a value to failures using a builder lambda. + *

*/ public final Builder failures(Function> fn) { return failures(fn.apply(new ShardFailure.Builder()).build()); @@ -226,16 +213,31 @@ public final Builder failures(Function op) { - - op.add(Builder::failed, JsonpDeserializer.numberDeserializer(), "failed"); - op.add(Builder::successful, JsonpDeserializer.numberDeserializer(), "successful"); - op.add(Builder::total, JsonpDeserializer.numberDeserializer(), "total"); + op.add(Builder::failed, JsonpDeserializer.integerDeserializer(), "failed"); op.add(Builder::failures, JsonpDeserializer.arrayDeserializer(ShardFailure._DESERIALIZER), "failures"); - op.add(Builder::skipped, JsonpDeserializer.numberDeserializer(), "skipped"); - + op.add(Builder::skipped, JsonpDeserializer.integerDeserializer(), "skipped"); + op.add(Builder::successful, JsonpDeserializer.integerDeserializer(), "successful"); + op.add(Builder::total, JsonpDeserializer.integerDeserializer(), "total"); } - } diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/_types/WriteResponseBase.java b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/WriteResponseBase.java similarity index 94% rename from java-client/src/main/java/org/opensearch/client/opensearch/_types/WriteResponseBase.java rename to java-client/src/generated/java/org/opensearch/client/opensearch/_types/WriteResponseBase.java index 27244d3539..83a031739d 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/_types/WriteResponseBase.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/WriteResponseBase.java @@ -30,10 +30,15 @@ * GitHub history for details. */ +//---------------------------------------------------- +// THIS CODE IS GENERATED. MANUAL EDITS WILL BE LOST. +//---------------------------------------------------- + package org.opensearch.client.opensearch._types; import jakarta.json.stream.JsonGenerator; import java.util.function.Function; +import javax.annotation.Generated; import javax.annotation.Nullable; import org.opensearch.client.json.JsonpDeserializer; import org.opensearch.client.json.JsonpMapper; @@ -45,7 +50,12 @@ // typedef: _types.WriteResponseBase +@Generated("org.opensearch.client.codegen.CodeGenerator") public abstract class WriteResponseBase implements PlainJsonSerializable { + + @Nullable + private final Boolean forcedRefresh; + private final String id; private final String index; @@ -60,13 +70,10 @@ public abstract class WriteResponseBase implements PlainJsonSerializable { private final long version; - @Nullable - private final Boolean forcedRefresh; - // --------------------------------------------------------------------------------------------- protected WriteResponseBase(AbstractBuilder builder) { - + this.forcedRefresh = builder.forcedRefresh; this.id = ApiTypeHelper.requireNonNull(builder.id, this, "id"); this.index = ApiTypeHelper.requireNonNull(builder.index, this, "index"); this.primaryTerm = ApiTypeHelper.requireNonNull(builder.primaryTerm, this, "primaryTerm"); @@ -74,8 +81,14 @@ protected WriteResponseBase(AbstractBuilder builder) { this.seqNo = ApiTypeHelper.requireNonNull(builder.seqNo, this, "seqNo"); this.shards = ApiTypeHelper.requireNonNull(builder.shards, this, "shards"); this.version = ApiTypeHelper.requireNonNull(builder.version, this, "version"); - this.forcedRefresh = builder.forcedRefresh; + } + /** + * API name: {@code forced_refresh} + */ + @Nullable + public final Boolean forcedRefresh() { + return this.forcedRefresh; } /** @@ -127,17 +140,10 @@ public final long version() { return this.version; } - /** - * API name: {@code forced_refresh} - */ - @Nullable - public final Boolean forcedRefresh() { - return this.forcedRefresh; - } - /** * Serialize this object to JSON. */ + @Override public void serialize(JsonGenerator generator, JsonpMapper mapper) { generator.writeStartObject(); serializeInternal(generator, mapper); @@ -145,6 +151,10 @@ public void serialize(JsonGenerator generator, JsonpMapper mapper) { } protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { + if (this.forcedRefresh != null) { + generator.writeKey("forced_refresh"); + generator.write(this.forcedRefresh); + } generator.writeKey("_id"); generator.write(this.id); @@ -157,6 +167,7 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { generator.writeKey("result"); this.result.serialize(generator, mapper); + generator.writeKey("_seq_no"); generator.write(this.seqNo); @@ -165,32 +176,28 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { generator.writeKey("_version"); generator.write(this.version); - - if (this.forcedRefresh != null) { - generator.writeKey("forced_refresh"); - generator.write(this.forcedRefresh); - - } - } + // --------------------------------------------------------------------------------------------- + protected abstract static class AbstractBuilder> extends ObjectBuilderBase { + @Nullable + private Boolean forcedRefresh; private String id; - private String index; - private Long primaryTerm; - private Result result; - private Long seqNo; - private ShardStatistics shards; - private Long version; - @Nullable - private Boolean forcedRefresh; + /** + * API name: {@code forced_refresh} + */ + public final BuilderT forcedRefresh(@Nullable Boolean value) { + this.forcedRefresh = value; + return self(); + } /** * Required - API name: {@code _id} @@ -244,7 +251,7 @@ public final BuilderT shards(ShardStatistics value) { * Required - API name: {@code _shards} */ public final BuilderT shards(Function> fn) { - return this.shards(fn.apply(new ShardStatistics.Builder()).build()); + return shards(fn.apply(new ShardStatistics.Builder()).build()); } /** @@ -255,21 +262,12 @@ public final BuilderT version(long value) { return self(); } - /** - * API name: {@code forced_refresh} - */ - public final BuilderT forcedRefresh(@Nullable Boolean value) { - this.forcedRefresh = value; - return self(); - } - protected abstract BuilderT self(); - } - // --------------------------------------------------------------------------------------------- - protected static > void setupWriteResponseBaseDeserializer(ObjectDeserializer op) { + protected static > void setupWriteResponseBaseDeserializer(ObjectDeserializer op) { + op.add(AbstractBuilder::forcedRefresh, JsonpDeserializer.booleanDeserializer(), "forced_refresh"); op.add(AbstractBuilder::id, JsonpDeserializer.stringDeserializer(), "_id"); op.add(AbstractBuilder::index, JsonpDeserializer.stringDeserializer(), "_index"); op.add(AbstractBuilder::primaryTerm, JsonpDeserializer.longDeserializer(), "_primary_term"); @@ -277,8 +275,5 @@ protected static > void setupWriteRes op.add(AbstractBuilder::seqNo, JsonpDeserializer.longDeserializer(), "_seq_no"); op.add(AbstractBuilder::shards, ShardStatistics._DESERIALIZER, "_shards"); op.add(AbstractBuilder::version, JsonpDeserializer.longDeserializer(), "_version"); - op.add(AbstractBuilder::forcedRefresh, JsonpDeserializer.booleanDeserializer(), "forced_refresh"); - } - } diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeleteModelGroupRequest.java b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeleteModelGroupRequest.java new file mode 100644 index 0000000000..181a605275 --- /dev/null +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeleteModelGroupRequest.java @@ -0,0 +1,101 @@ +/* + * 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. + */ + +//---------------------------------------------------- +// THIS CODE IS GENERATED. MANUAL EDITS WILL BE LOST. +//---------------------------------------------------- + +package org.opensearch.client.opensearch.ml; + +import java.util.function.Function; +import javax.annotation.Generated; +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; + +// typedef: ml.delete_model_group.Request + +/** + * Deletes a model group. + */ +@Generated("org.opensearch.client.codegen.CodeGenerator") +public class DeleteModelGroupRequest extends RequestBase { + + private final String modelGroupId; + + // --------------------------------------------------------------------------------------------- + + private DeleteModelGroupRequest(Builder builder) { + this.modelGroupId = ApiTypeHelper.requireNonNull(builder.modelGroupId, this, "modelGroupId"); + } + + public static DeleteModelGroupRequest of(Function> fn) { + return fn.apply(new Builder()).build(); + } + + /** + * Required - API name: {@code model_group_id} + */ + public final String modelGroupId() { + return this.modelGroupId; + } + + // --------------------------------------------------------------------------------------------- + + /** + * Builder for {@link DeleteModelGroupRequest}. + */ + public static class Builder extends ObjectBuilderBase implements ObjectBuilder { + private String modelGroupId; + + /** + * Required - API name: {@code model_group_id} + */ + public final Builder modelGroupId(String value) { + this.modelGroupId = value; + return this; + } + + /** + * Builds a {@link DeleteModelGroupRequest}. + * + * @throws NullPointerException if some of the required fields are null. + */ + public DeleteModelGroupRequest build() { + _checkSingleUse(); + + return new DeleteModelGroupRequest(this); + } + } + + // --------------------------------------------------------------------------------------------- + + /** + * Endpoint "{@code ml.delete_model_group}". + */ + public static final Endpoint _ENDPOINT = new SimpleEndpoint<>( + // Request method + request -> "DELETE", + // Request path + request -> { + StringBuilder buf = new StringBuilder(); + buf.append("/_plugins/_ml/model_groups/"); + SimpleEndpoint.pathEncode(request.modelGroupId, buf); + return buf.toString(); + }, + // Request parameters + SimpleEndpoint.emptyMap(), + SimpleEndpoint.emptyMap(), + false, + DeleteModelGroupResponse._DESERIALIZER + ); +} diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeleteModelGroupResponse.java b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeleteModelGroupResponse.java new file mode 100644 index 0000000000..d46916f638 --- /dev/null +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeleteModelGroupResponse.java @@ -0,0 +1,75 @@ +/* + * 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. + */ + +//---------------------------------------------------- +// THIS CODE IS GENERATED. MANUAL EDITS WILL BE LOST. +//---------------------------------------------------- + +package org.opensearch.client.opensearch.ml; + +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; +import org.opensearch.client.json.ObjectDeserializer; +import org.opensearch.client.opensearch._types.WriteResponseBase; +import org.opensearch.client.util.ObjectBuilder; + +// typedef: ml.delete_model_group.Response + +@JsonpDeserializable +@Generated("org.opensearch.client.codegen.CodeGenerator") +public class DeleteModelGroupResponse extends WriteResponseBase { + + // --------------------------------------------------------------------------------------------- + + private DeleteModelGroupResponse(Builder builder) { + super(builder); + } + + public static DeleteModelGroupResponse of(Function> fn) { + return fn.apply(new Builder()).build(); + } + + // --------------------------------------------------------------------------------------------- + + /** + * Builder for {@link DeleteModelGroupResponse}. + */ + public static class Builder extends WriteResponseBase.AbstractBuilder implements ObjectBuilder { + @Override + protected Builder self() { + return this; + } + + /** + * Builds a {@link DeleteModelGroupResponse}. + * + * @throws NullPointerException if some of the required fields are null. + */ + public DeleteModelGroupResponse build() { + _checkSingleUse(); + + return new DeleteModelGroupResponse(this); + } + } + // --------------------------------------------------------------------------------------------- + + /** + * Json deserializer for {@link DeleteModelGroupResponse} + */ + public static final JsonpDeserializer _DESERIALIZER = ObjectBuilderDeserializer.lazy( + Builder::new, + DeleteModelGroupResponse::setupDeleteModelGroupResponseDeserializer + ); + + protected static void setupDeleteModelGroupResponseDeserializer(ObjectDeserializer op) { + WriteResponseBase.setupWriteResponseBaseDeserializer(op); + } +} diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeleteModelRequest.java b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeleteModelRequest.java new file mode 100644 index 0000000000..f9be99c118 --- /dev/null +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeleteModelRequest.java @@ -0,0 +1,101 @@ +/* + * 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. + */ + +//---------------------------------------------------- +// THIS CODE IS GENERATED. MANUAL EDITS WILL BE LOST. +//---------------------------------------------------- + +package org.opensearch.client.opensearch.ml; + +import java.util.function.Function; +import javax.annotation.Generated; +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; + +// typedef: ml.delete_model.Request + +/** + * Deletes a model. + */ +@Generated("org.opensearch.client.codegen.CodeGenerator") +public class DeleteModelRequest extends RequestBase { + + private final String modelId; + + // --------------------------------------------------------------------------------------------- + + private DeleteModelRequest(Builder builder) { + this.modelId = ApiTypeHelper.requireNonNull(builder.modelId, this, "modelId"); + } + + public static DeleteModelRequest of(Function> fn) { + return fn.apply(new Builder()).build(); + } + + /** + * Required - API name: {@code model_id} + */ + public final String modelId() { + return this.modelId; + } + + // --------------------------------------------------------------------------------------------- + + /** + * Builder for {@link DeleteModelRequest}. + */ + public static class Builder extends ObjectBuilderBase implements ObjectBuilder { + private String modelId; + + /** + * Required - API name: {@code model_id} + */ + public final Builder modelId(String value) { + this.modelId = value; + return this; + } + + /** + * Builds a {@link DeleteModelRequest}. + * + * @throws NullPointerException if some of the required fields are null. + */ + public DeleteModelRequest build() { + _checkSingleUse(); + + return new DeleteModelRequest(this); + } + } + + // --------------------------------------------------------------------------------------------- + + /** + * Endpoint "{@code ml.delete_model}". + */ + public static final Endpoint _ENDPOINT = new SimpleEndpoint<>( + // Request method + request -> "DELETE", + // Request path + request -> { + StringBuilder buf = new StringBuilder(); + buf.append("/_plugins/_ml/models/"); + SimpleEndpoint.pathEncode(request.modelId, buf); + return buf.toString(); + }, + // Request parameters + SimpleEndpoint.emptyMap(), + SimpleEndpoint.emptyMap(), + false, + DeleteModelResponse._DESERIALIZER + ); +} diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeleteModelResponse.java b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeleteModelResponse.java new file mode 100644 index 0000000000..dcf77c93aa --- /dev/null +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeleteModelResponse.java @@ -0,0 +1,75 @@ +/* + * 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. + */ + +//---------------------------------------------------- +// THIS CODE IS GENERATED. MANUAL EDITS WILL BE LOST. +//---------------------------------------------------- + +package org.opensearch.client.opensearch.ml; + +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; +import org.opensearch.client.json.ObjectDeserializer; +import org.opensearch.client.opensearch._types.WriteResponseBase; +import org.opensearch.client.util.ObjectBuilder; + +// typedef: ml.delete_model.Response + +@JsonpDeserializable +@Generated("org.opensearch.client.codegen.CodeGenerator") +public class DeleteModelResponse extends WriteResponseBase { + + // --------------------------------------------------------------------------------------------- + + private DeleteModelResponse(Builder builder) { + super(builder); + } + + public static DeleteModelResponse of(Function> fn) { + return fn.apply(new Builder()).build(); + } + + // --------------------------------------------------------------------------------------------- + + /** + * Builder for {@link DeleteModelResponse}. + */ + public static class Builder extends WriteResponseBase.AbstractBuilder implements ObjectBuilder { + @Override + protected Builder self() { + return this; + } + + /** + * Builds a {@link DeleteModelResponse}. + * + * @throws NullPointerException if some of the required fields are null. + */ + public DeleteModelResponse build() { + _checkSingleUse(); + + return new DeleteModelResponse(this); + } + } + // --------------------------------------------------------------------------------------------- + + /** + * Json deserializer for {@link DeleteModelResponse} + */ + public static final JsonpDeserializer _DESERIALIZER = ObjectBuilderDeserializer.lazy( + Builder::new, + DeleteModelResponse::setupDeleteModelResponseDeserializer + ); + + protected static void setupDeleteModelResponseDeserializer(ObjectDeserializer op) { + WriteResponseBase.setupWriteResponseBaseDeserializer(op); + } +} diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeleteTaskRequest.java b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeleteTaskRequest.java new file mode 100644 index 0000000000..a378f83fde --- /dev/null +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeleteTaskRequest.java @@ -0,0 +1,101 @@ +/* + * 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. + */ + +//---------------------------------------------------- +// THIS CODE IS GENERATED. MANUAL EDITS WILL BE LOST. +//---------------------------------------------------- + +package org.opensearch.client.opensearch.ml; + +import java.util.function.Function; +import javax.annotation.Generated; +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; + +// typedef: ml.delete_task.Request + +/** + * Deletes a task. + */ +@Generated("org.opensearch.client.codegen.CodeGenerator") +public class DeleteTaskRequest extends RequestBase { + + private final String taskId; + + // --------------------------------------------------------------------------------------------- + + private DeleteTaskRequest(Builder builder) { + this.taskId = ApiTypeHelper.requireNonNull(builder.taskId, this, "taskId"); + } + + public static DeleteTaskRequest of(Function> fn) { + return fn.apply(new Builder()).build(); + } + + /** + * Required - API name: {@code task_id} + */ + public final String taskId() { + return this.taskId; + } + + // --------------------------------------------------------------------------------------------- + + /** + * Builder for {@link DeleteTaskRequest}. + */ + public static class Builder extends ObjectBuilderBase implements ObjectBuilder { + private String taskId; + + /** + * Required - API name: {@code task_id} + */ + public final Builder taskId(String value) { + this.taskId = value; + return this; + } + + /** + * Builds a {@link DeleteTaskRequest}. + * + * @throws NullPointerException if some of the required fields are null. + */ + public DeleteTaskRequest build() { + _checkSingleUse(); + + return new DeleteTaskRequest(this); + } + } + + // --------------------------------------------------------------------------------------------- + + /** + * Endpoint "{@code ml.delete_task}". + */ + public static final Endpoint _ENDPOINT = new SimpleEndpoint<>( + // Request method + request -> "DELETE", + // Request path + request -> { + StringBuilder buf = new StringBuilder(); + buf.append("/_plugins/_ml/tasks/"); + SimpleEndpoint.pathEncode(request.taskId, buf); + return buf.toString(); + }, + // Request parameters + SimpleEndpoint.emptyMap(), + SimpleEndpoint.emptyMap(), + false, + DeleteTaskResponse._DESERIALIZER + ); +} diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeleteTaskResponse.java b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeleteTaskResponse.java new file mode 100644 index 0000000000..f6d5e8c95d --- /dev/null +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeleteTaskResponse.java @@ -0,0 +1,75 @@ +/* + * 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. + */ + +//---------------------------------------------------- +// THIS CODE IS GENERATED. MANUAL EDITS WILL BE LOST. +//---------------------------------------------------- + +package org.opensearch.client.opensearch.ml; + +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; +import org.opensearch.client.json.ObjectDeserializer; +import org.opensearch.client.opensearch._types.WriteResponseBase; +import org.opensearch.client.util.ObjectBuilder; + +// typedef: ml.delete_task.Response + +@JsonpDeserializable +@Generated("org.opensearch.client.codegen.CodeGenerator") +public class DeleteTaskResponse extends WriteResponseBase { + + // --------------------------------------------------------------------------------------------- + + private DeleteTaskResponse(Builder builder) { + super(builder); + } + + public static DeleteTaskResponse of(Function> fn) { + return fn.apply(new Builder()).build(); + } + + // --------------------------------------------------------------------------------------------- + + /** + * Builder for {@link DeleteTaskResponse}. + */ + public static class Builder extends WriteResponseBase.AbstractBuilder implements ObjectBuilder { + @Override + protected Builder self() { + return this; + } + + /** + * Builds a {@link DeleteTaskResponse}. + * + * @throws NullPointerException if some of the required fields are null. + */ + public DeleteTaskResponse build() { + _checkSingleUse(); + + return new DeleteTaskResponse(this); + } + } + // --------------------------------------------------------------------------------------------- + + /** + * Json deserializer for {@link DeleteTaskResponse} + */ + public static final JsonpDeserializer _DESERIALIZER = ObjectBuilderDeserializer.lazy( + Builder::new, + DeleteTaskResponse::setupDeleteTaskResponseDeserializer + ); + + protected static void setupDeleteTaskResponseDeserializer(ObjectDeserializer op) { + WriteResponseBase.setupWriteResponseBaseDeserializer(op); + } +} diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeployModelRequest.java b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeployModelRequest.java new file mode 100644 index 0000000000..2230cb1d82 --- /dev/null +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeployModelRequest.java @@ -0,0 +1,102 @@ +/* + * 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. + */ + +//---------------------------------------------------- +// THIS CODE IS GENERATED. MANUAL EDITS WILL BE LOST. +//---------------------------------------------------- + +package org.opensearch.client.opensearch.ml; + +import java.util.function.Function; +import javax.annotation.Generated; +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; + +// typedef: ml.deploy_model.Request + +/** + * Deploys a model. + */ +@Generated("org.opensearch.client.codegen.CodeGenerator") +public class DeployModelRequest extends RequestBase { + + private final String modelId; + + // --------------------------------------------------------------------------------------------- + + private DeployModelRequest(Builder builder) { + this.modelId = ApiTypeHelper.requireNonNull(builder.modelId, this, "modelId"); + } + + public static DeployModelRequest of(Function> fn) { + return fn.apply(new Builder()).build(); + } + + /** + * Required - API name: {@code model_id} + */ + public final String modelId() { + return this.modelId; + } + + // --------------------------------------------------------------------------------------------- + + /** + * Builder for {@link DeployModelRequest}. + */ + public static class Builder extends ObjectBuilderBase implements ObjectBuilder { + private String modelId; + + /** + * Required - API name: {@code model_id} + */ + public final Builder modelId(String value) { + this.modelId = value; + return this; + } + + /** + * Builds a {@link DeployModelRequest}. + * + * @throws NullPointerException if some of the required fields are null. + */ + public DeployModelRequest build() { + _checkSingleUse(); + + return new DeployModelRequest(this); + } + } + + // --------------------------------------------------------------------------------------------- + + /** + * Endpoint "{@code ml.deploy_model}". + */ + public static final Endpoint _ENDPOINT = new SimpleEndpoint<>( + // Request method + request -> "POST", + // Request path + request -> { + StringBuilder buf = new StringBuilder(); + buf.append("/_plugins/_ml/models/"); + SimpleEndpoint.pathEncode(request.modelId, buf); + buf.append("/_deploy"); + return buf.toString(); + }, + // Request parameters + SimpleEndpoint.emptyMap(), + SimpleEndpoint.emptyMap(), + false, + DeployModelResponse._DESERIALIZER + ); +} diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeployModelResponse.java b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeployModelResponse.java new file mode 100644 index 0000000000..6ba333cde4 --- /dev/null +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/DeployModelResponse.java @@ -0,0 +1,160 @@ +/* + * 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. + */ + +//---------------------------------------------------- +// THIS CODE IS GENERATED. MANUAL EDITS WILL BE LOST. +//---------------------------------------------------- + +package org.opensearch.client.opensearch.ml; + +import jakarta.json.stream.JsonGenerator; +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; +import org.opensearch.client.json.JsonpMapper; +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: ml.deploy_model.Response + +@JsonpDeserializable +@Generated("org.opensearch.client.codegen.CodeGenerator") +public class DeployModelResponse implements PlainJsonSerializable { + + private final String status; + + private final String taskId; + + @Nullable + private final String taskType; + + // --------------------------------------------------------------------------------------------- + + private DeployModelResponse(Builder builder) { + this.status = ApiTypeHelper.requireNonNull(builder.status, this, "status"); + this.taskId = ApiTypeHelper.requireNonNull(builder.taskId, this, "taskId"); + this.taskType = builder.taskType; + } + + public static DeployModelResponse of(Function> fn) { + return fn.apply(new Builder()).build(); + } + + /** + * Required - API name: {@code status} + */ + public final String status() { + return this.status; + } + + /** + * Required - API name: {@code task_id} + */ + public final String taskId() { + return this.taskId; + } + + /** + * API name: {@code task_type} + */ + @Nullable + public final String taskType() { + return this.taskType; + } + + /** + * Serialize this object to JSON. + */ + @Override + public void serialize(JsonGenerator generator, JsonpMapper mapper) { + generator.writeStartObject(); + serializeInternal(generator, mapper); + generator.writeEnd(); + } + + protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { + generator.writeKey("status"); + generator.write(this.status); + + generator.writeKey("task_id"); + generator.write(this.taskId); + + if (this.taskType != null) { + generator.writeKey("task_type"); + generator.write(this.taskType); + } + } + + // --------------------------------------------------------------------------------------------- + + /** + * Builder for {@link DeployModelResponse}. + */ + public static class Builder extends ObjectBuilderBase implements ObjectBuilder { + private String status; + private String taskId; + @Nullable + private String taskType; + + /** + * Required - API name: {@code status} + */ + public final Builder status(String value) { + this.status = value; + return this; + } + + /** + * Required - API name: {@code task_id} + */ + public final Builder taskId(String value) { + this.taskId = value; + return this; + } + + /** + * API name: {@code task_type} + */ + public final Builder taskType(@Nullable String value) { + this.taskType = value; + return this; + } + + /** + * Builds a {@link DeployModelResponse}. + * + * @throws NullPointerException if some of the required fields are null. + */ + public DeployModelResponse build() { + _checkSingleUse(); + + return new DeployModelResponse(this); + } + } + // --------------------------------------------------------------------------------------------- + + /** + * Json deserializer for {@link DeployModelResponse} + */ + public static final JsonpDeserializer _DESERIALIZER = ObjectBuilderDeserializer.lazy( + Builder::new, + DeployModelResponse::setupDeployModelResponseDeserializer + ); + + protected static void setupDeployModelResponseDeserializer(ObjectDeserializer op) { + op.add(Builder::status, JsonpDeserializer.stringDeserializer(), "status"); + op.add(Builder::taskId, JsonpDeserializer.stringDeserializer(), "task_id"); + op.add(Builder::taskType, JsonpDeserializer.stringDeserializer(), "task_type"); + } +} diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/GetModelGroupRequest.java b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/GetModelGroupRequest.java new file mode 100644 index 0000000000..92c6537dc9 --- /dev/null +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/GetModelGroupRequest.java @@ -0,0 +1,101 @@ +/* + * 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. + */ + +//---------------------------------------------------- +// THIS CODE IS GENERATED. MANUAL EDITS WILL BE LOST. +//---------------------------------------------------- + +package org.opensearch.client.opensearch.ml; + +import java.util.function.Function; +import javax.annotation.Generated; +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; + +// typedef: ml.get_model_group.Request + +/** + * Retrieves a model group. + */ +@Generated("org.opensearch.client.codegen.CodeGenerator") +public class GetModelGroupRequest extends RequestBase { + + private final String modelGroupId; + + // --------------------------------------------------------------------------------------------- + + private GetModelGroupRequest(Builder builder) { + this.modelGroupId = ApiTypeHelper.requireNonNull(builder.modelGroupId, this, "modelGroupId"); + } + + public static GetModelGroupRequest of(Function> fn) { + return fn.apply(new Builder()).build(); + } + + /** + * Required - API name: {@code model_group_id} + */ + public final String modelGroupId() { + return this.modelGroupId; + } + + // --------------------------------------------------------------------------------------------- + + /** + * Builder for {@link GetModelGroupRequest}. + */ + public static class Builder extends ObjectBuilderBase implements ObjectBuilder { + private String modelGroupId; + + /** + * Required - API name: {@code model_group_id} + */ + public final Builder modelGroupId(String value) { + this.modelGroupId = value; + return this; + } + + /** + * Builds a {@link GetModelGroupRequest}. + * + * @throws NullPointerException if some of the required fields are null. + */ + public GetModelGroupRequest build() { + _checkSingleUse(); + + return new GetModelGroupRequest(this); + } + } + + // --------------------------------------------------------------------------------------------- + + /** + * Endpoint "{@code ml.get_model_group}". + */ + public static final Endpoint _ENDPOINT = new SimpleEndpoint<>( + // Request method + request -> "GET", + // Request path + request -> { + StringBuilder buf = new StringBuilder(); + buf.append("/_plugins/_ml/model_groups/"); + SimpleEndpoint.pathEncode(request.modelGroupId, buf); + return buf.toString(); + }, + // Request parameters + SimpleEndpoint.emptyMap(), + SimpleEndpoint.emptyMap(), + false, + GetModelGroupResponse._DESERIALIZER + ); +} diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/GetModelGroupResponse.java b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/GetModelGroupResponse.java new file mode 100644 index 0000000000..4a8321c607 --- /dev/null +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/GetModelGroupResponse.java @@ -0,0 +1,258 @@ +/* + * 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. + */ + +//---------------------------------------------------- +// THIS CODE IS GENERATED. MANUAL EDITS WILL BE LOST. +//---------------------------------------------------- + +package org.opensearch.client.opensearch.ml; + +import jakarta.json.stream.JsonGenerator; +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; +import org.opensearch.client.json.JsonpMapper; +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: ml.get_model_group.Response + +@JsonpDeserializable +@Generated("org.opensearch.client.codegen.CodeGenerator") +public class GetModelGroupResponse implements PlainJsonSerializable { + + private final String access; + + @Nullable + private final Long createdTime; + + private final String description; + + @Nullable + private final Long lastUpdatedTime; + + private final int latestVersion; + + private final String name; + + // --------------------------------------------------------------------------------------------- + + private GetModelGroupResponse(Builder builder) { + this.access = ApiTypeHelper.requireNonNull(builder.access, this, "access"); + this.createdTime = builder.createdTime; + this.description = ApiTypeHelper.requireNonNull(builder.description, this, "description"); + this.lastUpdatedTime = builder.lastUpdatedTime; + this.latestVersion = ApiTypeHelper.requireNonNull(builder.latestVersion, this, "latestVersion"); + this.name = ApiTypeHelper.requireNonNull(builder.name, this, "name"); + } + + public static GetModelGroupResponse of(Function> fn) { + return fn.apply(new Builder()).build(); + } + + /** + * Required - The model group access. + *

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

+ */ + public final String access() { + return this.access; + } + + /** + * API name: {@code created_time} + */ + @Nullable + public final Long createdTime() { + return this.createdTime; + } + + /** + * Required - The model group description. + *

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

+ */ + public final String description() { + return this.description; + } + + /** + * API name: {@code last_updated_time} + */ + @Nullable + public final Long lastUpdatedTime() { + return this.lastUpdatedTime; + } + + /** + * Required - The latest version. + *

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

+ */ + public final int latestVersion() { + return this.latestVersion; + } + + /** + * Required - The model group name. + *

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

+ */ + public final String name() { + return this.name; + } + + /** + * Serialize this object to JSON. + */ + @Override + public void serialize(JsonGenerator generator, JsonpMapper mapper) { + generator.writeStartObject(); + serializeInternal(generator, mapper); + generator.writeEnd(); + } + + protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { + generator.writeKey("access"); + generator.write(this.access); + + if (this.createdTime != null) { + generator.writeKey("created_time"); + generator.write(this.createdTime); + } + + generator.writeKey("description"); + generator.write(this.description); + + if (this.lastUpdatedTime != null) { + generator.writeKey("last_updated_time"); + generator.write(this.lastUpdatedTime); + } + + generator.writeKey("latest_version"); + generator.write(this.latestVersion); + + generator.writeKey("name"); + generator.write(this.name); + } + + // --------------------------------------------------------------------------------------------- + + /** + * Builder for {@link GetModelGroupResponse}. + */ + public static class Builder extends ObjectBuilderBase implements ObjectBuilder { + private String access; + @Nullable + private Long createdTime; + private String description; + @Nullable + private Long lastUpdatedTime; + private Integer latestVersion; + private String name; + + /** + * Required - The model group access. + *

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

+ */ + public final Builder access(String value) { + this.access = value; + return this; + } + + /** + * API name: {@code created_time} + */ + public final Builder createdTime(@Nullable Long value) { + this.createdTime = value; + return this; + } + + /** + * Required - The model group description. + *

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

+ */ + public final Builder description(String value) { + this.description = value; + return this; + } + + /** + * API name: {@code last_updated_time} + */ + public final Builder lastUpdatedTime(@Nullable Long value) { + this.lastUpdatedTime = value; + return this; + } + + /** + * Required - The latest version. + *

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

+ */ + public final Builder latestVersion(int value) { + this.latestVersion = value; + return this; + } + + /** + * Required - The model group name. + *

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

+ */ + public final Builder name(String value) { + this.name = value; + return this; + } + + /** + * Builds a {@link GetModelGroupResponse}. + * + * @throws NullPointerException if some of the required fields are null. + */ + public GetModelGroupResponse build() { + _checkSingleUse(); + + return new GetModelGroupResponse(this); + } + } + // --------------------------------------------------------------------------------------------- + + /** + * Json deserializer for {@link GetModelGroupResponse} + */ + public static final JsonpDeserializer _DESERIALIZER = ObjectBuilderDeserializer.lazy( + Builder::new, + GetModelGroupResponse::setupGetModelGroupResponseDeserializer + ); + + protected static void setupGetModelGroupResponseDeserializer(ObjectDeserializer op) { + op.add(Builder::access, JsonpDeserializer.stringDeserializer(), "access"); + op.add(Builder::createdTime, JsonpDeserializer.longDeserializer(), "created_time"); + op.add(Builder::description, JsonpDeserializer.stringDeserializer(), "description"); + op.add(Builder::lastUpdatedTime, JsonpDeserializer.longDeserializer(), "last_updated_time"); + op.add(Builder::latestVersion, JsonpDeserializer.integerDeserializer(), "latest_version"); + op.add(Builder::name, JsonpDeserializer.stringDeserializer(), "name"); + } +} diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/GetTaskRequest.java b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/GetTaskRequest.java new file mode 100644 index 0000000000..55f09a5df6 --- /dev/null +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/GetTaskRequest.java @@ -0,0 +1,101 @@ +/* + * 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. + */ + +//---------------------------------------------------- +// THIS CODE IS GENERATED. MANUAL EDITS WILL BE LOST. +//---------------------------------------------------- + +package org.opensearch.client.opensearch.ml; + +import java.util.function.Function; +import javax.annotation.Generated; +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; + +// typedef: ml.get_task.Request + +/** + * Retrieves a task. + */ +@Generated("org.opensearch.client.codegen.CodeGenerator") +public class GetTaskRequest extends RequestBase { + + private final String taskId; + + // --------------------------------------------------------------------------------------------- + + private GetTaskRequest(Builder builder) { + this.taskId = ApiTypeHelper.requireNonNull(builder.taskId, this, "taskId"); + } + + public static GetTaskRequest of(Function> fn) { + return fn.apply(new Builder()).build(); + } + + /** + * Required - API name: {@code task_id} + */ + public final String taskId() { + return this.taskId; + } + + // --------------------------------------------------------------------------------------------- + + /** + * Builder for {@link GetTaskRequest}. + */ + public static class Builder extends ObjectBuilderBase implements ObjectBuilder { + private String taskId; + + /** + * Required - API name: {@code task_id} + */ + public final Builder taskId(String value) { + this.taskId = value; + return this; + } + + /** + * Builds a {@link GetTaskRequest}. + * + * @throws NullPointerException if some of the required fields are null. + */ + public GetTaskRequest build() { + _checkSingleUse(); + + return new GetTaskRequest(this); + } + } + + // --------------------------------------------------------------------------------------------- + + /** + * Endpoint "{@code ml.get_task}". + */ + public static final Endpoint _ENDPOINT = new SimpleEndpoint<>( + // Request method + request -> "GET", + // Request path + request -> { + StringBuilder buf = new StringBuilder(); + buf.append("/_plugins/_ml/tasks/"); + SimpleEndpoint.pathEncode(request.taskId, buf); + return buf.toString(); + }, + // Request parameters + SimpleEndpoint.emptyMap(), + SimpleEndpoint.emptyMap(), + false, + GetTaskResponse._DESERIALIZER + ); +} diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/GetTaskResponse.java b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/GetTaskResponse.java new file mode 100644 index 0000000000..610b2c1cb4 --- /dev/null +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/GetTaskResponse.java @@ -0,0 +1,394 @@ +/* + * 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. + */ + +//---------------------------------------------------- +// THIS CODE IS GENERATED. MANUAL EDITS WILL BE LOST. +//---------------------------------------------------- + +package org.opensearch.client.opensearch.ml; + +import jakarta.json.stream.JsonGenerator; +import java.util.List; +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; +import org.opensearch.client.json.JsonpMapper; +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: ml.get_task.Response + +@JsonpDeserializable +@Generated("org.opensearch.client.codegen.CodeGenerator") +public class GetTaskResponse implements PlainJsonSerializable { + + @Nullable + private final Long createTime; + + @Nullable + private final String error; + + @Nullable + private final String functionName; + + @Nullable + private final Boolean isAsync; + + @Nullable + private final Long lastUpdateTime; + + @Nullable + private final String modelId; + + private final String state; + + @Nullable + private final String taskId; + + @Nullable + private final String taskType; + + private final List> workerNode; + + // --------------------------------------------------------------------------------------------- + + private GetTaskResponse(Builder builder) { + this.createTime = builder.createTime; + this.error = builder.error; + this.functionName = builder.functionName; + this.isAsync = builder.isAsync; + this.lastUpdateTime = builder.lastUpdateTime; + this.modelId = builder.modelId; + this.state = ApiTypeHelper.requireNonNull(builder.state, this, "state"); + this.taskId = builder.taskId; + this.taskType = builder.taskType; + this.workerNode = ApiTypeHelper.unmodifiable(builder.workerNode); + } + + public static GetTaskResponse of(Function> fn) { + return fn.apply(new Builder()).build(); + } + + /** + * API name: {@code create_time} + */ + @Nullable + public final Long createTime() { + return this.createTime; + } + + /** + * API name: {@code error} + */ + @Nullable + public final String error() { + return this.error; + } + + /** + * API name: {@code function_name} + */ + @Nullable + public final String functionName() { + return this.functionName; + } + + /** + * API name: {@code is_async} + */ + @Nullable + public final Boolean isAsync() { + return this.isAsync; + } + + /** + * API name: {@code last_update_time} + */ + @Nullable + public final Long lastUpdateTime() { + return this.lastUpdateTime; + } + + /** + * API name: {@code model_id} + */ + @Nullable + public final String modelId() { + return this.modelId; + } + + /** + * Required - API name: {@code state} + */ + public final String state() { + return this.state; + } + + /** + * API name: {@code task_id} + */ + @Nullable + public final String taskId() { + return this.taskId; + } + + /** + * Task type. + *

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

+ */ + @Nullable + public final String taskType() { + return this.taskType; + } + + /** + * API name: {@code worker_node} + */ + public final List> workerNode() { + return this.workerNode; + } + + /** + * Serialize this object to JSON. + */ + @Override + public void serialize(JsonGenerator generator, JsonpMapper mapper) { + generator.writeStartObject(); + serializeInternal(generator, mapper); + generator.writeEnd(); + } + + protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { + if (this.createTime != null) { + generator.writeKey("create_time"); + generator.write(this.createTime); + } + + if (this.error != null) { + generator.writeKey("error"); + generator.write(this.error); + } + + if (this.functionName != null) { + generator.writeKey("function_name"); + generator.write(this.functionName); + } + + if (this.isAsync != null) { + generator.writeKey("is_async"); + generator.write(this.isAsync); + } + + if (this.lastUpdateTime != null) { + generator.writeKey("last_update_time"); + generator.write(this.lastUpdateTime); + } + + if (this.modelId != null) { + generator.writeKey("model_id"); + generator.write(this.modelId); + } + + generator.writeKey("state"); + generator.write(this.state); + + if (this.taskId != null) { + generator.writeKey("task_id"); + generator.write(this.taskId); + } + + if (this.taskType != null) { + generator.writeKey("task_type"); + generator.write(this.taskType); + } + + if (ApiTypeHelper.isDefined(this.workerNode)) { + generator.writeKey("worker_node"); + generator.writeStartArray(); + for (List item0 : this.workerNode) { + generator.writeStartArray(); + for (String item1 : item0) { + generator.write(item1); + } + generator.writeEnd(); + } + generator.writeEnd(); + } + } + + // --------------------------------------------------------------------------------------------- + + /** + * Builder for {@link GetTaskResponse}. + */ + public static class Builder extends ObjectBuilderBase implements ObjectBuilder { + @Nullable + private Long createTime; + @Nullable + private String error; + @Nullable + private String functionName; + @Nullable + private Boolean isAsync; + @Nullable + private Long lastUpdateTime; + @Nullable + private String modelId; + private String state; + @Nullable + private String taskId; + @Nullable + private String taskType; + @Nullable + private List> workerNode; + + /** + * API name: {@code create_time} + */ + public final Builder createTime(@Nullable Long value) { + this.createTime = value; + return this; + } + + /** + * API name: {@code error} + */ + public final Builder error(@Nullable String value) { + this.error = value; + return this; + } + + /** + * API name: {@code function_name} + */ + public final Builder functionName(@Nullable String value) { + this.functionName = value; + return this; + } + + /** + * API name: {@code is_async} + */ + public final Builder isAsync(@Nullable Boolean value) { + this.isAsync = value; + return this; + } + + /** + * API name: {@code last_update_time} + */ + public final Builder lastUpdateTime(@Nullable Long value) { + this.lastUpdateTime = value; + return this; + } + + /** + * API name: {@code model_id} + */ + public final Builder modelId(@Nullable String value) { + this.modelId = value; + return this; + } + + /** + * Required - API name: {@code state} + */ + public final Builder state(String value) { + this.state = value; + return this; + } + + /** + * API name: {@code task_id} + */ + public final Builder taskId(@Nullable String value) { + this.taskId = value; + return this; + } + + /** + * Task type. + *

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

+ */ + public final Builder taskType(@Nullable String value) { + this.taskType = value; + return this; + } + + /** + * API name: {@code worker_node} + * + *

+ * Adds all elements of list to workerNode. + *

+ */ + public final Builder workerNode(List> list) { + this.workerNode = _listAddAll(this.workerNode, list); + return this; + } + + /** + * API name: {@code worker_node} + * + *

+ * Adds one or more values to workerNode. + *

+ */ + public final Builder workerNode(List value, List... values) { + this.workerNode = _listAdd(this.workerNode, value, values); + return this; + } + + /** + * Builds a {@link GetTaskResponse}. + * + * @throws NullPointerException if some of the required fields are null. + */ + public GetTaskResponse build() { + _checkSingleUse(); + + return new GetTaskResponse(this); + } + } + // --------------------------------------------------------------------------------------------- + + /** + * Json deserializer for {@link GetTaskResponse} + */ + public static final JsonpDeserializer _DESERIALIZER = ObjectBuilderDeserializer.lazy( + Builder::new, + GetTaskResponse::setupGetTaskResponseDeserializer + ); + + protected static void setupGetTaskResponseDeserializer(ObjectDeserializer op) { + op.add(Builder::createTime, JsonpDeserializer.longDeserializer(), "create_time"); + op.add(Builder::error, JsonpDeserializer.stringDeserializer(), "error"); + op.add(Builder::functionName, JsonpDeserializer.stringDeserializer(), "function_name"); + op.add(Builder::isAsync, JsonpDeserializer.booleanDeserializer(), "is_async"); + op.add(Builder::lastUpdateTime, JsonpDeserializer.longDeserializer(), "last_update_time"); + op.add(Builder::modelId, JsonpDeserializer.stringDeserializer(), "model_id"); + op.add(Builder::state, JsonpDeserializer.stringDeserializer(), "state"); + op.add(Builder::taskId, JsonpDeserializer.stringDeserializer(), "task_id"); + op.add(Builder::taskType, JsonpDeserializer.stringDeserializer(), "task_type"); + op.add( + Builder::workerNode, + JsonpDeserializer.arrayDeserializer(JsonpDeserializer.arrayDeserializer(JsonpDeserializer.stringDeserializer())), + "worker_node" + ); + } +} diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/OpenSearchMlAsyncClient.java b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/OpenSearchMlAsyncClient.java new file mode 100644 index 0000000000..8f2ab231ba --- /dev/null +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/OpenSearchMlAsyncClient.java @@ -0,0 +1,279 @@ +/* + * 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. + */ + +//---------------------------------------------------- +// THIS CODE IS GENERATED. MANUAL EDITS WILL BE LOST. +//---------------------------------------------------- + +package org.opensearch.client.opensearch.ml; + +import java.io.IOException; +import java.util.concurrent.CompletableFuture; +import java.util.function.Function; +import javax.annotation.Generated; +import javax.annotation.Nullable; +import org.opensearch.client.ApiClient; +import org.opensearch.client.opensearch._types.ErrorResponse; +import org.opensearch.client.opensearch._types.OpenSearchException; +import org.opensearch.client.transport.JsonEndpoint; +import org.opensearch.client.transport.OpenSearchTransport; +import org.opensearch.client.transport.TransportOptions; +import org.opensearch.client.util.ObjectBuilder; + +/** + * Client for the ml namespace. + */ +@Generated("org.opensearch.client.codegen.CodeGenerator") +public class OpenSearchMlAsyncClient extends ApiClient { + public OpenSearchMlAsyncClient(OpenSearchTransport transport) { + super(transport, null); + } + + public OpenSearchMlAsyncClient(OpenSearchTransport transport, @Nullable TransportOptions transportOptions) { + super(transport, transportOptions); + } + + @Override + public OpenSearchMlAsyncClient withTransportOptions(@Nullable TransportOptions transportOptions) { + return new OpenSearchMlAsyncClient(this.transport, transportOptions); + } + + // ----- Endpoint: ml.delete_model + + /** + * Deletes a model. + */ + public CompletableFuture deleteModel(DeleteModelRequest request) throws IOException, OpenSearchException { + @SuppressWarnings("unchecked") + JsonEndpoint endpoint = (JsonEndpoint< + DeleteModelRequest, + DeleteModelResponse, + ErrorResponse>) DeleteModelRequest._ENDPOINT; + + return this.transport.performRequestAsync(request, endpoint, this.transportOptions); + } + + /** + * Deletes a model. + * + * @param fn a function that initializes a builder to create the {@link DeleteModelRequest} + */ + public final CompletableFuture deleteModel( + Function> fn + ) throws IOException, OpenSearchException { + return deleteModel(fn.apply(new DeleteModelRequest.Builder()).build()); + } + + // ----- Endpoint: ml.delete_model_group + + /** + * Deletes a model group. + */ + public CompletableFuture deleteModelGroup(DeleteModelGroupRequest request) throws IOException, + OpenSearchException { + @SuppressWarnings("unchecked") + JsonEndpoint endpoint = (JsonEndpoint< + DeleteModelGroupRequest, + DeleteModelGroupResponse, + ErrorResponse>) DeleteModelGroupRequest._ENDPOINT; + + return this.transport.performRequestAsync(request, endpoint, this.transportOptions); + } + + /** + * Deletes a model group. + * + * @param fn a function that initializes a builder to create the {@link DeleteModelGroupRequest} + */ + public final CompletableFuture deleteModelGroup( + Function> fn + ) throws IOException, OpenSearchException { + return deleteModelGroup(fn.apply(new DeleteModelGroupRequest.Builder()).build()); + } + + // ----- Endpoint: ml.delete_task + + /** + * Deletes a task. + */ + public CompletableFuture deleteTask(DeleteTaskRequest request) throws IOException, OpenSearchException { + @SuppressWarnings("unchecked") + JsonEndpoint endpoint = (JsonEndpoint< + DeleteTaskRequest, + DeleteTaskResponse, + ErrorResponse>) DeleteTaskRequest._ENDPOINT; + + return this.transport.performRequestAsync(request, endpoint, this.transportOptions); + } + + /** + * Deletes a task. + * + * @param fn a function that initializes a builder to create the {@link DeleteTaskRequest} + */ + public final CompletableFuture deleteTask(Function> fn) + throws IOException, OpenSearchException { + return deleteTask(fn.apply(new DeleteTaskRequest.Builder()).build()); + } + + // ----- Endpoint: ml.deploy_model + + /** + * Deploys a model. + */ + public CompletableFuture deployModel(DeployModelRequest request) throws IOException, OpenSearchException { + @SuppressWarnings("unchecked") + JsonEndpoint endpoint = (JsonEndpoint< + DeployModelRequest, + DeployModelResponse, + ErrorResponse>) DeployModelRequest._ENDPOINT; + + return this.transport.performRequestAsync(request, endpoint, this.transportOptions); + } + + /** + * Deploys a model. + * + * @param fn a function that initializes a builder to create the {@link DeployModelRequest} + */ + public final CompletableFuture deployModel( + Function> fn + ) throws IOException, OpenSearchException { + return deployModel(fn.apply(new DeployModelRequest.Builder()).build()); + } + + // ----- Endpoint: ml.get_model_group + + /** + * Retrieves a model group. + */ + public CompletableFuture getModelGroup(GetModelGroupRequest request) throws IOException, OpenSearchException { + @SuppressWarnings("unchecked") + JsonEndpoint endpoint = (JsonEndpoint< + GetModelGroupRequest, + GetModelGroupResponse, + ErrorResponse>) GetModelGroupRequest._ENDPOINT; + + return this.transport.performRequestAsync(request, endpoint, this.transportOptions); + } + + /** + * Retrieves a model group. + * + * @param fn a function that initializes a builder to create the {@link GetModelGroupRequest} + */ + public final CompletableFuture getModelGroup( + Function> fn + ) throws IOException, OpenSearchException { + return getModelGroup(fn.apply(new GetModelGroupRequest.Builder()).build()); + } + + // ----- Endpoint: ml.get_task + + /** + * Retrieves a task. + */ + public CompletableFuture getTask(GetTaskRequest request) throws IOException, OpenSearchException { + @SuppressWarnings("unchecked") + JsonEndpoint endpoint = (JsonEndpoint< + GetTaskRequest, + GetTaskResponse, + ErrorResponse>) GetTaskRequest._ENDPOINT; + + return this.transport.performRequestAsync(request, endpoint, this.transportOptions); + } + + /** + * Retrieves a task. + * + * @param fn a function that initializes a builder to create the {@link GetTaskRequest} + */ + public final CompletableFuture getTask(Function> fn) + throws IOException, OpenSearchException { + return getTask(fn.apply(new GetTaskRequest.Builder()).build()); + } + + // ----- Endpoint: ml.register_model + + /** + * Registers a model. + */ + public CompletableFuture registerModel(RegisterModelRequest request) throws IOException, OpenSearchException { + @SuppressWarnings("unchecked") + JsonEndpoint endpoint = (JsonEndpoint< + RegisterModelRequest, + RegisterModelResponse, + ErrorResponse>) RegisterModelRequest._ENDPOINT; + + return this.transport.performRequestAsync(request, endpoint, this.transportOptions); + } + + /** + * Registers a model. + * + * @param fn a function that initializes a builder to create the {@link RegisterModelRequest} + */ + public final CompletableFuture registerModel( + Function> fn + ) throws IOException, OpenSearchException { + return registerModel(fn.apply(new RegisterModelRequest.Builder()).build()); + } + + // ----- Endpoint: ml.register_model_group + + /** + * Registers a model group. + */ + public CompletableFuture registerModelGroup(RegisterModelGroupRequest request) throws IOException, + OpenSearchException { + @SuppressWarnings("unchecked") + JsonEndpoint endpoint = (JsonEndpoint< + RegisterModelGroupRequest, + RegisterModelGroupResponse, + ErrorResponse>) RegisterModelGroupRequest._ENDPOINT; + + return this.transport.performRequestAsync(request, endpoint, this.transportOptions); + } + + /** + * Registers a model group. + * + * @param fn a function that initializes a builder to create the {@link RegisterModelGroupRequest} + */ + public final CompletableFuture registerModelGroup( + Function> fn + ) throws IOException, OpenSearchException { + return registerModelGroup(fn.apply(new RegisterModelGroupRequest.Builder()).build()); + } + + // ----- Endpoint: ml.undeploy_model + + /** + * Undeploys a model. + */ + public CompletableFuture undeployModel(UndeployModelRequest request) throws IOException, OpenSearchException { + @SuppressWarnings("unchecked") + JsonEndpoint endpoint = (JsonEndpoint< + UndeployModelRequest, + UndeployModelResponse, + ErrorResponse>) UndeployModelRequest._ENDPOINT; + + return this.transport.performRequestAsync(request, endpoint, this.transportOptions); + } + + /** + * Undeploys a model. + * + * @param fn a function that initializes a builder to create the {@link UndeployModelRequest} + */ + public final CompletableFuture undeployModel( + Function> fn + ) throws IOException, OpenSearchException { + return undeployModel(fn.apply(new UndeployModelRequest.Builder()).build()); + } +} diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/OpenSearchMlClient.java b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/OpenSearchMlClient.java new file mode 100644 index 0000000000..d3aba915be --- /dev/null +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/OpenSearchMlClient.java @@ -0,0 +1,271 @@ +/* + * 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. + */ + +//---------------------------------------------------- +// THIS CODE IS GENERATED. MANUAL EDITS WILL BE LOST. +//---------------------------------------------------- + +package org.opensearch.client.opensearch.ml; + +import java.io.IOException; +import java.util.function.Function; +import javax.annotation.Generated; +import javax.annotation.Nullable; +import org.opensearch.client.ApiClient; +import org.opensearch.client.opensearch._types.ErrorResponse; +import org.opensearch.client.opensearch._types.OpenSearchException; +import org.opensearch.client.transport.JsonEndpoint; +import org.opensearch.client.transport.OpenSearchTransport; +import org.opensearch.client.transport.TransportOptions; +import org.opensearch.client.util.ObjectBuilder; + +/** + * Client for the ml namespace. + */ +@Generated("org.opensearch.client.codegen.CodeGenerator") +public class OpenSearchMlClient extends ApiClient { + public OpenSearchMlClient(OpenSearchTransport transport) { + super(transport, null); + } + + public OpenSearchMlClient(OpenSearchTransport transport, @Nullable TransportOptions transportOptions) { + super(transport, transportOptions); + } + + @Override + public OpenSearchMlClient withTransportOptions(@Nullable TransportOptions transportOptions) { + return new OpenSearchMlClient(this.transport, transportOptions); + } + + // ----- Endpoint: ml.delete_model + + /** + * Deletes a model. + */ + public DeleteModelResponse deleteModel(DeleteModelRequest request) throws IOException, OpenSearchException { + @SuppressWarnings("unchecked") + JsonEndpoint endpoint = (JsonEndpoint< + DeleteModelRequest, + DeleteModelResponse, + ErrorResponse>) DeleteModelRequest._ENDPOINT; + + return this.transport.performRequest(request, endpoint, this.transportOptions); + } + + /** + * Deletes a model. + * + * @param fn a function that initializes a builder to create the {@link DeleteModelRequest} + */ + public final DeleteModelResponse deleteModel(Function> fn) + throws IOException, OpenSearchException { + return deleteModel(fn.apply(new DeleteModelRequest.Builder()).build()); + } + + // ----- Endpoint: ml.delete_model_group + + /** + * Deletes a model group. + */ + public DeleteModelGroupResponse deleteModelGroup(DeleteModelGroupRequest request) throws IOException, OpenSearchException { + @SuppressWarnings("unchecked") + JsonEndpoint endpoint = (JsonEndpoint< + DeleteModelGroupRequest, + DeleteModelGroupResponse, + ErrorResponse>) DeleteModelGroupRequest._ENDPOINT; + + return this.transport.performRequest(request, endpoint, this.transportOptions); + } + + /** + * Deletes a model group. + * + * @param fn a function that initializes a builder to create the {@link DeleteModelGroupRequest} + */ + public final DeleteModelGroupResponse deleteModelGroup( + Function> fn + ) throws IOException, OpenSearchException { + return deleteModelGroup(fn.apply(new DeleteModelGroupRequest.Builder()).build()); + } + + // ----- Endpoint: ml.delete_task + + /** + * Deletes a task. + */ + public DeleteTaskResponse deleteTask(DeleteTaskRequest request) throws IOException, OpenSearchException { + @SuppressWarnings("unchecked") + JsonEndpoint endpoint = (JsonEndpoint< + DeleteTaskRequest, + DeleteTaskResponse, + ErrorResponse>) DeleteTaskRequest._ENDPOINT; + + return this.transport.performRequest(request, endpoint, this.transportOptions); + } + + /** + * Deletes a task. + * + * @param fn a function that initializes a builder to create the {@link DeleteTaskRequest} + */ + public final DeleteTaskResponse deleteTask(Function> fn) throws IOException, + OpenSearchException { + return deleteTask(fn.apply(new DeleteTaskRequest.Builder()).build()); + } + + // ----- Endpoint: ml.deploy_model + + /** + * Deploys a model. + */ + public DeployModelResponse deployModel(DeployModelRequest request) throws IOException, OpenSearchException { + @SuppressWarnings("unchecked") + JsonEndpoint endpoint = (JsonEndpoint< + DeployModelRequest, + DeployModelResponse, + ErrorResponse>) DeployModelRequest._ENDPOINT; + + return this.transport.performRequest(request, endpoint, this.transportOptions); + } + + /** + * Deploys a model. + * + * @param fn a function that initializes a builder to create the {@link DeployModelRequest} + */ + public final DeployModelResponse deployModel(Function> fn) + throws IOException, OpenSearchException { + return deployModel(fn.apply(new DeployModelRequest.Builder()).build()); + } + + // ----- Endpoint: ml.get_model_group + + /** + * Retrieves a model group. + */ + public GetModelGroupResponse getModelGroup(GetModelGroupRequest request) throws IOException, OpenSearchException { + @SuppressWarnings("unchecked") + JsonEndpoint endpoint = (JsonEndpoint< + GetModelGroupRequest, + GetModelGroupResponse, + ErrorResponse>) GetModelGroupRequest._ENDPOINT; + + return this.transport.performRequest(request, endpoint, this.transportOptions); + } + + /** + * Retrieves a model group. + * + * @param fn a function that initializes a builder to create the {@link GetModelGroupRequest} + */ + public final GetModelGroupResponse getModelGroup(Function> fn) + throws IOException, OpenSearchException { + return getModelGroup(fn.apply(new GetModelGroupRequest.Builder()).build()); + } + + // ----- Endpoint: ml.get_task + + /** + * Retrieves a task. + */ + public GetTaskResponse getTask(GetTaskRequest request) throws IOException, OpenSearchException { + @SuppressWarnings("unchecked") + JsonEndpoint endpoint = (JsonEndpoint< + GetTaskRequest, + GetTaskResponse, + ErrorResponse>) GetTaskRequest._ENDPOINT; + + return this.transport.performRequest(request, endpoint, this.transportOptions); + } + + /** + * Retrieves a task. + * + * @param fn a function that initializes a builder to create the {@link GetTaskRequest} + */ + public final GetTaskResponse getTask(Function> fn) throws IOException, + OpenSearchException { + return getTask(fn.apply(new GetTaskRequest.Builder()).build()); + } + + // ----- Endpoint: ml.register_model + + /** + * Registers a model. + */ + public RegisterModelResponse registerModel(RegisterModelRequest request) throws IOException, OpenSearchException { + @SuppressWarnings("unchecked") + JsonEndpoint endpoint = (JsonEndpoint< + RegisterModelRequest, + RegisterModelResponse, + ErrorResponse>) RegisterModelRequest._ENDPOINT; + + return this.transport.performRequest(request, endpoint, this.transportOptions); + } + + /** + * Registers a model. + * + * @param fn a function that initializes a builder to create the {@link RegisterModelRequest} + */ + public final RegisterModelResponse registerModel(Function> fn) + throws IOException, OpenSearchException { + return registerModel(fn.apply(new RegisterModelRequest.Builder()).build()); + } + + // ----- Endpoint: ml.register_model_group + + /** + * Registers a model group. + */ + public RegisterModelGroupResponse registerModelGroup(RegisterModelGroupRequest request) throws IOException, OpenSearchException { + @SuppressWarnings("unchecked") + JsonEndpoint endpoint = (JsonEndpoint< + RegisterModelGroupRequest, + RegisterModelGroupResponse, + ErrorResponse>) RegisterModelGroupRequest._ENDPOINT; + + return this.transport.performRequest(request, endpoint, this.transportOptions); + } + + /** + * Registers a model group. + * + * @param fn a function that initializes a builder to create the {@link RegisterModelGroupRequest} + */ + public final RegisterModelGroupResponse registerModelGroup( + Function> fn + ) throws IOException, OpenSearchException { + return registerModelGroup(fn.apply(new RegisterModelGroupRequest.Builder()).build()); + } + + // ----- Endpoint: ml.undeploy_model + + /** + * Undeploys a model. + */ + public UndeployModelResponse undeployModel(UndeployModelRequest request) throws IOException, OpenSearchException { + @SuppressWarnings("unchecked") + JsonEndpoint endpoint = (JsonEndpoint< + UndeployModelRequest, + UndeployModelResponse, + ErrorResponse>) UndeployModelRequest._ENDPOINT; + + return this.transport.performRequest(request, endpoint, this.transportOptions); + } + + /** + * Undeploys a model. + * + * @param fn a function that initializes a builder to create the {@link UndeployModelRequest} + */ + public final UndeployModelResponse undeployModel(Function> fn) + throws IOException, OpenSearchException { + return undeployModel(fn.apply(new UndeployModelRequest.Builder()).build()); + } +} diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/RegisterModelGroupRequest.java b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/RegisterModelGroupRequest.java new file mode 100644 index 0000000000..ca633f61e5 --- /dev/null +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/RegisterModelGroupRequest.java @@ -0,0 +1,296 @@ +/* + * 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. + */ + +//---------------------------------------------------- +// THIS CODE IS GENERATED. MANUAL EDITS WILL BE LOST. +//---------------------------------------------------- + +package org.opensearch.client.opensearch.ml; + +import jakarta.json.stream.JsonGenerator; +import java.util.List; +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; +import org.opensearch.client.json.JsonpMapper; +import org.opensearch.client.json.ObjectBuilderDeserializer; +import org.opensearch.client.json.ObjectDeserializer; +import org.opensearch.client.json.PlainJsonSerializable; +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; + +// typedef: ml.register_model_group.Request + +/** + * Registers a model group. + */ +@JsonpDeserializable +@Generated("org.opensearch.client.codegen.CodeGenerator") +public class RegisterModelGroupRequest extends RequestBase implements PlainJsonSerializable { + + @Nullable + private final String accessMode; + + @Nullable + private final Boolean addAllBackendRoles; + + private final List backendRoles; + + @Nullable + private final String description; + + private final String name; + + // --------------------------------------------------------------------------------------------- + + private RegisterModelGroupRequest(Builder builder) { + this.accessMode = builder.accessMode; + this.addAllBackendRoles = builder.addAllBackendRoles; + this.backendRoles = ApiTypeHelper.unmodifiable(builder.backendRoles); + this.description = builder.description; + this.name = ApiTypeHelper.requireNonNull(builder.name, this, "name"); + } + + public static RegisterModelGroupRequest of(Function> fn) { + return fn.apply(new Builder()).build(); + } + + /** + * The model group access mode. + *

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

+ */ + @Nullable + public final String accessMode() { + return this.accessMode; + } + + /** + * The add all backend roles. + *

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

+ */ + @Nullable + public final Boolean addAllBackendRoles() { + return this.addAllBackendRoles; + } + + /** + * The backend roles. + *

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

+ */ + public final List backendRoles() { + return this.backendRoles; + } + + /** + * The model group description. + *

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

+ */ + @Nullable + public final String description() { + return this.description; + } + + /** + * Required - The model group name. + *

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

+ */ + public final String name() { + return this.name; + } + + /** + * Serialize this object to JSON. + */ + @Override + public void serialize(JsonGenerator generator, JsonpMapper mapper) { + generator.writeStartObject(); + serializeInternal(generator, mapper); + generator.writeEnd(); + } + + protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { + if (this.accessMode != null) { + generator.writeKey("access_mode"); + generator.write(this.accessMode); + } + + if (this.addAllBackendRoles != null) { + generator.writeKey("add_all_backend_roles"); + generator.write(this.addAllBackendRoles); + } + + if (ApiTypeHelper.isDefined(this.backendRoles)) { + generator.writeKey("backend_roles"); + generator.writeStartArray(); + for (String item0 : this.backendRoles) { + generator.write(item0); + } + generator.writeEnd(); + } + + if (this.description != null) { + generator.writeKey("description"); + generator.write(this.description); + } + + generator.writeKey("name"); + generator.write(this.name); + } + // --------------------------------------------------------------------------------------------- + + /** + * Builder for {@link RegisterModelGroupRequest}. + */ + public static class Builder extends ObjectBuilderBase implements ObjectBuilder { + @Nullable + private String accessMode; + @Nullable + private Boolean addAllBackendRoles; + @Nullable + private List backendRoles; + @Nullable + private String description; + private String name; + + /** + * The model group access mode. + *

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

+ */ + public final Builder accessMode(@Nullable String value) { + this.accessMode = value; + return this; + } + + /** + * The add all backend roles. + *

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

+ */ + public final Builder addAllBackendRoles(@Nullable Boolean value) { + this.addAllBackendRoles = value; + return this; + } + + /** + * The backend roles. + *

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

+ * + *

+ * Adds all elements of list to backendRoles. + *

+ */ + public final Builder backendRoles(List list) { + this.backendRoles = _listAddAll(this.backendRoles, list); + return this; + } + + /** + * The backend roles. + *

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

+ * + *

+ * Adds one or more values to backendRoles. + *

+ */ + public final Builder backendRoles(String value, String... values) { + this.backendRoles = _listAdd(this.backendRoles, value, values); + return this; + } + + /** + * The model group description. + *

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

+ */ + public final Builder description(@Nullable String value) { + this.description = value; + return this; + } + + /** + * Required - The model group name. + *

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

+ */ + public final Builder name(String value) { + this.name = value; + return this; + } + + /** + * Builds a {@link RegisterModelGroupRequest}. + * + * @throws NullPointerException if some of the required fields are null. + */ + public RegisterModelGroupRequest build() { + _checkSingleUse(); + + return new RegisterModelGroupRequest(this); + } + } + // --------------------------------------------------------------------------------------------- + + /** + * Json deserializer for {@link RegisterModelGroupRequest} + */ + public static final JsonpDeserializer _DESERIALIZER = ObjectBuilderDeserializer.lazy( + Builder::new, + RegisterModelGroupRequest::setupRegisterModelGroupRequestDeserializer + ); + + protected static void setupRegisterModelGroupRequestDeserializer(ObjectDeserializer op) { + op.add(Builder::accessMode, JsonpDeserializer.stringDeserializer(), "access_mode"); + op.add(Builder::addAllBackendRoles, JsonpDeserializer.booleanDeserializer(), "add_all_backend_roles"); + op.add(Builder::backendRoles, JsonpDeserializer.arrayDeserializer(JsonpDeserializer.stringDeserializer()), "backend_roles"); + op.add(Builder::description, JsonpDeserializer.stringDeserializer(), "description"); + op.add(Builder::name, JsonpDeserializer.stringDeserializer(), "name"); + } + + // --------------------------------------------------------------------------------------------- + + /** + * Endpoint "{@code ml.register_model_group}". + */ + public static final Endpoint _ENDPOINT = new SimpleEndpoint<>( + // Request method + request -> "POST", + // Request path + request -> "/_plugins/_ml/model_groups/_register", + // Request parameters + SimpleEndpoint.emptyMap(), + SimpleEndpoint.emptyMap(), + true, + RegisterModelGroupResponse._DESERIALIZER + ); +} diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/RegisterModelGroupResponse.java b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/RegisterModelGroupResponse.java new file mode 100644 index 0000000000..6a04cf66ad --- /dev/null +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/RegisterModelGroupResponse.java @@ -0,0 +1,145 @@ +/* + * 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. + */ + +//---------------------------------------------------- +// THIS CODE IS GENERATED. MANUAL EDITS WILL BE LOST. +//---------------------------------------------------- + +package org.opensearch.client.opensearch.ml; + +import jakarta.json.stream.JsonGenerator; +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.JsonpMapper; +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: ml.register_model_group.Response + +@JsonpDeserializable +@Generated("org.opensearch.client.codegen.CodeGenerator") +public class RegisterModelGroupResponse implements PlainJsonSerializable { + + private final String modelGroupId; + + private final String status; + + // --------------------------------------------------------------------------------------------- + + private RegisterModelGroupResponse(Builder builder) { + this.modelGroupId = ApiTypeHelper.requireNonNull(builder.modelGroupId, this, "modelGroupId"); + this.status = ApiTypeHelper.requireNonNull(builder.status, this, "status"); + } + + public static RegisterModelGroupResponse of( + Function> fn + ) { + return fn.apply(new Builder()).build(); + } + + /** + * Required - The model group ID. + *

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

+ */ + public final String modelGroupId() { + return this.modelGroupId; + } + + /** + * Required - The status. + *

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

+ */ + public final String status() { + return this.status; + } + + /** + * Serialize this object to JSON. + */ + @Override + public void serialize(JsonGenerator generator, JsonpMapper mapper) { + generator.writeStartObject(); + serializeInternal(generator, mapper); + generator.writeEnd(); + } + + protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { + generator.writeKey("model_group_id"); + generator.write(this.modelGroupId); + + generator.writeKey("status"); + generator.write(this.status); + } + + // --------------------------------------------------------------------------------------------- + + /** + * Builder for {@link RegisterModelGroupResponse}. + */ + public static class Builder extends ObjectBuilderBase implements ObjectBuilder { + private String modelGroupId; + private String status; + + /** + * Required - The model group ID. + *

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

+ */ + public final Builder modelGroupId(String value) { + this.modelGroupId = value; + return this; + } + + /** + * Required - The status. + *

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

+ */ + public final Builder status(String value) { + this.status = value; + return this; + } + + /** + * Builds a {@link RegisterModelGroupResponse}. + * + * @throws NullPointerException if some of the required fields are null. + */ + public RegisterModelGroupResponse build() { + _checkSingleUse(); + + return new RegisterModelGroupResponse(this); + } + } + // --------------------------------------------------------------------------------------------- + + /** + * Json deserializer for {@link RegisterModelGroupResponse} + */ + public static final JsonpDeserializer _DESERIALIZER = ObjectBuilderDeserializer.lazy( + Builder::new, + RegisterModelGroupResponse::setupRegisterModelGroupResponseDeserializer + ); + + protected static void setupRegisterModelGroupResponseDeserializer(ObjectDeserializer op) { + op.add(Builder::modelGroupId, JsonpDeserializer.stringDeserializer(), "model_group_id"); + op.add(Builder::status, JsonpDeserializer.stringDeserializer(), "status"); + } +} diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/RegisterModelRequest.java b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/RegisterModelRequest.java new file mode 100644 index 0000000000..c94be40813 --- /dev/null +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/RegisterModelRequest.java @@ -0,0 +1,264 @@ +/* + * 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. + */ + +//---------------------------------------------------- +// THIS CODE IS GENERATED. MANUAL EDITS WILL BE LOST. +//---------------------------------------------------- + +package org.opensearch.client.opensearch.ml; + +import jakarta.json.stream.JsonGenerator; +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; +import org.opensearch.client.json.JsonpMapper; +import org.opensearch.client.json.ObjectBuilderDeserializer; +import org.opensearch.client.json.ObjectDeserializer; +import org.opensearch.client.json.PlainJsonSerializable; +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; + +// typedef: ml.register_model.Request + +/** + * Registers a model. + */ +@JsonpDeserializable +@Generated("org.opensearch.client.codegen.CodeGenerator") +public class RegisterModelRequest extends RequestBase implements PlainJsonSerializable { + + @Nullable + private final String description; + + private final String modelFormat; + + @Nullable + private final String modelGroupId; + + private final String name; + + private final String version; + + // --------------------------------------------------------------------------------------------- + + private RegisterModelRequest(Builder builder) { + this.description = builder.description; + this.modelFormat = ApiTypeHelper.requireNonNull(builder.modelFormat, this, "modelFormat"); + this.modelGroupId = builder.modelGroupId; + this.name = ApiTypeHelper.requireNonNull(builder.name, this, "name"); + this.version = ApiTypeHelper.requireNonNull(builder.version, this, "version"); + } + + public static RegisterModelRequest of(Function> fn) { + return fn.apply(new Builder()).build(); + } + + /** + * The model description. + *

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

+ */ + @Nullable + public final String description() { + return this.description; + } + + /** + * Required - The portable format of the model file. + *

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

+ */ + public final String modelFormat() { + return this.modelFormat; + } + + /** + * The ID of the model group to which to register the model. + *

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

+ */ + @Nullable + public final String modelGroupId() { + return this.modelGroupId; + } + + /** + * Required - The model name. + *

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

+ */ + public final String name() { + return this.name; + } + + /** + * Required - The model version. + *

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

+ */ + public final String version() { + return this.version; + } + + /** + * Serialize this object to JSON. + */ + @Override + public void serialize(JsonGenerator generator, JsonpMapper mapper) { + generator.writeStartObject(); + serializeInternal(generator, mapper); + generator.writeEnd(); + } + + protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { + if (this.description != null) { + generator.writeKey("description"); + generator.write(this.description); + } + + generator.writeKey("model_format"); + generator.write(this.modelFormat); + + if (this.modelGroupId != null) { + generator.writeKey("model_group_id"); + generator.write(this.modelGroupId); + } + + generator.writeKey("name"); + generator.write(this.name); + + generator.writeKey("version"); + generator.write(this.version); + } + // --------------------------------------------------------------------------------------------- + + /** + * Builder for {@link RegisterModelRequest}. + */ + public static class Builder extends ObjectBuilderBase implements ObjectBuilder { + @Nullable + private String description; + private String modelFormat; + @Nullable + private String modelGroupId; + private String name; + private String version; + + /** + * The model description. + *

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

+ */ + public final Builder description(@Nullable String value) { + this.description = value; + return this; + } + + /** + * Required - The portable format of the model file. + *

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

+ */ + public final Builder modelFormat(String value) { + this.modelFormat = value; + return this; + } + + /** + * The ID of the model group to which to register the model. + *

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

+ */ + public final Builder modelGroupId(@Nullable String value) { + this.modelGroupId = value; + return this; + } + + /** + * Required - The model name. + *

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

+ */ + public final Builder name(String value) { + this.name = value; + return this; + } + + /** + * Required - The model version. + *

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

+ */ + public final Builder version(String value) { + this.version = value; + return this; + } + + /** + * Builds a {@link RegisterModelRequest}. + * + * @throws NullPointerException if some of the required fields are null. + */ + public RegisterModelRequest build() { + _checkSingleUse(); + + return new RegisterModelRequest(this); + } + } + // --------------------------------------------------------------------------------------------- + + /** + * Json deserializer for {@link RegisterModelRequest} + */ + public static final JsonpDeserializer _DESERIALIZER = ObjectBuilderDeserializer.lazy( + Builder::new, + RegisterModelRequest::setupRegisterModelRequestDeserializer + ); + + protected static void setupRegisterModelRequestDeserializer(ObjectDeserializer op) { + op.add(Builder::description, JsonpDeserializer.stringDeserializer(), "description"); + op.add(Builder::modelFormat, JsonpDeserializer.stringDeserializer(), "model_format"); + op.add(Builder::modelGroupId, JsonpDeserializer.stringDeserializer(), "model_group_id"); + op.add(Builder::name, JsonpDeserializer.stringDeserializer(), "name"); + op.add(Builder::version, JsonpDeserializer.stringDeserializer(), "version"); + } + + // --------------------------------------------------------------------------------------------- + + /** + * Endpoint "{@code ml.register_model}". + */ + public static final Endpoint _ENDPOINT = new SimpleEndpoint<>( + // Request method + request -> "POST", + // Request path + request -> "/_plugins/_ml/models/_register", + // Request parameters + SimpleEndpoint.emptyMap(), + SimpleEndpoint.emptyMap(), + true, + RegisterModelResponse._DESERIALIZER + ); +} diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/RegisterModelResponse.java b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/RegisterModelResponse.java new file mode 100644 index 0000000000..3b42ed8903 --- /dev/null +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/RegisterModelResponse.java @@ -0,0 +1,131 @@ +/* + * 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. + */ + +//---------------------------------------------------- +// THIS CODE IS GENERATED. MANUAL EDITS WILL BE LOST. +//---------------------------------------------------- + +package org.opensearch.client.opensearch.ml; + +import jakarta.json.stream.JsonGenerator; +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.JsonpMapper; +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: ml.register_model.Response + +@JsonpDeserializable +@Generated("org.opensearch.client.codegen.CodeGenerator") +public class RegisterModelResponse implements PlainJsonSerializable { + + private final String status; + + private final String taskId; + + // --------------------------------------------------------------------------------------------- + + private RegisterModelResponse(Builder builder) { + this.status = ApiTypeHelper.requireNonNull(builder.status, this, "status"); + this.taskId = ApiTypeHelper.requireNonNull(builder.taskId, this, "taskId"); + } + + public static RegisterModelResponse of(Function> fn) { + return fn.apply(new Builder()).build(); + } + + /** + * Required - API name: {@code status} + */ + public final String status() { + return this.status; + } + + /** + * Required - API name: {@code task_id} + */ + public final String taskId() { + return this.taskId; + } + + /** + * Serialize this object to JSON. + */ + @Override + public void serialize(JsonGenerator generator, JsonpMapper mapper) { + generator.writeStartObject(); + serializeInternal(generator, mapper); + generator.writeEnd(); + } + + protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { + generator.writeKey("status"); + generator.write(this.status); + + generator.writeKey("task_id"); + generator.write(this.taskId); + } + + // --------------------------------------------------------------------------------------------- + + /** + * Builder for {@link RegisterModelResponse}. + */ + public static class Builder extends ObjectBuilderBase implements ObjectBuilder { + private String status; + private String taskId; + + /** + * Required - API name: {@code status} + */ + public final Builder status(String value) { + this.status = value; + return this; + } + + /** + * Required - API name: {@code task_id} + */ + public final Builder taskId(String value) { + this.taskId = value; + return this; + } + + /** + * Builds a {@link RegisterModelResponse}. + * + * @throws NullPointerException if some of the required fields are null. + */ + public RegisterModelResponse build() { + _checkSingleUse(); + + return new RegisterModelResponse(this); + } + } + // --------------------------------------------------------------------------------------------- + + /** + * Json deserializer for {@link RegisterModelResponse} + */ + public static final JsonpDeserializer _DESERIALIZER = ObjectBuilderDeserializer.lazy( + Builder::new, + RegisterModelResponse::setupRegisterModelResponseDeserializer + ); + + protected static void setupRegisterModelResponseDeserializer(ObjectDeserializer op) { + op.add(Builder::status, JsonpDeserializer.stringDeserializer(), "status"); + op.add(Builder::taskId, JsonpDeserializer.stringDeserializer(), "task_id"); + } +} diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/UndeployModelNode.java b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/UndeployModelNode.java new file mode 100644 index 0000000000..6ba10b82ca --- /dev/null +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/UndeployModelNode.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. + */ + +//---------------------------------------------------- +// THIS CODE IS GENERATED. MANUAL EDITS WILL BE LOST. +//---------------------------------------------------- + +package org.opensearch.client.opensearch.ml; + +import jakarta.json.stream.JsonGenerator; +import java.util.Map; +import java.util.function.Function; +import javax.annotation.Generated; +import javax.annotation.Nullable; +import org.opensearch.client.json.JsonData; +import org.opensearch.client.json.JsonpDeserializable; +import org.opensearch.client.json.JsonpDeserializer; +import org.opensearch.client.json.JsonpMapper; +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: ml.UndeployModelNode + +@JsonpDeserializable +@Generated("org.opensearch.client.codegen.CodeGenerator") +public class UndeployModelNode implements PlainJsonSerializable { + + private final Map stats; + + // --------------------------------------------------------------------------------------------- + + private UndeployModelNode(Builder builder) { + this.stats = ApiTypeHelper.unmodifiable(builder.stats); + } + + public static UndeployModelNode of(Function> fn) { + return fn.apply(new Builder()).build(); + } + + /** + * API name: {@code stats} + */ + public final Map stats() { + return this.stats; + } + + /** + * Serialize this object to JSON. + */ + @Override + 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.stats)) { + generator.writeKey("stats"); + generator.writeStartObject(); + for (Map.Entry item0 : this.stats.entrySet()) { + generator.writeKey(item0.getKey()); + item0.getValue().serialize(generator, mapper); + } + generator.writeEnd(); + } + } + + // --------------------------------------------------------------------------------------------- + + /** + * Builder for {@link UndeployModelNode}. + */ + public static class Builder extends ObjectBuilderBase implements ObjectBuilder { + @Nullable + private Map stats; + + /** + * API name: {@code stats} + * + *

+ * Adds all elements of map to stats. + *

+ */ + public final Builder stats(Map map) { + this.stats = _mapPutAll(this.stats, map); + return this; + } + + /** + * API name: {@code stats} + * + *

+ * Adds an entry to stats. + *

+ */ + public final Builder stats(String key, JsonData value) { + this.stats = _mapPut(this.stats, key, value); + return this; + } + + /** + * Builds a {@link UndeployModelNode}. + * + * @throws NullPointerException if some of the required fields are null. + */ + public UndeployModelNode build() { + _checkSingleUse(); + + return new UndeployModelNode(this); + } + } + // --------------------------------------------------------------------------------------------- + + /** + * Json deserializer for {@link UndeployModelNode} + */ + public static final JsonpDeserializer _DESERIALIZER = ObjectBuilderDeserializer.lazy( + Builder::new, + UndeployModelNode::setupUndeployModelNodeDeserializer + ); + + protected static void setupUndeployModelNodeDeserializer(ObjectDeserializer op) { + op.add(Builder::stats, JsonpDeserializer.stringMapDeserializer(JsonData._DESERIALIZER), "stats"); + } +} diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/UndeployModelRequest.java b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/UndeployModelRequest.java new file mode 100644 index 0000000000..4ae83cb5b5 --- /dev/null +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/UndeployModelRequest.java @@ -0,0 +1,102 @@ +/* + * 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. + */ + +//---------------------------------------------------- +// THIS CODE IS GENERATED. MANUAL EDITS WILL BE LOST. +//---------------------------------------------------- + +package org.opensearch.client.opensearch.ml; + +import java.util.function.Function; +import javax.annotation.Generated; +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; + +// typedef: ml.undeploy_model.Request + +/** + * Undeploys a model. + */ +@Generated("org.opensearch.client.codegen.CodeGenerator") +public class UndeployModelRequest extends RequestBase { + + private final String modelId; + + // --------------------------------------------------------------------------------------------- + + private UndeployModelRequest(Builder builder) { + this.modelId = ApiTypeHelper.requireNonNull(builder.modelId, this, "modelId"); + } + + public static UndeployModelRequest of(Function> fn) { + return fn.apply(new Builder()).build(); + } + + /** + * Required - API name: {@code model_id} + */ + public final String modelId() { + return this.modelId; + } + + // --------------------------------------------------------------------------------------------- + + /** + * Builder for {@link UndeployModelRequest}. + */ + public static class Builder extends ObjectBuilderBase implements ObjectBuilder { + private String modelId; + + /** + * Required - API name: {@code model_id} + */ + public final Builder modelId(String value) { + this.modelId = value; + return this; + } + + /** + * Builds a {@link UndeployModelRequest}. + * + * @throws NullPointerException if some of the required fields are null. + */ + public UndeployModelRequest build() { + _checkSingleUse(); + + return new UndeployModelRequest(this); + } + } + + // --------------------------------------------------------------------------------------------- + + /** + * Endpoint "{@code ml.undeploy_model}". + */ + public static final Endpoint _ENDPOINT = new SimpleEndpoint<>( + // Request method + request -> "POST", + // Request path + request -> { + StringBuilder buf = new StringBuilder(); + buf.append("/_plugins/_ml/models/"); + SimpleEndpoint.pathEncode(request.modelId, buf); + buf.append("/_undeploy"); + return buf.toString(); + }, + // Request parameters + SimpleEndpoint.emptyMap(), + SimpleEndpoint.emptyMap(), + false, + UndeployModelResponse._DESERIALIZER + ); +} diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/ml/UndeployModelResponse.java b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/UndeployModelResponse.java new file mode 100644 index 0000000000..f7cdfea593 --- /dev/null +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/ml/UndeployModelResponse.java @@ -0,0 +1,142 @@ +/* + * 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. + */ + +//---------------------------------------------------- +// THIS CODE IS GENERATED. MANUAL EDITS WILL BE LOST. +//---------------------------------------------------- + +package org.opensearch.client.opensearch.ml; + +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; +import org.opensearch.client.json.JsonpMapper; +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: ml.undeploy_model.Response + +@JsonpDeserializable +@Generated("org.opensearch.client.codegen.CodeGenerator") +public class UndeployModelResponse implements PlainJsonSerializable { + + private final Map nodes; + + // --------------------------------------------------------------------------------------------- + + private UndeployModelResponse(Builder builder) { + this.nodes = ApiTypeHelper.unmodifiable(builder.nodes); + } + + public static UndeployModelResponse of(Function> fn) { + return fn.apply(new Builder()).build(); + } + + /** + */ + public final Map nodes() { + return this.nodes; + } + + /** + * Serialize this object to JSON. + */ + @Override + public void serialize(JsonGenerator generator, JsonpMapper mapper) { + generator.writeStartObject(); + serializeInternal(generator, mapper); + generator.writeEnd(); + } + + protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { + for (Map.Entry item0 : this.nodes.entrySet()) { + generator.writeKey(item0.getKey()); + item0.getValue().serialize(generator, mapper); + } + } + + // --------------------------------------------------------------------------------------------- + + /** + * Builder for {@link UndeployModelResponse}. + */ + public static class Builder extends ObjectBuilderBase implements ObjectBuilder { + @Nullable + private Map nodes; + + /** + * + *

+ * Adds all elements of map to nodes. + *

+ */ + public final Builder nodes(Map map) { + this.nodes = _mapPutAll(this.nodes, map); + return this; + } + + /** + * + *

+ * Adds an entry to nodes. + *

+ */ + public final Builder nodes(String key, UndeployModelNode value) { + this.nodes = _mapPut(this.nodes, key, value); + return this; + } + + /** + * + *

+ * Adds a value to nodes using a builder lambda. + *

+ */ + public final Builder nodes(String key, Function> fn) { + return nodes(key, fn.apply(new UndeployModelNode.Builder()).build()); + } + + /** + * Builds a {@link UndeployModelResponse}. + * + * @throws NullPointerException if some of the required fields are null. + */ + public UndeployModelResponse build() { + _checkSingleUse(); + + return new UndeployModelResponse(this); + } + } + // --------------------------------------------------------------------------------------------- + + /** + * Json deserializer for {@link UndeployModelResponse} + */ + public static final JsonpDeserializer _DESERIALIZER = ObjectBuilderDeserializer.lazy( + Builder::new, + UndeployModelResponse::setupUndeployModelResponseDeserializer + ); + + protected static void setupUndeployModelResponseDeserializer(ObjectDeserializer op) { + op.setUnknownFieldHandler((builder, name, parser, mapper) -> { + if (builder.nodes == null) { + builder.nodes = new HashMap<>(); + } + builder.nodes.put(name, UndeployModelNode._DESERIALIZER.deserialize(parser, mapper)); + }); + } +} diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/json/PlainJsonSerializableTest.java b/java-client/src/test/java/org/opensearch/client/opensearch/json/PlainJsonSerializableTest.java index c0af29e51b..7fbf6ec61c 100644 --- a/java-client/src/test/java/org/opensearch/client/opensearch/json/PlainJsonSerializableTest.java +++ b/java-client/src/test/java/org/opensearch/client/opensearch/json/PlainJsonSerializableTest.java @@ -23,7 +23,7 @@ public class PlainJsonSerializableTest extends Assert { public void testIndexResponse() { String expectedStringValue = - "{\"_id\":\"id\",\"_index\":\"index\",\"_primary_term\":1,\"result\":\"created\",\"_seq_no\":2,\"_shards\":{\"failed\":1.0,\"successful\":1.0,\"total\":3.0,\"failures\":[{\"index\":\"index\",\"node\":\"node\",\"reason\":{\"reason\":\"Failed to create query.\",\"type\":\"query_shard_exception\"},\"shard\":1,\"status\":\"Failed\"}],\"skipped\":1.0},\"_version\":3}"; + "{\"_id\":\"id\",\"_index\":\"index\",\"_primary_term\":1,\"result\":\"created\",\"_seq_no\":2,\"_shards\":{\"failed\":1,\"failures\":[{\"index\":\"index\",\"node\":\"node\",\"reason\":{\"reason\":\"Failed to create query.\",\"type\":\"query_shard_exception\"},\"shard\":1,\"status\":\"Failed\"}],\"skipped\":1,\"successful\":1,\"total\":3},\"_version\":3}"; IndexResponse indexResponse = IndexResponse.of( response -> response.result(Result.Created) .index("index") diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/model/TypedKeysTest.java b/java-client/src/test/java/org/opensearch/client/opensearch/model/TypedKeysTest.java index df69bc98a7..3472db587c 100644 --- a/java-client/src/test/java/org/opensearch/client/opensearch/model/TypedKeysTest.java +++ b/java-client/src/test/java/org/opensearch/client/opensearch/model/TypedKeysTest.java @@ -57,7 +57,7 @@ public void testMapProperty() { .timedOut(false) .build(); - String json = "{\"took\":1,\"timed_out\":false,\"_shards\":{\"failed\":0.0,\"successful\":1.0,\"total\":1.0}," + String json = "{\"took\":1,\"timed_out\":false,\"_shards\":{\"failed\":0,\"successful\":1,\"total\":1}," + "\"hits\":{\"total\":{\"relation\":\"eq\",\"value\":0},\"hits\":[]},\"aggregations\":{\"avg#foo\":{\"value\":3.14}}}"; assertEquals(json, toJson(resp)); @@ -95,7 +95,7 @@ public void testAdditionalProperties() { .timedOut(false) .build(); - String json = "{\"took\":1,\"timed_out\":false,\"_shards\":{\"failed\":0.0,\"successful\":1.0,\"total\":1.0}," + String json = "{\"took\":1,\"timed_out\":false,\"_shards\":{\"failed\":0,\"successful\":1,\"total\":1}," + "\"hits\":{\"total\":{\"relation\":\"eq\",\"value\":0},\"hits\":[]}," + "\"aggregations\":{\"sterms#foo\":{\"buckets\":[" + "{\"avg#bar\":{\"value\":1.0},\"doc_count\":1,\"key\":\"key_1\"}," diff --git a/java-codegen/build.gradle.kts b/java-codegen/build.gradle.kts index c5f1933713..49aa5ec3f5 100644 --- a/java-codegen/build.gradle.kts +++ b/java-codegen/build.gradle.kts @@ -167,6 +167,9 @@ dependencies { implementation("org.apache.maven.resolver", "maven-resolver-api", "1.9.20") implementation("org.apache.maven.resolver", "maven-resolver-supplier", "1.9.20") + // MIT + implementation("org.semver4j", "semver4j", "5.3.0") + // EPL-2.0 testImplementation(platform("org.junit:junit-bom:5.10.3")) testImplementation("org.junit.jupiter", "junit-jupiter") diff --git a/java-codegen/opensearch-openapi.yaml b/java-codegen/opensearch-openapi.yaml index fc23f29fe3..889bedbbdf 100644 --- a/java-codegen/opensearch-openapi.yaml +++ b/java-codegen/opensearch-openapi.yaml @@ -3887,6 +3887,20 @@ paths: '200': $ref: '#/components/responses/ml.undeploy_model@200' /_plugins/_ml/tasks/{task_id}: + delete: + operationId: ml.delete_task.0 + x-operation-group: ml.delete_task + description: Deletes a task. + parameters: + - $ref: '#/components/parameters/ml.delete_task::path.task_id' + - $ref: '#/components/parameters/_global::query.pretty' + - $ref: '#/components/parameters/_global::query.human' + - $ref: '#/components/parameters/_global::query.error_trace' + - $ref: '#/components/parameters/_global::query.source' + - $ref: '#/components/parameters/_global::query.filter_path' + responses: + '200': + $ref: '#/components/responses/ml.delete_task@200' get: operationId: ml.get_task.0 x-operation-group: ml.get_task @@ -20036,6 +20050,12 @@ components: required: true schema: type: string + ml.delete_task::path.task_id: + name: task_id + in: path + required: true + schema: + type: string ml.deploy_model::path.model_id: name: model_id in: path @@ -26139,6 +26159,11 @@ components: application/json: schema: $ref: '#/components/schemas/_common:WriteResponseBase' + ml.delete_task@200: + content: + application/json: + schema: + $ref: '#/components/schemas/_common:WriteResponseBase' ml.deploy_model@200: content: application/json: @@ -29286,6 +29311,7 @@ components: - version_map_memory_in_bytes _common:SequenceNumber: type: number + format: int64 _common:ShardFailure: type: object properties: @@ -29602,6 +29628,7 @@ components: type: string _common:VersionNumber: type: number + format: int64 _common:VersionString: type: string _common:VersionType: @@ -29671,6 +29698,7 @@ components: $ref: '#/components/schemas/_common:IndexName' _primary_term: type: number + format: int64 result: $ref: '#/components/schemas/_common:Result' _seq_no: @@ -46333,18 +46361,19 @@ components: type: string required: - state - ml._common:UndeployModelResponse: - type: object - additionalProperties: - $ref: '#/components/schemas/ml._common:UndeployModelResponseModels' - ml._common:UndeployModelResponseModels: + ml._common:UndeployModelNode: type: object properties: stats: - $ref: '#/components/schemas/ml._common:UndeployModelResponseStats' - ml._common:UndeployModelResponseStats: + $ref: '#/components/schemas/ml._common:UndeployModelNodeStats' + ml._common:UndeployModelNodeStats: type: object additionalProperties: true + ml._common:UndeployModelResponse: + type: object + additionalProperties: + title: nodes + $ref: '#/components/schemas/ml._common:UndeployModelNode' nodes._common:AdaptiveSelection: type: object properties: 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 457bc38f80..210079ccc2 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 @@ -8,6 +8,8 @@ package org.opensearch.client.codegen; +import static org.opensearch.client.codegen.model.OperationGroupMatcher.*; + import java.io.File; import java.io.IOException; import java.io.PrintWriter; @@ -26,14 +28,18 @@ import org.opensearch.client.codegen.exceptions.ApiSpecificationParseException; import org.opensearch.client.codegen.exceptions.RenderException; import org.opensearch.client.codegen.model.Namespace; -import org.opensearch.client.codegen.model.OperationGroup; +import org.opensearch.client.codegen.model.OperationGroupMatcher; import org.opensearch.client.codegen.model.ShapeRenderingContext; import org.opensearch.client.codegen.model.SpecTransformer; import org.opensearch.client.codegen.openapi.OpenApiSpecification; public class CodeGenerator { private static final Logger LOGGER = LogManager.getLogger(); - private static final OperationGroup.Matcher OPERATION_MATCHER = OperationGroup.matcher().add(null, "info").add("dangling_indices"); + private static final OperationGroupMatcher OPERATION_MATCHER = or( + 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 + ); public static void main(String[] args) { var inputOpt = Option.builder("i") diff --git a/java-codegen/src/main/java/org/opensearch/client/codegen/model/Deprecation.java b/java-codegen/src/main/java/org/opensearch/client/codegen/model/Deprecation.java index 9b1818a852..8f965bb14f 100644 --- a/java-codegen/src/main/java/org/opensearch/client/codegen/model/Deprecation.java +++ b/java-codegen/src/main/java/org/opensearch/client/codegen/model/Deprecation.java @@ -11,14 +11,15 @@ import java.util.Optional; import javax.annotation.Nonnull; import javax.annotation.Nullable; +import org.semver4j.Semver; public class Deprecation { @Nullable private final String description; @Nullable - private final String version; + private final Semver version; - public Deprecation(@Nullable String description, @Nullable String version) { + public Deprecation(@Nullable String description, @Nullable Semver version) { this.description = description; this.version = version; } @@ -29,7 +30,7 @@ public Optional getDescription() { } @Nonnull - public Optional getVersion() { + public Optional getVersion() { return Optional.ofNullable(version); } } diff --git a/java-codegen/src/main/java/org/opensearch/client/codegen/model/Namespace.java b/java-codegen/src/main/java/org/opensearch/client/codegen/model/Namespace.java index 1f455426a3..e0f52eb63d 100644 --- a/java-codegen/src/main/java/org/opensearch/client/codegen/model/Namespace.java +++ b/java-codegen/src/main/java/org/opensearch/client/codegen/model/Namespace.java @@ -47,10 +47,11 @@ public void addShape(Shape shape) { } public String getPackageName() { - return parent != null ? parent.getPackageName() + "." + getPackageNamePart() : "org.opensearch.client.opensearch"; + return parent != null ? parent.getPackageName() + "." + getName() : "org.opensearch.client.opensearch"; } - private String getPackageNamePart() { + @Nonnull + public String getName() { return name; } @@ -70,7 +71,7 @@ public Namespace child(@Nullable String name) { public void render(ShapeRenderingContext ctx) throws RenderException { for (Namespace child : children.values()) { - child.render(ctx.forSubDir(child.getPackageNamePart())); + child.render(ctx.forSubDir(child.getName())); } for (Shape shape : shapes) { diff --git a/java-codegen/src/main/java/org/opensearch/client/codegen/model/OperationGroup.java b/java-codegen/src/main/java/org/opensearch/client/codegen/model/OperationGroup.java index 818a4acd40..0d8dd650d9 100644 --- a/java-codegen/src/main/java/org/opensearch/client/codegen/model/OperationGroup.java +++ b/java-codegen/src/main/java/org/opensearch/client/codegen/model/OperationGroup.java @@ -8,12 +8,7 @@ package org.opensearch.client.codegen.model; -import java.util.Collection; -import java.util.HashSet; -import java.util.Objects; import java.util.Optional; -import java.util.Set; -import java.util.regex.Pattern; import javax.annotation.Nonnull; import javax.annotation.Nullable; import org.apache.commons.lang3.builder.EqualsBuilder; @@ -76,58 +71,4 @@ public boolean equals(Object o) { public int hashCode() { return new HashCodeBuilder(17, 37).append(namespace).append(name).toHashCode(); } - - @Nonnull - public static Matcher matcher() { - return new Matcher(); - } - - public static class Matcher { - private final Set namespaces = new HashSet<>(); - private final Set operations = new HashSet<>(); - private final Collection patterns = new HashSet<>(); - - private Matcher() {} - - @Nonnull - public Matcher add(@Nullable String namespace, @Nullable String... operations) { - if (operations == null || operations.length == 0) { - namespaces.add(Strings.requireNonBlank(namespace, "namespace must not be blank")); - } else { - for (String operation : operations) { - add(new OperationGroup(namespace, operation)); - } - } - return this; - } - - @Nonnull - public Matcher add(@Nonnull OperationGroup operation) { - operations.add(Objects.requireNonNull(operation, "operation must not be null")); - return this; - } - - @Nonnull - public Matcher add(@Nonnull Pattern pattern) { - patterns.add(Objects.requireNonNull(pattern, "pattern must not be null")); - return this; - } - - public boolean matches(@Nonnull OperationGroup operation) { - Objects.requireNonNull(operation, "operation must not be null"); - if (operation.getNamespace().map(namespaces::contains).orElse(false)) { - return true; - } - if (operations.contains(operation)) { - return true; - } - var str = operation.toString(); - for (Pattern pattern : patterns) { - if (pattern.matcher(str).matches()) { - return true; - } - } - return false; - } - } } diff --git a/java-codegen/src/main/java/org/opensearch/client/codegen/model/OperationGroupMatcher.java b/java-codegen/src/main/java/org/opensearch/client/codegen/model/OperationGroupMatcher.java new file mode 100644 index 0000000000..6a33bf3f81 --- /dev/null +++ b/java-codegen/src/main/java/org/opensearch/client/codegen/model/OperationGroupMatcher.java @@ -0,0 +1,61 @@ +/* + * 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.codegen.model; + +import java.util.Arrays; +import java.util.HashSet; +import javax.annotation.Nonnull; + +@FunctionalInterface +public interface OperationGroupMatcher { + boolean matches(OperationGroup group); + + static OperationGroupMatcher all() { + return group -> true; + } + + static OperationGroupMatcher none() { + return group -> false; + } + + static OperationGroupMatcher not(OperationGroupMatcher matcher) { + return group -> !matcher.matches(group); + } + + static OperationGroupMatcher or(OperationGroupMatcher... matchers) { + return group -> { + for (OperationGroupMatcher matcher : matchers) { + if (matcher.matches(group)) { + return true; + } + } + return false; + }; + } + + static OperationGroupMatcher and(OperationGroupMatcher... matchers) { + return group -> { + for (OperationGroupMatcher matcher : matchers) { + if (!matcher.matches(group)) { + return false; + } + } + return true; + }; + } + + static OperationGroupMatcher named(String... names) { + var set = new HashSet<>(Arrays.asList(names)); + return group -> set.contains(group.getName()); + } + + static OperationGroupMatcher namespace(@Nonnull String namespace) { + return group -> namespace.equals(group.getNamespace().orElse("")); + } +} 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 3e332ca8b8..53972b826c 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 @@ -136,6 +136,12 @@ public Collection getPathParams() { return pathParams.values(); } + @Override + public void addBodyField(Field field) { + super.addBodyField(field); + addField(field); + } + private void addField(Field field) { fields.put(field.getName(), field); } diff --git a/java-codegen/src/main/java/org/opensearch/client/codegen/model/Shape.java b/java-codegen/src/main/java/org/opensearch/client/codegen/model/Shape.java index 73d728a1db..bb59217c11 100644 --- a/java-codegen/src/main/java/org/opensearch/client/codegen/model/Shape.java +++ b/java-codegen/src/main/java/org/opensearch/client/codegen/model/Shape.java @@ -94,4 +94,8 @@ public Set getImports() { } return imports; } + + public boolean needsLegacyLicense() { + return !"ml".equals(parent.getName()); + } } diff --git a/java-codegen/src/main/java/org/opensearch/client/codegen/model/SpecTransformer.java b/java-codegen/src/main/java/org/opensearch/client/codegen/model/SpecTransformer.java index 55e6a45609..72527200ff 100644 --- a/java-codegen/src/main/java/org/opensearch/client/codegen/model/SpecTransformer.java +++ b/java-codegen/src/main/java/org/opensearch/client/codegen/model/SpecTransformer.java @@ -41,11 +41,12 @@ import org.opensearch.client.codegen.openapi.OpenApiSchemaType; import org.opensearch.client.codegen.openapi.OpenApiSpecification; import org.opensearch.client.codegen.utils.Lists; +import org.opensearch.client.codegen.utils.Versions; public class SpecTransformer { private static final Logger LOGGER = LogManager.getLogger(); @Nonnull - private final OperationGroup.Matcher matcher; + private final OperationGroupMatcher matcher; @Nonnull private final Namespace root = new Namespace(); @Nonnull @@ -53,7 +54,7 @@ public class SpecTransformer { @Nonnull private final Map schemaToType = new ConcurrentHashMap<>(); - public SpecTransformer(@Nonnull OperationGroup.Matcher matcher) { + public SpecTransformer(@Nonnull OperationGroupMatcher matcher) { this.matcher = Objects.requireNonNull(matcher, "matcher must not be null"); } @@ -285,14 +286,14 @@ private void visitInto(OpenApiSchema schema, ObjectShape shape) { final var required = collectObjectProperties(schema, properties, additionalProperties); properties.forEach( - (k, v) -> { shape.addBodyField(new Field(k, mapType(v), required.contains(k), v.getDescription().orElse(null), null)); } + (k, v) -> shape.addBodyField(new Field(k, mapType(v), required.contains(k), v.getDescription().orElse(null), null)) ); if (!additionalProperties.isEmpty()) { var valueSchema = additionalProperties.size() == 1 ? additionalProperties.get(0) : OpenApiSchema.ANONYMOUS_UNTYPED; shape.setAdditionalPropertiesField( new Field( - valueSchema.getTitle().orElseThrow(), + valueSchema.getTitle().orElse("metadata"), Types.Java.Util.Map(Types.Java.Lang.String, mapType(valueSchema)), false, valueSchema.getDescription().orElse(null), @@ -333,17 +334,28 @@ private Set collectObjectProperties( return required; } - schema.getProperties().ifPresent(props -> props.forEach((k, v) -> { - var existing = properties.get(k); + schema.getProperties().ifPresent(props -> props.forEach((propName, propSchema) -> { + var resolvedPropSchema = propSchema.resolve(); + var isRemoved = propSchema.getVersionRemoved() + .or(resolvedPropSchema::getVersionRemoved) + .map(ver -> ver.isLowerThanOrEqualTo(Versions.V2_0_0)) + .orElse(false); + + if (isRemoved) { + return; + } + + var existing = properties.get(propName); if (existing != null) { var existingType = existing.determineSingleType().orElse(null); - var newType = v.determineSingleType().orElse(null); + var newType = propSchema.determineSingleType().orElse(null); if (existingType != null && (existingType == OpenApiSchemaType.Object || existingType == OpenApiSchemaType.Array || existingType != newType)) { - v = OpenApiSchema.ANONYMOUS_UNTYPED; + propSchema = OpenApiSchema.ANONYMOUS_UNTYPED; } } - properties.put(k, v); + + properties.put(propName, propSchema); })); schema.getAdditionalProperties().ifPresent(additionalProperties::add); @@ -472,6 +484,11 @@ private boolean shouldKeepRef(OpenApiSchema schema) { if (schema.isString() && schema.getEnums().isEmpty()) { return false; } + if (schema.isObject() + && schema.getProperties().map(Map::isEmpty).orElse(true) + && schema.getAdditionalProperties().map(s -> s.getTitle().isEmpty()).orElse(false)) { + return false; + } if (schema.getOneOf().isPresent()) { return schema.getOneOf().orElseThrow().stream().allMatch(s -> s.getTitle().isPresent()); } diff --git a/java-codegen/src/main/java/org/opensearch/client/codegen/openapi/OpenApiOperation.java b/java-codegen/src/main/java/org/opensearch/client/codegen/openapi/OpenApiOperation.java index 34b2f4be9b..0489c44bd4 100644 --- a/java-codegen/src/main/java/org/opensearch/client/codegen/openapi/OpenApiOperation.java +++ b/java-codegen/src/main/java/org/opensearch/client/codegen/openapi/OpenApiOperation.java @@ -20,6 +20,8 @@ import javax.annotation.Nullable; import org.opensearch.client.codegen.model.Deprecation; import org.opensearch.client.codegen.model.OperationGroup; +import org.opensearch.client.codegen.utils.Versions; +import org.semver4j.Semver; public class OpenApiOperation extends OpenApiElement { @Nonnull @@ -43,7 +45,7 @@ public class OpenApiOperation extends OpenApiElement { @Nullable private final String versionAdded; @Nullable - private final String versionDeprecated; + private final Semver versionDeprecated; @Nullable private final String deprecationMessage; @@ -61,7 +63,7 @@ protected OpenApiOperation(@Nonnull OpenApiPath parent, @Nonnull JsonPointer poi this.requestBody = child("requestBody", operation.getRequestBody(), OpenApiRequestBody::new); this.responses = child("responses", operation.getResponses(), OpenApiResponses::new); this.versionAdded = ifNonnull(extensions.get("x-version-added"), String::valueOf); - this.versionDeprecated = ifNonnull(extensions.get("x-version-deprecated"), String::valueOf); + this.versionDeprecated = ifNonnull(extensions.get("x-version-deprecated"), v -> Versions.coerce((String) v)); this.deprecationMessage = ifNonnull(extensions.get("x-deprecation-message"), String::valueOf); } diff --git a/java-codegen/src/main/java/org/opensearch/client/codegen/openapi/OpenApiParameter.java b/java-codegen/src/main/java/org/opensearch/client/codegen/openapi/OpenApiParameter.java index 442873eab7..45e0178b46 100644 --- a/java-codegen/src/main/java/org/opensearch/client/codegen/openapi/OpenApiParameter.java +++ b/java-codegen/src/main/java/org/opensearch/client/codegen/openapi/OpenApiParameter.java @@ -16,6 +16,8 @@ import javax.annotation.Nullable; import org.opensearch.client.codegen.model.Deprecation; import org.opensearch.client.codegen.utils.Maps; +import org.opensearch.client.codegen.utils.Versions; +import org.semver4j.Semver; public class OpenApiParameter extends OpenApiRefElement { @Nullable @@ -31,7 +33,7 @@ public class OpenApiParameter extends OpenApiRefElement { @Nullable private final Boolean isDeprecated; @Nullable - private final String versionDeprecated; + private final Semver versionDeprecated; @Nullable private final String deprecationMessage; @Nullable @@ -46,7 +48,7 @@ protected OpenApiParameter(@Nullable OpenApiElement parent, @Nonnull JsonPoin this.schema = child("schema", parameter.getSchema(), OpenApiSchema::new); this.isDeprecated = parameter.getDeprecated(); var extensions = parameter.getExtensions(); - this.versionDeprecated = Maps.tryGet(extensions, "x-version-deprecated").map(String::valueOf).orElse(null); + this.versionDeprecated = Maps.tryGet(extensions, "x-version-deprecated").map(v -> Versions.coerce((String) v)).orElse(null); this.deprecationMessage = Maps.tryGet(extensions, "x-deprecation-message").map(String::valueOf).orElse(null); this.isGlobal = (Boolean) Maps.tryGet(extensions, "x-global").orElse(null); } diff --git a/java-codegen/src/main/java/org/opensearch/client/codegen/openapi/OpenApiSchema.java b/java-codegen/src/main/java/org/opensearch/client/codegen/openapi/OpenApiSchema.java index 5928c63fce..d48d1140e7 100644 --- a/java-codegen/src/main/java/org/opensearch/client/codegen/openapi/OpenApiSchema.java +++ b/java-codegen/src/main/java/org/opensearch/client/codegen/openapi/OpenApiSchema.java @@ -24,6 +24,8 @@ import org.opensearch.client.codegen.utils.Lists; import org.opensearch.client.codegen.utils.Maps; import org.opensearch.client.codegen.utils.Sets; +import org.opensearch.client.codegen.utils.Versions; +import org.semver4j.Semver; public class OpenApiSchema extends OpenApiRefElement { private static final JsonPointer ANONYMOUS = JsonPointer.of(""); @@ -65,6 +67,8 @@ public class OpenApiSchema extends OpenApiRefElement { private final String title; @Nullable private final String pattern; + @Nullable + private final Semver versionRemoved; private OpenApiSchema(@Nonnull Builder builder) { super(builder.parent, Objects.requireNonNull(builder.pointer, "pointer must not be null"), builder.$ref, OpenApiSchema.class); @@ -84,6 +88,7 @@ private OpenApiSchema(@Nonnull Builder builder) { required = builder.required; title = builder.title; pattern = builder.pattern; + versionRemoved = builder.versionRemoved; } protected OpenApiSchema(@Nullable OpenApiElement parent, @Nonnull JsonPointer pointer, @Nonnull Schema schema) { @@ -135,6 +140,8 @@ protected OpenApiSchema(@Nullable OpenApiElement parent, @Nonnull JsonPointer // noinspection unchecked deprecatedEnums = Maps.tryGet(extensions, "x-deprecated-enums").map(e -> (Collection) e).map(HashSet::new).orElse(null); + + versionRemoved = Maps.tryGet(extensions, "x-version-removed").map(v -> Versions.coerce((String) v)).orElse(null); } @Nonnull @@ -258,6 +265,11 @@ public Optional getPattern() { return Optional.ofNullable(pattern); } + @Nonnull + public Optional getVersionRemoved() { + return Optional.ofNullable(versionRemoved); + } + public static Set determineTypes(List schemas) { return schemas.stream().map(OpenApiSchema::determineTypes).flatMap(Set::stream).collect(Collectors.toSet()); } @@ -338,6 +350,8 @@ public static class Builder { private String title; @Nullable private String pattern; + @Nullable + private Semver versionRemoved; @Nonnull public Builder withPointer(@Nonnull JsonPointer pointer) { diff --git a/java-codegen/src/main/java/org/opensearch/client/codegen/utils/Strings.java b/java-codegen/src/main/java/org/opensearch/client/codegen/utils/Strings.java index a8afed9249..d6a751a84f 100644 --- a/java-codegen/src/main/java/org/opensearch/client/codegen/utils/Strings.java +++ b/java-codegen/src/main/java/org/opensearch/client/codegen/utils/Strings.java @@ -8,7 +8,9 @@ package org.opensearch.client.codegen.utils; +import java.util.HashMap; import java.util.Locale; +import java.util.Map; import java.util.Objects; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -35,12 +37,22 @@ public static String requireNonBlank(@Nullable String str, @Nullable String mess return str; } + private static final Map SPECIAL_CASE_SNAKE_CASE_CONVERSION = new HashMap<>() { + { + put("noop", "no_op"); + } + }; + @Nonnull public static String toSnakeCase(@Nonnull String str) { Objects.requireNonNull(str, "str must not be null"); if (str.isEmpty()) { return str; } + + var specialCase = SPECIAL_CASE_SNAKE_CASE_CONVERSION.get(str); + if (specialCase != null) return specialCase; + return str.replaceAll("([A-Z]+)([A-Z][a-z])", "$1_$2") .replaceAll("([a-z\\d])([A-Z])", "$1_$2") .replaceAll("(\\s|[-:.])", "_") diff --git a/java-codegen/src/main/java/org/opensearch/client/codegen/utils/Versions.java b/java-codegen/src/main/java/org/opensearch/client/codegen/utils/Versions.java new file mode 100644 index 0000000000..288c1bac88 --- /dev/null +++ b/java-codegen/src/main/java/org/opensearch/client/codegen/utils/Versions.java @@ -0,0 +1,25 @@ +/* + * 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.codegen.utils; + +import javax.annotation.Nonnull; +import org.semver4j.Semver; + +public final class Versions { + private Versions() {} + + public static final Semver V2_0_0 = Semver.of(2, 0, 0); + + @Nonnull + public static Semver coerce(String str) { + var version = Semver.coerce(str); + if (version == null) throw new IllegalArgumentException("Unable to coerce `" + str + "` to semver"); + return version; + } +} diff --git a/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/Partials/ClassHeader.mustache b/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/Partials/ClassHeader.mustache index b04007b760..04f604493e 100644 --- a/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/Partials/ClassHeader.mustache +++ b/java-codegen/src/main/resources/org/opensearch/client/codegen/templates/Partials/ClassHeader.mustache @@ -5,6 +5,7 @@ * this file be licensed under the Apache-2.0 license or a * compatible open source license. */ +{{#needsLegacyLicense}} /* * Licensed to Elasticsearch B.V. under one or more contributor @@ -29,6 +30,7 @@ * Modifications Copyright OpenSearch Contributors. See * GitHub history for details. */ +{{/needsLegacyLicense}} //---------------------------------------------------- // THIS CODE IS GENERATED. MANUAL EDITS WILL BE LOST. diff --git a/samples/src/main/java/org/opensearch/client/samples/neural/NeuralSearch.java b/samples/src/main/java/org/opensearch/client/samples/neural/NeuralSearch.java new file mode 100644 index 0000000000..263adb1475 --- /dev/null +++ b/samples/src/main/java/org/opensearch/client/samples/neural/NeuralSearch.java @@ -0,0 +1,333 @@ +/* + * 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.samples.neural; + +import java.io.IOException; +import java.util.Arrays; +import java.util.Objects; +import java.util.stream.Collectors; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.opensearch.client.json.JsonData; +import org.opensearch.client.opensearch.OpenSearchClient; +import org.opensearch.client.opensearch._types.OpenSearchException; +import org.opensearch.client.opensearch._types.Refresh; +import org.opensearch.client.opensearch._types.query_dsl.NeuralQuery; +import org.opensearch.client.opensearch._types.query_dsl.Query; +import org.opensearch.client.opensearch.core.SearchRequest; +import org.opensearch.client.opensearch.core.bulk.BulkOperation; +import org.opensearch.client.opensearch.ingest.Processor; +import org.opensearch.client.opensearch.ingest.PutPipelineRequest; +import org.opensearch.client.opensearch.ingest.TextEmbeddingProcessor; +import org.opensearch.client.opensearch.ml.DeleteModelGroupRequest; +import org.opensearch.client.opensearch.ml.DeleteModelRequest; +import org.opensearch.client.opensearch.ml.DeleteTaskRequest; +import org.opensearch.client.opensearch.ml.DeployModelRequest; +import org.opensearch.client.opensearch.ml.GetTaskRequest; +import org.opensearch.client.opensearch.ml.RegisterModelRequest; +import org.opensearch.client.opensearch.ml.UndeployModelRequest; +import org.opensearch.client.samples.SampleClient; + +/** + * Run with: ./gradlew :samples:run -Dsamples.mainClass=neural.NeuralSearch + */ +public class NeuralSearch { + private static final String SAMPLE_NAME = "neural-search"; + private static final String RESOURCE_NAME_PREFIX = "csharp-" + SAMPLE_NAME; + private static final String ML_MODEL_GROUP_NAME = RESOURCE_NAME_PREFIX + "-model-group"; + private static final String INGEST_PIPELINE_NAME = RESOURCE_NAME_PREFIX + "-ingest-pipeline"; + private static final String INDEX_NAME = RESOURCE_NAME_PREFIX + "-index"; + + private static final Logger LOGGER = LogManager.getLogger(NeuralSearch.class); + + public static void main(String[] args) { + OpenSearchClient client = null; + String modelGroupId = null; + String modelRegistrationTaskId = null; + String modelId = null; + String modelDeployTaskId = null; + boolean createdIngestPipeline = false; + boolean createdIndex = false; + + try { + client = SampleClient.create(); + + var version = client.info().version(); + LOGGER.info("Server: {}@{}", version.distribution(), version.number()); + + LOGGER.info("Temporarily configuring the cluster to allow local running of the ML model"); + client.cluster() + .putSettings( + p -> p.transient_("plugins.ml_commons.only_run_on_ml_node", JsonData.of(false)) + .transient_("plugins.ml_commons.model_access_control_enabled", JsonData.of(true)) + .transient_("plugins.ml_commons.native_memory_threshold", JsonData.of(99)) + ); + + LOGGER.info("Registering ML model group"); + var groupRegistration = client.ml() + .registerModelGroup( + r -> r.name(ML_MODEL_GROUP_NAME) + .description("A model group for the opensearch-java " + SAMPLE_NAME + " sample") + .accessMode("public") + ); + if (!"CREATED".equals(groupRegistration.status())) throw new Exception( + "Expected ML model group to be CREATED, was: " + groupRegistration.status() + ); + modelGroupId = groupRegistration.modelGroupId(); + LOGGER.info("ML model group `{}` id: {}", ML_MODEL_GROUP_NAME, modelGroupId); + + LOGGER.info("Registering ML model"); + var modelRegistration = client.ml() + .registerModel( + new RegisterModelRequest.Builder().name("huggingface/sentence-transformers/msmarco-distilbert-base-tas-b") + .version("1.0.1") + .modelGroupId(modelGroupId) + .modelFormat("TORCH_SCRIPT") + .build() + ); + if (!"CREATED".equals(modelRegistration.status())) throw new Exception( + "Expected ML model registration task to be CREATED, was: " + modelRegistration.status() + ); + modelRegistrationTaskId = modelRegistration.taskId(); + LOGGER.info("ML model registration task: {}", modelRegistrationTaskId); + + LOGGER.info("Waiting for ML model registration to complete"); + registerWait: while (true) { + var modelRegistrationTask = client.ml().getTask(new GetTaskRequest.Builder().taskId(modelRegistrationTaskId).build()); + LOGGER.info("ML model registration: {}", modelRegistrationTask.state()); + switch (modelRegistrationTask.state()) { + case "COMPLETED": + modelId = modelRegistrationTask.modelId(); + break registerWait; + case "FAILED": + throw new Exception("ML model registration failed: " + modelRegistrationTask.error()); + default: + // noinspection BusyWait + Thread.sleep(10_000); + } + } + LOGGER.info("ML model registered: {}", modelId); + + LOGGER.info("Deploying ML model"); + var modelDeploy = client.ml().deployModel(new DeployModelRequest.Builder().modelId(modelId).build()); + if (!"CREATED".equals(modelDeploy.status())) throw new Exception( + "Expected ML model deploy task to be CREATED, was: " + modelDeploy.status() + ); + modelDeployTaskId = modelDeploy.taskId(); + LOGGER.info("ML model deploy task: {}", modelDeployTaskId); + + LOGGER.info("Waiting for ML model deployment to complete"); + deployWait: while (true) { + var modelDeployTask = client.ml().getTask(new GetTaskRequest.Builder().taskId(modelDeployTaskId).build()); + LOGGER.info("ML model deployment: {}", modelDeployTask.state()); + switch (modelDeployTask.state()) { + case "COMPLETED": + break deployWait; + case "FAILED": + throw new Exception("ML model deployment failed: " + modelDeployTask.error()); + default: + // noinspection BusyWait + Thread.sleep(10_000); + } + } + LOGGER.info("ML model deployed"); + + LOGGER.info("Creating ingest pipeline: {}", INGEST_PIPELINE_NAME); + client.ingest() + .putPipeline( + new PutPipelineRequest.Builder().id(INGEST_PIPELINE_NAME) + .description("A test_embedding ingest pipeline for the opensearch-java " + SAMPLE_NAME + " sample") + .processors( + new Processor.Builder().textEmbedding( + new TextEmbeddingProcessor.Builder().modelId(modelId).fieldMap("text", "passageEmbedding").build() + ).build() + ) + .build() + ); + createdIngestPipeline = true; + LOGGER.info("Created ingest pipeline"); + + LOGGER.info("Creating index: {}", INDEX_NAME); + client.indices() + .create( + i -> i.index(INDEX_NAME) + .settings(s -> s.index(is -> is.knn(true)).defaultPipeline(INGEST_PIPELINE_NAME)) + .mappings( + m -> m.properties("id", p -> p.text(t -> t)) + .properties("text", p -> p.text(t -> t)) + .properties( + "passageEmbedding", + p -> p.knnVector( + kv -> kv.dimension(768).method(kvm -> kvm.engine("lucene").spaceType("l2").name("hnsw")) + ) + ) + ) + ); + createdIndex = true; + LOGGER.info("Created index"); + + LOGGER.info("Indexing documents"); + var documents = new NeuralSearchDoc[] { + new NeuralSearchDoc( + "4319130149.jpg", + "A West Virginia university women 's basketball team , officials , and a small gathering of fans are in a West Virginia arena ." + ), + new NeuralSearchDoc("1775029934.jpg", "A wild animal races across an uncut field with a minimal amount of trees ."), + new NeuralSearchDoc( + "2664027527.jpg", + "People line the stands which advertise Freemont 's orthopedics , a cowboy rides a light brown bucking bronco ." + ), + new NeuralSearchDoc("4427058951.jpg", "A man who is riding a wild horse in the rodeo is very near to falling off ."), + new NeuralSearchDoc( + "2691147709.jpg", + "A rodeo cowboy , wearing a cowboy hat , is being thrown off of a wild white horse ." + ) }; + var bulk = client.bulk( + b -> b.index(INDEX_NAME) + .operations( + Arrays.stream(documents) + .map(d -> new BulkOperation.Builder().index(i -> i.id(d.getId()).document(d)).build()) + .collect(Collectors.toList()) + ) + .refresh(Refresh.WaitFor) + ); + LOGGER.info("Indexed {} documents", bulk.items().stream().filter(i -> i.error() == null).count()); + + LOGGER.info("Performing neural search for text 'wild west'"); + var search = client.search( + new SearchRequest.Builder().index(INDEX_NAME) + .source(sc -> sc.filter(sf -> sf.excludes("passageEmbedding"))) + .query( + new Query.Builder().neural( + new NeuralQuery.Builder().field("passageEmbedding").queryText("wild west").modelId(modelId).k(5).build() + ).build() + ) + .build(), + NeuralSearchDoc.class + ); + LOGGER.info("Found {} documents", search.hits().hits().size()); + for (var hit : search.hits().hits()) { + LOGGER.info( + "- Document id: {}, score: {}, text: {}", + hit.id(), + hit.score(), + Objects.requireNonNull(hit.source()).getText() + ); + } + } catch (Exception e) { + LOGGER.error("Unexpected exception", e); + } finally { + LOGGER.info("-- CLEANING UP --"); + + if (createdIndex) { + try { + LOGGER.info("Deleting index: {}", INDEX_NAME); + client.indices().delete(d -> d.index(INDEX_NAME)); + LOGGER.info("Deleted index"); + } catch (Exception ignored) {} + } + + if (createdIngestPipeline) { + try { + LOGGER.info("Deleting ingest pipeline: {}", INGEST_PIPELINE_NAME); + client.ingest().deletePipeline(d -> d.id(INGEST_PIPELINE_NAME)); + LOGGER.info("Deleted ingest pipeline"); + } catch (Exception ignored) {} + } + + if (modelDeployTaskId != null) { + try { + LOGGER.info("Deleting ML model deploy task: {}", modelDeployTaskId); + var taskDeleted = client.ml().deleteTask(new DeleteTaskRequest.Builder().taskId(modelDeployTaskId).build()); + LOGGER.info("Deleted ML model deploy task: {}", taskDeleted.result()); + } catch (Exception ignored) {} + } + + if (modelId != null) { + while (true) { + try { + LOGGER.info("Deleting ML model: {}", modelId); + var modelDeleted = client.ml().deleteModel(new DeleteModelRequest.Builder().modelId(modelId).build()); + LOGGER.info("Deleted ML model: {}", modelDeleted.result()); + break; + } catch (OpenSearchException ex) { + var reason = ex.error() != null ? ex.error().reason() : null; + + if (reason == null || !reason.contains("Try undeploy")) break; + + try { + LOGGER.info("Un-deploying ML model: {}", modelId); + client.ml().undeployModel(new UndeployModelRequest.Builder().modelId(modelId).build()); + LOGGER.info("Un-deployed ML model"); + } catch (Exception ignored) {} + + try { + // noinspection BusyWait + Thread.sleep(10_000); + } catch (InterruptedException ignored) {} + } catch (IOException ignored) {} + } + } + + if (modelRegistrationTaskId != null) { + try { + LOGGER.info("Deleting ML model registration task: {}", modelRegistrationTaskId); + var taskDeleted = client.ml().deleteTask(new DeleteTaskRequest.Builder().taskId(modelRegistrationTaskId).build()); + LOGGER.info("Deleted ML model registration task: {}", taskDeleted.result()); + } catch (Exception ignored) {} + } + + if (modelGroupId != null) { + try { + LOGGER.info("Deleting ML model group: {}", modelGroupId); + var groupDeleted = client.ml() + .deleteModelGroup(new DeleteModelGroupRequest.Builder().modelGroupId(modelGroupId).build()); + LOGGER.info("Deleted ML model group: {}", groupDeleted.result()); + } catch (Exception ignored) {} + } + } + } + + private static class NeuralSearchDoc { + private String id; + private String text; + private float[] passageEmbedding; + + public NeuralSearchDoc() {} + + public NeuralSearchDoc(String id, String text) { + this.id = id; + this.text = text; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getText() { + return text; + } + + public void setText(String text) { + this.text = text; + } + + public float[] getPassageEmbedding() { + return passageEmbedding; + } + + public void setPassageEmbedding(float[] passageEmbedding) { + this.passageEmbedding = passageEmbedding; + } + } +}