Skip to content

Commit

Permalink
Update denpendency info
Browse files Browse the repository at this point in the history
Signed-off-by: Frank Lou <mloufra@amazon.com>
  • Loading branch information
mloufra committed Dec 2, 2022
1 parent 9563441 commit f031ae6
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.opensearch.plugins.PluginInfo;

import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
Expand All @@ -30,6 +31,7 @@
public class DiscoveryExtension extends DiscoveryNode implements Writeable, ToXContentFragment {

private final PluginInfo pluginInfo;
private ExtensionDenpendency dependencies;

public DiscoveryExtension(
String name,
Expand All @@ -40,16 +42,18 @@ public DiscoveryExtension(
TransportAddress address,
Map<String, String> 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);
}

/**
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,10 @@ private void extensionsDiscovery() throws IOException {
extension.getClassName(),
new ArrayList<String>(),
Boolean.parseBoolean(extension.hasNativeController())
),
new ExtensionDenpendency(
extension.getUniqueId(),
Version.fromString(extension.getVersion())
)
);
extensionIdMap.put(extension.getUniqueId(), discoveryExtension);
Expand Down
5 changes: 5 additions & 0 deletions server/src/test/resources/config/extensions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit f031ae6

Please sign in to comment.