From dc82cd0a51e9826fff231158b0c493b76ae26978 Mon Sep 17 00:00:00 2001 From: jbertram Date: Wed, 13 May 2015 10:02:54 -0500 Subject: [PATCH] Make CLI print data more friendly --- .../artemis/cli/commands/Configurable.java | 13 ++++++++----- .../artemis/cli/commands/tools/DataAbstract.java | 15 +++++++++++++++ .../artemis/cli/commands/tools/PrintData.java | 10 +++++++++- .../bootstrap/ActiveMQBootstrapBundle.java | 8 +++++++- .../bootstrap/ActiveMQBootstrapLogger.java | 12 ++++++++++++ 5 files changed, 51 insertions(+), 7 deletions(-) diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Configurable.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Configurable.java index 7f695a76f6..b635903063 100644 --- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Configurable.java +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Configurable.java @@ -25,6 +25,7 @@ import org.apache.activemq.artemis.core.config.FileDeploymentManager; import org.apache.activemq.artemis.core.config.impl.FileConfiguration; import org.apache.activemq.artemis.dto.BrokerDTO; import org.apache.activemq.artemis.factory.BrokerFactory; +import org.apache.activemq.artemis.integration.bootstrap.ActiveMQBootstrapLogger; import org.apache.activemq.artemis.jms.server.config.impl.FileJMSConfiguration; /** @@ -87,12 +88,14 @@ public abstract class Configurable { if (getBrokerInstance() == null) { + final String defaultLocation = "../data"; + ActiveMQBootstrapLogger.LOGGER.brokerConfigNotFound(defaultLocation); fileConfiguration = new FileConfiguration(); // These will be the default places in case the file can't be loaded - fileConfiguration.setBindingsDirectory("../data/bindings"); - fileConfiguration.setJournalDirectory("../data/journal"); - fileConfiguration.setLargeMessagesDirectory("../data/largemessages"); - fileConfiguration.setPagingDirectory("../data/paging"); + fileConfiguration.setBindingsDirectory(defaultLocation + "/bindings"); + fileConfiguration.setJournalDirectory(defaultLocation + "/journal"); + fileConfiguration.setLargeMessagesDirectory(defaultLocation + "/largemessages"); + fileConfiguration.setPagingDirectory(defaultLocation + "/paging"); } else { @@ -143,7 +146,7 @@ public abstract class Configurable // To support Windows paths as explained above. configuration = configuration.replace("\\", "/"); - System.out.println("Loading configuration file: " + configuration); + ActiveMQBootstrapLogger.LOGGER.usingBrokerConfig(configuration); } return configuration; diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/DataAbstract.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/DataAbstract.java index 7f23f98a4d..d222eed58e 100644 --- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/DataAbstract.java +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/DataAbstract.java @@ -19,6 +19,9 @@ package org.apache.activemq.artemis.cli.commands.tools; import io.airlift.airline.Option; import org.apache.activemq.artemis.cli.commands.Configurable; +import org.apache.activemq.artemis.integration.bootstrap.ActiveMQBootstrapBundle; + +import java.io.File; /** Abstract class for places where you need bindings, journal paging and large messages configuration */ public abstract class DataAbstract extends Configurable @@ -41,6 +44,7 @@ public abstract class DataAbstract extends Configurable if (largeMessges == null) { largeMessges = getFileConfiguration().getLargeMessagesDirectory(); + checkIfDirectoryExists(largeMessges); } return largeMessges; @@ -52,6 +56,7 @@ public abstract class DataAbstract extends Configurable if (binding == null) { binding = getFileConfiguration().getBindingsDirectory(); + checkIfDirectoryExists(binding); } return binding; @@ -62,6 +67,7 @@ public abstract class DataAbstract extends Configurable if (journal == null) { journal = getFileConfiguration().getJournalDirectory(); + checkIfDirectoryExists(journal); } return journal; @@ -77,4 +83,13 @@ public abstract class DataAbstract extends Configurable return paging; } + private void checkIfDirectoryExists(String directory) + { + File f = new File(directory); + if (!f.exists()) + { + throw ActiveMQBootstrapBundle.BUNDLE.directoryDoesNotExist(directory); + } + } + } diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/PrintData.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/PrintData.java index 3408d93531..077afe0831 100644 --- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/PrintData.java +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/PrintData.java @@ -54,6 +54,7 @@ import org.apache.activemq.artemis.core.server.impl.FileLockNodeManager; import org.apache.activemq.artemis.core.settings.HierarchicalRepository; import org.apache.activemq.artemis.core.settings.impl.AddressSettings; import org.apache.activemq.artemis.core.settings.impl.HierarchicalObjectRepository; +import org.apache.activemq.artemis.integration.bootstrap.ActiveMQBootstrapLogger; import org.apache.activemq.artemis.utils.ExecutorFactory; @Command(name = "print", description = "Print data records information (WARNING: don't use while a production server is running)") @@ -63,7 +64,14 @@ public class PrintData extends DataAbstract implements Action @Override public Object execute(ActionContext context) throws Exception { - printData(getBinding(), getJournal(), getPaging()); + try + { + printData(getBinding(), getJournal(), getPaging()); + } + catch (Exception e) + { + ActiveMQBootstrapLogger.LOGGER.printDataFailed(e.getMessage()); + } return null; } diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/integration/bootstrap/ActiveMQBootstrapBundle.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/integration/bootstrap/ActiveMQBootstrapBundle.java index 4254e8a405..a7d14acd52 100644 --- a/artemis-cli/src/main/java/org/apache/activemq/artemis/integration/bootstrap/ActiveMQBootstrapBundle.java +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/integration/bootstrap/ActiveMQBootstrapBundle.java @@ -17,6 +17,8 @@ package org.apache.activemq.artemis.integration.bootstrap; +import org.jboss.logging.Messages; +import org.jboss.logging.annotations.Message; import org.jboss.logging.annotations.MessageBundle; /** @@ -27,6 +29,10 @@ import org.jboss.logging.annotations.MessageBundle; * so 109000 to 109999 */ @MessageBundle(projectCode = "AMQ") -public class ActiveMQBootstrapBundle +public interface ActiveMQBootstrapBundle { + ActiveMQBootstrapBundle BUNDLE = Messages.getBundle(ActiveMQBootstrapBundle.class); + + @Message(id = 109000, value = "Directory does not exist: {0}", format = Message.Format.MESSAGE_FORMAT) + IllegalStateException directoryDoesNotExist(String directory); } diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/integration/bootstrap/ActiveMQBootstrapLogger.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/integration/bootstrap/ActiveMQBootstrapLogger.java index b2249b3f2d..2d0b311deb 100644 --- a/artemis-cli/src/main/java/org/apache/activemq/artemis/integration/bootstrap/ActiveMQBootstrapLogger.java +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/integration/bootstrap/ActiveMQBootstrapLogger.java @@ -61,6 +61,14 @@ public interface ActiveMQBootstrapLogger extends BasicLogger @Message(id = 101003, value = "Halting ActiveMQ Artemis Server after user request", format = Message.Format.MESSAGE_FORMAT) void serverKilled(); + @LogMessage(level = Logger.Level.INFO) + @Message(id = 101004, value = "Broker configuration not found. Looking for data files in the ''{0}'' directory.", format = Message.Format.MESSAGE_FORMAT) + void brokerConfigNotFound(String defaultLocation); + + @LogMessage(level = Logger.Level.INFO) + @Message(id = 101005, value = "Using broker configuration: {0}", format = Message.Format.MESSAGE_FORMAT) + void usingBrokerConfig(String location); + @LogMessage(level = Logger.Level.WARN) @Message(id = 102000, value = "Error during undeployment: {0}", format = Message.Format.MESSAGE_FORMAT) void errorDuringUndeployment(@Cause Throwable t, String name); @@ -72,4 +80,8 @@ public interface ActiveMQBootstrapLogger extends BasicLogger @LogMessage(level = Logger.Level.ERROR) @Message(id = 104001, value = "Failed to start server", format = Message.Format.MESSAGE_FORMAT) void errorStartingServer(@Cause Exception e); + + @LogMessage(level = Logger.Level.ERROR) + @Message(id = 104002, value = "The print data operation failed: {0}", format = Message.Format.MESSAGE_FORMAT) + void printDataFailed(String exceptionMessage); }