From 29ff5b0b5b843f43a7e8a64b444bd645b4e8231d Mon Sep 17 00:00:00 2001 From: Craig Perkins Date: Mon, 23 Dec 2024 19:10:59 -0500 Subject: [PATCH] Only optional extended plugins Signed-off-by: Craig Perkins --- .../opensearch/plugins/ClasspathPluginIT.java | 52 ------------------- ....plugins.ClasspathPluginIT$SampleExtension | 8 --- .../opensearch/plugins/PluginsService.java | 13 +---- 3 files changed, 2 insertions(+), 71 deletions(-) delete mode 100644 server/src/internalClusterTest/java/org/opensearch/plugins/ClasspathPluginIT.java delete mode 100644 server/src/internalClusterTest/resources/META-INF/services/org.opensearch.plugins.ClasspathPluginIT$SampleExtension diff --git a/server/src/internalClusterTest/java/org/opensearch/plugins/ClasspathPluginIT.java b/server/src/internalClusterTest/java/org/opensearch/plugins/ClasspathPluginIT.java deleted file mode 100644 index fffef3f55c5b3..0000000000000 --- a/server/src/internalClusterTest/java/org/opensearch/plugins/ClasspathPluginIT.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * The OpenSearch Contributors require contributions made to - * this file be licensed under the Apache-2.0 license or a - * compatible open source license. - */ - -package org.opensearch.plugins; - -import org.opensearch.test.OpenSearchIntegTestCase; - -import java.io.IOException; -import java.util.Collection; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import static org.hamcrest.Matchers.equalTo; - -@OpenSearchIntegTestCase.ClusterScope(scope = OpenSearchIntegTestCase.Scope.TEST, numDataNodes = 0) -public class ClasspathPluginIT extends OpenSearchIntegTestCase { - - public interface SampleExtension {} - - public static class SampleExtensiblePlugin extends Plugin implements ExtensiblePlugin { - public SampleExtensiblePlugin() {} - - @Override - public void loadExtensions(ExtensiblePlugin.ExtensionLoader loader) { - int nLoaded = 0; - for (SampleExtension e : loader.loadExtensions(SampleExtension.class)) { - nLoaded++; - } - - assertThat(nLoaded, equalTo(1)); - } - } - - public static class SampleExtendingPlugin extends Plugin implements SampleExtension { - public SampleExtendingPlugin() {} - }; - - @Override - protected Collection> nodePlugins() { - return Stream.concat(super.nodePlugins().stream(), Stream.of(SampleExtensiblePlugin.class, SampleExtendingPlugin.class)) - .collect(Collectors.toList()); - } - - public void testPluginExtensionWithClasspathPlugins() throws IOException { - internalCluster().startNode(); - } -} diff --git a/server/src/internalClusterTest/resources/META-INF/services/org.opensearch.plugins.ClasspathPluginIT$SampleExtension b/server/src/internalClusterTest/resources/META-INF/services/org.opensearch.plugins.ClasspathPluginIT$SampleExtension deleted file mode 100644 index f369b9d0f63b7..0000000000000 --- a/server/src/internalClusterTest/resources/META-INF/services/org.opensearch.plugins.ClasspathPluginIT$SampleExtension +++ /dev/null @@ -1,8 +0,0 @@ -# -# SPDX-License-Identifier: Apache-2.0 -# -# The OpenSearch Contributors require contributions made to -# this file be licensed under the Apache-2.0 license or a -# compatible open source license. - -org.opensearch.plugins.ClasspathPluginIT$SampleExtendingPlugin diff --git a/server/src/main/java/org/opensearch/plugins/PluginsService.java b/server/src/main/java/org/opensearch/plugins/PluginsService.java index a4b3bec0c1db8..f96e34c27442c 100644 --- a/server/src/main/java/org/opensearch/plugins/PluginsService.java +++ b/server/src/main/java/org/opensearch/plugins/PluginsService.java @@ -150,7 +150,7 @@ public PluginsService( "1.8", pluginClass.getName(), null, - classpathPlugins.stream().map(Class::getName).filter(cp -> !pluginClass.getName().equals(cp)).collect(Collectors.toList()), + Collections.emptyList(), false ); if (logger.isTraceEnabled()) { @@ -160,7 +160,6 @@ public PluginsService( pluginsList.add(pluginInfo); pluginsNames.add(pluginInfo.getName()); } - loadExtensions(pluginsLoaded); Set seenBundles = new LinkedHashSet<>(); List modulesList = new ArrayList<>(); @@ -571,17 +570,9 @@ private static void loadExtensionsForPlugin(ExtensiblePlugin extensiblePlugin, L ExtensiblePlugin.ExtensionLoader extensionLoader = new ExtensiblePlugin.ExtensionLoader() { @Override public List loadExtensions(Class extensionPointType) { - Set> seenClasses = new LinkedHashSet<>(); List result = new ArrayList<>(); - for (Plugin extendingPlugin : extendingPlugins) { - List extensions = createExtensions(extensionPointType, extendingPlugin); - for (T extension : extensions) { - // Only add if we haven't seen this class before, needed for classpath extensions for testing - if (seenClasses.add(extension.getClass())) { - result.add(extension); - } - } + result.addAll(createExtensions(extensionPointType, extendingPlugin)); } return Collections.unmodifiableList(result); }