diff --git a/server/src/main/java/org/opensearch/extensions/DiscoveryExtension.java b/server/src/main/java/org/opensearch/extensions/DiscoveryExtension.java index adb55742b1063..0b952106687af 100644 --- a/server/src/main/java/org/opensearch/extensions/DiscoveryExtension.java +++ b/server/src/main/java/org/opensearch/extensions/DiscoveryExtension.java @@ -20,6 +20,7 @@ import org.opensearch.plugins.PluginInfo; import java.io.IOException; +import java.util.List; import java.util.Map; /** @@ -30,6 +31,7 @@ public class DiscoveryExtension extends DiscoveryNode implements Writeable, ToXContentFragment { private final PluginInfo pluginInfo; + private ExtensionDenpendency dependencies; public DiscoveryExtension( String name, @@ -40,16 +42,18 @@ public DiscoveryExtension( TransportAddress address, Map attributes, Version version, - PluginInfo pluginInfo + PluginInfo pluginInfo, + ExtensionDenpendency dependencies ) { super(name, id, ephemeralId, hostName, hostAddress, address, attributes, DiscoveryNodeRole.BUILT_IN_ROLES, version); - this.pluginInfo = pluginInfo; + this.pluginInfo = pluginInfo; } @Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); pluginInfo.writeTo(out); + dependencies.writeTo(out); } /** @@ -61,6 +65,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 ExtensionDenpendency(in); } @Override diff --git a/server/src/main/java/org/opensearch/extensions/ExtensionDenpendency.java b/server/src/main/java/org/opensearch/extensions/ExtensionDenpendency.java new file mode 100644 index 0000000000000..1684229f35b32 --- /dev/null +++ b/server/src/main/java/org/opensearch/extensions/ExtensionDenpendency.java @@ -0,0 +1,53 @@ +package org.opensearch.extensions; + +import java.io.IOException; +import java.util.Objects; + +import org.opensearch.Version; +import org.opensearch.common.io.stream.StreamInput; +import org.opensearch.common.io.stream.StreamOutput; +import org.opensearch.common.io.stream.Writeable; + +public class ExtensionDenpendency implements Writeable { + public String uniqueId; + public Version version; + + public ExtensionDenpendency(String uniqueId, Version version){ + this.uniqueId = uniqueId; + this.version = version; + } + + public ExtensionDenpendency(StreamInput in) throws IOException { + uniqueId = in.readString(); + version = Version.readVersion(in); + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + out.writeString(uniqueId); + Version.writeVersion(version, out); + } + + public String getUniqueId(){ + return uniqueId; + } + + public Version getVersion(){ + return version; + } + + public String toString() { + return "RestActionsRequest{uniqueId=" + uniqueId + ", version=" + version + "}"; + } + + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + ExtensionDenpendency that = (ExtensionDenpendency) obj; + return Objects.equals(uniqueId, that.uniqueId) && Objects.equals(version, that.version); + } + + public int hashCode() { + return Objects.hash(uniqueId, version); + } +} diff --git a/server/src/main/java/org/opensearch/extensions/ExtensionsOrchestrator.java b/server/src/main/java/org/opensearch/extensions/ExtensionsOrchestrator.java index 838c5924d213c..d78c0d6e2152a 100644 --- a/server/src/main/java/org/opensearch/extensions/ExtensionsOrchestrator.java +++ b/server/src/main/java/org/opensearch/extensions/ExtensionsOrchestrator.java @@ -333,6 +333,10 @@ private void extensionsDiscovery() throws IOException { extension.getClassName(), new ArrayList(), Boolean.parseBoolean(extension.hasNativeController()) + ), + new ExtensionDenpendency( + extension.getUniqueId(), + Version.fromString(extension.getVersion()) ) ); extensionIdMap.put(extension.getUniqueId(), discoveryExtension); diff --git a/server/src/test/resources/config/extensions.yml b/server/src/test/resources/config/extensions.yml index 6264e9630ad60..e02a2913385d9 100644 --- a/server/src/test/resources/config/extensions.yml +++ b/server/src/test/resources/config/extensions.yml @@ -7,6 +7,11 @@ extensions: version: '3.0.0' - name: "secondExtension" uniqueId: 'uniqueid2' + dependencies: + - name: 'uniqueid0' + version: '2.0.0' + - name: 'uniqueid1' + version: '3.0.0' hostName: 'myIndependentPluginHost2' hostAddress: '127.0.0.1' port: '9301'