Skip to content

Commit

Permalink
Include in ser/de of PluginInfo
Browse files Browse the repository at this point in the history
Signed-off-by: Craig Perkins <[email protected]>
  • Loading branch information
cwperks committed Jan 3, 2025
1 parent 4a6d065 commit 754bc6f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
16 changes: 11 additions & 5 deletions server/src/main/java/org/opensearch/plugins/PluginInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,10 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -89,7 +87,7 @@ public class PluginInfo implements Writeable, ToXContentObject {
private final String customFolderName;
private final List<String> extendedPlugins;
// Optional extended plugins are a subset of extendedPlugins that only contains the optional extended plugins
private final Set<String> optionalExtendedPlugins;
private final List<String> optionalExtendedPlugins;
private final boolean hasNativeController;

/**
Expand Down Expand Up @@ -157,7 +155,7 @@ public PluginInfo(
this.optionalExtendedPlugins = extendedPlugins.stream()
.filter(PluginInfo::isOptionalExtension)
.map(s -> s.split(";")[0])
.collect(Collectors.toUnmodifiableSet());
.collect(Collectors.toUnmodifiableList());
this.hasNativeController = hasNativeController;
}

Expand Down Expand Up @@ -217,7 +215,11 @@ public PluginInfo(final StreamInput in) throws IOException {
this.customFolderName = in.readString();
this.extendedPlugins = in.readStringList();
this.hasNativeController = in.readBoolean();
this.optionalExtendedPlugins = new HashSet<>();
if (in.getVersion().onOrAfter(Version.V_2_19_0)) {
this.optionalExtendedPlugins = in.readStringList();
} else {
this.optionalExtendedPlugins = new ArrayList<>();
}
}

static boolean isOptionalExtension(String extendedPlugin) {
Expand Down Expand Up @@ -248,6 +250,9 @@ This works for currently supported range notations (=,~)
}
out.writeStringCollection(extendedPlugins);
out.writeBoolean(hasNativeController);
if (out.getVersion().onOrAfter(Version.V_2_19_0)) {
out.writeStringCollection(optionalExtendedPlugins);
}
}

/**
Expand Down Expand Up @@ -516,6 +521,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
builder.field("custom_foldername", customFolderName);
builder.field("extended_plugins", extendedPlugins);
builder.field("has_native_controller", hasNativeController);
builder.field("optional_extended_plugins", optionalExtendedPlugins);
}
builder.endObject();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,10 @@ private Plugin loadBundle(Bundle bundle, Map<String, Plugin> loaded) {
List<ClassLoader> extendedLoaders = new ArrayList<>();
for (String extendedPluginName : bundle.plugin.getExtendedPlugins()) {
Plugin extendedPlugin = loaded.get(extendedPluginName);
if (extendedPlugin == null && bundle.plugin.isExtendedPluginOptional(extendedPluginName)) {
// extended plugin is optional and is not installed
continue;
}
assert extendedPlugin != null;
if (ExtensiblePlugin.class.isInstance(extendedPlugin) == false) {
throw new IllegalStateException("Plugin [" + name + "] cannot extend non-extensible plugin [" + extendedPluginName + "]");
Expand Down

0 comments on commit 754bc6f

Please sign in to comment.