Skip to content

Commit

Permalink
Kept the original constructor for PluginInfo to maintain bwc (opensea…
Browse files Browse the repository at this point in the history
…rch-project#1206)

Signed-off-by: Vacha <vachshah@amazon.com>
  • Loading branch information
VachaShah committed Sep 3, 2021
1 parent 495317f commit 601e5dc
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 33 deletions.
18 changes: 18 additions & 0 deletions server/src/main/java/org/opensearch/plugins/PluginInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,24 @@ public PluginInfo(String name, String description, String version, Version opens
this.hasNativeController = hasNativeController;
}

/**
* Construct plugin info.
*
* @param name the name of the plugin
* @param description a description of the plugin
* @param version an opaque version identifier for the plugin
* @param opensearchVersion the version of OpenSearch the plugin was built for
* @param javaVersion the version of Java the plugin was built with
* @param classname the entry point to the plugin
* @param extendedPlugins other plugins this plugin extends through SPI
* @param hasNativeController whether or not the plugin has a native controller
*/
public PluginInfo(String name, String description, String version, Version opensearchVersion, String javaVersion,
String classname, List<String> extendedPlugins, boolean hasNativeController) {
this(name, description, version, opensearchVersion, javaVersion, classname, null /* customFolderName */,
extendedPlugins, hasNativeController);
}

/**
* Construct plugin info from a stream.
*
Expand Down
12 changes: 6 additions & 6 deletions server/src/test/java/org/opensearch/plugins/PluginInfoTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ public void testExtendedPluginsEmpty() throws Exception {

public void testSerialize() throws Exception {
PluginInfo info = new PluginInfo("c", "foo", "dummy", Version.CURRENT, "1.8", "dummyclass",
"c", Collections.singletonList("foo"), randomBoolean());
"c", Collections.singletonList("foo"), randomBoolean());
BytesStreamOutput output = new BytesStreamOutput();
info.writeTo(output);
ByteBuffer buffer = ByteBuffer.wrap(output.bytes().toBytesRef().bytes);
Expand All @@ -250,15 +250,15 @@ public void testSerialize() throws Exception {
public void testPluginListSorted() {
List<PluginInfo> plugins = new ArrayList<>();
plugins.add(new PluginInfo("c", "foo", "dummy", Version.CURRENT, "1.8", "dummyclass",
null, Collections.emptyList(), randomBoolean()));
Collections.emptyList(), randomBoolean()));
plugins.add(new PluginInfo("b", "foo", "dummy", Version.CURRENT, "1.8", "dummyclass",
null, Collections.emptyList(), randomBoolean()));
Collections.emptyList(), randomBoolean()));
plugins.add(new PluginInfo( "e", "foo", "dummy", Version.CURRENT, "1.8", "dummyclass",
null, Collections.emptyList(), randomBoolean()));
Collections.emptyList(), randomBoolean()));
plugins.add(new PluginInfo("a", "foo", "dummy", Version.CURRENT, "1.8", "dummyclass",
null, Collections.emptyList(), randomBoolean()));
Collections.emptyList(), randomBoolean()));
plugins.add(new PluginInfo("d", "foo", "dummy", Version.CURRENT, "1.8", "dummyclass",
null, Collections.emptyList(), randomBoolean()));
Collections.emptyList(), randomBoolean()));
PluginsAndModules pluginsInfo = new PluginsAndModules(plugins, Collections.emptyList());

final List<PluginInfo> infos = pluginsInfo.getPluginInfos();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ public OneParameterIncorrectType(Object object) {
public void testSortBundlesCycleSelfReference() throws Exception {
Path pluginDir = createTempDir();
PluginInfo info = new PluginInfo("foo", "desc", "1.0", Version.CURRENT, "1.8",
"MyPlugin", null, Collections.singletonList("foo"), false);
"MyPlugin", Collections.singletonList("foo"), false);
PluginsService.Bundle bundle = new PluginsService.Bundle(info, pluginDir);
IllegalStateException e = expectThrows(IllegalStateException.class, () ->
PluginsService.sortBundles(Collections.singleton(bundle))
Expand All @@ -335,16 +335,16 @@ public void testSortBundlesCycle() throws Exception {
Path pluginDir = createTempDir();
Set<PluginsService.Bundle> bundles = new LinkedHashSet<>(); // control iteration order, so we get know the beginning of the cycle
PluginInfo info = new PluginInfo("foo", "desc", "1.0", Version.CURRENT, "1.8",
"MyPlugin", null, Arrays.asList("bar", "other"), false);
"MyPlugin", Arrays.asList("bar", "other"), false);
bundles.add(new PluginsService.Bundle(info, pluginDir));
PluginInfo info2 = new PluginInfo("bar", "desc", "1.0", Version.CURRENT, "1.8",
"MyPlugin", null, Collections.singletonList("baz"), false);
"MyPlugin", Collections.singletonList("baz"), false);
bundles.add(new PluginsService.Bundle(info2, pluginDir));
PluginInfo info3 = new PluginInfo("baz", "desc", "1.0", Version.CURRENT, "1.8",
"MyPlugin", null, Collections.singletonList("foo"), false);
"MyPlugin", Collections.singletonList("foo"), false);
bundles.add(new PluginsService.Bundle(info3, pluginDir));
PluginInfo info4 = new PluginInfo("other", "desc", "1.0", Version.CURRENT, "1.8",
"MyPlugin", null, Collections.emptyList(), false);
"MyPlugin", Collections.emptyList(), false);
bundles.add(new PluginsService.Bundle(info4, pluginDir));

IllegalStateException e = expectThrows(IllegalStateException.class, () -> PluginsService.sortBundles(bundles));
Expand All @@ -354,7 +354,7 @@ public void testSortBundlesCycle() throws Exception {
public void testSortBundlesSingle() throws Exception {
Path pluginDir = createTempDir();
PluginInfo info = new PluginInfo("foo", "desc", "1.0", Version.CURRENT, "1.8",
"MyPlugin", null, Collections.emptyList(), false);
"MyPlugin", Collections.emptyList(), false);
PluginsService.Bundle bundle = new PluginsService.Bundle(info, pluginDir);
List<PluginsService.Bundle> sortedBundles = PluginsService.sortBundles(Collections.singleton(bundle));
assertThat(sortedBundles, Matchers.contains(bundle));
Expand All @@ -364,15 +364,15 @@ public void testSortBundlesNoDeps() throws Exception {
Path pluginDir = createTempDir();
Set<PluginsService.Bundle> bundles = new LinkedHashSet<>(); // control iteration order
PluginInfo info1 = new PluginInfo("foo", "desc", "1.0", Version.CURRENT, "1.8",
"MyPlugin", null, Collections.emptyList(), false);
"MyPlugin", Collections.emptyList(), false);
PluginsService.Bundle bundle1 = new PluginsService.Bundle(info1, pluginDir);
bundles.add(bundle1);
PluginInfo info2 = new PluginInfo("bar", "desc", "1.0", Version.CURRENT, "1.8",
"MyPlugin", null, Collections.emptyList(), false);
"MyPlugin", Collections.emptyList(), false);
PluginsService.Bundle bundle2 = new PluginsService.Bundle(info2, pluginDir);
bundles.add(bundle2);
PluginInfo info3 = new PluginInfo("baz", "desc", "1.0", Version.CURRENT, "1.8",
"MyPlugin", null, Collections.emptyList(), false);
"MyPlugin", Collections.emptyList(), false);
PluginsService.Bundle bundle3 = new PluginsService.Bundle(info3, pluginDir);
bundles.add(bundle3);
List<PluginsService.Bundle> sortedBundles = PluginsService.sortBundles(bundles);
Expand All @@ -382,7 +382,7 @@ public void testSortBundlesNoDeps() throws Exception {
public void testSortBundlesMissingDep() throws Exception {
Path pluginDir = createTempDir();
PluginInfo info = new PluginInfo("foo", "desc", "1.0", Version.CURRENT, "1.8",
"MyPlugin", "", Collections.singletonList("dne"), false);
"MyPlugin", Collections.singletonList("dne"), false);
PluginsService.Bundle bundle = new PluginsService.Bundle(info, pluginDir);
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () ->
PluginsService.sortBundles(Collections.singleton(bundle))
Expand All @@ -394,19 +394,19 @@ public void testSortBundlesCommonDep() throws Exception {
Path pluginDir = createTempDir();
Set<PluginsService.Bundle> bundles = new LinkedHashSet<>(); // control iteration order
PluginInfo info1 = new PluginInfo("grandparent", "desc", "1.0",Version.CURRENT, "1.8",
"MyPlugin", null, Collections.emptyList(), false);
"MyPlugin", Collections.emptyList(), false);
PluginsService.Bundle bundle1 = new PluginsService.Bundle(info1, pluginDir);
bundles.add(bundle1);
PluginInfo info2 = new PluginInfo("foo", "desc", "1.0", Version.CURRENT, "1.8",
"MyPlugin", null, Collections.singletonList("common"), false);
"MyPlugin", Collections.singletonList("common"), false);
PluginsService.Bundle bundle2 = new PluginsService.Bundle(info2, pluginDir);
bundles.add(bundle2);
PluginInfo info3 = new PluginInfo("bar", "desc", "1.0", Version.CURRENT, "1.8",
"MyPlugin", null, Collections.singletonList("common"), false);
"MyPlugin", Collections.singletonList("common"), false);
PluginsService.Bundle bundle3 = new PluginsService.Bundle(info3, pluginDir);
bundles.add(bundle3);
PluginInfo info4 = new PluginInfo("common", "desc", "1.0", Version.CURRENT, "1.8",
"MyPlugin", null, Collections.singletonList("grandparent"), false);
"MyPlugin", Collections.singletonList("grandparent"), false);
PluginsService.Bundle bundle4 = new PluginsService.Bundle(info4, pluginDir);
bundles.add(bundle4);
List<PluginsService.Bundle> sortedBundles = PluginsService.sortBundles(bundles);
Expand All @@ -417,11 +417,11 @@ public void testSortBundlesAlreadyOrdered() throws Exception {
Path pluginDir = createTempDir();
Set<PluginsService.Bundle> bundles = new LinkedHashSet<>(); // control iteration order
PluginInfo info1 = new PluginInfo("dep", "desc", "1.0", Version.CURRENT, "1.8",
"MyPlugin", null, Collections.emptyList(), false);
"MyPlugin", Collections.emptyList(), false);
PluginsService.Bundle bundle1 = new PluginsService.Bundle(info1, pluginDir);
bundles.add(bundle1);
PluginInfo info2 = new PluginInfo("myplugin", "desc", "1.0", Version.CURRENT, "1.8",
"MyPlugin", null, Collections.singletonList("dep"), false);
"MyPlugin", Collections.singletonList("dep"), false);
PluginsService.Bundle bundle2 = new PluginsService.Bundle(info2, pluginDir);
bundles.add(bundle2);
List<PluginsService.Bundle> sortedBundles = PluginsService.sortBundles(bundles);
Expand Down Expand Up @@ -480,7 +480,7 @@ public void testJarHellDuplicateCodebaseWithDep() throws Exception {
Map<String, Set<URL>> transitiveDeps = new HashMap<>();
transitiveDeps.put("dep", Collections.singleton(dupJar.toUri().toURL()));
PluginInfo info1 = new PluginInfo("myplugin", "desc", "1.0", Version.CURRENT, "1.8",
"MyPlugin", null, Collections.singletonList("dep"), false);
"MyPlugin", Collections.singletonList("dep"), false);
PluginsService.Bundle bundle = new PluginsService.Bundle(info1, pluginDir);
IllegalStateException e = expectThrows(IllegalStateException.class, () ->
PluginsService.checkBundleJarHell(JarHell.parseClassPath(), bundle, transitiveDeps));
Expand All @@ -499,7 +499,7 @@ public void testJarHellDuplicateCodebaseAcrossDeps() throws Exception {
transitiveDeps.put("dep1", Collections.singleton(dupJar.toUri().toURL()));
transitiveDeps.put("dep2", Collections.singleton(dupJar.toUri().toURL()));
PluginInfo info1 = new PluginInfo("myplugin", "desc", "1.0", Version.CURRENT, "1.8",
"MyPlugin", null, Arrays.asList("dep1", "dep2"), false);
"MyPlugin", Arrays.asList("dep1", "dep2"), false);
PluginsService.Bundle bundle = new PluginsService.Bundle(info1, pluginDir);
IllegalStateException e = expectThrows(IllegalStateException.class, () ->
PluginsService.checkBundleJarHell(JarHell.parseClassPath(), bundle, transitiveDeps));
Expand All @@ -516,7 +516,7 @@ public void testJarHellDuplicateClassWithCore() throws Exception {
Path pluginJar = pluginDir.resolve("plugin.jar");
makeJar(pluginJar, Level.class);
PluginInfo info1 = new PluginInfo("myplugin", "desc", "1.0", Version.CURRENT, "1.8",
"MyPlugin", null, Collections.emptyList(), false);
"MyPlugin", Collections.emptyList(), false);
PluginsService.Bundle bundle = new PluginsService.Bundle(info1, pluginDir);
IllegalStateException e = expectThrows(IllegalStateException.class, () ->
PluginsService.checkBundleJarHell(JarHell.parseClassPath(), bundle, new HashMap<>()));
Expand All @@ -535,7 +535,7 @@ public void testJarHellDuplicateClassWithDep() throws Exception {
Map<String, Set<URL>> transitiveDeps = new HashMap<>();
transitiveDeps.put("dep", Collections.singleton(depJar.toUri().toURL()));
PluginInfo info1 = new PluginInfo("myplugin", "desc", "1.0", Version.CURRENT, "1.8",
"MyPlugin", null, Collections.singletonList("dep"), false);
"MyPlugin", Collections.singletonList("dep"), false);
PluginsService.Bundle bundle = new PluginsService.Bundle(info1, pluginDir);
IllegalStateException e = expectThrows(IllegalStateException.class, () ->
PluginsService.checkBundleJarHell(JarHell.parseClassPath(), bundle, transitiveDeps));
Expand All @@ -558,7 +558,7 @@ public void testJarHellDuplicateClassAcrossDeps() throws Exception {
transitiveDeps.put("dep1", Collections.singleton(dep1Jar.toUri().toURL()));
transitiveDeps.put("dep2", Collections.singleton(dep2Jar.toUri().toURL()));
PluginInfo info1 = new PluginInfo("myplugin", "desc", "1.0", Version.CURRENT, "1.8",
"MyPlugin", null, Arrays.asList("dep1", "dep2"), false);
"MyPlugin", Arrays.asList("dep1", "dep2"), false);
PluginsService.Bundle bundle = new PluginsService.Bundle(info1, pluginDir);
IllegalStateException e = expectThrows(IllegalStateException.class, () ->
PluginsService.checkBundleJarHell(JarHell.parseClassPath(), bundle, transitiveDeps));
Expand All @@ -581,7 +581,7 @@ public void testJarHellTransitiveMap() throws Exception {
transitiveDeps.put("dep1", Collections.singleton(dep1Jar.toUri().toURL()));
transitiveDeps.put("dep2", Collections.singleton(dep2Jar.toUri().toURL()));
PluginInfo info1 = new PluginInfo("myplugin", "desc", "1.0", Version.CURRENT, "1.8",
"MyPlugin", null, Arrays.asList("dep1", "dep2"), false);
"MyPlugin", Arrays.asList("dep1", "dep2"), false);
PluginsService.Bundle bundle = new PluginsService.Bundle(info1, pluginDir);
PluginsService.checkBundleJarHell(JarHell.parseClassPath(), bundle, transitiveDeps);
Set<URL> deps = transitiveDeps.get("myplugin");
Expand Down Expand Up @@ -630,14 +630,14 @@ public void testNonExtensibleDep() throws Exception {

public void testIncompatibleOpenSearchVersion() throws Exception {
PluginInfo info = new PluginInfo("my_plugin", "desc", "1.0", LegacyESVersion.V_6_0_0,
"1.8", "FakePlugin", null, Collections.emptyList(), false);
"1.8", "FakePlugin", Collections.emptyList(), false);
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> PluginsService.verifyCompatibility(info));
assertThat(e.getMessage(), containsString("was built for OpenSearch version 6.0.0"));
}

public void testIncompatibleJavaVersion() throws Exception {
PluginInfo info = new PluginInfo("my_plugin", "desc", "1.0", Version.CURRENT,
"1000000.0", "FakePlugin", null, Collections.emptyList(), false);
"1000000.0", "FakePlugin", Collections.emptyList(), false);
IllegalStateException e = expectThrows(IllegalStateException.class, () -> PluginsService.verifyCompatibility(info));
assertThat(e.getMessage(), containsString("my_plugin requires Java"));
}
Expand Down Expand Up @@ -761,7 +761,7 @@ public void testPluginLoadFailure() throws IOException {
public void testExtensiblePlugin() {
TestExtensiblePlugin extensiblePlugin = new TestExtensiblePlugin();
PluginsService.loadExtensions(Collections.singletonList(
Tuple.tuple(new PluginInfo("extensible", null, null, null, null, null, null, Collections.emptyList(), false), extensiblePlugin)
Tuple.tuple(new PluginInfo("extensible", null, null, null, null, null, Collections.emptyList(), false), extensiblePlugin)
));

assertThat(extensiblePlugin.extensions, notNullValue());
Expand All @@ -770,8 +770,8 @@ public void testExtensiblePlugin() {
extensiblePlugin = new TestExtensiblePlugin();
TestPlugin testPlugin = new TestPlugin();
PluginsService.loadExtensions(Arrays.asList(
Tuple.tuple(new PluginInfo("extensible", null, null, null, null, null, null, Collections.emptyList(), false), extensiblePlugin),
Tuple.tuple(new PluginInfo("test", null, null, null, null, null, null, Collections.singletonList("extensible"), false),
Tuple.tuple(new PluginInfo("extensible", null, null, null, null, null, Collections.emptyList(), false), extensiblePlugin),
Tuple.tuple(new PluginInfo("test", null, null, null, null, null, Collections.singletonList("extensible"), false),
testPlugin)
));

Expand Down

0 comments on commit 601e5dc

Please sign in to comment.