Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable testing for ExtensiblePlugins using classpath plugins #16908

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
44154b5
Make extended plugins optional
cwperks Oct 15, 2024
9501854
Make extended plugins optional
cwperks Oct 15, 2024
9b3f406
Merge branch 'main' into optional-extended-plugins
cwperks Dec 13, 2024
44a4042
Load extensions for classpath plugins
cwperks Dec 14, 2024
7b4d7d7
Ensure only single instance for each classpath extension
cwperks Dec 14, 2024
1614706
Add test for classpath plugin extended plugin loading
cwperks Dec 22, 2024
4176c46
Enable testing for ExtensiblePlugins using classpath plugins
cwperks Dec 23, 2024
ef041b0
Merge branch 'main' into extend-classpath-plugins
cwperks Dec 24, 2024
09d1c82
Merge branch 'main' into extend-classpath-plugins
cwperks Dec 31, 2024
f840850
Add to CHANGELOG
cwperks Dec 31, 2024
69ceaab
Merge branch 'main' into extend-classpath-plugins
cwperks Jan 3, 2025
0fbe489
Merge branch 'main' into extend-classpath-plugins
cwperks Jan 6, 2025
7a07307
Merge branch 'extend-classpath-plugins' of https://github.com/cwperks…
cwperks Jan 6, 2025
7ddd9a3
Define PluginInfos from test files for classpath plugins
cwperks Jan 8, 2025
07df814
Merge branch 'main' into extend-classpath-plugins
cwperks Jan 21, 2025
df48c29
Add testing constructor for PluginsService
cwperks Jan 21, 2025
a4937bd
Single call to loadExtensions
cwperks Jan 21, 2025
49ec944
Merge branch 'main' into extend-classpath-plugins
cwperks Jan 22, 2025
4cf427c
Reduce number of MockNode constructors
cwperks Jan 22, 2025
f9bc2ae
Create 2 public constructors for MockNode
cwperks Jan 22, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add testing constructor for PluginsService
Signed-off-by: Craig Perkins <cwperx@amazon.com>
  • Loading branch information
cwperks committed Jan 21, 2025
commit df48c297a885a77c213886db7697069189723ce0
37 changes: 37 additions & 0 deletions server/src/main/java/org/opensearch/plugins/PluginsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,43 @@
return plugins.stream().flatMap(p -> p.v2().getSettingsFilter().stream()).collect(Collectors.toList());
}

/**
* Constructs a new PluginService
* @param settings The settings of the system
* @param modulesDirectory The directory modules exist in, or null if modules should not be loaded from the filesystem
* @param pluginsDirectory The directory plugins exist in, or null if plugins should not be loaded from the filesystem
* @param classpathPlugins Plugins that exist in the classpath which should be loaded
*/
public PluginsService(
Settings settings,
Path modulesDirectory,
Path pluginsDirectory,
Collection<Class<? extends Plugin>> classpathPlugins
) {
// Used for testing
this(
settings,
null,
modulesDirectory,
pluginsDirectory,
classpathPlugins.stream()
.map(
p -> new PluginInfo(
p.getName(),
"classpath plugin",
"NA",
Version.CURRENT,
"1.8",
p.getName(),
null,
Collections.emptyList(),
false
)
)
.collect(Collectors.toList())
);
}

/**
* Constructs a new PluginService
* @param settings The settings of the system
Expand Down Expand Up @@ -151,8 +188,8 @@
pluginsLoaded.add(new Tuple<>(pluginInfo, plugin));
pluginsList.add(pluginInfo);
pluginsNames.add(pluginInfo.getName());
} catch (ClassNotFoundException e) {
logger.error("Failed to load classpath plugin: " + pluginInfo.getClassname());

Check warning on line 192 in server/src/main/java/org/opensearch/plugins/PluginsService.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/plugins/PluginsService.java#L191-L192

Added lines #L191 - L192 were not covered by tests
}
}
loadExtensions(pluginsLoaded);
cwperks marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
Expand Down Expand Up @@ -101,23 +100,7 @@ public Settings additionalSettings() {
public static class FilterablePlugin extends Plugin implements ScriptPlugin {}

static PluginsService newPluginsService(Settings settings, Class<? extends Plugin>... classpathPlugins) {
Collection<PluginInfo> pluginInfos = new ArrayList<>();
for (Class<? extends Plugin> plugin : classpathPlugins) {
pluginInfos.add(
new PluginInfo(
plugin.getName(),
"classpath plugin",
"NA",
Version.CURRENT,
"1.8",
plugin.getName(),
null,
Collections.emptyList(),
false
)
);
}
return new PluginsService(settings, null, null, TestEnvironment.newEnvironment(settings).pluginsDir(), pluginInfos);
return new PluginsService(settings, null, TestEnvironment.newEnvironment(settings).pluginsDir(), Arrays.asList(classpathPlugins));
}

public void testAdditionalSettings() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@
import org.opensearch.node.InternalSettingsPreparer;
import org.opensearch.plugins.MapperPlugin;
import org.opensearch.plugins.Plugin;
import org.opensearch.plugins.PluginInfo;
import org.opensearch.plugins.PluginsService;
import org.opensearch.plugins.ScriptPlugin;
import org.opensearch.plugins.SearchPlugin;
Expand Down Expand Up @@ -390,23 +389,7 @@ private static class ServiceHolder implements Closeable {
throw new AssertionError("node.name must be set");
});
PluginsService pluginsService;
Collection<PluginInfo> pluginInfos = new ArrayList<>();
for (Class<? extends Plugin> plugin : plugins) {
pluginInfos.add(
new PluginInfo(
plugin.getName(),
"classpath plugin",
"NA",
Version.CURRENT,
"1.8",
plugin.getName(),
null,
Collections.emptyList(),
false
)
);
}
pluginsService = new PluginsService(nodeSettings, null, env.modulesDir(), env.pluginsDir(), pluginInfos);
pluginsService = new PluginsService(nodeSettings, env.modulesDir(), env.pluginsDir(), plugins);

client = (Client) Proxy.newProxyInstance(Client.class.getClassLoader(), new Class[] { Client.class }, clientInvocationHandler);
ScriptModule scriptModule = createScriptModule(pluginsService.filterPlugins(ScriptPlugin.class));
Expand Down
Loading