-
Notifications
You must be signed in to change notification settings - Fork 141
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
[Feature/multi_tenancy] [WIP] SdkClient interface and implementation #2430
Closed
dbwiddis
wants to merge
15
commits into
opensearch-project:feature_multi_tenancy
from
dbwiddis:feature_multi_tenancy
Closed
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
fb99c9a
Create SdkClient interface and XContent implementation
dbwiddis d3fdbdb
Implement put, get, delete for Connector
dbwiddis 79b2e1f
Implement Custom interface parse method in Connector interface
dbwiddis b5d0e2a
Fix test compiling. Still expect failures on exceptions/messages
dbwiddis 0922be8
Use anonymous class to work around injection
dbwiddis 3d550c3
Injection doesn't like anonymous classes
dbwiddis bc469de
Make SdkClient an interface again and bind it to the implementation
dbwiddis aba9780
Rename XContentClient to LocalClusterIndicesClient
dbwiddis e298731
Remote client implementation
dbwiddis 59ef8c5
Rename Custom to DataObject
dbwiddis e110f30
Temporarily suppress failing connector tests
dbwiddis d8d4661
Return parser rather than object to keep implementation generic
dbwiddis aaa0cb1
Remove DataObject interface
dbwiddis b984ad5
Add test classes
dbwiddis fd22232
Refactor clients with supplyAsync, handle not found on get
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
84 changes: 84 additions & 0 deletions
84
common/src/main/java/org/opensearch/sdk/DeleteDataObjectRequest.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,84 @@ | ||
/* | ||
* 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; | ||
|
||
public class DeleteDataObjectRequest { | ||
|
||
private final String index; | ||
private final String id; | ||
|
||
/** | ||
* Instantiate this request with an index and id. | ||
* <p> | ||
* For data storage implementations other than OpenSearch, an index may be referred to as a table and the id may be referred to as a primary key. | ||
* @param index the index location to delete the object | ||
* @param id the document id | ||
*/ | ||
public DeleteDataObjectRequest(String index, String id) { | ||
this.index = index; | ||
this.id = id; | ||
} | ||
|
||
/** | ||
* Returns the index | ||
* @return the index | ||
*/ | ||
public String index() { | ||
return this.index; | ||
} | ||
|
||
/** | ||
* Returns the document id | ||
* @return the id | ||
*/ | ||
public String id() { | ||
return this.id; | ||
} | ||
|
||
/** | ||
* Class for constructing a Builder for this Request Object | ||
*/ | ||
public static class Builder { | ||
private String index = null; | ||
private String id = null; | ||
|
||
/** | ||
* Empty Constructor for the Builder object | ||
*/ | ||
public Builder() {} | ||
|
||
/** | ||
* Add an index to this builder | ||
* @param index the index to put the object | ||
* @return the updated builder | ||
*/ | ||
public Builder index(String index) { | ||
this.index = index; | ||
return this; | ||
} | ||
|
||
/** | ||
* Add an id to this builder | ||
* @param id the document id | ||
* @return the updated builder | ||
*/ | ||
public Builder id(String id) { | ||
this.id = id; | ||
return this; | ||
} | ||
|
||
/** | ||
* Builds the object | ||
* @return A {@link DeleteDataObjectRequest} | ||
*/ | ||
public DeleteDataObjectRequest build() { | ||
return new DeleteDataObjectRequest(this.index, this.id); | ||
} | ||
} | ||
} |
118 changes: 118 additions & 0 deletions
118
common/src/main/java/org/opensearch/sdk/DeleteDataObjectResponse.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,118 @@ | ||
/* | ||
* 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.core.common.Strings; | ||
import org.opensearch.core.index.shard.ShardId; | ||
|
||
public class DeleteDataObjectResponse { | ||
private final String id; | ||
private final ShardId shardId; | ||
private final boolean deleted; | ||
|
||
/** | ||
* Instantiate this request with an id and deletion status. | ||
* <p> | ||
* For data storage implementations other than OpenSearch, an index may be referred to as a table and the id may be referred to as a primary key. | ||
* @param id the document id | ||
* @param shardId the shard id | ||
* @param deleted Whether the object was deleted. Use {@code false} if the object was not found. | ||
*/ | ||
public DeleteDataObjectResponse(String id, ShardId shardId, boolean deleted) { | ||
this.id = id; | ||
this.shardId = shardId; | ||
this.deleted = deleted; | ||
} | ||
|
||
/** | ||
* Returns the document id | ||
* @return the id | ||
*/ | ||
public String id() { | ||
return id; | ||
} | ||
|
||
/** | ||
* Returns the shard id. | ||
* @return the shard id, or a generated id if shards are not applicable | ||
*/ | ||
public ShardId shardId() { | ||
return shardId; | ||
} | ||
|
||
/** | ||
* Returns whether deletion was successful | ||
* @return true if deletion was successful, false if the object was not found | ||
*/ | ||
public boolean deleted() { | ||
return deleted; | ||
} | ||
|
||
/** | ||
* Class for constructing a Builder for this Response Object | ||
*/ | ||
public static class Builder { | ||
private String id = null; | ||
private ShardId shardId = null; | ||
private boolean deleted = false; | ||
|
||
/** | ||
* Empty Constructor for the Builder object | ||
*/ | ||
public Builder() {} | ||
|
||
/** | ||
* Add an id to this builder | ||
* @param id the id to add | ||
* @return the updated builder | ||
*/ | ||
public Builder id(String id) { | ||
this.id = id; | ||
return this; | ||
} | ||
|
||
/** | ||
* Adds a shard id to this builder | ||
* @param shardId the shard id to add | ||
* @return the updated builder | ||
*/ | ||
public Builder shardId(ShardId shardId) { | ||
this.shardId = shardId; | ||
return this; | ||
} | ||
|
||
/** | ||
* Adds a generated shard id to this builder | ||
* @param indexName the index name to generate a shard id | ||
* @return the updated builder | ||
*/ | ||
public Builder shardId(String indexName) { | ||
this.shardId = new ShardId(indexName, Strings.UNKNOWN_UUID_VALUE, 0); | ||
return this; | ||
} | ||
|
||
/** | ||
* Add a deleted status to this builder | ||
* @param deleted the deleted status to add | ||
* @return the updated builder | ||
*/ | ||
public Builder deleted(boolean deleted) { | ||
this.deleted = deleted; | ||
return this; | ||
} | ||
|
||
/** | ||
* Builds the object | ||
* @return A {@link DeleteDataObjectResponse} | ||
*/ | ||
public DeleteDataObjectResponse build() { | ||
return new DeleteDataObjectResponse(this.id, this.shardId, this.deleted); | ||
} | ||
} | ||
} |
108 changes: 108 additions & 0 deletions
108
common/src/main/java/org/opensearch/sdk/GetDataObjectRequest.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,108 @@ | ||
/* | ||
* 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.search.fetch.subphase.FetchSourceContext; | ||
|
||
public class GetDataObjectRequest { | ||
|
||
private final String index; | ||
private final String id; | ||
private final FetchSourceContext fetchSourceContext; | ||
|
||
/** | ||
* Instantiate this request with an index and id | ||
* <p> | ||
* For data storage implementations other than OpenSearch, an index may be referred to as a table and the id may be referred to as a primary key. | ||
* @param index the index location to get the object | ||
* @param id the document id | ||
* @param fetchSourceContext the context to use when fetching _source | ||
*/ | ||
public GetDataObjectRequest(String index, String id, FetchSourceContext fetchSourceContext) { | ||
this.index = index; | ||
this.id = id; | ||
this.fetchSourceContext = fetchSourceContext; | ||
} | ||
|
||
/** | ||
* Returns the index | ||
* @return the index | ||
*/ | ||
public String index() { | ||
return this.index; | ||
} | ||
|
||
/** | ||
* Returns the document id | ||
* @return the id | ||
*/ | ||
public String id() { | ||
return this.id; | ||
} | ||
|
||
/** | ||
* Returns the context for fetching _source | ||
* @return the fetchSourceContext | ||
*/ | ||
public FetchSourceContext fetchSourceContext() { | ||
return this.fetchSourceContext; | ||
} | ||
|
||
/** | ||
* Class for constructing a Builder for this Request Object | ||
*/ | ||
public static class Builder { | ||
private String index = null; | ||
private String id = null; | ||
private FetchSourceContext fetchSourceContext; | ||
|
||
/** | ||
* Empty Constructor for the Builder object | ||
*/ | ||
public Builder() {} | ||
|
||
/** | ||
* Add an index to this builder | ||
* @param index the index to put the object | ||
* @return the updated builder | ||
*/ | ||
public Builder index(String index) { | ||
this.index = index; | ||
return this; | ||
} | ||
|
||
/** | ||
* Add an id to this builder | ||
* @param id the document id | ||
* @return the updated builder | ||
*/ | ||
public Builder id(String id) { | ||
this.id = id; | ||
return this; | ||
} | ||
|
||
/** | ||
* Add a fetchSourceContext to this builder | ||
* @param fetchSourceContext the fetchSourceContext | ||
* @return the updated builder | ||
*/ | ||
public Builder fetchSourceContext(FetchSourceContext fetchSourceContext) { | ||
this.fetchSourceContext = fetchSourceContext; | ||
return this; | ||
} | ||
|
||
/** | ||
* Builds the request | ||
* @return A {@link GetDataObjectRequest} | ||
*/ | ||
public GetDataObjectRequest build() { | ||
return new GetDataObjectRequest(this.index, this.id, this.fetchSourceContext); | ||
} | ||
} | ||
} |
85 changes: 85 additions & 0 deletions
85
common/src/main/java/org/opensearch/sdk/GetDataObjectResponse.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,85 @@ | ||
/* | ||
* 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.core.xcontent.XContentParser; | ||
|
||
public class GetDataObjectResponse { | ||
private final String id; | ||
private final XContentParser parser; | ||
|
||
/** | ||
* Instantiate this request with an id and parser used to recreate the data object. | ||
* <p> | ||
* For data storage implementations other than OpenSearch, the id may be referred to as a primary key. | ||
* @param id the document id | ||
* @param parser an XContentParser that can be used to create the object. | ||
*/ | ||
public GetDataObjectResponse(String id, XContentParser parser) { | ||
this.id = id; | ||
this.parser = parser; | ||
} | ||
|
||
/** | ||
* Returns the document id | ||
* @return the id | ||
*/ | ||
public String id() { | ||
return this.id; | ||
} | ||
|
||
/** | ||
* Returns the parser | ||
* @return the parser | ||
*/ | ||
public XContentParser parser() { | ||
return this.parser; | ||
} | ||
|
||
/** | ||
* Class for constructing a Builder for this Response Object | ||
*/ | ||
public static class Builder { | ||
private String id = null; | ||
private XContentParser parser = null; | ||
|
||
/** | ||
* Empty Constructor for the Builder object | ||
*/ | ||
public Builder() {} | ||
|
||
/** | ||
* Add an id to this builder | ||
* @param id the id to add | ||
* @return the updated builder | ||
*/ | ||
public Builder id(String id) { | ||
this.id = id; | ||
return this; | ||
} | ||
|
||
/** | ||
* Add a parser to this builder | ||
* @param parser the parser | ||
* @return the updated builder | ||
*/ | ||
public Builder parser(XContentParser parser) { | ||
this.parser = parser; | ||
return this; | ||
} | ||
|
||
/** | ||
* Builds the response | ||
* @return A {@link GetDataObjectResponse} | ||
*/ | ||
public GetDataObjectResponse build() { | ||
return new GetDataObjectResponse(this.id, this.parser); | ||
} | ||
} | ||
} |
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.
Is
shardId
required? This can tie implementation specific to opensearch?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.
Unfortunately, yes. I didn't add anything I didn't have to.
This was required for
DeleteConnectorTransportAction
which processes anActionListener<DeleteResponse>
(which is eventually parsed and returned to the user) as a response to the delete API:It's not allowed to be null:
I can manufacture one (and the builder provides the facility to do that) but it's gotta be there. 😦