Skip to content
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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 common/src/main/java/org/opensearch/sdk/DeleteDataObjectResponse.java
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;
Copy link
Contributor

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?

Copy link
Member Author

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 an ActionListener<DeleteResponse> (which is eventually parsed and returned to the user) as a response to the delete API:

{
    "_index": "the_index",
    "_id": "vZAyLY8BaPsQZP-UDULE",
    "_version": 2,
    "result": "deleted",
    "_shards": {
        "total": 1,
        "successful": 1,
        "failed": 0
    },
    "_seq_no": 1,
    "_primary_term": 1
}

It's not allowed to be null:

this.shardId = Objects.requireNonNull(shardId);

I can manufacture one (and the builder provides the facility to do that) but it's gotta be there. 😦

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 common/src/main/java/org/opensearch/sdk/GetDataObjectRequest.java
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 common/src/main/java/org/opensearch/sdk/GetDataObjectResponse.java
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);
}
}
}
Loading
Loading