-
Notifications
You must be signed in to change notification settings - Fork 143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor SdkClient to a concrete class with delegate implementation #2638
Merged
dhrubo-os
merged 4 commits into
opensearch-project:feature/multi_tenancy
from
dbwiddis:sdkclient-as-instance
Jul 11, 2024
+559
−366
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
34a479e
Refactor SdkClient to a concrete class with delegate implementation
dbwiddis 91f68b3
Make delegate implementation an interface and remove client getter
dbwiddis e1f7085
Move SdkClient Settings to their own class
dbwiddis 00cd4ff
Add validation, support Java8 time, implement SSL/TLS
dbwiddis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
common/src/main/java/org/opensearch/sdk/SdkClientDelegate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* 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.sdk; | ||
|
||
import java.util.concurrent.CompletionStage; | ||
import java.util.concurrent.Executor; | ||
|
||
public interface SdkClientDelegate { | ||
|
||
/** | ||
* Create/Put/Index a data object/document into a table/index. | ||
* @param request A request encapsulating the data object to store | ||
* @param executor the executor to use for asynchronous execution | ||
* @return A completion stage encapsulating the response or exception | ||
*/ | ||
CompletionStage<PutDataObjectResponse> putDataObjectAsync(PutDataObjectRequest request, Executor executor); | ||
|
||
/** | ||
* Read/Get a data object/document from a table/index. | ||
* | ||
* @param request A request identifying the data object to retrieve | ||
* @param executor the executor to use for asynchronous execution | ||
* @return A completion stage encapsulating the response or exception | ||
*/ | ||
CompletionStage<GetDataObjectResponse> getDataObjectAsync(GetDataObjectRequest request, Executor executor); | ||
|
||
/** | ||
* Update a data object/document in a table/index. | ||
* | ||
* @param request A request identifying the data object to update | ||
* @param executor the executor to use for asynchronous execution | ||
* @return A completion stage encapsulating the response or exception | ||
*/ | ||
CompletionStage<UpdateDataObjectResponse> updateDataObjectAsync(UpdateDataObjectRequest request, Executor executor); | ||
|
||
/** | ||
* Delete a data object/document from a table/index. | ||
* | ||
* @param request A request identifying the data object to delete | ||
* @param executor the executor to use for asynchronous execution | ||
* @return A completion stage encapsulating the response or exception | ||
*/ | ||
CompletionStage<DeleteDataObjectResponse> deleteDataObjectAsync(DeleteDataObjectRequest request, Executor executor); | ||
|
||
/** | ||
* Search for data objects/documents in a table/index. | ||
* | ||
* @param request A request identifying the data objects to search for | ||
* @param executor the executor to use for asynchronous execution | ||
* @return A completion stage encapsulating the response or exception | ||
*/ | ||
CompletionStage<SearchDataObjectResponse> searchDataObjectAsync(SearchDataObjectRequest request, Executor executor); | ||
} |
36 changes: 36 additions & 0 deletions
36
common/src/main/java/org/opensearch/sdk/SdkClientSettings.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* 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.sdk; | ||
|
||
import org.opensearch.common.settings.Setting; | ||
import org.opensearch.common.settings.Setting.Property; | ||
|
||
/** Settings applicable to the SdkClient */ | ||
public class SdkClientSettings { | ||
|
||
/** The key for remote metadata type. */ | ||
public static final String REMOTE_METADATA_TYPE_KEY = "plugins.ml_commons.remote_metadata_type"; | ||
|
||
/** The value for remote metadata type for a remote cluster. */ | ||
public static final String REMOTE_OPENSEARCH = "RemoteOpenSearch"; | ||
/** The value for remote metadata type for a remote cluster on AWS OpenSearch Service. */ | ||
public static final String AWS_OPENSEARCH_SERVICE = "AWSOpenSearchService"; | ||
/** The value for remote metadata type for a remote cluster on AWS Dynamo DB. */ | ||
public static final String AWS_DYNAMO_DB = "AWSDynamoDB"; | ||
|
||
/** The key for remote metadata endpoint, applicable to remote clusters or DynamoDB. */ | ||
public static final String REMOTE_METADATA_ENDPOINT_KEY = "plugins.ml_commons.remote_metadata_endpoint"; | ||
/** The key for remote metadata region, applicable to AWS remote clusters or DynamoDB. */ | ||
public static final String REMOTE_METADATA_REGION_KEY = "plugins.ml_commons.remote_metadata_region"; | ||
|
||
public static final Setting<String> REMOTE_METADATA_TYPE = Setting.simpleString(REMOTE_METADATA_TYPE_KEY, Property.NodeScope, Property.Final); | ||
public static final Setting<String> REMOTE_METADATA_ENDPOINT = Setting.simpleString(REMOTE_METADATA_ENDPOINT_KEY, Property.NodeScope, Property.Final); | ||
public static final Setting<String> REMOTE_METADATA_REGION = Setting.simpleString(REMOTE_METADATA_REGION_KEY, Property.NodeScope, Property.Final); | ||
|
||
} |
53 changes: 53 additions & 0 deletions
53
common/src/test/java/org/opensearch/sdk/SdkClientSettingsTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* 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.sdk; | ||
|
||
import org.opensearch.common.settings.ClusterSettings; | ||
import org.opensearch.common.settings.Setting; | ||
import org.opensearch.common.settings.Settings; | ||
|
||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
import static org.opensearch.sdk.SdkClientSettings.REMOTE_METADATA_ENDPOINT; | ||
import static org.opensearch.sdk.SdkClientSettings.REMOTE_METADATA_ENDPOINT_KEY; | ||
import static org.opensearch.sdk.SdkClientSettings.REMOTE_METADATA_REGION; | ||
import static org.opensearch.sdk.SdkClientSettings.REMOTE_METADATA_REGION_KEY; | ||
import static org.opensearch.sdk.SdkClientSettings.REMOTE_METADATA_TYPE; | ||
import static org.opensearch.sdk.SdkClientSettings.REMOTE_METADATA_TYPE_KEY; | ||
|
||
public class SdkClientSettingsTests { | ||
|
||
private Settings settings; | ||
private ClusterSettings clusterSettings; | ||
|
||
public void setUp() throws Exception { | ||
settings = Settings.builder().build(); | ||
final Set<Setting<?>> settingsSet = Stream | ||
.concat( | ||
ClusterSettings.BUILT_IN_CLUSTER_SETTINGS.stream(), | ||
Stream | ||
.of( | ||
REMOTE_METADATA_TYPE, | ||
REMOTE_METADATA_ENDPOINT, | ||
REMOTE_METADATA_REGION | ||
) | ||
) | ||
.collect(Collectors.toSet()); | ||
clusterSettings = new ClusterSettings(settings, settingsSet); | ||
} | ||
|
||
public void testSettings() { | ||
assertTrue(clusterSettings.isFinalSetting(REMOTE_METADATA_TYPE_KEY)); | ||
assertTrue(clusterSettings.isFinalSetting(REMOTE_METADATA_ENDPOINT_KEY)); | ||
assertTrue(clusterSettings.isFinalSetting(REMOTE_METADATA_REGION_KEY)); | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume these settings will eventually move to core, right?
Otherwise we usually keep our settings in one place:
ml-commons/plugin/src/main/java/org/opensearch/ml/settings/MLCommonsSettings.java
Line 17 in 0b9708b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, these are intended to be moved to wherever this whole package will eventually move (an OpenSearch module? Another plugin? The SDK for Java extensions repo? But it will not remain in ML Commons long term and those settings names will probably change when we relocate it.