Make CLI print data more friendly

This commit is contained in:
jbertram 2015-05-13 10:02:54 -05:00
parent 73c5f2e342
commit dc82cd0a51
5 changed files with 51 additions and 7 deletions

View File

@ -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.core.config.impl.FileConfiguration;
import org.apache.activemq.artemis.dto.BrokerDTO; import org.apache.activemq.artemis.dto.BrokerDTO;
import org.apache.activemq.artemis.factory.BrokerFactory; 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; import org.apache.activemq.artemis.jms.server.config.impl.FileJMSConfiguration;
/** /**
@ -87,12 +88,14 @@ public abstract class Configurable
{ {
if (getBrokerInstance() == null) if (getBrokerInstance() == null)
{ {
final String defaultLocation = "../data";
ActiveMQBootstrapLogger.LOGGER.brokerConfigNotFound(defaultLocation);
fileConfiguration = new FileConfiguration(); fileConfiguration = new FileConfiguration();
// These will be the default places in case the file can't be loaded // These will be the default places in case the file can't be loaded
fileConfiguration.setBindingsDirectory("../data/bindings"); fileConfiguration.setBindingsDirectory(defaultLocation + "/bindings");
fileConfiguration.setJournalDirectory("../data/journal"); fileConfiguration.setJournalDirectory(defaultLocation + "/journal");
fileConfiguration.setLargeMessagesDirectory("../data/largemessages"); fileConfiguration.setLargeMessagesDirectory(defaultLocation + "/largemessages");
fileConfiguration.setPagingDirectory("../data/paging"); fileConfiguration.setPagingDirectory(defaultLocation + "/paging");
} }
else else
{ {
@ -143,7 +146,7 @@ public abstract class Configurable
// To support Windows paths as explained above. // To support Windows paths as explained above.
configuration = configuration.replace("\\", "/"); configuration = configuration.replace("\\", "/");
System.out.println("Loading configuration file: " + configuration); ActiveMQBootstrapLogger.LOGGER.usingBrokerConfig(configuration);
} }
return configuration; return configuration;

View File

@ -19,6 +19,9 @@ package org.apache.activemq.artemis.cli.commands.tools;
import io.airlift.airline.Option; import io.airlift.airline.Option;
import org.apache.activemq.artemis.cli.commands.Configurable; 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 */ /** Abstract class for places where you need bindings, journal paging and large messages configuration */
public abstract class DataAbstract extends Configurable public abstract class DataAbstract extends Configurable
@ -41,6 +44,7 @@ public abstract class DataAbstract extends Configurable
if (largeMessges == null) if (largeMessges == null)
{ {
largeMessges = getFileConfiguration().getLargeMessagesDirectory(); largeMessges = getFileConfiguration().getLargeMessagesDirectory();
checkIfDirectoryExists(largeMessges);
} }
return largeMessges; return largeMessges;
@ -52,6 +56,7 @@ public abstract class DataAbstract extends Configurable
if (binding == null) if (binding == null)
{ {
binding = getFileConfiguration().getBindingsDirectory(); binding = getFileConfiguration().getBindingsDirectory();
checkIfDirectoryExists(binding);
} }
return binding; return binding;
@ -62,6 +67,7 @@ public abstract class DataAbstract extends Configurable
if (journal == null) if (journal == null)
{ {
journal = getFileConfiguration().getJournalDirectory(); journal = getFileConfiguration().getJournalDirectory();
checkIfDirectoryExists(journal);
} }
return journal; return journal;
@ -77,4 +83,13 @@ public abstract class DataAbstract extends Configurable
return paging; return paging;
} }
private void checkIfDirectoryExists(String directory)
{
File f = new File(directory);
if (!f.exists())
{
throw ActiveMQBootstrapBundle.BUNDLE.directoryDoesNotExist(directory);
}
}
} }

View File

@ -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.HierarchicalRepository;
import org.apache.activemq.artemis.core.settings.impl.AddressSettings; import org.apache.activemq.artemis.core.settings.impl.AddressSettings;
import org.apache.activemq.artemis.core.settings.impl.HierarchicalObjectRepository; import org.apache.activemq.artemis.core.settings.impl.HierarchicalObjectRepository;
import org.apache.activemq.artemis.integration.bootstrap.ActiveMQBootstrapLogger;
import org.apache.activemq.artemis.utils.ExecutorFactory; 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)") @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 @Override
public Object execute(ActionContext context) throws Exception 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; return null;
} }

View File

@ -17,6 +17,8 @@
package org.apache.activemq.artemis.integration.bootstrap; package org.apache.activemq.artemis.integration.bootstrap;
import org.jboss.logging.Messages;
import org.jboss.logging.annotations.Message;
import org.jboss.logging.annotations.MessageBundle; import org.jboss.logging.annotations.MessageBundle;
/** /**
@ -27,6 +29,10 @@ import org.jboss.logging.annotations.MessageBundle;
* so 109000 to 109999 * so 109000 to 109999
*/ */
@MessageBundle(projectCode = "AMQ") @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);
} }

View File

@ -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) @Message(id = 101003, value = "Halting ActiveMQ Artemis Server after user request", format = Message.Format.MESSAGE_FORMAT)
void serverKilled(); 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) @LogMessage(level = Logger.Level.WARN)
@Message(id = 102000, value = "Error during undeployment: {0}", format = Message.Format.MESSAGE_FORMAT) @Message(id = 102000, value = "Error during undeployment: {0}", format = Message.Format.MESSAGE_FORMAT)
void errorDuringUndeployment(@Cause Throwable t, String name); void errorDuringUndeployment(@Cause Throwable t, String name);
@ -72,4 +80,8 @@ public interface ActiveMQBootstrapLogger extends BasicLogger
@LogMessage(level = Logger.Level.ERROR) @LogMessage(level = Logger.Level.ERROR)
@Message(id = 104001, value = "Failed to start server", format = Message.Format.MESSAGE_FORMAT) @Message(id = 104001, value = "Failed to start server", format = Message.Format.MESSAGE_FORMAT)
void errorStartingServer(@Cause Exception e); 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);
} }