Plugins: Output better error message when existing plugin is incompatible (#23562)

This commit catches the underlying failure when trying to list plugin
information when a plugin is incompatible with the current version of
elasticsearch. This could happen when elasticsearch is upgraded but old
plugins still exist. With this change, all plugins will be output,
instead of failing at the first out of date plugin.

closes #20691
This commit is contained in:
Ryan Ernst 2017-03-21 13:45:27 -07:00 committed by GitHub
parent bc65be2a65
commit 111e703cde
2 changed files with 34 additions and 7 deletions

View File

@ -56,9 +56,17 @@ class ListPluginsCommand extends EnvironmentAwareCommand {
}
Collections.sort(plugins);
for (final Path plugin : plugins) {
terminal.println(plugin.getFileName().toString());
PluginInfo info = PluginInfo.readFromProperties(env.pluginsFile().resolve(plugin.toAbsolutePath()));
terminal.println(Terminal.Verbosity.VERBOSE, info.toString());
terminal.println(Terminal.Verbosity.SILENT, plugin.getFileName().toString());
try {
PluginInfo info = PluginInfo.readFromProperties(env.pluginsFile().resolve(plugin.toAbsolutePath()));
terminal.println(Terminal.Verbosity.VERBOSE, info.toString());
} catch (IllegalArgumentException e) {
if (e.getMessage().contains("incompatible with Elasticsearch")) {
terminal.println("WARNING: " + e.getMessage());
} else {
throw e;
}
}
}
}
}

View File

@ -25,18 +25,15 @@ import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
import org.apache.lucene.util.LuceneTestCase;
import org.elasticsearch.Version;
import org.elasticsearch.cli.ExitCodes;
import org.elasticsearch.cli.MockTerminal;
import org.elasticsearch.common.inject.spi.HasDependencies;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.env.Environment;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.Version;
import org.junit.Before;
@LuceneTestCase.SuppressFileSystems("*")
@ -155,4 +152,26 @@ public class ListPluginsCommandTests extends ESTestCase {
env.pluginsFile().resolve("fake1").resolve(PluginInfo.ES_PLUGIN_PROPERTIES).toString() + "]");
}
public void testExistingIncompatiblePlugin() throws Exception {
PluginTestUtil.writeProperties(env.pluginsFile().resolve("fake_plugin1"),
"description", "fake desc 1",
"name", "fake_plugin1",
"version", "1.0",
"elasticsearch.version", Version.fromString("1.0.0").toString(),
"java.version", System.getProperty("java.specification.version"),
"classname", "org.fake1");
buildFakePlugin(env, "fake desc 2", "fake_plugin2", "org.fake2");
MockTerminal terminal = listPlugins(home);
assertEquals("fake_plugin1\n" +
"WARNING: Plugin [fake_plugin1] is incompatible with Elasticsearch [" +
Version.CURRENT.toString() + "]. Was designed for version [1.0.0]\n" +
"fake_plugin2\n",
terminal.getOutput());
String[] params = {"-s"};
terminal = listPlugins(home, params);
assertEquals("fake_plugin1\nfake_plugin2\n", terminal.getOutput());
}
}