From e0d4608b664209f21d767a342618e0a2e4540bd1 Mon Sep 17 00:00:00 2001 From: Daniel Widdis Date: Wed, 3 Jul 2024 12:38:44 -0700 Subject: [PATCH] Simplify instantiating Data Object Request/Response builders (#2608) Signed-off-by: Daniel Widdis --- plugin/build.gradle | 1 - .../CreateControllerTransportAction.java | 1 + .../DeleteControllerTransportAction.java | 1 + .../GetControllerTransportAction.java | 1 + .../UpdateControllerTransportAction.java | 1 + .../deploy/TransportDeployModelAction.java | 5 ++++- .../ml/sdkclient/SdkClientModule.java | 21 +++++++------------ 7 files changed, 15 insertions(+), 16 deletions(-) diff --git a/plugin/build.gradle b/plugin/build.gradle index 7579b2a839..5b4f1ee3fb 100644 --- a/plugin/build.gradle +++ b/plugin/build.gradle @@ -84,7 +84,6 @@ dependencies { implementation "software.amazon.awssdk:third-party-jackson-core:2.25.40" implementation("software.amazon.awssdk:url-connection-client:2.25.40") implementation("software.amazon.awssdk:utils:2.25.40") - implementation("software.amazon.awssdk:apache-client:2.25.40") configurations.all { diff --git a/plugin/src/main/java/org/opensearch/ml/action/controller/CreateControllerTransportAction.java b/plugin/src/main/java/org/opensearch/ml/action/controller/CreateControllerTransportAction.java index 3172b337f2..44e7e6f37a 100644 --- a/plugin/src/main/java/org/opensearch/ml/action/controller/CreateControllerTransportAction.java +++ b/plugin/src/main/java/org/opensearch/ml/action/controller/CreateControllerTransportAction.java @@ -99,6 +99,7 @@ protected void doExecute(Task task, ActionRequest request, ActionListener wrappedListener = ActionListener.runBefore(actionListener, context::restore); + // TODO: Add support for multi tenancy mlModelManager.getModel(modelId, null, null, excludes, ActionListener.wrap(mlModel -> { FunctionName functionName = mlModel.getAlgorithm(); Boolean isHidden = mlModel.getIsHidden(); diff --git a/plugin/src/main/java/org/opensearch/ml/action/controller/DeleteControllerTransportAction.java b/plugin/src/main/java/org/opensearch/ml/action/controller/DeleteControllerTransportAction.java index 37b4757017..a5b3931ff6 100644 --- a/plugin/src/main/java/org/opensearch/ml/action/controller/DeleteControllerTransportAction.java +++ b/plugin/src/main/java/org/opensearch/ml/action/controller/DeleteControllerTransportAction.java @@ -86,6 +86,7 @@ protected void doExecute(Task task, ActionRequest request, ActionListener wrappedListener = ActionListener.runBefore(actionListener, context::restore); + // TODO: Add support for multi tenancy mlModelManager.getModel(modelId, null, null, excludes, ActionListener.wrap(mlModel -> { Boolean isHidden = mlModel.getIsHidden(); modelAccessControlHelper diff --git a/plugin/src/main/java/org/opensearch/ml/action/controller/GetControllerTransportAction.java b/plugin/src/main/java/org/opensearch/ml/action/controller/GetControllerTransportAction.java index 183c081da1..a5020a52f8 100644 --- a/plugin/src/main/java/org/opensearch/ml/action/controller/GetControllerTransportAction.java +++ b/plugin/src/main/java/org/opensearch/ml/action/controller/GetControllerTransportAction.java @@ -85,6 +85,7 @@ protected void doExecute(Task task, ActionRequest request, ActionListener { Boolean isHidden = mlModel.getIsHidden(); modelAccessControlHelper diff --git a/plugin/src/main/java/org/opensearch/ml/action/controller/UpdateControllerTransportAction.java b/plugin/src/main/java/org/opensearch/ml/action/controller/UpdateControllerTransportAction.java index 9b378f3334..95fb42c5a8 100644 --- a/plugin/src/main/java/org/opensearch/ml/action/controller/UpdateControllerTransportAction.java +++ b/plugin/src/main/java/org/opensearch/ml/action/controller/UpdateControllerTransportAction.java @@ -91,6 +91,7 @@ protected void doExecute(Task task, ActionRequest request, ActionListener wrappedListener = ActionListener.runBefore(actionListener, context::restore); + // TODO: Add support for multi tenancy mlModelManager.getModel(modelId, null, null, excludes, ActionListener.wrap(mlModel -> { FunctionName functionName = mlModel.getAlgorithm(); Boolean isHidden = mlModel.getIsHidden(); diff --git a/plugin/src/main/java/org/opensearch/ml/action/deploy/TransportDeployModelAction.java b/plugin/src/main/java/org/opensearch/ml/action/deploy/TransportDeployModelAction.java index 6151e645a3..1e7d0cce51 100644 --- a/plugin/src/main/java/org/opensearch/ml/action/deploy/TransportDeployModelAction.java +++ b/plugin/src/main/java/org/opensearch/ml/action/deploy/TransportDeployModelAction.java @@ -284,7 +284,10 @@ private void deployModel( mlTaskManager.createMLTask(mlTask, ActionListener.wrap(response -> { String taskId = response.getId(); mlTask.setTaskId(taskId); - if (algorithm == FunctionName.REMOTE && !mlFeatureEnabledSetting.isMultiTenancyEnabled()) { + if (algorithm == FunctionName.REMOTE) { + if (!mlFeatureEnabledSetting.isMultiTenancyEnabled()) { + return; + } mlTaskManager.add(mlTask, eligibleNodeIds); deployRemoteModel(mlModel, mlTask, localNodeId, eligibleNodes, deployToAllNodes, listener); return; diff --git a/plugin/src/main/java/org/opensearch/ml/sdkclient/SdkClientModule.java b/plugin/src/main/java/org/opensearch/ml/sdkclient/SdkClientModule.java index e296109bbd..3ca2a15aab 100644 --- a/plugin/src/main/java/org/opensearch/ml/sdkclient/SdkClientModule.java +++ b/plugin/src/main/java/org/opensearch/ml/sdkclient/SdkClientModule.java @@ -9,12 +9,16 @@ package org.opensearch.ml.sdkclient; import org.apache.http.HttpHost; +import org.apache.http.conn.ssl.NoopHostnameVerifier; import org.apache.http.impl.client.BasicCredentialsProvider; import org.opensearch.OpenSearchException; import org.opensearch.client.Client; +import org.opensearch.client.RestClient; +import org.opensearch.client.json.jackson.JacksonJsonpMapper; import org.opensearch.client.opensearch.OpenSearchClient; import org.opensearch.client.transport.aws.AwsSdk2Transport; import org.opensearch.client.transport.aws.AwsSdk2TransportOptions; +import org.opensearch.client.transport.rest_client.RestClientTransport; import org.opensearch.common.inject.AbstractModule; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.sdk.SdkClient; @@ -28,8 +32,6 @@ import software.amazon.awssdk.auth.credentials.ContainerCredentialsProvider; import software.amazon.awssdk.auth.credentials.EnvironmentVariableCredentialsProvider; import software.amazon.awssdk.auth.credentials.InstanceProfileCredentialsProvider; -import software.amazon.awssdk.http.SdkHttpClient; -import software.amazon.awssdk.http.apache.ApacheHttpClient; import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.dynamodb.DynamoDbClient; @@ -135,15 +137,7 @@ private OpenSearchClient createOpenSearchClient() { try { BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider(); // Basic http(not-s) client using RestClient. - SdkHttpClient httpClient = ApacheHttpClient.builder().build(); - AwsSdk2Transport awsSdk2Transport = new AwsSdk2Transport( - httpClient, - HttpHost.create(remoteMetadataEndpoint).getHostName(), - "aoss", - Region.of(region), - AwsSdk2TransportOptions.builder().build() - ); - /*RestClient restClient = RestClient + RestClient restClient = RestClient // This HttpHost syntax works with export REMOTE_METADATA_ENDPOINT=http://127.0.0.1:9200 .builder(HttpHost.create(remoteMetadataEndpoint)) .setStrictDeprecationMode(true) @@ -156,12 +150,11 @@ private OpenSearchClient createOpenSearchClient() { throw new OpenSearchException(e); } }) - .build();*/ + .build(); ObjectMapper objectMapper = new ObjectMapper() .setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE) .setSerializationInclusion(JsonInclude.Include.NON_NULL); - // return new OpenSearchClient(new RestClientTransport(restClient, new JacksonJsonpMapper(objectMapper))); - return new OpenSearchClient(awsSdk2Transport); + return new OpenSearchClient(new RestClientTransport(restClient, new JacksonJsonpMapper(objectMapper))); } catch (Exception e) { throw new OpenSearchException(e); }