This closes #258 CLI improvements
This commit is contained in:
commit
efb9edbc66
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -69,7 +69,7 @@ public class DecodeJournal extends Configurable implements Action
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
treatError(e, "data", "decode");
|
||||
}
|
||||
|
||||
return null;
|
||||
|
|
|
@ -64,7 +64,7 @@ public class EncodeJournal extends Configurable implements Action
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
treatError(e, "data", "encode");
|
||||
}
|
||||
|
||||
return null;
|
||||
|
|
|
@ -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
|
||||
{
|
||||
try
|
||||
{
|
||||
printData(getBinding(), getJournal(), getPaging());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
treatError(e, "data", "print");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -125,8 +125,15 @@ public final class XmlDataExporter extends DataAbstract implements Action
|
|||
|
||||
@Override
|
||||
public Object execute(ActionContext context) throws Exception
|
||||
{
|
||||
try
|
||||
{
|
||||
process(System.out, getBinding(), getJournal(), getPaging(), getLargeMessages());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
treatError(e, "data", "exp");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue