From cff9f5b785237c9f3fb72b1d2689e883fa1e0c29 Mon Sep 17 00:00:00 2001 From: Clebert Suconic Date: Mon, 4 May 2015 14:54:43 -0400 Subject: [PATCH] Improving tools to use configuration PrintData / Export and other tools are now reading default configuration from broker.xml I also did some refactoring so Stop and Run will share some of the basic functions --- .../artemis/cli/commands/Configurable.java | 134 ++++++++++++++++++ .../activemq/artemis/cli/commands/Run.java | 52 ++----- .../activemq/artemis/cli/commands/Stop.java | 33 +---- .../cli/commands/tools/DataAbstract.java | 80 +++++++++++ .../cli/commands/tools/DecodeJournal.java | 18 ++- .../cli/commands/tools/EncodeJournal.java | 14 +- .../artemis/cli/commands/tools/PrintData.java | 21 ++- .../cli/commands/tools/XmlDataExporter.java | 21 +-- .../cli/commands/tools/XmlDataImporter.java | 11 +- .../artemis/factory/BrokerFactory.java | 10 +- .../activemq/artemis/dto/BrokerDTO.java | 1 - .../activemq/artemis/dto/ServerDTO.java | 39 +++++ 12 files changed, 311 insertions(+), 123 deletions(-) create mode 100644 artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Configurable.java create mode 100644 artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/DataAbstract.java 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 new file mode 100644 index 0000000000..404b746448 --- /dev/null +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Configurable.java @@ -0,0 +1,134 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.activemq.artemis.cli.commands; + +import java.io.File; + +import io.airlift.airline.Arguments; +import io.airlift.airline.Option; +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.jms.server.config.impl.FileJMSConfiguration; + +/** + * Abstract class where we can replace the configuration in various places * + */ +public abstract class Configurable +{ + @Arguments(description = "Broker Configuration URI, default 'xml:${ARTEMIS_INSTANCE}/etc/bootstrap.xml'") + String configuration; + + @Option(name = "--broker", description = "This would override the broker configuration from the bootstrap") + String brokerConfig; + + private BrokerDTO brokerDTO = null; + + private String brokerInstance; + + private FileConfiguration fileConfiguration; + + protected String getBrokerInstance() + { + if (brokerInstance == null) + { + /* We use File URI for locating files. The ARTEMIS_HOME variable is used to determine file paths. For Windows + the ARTEMIS_HOME variable will include back slashes (An invalid file URI character path separator). For this + reason we overwrite the ARTEMIS_HOME variable with backslashes replaced with forward slashes. */ + brokerInstance = System.getProperty("artemis.instance"); + if (brokerInstance != null) + { + brokerInstance = brokerInstance.replace("\\", "/"); + System.setProperty("artemis.instance", brokerInstance); + } + } + return brokerInstance; + } + + + protected FileConfiguration getFileConfiguration() throws Exception + { + if (fileConfiguration == null) + { + if (getBrokerInstance() == null) + { + 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"); + } + else + { + fileConfiguration = new FileConfiguration(); + FileJMSConfiguration jmsConfiguration = new FileJMSConfiguration(); + + String serverConfiguration = getBrokerDTO().server.configuration; + FileDeploymentManager fileDeploymentManager = new FileDeploymentManager(serverConfiguration); + fileDeploymentManager.addDeployable(fileConfiguration).addDeployable(jmsConfiguration); + fileDeploymentManager.readConfiguration(); + } + } + + return fileConfiguration; + } + + + protected BrokerDTO getBrokerDTO() throws Exception + { + if (brokerDTO == null) + { + getConfiguration(); + + + brokerDTO = BrokerFactory.createBrokerConfiguration(configuration); + + if (brokerConfig != null) + { + if (!brokerConfig.startsWith("file:")) + { + brokerConfig = "file:" + brokerConfig; + } + + brokerDTO.server.configuration = brokerConfig; + } + } + + return brokerDTO; + } + + protected String getConfiguration() + { + if (configuration == null) + { + File xmlFile = new File(new File(new File(getBrokerInstance()), "etc"), "bootstrap.xml"); + configuration = "xml:" + xmlFile.toURI().toString().substring("file:".length()); + + // To support Windows paths as explained above. + configuration = configuration.replace("\\", "/"); + + System.out.println("Loading configuration file: " + 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 8410badded..3aa6c96c8e 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 @@ -16,9 +16,12 @@ */ package org.apache.activemq.artemis.cli.commands; -import io.airlift.airline.Arguments; -import io.airlift.airline.Command; +import java.io.File; +import java.util.ArrayList; +import java.util.Timer; +import java.util.TimerTask; +import io.airlift.airline.Command; import org.apache.activemq.artemis.cli.Artemis; import org.apache.activemq.artemis.components.ExternalComponent; import org.apache.activemq.artemis.core.server.ActiveMQComponent; @@ -30,31 +33,13 @@ import org.apache.activemq.artemis.integration.Broker; import org.apache.activemq.artemis.integration.bootstrap.ActiveMQBootstrapLogger; import org.apache.activemq.artemis.spi.core.security.ActiveMQSecurityManager; -import java.io.File; -import java.net.URI; -import java.util.ArrayList; -import java.util.Timer; -import java.util.TimerTask; - @Command(name = "run", description = "runs the broker instance") -public class Run implements Action +public class Run extends Configurable implements Action { - @Arguments(description = "Broker Configuration URI, default 'xml:${ARTEMIS_INSTANCE}/etc/bootstrap.xml'") - String configuration; - private ArrayList components = new ArrayList<>(); - private Broker server; - static String fixupFileURI(String value) - { - if (value != null && value.startsWith("file:")) - { - value = value.substring("file:".length()); - value = new File(value).toURI().toString(); - } - return value; - } + private ArrayList components = new ArrayList<>(); @Override public Object execute(ActionContext context) throws Exception @@ -62,26 +47,9 @@ public class Run implements Action Artemis.printBanner(); - /* We use File URI for locating files. The ARTEMIS_HOME variable is used to determine file paths. For Windows - the ARTEMIS_HOME variable will include back slashes (An invalid file URI character path separator). For this - reason we overwrite the ARTEMIS_HOME variable with backslashes replaced with forward slashes. */ - String activemqInstance = System.getProperty("artemis.instance").replace("\\", "/"); - System.setProperty("artemis.instance", activemqInstance); + BrokerDTO broker = getBrokerDTO(); - if (configuration == null) - { - File xmlFile = new File(new File(new File(activemqInstance), "etc"), "bootstrap.xml"); - configuration = "xml:" + xmlFile.toURI().toString().substring("file:".length()); - } - - // To support Windows paths as explained above. - System.out.println("Loading configuration file: " + configuration); - - BrokerDTO broker = BrokerFactory.createBrokerConfiguration(configuration); - - String fileName = new URI(fixupFileURI(broker.server.configuration)).getSchemeSpecificPart(); - - addShutdownHook(new File(fileName).getParentFile()); + addShutdownHook(broker.server.getConfigurationFile().getParentFile()); ActiveMQSecurityManager security = SecurityManagerFactory.create(broker.security); @@ -98,7 +66,7 @@ public class Run implements Action { Class clazz = this.getClass().getClassLoader().loadClass(componentDTO.componentClassName); ExternalComponent component = (ExternalComponent)clazz.newInstance(); - component.configure(componentDTO, activemqInstance); + component.configure(componentDTO, getBrokerInstance()); component.start(); components.add(component); } diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Stop.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Stop.java index 906b296084..8d944e355d 100644 --- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Stop.java +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Stop.java @@ -16,42 +16,21 @@ */ package org.apache.activemq.artemis.cli.commands; -import io.airlift.airline.Arguments; +import java.io.File; + import io.airlift.airline.Command; import org.apache.activemq.artemis.dto.BrokerDTO; -import org.apache.activemq.artemis.factory.BrokerFactory; - -import java.io.File; -import java.net.URI; @Command(name = "stop", description = "stops the broker instance") -public class Stop implements Action +public class Stop extends Configurable implements Action { - @Arguments(description = "Broker Configuration URI, default 'xml:${ARTEMIS_INSTANCE}/etc/bootstrap.xml'") - String configuration; - @Override public Object execute(ActionContext context) throws Exception + { - /* We use File URI for locating files. The ARTEMIS_HOME variable is used to determine file paths. For Windows - the ARTEMIS_HOME variable will include back slashes (An invalid file URI character path separator). For this - reason we overwrite the ARTEMIS_HOME variable with backslashes replaced with forward slashes. */ - String activemqHome = System.getProperty("artemis.instance").replace("\\", "/"); - System.setProperty("artemis.instance", activemqHome); + BrokerDTO broker = getBrokerDTO(); - if (configuration == null) - { - configuration = "xml:" + activemqHome + "/etc/bootstrap.xml"; - } - - // To support Windows paths as explained above. - configuration = configuration.replace("\\", "/"); - - BrokerDTO broker = BrokerFactory.createBrokerConfiguration(configuration); - - String fileName = new URI(broker.server.configuration).getSchemeSpecificPart(); - - File file = new File(fileName).getParentFile(); + File file = broker.server.getConfigurationFile().getParentFile(); File stopFile = new File(file, "STOP_ME"); 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 new file mode 100644 index 0000000000..7f23f98a4d --- /dev/null +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/DataAbstract.java @@ -0,0 +1,80 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.activemq.artemis.cli.commands.tools; + +import io.airlift.airline.Option; +import org.apache.activemq.artemis.cli.commands.Configurable; + +/** Abstract class for places where you need bindings, journal paging and large messages configuration */ +public abstract class DataAbstract extends Configurable +{ + @Option(name = "--bindings", description = "The folder used for bindings (default from broker.xml)") + public String binding; + + @Option(name = "--journal", description = "The folder used for messages journal (default from broker.xml)") + public String journal; + + @Option(name = "--paging", description = "The folder used for paging (default from broker.xml)") + public String paging; + + @Option(name = "--large-messages", description = "The folder used for large-messages (default from broker.xml)") + public String largeMessges; + + + public String getLargeMessages() throws Exception + { + if (largeMessges == null) + { + largeMessges = getFileConfiguration().getLargeMessagesDirectory(); + } + + return largeMessges; + } + + + public String getBinding() throws Exception + { + if (binding == null) + { + binding = getFileConfiguration().getBindingsDirectory(); + } + + return binding; + } + + public String getJournal() throws Exception + { + if (journal == null) + { + journal = getFileConfiguration().getJournalDirectory(); + } + + return journal; + } + + public String getPaging() throws Exception + { + if (paging == null) + { + paging = getFileConfiguration().getPagingDirectory(); + } + + return paging; + } + +} 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 cd21418c4f..106412fd26 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 @@ -27,11 +27,11 @@ import java.util.Map; import java.util.Properties; import java.util.concurrent.atomic.AtomicInteger; -import io.airlift.airline.Arguments; import io.airlift.airline.Command; import io.airlift.airline.Option; import org.apache.activemq.artemis.cli.commands.Action; import org.apache.activemq.artemis.cli.commands.ActionContext; +import org.apache.activemq.artemis.cli.commands.Configurable; import org.apache.activemq.artemis.core.journal.RecordInfo; import org.apache.activemq.artemis.core.journal.impl.JournalImpl; import org.apache.activemq.artemis.core.journal.impl.JournalRecord; @@ -39,13 +39,13 @@ import org.apache.activemq.artemis.core.journal.impl.NIOSequentialFileFactory; import org.apache.activemq.artemis.utils.Base64; @Command(name = "decode", description = "Decode a journal's internal format into a new journal set of files") -public class DecodeJournal implements Action +public class DecodeJournal extends Configurable implements Action { - @Option(name = "--directory", description = "The journal folder (default ../data/journal)") - public String directory = "../data/journal"; + @Option(name = "--directory", description = "The journal folder (default journal folder from broker.xml)") + public String directory; - @Option(name = "--prefix", description = "The journal prefix (default activemq-datal)") + @Option(name = "--prefix", description = "The journal prefix (default activemq-data)") public String prefix = "activemq-data"; @Option(name = "--suffix", description = "The journal suffix (default amq)") @@ -54,13 +54,17 @@ public class DecodeJournal implements Action @Option(name = "--file-size", description = "The journal size (default 10485760)") public int size = 10485760; - @Arguments(description = "The input file name (default=exp.dmp)", required = true) - public String input; + @Option(name = "--input", description = "The input file name (default=exp.dmp)", required = true) + public String input = "exp.dmp"; public Object execute(ActionContext context) throws Exception { try { + if (directory == null) + { + directory = getFileConfiguration().getJournalDirectory(); + } importJournal(directory, prefix, suffix, 2, size, input); } catch (Exception e) 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 ab20d6872d..426016efcd 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 @@ -25,6 +25,7 @@ import io.airlift.airline.Command; import io.airlift.airline.Option; import org.apache.activemq.artemis.cli.commands.Action; import org.apache.activemq.artemis.cli.commands.ActionContext; +import org.apache.activemq.artemis.cli.commands.Configurable; import org.apache.activemq.artemis.core.journal.RecordInfo; import org.apache.activemq.artemis.core.journal.SequentialFileFactory; import org.apache.activemq.artemis.core.journal.impl.JournalFile; @@ -34,13 +35,13 @@ import org.apache.activemq.artemis.core.journal.impl.NIOSequentialFileFactory; import org.apache.activemq.artemis.utils.Base64; @Command(name = "encode", description = "Encode a set of journal files into an internal encoded data format") -public class EncodeJournal implements Action +public class EncodeJournal extends Configurable implements Action { - @Option(name = "--directory", description = "The journal folder (default ../data/journal)") - public String directory = "../data/journal"; + @Option(name = "--directory", description = "The journal folder (default the journal folder from broker.xml)") + public String directory; - @Option(name = "--prefix", description = "The journal prefix (default activemq-datal)") + @Option(name = "--prefix", description = "The journal prefix (default activemq-data)") public String prefix = "activemq-data"; @Option(name = "--suffix", description = "The journal suffix (default amq)") @@ -54,6 +55,11 @@ public class EncodeJournal implements Action { try { + if (directory == null) + { + directory = getFileConfiguration().getJournalDirectory(); + } + exportJournal(directory, prefix, suffix, 2, size); } catch (Exception e) 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 d8a15285c4..3408d93531 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 @@ -28,10 +28,10 @@ import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import io.airlift.airline.Command; -import io.airlift.airline.Option; import org.apache.activemq.artemis.api.core.ActiveMQBuffer; import org.apache.activemq.artemis.api.core.ActiveMQBuffers; import org.apache.activemq.artemis.api.core.SimpleString; +import org.apache.activemq.artemis.cli.Artemis; import org.apache.activemq.artemis.cli.commands.Action; import org.apache.activemq.artemis.cli.commands.ActionContext; import org.apache.activemq.artemis.core.journal.RecordInfo; @@ -57,27 +57,22 @@ import org.apache.activemq.artemis.core.settings.impl.HierarchicalObjectReposito 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 implements Action +public class PrintData extends DataAbstract implements Action { - @Option(name = "--bindings", description = "The folder used for bindings (default ../data/bindings)") - public String binding = "../data/bindings"; - - @Option(name = "--journal", description = "The folder used for messages journal (default ../data/journal)") - public String journal = "../data/journal"; - - @Option(name = "--paging", description = "The folder used for paging (default ../data/paging)") - public String paging = "../data/paging"; - @Override public Object execute(ActionContext context) throws Exception { - printData(binding, journal, paging); + printData(getBinding(), getJournal(), getPaging()); return null; } - public static void printData(String bindingsDirectory, String messagesDirectory, String pagingDirectory) + public static void printData(String bindingsDirectory, String messagesDirectory, String pagingDirectory) throws Exception { + // Having the version on the data report is an information very useful to understand what happened + // When debugging stuff + Artemis.printBanner(); + File serverLockFile = new File(messagesDirectory, "server.lock"); if (serverLockFile.isFile()) 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 f7d5c4e9dc..b8366d9b3e 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 @@ -37,9 +37,6 @@ import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import io.airlift.airline.Command; -import io.airlift.airline.Option; -import org.apache.activemq.artemis.cli.commands.Action; -import org.apache.activemq.artemis.cli.commands.ActionContext; import org.apache.activemq.artemis.api.core.ActiveMQBuffer; import org.apache.activemq.artemis.api.core.ActiveMQBuffers; import org.apache.activemq.artemis.api.core.ActiveMQException; @@ -47,6 +44,8 @@ import org.apache.activemq.artemis.api.core.Message; import org.apache.activemq.artemis.api.core.Pair; import org.apache.activemq.artemis.api.core.SimpleString; import org.apache.activemq.artemis.api.jms.JMSFactoryType; +import org.apache.activemq.artemis.cli.commands.Action; +import org.apache.activemq.artemis.cli.commands.ActionContext; import org.apache.activemq.artemis.core.config.Configuration; import org.apache.activemq.artemis.core.config.impl.ConfigurationImpl; import org.apache.activemq.artemis.core.journal.Journal; @@ -92,7 +91,7 @@ import org.apache.activemq.artemis.utils.Base64; import org.apache.activemq.artemis.utils.ExecutorFactory; @Command(name = "exp", description = "Export all message-data using an XML that could be interpreted by any system.") -public final class XmlDataExporter implements Action +public final class XmlDataExporter extends DataAbstract implements Action { private static final Long LARGE_MESSAGE_CHUNK_SIZE = 1000L; @@ -120,18 +119,6 @@ public final class XmlDataExporter implements Action private final Map, PersistedBindings> jmsJNDI = new ConcurrentHashMap<>(); - @Option(name = "--bindings", description = "The folder used for bindings (default ../data/bindings)") - public String binding = "../data/bindings"; - - @Option(name = "--journal", description = "The folder used for messages journal (default ../data/journal)") - public String journal = "../data/journal"; - - @Option(name = "--paging", description = "The folder used for paging (default ../data/paging)") - public String paging = "../data/paging"; - - @Option(name = "--large-messages", description = "The folder used for large-messages (default ../data/largemessages)") - public String largeMessges = "../data/paging"; - long messagesPrinted = 0L; long bindingsPrinted = 0L; @@ -139,7 +126,7 @@ public final class XmlDataExporter implements Action @Override public Object execute(ActionContext context) throws Exception { - process(System.out, binding, journal, paging, largeMessges); + process(System.out, getBinding(), getJournal(), getPaging(), getLargeMessages()); return null; } diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/XmlDataImporter.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/XmlDataImporter.java index 3755e90ec5..ce3d673a30 100644 --- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/XmlDataImporter.java +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/XmlDataImporter.java @@ -34,11 +34,8 @@ import java.util.HashMap; import java.util.Map; import java.util.UUID; -import io.airlift.airline.Arguments; import io.airlift.airline.Command; import io.airlift.airline.Option; -import org.apache.activemq.artemis.cli.commands.Action; -import org.apache.activemq.artemis.cli.commands.ActionContext; import org.apache.activemq.artemis.api.core.Message; import org.apache.activemq.artemis.api.core.SimpleString; import org.apache.activemq.artemis.api.core.TransportConfiguration; @@ -51,6 +48,8 @@ import org.apache.activemq.artemis.api.core.client.ClientSessionFactory; import org.apache.activemq.artemis.api.core.client.ServerLocator; import org.apache.activemq.artemis.api.core.management.ManagementHelper; import org.apache.activemq.artemis.api.core.management.ResourceNames; +import org.apache.activemq.artemis.cli.commands.Action; +import org.apache.activemq.artemis.cli.commands.ActionContext; import org.apache.activemq.artemis.core.message.impl.MessageImpl; import org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnectorFactory; import org.apache.activemq.artemis.core.remoting.impl.netty.TransportConstants; @@ -100,10 +99,8 @@ public final class XmlDataImporter implements Action @Option(name = "--password", description = "User name used to import the data. (default null)") public String password = null; - @Arguments(description = "The input file name (default=exp.dmp)", required = true) - public String input; - - + @Option(name = "--input", description = "The input file name (default=exp.dmp)", required = true) + public String input = "exp.dmp"; public String getPassword() { diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/factory/BrokerFactory.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/factory/BrokerFactory.java index 06ad977b4d..bd6ee8cade 100644 --- a/artemis-cli/src/main/java/org/apache/activemq/artemis/factory/BrokerFactory.java +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/factory/BrokerFactory.java @@ -16,6 +16,10 @@ */ package org.apache.activemq.artemis.factory; +import java.io.File; +import java.io.IOException; +import java.net.URI; + import org.apache.activemq.artemis.cli.ConfigurationException; import org.apache.activemq.artemis.dto.BrokerDTO; import org.apache.activemq.artemis.dto.ServerDTO; @@ -23,10 +27,6 @@ import org.apache.activemq.artemis.integration.Broker; import org.apache.activemq.artemis.spi.core.security.ActiveMQSecurityManager; import org.apache.activemq.artemis.utils.FactoryFinder; -import java.io.File; -import java.io.IOException; -import java.net.URI; - public class BrokerFactory { @@ -72,7 +72,7 @@ public class BrokerFactory if (brokerDTO.configuration != null) { BrokerHandler handler; - URI configURI = new URI(fixupFileURI(brokerDTO.configuration)); + URI configURI = brokerDTO.getConfigurationURI(); try { diff --git a/artemis-dto/src/main/java/org/apache/activemq/artemis/dto/BrokerDTO.java b/artemis-dto/src/main/java/org/apache/activemq/artemis/dto/BrokerDTO.java index ea14d87570..28e48416d2 100644 --- a/artemis-dto/src/main/java/org/apache/activemq/artemis/dto/BrokerDTO.java +++ b/artemis-dto/src/main/java/org/apache/activemq/artemis/dto/BrokerDTO.java @@ -33,7 +33,6 @@ public class BrokerDTO @XmlElementRef public ServerDTO server; - @XmlElementRef(required = false) public WebServerDTO web; diff --git a/artemis-dto/src/main/java/org/apache/activemq/artemis/dto/ServerDTO.java b/artemis-dto/src/main/java/org/apache/activemq/artemis/dto/ServerDTO.java index 0595dab45b..dc8e310cef 100644 --- a/artemis-dto/src/main/java/org/apache/activemq/artemis/dto/ServerDTO.java +++ b/artemis-dto/src/main/java/org/apache/activemq/artemis/dto/ServerDTO.java @@ -20,6 +20,8 @@ import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlRootElement; +import java.io.File; +import java.net.URI; @XmlRootElement(name = "server") @XmlAccessorType(XmlAccessType.FIELD) @@ -29,4 +31,41 @@ public class ServerDTO @XmlAttribute public String configuration; + + private File configurationFile; + + private URI configurationURI; + + + public URI getConfigurationURI() throws Exception + { + if (configurationURI == null) + { + configurationURI = new URI(fixupFileURI(configuration)); + } + + return configurationURI; + } + + public File getConfigurationFile() throws Exception + { + if (configurationFile == null) + { + configurationFile = new File(new URI(fixupFileURI(configuration)).getSchemeSpecificPart()); + } + return configurationFile; + } + + private static String fixupFileURI(String value) + { + if (value != null && value.startsWith("file:")) + { + value = value.substring("file:".length()); + value = new File(value).toURI().toString(); + } + return value; + } + + + }