From 659493c4d2e0685577bca96c9bdb3fb7ab6c8004 Mon Sep 17 00:00:00 2001 From: Himadri Singh Date: Sun, 24 Nov 2013 20:27:34 +0530 Subject: [PATCH 1/9] Add versions to static page --- pom.xml | 3 ++- server/pom.xml | 6 ++++++ server/src/main/resources/static/index.html | 3 +++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index dee4133212e..e67cd1dbdee 100644 --- a/pom.xml +++ b/pom.xml @@ -41,6 +41,7 @@ UTF-8 0.25.0 2.1.0-incubating + 0.1.3 @@ -64,7 +65,7 @@ io.druid druid-api - 0.1.3 + ${druid.api.version} diff --git a/server/pom.xml b/server/pom.xml index 420e53cd7fc..7e45726afb8 100644 --- a/server/pom.xml +++ b/server/pom.xml @@ -229,6 +229,12 @@ + + + true + ${basedir}/src/main/resources + + maven-jar-plugin diff --git a/server/src/main/resources/static/index.html b/server/src/main/resources/static/index.html index cec3d620e88..fb8831e29ed 100644 --- a/server/src/main/resources/static/index.html +++ b/server/src/main/resources/static/index.html @@ -32,6 +32,9 @@
+
+

Druid Version: ${pom.version} Druid API Version: ${druid.api.version}

