From 7d6acde538b1126f175b58a7f5b1e5a90b22162d Mon Sep 17 00:00:00 2001 From: Andrey Fadeyev Date: Sat, 15 Aug 2015 14:40:03 +0100 Subject: [PATCH 1/3] Show PluginInfo information after install only in verbose mode --- core/src/main/java/org/elasticsearch/plugins/PluginManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/elasticsearch/plugins/PluginManager.java b/core/src/main/java/org/elasticsearch/plugins/PluginManager.java index fd140ec3303..f50be0cc8a6 100644 --- a/core/src/main/java/org/elasticsearch/plugins/PluginManager.java +++ b/core/src/main/java/org/elasticsearch/plugins/PluginManager.java @@ -218,7 +218,7 @@ public class PluginManager { // read and validate the plugin descriptor PluginInfo info = PluginInfo.readFromProperties(root); - terminal.println("%s", info); + terminal.println(VERBOSE, "%s", info); // check for jar hell before any copying if (info.isJvm()) { From fc418de46e3f1b9393f540c029893452ed0a6508 Mon Sep 17 00:00:00 2001 From: Andrey Fadeyev Date: Sat, 15 Aug 2015 14:42:29 +0100 Subject: [PATCH 2/3] Format plugin info a bit more user-friendly to output it in a terminal Before: PluginInfo{name='cloud-aws', description='The Amazon Web Service (AWS) Cloud plugin allows to use AWS API for the unicast discovery mechanism and add S3 repositories.', site=false, jvm=true, classname=org.elasticsearch.plugin.cloud.aws.CloudAwsPlugin, isolated=true, version='2.1.0-SNAPSHOT'} After: - Plugin information: Name: cloud-aws Description: The Amazon Web Service (AWS) Cloud plugin allows to use AWS API for the unicast discovery mechanism and add S3 repositories. Site: false Version: 2.1.0-SNAPSHOT JVM: true * Classname: org.elasticsearch.plugin.cloud.aws.CloudAwsPlugin * Isolated: true --- .../org/elasticsearch/plugins/PluginInfo.java | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/plugins/PluginInfo.java b/core/src/main/java/org/elasticsearch/plugins/PluginInfo.java index 66f24e3a8c8..59ac62659ef 100644 --- a/core/src/main/java/org/elasticsearch/plugins/PluginInfo.java +++ b/core/src/main/java/org/elasticsearch/plugins/PluginInfo.java @@ -262,17 +262,19 @@ public class PluginInfo implements Streamable, ToXContent { @Override public String toString() { - final StringBuffer sb = new StringBuffer("PluginInfo{"); - sb.append("name='").append(name).append('\''); - sb.append(", description='").append(description).append('\''); - sb.append(", site=").append(site); - sb.append(", jvm=").append(jvm); + final StringBuilder information = new StringBuilder() + .append("- Plugin information:\n") + .append("Name: ").append(name).append("\n") + .append("Description: ").append(description).append("\n") + .append("Site: ").append(site).append("\n") + .append("Version: ").append(version).append("\n") + .append("JVM: ").append(jvm).append("\n"); + if (jvm) { - sb.append(", classname=").append(classname); - sb.append(", isolated=").append(isolated); + information.append(" * Classname: ").append(classname).append("\n"); + information.append(" * Isolated: ").append(isolated); } - sb.append(", version='").append(version).append('\''); - sb.append('}'); - return sb.toString(); + + return information.toString(); } } From 3fa3b1597f590bce6dfeb632e3ea7bf961e70399 Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Mon, 14 Sep 2015 11:32:33 -0400 Subject: [PATCH 3/3] [test] PluginManager plugin info printing Also removes @Test in keeping with Elasticsearch's slow migration away from the annotation in favor of test methods named testSomeThing. --- .../plugins/PluginManagerIT.java | 97 +++++++++++++------ 1 file changed, 68 insertions(+), 29 deletions(-) diff --git a/core/src/test/java/org/elasticsearch/plugins/PluginManagerIT.java b/core/src/test/java/org/elasticsearch/plugins/PluginManagerIT.java index bb2b01ca979..d7dbb3e7978 100644 --- a/core/src/test/java/org/elasticsearch/plugins/PluginManagerIT.java +++ b/core/src/test/java/org/elasticsearch/plugins/PluginManagerIT.java @@ -172,7 +172,7 @@ public class PluginManagerIT extends ESIntegTestCase { } return zip.toUri().toURL().toString(); } - @Test + public void testThatPluginNameMustBeSupplied() throws IOException { Path pluginDir = createTempDir().resolve("fake-plugin"); String pluginUrl = createPlugin(pluginDir, @@ -184,7 +184,6 @@ public class PluginManagerIT extends ESIntegTestCase { assertStatus("install --url " + pluginUrl, USAGE); } - @Test public void testLocalPluginInstallWithBinAndConfig() throws Exception { String pluginName = "fake-plugin"; Path pluginDir = createTempDir().resolve(pluginName); @@ -193,7 +192,7 @@ public class PluginManagerIT extends ESIntegTestCase { Files.createFile(pluginDir.resolve("bin").resolve("tool")); Files.createDirectories(pluginDir.resolve("config")); Files.createFile(pluginDir.resolve("config").resolve("file")); - + String pluginUrl = createPlugin(pluginDir, "description", "fake desc", "version", "1.0", @@ -201,7 +200,7 @@ public class PluginManagerIT extends ESIntegTestCase { "java.version", System.getProperty("java.specification.version"), "jvm", "true", "classname", "FakePlugin"); - + Environment env = initialSettings.v2(); Path binDir = env.binFile(); Path pluginBinDir = binDir.resolve(pluginName); @@ -231,14 +230,13 @@ public class PluginManagerIT extends ESIntegTestCase { /** * Test for #7890 */ - @Test public void testLocalPluginInstallWithBinAndConfigInAlreadyExistingConfigDir_7890() throws Exception { String pluginName = "fake-plugin"; Path pluginDir = createTempDir().resolve(pluginName); // create config/test.txt with contents 'version1' Files.createDirectories(pluginDir.resolve("config")); Files.write(pluginDir.resolve("config").resolve("test.txt"), "version1".getBytes(StandardCharsets.UTF_8)); - + String pluginUrl = createPlugin(pluginDir, "description", "fake desc", "version", "1.0", @@ -246,7 +244,7 @@ public class PluginManagerIT extends ESIntegTestCase { "java.version", System.getProperty("java.specification.version"), "jvm", "true", "classname", "FakePlugin"); - + Environment env = initialSettings.v2(); Path pluginConfigDir = env.configFile().resolve(pluginName); @@ -282,7 +280,7 @@ public class PluginManagerIT extends ESIntegTestCase { "java.version", System.getProperty("java.specification.version"), "jvm", "true", "classname", "FakePlugin"); - + assertStatusOk(String.format(Locale.ROOT, "install %s --url %s --verbose", pluginName, pluginUrl)); assertFileContent(pluginConfigDir, "test.txt", "version1"); @@ -332,7 +330,6 @@ public class PluginManagerIT extends ESIntegTestCase { } // For #7152 - @Test public void testLocalPluginInstallWithBinOnly_7152() throws Exception { String pluginName = "fake-plugin"; Path pluginDir = createTempDir().resolve(pluginName); @@ -346,7 +343,7 @@ public class PluginManagerIT extends ESIntegTestCase { "java.version", System.getProperty("java.specification.version"), "jvm", "true", "classname", "FakePlugin"); - + Environment env = initialSettings.v2(); Path binDir = env.binFile(); Path pluginBinDir = binDir.resolve(pluginName); @@ -356,20 +353,38 @@ public class PluginManagerIT extends ESIntegTestCase { assertDirectoryExists(pluginBinDir); } - @Test public void testListInstalledEmpty() throws IOException { assertStatusOk("list"); assertThat(terminal.getTerminalOutput(), hasItem(containsString("No plugin detected"))); } - @Test public void testListInstalledEmptyWithExistingPluginDirectory() throws IOException { Files.createDirectory(initialSettings.v2().pluginsFile()); assertStatusOk("list"); assertThat(terminal.getTerminalOutput(), hasItem(containsString("No plugin detected"))); } - @Test + public void testInstallPluginVerbose() throws IOException { + String pluginName = "fake-plugin"; + Path pluginDir = createTempDir().resolve(pluginName); + String pluginUrl = createPlugin(pluginDir, + "description", "fake desc", + "version", "1.0", + "elasticsearch.version", Version.CURRENT.toString(), + "java.version", System.getProperty("java.specification.version"), + "jvm", "true", + "classname", "FakePlugin"); + String command = String.format(Locale.ROOT, "install %s --url %s --verbose", pluginName, pluginUrl); + ExitStatus status = new PluginManagerCliParser(terminal).execute(args(command)); + assertThat("Terminal output was: " + terminal.getTerminalOutput(), status, is(ExitStatus.OK)); + assertThat(terminal.getTerminalOutput(), hasItem(containsString("Name: fake-plugin"))); + assertThat(terminal.getTerminalOutput(), hasItem(containsString("Description: fake desc"))); + assertThat(terminal.getTerminalOutput(), hasItem(containsString("Site: false"))); + assertThat(terminal.getTerminalOutput(), hasItem(containsString("Version: 1.0"))); + assertThat(terminal.getTerminalOutput(), hasItem(containsString("JVM: true"))); + assertThatPluginIsListed(pluginName); + } + public void testInstallPlugin() throws IOException { String pluginName = "fake-plugin"; Path pluginDir = createTempDir().resolve(pluginName); @@ -380,11 +395,39 @@ public class PluginManagerIT extends ESIntegTestCase { "java.version", System.getProperty("java.specification.version"), "jvm", "true", "classname", "FakePlugin"); - assertStatusOk(String.format(Locale.ROOT, "install %s --url %s --verbose", pluginName, pluginUrl)); + String command = String.format(Locale.ROOT, "install %s --url %s", pluginName, pluginUrl); + ExitStatus status = new PluginManagerCliParser(terminal).execute(args(command)); + assertThat("Terminal output was: " + terminal.getTerminalOutput(), status, is(ExitStatus.OK)); + assertThat(terminal.getTerminalOutput(), not(hasItem(containsString("Name: fake-plugin")))); + assertThat(terminal.getTerminalOutput(), not(hasItem(containsString("Description:")))); + assertThat(terminal.getTerminalOutput(), not(hasItem(containsString("Site:")))); + assertThat(terminal.getTerminalOutput(), not(hasItem(containsString("Version:")))); + assertThat(terminal.getTerminalOutput(), not(hasItem(containsString("JVM:")))); assertThatPluginIsListed(pluginName); } - @Test + public void testInstallSitePluginVerbose() throws IOException { + String pluginName = "fake-plugin"; + Path pluginDir = createTempDir().resolve(pluginName); + Files.createDirectories(pluginDir.resolve("_site")); + Files.createFile(pluginDir.resolve("_site").resolve("somefile")); + String pluginUrl = createPlugin(pluginDir, + "description", "fake desc", + "version", "1.0", + "site", "true"); + String command = String.format(Locale.ROOT, "install %s --url %s --verbose", pluginName, pluginUrl); + ExitStatus status = new PluginManagerCliParser(terminal).execute(args(command)); + assertThat("Terminal output was: " + terminal.getTerminalOutput(), status, is(ExitStatus.OK)); + assertThat(terminal.getTerminalOutput(), hasItem(containsString("Name: fake-plugin"))); + assertThat(terminal.getTerminalOutput(), hasItem(containsString("Description: fake desc"))); + assertThat(terminal.getTerminalOutput(), hasItem(containsString("Site: true"))); + assertThat(terminal.getTerminalOutput(), hasItem(containsString("Version: 1.0"))); + assertThat(terminal.getTerminalOutput(), hasItem(containsString("JVM: false"))); + assertThatPluginIsListed(pluginName); + // We want to check that Plugin Manager moves content to _site + assertFileExists(initialSettings.v2().pluginsFile().resolve(pluginName).resolve("_site")); + } + public void testInstallSitePlugin() throws IOException { String pluginName = "fake-plugin"; Path pluginDir = createTempDir().resolve(pluginName); @@ -394,13 +437,19 @@ public class PluginManagerIT extends ESIntegTestCase { "description", "fake desc", "version", "1.0", "site", "true"); - assertStatusOk(String.format(Locale.ROOT, "install %s --url %s --verbose", pluginName, pluginUrl)); + String command = String.format(Locale.ROOT, "install %s --url %s", pluginName, pluginUrl); + ExitStatus status = new PluginManagerCliParser(terminal).execute(args(command)); + assertThat("Terminal output was: " + terminal.getTerminalOutput(), status, is(ExitStatus.OK)); + assertThat(terminal.getTerminalOutput(), not(hasItem(containsString("Name: fake-plugin")))); + assertThat(terminal.getTerminalOutput(), not(hasItem(containsString("Description:")))); + assertThat(terminal.getTerminalOutput(), not(hasItem(containsString("Site:")))); + assertThat(terminal.getTerminalOutput(), not(hasItem(containsString("Version:")))); + assertThat(terminal.getTerminalOutput(), not(hasItem(containsString("JVM:")))); assertThatPluginIsListed(pluginName); // We want to check that Plugin Manager moves content to _site assertFileExists(initialSettings.v2().pluginsFile().resolve(pluginName).resolve("_site")); } - @Test public void testInstallPluginWithBadChecksum() throws IOException { String pluginName = "fake-plugin"; Path pluginDir = createTempDir().resolve(pluginName); @@ -441,7 +490,6 @@ public class PluginManagerIT extends ESIntegTestCase { * We test regular form: username/reponame/version * It should find it in download.elasticsearch.org service */ - @Test @Network @AwaitsFix(bugUrl = "fails with jar hell failures - http://build-us-00.elastic.co/job/es_core_master_oracle_6/519/testReport/") public void testInstallPluginWithElasticsearchDownloadService() throws IOException { @@ -455,7 +503,6 @@ public class PluginManagerIT extends ESIntegTestCase { * We test regular form: groupId/artifactId/version * It should find it in maven central service */ - @Test @Network @AwaitsFix(bugUrl = "fails with jar hell failures - http://build-us-00.elastic.co/job/es_core_master_oracle_6/519/testReport/") public void testInstallPluginWithMavenCentral() throws IOException { @@ -470,7 +517,6 @@ public class PluginManagerIT extends ESIntegTestCase { * We test site plugins from github: userName/repoName * It should find it on github */ - @Test @Network @AwaitsFix(bugUrl = "needs to be adapted to 2.0") public void testInstallPluginWithGithub() throws IOException { assumeTrue("github.com is accessible", isDownloadServiceWorking("github.com", 443, "/")); @@ -492,10 +538,9 @@ public class PluginManagerIT extends ESIntegTestCase { return false; } - @Test public void testRemovePlugin() throws Exception { String pluginName = "plugintest"; - Path pluginDir = createTempDir().resolve(pluginName); + Path pluginDir = createTempDir().resolve(pluginName); String pluginUrl = createPlugin(pluginDir, "description", "fake desc", "version", "1.0.0", @@ -503,7 +548,7 @@ public class PluginManagerIT extends ESIntegTestCase { "java.version", System.getProperty("java.specification.version"), "jvm", "true", "classname", "FakePlugin"); - + // We want to remove plugin with plugin short name singlePluginInstallAndRemove("plugintest", "plugintest", pluginUrl); @@ -514,18 +559,15 @@ public class PluginManagerIT extends ESIntegTestCase { singlePluginInstallAndRemove("groupid/plugintest", "plugintest", pluginUrl); } - @Test public void testRemovePlugin_NullName_ThrowsException() throws IOException { assertStatus("remove ", USAGE); } - @Test public void testRemovePluginWithURLForm() throws Exception { assertStatus("remove file://whatever", USAGE); assertThat(terminal.getTerminalOutput(), hasItem(containsString("Illegal plugin name"))); } - @Test public void testForbiddenPluginNames() throws IOException { assertStatus("remove elasticsearch", USAGE); assertStatus("remove elasticsearch.bat", USAGE); @@ -537,7 +579,6 @@ public class PluginManagerIT extends ESIntegTestCase { assertStatus("remove ELASTICSEARCH.IN.SH", USAGE); } - @Test public void testOfficialPluginName_ThrowsException() throws IOException { PluginManager.checkForOfficialPlugins("elasticsearch-analysis-icu"); PluginManager.checkForOfficialPlugins("elasticsearch-analysis-kuromoji"); @@ -559,13 +600,11 @@ public class PluginManagerIT extends ESIntegTestCase { } } - @Test public void testThatBasicAuthIsRejectedOnHttp() throws Exception { assertStatus(String.format(Locale.ROOT, "install foo --url http://user:pass@localhost:12345/foo.zip --verbose"), CliTool.ExitStatus.IO_ERROR); assertThat(terminal.getTerminalOutput(), hasItem(containsString("Basic auth is only supported for HTTPS!"))); } - @Test public void testThatBasicAuthIsSupportedWithHttps() throws Exception { assumeTrue("test requires security manager to be disabled", System.getSecurityManager() == null);