check "plugin already installed" before jar hell check.

In the case of a plugin using the deprecated `isolated=false` functionality
this will cause confusion otherwise.

Closes #14205
Closes #14207
This commit is contained in:
Robert Muir 2015-10-20 09:58:20 -04:00
parent ae73979e4b
commit 82eb5d299a
2 changed files with 46 additions and 5 deletions

View File

@ -220,11 +220,6 @@ public class PluginManager {
PluginInfo info = PluginInfo.readFromProperties(root); PluginInfo info = PluginInfo.readFromProperties(root);
terminal.println(VERBOSE, "%s", info); terminal.println(VERBOSE, "%s", info);
// check for jar hell before any copying
if (info.isJvm()) {
jarHellCheck(root, info.isIsolated());
}
// update name in handle based on 'name' property found in descriptor file // update name in handle based on 'name' property found in descriptor file
pluginHandle = new PluginHandle(info.getName(), pluginHandle.version, pluginHandle.user); pluginHandle = new PluginHandle(info.getName(), pluginHandle.version, pluginHandle.user);
final Path extractLocation = pluginHandle.extractedDir(environment); final Path extractLocation = pluginHandle.extractedDir(environment);
@ -232,6 +227,11 @@ public class PluginManager {
throw new IOException("plugin directory " + extractLocation.toAbsolutePath() + " already exists. To update the plugin, uninstall it first using 'remove " + pluginHandle.name + "' command"); throw new IOException("plugin directory " + extractLocation.toAbsolutePath() + " already exists. To update the plugin, uninstall it first using 'remove " + pluginHandle.name + "' command");
} }
// check for jar hell before any copying
if (info.isJvm()) {
jarHellCheck(root, info.isIsolated());
}
// read optional security policy (extra permissions) // read optional security policy (extra permissions)
// if it exists, confirm or warn the user // if it exists, confirm or warn the user
Path policy = root.resolve(PluginInfo.ES_PLUGIN_POLICY); Path policy = root.resolve(PluginInfo.ES_PLUGIN_POLICY);

View File

@ -57,6 +57,7 @@ import java.nio.file.FileVisitResult;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.SimpleFileVisitor; import java.nio.file.SimpleFileVisitor;
import java.nio.file.StandardOpenOption;
import java.nio.file.attribute.BasicFileAttributes; import java.nio.file.attribute.BasicFileAttributes;
import java.nio.file.attribute.PosixFileAttributeView; import java.nio.file.attribute.PosixFileAttributeView;
import java.nio.file.attribute.PosixFileAttributes; import java.nio.file.attribute.PosixFileAttributes;
@ -64,6 +65,7 @@ import java.nio.file.attribute.PosixFilePermission;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.jar.JarOutputStream;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream; import java.util.zip.ZipOutputStream;
@ -407,6 +409,45 @@ public class PluginManagerIT extends ESIntegTestCase {
assertThatPluginIsListed(pluginName); assertThatPluginIsListed(pluginName);
} }
/**
* @deprecated support for this is not going to stick around, seriously.
*/
@Deprecated
public void testAlreadyInstalledNotIsolated() throws Exception {
String pluginName = "fake-plugin";
Path pluginDir = createTempDir().resolve(pluginName);
Files.createDirectories(pluginDir);
// create a jar file in the plugin
Path pluginJar = pluginDir.resolve("fake-plugin.jar");
try (ZipOutputStream out = new JarOutputStream(Files.newOutputStream(pluginJar, StandardOpenOption.CREATE))) {
out.putNextEntry(new ZipEntry("foo.class"));
out.closeEntry();
}
String pluginUrl = createPlugin(pluginDir,
"description", "fake desc",
"name", pluginName,
"version", "1.0",
"elasticsearch.version", Version.CURRENT.toString(),
"java.version", System.getProperty("java.specification.version"),
"isolated", "false",
"jvm", "true",
"classname", "FakePlugin");
// install
ExitStatus status = new PluginManagerCliParser(terminal).execute(args("install " + pluginUrl));
assertEquals("unexpected exit status: output: " + terminal.getTerminalOutput(), ExitStatus.OK, status);
// install again
status = new PluginManagerCliParser(terminal).execute(args("install " + pluginUrl));
List<String> output = terminal.getTerminalOutput();
assertEquals("unexpected exit status: output: " + output, ExitStatus.IO_ERROR, status);
boolean foundExpectedMessage = false;
for (String line : output) {
foundExpectedMessage |= line.contains("already exists");
}
assertTrue(foundExpectedMessage);
}
public void testInstallSitePluginVerbose() throws IOException { public void testInstallSitePluginVerbose() throws IOException {
String pluginName = "fake-plugin"; String pluginName = "fake-plugin";
Path pluginDir = createTempDir().resolve(pluginName); Path pluginDir = createTempDir().resolve(pluginName);