+
From abf417a1c4f9fef20e8cde8d35f0a34ebe6bc299 Mon Sep 17 00:00:00 2001 From: Himadri Singh Date: Tue, 26 Nov 2013 17:47:23 +0530 Subject: [PATCH 2/9] version of druid-server --- .../java/io/druid/server/StatusResource.java | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/server/src/main/java/io/druid/server/StatusResource.java b/server/src/main/java/io/druid/server/StatusResource.java index a2b30268d4d..3625641215c 100644 --- a/server/src/main/java/io/druid/server/StatusResource.java +++ b/server/src/main/java/io/druid/server/StatusResource.java @@ -24,6 +24,9 @@ import com.fasterxml.jackson.annotation.JsonProperty; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; /** */ @@ -35,11 +38,33 @@ public class StatusResource public Status doGet() { return new Status( - StatusResource.class.getPackage().getImplementationVersion(), + getMavenVersion("io.druid","druid-server"), new Memory(Runtime.getRuntime()) ); } + private String getMavenVersion(String groupId, String artifactId){ + + Properties properties = new Properties(); + try { + InputStream is = StatusResource.class.getClassLoader().getResourceAsStream( + String.format( + "META-INF/maven/%s/%s/pom.properties", + groupId, + artifactId + ) + ); + if (is == null) { + return null; + } + properties.load(is); + } + catch (IOException e) { +// e.printStackTrace(); + } + return properties.getProperty("version"); + } + public static class Status { final String version; final Memory memory; From 95fafe02a7ba3637199da00f000db2a5732f8203 Mon Sep 17 00:00:00 2001 From: Himadri Singh Date: Wed, 27 Nov 2013 12:21:35 +0530 Subject: [PATCH 3/9] server versions with loaded extensions versions --- s3-extensions/pom.xml | 14 +++ .../java/io/druid/server/StatusResource.java | 87 +++++++++++++++---- .../src/main/resources/druid-server.version | 3 + 3 files changed, 87 insertions(+), 17 deletions(-) create mode 100644 server/src/main/resources/druid-server.version diff --git a/s3-extensions/pom.xml b/s3-extensions/pom.xml index 93e0844925b..9b6f5ab3d54 100644 --- a/s3-extensions/pom.xml +++ b/s3-extensions/pom.xml @@ -66,4 +66,18 @@ test + + + + maven-jar-plugin + + + + true + + + + + + diff --git a/server/src/main/java/io/druid/server/StatusResource.java b/server/src/main/java/io/druid/server/StatusResource.java index 3625641215c..2f79d3564d6 100644 --- a/server/src/main/java/io/druid/server/StatusResource.java +++ b/server/src/main/java/io/druid/server/StatusResource.java @@ -20,12 +20,19 @@ package io.druid.server; import com.fasterxml.jackson.annotation.JsonProperty; +import com.google.inject.Injector; +import io.druid.initialization.DruidModule; +import io.druid.initialization.Initialization; +import io.druid.server.initialization.ExtensionsConfig; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; import java.io.IOException; import java.io.InputStream; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import java.util.Properties; /** @@ -38,22 +45,44 @@ public class StatusResource public Status doGet() { return new Status( - getMavenVersion("io.druid","druid-server"), + getVersion("/druid-server.version"), + getVersion("/druid-api.version"), + getExtensionVersions(), new Memory(Runtime.getRuntime()) ); } - private String getMavenVersion(String groupId, String artifactId){ + /** + * Load the extensions list and return the implementation-versions + * + * @return map of extensions loaded with their respective implementation versions. + */ + private Map getExtensionVersions() + { + final Injector injector = Initialization.makeStartupInjector(); + final ExtensionsConfig config = injector.getInstance(ExtensionsConfig.class); + final List druidModules = Initialization.getFromExtensions(config, DruidModule.class); + Map moduleVersions = new HashMap<>(); + for (DruidModule module : druidModules) { + Package pkg = module.getClass().getPackage(); + moduleVersions.put(pkg.getImplementationTitle(), pkg.getImplementationVersion()); + } + return moduleVersions; + } + + /** + * Load properties files from the classpath and return version number + * + * @param versionFile + * + * @return version number + */ + private String getVersion(String versionFile) + { Properties properties = new Properties(); try { - InputStream is = StatusResource.class.getClassLoader().getResourceAsStream( - String.format( - "META-INF/maven/%s/%s/pom.properties", - groupId, - artifactId - ) - ); + InputStream is = StatusResource.class.getResourceAsStream(versionFile); if (is == null) { return null; } @@ -65,20 +94,42 @@ public class StatusResource return properties.getProperty("version"); } - public static class Status { - final String version; + public static class Status + { + final String serverVersion; + final String apiVersion; + final Map extensionsVersion; final Memory memory; - public Status(String version, Memory memory) + public Status( + String serverVersion, + String apiVersion, + Map extensionsVersion, + Memory memory + ) { - this.version = version; + this.serverVersion = serverVersion; + this.apiVersion = apiVersion; + this.extensionsVersion = extensionsVersion; this.memory = memory; } @JsonProperty - public String getVersion() + public String getServerVersion() { - return version; + return serverVersion; + } + + @JsonProperty + public String getApiVersion() + { + return apiVersion; + } + + @JsonProperty + public Map getExtensionsVersion() + { + return extensionsVersion; } @JsonProperty @@ -88,13 +139,15 @@ public class StatusResource } } - public static class Memory { + public static class Memory + { final long maxMemory; final long totalMemory; final long freeMemory; final long usedMemory; - public Memory(Runtime runtime) { + public Memory(Runtime runtime) + { maxMemory = runtime.maxMemory(); totalMemory = runtime.totalMemory(); freeMemory = runtime.freeMemory(); diff --git a/server/src/main/resources/druid-server.version b/server/src/main/resources/druid-server.version new file mode 100644 index 00000000000..58b62601e88 --- /dev/null +++ b/server/src/main/resources/druid-server.version @@ -0,0 +1,3 @@ +version=${pom.version} +groupId=${pom.groupId} +artifactId=${pom.artifactId} From 47278ad10965210ffa7c597a8e442ee0c855ba9c Mon Sep 17 00:00:00 2001 From: Himadri Singh Date: Wed, 4 Dec 2013 10:21:19 +0530 Subject: [PATCH 4/9] Merge relevant changes from 'druid-version-info' --- cassandra-storage/pom.xml | 16 +++++++ common/pom.xml | 10 +++- examples/pom.xml | 8 ++++ hdfs-storage/pom.xml | 16 +++++++ indexing-hadoop/pom.xml | 11 +++++ indexing-service/pom.xml | 16 +++++++ kafka-eight/pom.xml | 16 +++++++ kafka-seven/pom.xml | 15 ++++++ processing/pom.xml | 8 ++++ s3-extensions/pom.xml | 1 + server/pom.xml | 16 +++---- services/pom.xml | 12 +++++ services/src/main/java/io/druid/cli/Main.java | 10 +++- .../src/main/java/io/druid/cli/Version.java | 46 +++++++++++++++++++ 14 files changed, 191 insertions(+), 10 deletions(-) create mode 100644 services/src/main/java/io/druid/cli/Version.java diff --git a/cassandra-storage/pom.xml b/cassandra-storage/pom.xml index 8a4a9f6278e..265b1ac71ba 100644 --- a/cassandra-storage/pom.xml +++ b/cassandra-storage/pom.xml @@ -53,4 +53,20 @@ test + + + + + maven-jar-plugin + + + + true + true + + + + + + diff --git a/common/pom.xml b/common/pom.xml index 7b15f631fc8..9b139d230b1 100644 --- a/common/pom.xml +++ b/common/pom.xml @@ -168,7 +168,15 @@ - + + + + true + true + + + + diff --git a/examples/pom.xml b/examples/pom.xml index 3ef0caaa856..8c510a12a78 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -104,6 +104,14 @@ + + + + true + true + + + diff --git a/hdfs-storage/pom.xml b/hdfs-storage/pom.xml index af3eb2a4140..40b122aed77 100644 --- a/hdfs-storage/pom.xml +++ b/hdfs-storage/pom.xml @@ -71,4 +71,20 @@ test + + + + + maven-jar-plugin + + + + true + true + + + + + + diff --git a/indexing-hadoop/pom.xml b/indexing-hadoop/pom.xml index 1278df33166..f3630004a85 100644 --- a/indexing-hadoop/pom.xml +++ b/indexing-hadoop/pom.xml @@ -101,6 +101,17 @@ + + maven-jar-plugin + + + + true + true + + + + maven-shade-plugin diff --git a/indexing-service/pom.xml b/indexing-service/pom.xml index 33361b66f2c..e21bccdd869 100644 --- a/indexing-service/pom.xml +++ b/indexing-service/pom.xml @@ -160,4 +160,20 @@ test + + + + + maven-jar-plugin + + + + true + true + + + + + + diff --git a/kafka-eight/pom.xml b/kafka-eight/pom.xml index 53601c90cee..9df3ab928c4 100644 --- a/kafka-eight/pom.xml +++ b/kafka-eight/pom.xml @@ -116,4 +116,20 @@ test + + + + + maven-jar-plugin + + + + true + true + + + + + + diff --git a/kafka-seven/pom.xml b/kafka-seven/pom.xml index f00bdea925a..216435b0046 100644 --- a/kafka-seven/pom.xml +++ b/kafka-seven/pom.xml @@ -55,4 +55,19 @@ test + + + + maven-jar-plugin + + + + true + true + + + + + + diff --git a/processing/pom.xml b/processing/pom.xml index a58ffad72fc..f682c9b5877 100644 --- a/processing/pom.xml +++ b/processing/pom.xml @@ -133,6 +133,14 @@ + + + + true + true + + + diff --git a/s3-extensions/pom.xml b/s3-extensions/pom.xml index 9b6f5ab3d54..da03fefb20d 100644 --- a/s3-extensions/pom.xml +++ b/s3-extensions/pom.xml @@ -74,6 +74,7 @@ true + true diff --git a/server/pom.xml b/server/pom.xml index 7e45726afb8..f1f34ef279b 100644 --- a/server/pom.xml +++ b/server/pom.xml @@ -224,17 +224,9 @@ caliper test - - - - - true - ${basedir}/src/main/resources - - maven-jar-plugin @@ -245,6 +237,14 @@ + + + + true + true + + + org.antlr diff --git a/services/pom.xml b/services/pom.xml index cf0f4d41d2c..fa08b5ae19e 100644 --- a/services/pom.xml +++ b/services/pom.xml @@ -51,8 +51,20 @@ ${project.parent.version} + + + maven-jar-plugin + + + + true + true + + + + org.apache.maven.plugins maven-shade-plugin diff --git a/services/src/main/java/io/druid/cli/Main.java b/services/src/main/java/io/druid/cli/Main.java index 551acea0706..91b56a83977 100644 --- a/services/src/main/java/io/druid/cli/Main.java +++ b/services/src/main/java/io/druid/cli/Main.java @@ -27,6 +27,8 @@ import io.druid.cli.convert.ConvertProperties; import io.druid.cli.validate.DruidJsonValidator; import io.druid.initialization.Initialization; import io.druid.server.initialization.ExtensionsConfig; +import org.apache.log4j.Level; +import org.apache.log4j.Logger; import java.util.List; @@ -41,7 +43,13 @@ public class Main builder.withDescription("Druid command-line runner.") .withDefaultCommand(Help.class) - .withCommands(Help.class); + .withCommands(Help.class, Version.class); + + Runnable cmd = builder.build().parse(args); + if (cmd instanceof Version) { + Logger.getRootLogger().setLevel(Level.OFF); + } + builder.withGroup("server") .withDescription("Run one of the Druid server types.") diff --git a/services/src/main/java/io/druid/cli/Version.java b/services/src/main/java/io/druid/cli/Version.java new file mode 100644 index 00000000000..40335deb1b7 --- /dev/null +++ b/services/src/main/java/io/druid/cli/Version.java @@ -0,0 +1,46 @@ +package io.druid.cli; + +import io.airlift.command.Command; +import io.druid.initialization.DruidModule; +import io.druid.initialization.Initialization; +import io.druid.server.initialization.ExtensionsConfig; + +@Command( + name = "version", + description = "Returns Druid version information" +) +public class Version implements Runnable { + @Override + public void run() + { + System.out.println("Druid version " + Initialization.class.getPackage().getImplementationVersion()); + System.out.println("Druid API version " + DruidModule.class.getPackage().getImplementationVersion()); + + ExtensionsConfig config = Initialization.makeStartupInjector().getInstance(ExtensionsConfig.class); + + System.out.println(""); + System.out.println("Registered Druid Modules"); + for (DruidModule module : Initialization.getFromExtensions(config, DruidModule.class)) { + String artifact = module.getClass().getPackage().getImplementationTitle(); + String version = module.getClass().getPackage().getImplementationVersion(); + + if(artifact != null) { + System.out.println( + String.format( + " - %s (%s-%s)", + module.getClass().getCanonicalName(), + module.getClass().getPackage().getImplementationTitle(), + module.getClass().getPackage().getImplementationVersion() + ) + ); + } else { + System.out.println( + String.format( + " - %s", + module.getClass().getCanonicalName() + ) + ); + } + } + } +} From a2c83887421b87d1053594c043b8dc3902112513 Mon Sep 17 00:00:00 2001 From: Himadri Singh Date: Wed, 4 Dec 2013 10:21:36 +0530 Subject: [PATCH 5/9] No need of druid-server.version --- server/src/main/java/io/druid/server/StatusResource.java | 2 +- server/src/main/resources/druid-server.version | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) delete mode 100644 server/src/main/resources/druid-server.version diff --git a/server/src/main/java/io/druid/server/StatusResource.java b/server/src/main/java/io/druid/server/StatusResource.java index 2f79d3564d6..59c6da0f4b1 100644 --- a/server/src/main/java/io/druid/server/StatusResource.java +++ b/server/src/main/java/io/druid/server/StatusResource.java @@ -45,7 +45,7 @@ public class StatusResource public Status doGet() { return new Status( - getVersion("/druid-server.version"), + Initialization.class.getPackage().getImplementationVersion(), getVersion("/druid-api.version"), getExtensionVersions(), new Memory(Runtime.getRuntime()) diff --git a/server/src/main/resources/druid-server.version b/server/src/main/resources/druid-server.version deleted file mode 100644 index 58b62601e88..00000000000 --- a/server/src/main/resources/druid-server.version +++ /dev/null @@ -1,3 +0,0 @@ -version=${pom.version} -groupId=${pom.groupId} -artifactId=${pom.artifactId} From 32200b9b41300d52826b4c73707801a7d24db308 Mon Sep 17 00:00:00 2001 From: Himadri Singh Date: Wed, 4 Dec 2013 11:00:47 +0530 Subject: [PATCH 6/9] removing debug line. --- services/src/main/java/io/druid/cli/Version.java | 1 - 1 file changed, 1 deletion(-) diff --git a/services/src/main/java/io/druid/cli/Version.java b/services/src/main/java/io/druid/cli/Version.java index 40335deb1b7..0ec5298a1bf 100644 --- a/services/src/main/java/io/druid/cli/Version.java +++ b/services/src/main/java/io/druid/cli/Version.java @@ -14,7 +14,6 @@ public class Version implements Runnable { public void run() { System.out.println("Druid version " + Initialization.class.getPackage().getImplementationVersion()); - System.out.println("Druid API version " + DruidModule.class.getPackage().getImplementationVersion()); ExtensionsConfig config = Initialization.makeStartupInjector().getInstance(ExtensionsConfig.class); From e6b915f1e7a42db676267d0efa23dd60d7c4ab15 Mon Sep 17 00:00:00 2001 From: Himadri Singh Date: Tue, 10 Dec 2013 00:05:56 +0530 Subject: [PATCH 7/9] druid-api version not required --- .../java/io/druid/server/StatusResource.java | 36 +------------------ 1 file changed, 1 insertion(+), 35 deletions(-) diff --git a/server/src/main/java/io/druid/server/StatusResource.java b/server/src/main/java/io/druid/server/StatusResource.java index 59c6da0f4b1..8fb6733d97f 100644 --- a/server/src/main/java/io/druid/server/StatusResource.java +++ b/server/src/main/java/io/druid/server/StatusResource.java @@ -46,14 +46,13 @@ public class StatusResource { return new Status( Initialization.class.getPackage().getImplementationVersion(), - getVersion("/druid-api.version"), getExtensionVersions(), new Memory(Runtime.getRuntime()) ); } /** - * Load the extensions list and return the implementation-versions + * Load the unique extensions and return their implementation-versions * * @return map of extensions loaded with their respective implementation versions. */ @@ -70,46 +69,19 @@ public class StatusResource return moduleVersions; } - /** - * Load properties files from the classpath and return version number - * - * @param versionFile - * - * @return version number - */ - private String getVersion(String versionFile) - { - - Properties properties = new Properties(); - try { - InputStream is = StatusResource.class.getResourceAsStream(versionFile); - if (is == null) { - return null; - } - properties.load(is); - } - catch (IOException e) { -// e.printStackTrace(); - } - return properties.getProperty("version"); - } - public static class Status { final String serverVersion; - final String apiVersion; final Map extensionsVersion; final Memory memory; public Status( String serverVersion, - String apiVersion, Map extensionsVersion, Memory memory ) { this.serverVersion = serverVersion; - this.apiVersion = apiVersion; this.extensionsVersion = extensionsVersion; this.memory = memory; } @@ -120,12 +92,6 @@ public class StatusResource return serverVersion; } - @JsonProperty - public String getApiVersion() - { - return apiVersion; - } - @JsonProperty public Map getExtensionsVersion() { From 8117fff4e20a8aeb1cf3fb5966c219054ccb348c Mon Sep 17 00:00:00 2001 From: Himadri Singh Date: Tue, 10 Dec 2013 00:39:10 +0530 Subject: [PATCH 8/9] Some minor fixes --- .../src/main/java/io/druid/cli/Version.java | 57 ++++++++++++------- 1 file changed, 38 insertions(+), 19 deletions(-) diff --git a/services/src/main/java/io/druid/cli/Version.java b/services/src/main/java/io/druid/cli/Version.java index 0ec5298a1bf..89306fc42fc 100644 --- a/services/src/main/java/io/druid/cli/Version.java +++ b/services/src/main/java/io/druid/cli/Version.java @@ -1,3 +1,22 @@ +/* + * Druid - a distributed column store. + * Copyright (C) 2012, 2013 Metamarkets Group Inc. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + package io.druid.cli; import io.airlift.command.Command; @@ -5,41 +24,41 @@ import io.druid.initialization.DruidModule; import io.druid.initialization.Initialization; import io.druid.server.initialization.ExtensionsConfig; +import java.lang.StringBuilder; + @Command( name = "version", description = "Returns Druid version information" ) -public class Version implements Runnable { +public class Version implements Runnable +{ + private static final String NL = "\n"; @Override public void run() { - System.out.println("Druid version " + Initialization.class.getPackage().getImplementationVersion()); + StringBuilder output = new StringBuilder(); + output.append("Druid version ").append(NL); + output.append(Initialization.class.getPackage().getImplementationVersion()).append(NL).append(NL); ExtensionsConfig config = Initialization.makeStartupInjector().getInstance(ExtensionsConfig.class); - System.out.println(""); - System.out.println("Registered Druid Modules"); + output.append("Registered Druid Modules").append(NL); + for (DruidModule module : Initialization.getFromExtensions(config, DruidModule.class)) { String artifact = module.getClass().getPackage().getImplementationTitle(); String version = module.getClass().getPackage().getImplementationVersion(); - if(artifact != null) { - System.out.println( - String.format( - " - %s (%s-%s)", - module.getClass().getCanonicalName(), - module.getClass().getPackage().getImplementationTitle(), - module.getClass().getPackage().getImplementationVersion() - ) - ); + if (artifact != null) { + output.append( + String.format(" - %s (%s-%s)", module.getClass().getCanonicalName(), artifact, version) + ).append(NL); } else { - System.out.println( - String.format( - " - %s", - module.getClass().getCanonicalName() - ) - ); + output.append( + String.format(" - %s", module.getClass().getCanonicalName()) + ).append(NL); } } + + System.out.println(output.toString()); } } From b5f6dbc32f9fdd3745f78da9ea7353c308de4b1b Mon Sep 17 00:00:00 2001 From: Himadri Singh Date: Tue, 10 Dec 2013 02:09:41 +0530 Subject: [PATCH 9/9] Code refactoring, one place! --- .../java/io/druid/server/StatusResource.java | 117 +++++++++++++++--- services/src/main/java/io/druid/cli/Main.java | 6 - .../src/main/java/io/druid/cli/Version.java | 32 +---- 3 files changed, 99 insertions(+), 56 deletions(-) diff --git a/server/src/main/java/io/druid/server/StatusResource.java b/server/src/main/java/io/druid/server/StatusResource.java index 8fb6733d97f..f2c01050496 100644 --- a/server/src/main/java/io/druid/server/StatusResource.java +++ b/server/src/main/java/io/druid/server/StatusResource.java @@ -28,12 +28,8 @@ import io.druid.server.initialization.ExtensionsConfig; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; -import java.io.IOException; -import java.io.InputStream; -import java.util.HashMap; +import java.util.ArrayList; import java.util.List; -import java.util.Map; -import java.util.Properties; /** */ @@ -43,6 +39,11 @@ public class StatusResource @GET @Produces("application/json") public Status doGet() + { + return getStatus(); + } + + public static Status getStatus() { return new Status( Initialization.class.getPackage().getImplementationVersion(), @@ -56,46 +57,55 @@ public class StatusResource * * @return map of extensions loaded with their respective implementation versions. */ - private Map getExtensionVersions() + private static List getExtensionVersions() { final Injector injector = Initialization.makeStartupInjector(); final ExtensionsConfig config = injector.getInstance(ExtensionsConfig.class); final List druidModules = Initialization.getFromExtensions(config, DruidModule.class); - Map moduleVersions = new HashMap<>(); + + List moduleVersions = new ArrayList<>(); for (DruidModule module : druidModules) { - Package pkg = module.getClass().getPackage(); - moduleVersions.put(pkg.getImplementationTitle(), pkg.getImplementationVersion()); + + String artifact = module.getClass().getPackage().getImplementationTitle(); + String version = module.getClass().getPackage().getImplementationVersion(); + + ModuleVersion moduleVersion; + if (artifact != null) { + moduleVersion = new ModuleVersion(module.getClass().getCanonicalName(), artifact, version); + } else { + moduleVersion = new ModuleVersion(module.getClass().getCanonicalName()); + } + + moduleVersions.add(moduleVersion); } return moduleVersions; } public static class Status { - final String serverVersion; - final Map extensionsVersion; + final String version; + final List modules; final Memory memory; public Status( - String serverVersion, - Map extensionsVersion, - Memory memory + String version, List modules, Memory memory ) { - this.serverVersion = serverVersion; - this.extensionsVersion = extensionsVersion; + this.version = version; + this.modules = modules; this.memory = memory; } @JsonProperty - public String getServerVersion() + public String getVersion() { - return serverVersion; + return version; } @JsonProperty - public Map getExtensionsVersion() + public List getModules() { - return extensionsVersion; + return modules; } @JsonProperty @@ -103,6 +113,72 @@ public class StatusResource { return memory; } + + @Override + public String toString() + { + final String NL = "\n"; + StringBuilder output = new StringBuilder(); + output.append(String.format("Druid version - %s", version)).append(NL).append(NL); + + if (modules.size() > 0) { + output.append("Registered Druid Modules").append(NL); + } else { + output.append("No Druid Modules loaded !"); + } + + for (ModuleVersion moduleVersion : modules) { + output.append(moduleVersion).append(NL); + } + return output.toString(); + } + } + + public static class ModuleVersion + { + final String name; + final String artifact; + final String version; + + public ModuleVersion(String name) + { + this(name, "", ""); + } + + public ModuleVersion(String name, String artifact, String version) + { + this.name = name; + this.artifact = artifact; + this.version = version; + } + + @JsonProperty + public String getName() + { + return name; + } + + @JsonProperty + public String getArtifact() + { + return artifact; + } + + @JsonProperty + public String getVersion() + { + return version; + } + + @Override + public String toString() + { + if (artifact.isEmpty()) { + return String.format(" - %s ", name); + } else { + return String.format(" - %s (%s-%s)", name, artifact, version); + } + } } public static class Memory @@ -143,5 +219,6 @@ public class StatusResource { return usedMemory; } + } } diff --git a/services/src/main/java/io/druid/cli/Main.java b/services/src/main/java/io/druid/cli/Main.java index 91b56a83977..7e9a633e8ed 100644 --- a/services/src/main/java/io/druid/cli/Main.java +++ b/services/src/main/java/io/druid/cli/Main.java @@ -45,12 +45,6 @@ public class Main .withDefaultCommand(Help.class) .withCommands(Help.class, Version.class); - Runnable cmd = builder.build().parse(args); - if (cmd instanceof Version) { - Logger.getRootLogger().setLevel(Level.OFF); - } - - builder.withGroup("server") .withDescription("Run one of the Druid server types.") .withDefaultCommand(Help.class) diff --git a/services/src/main/java/io/druid/cli/Version.java b/services/src/main/java/io/druid/cli/Version.java index 89306fc42fc..9212a3cb800 100644 --- a/services/src/main/java/io/druid/cli/Version.java +++ b/services/src/main/java/io/druid/cli/Version.java @@ -20,11 +20,7 @@ package io.druid.cli; import io.airlift.command.Command; -import io.druid.initialization.DruidModule; -import io.druid.initialization.Initialization; -import io.druid.server.initialization.ExtensionsConfig; - -import java.lang.StringBuilder; +import io.druid.server.StatusResource; @Command( name = "version", @@ -32,33 +28,9 @@ import java.lang.StringBuilder; ) public class Version implements Runnable { - private static final String NL = "\n"; @Override public void run() { - StringBuilder output = new StringBuilder(); - output.append("Druid version ").append(NL); - output.append(Initialization.class.getPackage().getImplementationVersion()).append(NL).append(NL); - - ExtensionsConfig config = Initialization.makeStartupInjector().getInstance(ExtensionsConfig.class); - - output.append("Registered Druid Modules").append(NL); - - for (DruidModule module : Initialization.getFromExtensions(config, DruidModule.class)) { - String artifact = module.getClass().getPackage().getImplementationTitle(); - String version = module.getClass().getPackage().getImplementationVersion(); - - if (artifact != null) { - output.append( - String.format(" - %s (%s-%s)", module.getClass().getCanonicalName(), artifact, version) - ).append(NL); - } else { - output.append( - String.format(" - %s", module.getClass().getCanonicalName()) - ).append(NL); - } - } - - System.out.println(output.toString()); + System.out.println(StatusResource.getStatus()); } }