From 75956604eb328c5c158e3c4a80fc684e7fa8f825 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Tue, 6 Sep 2016 07:51:38 -0400 Subject: [PATCH] Print message when removing plugin with config When removing a plugin with a config directory, we preserve the config directory. This is because the workflow for upgrading a plugin involves removing and then installing the plugin again and losing the plugin config in this case would be terrible. This commit causes a message regarding this to be printed in case the user wants to manually delete these files. --- .../plugins/RemovePluginCommand.java | 7 ++++ .../plugins/RemovePluginCommandTests.java | 35 +++++++++++++++---- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/plugins/RemovePluginCommand.java b/core/src/main/java/org/elasticsearch/plugins/RemovePluginCommand.java index 808a30b5d4d..b86e36d772c 100644 --- a/core/src/main/java/org/elasticsearch/plugins/RemovePluginCommand.java +++ b/core/src/main/java/org/elasticsearch/plugins/RemovePluginCommand.java @@ -88,5 +88,12 @@ final class RemovePluginCommand extends SettingCommand { pluginPaths.add(tmpPluginDir); IOUtils.rm(pluginPaths.toArray(new Path[pluginPaths.size()])); + + // we preserve the config files in case the user is upgrading the plugin, but we print + // a message so the user knows in case they want to remove manually + final Path pluginConfigDir = env.configFile().resolve(pluginName); + if (Files.exists(pluginConfigDir)) { + terminal.println("-> Preserving plugin config files: " + pluginConfigDir); + } } } diff --git a/qa/evil-tests/src/test/java/org/elasticsearch/plugins/RemovePluginCommandTests.java b/qa/evil-tests/src/test/java/org/elasticsearch/plugins/RemovePluginCommandTests.java index e2910be64f0..b54c5ed00e4 100644 --- a/qa/evil-tests/src/test/java/org/elasticsearch/plugins/RemovePluginCommandTests.java +++ b/qa/evil-tests/src/test/java/org/elasticsearch/plugins/RemovePluginCommandTests.java @@ -19,6 +19,14 @@ package org.elasticsearch.plugins; +import org.apache.lucene.util.LuceneTestCase; +import org.elasticsearch.cli.MockTerminal; +import org.elasticsearch.cli.UserException; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.env.Environment; +import org.elasticsearch.test.ESTestCase; +import org.junit.Before; + import java.io.IOException; import java.nio.file.DirectoryStream; import java.nio.file.Files; @@ -26,13 +34,8 @@ import java.nio.file.Path; import java.util.HashMap; import java.util.Map; -import org.apache.lucene.util.LuceneTestCase; -import org.elasticsearch.cli.UserException; -import org.elasticsearch.cli.MockTerminal; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.env.Environment; -import org.elasticsearch.test.ESTestCase; -import org.junit.Before; +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.CoreMatchers.not; @LuceneTestCase.SuppressFileSystems("*") public class RemovePluginCommandTests extends ESTestCase { @@ -109,4 +112,22 @@ public class RemovePluginCommandTests extends ESTestCase { assertRemoveCleaned(env); } + public void testConfigDirPreserved() throws Exception { + Files.createDirectories(env.pluginsFile().resolve("fake")); + final Path configDir = env.configFile().resolve("fake"); + Files.createDirectories(configDir); + Files.createFile(configDir.resolve("fake.yml")); + final MockTerminal terminal = removePlugin("fake", home); + assertTrue(Files.exists(env.configFile().resolve("fake"))); + assertThat(terminal.getOutput(), containsString("-> Preserving plugin config files: " + configDir)); + assertRemoveCleaned(env); + } + + public void testNoConfigDirPreserved() throws Exception { + Files.createDirectories(env.pluginsFile().resolve("fake")); + final Path configDir = env.configFile().resolve("fake"); + final MockTerminal terminal = removePlugin("fake", home); + assertThat(terminal.getOutput(), not(containsString("-> Preserving plugin config files: " + configDir))); + } + }