-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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/extensions] Added dependency information to Extensions #5438
[Feature/extensions] Added dependency information to Extensions #5438
Conversation
Gradle Check (Jenkins) Run Completed with:
|
Gradle Check (Jenkins) Run Completed with:
|
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.
Good start. Don't forget you'll need tests.
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
super.writeTo(out); | ||
pluginInfo.writeTo(out); | ||
((DiscoveryNode) dependencies).writeTo(out); |
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.
Dependencies is a List
, you shouldn't cast it to another class. I believe you either want out.writeList(List<? extends Writeable> list)
here, or you want to write an integer of the size and then write each list element. See example here
@@ -61,6 +67,7 @@ public void writeTo(StreamOutput out) throws IOException { | |||
public DiscoveryExtension(final StreamInput in) throws IOException { | |||
super(in); | |||
this.pluginInfo = new PluginInfo(in); | |||
this.dependencies = new ArrayList<ExtensionDenpendency>(); |
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.
You need the counterpart here of whatever you're writing in writeTo()
above. Simplest approach is probably to read the list size, declare your array list with that size, and then iterate up to that size and add to it. See example here
There's another option of in.readList()
that involves using a Reader
but a more simple iteration will probably work here.
import org.opensearch.common.io.stream.Writeable; | ||
|
||
public class ExtensionDenpendency implements Writeable { | ||
public String uniqueId; |
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.
make these private
since we have getters for them.
public ExtensionDenpendency(String uniqueId, Version version){ | ||
this.uniqueId = uniqueId; | ||
this.version = version; | ||
List<ExtensionDenpendency> dependencies = Collections.<ExtensionDenpendency>emptyList(); |
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.
No need to add a generic type for Collections.emptyList()
. It is inferred from the type definition.
@@ -333,7 +333,8 @@ private void extensionsDiscovery() throws IOException { | |||
extension.getClassName(), | |||
new ArrayList<String>(), | |||
Boolean.parseBoolean(extension.hasNativeController()) | |||
) | |||
), | |||
new ArrayList<ExtensionDenpendency>() |
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.
shouldn't this be extension.getDependencies()
?
Gradle Check (Jenkins) Run Completed with:
|
Gradle Check (Jenkins) Run Completed with:
|
for the tests, do you means |
Gradle Check (Jenkins) Run Completed with:
|
Gradle Check (Jenkins) Run Completed with:
|
Gradle Check (Jenkins) Run Completed with:
|
Gradle Check (Jenkins) Run Completed with:
|
Gradle Check (Jenkins) Run Completed with:
|
Gradle Check (Jenkins) Run Completed with:
|
Gradle Check (Jenkins) Run Completed with:
|
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.
This is looking really good! A few more tests needed!
CHANGELOG.md
Outdated
@@ -128,6 +128,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), | |||
- Enforce type safety for RegisterTransportActionsRequest([#4796](https://github.com/opensearch-project/OpenSearch/pull/4796)) | |||
- Modified local node request to return Discovery Node ([#4862](https://github.com/opensearch-project/OpenSearch/pull/4862)) | |||
- Enforce type safety for NamedWriteableRegistryParseRequest ([#4923](https://github.com/opensearch-project/OpenSearch/pull/4923)) | |||
- Update dependency information ([#5438](https://github.com/opensearch-project/OpenSearch/pull/5438)) |
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.
(Preference) Probably want this change log (and PR title) to be a little bit more self-explanatory, like "Add dependency information to Extensions"
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
super.writeTo(out); | ||
pluginInfo.writeTo(out); | ||
out.writeVInt(dependencies.size()); | ||
for (ExtensionDependency result : dependencies) { |
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.
(Preference) Let's use a loop variable name representing what we actually have here, like dependency
or dep
.
@@ -43,6 +43,7 @@ public static class Extension { | |||
private String className; | |||
private String customFolderName; | |||
private String hasNativeController; | |||
private List<ExtensionDependency> dependencies; |
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'm not sure what Jackson's ObjectMapper
does reading in a list from a YAML file when it doesn't exist. (If an extension has no dependencies we may want to allow them to leave dependencies:
blank. It may end up null
.
Since Jackson uses the no-arg constructor right below this, I'd suggest you initialize this to an empty list in that no-arg constructor block.
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.
Rereading this again, I see this is static inner Extension
class here in ExtensionSettings
. I don't think this is ever used or is needed at all. It's completely redundant with the DiscoveryExtension
class which is used elsewhere.
The change to add the list of dependencies is done in the DiscoveryExtension
class.
I actually think this entire inner class can be deleted. @owaiskazi19 do you agree?
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.
@dbwiddis Can we use Arrays.asList(new ExtensionDependency(extension.getUniqueId(), Version.fromString(extension.getOpensearchVersion())))
to replace extension.getDepdendency
in ExtensionsOrchestrator
, in this way, we can delete the getDependency
method in ExtensionSetting
.
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.
@dbwiddis Can we use
Arrays.asList(...
It's been a while since I did YAML import from Jackson. If Jackson reads in a list as an array, then:
- define the dependencies in this class as an array
- in ExtensionsOrchestrator, convert the array to a list as
Arrays.asList(extension.getDependencies())
return dependencies; | ||
} | ||
|
||
public void setDependencies(List<ExtensionDependency> dependencies) { |
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 don't think we need a setter for this list.
@@ -184,6 +185,14 @@ public void setHasNativeController(String hasNativeController) { | |||
this.hasNativeController = hasNativeController; | |||
} | |||
|
|||
public List<ExtensionDependency> getDependenices() { |
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.
Typo in the getter name here.
) | ||
); | ||
assertEquals(expectedExtensionsList.size(), extensionsOrchestrator.extensionIdMap.values().size()); | ||
assertTrue(expectedExtensionsList.containsAll(extensionsOrchestrator.extensionIdMap.values())); | ||
assertTrue(extensionsOrchestrator.extensionIdMap.values().containsAll(expectedExtensionsList)); | ||
} | ||
|
||
public void testExtensionDependency() throws Exception { |
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.
Great job on this test method for the new Dependency class.
You also need to alter the test for the DiscoveryExtension
to test the new dependencies
field.
Also higher up in the class, see where the YAML file is generated using a list of strings. You should add a dependency (or two) in the list for the second item (same as the test yaml file below), so you can:
- test that the first extension's dependency list is empty
- test that the second dependency list has an item with the appropriate unique ID and version.
f550c57
to
ea6c97c
Compare
Gradle Check (Jenkins) Run Completed with:
|
Codecov Report
@@ Coverage Diff @@
## feature/extensions #5438 +/- ##
========================================================
+ Coverage 70.97% 71.09% +0.12%
- Complexity 58486 58541 +55
========================================================
Files 4756 4757 +1
Lines 278926 278956 +30
Branches 40283 40287 +4
========================================================
+ Hits 197964 198321 +357
+ Misses 64810 64516 -294
+ Partials 16152 16119 -33
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
Gradle Check (Jenkins) Run Completed with:
|
) | ||
); | ||
assertEquals(expectedExtensionsList.size(), extensionsOrchestrator.extensionIdMap.values().size()); | ||
assertTrue(expectedExtensionsList.containsAll(extensionsOrchestrator.extensionIdMap.values())); | ||
assertTrue(extensionsOrchestrator.extensionIdMap.values().containsAll(expectedExtensionsList)); | ||
assertEquals(expectedExtensionsList.get(expectedExtensionsList.size() - 1), dependency.get(0)); |
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.
This works, but since we know we created a single-dependency list, can we just get(0)
here?
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.
You are right. we do not need the get(0)
, because we already create dependency as a single list and it is all we need.
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.
You are right. we do not need the
get(0)
, because we already create dependency as a single list and it is all we need.
Correct. We could even ignore the list and actually create a expectedDependency
object.
Gradle Check (Jenkins) Run Completed with:
|
Gradle Check (Jenkins) Run Completed with:
|
Gradle Check (Jenkins) Run Completed with:
|
Gradle Check (Jenkins) Run Completed with:
|
Gradle Check (Jenkins) Run Completed with:
|
Signed-off-by: Frank Lou mloufra@amazon.com
Description
ExtensionDependency
class with two field (uniqueId and version) to get and store dependency information dataList<ExtensionDependency> dependencies
inDiscoveryExtension
class to let Jackson ObjectMapper can automatically map the dependencies entry toList<ExtensionDependency>
.extensions.yml
to show how it looks like after get the dependency information.Issues Resolved
Fixs opensearch-project/opensearch-sdk-java#151
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.