diff options
author | Martin Ritchie <ritchiem@apache.org> | 2007-07-05 12:40:50 +0000 |
---|---|---|
committer | Martin Ritchie <ritchiem@apache.org> | 2007-07-05 12:40:50 +0000 |
commit | 58bd497db4de68b04eb1c4eb4e21cf86c4ae3b29 (patch) | |
tree | ebd340eefa0a28c836137e526d006b5f6b1977b9 | |
parent | 7352d9c999fa9f5b62bbb0aa283e06f53bc35965 (diff) | |
download | qpid-python-58bd497db4de68b04eb1c4eb4e21cf86c4ae3b29.tar.gz |
Minor changes and tidy up when running via command line.
Added Copy command.
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/branches/M2@553480 13f79535-47bb-0310-9956-ffa450edef68
-rwxr-xr-x | java/broker/bin/msTool.sh | 28 | ||||
-rw-r--r-- | java/broker/etc/mstool-log4j.xml (renamed from java/broker/etc/messagestoretool-log4j.xml) | 7 | ||||
-rw-r--r-- | java/broker/src/main/java/org/apache/qpid/tools/messagestore/MessageStoreTool.java | 79 | ||||
-rw-r--r-- | java/broker/src/main/java/org/apache/qpid/tools/messagestore/commands/Copy.java | 149 | ||||
-rw-r--r-- | java/broker/src/main/java/org/apache/qpid/tools/messagestore/commands/Dump.java | 2 | ||||
-rw-r--r-- | java/broker/src/main/java/org/apache/qpid/tools/messagestore/commands/Help.java | 3 | ||||
-rw-r--r-- | java/broker/src/main/java/org/apache/qpid/tools/messagestore/commands/List.java | 4 | ||||
-rw-r--r-- | java/broker/src/main/java/org/apache/qpid/tools/messagestore/commands/Select.java | 4 | ||||
-rw-r--r-- | java/broker/src/main/java/org/apache/qpid/tools/messagestore/commands/Show.java | 33 | ||||
-rw-r--r-- | java/broker/src/main/java/org/apache/qpid/tools/utils/SimpleCommandParser.java | 5 |
10 files changed, 262 insertions, 52 deletions
diff --git a/java/broker/bin/msTool.sh b/java/broker/bin/msTool.sh index 2f05e511c5..4d55ee7811 100755 --- a/java/broker/bin/msTool.sh +++ b/java/broker/bin/msTool.sh @@ -19,16 +19,38 @@ # # Set classpath to include Qpid jar with all required jars in manifest -QPID_LIBS=$QPID_HOME/lib/qpid-incubating.jar +QPID_LIBS=$QPID_TOOLS/lib/qpid-incubating.jar + +die() { + if [[ $1 = -usage ]]; then + shift + usage=true + else + usage=false + fi + echo "$@" + $usage && echo + $usage && usage + exit 1 +} + +cygwin=false +if [[ "$(uname -a | fgrep Cygwin)" != "" ]]; then + cygwin=true +fi + +if $cygwin; then + QPID_TOOLS=$(cygpath -w $QPID_TOOLS) +fi # Set other variables used by the qpid-run script before calling export JAVA=java \ JAVA_VM=-server \ - JAVA_OPTS=-Dlog4j.configuration=$QPID_TOOLS\etc\messagestoretool-log4j.xml \ + JAVA_OPTS=-Dlog4j.configuration=file:$QPID_TOOLS/etc/mstool-log4j.xml \ QPID_CLASSPATH=$QPID_LIBS if [ -z "$QPID_TOOLS" ]; then - die "QPID_HOME must be set" + die "QPID_TOOLS be set" fi . qpid-run org.apache.qpid.tools.messagestore.MessageStoreTool "$@" diff --git a/java/broker/etc/messagestoretool-log4j.xml b/java/broker/etc/mstool-log4j.xml index 0313de4f95..8c46010e2d 100644 --- a/java/broker/etc/messagestoretool-log4j.xml +++ b/java/broker/etc/mstool-log4j.xml @@ -25,7 +25,8 @@ <appender name="STDOUT" class="org.apache.log4j.ConsoleAppender"> <layout class="org.apache.log4j.PatternLayout"> - <param name="ConversionPattern" value="%d %-5p [%t] %C{2} (%F:%L) - %m%n"/> + <!--param name="ConversionPattern" value="%d %-5p [%t] %C{2} (%F:%L) - %m%n"/--> + <param name="ConversionPattern" value="%d %-5p [%t] (%F:%L) - %m%n"/> </layout> </appender> @@ -34,11 +35,11 @@ </category> <category name="org.apache.qpid"> - <priority value="info"/> + <priority value="error"/> </category> <category name="org.apache.qpid.server.security"> - <priority value="info"/> + <priority value="error"/> </category> <category name="org.apache.qpid.server.management"> diff --git a/java/broker/src/main/java/org/apache/qpid/tools/messagestore/MessageStoreTool.java b/java/broker/src/main/java/org/apache/qpid/tools/messagestore/MessageStoreTool.java index c81d1dbffa..afa7916074 100644 --- a/java/broker/src/main/java/org/apache/qpid/tools/messagestore/MessageStoreTool.java +++ b/java/broker/src/main/java/org/apache/qpid/tools/messagestore/MessageStoreTool.java @@ -32,6 +32,7 @@ import org.apache.qpid.server.store.MemoryMessageStore; import org.apache.qpid.server.virtualhost.VirtualHost; import org.apache.qpid.tools.messagestore.commands.Clear; import org.apache.qpid.tools.messagestore.commands.Command; +import org.apache.qpid.tools.messagestore.commands.Copy; import org.apache.qpid.tools.messagestore.commands.Dump; import org.apache.qpid.tools.messagestore.commands.Help; import org.apache.qpid.tools.messagestore.commands.List; @@ -56,7 +57,9 @@ import java.io.OutputStream; import java.io.OutputStreamWriter; import java.util.Collection; import java.util.HashMap; +import java.util.LinkedList; import java.util.Map; +import java.util.StringTokenizer; /** * MessageStoreTool. @@ -85,6 +88,7 @@ public class MessageStoreTool /** Control used for main run loop. */ private boolean _running = true; + private boolean _initialised = false; //---------------------------------------------------------------------------------------------------/ @@ -182,13 +186,16 @@ public class MessageStoreTool public void quit() { - ApplicationRegistry.remove(1); + _running = false; + + if (_initialised) + { + ApplicationRegistry.remove(1); + } _console.println("...exiting"); _console.close(); - - _running = false; } public void setBatchMode(boolean batchmode) @@ -203,6 +210,15 @@ public class MessageStoreTool { setup(); + if (!_initialised) + { + System.exit(1); + } + + _console.println(""); + + _console.println(BOILER_PLATE); + runCLI(); } @@ -212,8 +228,6 @@ public class MessageStoreTool loadCommands(); - _console.println(BOILER_PLATE); - _state.clearAll(); } @@ -222,6 +236,7 @@ public class MessageStoreTool _commands.clear(); //todo Dynamically load the classes that exis in com.redhat.etp.qpid.commands _commands.put("close", new Clear(this)); + _commands.put("copy", new Copy(this)); _commands.put("dump", new Dump(this)); _commands.put("help", new Help(this)); _commands.put("list", new List(this)); @@ -256,9 +271,11 @@ public class MessageStoreTool ConfigurationFileApplicationRegistry registry = new ConfigurationFileApplicationRegistry(configFile); ApplicationRegistry.remove(1); + ApplicationRegistry.initialise(registry); checkMessageStores(); + _initialised = true; } catch (ConfigurationException e) { @@ -314,12 +331,15 @@ public class MessageStoreTool { exec(args); - if (!_batchMode) + if (_running) { - printPrompt(); - } + if (!_batchMode) + { + printPrompt(); + } - args = _console.readCommand(); + args = _console.readCommand(); + } } } } @@ -573,6 +593,47 @@ public class MessageStoreTool _msgids = null; } + /** + * A common location to provide parsing of the message id string + * utilised by a number of the commands. + * The String is comma separated list of ids that can be individual ids + * or a range (4-10) + * + * @param msgString string of msg ids to parse 1,2,4-10 + */ + public void setMessages(String msgString) + { + StringTokenizer tok = new StringTokenizer(msgString, ","); + + if (tok.hasMoreTokens()) + { + _msgids = new LinkedList<Long>(); + } + + while (tok.hasMoreTokens()) + { + String next = tok.nextToken(); + if (next.contains("-")) + { + Long start = Long.parseLong(next.substring(0, next.indexOf("-"))); + Long end = Long.parseLong(next.substring(next.indexOf("-") + 1)); + + if (end >= start) + { + for (long l = start; l <= end; l++) + { + _msgids.add(l); + } + } + } + else + { + _msgids.add(Long.parseLong(next)); + } + } + + } + public void setMessages(java.util.List<Long> msgids) { _msgids = msgids; diff --git a/java/broker/src/main/java/org/apache/qpid/tools/messagestore/commands/Copy.java b/java/broker/src/main/java/org/apache/qpid/tools/messagestore/commands/Copy.java new file mode 100644 index 0000000000..831cb90a4d --- /dev/null +++ b/java/broker/src/main/java/org/apache/qpid/tools/messagestore/commands/Copy.java @@ -0,0 +1,149 @@ +/* + * 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.qpid.tools.messagestore.commands; + +import org.apache.qpid.framing.AMQShortString; +import org.apache.qpid.server.queue.AMQQueue; +import org.apache.qpid.server.store.StoreContext; +import org.apache.qpid.tools.messagestore.MessageStoreTool; + +public class Copy extends AbstractCommand +{ + + /** + * Since the Coopy command is not associated with a real channel we can safely create our own store context + * for use in the few methods that require one. + */ + private StoreContext _storeContext = new StoreContext(); + + public Copy(MessageStoreTool tool) + { + super(tool); + } + + public String help() + { + return "Copy messages between queues.\n" + + "The currently selected message set will be copied to the specifed queue.\n" + + "Alternatively the values can be provided on the command line."; + } + + public String usage() + { + return "copy to=<queue> [from=<queue>] [msgids=<msgids eg, 1,2,4-10>]"; + } + + public String getCommand() + { + return "copy"; + } + + public void execute(String... args) + { + AMQQueue toQueue = null; + AMQQueue fromQueue = _tool.getState().getQueue(); + java.util.List<Long> msgids = _tool.getState().getMessages(); + + if (args.length >= 2) + { + for (String arg : args) + { + if (arg.startsWith("to=")) + { + String queueName = arg.substring(arg.indexOf("=") + 1); + toQueue = _tool.getState().getVhost().getQueueRegistry().getQueue(new AMQShortString(queueName)); + } + + if (arg.startsWith("from=")) + { + String queueName = arg.substring(arg.indexOf("=") + 1); + fromQueue = _tool.getState().getVhost().getQueueRegistry().getQueue(new AMQShortString(queueName)); + } + + if (arg.startsWith("msgids=")) + { + String msgidStr = arg.substring(arg.indexOf("=") + 1); + + // Record the current message selection + java.util.List<Long> currentIDs = _tool.getState().getMessages(); + + // Use the ToolState class to perform the messasge parsing + _tool.getState().setMessages(msgidStr); + msgids = _tool.getState().getMessages(); + + // Reset the original selection of messages + _tool.getState().setMessages(currentIDs); + } + } + } + + if (toQueue == null) + { + _console.println("Queue to copy to not specifed."); + _console.println(usage()); + return; + } + + if (fromQueue == null) + { + _console.println("Queue to copy from not specifed."); + _console.println(usage()); + return; + } + + performCopy(fromQueue, toQueue, msgids); + } + + protected void performCopy(AMQQueue fromQueue, AMQQueue toQueue, java.util.List<Long> msgids) + { + Long previous = null; + Long start = null; + + for (long id : msgids) + { + if (previous != null) + { + if (id == previous + 1) + { + if (start == null) + { + start = previous; + } + } + else + { + if (start != null) + { + //move a range of ids + fromQueue.moveMessagesToAnotherQueue(start, id, toQueue.getName().toString(), _storeContext); + } + else + { + //move a single id + fromQueue.moveMessagesToAnotherQueue(id, id, toQueue.getName().toString(), _storeContext); + } + } + } + + previous = id; + } + } +} diff --git a/java/broker/src/main/java/org/apache/qpid/tools/messagestore/commands/Dump.java b/java/broker/src/main/java/org/apache/qpid/tools/messagestore/commands/Dump.java index 0dd6924d56..eea53252c6 100644 --- a/java/broker/src/main/java/org/apache/qpid/tools/messagestore/commands/Dump.java +++ b/java/broker/src/main/java/org/apache/qpid/tools/messagestore/commands/Dump.java @@ -54,7 +54,7 @@ public class Dump extends Show public String usage() { - return getCommand() + " [show=[all],[msgheaders],[_amqHeaders],[routing],[content] id=<msgid e.g. 1,2,4-10>"; + return getCommand() + " [show=[all],[msgheaders],[_amqHeaders],[routing],[content]] [id=<msgid e.g. 1,2,4-10>]"; } public String getCommand() diff --git a/java/broker/src/main/java/org/apache/qpid/tools/messagestore/commands/Help.java b/java/broker/src/main/java/org/apache/qpid/tools/messagestore/commands/Help.java index 76967ff06f..0f9546541b 100644 --- a/java/broker/src/main/java/org/apache/qpid/tools/messagestore/commands/Help.java +++ b/java/broker/src/main/java/org/apache/qpid/tools/messagestore/commands/Help.java @@ -35,7 +35,7 @@ public class Help extends AbstractCommand public String help() { - return "Provides detailed help on commands. "; + return "Provides detailed help on commands."; } public String getCommand() @@ -59,6 +59,7 @@ public class Help extends AbstractCommand if (command != null) { _console.println(command.help()); + _console.println("Usage:" + command.usage()); } else { diff --git a/java/broker/src/main/java/org/apache/qpid/tools/messagestore/commands/List.java b/java/broker/src/main/java/org/apache/qpid/tools/messagestore/commands/List.java index 37d89c079f..8a42718542 100644 --- a/java/broker/src/main/java/org/apache/qpid/tools/messagestore/commands/List.java +++ b/java/broker/src/main/java/org/apache/qpid/tools/messagestore/commands/List.java @@ -47,12 +47,12 @@ public class List extends AbstractCommand public String help() { - return "list availble items."; + return "list available items."; } public String usage() { - return "list queues [<exchange>] | exchanges| bindings [<exchange>] | all."; + return "list queues [<exchange>] | exchanges | bindings [<exchange>] | all"; } public String getCommand() diff --git a/java/broker/src/main/java/org/apache/qpid/tools/messagestore/commands/Select.java b/java/broker/src/main/java/org/apache/qpid/tools/messagestore/commands/Select.java index b9156f6889..f92e56a7bf 100644 --- a/java/broker/src/main/java/org/apache/qpid/tools/messagestore/commands/Select.java +++ b/java/broker/src/main/java/org/apache/qpid/tools/messagestore/commands/Select.java @@ -41,12 +41,12 @@ public class Select extends AbstractCommand public String help() { - return "Perform a selection"; + return "Perform a selection."; } public String usage() { - return "select virtualhost <name> |exchange <name> |queue <name> | msgs id=< msgids eg. 1,2,4-10 >"; + return "select virtualhost <name> |exchange <name> |queue <name> | msgs id=<msgids eg. 1,2,4-10>"; } public String getCommand() diff --git a/java/broker/src/main/java/org/apache/qpid/tools/messagestore/commands/Show.java b/java/broker/src/main/java/org/apache/qpid/tools/messagestore/commands/Show.java index 7bff89f61f..5988cdabfc 100644 --- a/java/broker/src/main/java/org/apache/qpid/tools/messagestore/commands/Show.java +++ b/java/broker/src/main/java/org/apache/qpid/tools/messagestore/commands/Show.java @@ -52,7 +52,7 @@ public class Show extends AbstractCommand public String usage() { - return getCommand() + " [show=[all],[msgheaders],[amqheaders],[routing] id=<msgid e.g. 1,2,4-10>"; + return getCommand() + " [show=[all],[msgheaders],[amqheaders],[routing]] [id=<msgid e.g. 1,2,4-10>]"; } public String getCommand() @@ -94,35 +94,6 @@ public class Show extends AbstractCommand if (arg.startsWith("id=")) { - StringTokenizer tok = new StringTokenizer(arg.substring(arg.indexOf("=") + 1), ","); - - if (tok.hasMoreTokens()) - { - msgids = new LinkedList<Long>(); - } - - while (tok.hasMoreTokens()) - { - String next = tok.nextToken(); - if (next.contains("-")) - { - Long start = Long.parseLong(next.substring(0, next.indexOf("-"))); - Long end = Long.parseLong(next.substring(next.indexOf("-") + 1)); - - if (end >= start) - { - for (long l = start; l <= end; l++) - { - msgids.add(l); - } - } - } - else - { - msgids.add(Long.parseLong(next)); - } - } - _tool.getState().setMessages(msgids); } }//for args @@ -133,7 +104,7 @@ public class Show extends AbstractCommand { if (_tool.getState().getVhost() == null) { - _console.println("No Virtualhost open. Open a Virtualhost first."); + _console.println("No Virtualhost selected. 'DuSelect' a Virtualhost first."); return; } diff --git a/java/broker/src/main/java/org/apache/qpid/tools/utils/SimpleCommandParser.java b/java/broker/src/main/java/org/apache/qpid/tools/utils/SimpleCommandParser.java index ba272ef19d..09444ccdd7 100644 --- a/java/broker/src/main/java/org/apache/qpid/tools/utils/SimpleCommandParser.java +++ b/java/broker/src/main/java/org/apache/qpid/tools/utils/SimpleCommandParser.java @@ -65,6 +65,11 @@ public class SimpleCommandParser implements CommandParser _nextCommand = null; } + if (input == null) + { + return null; + } + StringTokenizer tok = new StringTokenizer(input, " "); int tokenCount = tok.countTokens(); |