From a1068ffc85dce8b0b45d1c1b4737cbfb69c85256 Mon Sep 17 00:00:00 2001 From: Thomas Farr Date: Tue, 27 Aug 2024 11:20:42 +1200 Subject: [PATCH] [Backport 2.x] Generate the ml namespace (#1158) (#1160) * 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 (cherry picked from commit c6e61e1b559cc7e26b1e65765440c02192e44180) * Tie into manually edited client Signed-off-by: Thomas Farr * Remove stray codegen files Signed-off-by: Thomas Farr --------- Signed-off-by: Thomas Farr --- CHANGELOG.md | 5 +- java-client/build.gradle.kts | 12 + .../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 +++++++ .../opensearch/OpenSearchAsyncClient.java | 5 + .../client/opensearch/OpenSearchClient.java | 5 + .../client/opensearch/_types/Result.java | 16 +- .../opensearch/_types/ShardFailure.java | 33 +- .../opensearch/_types/WriteResponseBase.java | 81 ++-- .../client/samples/neural/NeuralSearch.java | 333 +++++++++++++++ 29 files changed, 3829 insertions(+), 70 deletions(-) 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 samples/src/main/java/org/opensearch/client/samples/neural/NeuralSearch.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f6da098a4..92b13610d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,8 +3,9 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ## [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 - Bumps `commons-logging:commons-logging` from 1.3.3 to 1.3.4 diff --git a/java-client/build.gradle.kts b/java-client/build.gradle.kts index 1fc18b2412..1243aad67e 100644 --- a/java-client/build.gradle.kts +++ b/java-client/build.gradle.kts @@ -84,6 +84,14 @@ java { } } +sourceSets { + main { + java { + srcDir("src/generated/java") + } + } +} + tasks.withType { expand( "version" to version, @@ -186,6 +194,10 @@ dependencies { // http://json-b.net/ implementation("jakarta.json.bind", "jakarta.json.bind-api", "2.0.0") + // EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + // https://projects.eclipse.org/projects/ee4j.ca + implementation("jakarta.annotation", "jakarta.annotation-api", "1.3.5") + // Apache 2.0 implementation("com.fasterxml.jackson.core", "jackson-core", jacksonVersion) 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/main/java/org/opensearch/client/opensearch/OpenSearchAsyncClient.java b/java-client/src/main/java/org/opensearch/client/opensearch/OpenSearchAsyncClient.java index 5d869c6f59..e67d6148f7 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/OpenSearchAsyncClient.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/OpenSearchAsyncClient.java @@ -126,6 +126,7 @@ import org.opensearch.client.opensearch.features.OpenSearchFeaturesAsyncClient; import org.opensearch.client.opensearch.indices.OpenSearchIndicesAsyncClient; import org.opensearch.client.opensearch.ingest.OpenSearchIngestAsyncClient; +import org.opensearch.client.opensearch.ml.OpenSearchMlAsyncClient; import org.opensearch.client.opensearch.nodes.OpenSearchNodesAsyncClient; import org.opensearch.client.opensearch.shutdown.OpenSearchShutdownAsyncClient; import org.opensearch.client.opensearch.snapshot.OpenSearchSnapshotAsyncClient; @@ -181,6 +182,10 @@ public OpenSearchIngestAsyncClient ingest() { return new OpenSearchIngestAsyncClient(this.transport, this.transportOptions); } + public OpenSearchMlAsyncClient ml() { + return new OpenSearchMlAsyncClient(this.transport, this.transportOptions); + } + public OpenSearchNodesAsyncClient nodes() { return new OpenSearchNodesAsyncClient(this.transport, this.transportOptions); } diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/OpenSearchClient.java b/java-client/src/main/java/org/opensearch/client/opensearch/OpenSearchClient.java index ee83bcc20d..a16c771822 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/OpenSearchClient.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/OpenSearchClient.java @@ -126,6 +126,7 @@ import org.opensearch.client.opensearch.generic.OpenSearchGenericClient; import org.opensearch.client.opensearch.indices.OpenSearchIndicesClient; import org.opensearch.client.opensearch.ingest.OpenSearchIngestClient; +import org.opensearch.client.opensearch.ml.OpenSearchMlClient; import org.opensearch.client.opensearch.nodes.OpenSearchNodesClient; import org.opensearch.client.opensearch.shutdown.OpenSearchShutdownClient; import org.opensearch.client.opensearch.snapshot.OpenSearchSnapshotClient; @@ -184,6 +185,10 @@ public OpenSearchIngestClient ingest() { return new OpenSearchIngestClient(this.transport, this.transportOptions); } + public OpenSearchMlClient ml() { + return new OpenSearchMlClient(this.transport, this.transportOptions); + } + public OpenSearchNodesClient nodes() { return new OpenSearchNodesClient(this.transport, this.transportOptions); } diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/_types/Result.java b/java-client/src/main/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/main/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/main/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/main/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/WriteResponseBase.java b/java-client/src/main/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/main/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/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..3036ef2c89 --- /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 = "java-" + 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; + } + } +}