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.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;

View File

@ -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);
}
}
}

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.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;
}

View File

@ -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);
}

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)
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);
}