You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ch...@apache.org on 2014/02/01 19:26:55 UTC
[2/2] git commit: Implements APLO-348: Decouple cli argument parsing
from the Karaf version used using Airline to parse the args
Implements APLO-348: Decouple cli argument parsing from the Karaf version used using Airline to parse the args
Project: http://git-wip-us.apache.org/repos/asf/activemq-apollo/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-apollo/commit/0debf217
Tree: http://git-wip-us.apache.org/repos/asf/activemq-apollo/tree/0debf217
Diff: http://git-wip-us.apache.org/repos/asf/activemq-apollo/diff/0debf217
Branch: refs/heads/trunk
Commit: 0debf2173384bb6f1164b2f2bd68ffc2dd5ada28
Parents: 6e623f8
Author: Hiram Chirino <hi...@hiramchirino.com>
Authored: Sat Feb 1 13:26:34 2014 -0500
Committer: Hiram Chirino <hi...@hiramchirino.com>
Committed: Sat Feb 1 13:26:34 2014 -0500
----------------------------------------------------------------------
.../activemq/apollo/broker/BrokerCreate.scala | 57 ++--
apollo-cli/pom.xml | 12 +-
.../org/apache/activemq/apollo/cli/tips.txt | 4 -
.../apollo-broker-commands.index | 6 +-
.../apollo-commands.index | 6 +-
.../apollo-main.index | 17 --
.../resources/OSGI-INF/blueprint/broker.xml | 6 +-
.../org/apache/activemq/apollo/cli/Apollo.scala | 153 ++++-------
.../activemq/apollo/cli/commands/Action.scala | 63 +++++
.../activemq/apollo/cli/commands/Create.scala | 60 +++++
.../activemq/apollo/cli/commands/Decrypt.scala | 49 ++++
.../apollo/cli/commands/DiskBenchmark.scala | 270 +++++++++++++++++++
.../activemq/apollo/cli/commands/Encrypt.scala | 45 ++++
.../apollo/cli/commands/HelpAction.scala | 29 ++
.../activemq/apollo/cli/commands/Helper.scala | 43 +++
.../activemq/apollo/cli/commands/Run.scala | 175 ++++++++++++
.../apollo/cli/commands/StoreExport.scala | 99 +++++++
.../apollo/cli/commands/StoreImport.scala | 100 +++++++
.../activemq/apollo/cli/commands/Version.scala | 34 +++
.../apollo/cli/osgi/BrokerService.scala | 7 +-
.../activemq/apollo/commands/Create.scala | 62 -----
.../activemq/apollo/commands/DashHelp.scala | 27 --
.../activemq/apollo/commands/Decrypt.scala | 48 ----
.../apollo/commands/DiskBenchmark.scala | 268 ------------------
.../activemq/apollo/commands/Encrypt.scala | 43 ---
.../apache/activemq/apollo/commands/Exit.scala | 34 ---
.../apache/activemq/apollo/commands/Help.scala | 27 --
.../activemq/apollo/commands/Helper.scala | 43 ---
.../apache/activemq/apollo/commands/Run.scala | 179 ------------
.../activemq/apollo/commands/StoreExport.scala | 99 -------
.../activemq/apollo/commands/StoreImport.scala | 101 -------
.../activemq/apollo/commands/Version.scala | 33 ---
.../activemq/apollo/cli/ApolloIDERunner.scala | 2 +-
apollo-distro/pom.xml | 6 -
.../src/main/descriptors/common-bin.xml | 6 +-
.../activemq/apollo/web/ApolloApplication.scala | 2 +-
pom.xml | 4 +-
37 files changed, 1078 insertions(+), 1141 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/activemq-apollo/blob/0debf217/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/BrokerCreate.scala
----------------------------------------------------------------------
diff --git a/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/BrokerCreate.scala b/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/BrokerCreate.scala
index a47c621..f2250a8 100644
--- a/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/BrokerCreate.scala
+++ b/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/BrokerCreate.scala
@@ -49,17 +49,14 @@ class BrokerCreate {
var create_login_config = true
var create_log_config = true
- var println = (value:Any)=>{}
-
val IS_WINDOWS = System.getProperty("os.name").toLowerCase().trim().startsWith("win");
val IS_CYGWIN = IS_WINDOWS && System.getenv("OSTYPE") == "cygwin";
- def run() = {
+ def run(out:PrintStream, err:PrintStream) = {
try {
-
- println("Creating apollo instance at: %s".format(directory))
+ out.println("Creating apollo instance at: %s".format(directory))
if( host == null ) {
host = directory.getName
@@ -81,7 +78,7 @@ class BrokerCreate {
// Generate a keystore with a new key
val ssl = with_ssl && {
- println("Generating ssl keystore...")
+ out.println("Generating ssl keystore...")
val rc = system(etc, Array(
"keytool", "-genkey",
"-storetype", "JKS",
@@ -94,7 +91,7 @@ class BrokerCreate {
"-dname", "cn=%s".format(host),
"-validity", "3650"))==0
if(!rc) {
- println("WARNING: Could not generate the keystore, make sure the keytool command is in your PATH")
+ out.println("WARNING: Could not generate the keystore, make sure the keytool command is in your PATH")
}
rc
}
@@ -134,52 +131,50 @@ class BrokerCreate {
setExecutable(bin/"apollo-broker-service")
}
- println("")
- println("You can now start the broker by executing: ")
- println("")
- println(" \"%s\" run".format(cp(bin/"apollo-broker", true)))
+ out.println("")
+ out.println("You can now start the broker by executing: ")
+ out.println("")
+ out.println(" \"%s\" run".format(cp(bin/"apollo-broker", true)))
val service = bin / "apollo-broker-service"
- println("")
+ out.println("")
if( !IS_WINDOWS || IS_CYGWIN ) {
// Does it look like we are on a System V init system?
if( new File("/etc/init.d/").isDirectory ) {
- println("Or you can setup the broker as system service and run it in the background:")
- println("")
- println(" sudo ln -s \"%s\" /etc/init.d/".format(service.getCanonicalPath))
- println(" /etc/init.d/apollo-broker-service start")
- println("")
+ out.println("Or you can setup the broker as system service and run it in the background:")
+ out.println("")
+ out.println(" sudo ln -s \"%s\" /etc/init.d/".format(service.getCanonicalPath))
+ out.println(" /etc/init.d/apollo-broker-service start")
+ out.println("")
} else {
- println("Or you can run the broker in the background using:")
- println("")
- println(" \"%s\" start".format(cp(service,true)))
- println("")
+ out.println("Or you can run the broker in the background using:")
+ out.println("")
+ out.println(" \"%s\" start".format(cp(service,true)))
+ out.println("")
}
}
if ( IS_WINDOWS ) {
- println("Or you can setup the broker as Windows service and run it in the background:")
- println("")
- println(" \"%s\" install".format(cp(service,true)))
- println(" \"%s\" start".format(cp(service,true)))
- println("")
+ out.println("Or you can setup the broker as Windows service and run it in the background:")
+ out.println("")
+ out.println(" \"%s\" install".format(cp(service,true)))
+ out.println(" \"%s\" start".format(cp(service,true)))
+ out.println("")
}
}
-
-
+ 0
} catch {
case x:Exception =>
- println("ERROR: "+x.getMessage)
+ err.println("ERROR: "+x.getMessage)
+ 1
}
-
- null
}
def cp(value:String, unixPaths:Boolean):String = cp(new File(value), unixPaths)
http://git-wip-us.apache.org/repos/asf/activemq-apollo/blob/0debf217/apollo-cli/pom.xml
----------------------------------------------------------------------
diff --git a/apollo-cli/pom.xml b/apollo-cli/pom.xml
index 652478c..9f44c15 100644
--- a/apollo-cli/pom.xml
+++ b/apollo-cli/pom.xml
@@ -61,9 +61,15 @@
</dependency>
<dependency>
- <groupId>org.apache.karaf.shell</groupId>
- <artifactId>org.apache.karaf.shell.console</artifactId>
- <version>${karaf-version}</version>
+ <groupId>io.airlift</groupId>
+ <artifactId>airline</artifactId>
+ <version>${airline-version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.fusesource.jansi</groupId>
+ <artifactId>jansi</artifactId>
+ <version>${jansi-version}</version>
</dependency>
<dependency>
http://git-wip-us.apache.org/repos/asf/activemq-apollo/blob/0debf217/apollo-cli/src/main/filtered-resources/org/apache/activemq/apollo/cli/tips.txt
----------------------------------------------------------------------
diff --git a/apollo-cli/src/main/filtered-resources/org/apache/activemq/apollo/cli/tips.txt b/apollo-cli/src/main/filtered-resources/org/apache/activemq/apollo/cli/tips.txt
deleted file mode 100644
index 26cc6f2..0000000
--- a/apollo-cli/src/main/filtered-resources/org/apache/activemq/apollo/cli/tips.txt
+++ /dev/null
@@ -1,4 +0,0 @@
-Hit '[1m<tab>[0m' for a list of available commands
- and '[1m[cmd] --help[0m' for help on a specific command.
-Run '[1mexit[0m' to exit the shell.
-
http://git-wip-us.apache.org/repos/asf/activemq-apollo/blob/0debf217/apollo-cli/src/main/resources/META-INF/services/org.apache.activemq.apollo/apollo-broker-commands.index
----------------------------------------------------------------------
diff --git a/apollo-cli/src/main/resources/META-INF/services/org.apache.activemq.apollo/apollo-broker-commands.index b/apollo-cli/src/main/resources/META-INF/services/org.apache.activemq.apollo/apollo-broker-commands.index
index bdeacce..3ee7327 100644
--- a/apollo-cli/src/main/resources/META-INF/services/org.apache.activemq.apollo/apollo-broker-commands.index
+++ b/apollo-cli/src/main/resources/META-INF/services/org.apache.activemq.apollo/apollo-broker-commands.index
@@ -14,13 +14,11 @@
## See the License for the specific language governing permissions and
## limitations under the License.
## ---------------------------------------------------------------------------
-org.apache.activemq.apollo.cli.commands.Exit
-org.apache.activemq.apollo.cli.commands.Help
org.apache.activemq.apollo.cli.commands.Run
org.apache.activemq.apollo.cli.commands.Encrypt
org.apache.activemq.apollo.cli.commands.Decrypt
org.apache.activemq.apollo.cli.commands.StoreExport
org.apache.activemq.apollo.cli.commands.StoreImport
-org.apache.activemq.apollo.cli.commands.DashHelp
+org.apache.activemq.apollo.cli.commands.DiskBenchmark
org.apache.activemq.apollo.cli.commands.Version
-org.apache.activemq.apollo.cli.commands.DiskBenchmark
\ No newline at end of file
+org.apache.activemq.apollo.cli.commands.HelpAction
http://git-wip-us.apache.org/repos/asf/activemq-apollo/blob/0debf217/apollo-cli/src/main/resources/META-INF/services/org.apache.activemq.apollo/apollo-commands.index
----------------------------------------------------------------------
diff --git a/apollo-cli/src/main/resources/META-INF/services/org.apache.activemq.apollo/apollo-commands.index b/apollo-cli/src/main/resources/META-INF/services/org.apache.activemq.apollo/apollo-commands.index
index f573ae1..1be77c5 100644
--- a/apollo-cli/src/main/resources/META-INF/services/org.apache.activemq.apollo/apollo-commands.index
+++ b/apollo-cli/src/main/resources/META-INF/services/org.apache.activemq.apollo/apollo-commands.index
@@ -14,9 +14,7 @@
## See the License for the specific language governing permissions and
## limitations under the License.
## ---------------------------------------------------------------------------
-org.apache.activemq.apollo.cli.commands.Exit
org.apache.activemq.apollo.cli.commands.Create
-org.apache.activemq.apollo.cli.commands.Help
-org.apache.activemq.apollo.cli.commands.DashHelp
+org.apache.activemq.apollo.cli.commands.DiskBenchmark
org.apache.activemq.apollo.cli.commands.Version
-org.apache.activemq.apollo.cli.commands.DiskBenchmark
\ No newline at end of file
+org.apache.activemq.apollo.cli.commands.HelpAction
http://git-wip-us.apache.org/repos/asf/activemq-apollo/blob/0debf217/apollo-cli/src/main/resources/META-INF/services/org.apache.activemq.apollo/apollo-main.index
----------------------------------------------------------------------
diff --git a/apollo-cli/src/main/resources/META-INF/services/org.apache.activemq.apollo/apollo-main.index b/apollo-cli/src/main/resources/META-INF/services/org.apache.activemq.apollo/apollo-main.index
deleted file mode 100644
index 3e4d65a..0000000
--- a/apollo-cli/src/main/resources/META-INF/services/org.apache.activemq.apollo/apollo-main.index
+++ /dev/null
@@ -1,17 +0,0 @@
-## ---------------------------------------------------------------------------
-## Licensed to the Apache Software Foundation (ASF) under one or more
-## contributor license agreements. See the NOTICE file distributed with
-## this work for additional information regarding copyright ownership.
-## The ASF licenses this file to You under the Apache License, Version 2.0
-## (the "License"); you may not use this file except in compliance with
-## the License. You may obtain a copy of the License at
-##
-## http://www.apache.org/licenses/LICENSE-2.0
-##
-## Unless required by applicable law or agreed to in writing, software
-## distributed under the License is distributed on an "AS IS" BASIS,
-## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-## See the License for the specific language governing permissions and
-## limitations under the License.
-## ---------------------------------------------------------------------------
-org.apache.activemq.apollo.cli.Apollo
http://git-wip-us.apache.org/repos/asf/activemq-apollo/blob/0debf217/apollo-cli/src/main/resources/OSGI-INF/blueprint/broker.xml
----------------------------------------------------------------------
diff --git a/apollo-cli/src/main/resources/OSGI-INF/blueprint/broker.xml b/apollo-cli/src/main/resources/OSGI-INF/blueprint/broker.xml
index d5d7aae..9b860a1 100644
--- a/apollo-cli/src/main/resources/OSGI-INF/blueprint/broker.xml
+++ b/apollo-cli/src/main/resources/OSGI-INF/blueprint/broker.xml
@@ -32,13 +32,13 @@
<command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.0.0">
<command name="apollo/encrypt">
- <action class="org.apache.activemq.apollo.commands.Encrypt"/>
+ <action class="org.apache.activemq.apollo.cli.commands.Encrypt"/>
</command>
<command name="apollo/decrypt">
- <action class="org.apache.activemq.apollo.commands.Decrypt"/>
+ <action class="org.apache.activemq.apollo.cli.commands.Decrypt"/>
</command>
<command name="apollo/version">
- <action class="org.apache.activemq.apollo.commands.Version"/>
+ <action class="org.apache.activemq.apollo.cli.commands.Version"/>
</command>
</command-bundle>
http://git-wip-us.apache.org/repos/asf/activemq-apollo/blob/0debf217/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/Apollo.scala
----------------------------------------------------------------------
diff --git a/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/Apollo.scala b/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/Apollo.scala
index 96718ed..3986beb 100644
--- a/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/Apollo.scala
+++ b/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/Apollo.scala
@@ -16,18 +16,13 @@
*/
package org.apache.activemq.apollo.cli
-import org.apache.karaf.shell.console.Main
-import org.apache.karaf.shell.console.jline.Console
-import jline.Terminal
-import org.fusesource.jansi.Ansi
import org.apache.activemq.apollo.util.FileSupport._
-import org.apache.felix.service.command.CommandSession
-import org.apache.felix.gogo.runtime.CommandProcessorImpl
import java.util.logging.LogManager
-import java.io.{FileInputStream, File, PrintStream, InputStream}
-import org.apache.log4j.PropertyConfigurator
+import java.io._
import java.util.Properties
-import org.apache.felix.gogo.commands.{Action, Option => option, Argument => argument, Command => command}
+import io.airlift.command.{ParseArgumentsUnexpectedException, Cli}
+import org.apache.activemq.apollo.cli.commands.{HelpAction, Action}
+import org.fusesource.jansi.Ansi
/**
* <p>
@@ -36,8 +31,10 @@ import org.apache.felix.gogo.commands.{Action, Option => option, Argument => arg
* @author <a href="http://hiramchirino.com">Hiram Chirino</a>
*/
object Apollo extends Apollo {
+
def main(args: Array[String]) = {
+ // Lets configure java.util.logging
if( System.getProperty("java.util.logging.config.file") == null ) {
val home = System.getProperty("apollo.home", ".")
var jul_config = new File(home) / "etc" / "jul.properties"
@@ -54,21 +51,16 @@ object Apollo extends Apollo {
using(new FileInputStream(jul_config)) { is =>
LogManager.getLogManager.readConfiguration(is)
}
+ } else {
+ LogManager.getLogManager.readConfiguration(new ByteArrayInputStream("handlers=\n".getBytes()))
}
}
Ansi.ansi()
- Apollo.run(("apollo"::args.toList).toArray)
- System.exit(0)
+ System.exit(Apollo.run(System.in, System.out, System.err, args))
}
- // Some ANSI helpers...
- def ANSI(value:Any) = "\u001B["+value+"m"
- val BOLD = ANSI(1)
- val RESET = ANSI(0)
-
var banner_displayed = false
-
def print_banner(out: PrintStream) = {
if( !banner_displayed ) {
using(getClass().getResourceAsStream("banner.txt")) { source=>
@@ -77,96 +69,65 @@ object Apollo extends Apollo {
banner_displayed = true
}
}
-
- override def getDiscoveryResource = "META-INF/services/org.apache.activemq.apollo/apollo-main.index"
-
- def print_tips(out: PrintStream) = using(getClass().getResourceAsStream("tips.txt")) { source=>
- copy(source, out)
- }
-
}
-
-@command(scope="apollo", name = "apollo", description = "The Apollo Command line tool")
-class Apollo extends Main with Action {
- import Apollo._
-
- setUser("me")
- setApplication("apollo")
-
- var debug = false
-
- val is_apollo_broker = System.getProperty("apollo.base")!=null
-
- override def getDiscoveryResource = {
- if( is_apollo_broker ) {
- "META-INF/services/org.apache.activemq.apollo/apollo-broker-commands.index"
- } else {
- "META-INF/services/org.apache.activemq.apollo/apollo-commands.index"
+class Apollo {
+
+ def properties(is:InputStream):Properties = {
+ try {
+ val p = new Properties()
+ p.load(is);
+ return p
+ } finally {
+ try {
+ is.close()
+ } catch {
+ case _:Throwable =>
+ }
}
+ }
+ def action_classes(resourceFile:String) = {
+ import collection.JavaConversions._
+ val loader = this.getClass().getClassLoader
+ properties(loader.getResourceAsStream(resourceFile)).keys.map { next =>
+ loader.loadClass(next.asInstanceOf[String]).asInstanceOf[Class[Action]]
+ }.toArray
}
- override def isMultiScopeMode() = false
+ def run(in:InputStream, out:PrintStream, err:PrintStream, args: Array[String]):Int = {
- protected override def createConsole(impl: CommandProcessorImpl, in: InputStream, out: PrintStream, err: PrintStream, terminal: Terminal) = {
- new Console(impl, in, out, err, terminal, null) {
- protected override def getPrompt = if (is_apollo_broker) {
- BOLD+"apollo-broker> "+RESET
- } else {
- BOLD+"apollo> "+RESET
- }
- protected override def welcome = {
- print_banner(session.getConsole)
- print_tips(session.getConsole)
- }
+ val is_apollo_broker = System.getProperty("apollo.base")!=null
+ val command_name = if( is_apollo_broker ) {
+ "apollo-broker"
+ } else {
+ "apollo"
+ }
- protected override def setSessionProperties = {}
+ var builder = Cli.builder[Action](command_name)
+ .withDescription("The Apollo command line tool")
+ .withDefaultCommand(classOf[HelpAction])
- protected override def getHistoryFile: File = {
- val default = (new File(System.getProperty("user.home"))/".apollo"/"apollo.history").getCanonicalPath
- new File(System.getProperty("apollo.history",default))
- }
+ for( action <- action_classes("META-INF/services/org.apache.activemq.apollo/" + command_name + "-commands.index") ) {
+ builder.withCommand(action)
}
- }
- @option(name = "--log", description="The logging level use.")
- var log_level:String = "WARN"
-
- @argument(name = "args", description = "apollo sub command arguments", multiValued=true, valueToShowInHelp="")
- var args:Array[String] = Array()
-
- def execute(session: CommandSession): AnyRef = {
-
- // Just in case your running a sub command an not
- // the broker
- var log_properties: Properties = new Properties()
- log_properties.put("log4j.appender.console", "org.apache.log4j.ConsoleAppender")
- log_properties.put("log4j.appender.console.layout", "org.apache.log4j.PatternLayout")
- log_properties.put("log4j.appender.console.layout.ConversionPattern", "%-5p | %m%n")
-
-
- log_level = log_level.toUpperCase()
- log_level match {
- case "NONE" => log_properties.clear()
- log_properties.put("log4j.rootLogger", "FATAL")
- case "FATAL" =>
- log_properties.put("log4j.rootLogger", log_level+", console")
- case "ERROR" =>
- log_properties.put("log4j.rootLogger", log_level+", console")
- case "WARN" =>
- log_properties.put("log4j.rootLogger", log_level+", console")
- case "INFO" =>
- log_properties.put("log4j.rootLogger", log_level+", console")
- case "DEBUG" =>
- log_properties.put("log4j.rootLogger", log_level+", console")
- case "TRACE" =>
- log_properties.put("log4j.rootLogger", log_level+", console")
+// builder.withGroup("remote")
+// .withDescription("Manage set of tracked repositories")
+// .withDefaultCommand(RemoteShow.class)
+// .withCommands(RemoteShow.class, RemoteAdd.class);
+
+ var parser = builder.build()
+
+ val action = try {
+ parser.parse(args: _*)
+ } catch {
+ case e:ParseArgumentsUnexpectedException =>
+ err.println(e.getMessage)
+ out.println()
+ parser.parse("help").execute(in, out, err)
+ return 1;
}
- PropertyConfigurator.configure(log_properties)
-
- run(session, args)
- null
+ action.execute(in, out, err)
}
-
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/activemq-apollo/blob/0debf217/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/commands/Action.scala
----------------------------------------------------------------------
diff --git a/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/commands/Action.scala b/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/commands/Action.scala
new file mode 100644
index 0000000..e22b31e
--- /dev/null
+++ b/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/commands/Action.scala
@@ -0,0 +1,63 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.apollo.cli.commands
+
+import java.io.{InputStream, PrintStream}
+import io.airlift.command.OptionType
+import io.airlift.command.Option
+import java.util.Properties
+import org.apache.log4j.PropertyConfigurator
+
+/**
+ */
+trait Action {
+ def execute(in:InputStream, out:PrintStream, err:PrintStream):Int
+}
+
+abstract class BaseAction extends Action {
+
+ @Option(`type`=OptionType.GLOBAL, name=Array("--log"), description="The logging level use.")
+ var log_level:String = "WARN"
+
+ def init_logging = {
+ // Just in case your running a sub command an not the broker
+ var log_properties: Properties = new Properties()
+ log_properties.put("log4j.appender.console", "org.apache.log4j.ConsoleAppender")
+ log_properties.put("log4j.appender.console.layout", "org.apache.log4j.PatternLayout")
+ log_properties.put("log4j.appender.console.layout.ConversionPattern", "%-5p | %m%n")
+
+ log_level = log_level.toUpperCase()
+ log_level match {
+ case "NONE" => log_properties.clear()
+ log_properties.put("log4j.rootLogger", "FATAL")
+ case "FATAL" =>
+ log_properties.put("log4j.rootLogger", log_level+", console")
+ case "ERROR" =>
+ log_properties.put("log4j.rootLogger", log_level+", console")
+ case "WARN" =>
+ log_properties.put("log4j.rootLogger", log_level+", console")
+ case "INFO" =>
+ log_properties.put("log4j.rootLogger", log_level+", console")
+ case "DEBUG" =>
+ log_properties.put("log4j.rootLogger", log_level+", console")
+ case "TRACE" =>
+ log_properties.put("log4j.rootLogger", log_level+", console")
+ }
+ PropertyConfigurator.configure(log_properties)
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/activemq-apollo/blob/0debf217/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/commands/Create.scala
----------------------------------------------------------------------
diff --git a/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/commands/Create.scala b/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/commands/Create.scala
new file mode 100755
index 0000000..36a617b
--- /dev/null
+++ b/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/commands/Create.scala
@@ -0,0 +1,60 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.apollo.cli.commands
+
+import java.io._
+import scala.Predef._
+import org.apache.activemq.apollo.broker.BrokerCreate
+import io.airlift.command.{Arguments, Command, Option}
+
+/**
+ * The apollo create command
+ */
+@Command(name = "create", description = "creates a new broker instance")
+class Create extends BaseAction {
+
+ @Arguments(description = "The instance directory to hold the broker's configuration and data", required=true)
+ var directory:File = _
+
+ @Option(name = Array("--host"), description = "The host name of the broker")
+ var host:String = _
+
+ @Option(name = Array("--force"), description = "Overwrite configuration at destination directory")
+ var force = false
+
+ @Option(name = Array("--home"), description = "Directory where apollo is installed")
+ var home: File = _
+
+ @Option(name = Array("--with-ssl"), description = "Generate an SSL enabled configuration")
+ var with_ssl = true
+
+ @Option(name = Array("--encoding"), description = "The encoding that text files should use")
+ var encoding:String = _
+
+ def execute(in:InputStream, out:PrintStream, err:PrintStream) = {
+ init_logging
+ val create = new BrokerCreate
+ if( directory!=null ) create.directory = directory
+ if( host!=null ) create.host = host
+ create.force = force
+ if( home!=null ) create.home = home
+ create.with_ssl = with_ssl
+ if( encoding!=null ) create.encoding = encoding
+ create.run(out, err)
+ 0
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/activemq-apollo/blob/0debf217/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/commands/Decrypt.scala
----------------------------------------------------------------------
diff --git a/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/commands/Decrypt.scala b/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/commands/Decrypt.scala
new file mode 100644
index 0000000..acd9aae
--- /dev/null
+++ b/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/commands/Decrypt.scala
@@ -0,0 +1,49 @@
+package org.apache.activemq.apollo.cli.commands
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+import org.apache.activemq.apollo.util.Logging
+import org.apache.activemq.apollo.broker.security.EncryptionSupport
+import io.airlift.command.{Arguments, Command}
+import java.io.{PrintStream, InputStream}
+
+/**
+ * The apollo encrypt command
+ */
+@Command(name = "decrypt", description = "decrypts a value")
+class Decrypt extends BaseAction with Logging {
+
+ @Arguments(description = "The value to decrypt", required=true)
+ var value:String = _
+
+ def execute(in:InputStream, out:PrintStream, err:PrintStream) = {
+ init_logging
+ try {
+ val unwrapped = if ( value.startsWith("ENC(") && value.endsWith(")") ) {
+ value.stripPrefix("ENC(").stripSuffix(")")
+ } else {
+ value
+ }
+ out.println(EncryptionSupport.encryptor.decrypt(unwrapped));
+ 0
+ } catch {
+ case x:Helper.Failure=>
+ error(x.getMessage)
+ 2
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/activemq-apollo/blob/0debf217/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/commands/DiskBenchmark.scala
----------------------------------------------------------------------
diff --git a/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/commands/DiskBenchmark.scala b/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/commands/DiskBenchmark.scala
new file mode 100644
index 0000000..ecc0ba5
--- /dev/null
+++ b/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/commands/DiskBenchmark.scala
@@ -0,0 +1,270 @@
+package org.apache.activemq.apollo.cli.commands
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+import io.airlift.command.{Arguments, Command, Option}
+import java.io.{PrintStream, InputStream, RandomAccessFile, File}
+import java.util.concurrent.TimeUnit
+import javax.management.ObjectName
+import management.ManagementFactory
+import org.apache.activemq.apollo.util.{MemoryPropertyEditor, IOHelper}
+import MemoryPropertyEditor._
+
+
+class Report {
+
+ var block_size: Int = 0
+ var async_writes: Int = 0
+ var async_write_duration: Long = 0L
+ var sync_writes: Int = 0
+ var sync_write_duration: Long = 0L
+ var reads: Int = 0
+ var read_duration: Long = 0L
+
+ def async_write_size_rate: Float = {
+ var rc: Float = async_writes
+ rc *= block_size
+ rc /= (1024 * 1024)
+ rc /= (async_write_duration / 1000.0f)
+ return rc
+ }
+
+ def async_write_rate: Float = {
+ var rc: Float = async_writes
+ rc /= (async_write_duration / 1000.0f)
+ return rc
+ }
+
+ def sync_write_size_rate: Float = {
+ var rc: Float = sync_writes
+ rc *= block_size
+ rc /= (1024 * 1024)
+ rc /= (sync_write_duration / 1000.0f)
+ return rc
+ }
+
+ def sync_write_rate: Float = {
+ var rc: Float = sync_writes
+ rc /= (sync_write_duration / 1000.0f)
+ return rc
+ }
+
+ def read_size_rate: Float = {
+ var rc: Float = reads
+ rc *= block_size
+ rc /= (1024 * 1024)
+ rc /= (read_duration / 1000.0f)
+ return rc
+ }
+
+ def read_rate: Float = {
+ var rc: Float = reads
+ rc /= (read_duration / 1000.0f)
+ return rc
+ }
+
+ override def toString: String = {
+ return "Async writes: \n" + " " + async_writes + " writes of size " + block_size + " written in " + (async_write_duration / 1000.0) + " seconds.\n" +
+ " " + async_write_rate + " writes/second.\n" +
+ " " + async_write_size_rate + " megs/second.\n" +
+ "\n" +
+ "Sync writes: \n" + " " + sync_writes + " writes of size " + block_size + " written in " + (sync_write_duration / 1000.0) + " seconds.\n" +
+ " " + sync_write_rate + " writes/second.\n" +
+ " " + sync_write_size_rate + " megs/second.\n" +
+ "\n" +
+ "Reads: \n" + " " + reads + " reads of size " + block_size + " read in " + (read_duration / 1000.0) + " seconds.\n" +
+ " " + read_rate + " reads/second.\n" +
+ " " + read_size_rate + " megs/second.\n" +
+ "\n" + ""
+ }
+
+}
+
+object DiskBenchmark {
+
+ final val PHYSICAL_MEM_SIZE = format((try {
+ val mbean_server = ManagementFactory.getPlatformMBeanServer()
+ mbean_server.getAttribute(new ObjectName("java.lang:type=OperatingSystem"), "TotalPhysicalMemorySize") match {
+ case x:java.lang.Long=> Some(x.longValue)
+ case _ => None
+ }
+ } catch {
+ case _ => None
+ }).getOrElse(1024*1024*500L))
+
+}
+
+
+/**
+ * The apollo encrypt command
+ */
+@Command(name = "disk-benchmark", description = "Benchmarks your disk's speed")
+class DiskBenchmark extends BaseAction {
+ import DiskBenchmark._
+
+
+ @Option(name = Array("--verbose"), description = "Enable verbose output")
+ var verbose: Boolean = false
+ @Option(name = Array("--sample-interval"), description = "The number of milliseconds to spend mesuring perfomance.")
+ var sampleInterval: Long = 30 * 1000
+
+ @Option(name = Array("--block-size"), description = "The size of each IO operation.")
+ var block_size_txt = "4k"
+ def block_size = parse(block_size_txt).toInt
+
+ @Option(name = Array("--file-size"), description = "The size of the data file to use, this should be big enough to flush the OS write cache.")
+ var file_size_txt = PHYSICAL_MEM_SIZE
+ def file_size = parse(file_size_txt)
+
+ @Option(name = Array("--warm-up-size"), description = "The amount of data we should initial write before measuring performance samples (used to flush the OS write cache).")
+ var warm_up_size_txt = format(parse("500M").min(parse(PHYSICAL_MEM_SIZE)/2))
+ def warm_up_size = parse(warm_up_size_txt)
+
+ @Arguments(description="The file that will be used to benchmark your disk (must NOT exist)")
+ var file = new File("disk-benchmark.dat")
+
+ def execute(in: InputStream, out: PrintStream, err: PrintStream): Int = {
+ init_logging
+ try {
+ if (file.exists) {
+ out.println("File " + file + " allready exists, will not benchmark.")
+ } else {
+ out.println("Benchmark using data file: " + file.getCanonicalPath)
+
+ // Initialize the block /w data..
+ var data = new Array[Byte](block_size)
+ var i: Int = 0
+ while (i < data.length) {
+ data(i) = ('a' + (i % 26)).asInstanceOf[Byte]
+ i += 1
+ }
+
+ val report = new Report
+ report.block_size = block_size
+
+ // Pre-allocate the file size..
+ var raf = new RandomAccessFile(file, "rw")
+ try {
+
+ out.println("Pre-allocating data file of size: "+file_size_txt)
+ raf.setLength(file_size)
+ raf.seek(file_size-1)
+ raf.writeByte(0);
+ IOHelper.sync(raf.getFD)
+
+ if( warm_up_size > 0 ) {
+ val max = warm_up_size
+ out.println("Warming up... writing async "+warm_up_size_txt+" so that async writes don't have that much of an advantage due to the OS write cache.")
+ write(raf, data, (count)=>{
+ count > max
+ })
+ }
+
+
+ out.println("Benchmarking async writes")
+ var start = System.nanoTime()
+ var end = start
+ report.async_writes = write(raf, data, (count)=>{
+ end = System.nanoTime
+ TimeUnit.NANOSECONDS.toMillis(end-start) > sampleInterval
+ })
+ report.async_write_duration = TimeUnit.NANOSECONDS.toMillis(end-start)
+
+ out.println("Syncing previous writes before measuring sync write performance.. (might take a while if your OS has a big write cache)")
+ IOHelper.sync(raf.getFD)
+
+ out.println("Benchmarking sync writes")
+ start = System.nanoTime()
+ end = start
+ report.sync_writes = write(raf, data, (count)=>{
+ IOHelper.sync(raf.getFD)
+ end = System.nanoTime
+ TimeUnit.NANOSECONDS.toMillis(end-start) > sampleInterval
+ })
+ report.sync_write_duration = TimeUnit.NANOSECONDS.toMillis(end-start)
+
+ if(!filled) {
+ file_size_txt = ""+raf.getFilePointer
+ out.println("File was not fully written, read benchmark will be operating against: "+(file_size/(1024 * 1024.0f))+" megs of data" )
+ raf.seek(0);
+ }
+ out.println("Benchmarking reads")
+ start = System.nanoTime()
+ end = start
+ report.reads = read(raf, data, (count)=>{
+ end = System.nanoTime
+ TimeUnit.NANOSECONDS.toMillis(end-start) > sampleInterval
+ })
+ report.read_duration = TimeUnit.NANOSECONDS.toMillis(end-start)
+
+ } finally {
+ out.println("Closing.")
+ raf.close
+ }
+ file.delete
+ out.println(report)
+ }
+ 0
+ } catch {
+ case x:Helper.Failure=>
+ sys.error(x.getMessage)
+ 1
+ case e: Throwable =>
+ if (verbose) {
+ err.println("ERROR:")
+ e.printStackTrace(System.out)
+ } else {
+ err.println("ERROR: " + e)
+ }
+ 1
+ }
+ }
+
+ var filled = false
+
+ private def write(raf: RandomAccessFile, data: Array[Byte], until: (Long)=>Boolean) = {
+ var file_position = raf.getFilePointer
+ var counter = 0
+ while (!until(counter.toLong * data.length)) {
+ if( file_position + data.length >= file_size ) {
+ filled = true
+ file_position = 0;
+ raf.seek(file_position)
+ }
+ raf.write(data)
+ counter += 1;
+ file_position += data.length
+ }
+ counter
+ }
+
+ private def read(raf: RandomAccessFile, data: Array[Byte], until: (Long)=>Boolean) = {
+ var file_position = raf.getFilePointer
+ var counter = 0
+ while (!until(counter.toLong * data.length)) {
+ if( file_position + data.length >= file_size ) {
+ file_position = 0;
+ raf.seek(file_position)
+ }
+ raf.readFully(data)
+ counter += 1;
+ file_position += data.length
+ }
+ counter
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/activemq-apollo/blob/0debf217/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/commands/Encrypt.scala
----------------------------------------------------------------------
diff --git a/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/commands/Encrypt.scala b/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/commands/Encrypt.scala
new file mode 100644
index 0000000..be7b7ce
--- /dev/null
+++ b/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/commands/Encrypt.scala
@@ -0,0 +1,45 @@
+package org.apache.activemq.apollo.cli.commands
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+import io.airlift.command.{Arguments, Command}
+import org.apache.activemq.apollo.util.Logging
+import org.apache.activemq.apollo.broker.security.EncryptionSupport
+import java.io.{PrintStream, InputStream}
+
+/**
+ * The apollo encrypt command
+ */
+@Command(name = "encrypt", description = "encrypts a value")
+class Encrypt extends BaseAction with Logging {
+
+ @Arguments(description = "The value to encrypt", required=true)
+ var value:String = _
+
+ def execute(in: InputStream, out: PrintStream, err: PrintStream): Int = {
+ init_logging
+ try {
+ out.println("ENC("+EncryptionSupport.encryptor.encrypt(value)+")");
+ 0
+ } catch {
+ case x:Helper.Failure=>
+ error(x.getMessage)
+ 1
+ }
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/activemq-apollo/blob/0debf217/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/commands/HelpAction.scala
----------------------------------------------------------------------
diff --git a/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/commands/HelpAction.scala b/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/commands/HelpAction.scala
new file mode 100644
index 0000000..dbcbf15
--- /dev/null
+++ b/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/commands/HelpAction.scala
@@ -0,0 +1,29 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.apollo.cli.commands
+
+import io.airlift.command.{Command, Help}
+import java.io.{PrintStream, InputStream}
+
+/**
+ */
+class HelpAction extends Help with Action {
+ def execute(in: InputStream, out: PrintStream, err: PrintStream): Int = {
+ super.run()
+ 0
+ }
+}
http://git-wip-us.apache.org/repos/asf/activemq-apollo/blob/0debf217/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/commands/Helper.scala
----------------------------------------------------------------------
diff --git a/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/commands/Helper.scala b/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/commands/Helper.scala
new file mode 100644
index 0000000..52bd913
--- /dev/null
+++ b/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/commands/Helper.scala
@@ -0,0 +1,43 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.apollo.cli.commands
+
+import org.fusesource.jansi.Ansi
+import org.fusesource.jansi.Ansi.Attribute._
+import java.io.{OutputStream, InputStream, File}
+
+/**
+ * <p>
+ * </p>
+ *
+ * @author <a href="http://hiramchirino.com">Hiram Chirino</a>
+ */
+object Helper {
+
+ def ansi= new Ansi()
+
+ class Failure(msg:String, e:Throwable) extends RuntimeException(msg, e) {
+ def this(msg:String) = this(msg,null)
+ }
+
+ def error(value:Any) = throw new Failure(value.toString)
+
+ def bold(v:String) = ansi.a(INTENSITY_BOLD).a(v).reset
+
+}
+
+
http://git-wip-us.apache.org/repos/asf/activemq-apollo/blob/0debf217/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/commands/Run.scala
----------------------------------------------------------------------
diff --git a/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/commands/Run.scala b/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/commands/Run.scala
new file mode 100644
index 0000000..a8e8c9a
--- /dev/null
+++ b/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/commands/Run.scala
@@ -0,0 +1,175 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.apollo.cli.commands
+
+import io.airlift.command.Command
+import org.apache.activemq.apollo.broker.{Broker, ConfigStore}
+import org.apache.activemq.apollo.util.FileSupport._
+import org.apache.activemq.apollo.cli.Apollo
+import org.fusesource.hawtdispatch._
+import org.apache.activemq.apollo.util.{FileMonitor, ServiceControl}
+import org.apache.log4j.PropertyConfigurator
+import java.io.{PrintStream, InputStream, FileInputStream, File}
+import java.util.logging.LogManager
+import scala.collection.mutable.ListBuffer
+import java.lang.Thread.UncaughtExceptionHandler
+import java.security.{Security, Provider}
+import scala._
+
+/**
+ * The apollo run command
+ */
+@Command(name = "run", description = "runs the broker instance")
+class Run extends Action {
+
+ def system_dir(name:String) = {
+ val base_value = System.getProperty(name)
+ if( base_value==null ) {
+ sys.error("The the %s system property is not set.".format(name))
+ }
+ val file = new File(base_value)
+ if( !file.isDirectory ) {
+ sys.error("The the %s system property is not set to valid directory path %s".format(name, base_value))
+ }
+ file
+ }
+
+ def execute(in: InputStream, out: PrintStream, err: PrintStream): Int = {
+ try {
+
+ //
+ // Install an UncaughtExceptionHandler so that all exceptions get properly logged.
+ val exception_handler = new UncaughtExceptionHandler {
+ def uncaughtException(t: Thread, error: Throwable) {
+ Broker.warn(error)
+ }
+ }
+ Thread.setDefaultUncaughtExceptionHandler(exception_handler)
+ getGlobalQueue().sync(Thread.currentThread().setUncaughtExceptionHandler(exception_handler))
+
+ val base = system_dir("apollo.base")
+ val etc: File = base / "etc"
+
+ val log4j_config = etc / "log4j.properties"
+ PropertyConfigurator.configure(log4j_config.getCanonicalPath)
+
+ val conf = etc / "apollo.xml"
+
+ if( !conf.exists ) {
+ sys.error("Configuration file'%s' does not exist.\n\nTry creating a broker instance using the 'apollo create' command.".format(conf));
+ }
+
+ if( System.getProperty("java.security.auth.login.config")==null ) {
+ val login_config = etc / "login.config"
+ if( login_config.exists ) {
+ System.setProperty("java.security.auth.login.config", login_config.getCanonicalPath)
+ }
+ }
+
+ val tmp = base / "tmp"
+ tmp.mkdirs
+
+ Apollo.print_banner(out)
+
+ // Load the configs and start the brokers up.
+ out.println("Loading configuration file '%s'.".format(conf))
+
+ // Use bouncycastle if it's installed.
+ try {
+ var loader: ClassLoader = getClass.getClassLoader
+ var clazz: Class[_] = loader.loadClass("org.bouncycastle.jce.provider.BouncyCastleProvider")
+ val bouncycastle_provider = clazz.newInstance().asInstanceOf[Provider]
+ Security.insertProviderAt(bouncycastle_provider, 2)
+ Broker.info("Loaded the Bouncy Castle security provider.")
+ } catch {
+ case e:Throwable => // ignore, we can live without bouncycastle
+ }
+
+ val broker = new Broker()
+
+ val validation_messages = ListBuffer[String]()
+ try {
+ broker.config = ConfigStore.load(conf, validation_messages += _)
+ } finally {
+ if( !validation_messages.isEmpty && broker.config.validation != "hide") {
+ Broker.warn("")
+ Broker.warn("Broker configuration file failed the following validations:")
+ validation_messages.foreach{ v =>
+ Broker.warn("")
+ Broker.warn(" "+v)
+ }
+ Broker.warn("")
+ }
+ }
+
+ if( broker.config.validation == "strict" && !validation_messages.isEmpty) {
+ Broker.error("Strict validation was configured, shutting down")
+ return 1
+ }
+
+ broker.tmp = tmp
+ broker.start(NOOP)
+
+ val broker_config_monitor = new FileMonitor(conf,broker.dispatch_queue {
+ broker.console_log.info("Reloading configuration file '%s'.".format(conf))
+ broker.update(ConfigStore.load(conf, x=> broker.console_log.info(x) ), ^{
+ })
+ })
+ val log4j_config_monitor = new FileMonitor(log4j_config, {
+ PropertyConfigurator.configure(log4j_config.getCanonicalPath)
+ })
+
+ var jul_config = etc / "jul.properties"
+ val jul_config_monitor = if ( jul_config.exists()) {
+ new FileMonitor(jul_config, {
+ using(new FileInputStream(jul_config)) { is =>
+ LogManager.getLogManager.readConfiguration(is)
+ }
+ })
+ } else {
+ null
+ }
+
+ if(jul_config_monitor!=null) jul_config_monitor.start(NOOP)
+ log4j_config_monitor.start(NOOP)
+ broker_config_monitor.start(NOOP)
+
+ Runtime.getRuntime.addShutdownHook(new Thread(){
+ override def run: Unit = {
+ var services = List(log4j_config_monitor, broker_config_monitor, broker)
+ if(jul_config_monitor!=null)
+ services ::= jul_config_monitor
+ ServiceControl.stop(services, "stopping broker")
+ }
+ })
+
+ // wait forever... broker will system exit.
+ this.synchronized {
+ this.wait
+ }
+ 0
+ } catch {
+ case x:Helper.Failure=>
+ err.print("Startup failed: "+x.getMessage)
+ 1
+ case x:Throwable=>
+ err.print("Startup failed: "+x)
+ 1
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/activemq-apollo/blob/0debf217/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/commands/StoreExport.scala
----------------------------------------------------------------------
diff --git a/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/commands/StoreExport.scala b/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/commands/StoreExport.scala
new file mode 100644
index 0000000..22601f5
--- /dev/null
+++ b/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/commands/StoreExport.scala
@@ -0,0 +1,99 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.apollo.cli.commands
+
+
+import io.airlift.command.{Arguments, Command, Option}
+import org.apache.activemq.apollo.util.FileSupport._
+import org.apache.activemq.apollo.dto.VirtualHostDTO
+import org.apache.activemq.apollo.util._
+import org.apache.activemq.apollo.broker.ConfigStore
+import java.io._
+import org.apache.activemq.apollo.broker.store.StoreFactory
+
+/**
+ * The apollo stop command
+ */
+@Command(name = "store-export", description = "exports the contents of a broker message store")
+class StoreExport extends BaseAction {
+
+ object StoreExport extends Log
+
+ @Option(name = Array("--conf"), description = "The Apollo configuration file.")
+ var conf: File = _
+
+ @Option(name = Array("--virtual-host"), description = "The id of the virtual host to export, if not specified, the default virtual host is selected.")
+ var host: String = _
+
+ @Arguments(description = "The compressed tar file to hold the exported data", required=true)
+ var file:File = _
+
+ def execute(in: InputStream, out: PrintStream, err: PrintStream): Int = {
+ init_logging
+ import Helper._
+
+ try {
+
+ val base = system_dir("apollo.base")
+
+ if( conf == null ) {
+ conf = base / "etc" / "apollo.xml"
+ }
+
+ if( !conf.exists ) {
+ error("Configuration file'%s' does not exist.\n\nTry creating a broker instance using the 'apollo create' command.".format(conf));
+ }
+
+ val config = ConfigStore.load(conf, out.println _)
+
+ val hosts = collection.JavaConversions.collectionAsScalaIterable(config.virtual_hosts).toArray
+ val vho:scala.Option[VirtualHostDTO] = if( host==null ) {
+ hosts.headOption
+ } else {
+ hosts.filter( _.id == host ).headOption
+ }
+
+ val vh = vho.getOrElse(error("Could find host to export"))
+ if( vh.store == null ) {
+ error("The virtual host '%s' does not have a store configured.".format(vh.id))
+ }
+
+ val store = StoreFactory.create(vh.store)
+ if( store==null ) {
+ error("Could not create the store.")
+ }
+
+ out.println("Starting store: "+store)
+ ServiceControl.start(store, "store startup")
+
+ out.println("Exporting... (this might take a while)")
+ using( new BufferedOutputStream(new FileOutputStream(file)) ) { os=>
+ sync_cb[scala.Option[String]] { cb =>
+ store.export_data(os, cb)
+ }.foreach(error _)
+ }
+ ServiceControl.stop(store, "store stop");
+ out.println("Done. Export located at: "+file)
+ 0
+ } catch {
+ case x:Failure=>
+ error(x.getMessage)
+ 1
+ }
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/activemq-apollo/blob/0debf217/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/commands/StoreImport.scala
----------------------------------------------------------------------
diff --git a/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/commands/StoreImport.scala b/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/commands/StoreImport.scala
new file mode 100644
index 0000000..0c91411
--- /dev/null
+++ b/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/commands/StoreImport.scala
@@ -0,0 +1,100 @@
+package org.apache.activemq.apollo.cli.commands
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+import io.airlift.command.{Command, Option, Arguments}
+import org.apache.activemq.apollo.util.FileSupport._
+import org.apache.activemq.apollo.dto.VirtualHostDTO
+import org.apache.activemq.apollo.util._
+import org.apache.activemq.apollo.broker.ConfigStore
+import org.apache.activemq.apollo.broker.store.StoreFactory
+import java.io._
+import org.apache.activemq.apollo.util.Failure
+
+
+/**
+ * The apollo stop command
+ */
+@Command(name = "store-import", description = "imports a previously exported message store")
+class StoreImport extends BaseAction {
+
+ object StoreImport extends Log
+
+ @Option(name = Array("--conf"), description = "The Apollo configuration file.")
+ var conf: File = _
+
+ @Option(name = Array("--virtual-host"), description = "The id of the virtual host to import into, if not specified, the default virtual host is selected.")
+ var host: String = _
+
+ @Arguments(description = "The compressed tar file the contains that data for the import", required=true)
+ var file:File = _
+
+ def execute(in: InputStream, out: PrintStream, err: PrintStream): Int = {
+ init_logging
+ try {
+
+ val base = system_dir("apollo.base")
+
+ if( conf == null ) {
+ conf = base / "etc" / "apollo.xml"
+ }
+
+ if( !conf.exists ) {
+ error("Configuration file'%s' does not exist.\n\nTry creating a broker instance using the 'apollo create' command.".format(conf));
+ }
+
+ val config = ConfigStore.load(conf, out.println _)
+
+ val hosts = collection.JavaConversions.collectionAsScalaIterable(config.virtual_hosts).toArray
+ val vho:scala.Option[VirtualHostDTO] = if( host==null ) {
+ hosts.headOption
+ } else {
+ hosts.filter( _.id == host ).headOption
+ }
+
+ val vh = vho.getOrElse(error("Could find host to export"))
+ if( vh.store == null ) {
+ error("The virtual host '%s' does not have a store configured.".format(vh.id))
+ }
+
+ val store = StoreFactory.create(vh.store)
+ if( store==null ) {
+ error("Could not create the store.")
+ }
+
+ out.println("Starting store: "+store)
+ ServiceControl.start(store, "store startup")
+
+ out.println("Importing: "+file)
+ using( new BufferedInputStream(new FileInputStream(file)) ) { is =>
+ sync_cb[scala.Option[String]] { cb =>
+ store.import_data(is, cb)
+ }.foreach(error _)
+ }
+
+ ServiceControl.stop(store, "store stop");
+ out.println("Done.")
+ 0
+ } catch {
+ case x:Helper.Failure=>
+ error(x.getMessage)
+ 1
+ }
+ }
+
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/activemq-apollo/blob/0debf217/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/commands/Version.scala
----------------------------------------------------------------------
diff --git a/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/commands/Version.scala b/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/commands/Version.scala
new file mode 100644
index 0000000..b4392ca
--- /dev/null
+++ b/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/commands/Version.scala
@@ -0,0 +1,34 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.apollo.cli.commands
+
+import io.airlift.command.Command
+import org.apache.activemq.apollo.broker.Broker
+import java.io.{PrintStream, InputStream}
+
+/**
+ * The apollo run command
+ */
+@Command(name = "version", description = "Displays the broker version")
+class Version extends Action {
+
+ def execute(in: InputStream, out: PrintStream, err: PrintStream): Int = {
+ out.println(Broker.version)
+ 0
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/activemq-apollo/blob/0debf217/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/osgi/BrokerService.scala
----------------------------------------------------------------------
diff --git a/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/osgi/BrokerService.scala b/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/osgi/BrokerService.scala
index 6dae895..bea726c 100644
--- a/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/osgi/BrokerService.scala
+++ b/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/osgi/BrokerService.scala
@@ -24,11 +24,10 @@ import org.osgi.framework._
import collection.JavaConversions._
import org.apache.activemq.apollo.util._
import FileSupport._
-import java.util.{Hashtable, Dictionary, Properties}
+import java.util.Properties
import org.osgi.service.cm.{Configuration, ConfigurationAdmin}
-import org.apache.felix.service.command.CommandSession
import java.io._
-import java.lang.{UnsupportedOperationException, String}
+import java.lang.String
/**
* @author <a href="http://hiramchirino.com">Hiram Chirino</a>
@@ -90,7 +89,7 @@ object BrokerService extends Log {
<config allow="admin"/>
</acl>
"""
- create.run()
+ create.run(System.out, System.err)
}
// in case the config gets injected.
http://git-wip-us.apache.org/repos/asf/activemq-apollo/blob/0debf217/apollo-cli/src/main/scala/org/apache/activemq/apollo/commands/Create.scala
----------------------------------------------------------------------
diff --git a/apollo-cli/src/main/scala/org/apache/activemq/apollo/commands/Create.scala b/apollo-cli/src/main/scala/org/apache/activemq/apollo/commands/Create.scala
deleted file mode 100755
index 64a4e04..0000000
--- a/apollo-cli/src/main/scala/org/apache/activemq/apollo/commands/Create.scala
+++ /dev/null
@@ -1,62 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.activemq.apollo.cli.commands
-
-import org.apache.felix.gogo.commands.{Action, Option => option, Argument => argument, Command => command}
-import java.io._
-import org.apache.felix.service.command.CommandSession
-import scala.Predef._
-import org.apache.activemq.apollo.broker.BrokerCreate
-
-/**
- * The apollo create command
- */
-@command(scope = "apollo", name = "create", description = "creates a new broker instance")
-class Create extends Action {
-
- @argument(name = "directory", description = "The instance directory to hold the broker's configuration and data", index=0, required=true)
- var directory:File = _
-
- @option(name = "--host", description = "The host name of the broker")
- var host:String = _
-
- @option(name = "--force", description = "Overwrite configuration at destination directory")
- var force = false
-
- @option(name = "--home", description = "Directory where apollo is installed")
- var home: File = _
-
- @option(name = "--with-ssl", description = "Generate an SSL enabled configuration")
- var with_ssl = true
-
- @option(name = "--encoding", description = "The encoding that text files should use")
- var encoding:String = _
-
- def execute(session: CommandSession) = {
- val create = new BrokerCreate
- if( directory!=null ) create.directory = directory
- if( host!=null ) create.host = host
- create.force = force
- if( home!=null ) create.home = home
- create.with_ssl = with_ssl
- if( encoding!=null ) create.encoding = encoding
- create.println = { value =>
- session.getConsole.println(value)
- }
- create.run()
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/activemq-apollo/blob/0debf217/apollo-cli/src/main/scala/org/apache/activemq/apollo/commands/DashHelp.scala
----------------------------------------------------------------------
diff --git a/apollo-cli/src/main/scala/org/apache/activemq/apollo/commands/DashHelp.scala b/apollo-cli/src/main/scala/org/apache/activemq/apollo/commands/DashHelp.scala
deleted file mode 100644
index cae6553..0000000
--- a/apollo-cli/src/main/scala/org/apache/activemq/apollo/commands/DashHelp.scala
+++ /dev/null
@@ -1,27 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.activemq.apollo.cli.commands
-
-import org.apache.felix.gogo.commands.{Option => option, Argument => argument, Command => command}
-import org.apache.karaf.shell.console.HelpAction
-
-/**
- * Provides help for the current shell or an individual command
- */
-@command(scope="apollo", name = "--help", description = "Displays this help or help about a command")
-class DashHelp extends HelpAction {
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/activemq-apollo/blob/0debf217/apollo-cli/src/main/scala/org/apache/activemq/apollo/commands/Decrypt.scala
----------------------------------------------------------------------
diff --git a/apollo-cli/src/main/scala/org/apache/activemq/apollo/commands/Decrypt.scala b/apollo-cli/src/main/scala/org/apache/activemq/apollo/commands/Decrypt.scala
deleted file mode 100644
index 1fa243d..0000000
--- a/apollo-cli/src/main/scala/org/apache/activemq/apollo/commands/Decrypt.scala
+++ /dev/null
@@ -1,48 +0,0 @@
-package org.apache.activemq.apollo.cli.commands
-
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-import org.apache.felix.gogo.commands.{Action, Option => option, Argument => argument, Command => command}
-import org.apache.activemq.apollo.util.Logging
-import org.apache.activemq.apollo.broker.security.EncryptionSupport
-import org.apache.felix.service.command.CommandSession
-
-/**
- * The apollo encrypt command
- */
-@command(scope="apollo", name = "decrypt", description = "decrypts a value")
-class Decrypt extends Action with Logging {
-
- @argument(name = "value", description = "The value to decrypt", index=0, required=true)
- var value:String = _
-
- def execute(session: CommandSession):AnyRef = {
- try {
- val unwrapped = if ( value.startsWith("ENC(") && value.endsWith(")") ) {
- value.stripPrefix("ENC(").stripSuffix(")")
- } else {
- value
- }
- session.getConsole.println(EncryptionSupport.encryptor.decrypt(unwrapped));
- } catch {
- case x:Helper.Failure=> error(x.getMessage)
- }
- null
- }
-
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/activemq-apollo/blob/0debf217/apollo-cli/src/main/scala/org/apache/activemq/apollo/commands/DiskBenchmark.scala
----------------------------------------------------------------------
diff --git a/apollo-cli/src/main/scala/org/apache/activemq/apollo/commands/DiskBenchmark.scala b/apollo-cli/src/main/scala/org/apache/activemq/apollo/commands/DiskBenchmark.scala
deleted file mode 100644
index de9f912..0000000
--- a/apollo-cli/src/main/scala/org/apache/activemq/apollo/commands/DiskBenchmark.scala
+++ /dev/null
@@ -1,268 +0,0 @@
-package org.apache.activemq.apollo.cli.commands
-
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-import org.apache.felix.gogo.commands.{Action, Option => option, Argument => argument, Command => command}
-import org.apache.felix.service.command.CommandSession
-import java.io.{RandomAccessFile, File}
-import java.util.concurrent.TimeUnit
-import javax.management.ObjectName
-import management.ManagementFactory
-import org.apache.activemq.apollo.util.{MemoryPropertyEditor, IOHelper}
-import MemoryPropertyEditor._
-
-
-class Report {
-
- var block_size: Int = 0
- var async_writes: Int = 0
- var async_write_duration: Long = 0L
- var sync_writes: Int = 0
- var sync_write_duration: Long = 0L
- var reads: Int = 0
- var read_duration: Long = 0L
-
- def async_write_size_rate: Float = {
- var rc: Float = async_writes
- rc *= block_size
- rc /= (1024 * 1024)
- rc /= (async_write_duration / 1000.0f)
- return rc
- }
-
- def async_write_rate: Float = {
- var rc: Float = async_writes
- rc /= (async_write_duration / 1000.0f)
- return rc
- }
-
- def sync_write_size_rate: Float = {
- var rc: Float = sync_writes
- rc *= block_size
- rc /= (1024 * 1024)
- rc /= (sync_write_duration / 1000.0f)
- return rc
- }
-
- def sync_write_rate: Float = {
- var rc: Float = sync_writes
- rc /= (sync_write_duration / 1000.0f)
- return rc
- }
-
- def read_size_rate: Float = {
- var rc: Float = reads
- rc *= block_size
- rc /= (1024 * 1024)
- rc /= (read_duration / 1000.0f)
- return rc
- }
-
- def read_rate: Float = {
- var rc: Float = reads
- rc /= (read_duration / 1000.0f)
- return rc
- }
-
- override def toString: String = {
- return "Async writes: \n" + " " + async_writes + " writes of size " + block_size + " written in " + (async_write_duration / 1000.0) + " seconds.\n" +
- " " + async_write_rate + " writes/second.\n" +
- " " + async_write_size_rate + " megs/second.\n" +
- "\n" +
- "Sync writes: \n" + " " + sync_writes + " writes of size " + block_size + " written in " + (sync_write_duration / 1000.0) + " seconds.\n" +
- " " + sync_write_rate + " writes/second.\n" +
- " " + sync_write_size_rate + " megs/second.\n" +
- "\n" +
- "Reads: \n" + " " + reads + " reads of size " + block_size + " read in " + (read_duration / 1000.0) + " seconds.\n" +
- " " + read_rate + " reads/second.\n" +
- " " + read_size_rate + " megs/second.\n" +
- "\n" + ""
- }
-
-}
-
-object DiskBenchmark {
-
- final val PHYSICAL_MEM_SIZE = format((try {
- val mbean_server = ManagementFactory.getPlatformMBeanServer()
- mbean_server.getAttribute(new ObjectName("java.lang:type=OperatingSystem"), "TotalPhysicalMemorySize") match {
- case x:java.lang.Long=> Some(x.longValue)
- case _ => None
- }
- } catch {
- case _ => None
- }).getOrElse(1024*1024*500L))
-
-}
-
-
-/**
- * The apollo encrypt command
- */
-@command(scope="apollo", name = "disk-benchmark", description = "Benchmarks your disk's speed")
-class DiskBenchmark extends Action {
- import DiskBenchmark._
-
-
- @option(name = "--verbose", description = "Enable verbose output")
- var verbose: Boolean = false
- @option(name = "--sample-interval", description = "The number of milliseconds to spend mesuring perfomance.")
- var sampleInterval: Long = 30 * 1000
-
- @option(name = "--block-size", description = "The size of each IO operation.")
- var block_size_txt = "4k"
- def block_size = parse(block_size_txt).toInt
-
- @option(name = "--file-size", description = "The size of the data file to use, this should be big enough to flush the OS write cache.")
- var file_size_txt = PHYSICAL_MEM_SIZE
- def file_size = parse(file_size_txt)
-
- @option(name = "--warm-up-size", description = "The amount of data we should initial write before measuring performance samples (used to flush the OS write cache).")
- var warm_up_size_txt = format(parse("500M").min(parse(PHYSICAL_MEM_SIZE)/2))
- def warm_up_size = parse(warm_up_size_txt)
-
- @argument(name="file", description="The file that will be used to benchmark your disk (must NOT exist)")
- var file = new File("disk-benchmark.dat")
-
- def execute(session: CommandSession):AnyRef = {
- def out = session.getConsole
- try {
- if (file.exists) {
- out.println("File " + file + " allready exists, will not benchmark.")
- } else {
- out.println("Benchmark using data file: " + file.getCanonicalPath)
-
- // Initialize the block /w data..
- var data = new Array[Byte](block_size)
- var i: Int = 0
- while (i < data.length) {
- data(i) = ('a' + (i % 26)).asInstanceOf[Byte]
- i += 1
- }
-
- val report = new Report
- report.block_size = block_size
-
- // Pre-allocate the file size..
- var raf = new RandomAccessFile(file, "rw")
- try {
-
- out.println("Pre-allocating data file of size: "+file_size_txt)
- raf.setLength(file_size)
- raf.seek(file_size-1)
- raf.writeByte(0);
- IOHelper.sync(raf.getFD)
-
- if( warm_up_size > 0 ) {
- val max = warm_up_size
- out.println("Warming up... writing async "+warm_up_size_txt+" so that async writes don't have that much of an advantage due to the OS write cache.")
- write(raf, data, (count)=>{
- count > max
- })
- }
-
-
- out.println("Benchmarking async writes")
- var start = System.nanoTime()
- var end = start
- report.async_writes = write(raf, data, (count)=>{
- end = System.nanoTime
- TimeUnit.NANOSECONDS.toMillis(end-start) > sampleInterval
- })
- report.async_write_duration = TimeUnit.NANOSECONDS.toMillis(end-start)
-
- out.println("Syncing previous writes before measuring sync write performance.. (might take a while if your OS has a big write cache)")
- IOHelper.sync(raf.getFD)
-
- out.println("Benchmarking sync writes")
- start = System.nanoTime()
- end = start
- report.sync_writes = write(raf, data, (count)=>{
- IOHelper.sync(raf.getFD)
- end = System.nanoTime
- TimeUnit.NANOSECONDS.toMillis(end-start) > sampleInterval
- })
- report.sync_write_duration = TimeUnit.NANOSECONDS.toMillis(end-start)
-
- if(!filled) {
- file_size_txt = ""+raf.getFilePointer
- out.println("File was not fully written, read benchmark will be operating against: "+(file_size/(1024 * 1024.0f))+" megs of data" )
- raf.seek(0);
- }
- out.println("Benchmarking reads")
- start = System.nanoTime()
- end = start
- report.reads = read(raf, data, (count)=>{
- end = System.nanoTime
- TimeUnit.NANOSECONDS.toMillis(end-start) > sampleInterval
- })
- report.read_duration = TimeUnit.NANOSECONDS.toMillis(end-start)
-
- } finally {
- out.println("Closing.")
- raf.close
- }
- file.delete
- out.println(report)
- }
- } catch {
- case x:Helper.Failure=> sys.error(x.getMessage)
- case e: Throwable =>
- if (verbose) {
- out.println("ERROR:")
- e.printStackTrace(System.out)
- } else {
- out.println("ERROR: " + e)
- }
- }
- null
- }
-
- var filled = false
-
- private def write(raf: RandomAccessFile, data: Array[Byte], until: (Long)=>Boolean) = {
- var file_position = raf.getFilePointer
- var counter = 0
- while (!until(counter.toLong * data.length)) {
- if( file_position + data.length >= file_size ) {
- filled = true
- file_position = 0;
- raf.seek(file_position)
- }
- raf.write(data)
- counter += 1;
- file_position += data.length
- }
- counter
- }
-
- private def read(raf: RandomAccessFile, data: Array[Byte], until: (Long)=>Boolean) = {
- var file_position = raf.getFilePointer
- var counter = 0
- while (!until(counter.toLong * data.length)) {
- if( file_position + data.length >= file_size ) {
- file_position = 0;
- raf.seek(file_position)
- }
- raf.readFully(data)
- counter += 1;
- file_position += data.length
- }
- counter
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/activemq-apollo/blob/0debf217/apollo-cli/src/main/scala/org/apache/activemq/apollo/commands/Encrypt.scala
----------------------------------------------------------------------
diff --git a/apollo-cli/src/main/scala/org/apache/activemq/apollo/commands/Encrypt.scala b/apollo-cli/src/main/scala/org/apache/activemq/apollo/commands/Encrypt.scala
deleted file mode 100644
index c000937..0000000
--- a/apollo-cli/src/main/scala/org/apache/activemq/apollo/commands/Encrypt.scala
+++ /dev/null
@@ -1,43 +0,0 @@
-package org.apache.activemq.apollo.cli.commands
-
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-import org.apache.felix.gogo.commands.{Action, Option => option, Argument => argument, Command => command}
-import org.apache.activemq.apollo.util.Logging
-import org.apache.activemq.apollo.broker.security.EncryptionSupport
-import org.apache.felix.service.command.CommandSession
-
-/**
- * The apollo encrypt command
- */
-@command(scope="apollo", name = "encrypt", description = "encrypts a value")
-class Encrypt extends Action with Logging {
-
- @argument(name = "value", description = "The value to encrypt", index=0, required=true)
- var value:String = _
-
- def execute(session: CommandSession):AnyRef = {
- try {
- session.getConsole.println("ENC("+EncryptionSupport.encryptor.encrypt(value)+")");
- } catch {
- case x:Helper.Failure=> x.printStackTrace; error(x.getMessage)
- }
- null
- }
-
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/activemq-apollo/blob/0debf217/apollo-cli/src/main/scala/org/apache/activemq/apollo/commands/Exit.scala
----------------------------------------------------------------------
diff --git a/apollo-cli/src/main/scala/org/apache/activemq/apollo/commands/Exit.scala b/apollo-cli/src/main/scala/org/apache/activemq/apollo/commands/Exit.scala
deleted file mode 100644
index eaa0b46..0000000
--- a/apollo-cli/src/main/scala/org/apache/activemq/apollo/commands/Exit.scala
+++ /dev/null
@@ -1,34 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.activemq.apollo.cli.commands
-
-import org.apache.felix.gogo.commands.{Action, Command => command}
-import org.apache.karaf.shell.console.CloseShellException
-import org.apache.felix.service.command.CommandSession
-
-/**
- * The 'exit' sub command.
- */
-@command(scope="apollo", name = "exit", description = "exit the shell")
-class Exit extends Action {
-
- def execute(session: CommandSession): AnyRef = {
- throw new CloseShellException
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/activemq-apollo/blob/0debf217/apollo-cli/src/main/scala/org/apache/activemq/apollo/commands/Help.scala
----------------------------------------------------------------------
diff --git a/apollo-cli/src/main/scala/org/apache/activemq/apollo/commands/Help.scala b/apollo-cli/src/main/scala/org/apache/activemq/apollo/commands/Help.scala
deleted file mode 100644
index fc141af..0000000
--- a/apollo-cli/src/main/scala/org/apache/activemq/apollo/commands/Help.scala
+++ /dev/null
@@ -1,27 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.activemq.apollo.cli.commands
-
-import org.apache.felix.gogo.commands.{Action, Option => option, Argument => argument, Command => command}
-import org.apache.karaf.shell.console.HelpAction
-
-/**
- * Provides help for the current shell or an individual command
- */
-@command(scope="apollo", name = "help", description = "Displays this help or help about a command")
-class Help extends HelpAction {
-}
\ No newline at end of file