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..b378697835 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 @@ -17,14 +17,20 @@ package org.apache.activemq.artemis.cli.commands; +import javax.inject.Inject; import java.io.File; import io.airlift.airline.Arguments; +import io.airlift.airline.Help; import io.airlift.airline.Option; +import io.airlift.airline.model.CommandGroupMetadata; +import io.airlift.airline.model.CommandMetadata; +import io.airlift.airline.model.GlobalMetadata; 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; /** @@ -38,6 +44,10 @@ public abstract class Configurable @Option(name = "--broker", description = "This would override the broker configuration from the bootstrap") String brokerConfig; + + @Inject + public GlobalMetadata global; + private BrokerDTO brokerDTO = null; private String brokerInstance; @@ -46,6 +56,15 @@ public abstract class Configurable private FileConfiguration fileConfiguration; + protected void treatError(Exception e, String group, String command) + { + ActiveMQBootstrapLogger.LOGGER.debug(e.getMessage(), e); + System.err.println(); + System.err.println("Error:" + e.getMessage()); + System.err.println(); + helpGroup(group, command); + } + protected String getBrokerInstance() { if (brokerInstance == null) @@ -63,6 +82,24 @@ public abstract class Configurable return brokerInstance; } + protected void helpGroup(String groupName, String commandName) + { + for (CommandGroupMetadata group: global.getCommandGroups()) + { + if (group.getName().equals(groupName)) + { + for (CommandMetadata command: group.getCommands()) + { + if (command.getName().equals(commandName)) + { + Help.help(command); + } + } + break; + } + } + } + protected String getBrokerHome() { if (brokerHome == null) @@ -87,12 +124,13 @@ public abstract class Configurable { if (getBrokerInstance() == null) { + final String defaultLocation = "../data"; 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 +181,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/Run.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Run.java index 2ae98c4907..584911b22a 100644 --- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Run.java +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Run.java @@ -25,6 +25,7 @@ import io.airlift.airline.Command; import io.airlift.airline.Option; import org.apache.activemq.artemis.cli.Artemis; import org.apache.activemq.artemis.components.ExternalComponent; +import org.apache.activemq.artemis.core.config.impl.FileConfiguration; import org.apache.activemq.artemis.core.server.ActiveMQComponent; import org.apache.activemq.artemis.dto.BrokerDTO; import org.apache.activemq.artemis.dto.ComponentDTO; @@ -50,6 +51,8 @@ public class Run extends Configurable implements Action Artemis.printBanner(); + createDirectories(getFileConfiguration()); + BrokerDTO broker = getBrokerDTO(); addShutdownHook(broker.server.getConfigurationFile().getParentFile()); @@ -77,6 +80,15 @@ public class Run extends Configurable implements Action return null; } + + private void createDirectories(FileConfiguration fileConfiguration) + { + new File(fileConfiguration.getBindingsDirectory()).mkdirs(); + new File(fileConfiguration.getJournalDirectory()).mkdirs(); + new File(fileConfiguration.getPagingDirectory()).mkdirs(); + new File(fileConfiguration.getLargeMessagesDirectory()).mkdirs(); + } + /** * Add a simple shutdown hook to stop the server. * @param configurationDir 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..717a9de97a 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 @@ -17,6 +17,8 @@ package org.apache.activemq.artemis.cli.commands.tools; +import java.io.File; + import io.airlift.airline.Option; import org.apache.activemq.artemis.cli.commands.Configurable; @@ -43,6 +45,8 @@ public abstract class DataAbstract extends Configurable largeMessges = getFileConfiguration().getLargeMessagesDirectory(); } + checkIfDirectoryExists(largeMessges); + return largeMessges; } @@ -54,6 +58,8 @@ public abstract class DataAbstract extends Configurable binding = getFileConfiguration().getBindingsDirectory(); } + checkIfDirectoryExists(binding); + return binding; } @@ -64,6 +70,8 @@ public abstract class DataAbstract extends Configurable journal = getFileConfiguration().getJournalDirectory(); } + checkIfDirectoryExists(journal); + return journal; } @@ -74,7 +82,18 @@ public abstract class DataAbstract extends Configurable paging = getFileConfiguration().getPagingDirectory(); } + checkIfDirectoryExists(paging); + return paging; } + private void checkIfDirectoryExists(String directory) + { + File f = new File(directory); + if (!f.exists()) + { + throw new IllegalStateException("Could not find folder: " + directory + ", please pass --bindings, --journal and --paging as arguments"); + } + } + } diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/DecodeJournal.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/DecodeJournal.java index 106412fd26..352bffde04 100644 --- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/DecodeJournal.java +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/DecodeJournal.java @@ -69,7 +69,7 @@ public class DecodeJournal extends Configurable implements Action } catch (Exception e) { - e.printStackTrace(); + treatError(e, "data", "decode"); } return null; diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/EncodeJournal.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/EncodeJournal.java index 426016efcd..d81773f5b0 100644 --- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/EncodeJournal.java +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/EncodeJournal.java @@ -64,7 +64,7 @@ public class EncodeJournal extends Configurable implements Action } catch (Exception e) { - e.printStackTrace(); + treatError(e, "data", "encode"); } return null; 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..2d2d004b75 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 @@ -59,11 +59,17 @@ 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)") 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) + { + treatError(e, "data", "print"); + } return null; } diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/XmlDataExporter.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/XmlDataExporter.java index b8366d9b3e..c887dfb8b8 100644 --- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/XmlDataExporter.java +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/XmlDataExporter.java @@ -126,7 +126,14 @@ public final class XmlDataExporter extends DataAbstract implements Action @Override public Object execute(ActionContext context) throws Exception { - process(System.out, getBinding(), getJournal(), getPaging(), getLargeMessages()); + try + { + process(System.out, getBinding(), getJournal(), getPaging(), getLargeMessages()); + } + catch (Exception e) + { + treatError(e, "data", "exp"); + } 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..568b98e080 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,7 @@ package org.apache.activemq.artemis.integration.bootstrap; +import org.jboss.logging.Messages; import org.jboss.logging.annotations.MessageBundle; /** @@ -27,6 +28,8 @@ 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); + } 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..0b3a467589 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,10 @@ 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 = 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 +76,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); }