[Feature/extensions]Added query for initialized extensions#5628
[Feature/extensions]Added query for initialized extensions#5628mloufra wants to merge 16 commits intoopensearch-project:feature/extensionsfrom
Conversation
Signed-off-by: Frank Lou <mloufra@amazon.com>
Gradle Check (Jenkins) Run Completed with:
|
Codecov Report
@@ Coverage Diff @@
## feature/extensions #5628 +/- ##
========================================================
- Coverage 71.10% 70.94% -0.17%
+ Complexity 58612 58549 -63
========================================================
Files 4762 4763 +1
Lines 279038 279086 +48
Branches 40301 40309 +8
========================================================
- Hits 198414 197987 -427
- Misses 64439 64960 +521
+ Partials 16185 16139 -46
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
Signed-off-by: Frank Lou <mloufra@amazon.com>
Gradle Check (Jenkins) Run Completed with:
|
Signed-off-by: Frank Lou <mloufra@amazon.com>
Gradle Check (Jenkins) Run Completed with:
|
| } | ||
|
|
||
| public ExtensionRequest(ExtensionsManager.RequestType requestType, String uniqueId) { | ||
| this.requestType = requestType; |
There was a problem hiding this comment.
Is there a reason that we don't have a super call here, when we have one in the StreamInput constructor?
There was a problem hiding this comment.
you means the constructor only for RequestType?
There was a problem hiding this comment.
I guess if the super constructor only has the one argument, then the super call should be in the other constructor actually.
There was a problem hiding this comment.
For here, I am trying to use constructor overloading. we can define the first constructor is a special case of the second constructor, constructor can uses the this keyword to call another constructor in the same class, and for the first constructor we only need requestType so we set the argument uniqueId as null and only pass requestType.
There was a problem hiding this comment.
I looked more into it, and there isn't a constructor on TransportRequest that only uses requestType so we're fine in this case. In general though, even when overloading we can still use a super call if the same method exists in the class that we are extending.
There was a problem hiding this comment.
You are right, I will delete the first constructor.
There was a problem hiding this comment.
Don't delete it - the overload is necessary here
There was a problem hiding this comment.
Everything is good with the constructors on this PR
|
I see that one of the big conceptual changes in this PR is the ability for uniqueId to be |
For the issue #149, we are going to create a request class for SDK to send extension dependency request to Opensearch to get the information. And this uniqueId is the clues used to find the extension information. The reason why we check the uniqueId is |
Signed-off-by: Frank Lou <mloufra@amazon.com>
Signed-off-by: Frank Lou <mloufra@amazon.com>
Signed-off-by: Frank Lou <mloufra@amazon.com>
Signed-off-by: Frank Lou <mloufra@amazon.com>
Gradle Check (Jenkins) Run Completed with:
|
|
|
||
| public boolean dependenciesContain(ExtensionDependency dependency) { | ||
| for (ExtensionDependency extensiondependency : this.dependencies) { | ||
| if (dependency.getUniqueId().equals(extensiondependency.getUniqueId())) { |
There was a problem hiding this comment.
Nit: these nested if statements could be combined with &
Signed-off-by: Frank Lou <mloufra@amazon.com>
Gradle Check (Jenkins) Run Completed with:
|
Gradle Check (Jenkins) Run Completed with:
|
Gradle Check (Jenkins) Run Completed with:
|
Gradle Check (Jenkins) Run Completed with:
|
dbwiddis
left a comment
There was a problem hiding this comment.
This looks great so far. @owaiskazi19 has a really good point about it being a bad idea to internally store (and returning via getter) the id as a possibly null string.
Recommend you change the instance variable to Optional<String> uniqueId. Then:
equals()doesn't need a special null case- getter can directly return the optional
- in the stream constructor you'll need to temporarily store
id = in.readOptionalString();and then setthis.uniqueId = id == null ? Optional.empty() : Optional.of(id);
| } | ||
|
|
||
| @Override | ||
| public void writeTo(StreamOutput out) throws IOException { |
There was a problem hiding this comment.
We probably want to remove the super(in) on the stream constructor, then. I think it's a no-op for responses anyway, but I think the two methods should match up.
| * @opensearch.internal | ||
| */ | ||
| public class ExtensionDependencyResponse extends TransportResponse { | ||
| private List<DiscoveryExtensionNode> dependency; |
There was a problem hiding this comment.
(Style/Naming) Since this is a list of possibly more than one dependency, would prefer to use the plural dependencies here (and the getter, toString, equals, hashCode, etc.).
| @Override | ||
| public void writeTo(StreamOutput out) throws IOException { | ||
| out.writeVInt(dependency.size()); | ||
| for (DiscoveryExtensionNode dependency : dependency) { |
There was a problem hiding this comment.
(Code smell) This is not a good idea to have a locally scoped loop variable dependency with the same name as the instance variable. If you change the instance variable to dependencies the use of dependency inside the loop will be unambiguous.
| private final String uniqueId; | ||
|
|
||
| public ExtensionRequest(ExtensionsManager.RequestType requestType) { | ||
| this(requestType, null); |
There was a problem hiding this comment.
@mloufra is correct here, we can't use both super() and this(). We could use super() in the other constructor, but the constructor for the superclass doesn't do anything so it's not needed.
| public ExtensionRequest(StreamInput in) throws IOException { | ||
| super(in); | ||
| this.requestType = in.readEnum(ExtensionsManager.RequestType.class); | ||
| this.uniqueId = in.readOptionalString(); |
There was a problem hiding this comment.
For all the other existing use cases of ExtensionRequest we are asking for information that does not depend on the calling extension. Requiring us to include the uniqueId would add unnecessary bandwidth to the transport request.
This would require changing 3 other request/response use cases. If you want to open a new issue to discuss that, I'm ok with further discussion, but I think in this case making it optional is fine.
I would be open to changing the return type from the getUniqueId() getter from a nullable String to an Optional<String> and handling the null check internally if you think that's a better way of handling it.
|
|
||
| @Nullable | ||
| public String getUniqueId() { | ||
| return uniqueId; |
There was a problem hiding this comment.
Consider avoiding null here by making this:
public Optional<String> getUniqueId() {
return uniqueId == null ? Optional.empty() : Optional.of(uniqueId);
}Or, consider handling the readOptionalString(in) similarly to the above and storing the value internally as an Optional<String>, which after looking at the equals() implementation is a better idea.
There was a problem hiding this comment.
Since we set uniqueId as Optional<String>, it should be return uniqueId == null ? Optional.empty() : uniqueId;
| } else if (that.uniqueId == null) { | ||
| return Objects.equals(requestType, that.requestType) && false; | ||
| } else { | ||
| return Objects.equals(requestType, that.requestType) && uniqueId.equals(that.uniqueId); |
There was a problem hiding this comment.
I agree that storing uniqueId as a possible null creates a requirement to check it elsewhere. If we handle the input stream reading and make it an optional there (instead of null) then we could rely on Java to handle .equals() between two optionals without an extra check.
Signed-off-by: Frank Lou <mloufra@amazon.com>
Signed-off-by: Frank Lou <mloufra@amazon.com>
Gradle Check (Jenkins) Run Completed with:
|
Signed-off-by: Frank Lou <mloufra@amazon.com>
Gradle Check (Jenkins) Run Completed with:
|
Description
Create a feature to have an extension query to OpenSearch to obtain a list of initialized extensions and determine whether a particular extension is initialized.
Equivalent PR on OpenSearch-sdk-java : opensearch-project/opensearch-sdk-java#300
Issues Resolved
fixes opensearch-project/opensearch-sdk-java#149
Check List
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.