Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Fix SearchPhaseExecutionException to properly initCause ([#20320](https://github.com/opensearch-project/OpenSearch/pull/20320))
- Fix `cluster.remote.<cluster_alias>.server_name` setting no populating SNI ([#20321](https://github.com/opensearch-project/OpenSearch/pull/20321))
- Fix X-Opaque-Id header propagation (along with other response headers) for streaming Reactor Netty 4 transport ([#20371](https://github.com/opensearch-project/OpenSearch/pull/20371))
- Allow removing plugin that's optionally extended ([#20417](https://github.com/opensearch-project/OpenSearch/pull/20417))
- Fix indexing regression and bug fixes for grouping criteria. ([20145](https://github.com/opensearch-project/OpenSearch/pull/20145))

### Dependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.opensearch.cli.Terminal;
import org.opensearch.cli.UserException;
import org.opensearch.common.cli.EnvironmentAwareCommand;
import org.opensearch.common.collect.Tuple;
import org.opensearch.common.util.io.IOUtils;
import org.opensearch.env.Environment;
import org.opensearch.plugins.PluginsService;
Expand Down Expand Up @@ -98,13 +99,20 @@ void execute(Terminal terminal, Environment env, String pluginName, boolean purg
}

// first make sure nothing extends this plugin
List<String> usedBy = PluginsService.findPluginsByDependency(env.pluginsDir(), pluginName);
Tuple<List<String>, List<String>> dependents = PluginsService.findPluginsByDependency(env.pluginsDir(), pluginName);
List<String> usedBy = dependents.v1();
List<String> optionallyExtendedBy = dependents.v2();
if (usedBy.isEmpty() == false) {
throw new UserException(
PLUGIN_STILL_USED,
"plugin [" + pluginName + "] cannot be removed" + " because it is extended by other plugins: " + usedBy
);
}
if (optionallyExtendedBy.isEmpty() == false) {
terminal.println(
"WARNING: Some features of " + optionallyExtendedBy + " may not function without the dependency [" + pluginName + "]."
);
}

Path pluginDir = env.pluginsDir().resolve(pluginName);
Path pluginConfigDir = env.configDir().resolve(pluginName);
Expand Down
21 changes: 17 additions & 4 deletions server/src/main/java/org/opensearch/plugins/PluginsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -405,17 +405,30 @@ public static void checkJarHellForPlugin(
}
}

public static List<String> findPluginsByDependency(Path pluginsDir, String pluginName) throws IOException {
List<String> usedBy = new ArrayList<>();
/**
* Finds plugins that depend on the given plugin.
*
* @param pluginsDir the plugins directory
* @param pluginName the plugin name to find dependents for
* @return a Tuple where v1() is the list of plugins with required dependencies,
* and v2() is the list of plugins with optional dependencies
*/
public static Tuple<List<String>, List<String>> findPluginsByDependency(Path pluginsDir, String pluginName) throws IOException {
List<String> requiredBy = new ArrayList<>();
List<String> optionallyExtendedBy = new ArrayList<>();
Set<Bundle> bundles = getPluginBundles(pluginsDir);
for (Bundle bundle : bundles) {
for (String extendedPlugin : bundle.plugin.getExtendedPlugins()) {
if (extendedPlugin.equals(pluginName)) {
usedBy.add(bundle.plugin.getName());
if (bundle.plugin.isExtendedPluginOptional(extendedPlugin)) {
optionallyExtendedBy.add(bundle.plugin.getName());
} else {
requiredBy.add(bundle.plugin.getName());
}
}
}
}
return usedBy;
return new Tuple<>(requiredBy, optionallyExtendedBy);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1184,14 +1184,17 @@ public void testFindPluginsByDependency() throws Exception {
"other-plugin"
);

List<String> basePluginDependents = PluginsService.findPluginsByDependency(pluginsDir, "base-plugin");
assertThat(basePluginDependents, containsInAnyOrder("plugin1", "plugin2"));
Tuple<List<String>, List<String>> basePluginDependents = PluginsService.findPluginsByDependency(pluginsDir, "base-plugin");
assertThat(basePluginDependents.v1(), containsInAnyOrder("plugin1", "plugin2"));
assertTrue(basePluginDependents.v2().isEmpty());

List<String> otherPluginDependents = PluginsService.findPluginsByDependency(pluginsDir, "other-plugin");
assertThat(otherPluginDependents, containsInAnyOrder("plugin2", "plugin3"));
Tuple<List<String>, List<String>> otherPluginDependents = PluginsService.findPluginsByDependency(pluginsDir, "other-plugin");
assertThat(otherPluginDependents.v1(), containsInAnyOrder("plugin2", "plugin3"));
assertTrue(otherPluginDependents.v2().isEmpty());

List<String> nonExistentDependents = PluginsService.findPluginsByDependency(pluginsDir, "non-existent");
assertTrue(nonExistentDependents.isEmpty());
Tuple<List<String>, List<String>> nonExistentDependents = PluginsService.findPluginsByDependency(pluginsDir, "non-existent");
assertTrue(nonExistentDependents.v1().isEmpty());
assertTrue(nonExistentDependents.v2().isEmpty());
}

private PluginInfo getPluginInfoWithWithSemverRange(String semverRange) {
Expand Down
Loading