Skip to content

Commit

Permalink
Remove patch version check for plugin compatibility
Browse files Browse the repository at this point in the history
Signed-off-by: Abhilasha Seth <abseth@amazon.com>
  • Loading branch information
abseth-amzn committed Mar 26, 2023
1 parent 4d78bbf commit 2d82f13
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
12 changes: 11 additions & 1 deletion server/src/main/java/org/opensearch/plugins/PluginsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ public static List<Path> findPluginDirs(final Path rootPath) throws IOException
* Verify the given plugin is compatible with the current OpenSearch installation.
*/
static void verifyCompatibility(PluginInfo info) {
if (info.getOpenSearchVersion().equals(Version.CURRENT) == false) {
if (!isPluginVersionCompatibile(info.getOpenSearchVersion(), Version.CURRENT)) {
throw new IllegalArgumentException(
"Plugin ["
+ info.getName()
Expand All @@ -401,6 +401,16 @@ static void verifyCompatibility(PluginInfo info) {
JarHell.checkJavaVersion(info.getName(), info.getJavaVersion());
}

/**
* This method checks if plugin was built with a version that is compatible with core's version.
* @param pluginVersion OS version plugin was built with
* @param coreVersion Core version
* @return true if plugin's version is compatible with core, false otherwise
*/
static boolean isPluginVersionCompatibile(final Version pluginVersion, final Version coreVersion) {
return pluginVersion.major == coreVersion.major && pluginVersion.minor == coreVersion.minor;
}

static void checkForFailedPluginRemovals(final Path pluginsDirectory) throws IOException {
/*
* Check for the existence of a marker file that indicates any plugins are in a garbage state from a failed attempt to remove the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import org.opensearch.index.IndexModule;
import org.opensearch.test.MockLogAppender;
import org.opensearch.test.OpenSearchTestCase;
import org.opensearch.test.VersionUtils;
import org.hamcrest.Matchers;

import java.io.IOException;
Expand Down Expand Up @@ -717,6 +718,19 @@ public void testIncompatibleOpenSearchVersion() throws Exception {
assertThat(e.getMessage(), containsString("was built for OpenSearch version 6.0.0"));
}

public void testPluginDifferingWithCoreForPatchVersion() throws Exception {
// Get a version for plugin to use that is just before the core's version.
// We will use the plugin version for test only if it differs in patch version
Version pluginVersion = VersionUtils.getPreviousVersion(Version.CURRENT);
if (pluginVersion.major != Version.CURRENT.major || pluginVersion.minor != Version.CURRENT.minor) {
// Cannot fail the test as there is no version that differs with core's patch version
// but has the same major and minor version as core. Not a valid test in that case.
return;
}
PluginInfo info = new PluginInfo("my_plugin", "desc", "1.0", pluginVersion, "1.8", "FakePlugin", Collections.emptyList(), false);
PluginsService.verifyCompatibility(info);
}

public void testIncompatibleJavaVersion() throws Exception {
PluginInfo info = new PluginInfo(
"my_plugin",
Expand Down

0 comments on commit 2d82f13

Please sign in to comment.