Skip to content

Commit

Permalink
Check version compatiblity for non-semantic builds
Browse files Browse the repository at this point in the history
  • Loading branch information
williamrandolph committed Oct 24, 2023
1 parent d84c7c6 commit 3cb85f0
Showing 1 changed file with 51 additions and 49 deletions.
100 changes: 51 additions & 49 deletions server/src/main/java/org/elasticsearch/plugins/PluginsUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,16 @@ public static List<Path> findPluginDirs(final Path rootPath) throws IOException

/**
* Verify the given plugin is compatible with the current Elasticsearch installation.
*
* <p>If the build version is not semantic, or if the plugin is an internal (old-style) plugin
* we require that the plugin ES version match the current build version. If we are loading
* a stable plugin on a semantic build, we do a semantic comparison to verify that the
* plugin was built with an earlier version of the same major release.</p>
*/
public static void verifyCompatibility(PluginDescriptor info) {
final String currentVersion = Build.current().version();
Matcher buildVersionMatcher = SemanticVersion.semanticPattern.matcher(currentVersion);
// If we're not on a semantic version, assume plugins are compatible
if (buildVersionMatcher.matches()) {
if (buildVersionMatcher.matches() && info.isStable()) {
SemanticVersion currentElasticsearchSemanticVersion;
try {
currentElasticsearchSemanticVersion = new SemanticVersion(
Expand All @@ -93,63 +97,61 @@ public static void verifyCompatibility(PluginDescriptor info) {
} catch (NumberFormatException e) {
throw new IllegalArgumentException("Couldn't parse integers from build version [" + currentVersion + "]", e);
}
if (info.isStable()) {
Matcher pluginEsVersionMatcher = SemanticVersion.semanticPattern.matcher(info.getElasticsearchVersion());
if (pluginEsVersionMatcher.matches() == false) {
throw new IllegalArgumentException(
"Expected semantic version for plugin [" + info.getName() + "] but was [" + info.getElasticsearchVersion() + "]"
);
}
SemanticVersion pluginElasticsearchSemanticVersion;
try {
pluginElasticsearchSemanticVersion = new SemanticVersion(
Integer.parseInt(pluginEsVersionMatcher.group(1)),
Integer.parseInt(pluginEsVersionMatcher.group(2)),
Integer.parseInt(pluginEsVersionMatcher.group(3))
);
} catch (NumberFormatException e) {
throw new IllegalArgumentException(
"Expected integer version for plugin [" + info.getName() + "] but found [" + info.getElasticsearchVersion() + "]",
e
);
}
Matcher pluginEsVersionMatcher = SemanticVersion.semanticPattern.matcher(info.getElasticsearchVersion());
if (pluginEsVersionMatcher.matches() == false) {
throw new IllegalArgumentException(
"Expected semantic version for plugin [" + info.getName() + "] but was [" + info.getElasticsearchVersion() + "]"
);
}
SemanticVersion pluginElasticsearchSemanticVersion;
try {
pluginElasticsearchSemanticVersion = new SemanticVersion(
Integer.parseInt(pluginEsVersionMatcher.group(1)),
Integer.parseInt(pluginEsVersionMatcher.group(2)),
Integer.parseInt(pluginEsVersionMatcher.group(3))
);
} catch (NumberFormatException e) {
throw new IllegalArgumentException(
"Expected integer version for plugin [" + info.getName() + "] but found [" + info.getElasticsearchVersion() + "]",
e
);
}

// case: Major version mismatch
if (pluginElasticsearchSemanticVersion.major != currentElasticsearchSemanticVersion.major) {
throw new IllegalArgumentException(
"Stable Plugin ["
+ info.getName()
+ "] was built for Elasticsearch major version "
+ pluginElasticsearchSemanticVersion.major
+ " but version "
+ currentVersion
+ " is running"
);
}
// case: Major version mismatch
if (pluginElasticsearchSemanticVersion.major != currentElasticsearchSemanticVersion.major) {
throw new IllegalArgumentException(
"Stable Plugin ["
+ info.getName()
+ "] was built for Elasticsearch major version "
+ pluginElasticsearchSemanticVersion.major
+ " but version "
+ currentVersion
+ " is running"
);
}

// case: stable plugin from the future
if (pluginElasticsearchSemanticVersion.after(currentElasticsearchSemanticVersion)) {
throw new IllegalArgumentException(
"Stable Plugin ["
+ info.getName()
+ "] was built for Elasticsearch version "
+ info.getElasticsearchVersion()
+ " but earlier version "
+ currentVersion
+ " is running"
);
}
} else if (info.getElasticsearchVersion().equals(currentVersion) == false) {
// case: stable plugin from the future
if (pluginElasticsearchSemanticVersion.after(currentElasticsearchSemanticVersion)) {
throw new IllegalArgumentException(
"Plugin ["
"Stable Plugin ["
+ info.getName()
+ "] was built for Elasticsearch version "
+ info.getElasticsearchVersion()
+ " but version "
+ " but earlier version "
+ currentVersion
+ " is running"
);
}
} else if (info.getElasticsearchVersion().equals(currentVersion) == false) {
throw new IllegalArgumentException(
"Plugin ["
+ info.getName()
+ "] was built for Elasticsearch version "
+ info.getElasticsearchVersion()
+ " but version "
+ currentVersion
+ " is running"
);
}
JarHell.checkJavaVersion(info.getName(), info.getJavaVersion());
}
Expand Down

0 comments on commit 3cb85f0

Please sign in to comment.