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.
This commit is contained in:
Jason Tedor 2016-09-06 07:51:38 -04:00
parent ab86660c65
commit 75956604eb
2 changed files with 35 additions and 7 deletions

View File

@ -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);
}
}
}

View File

@ -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)));
}
}