qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acon...@apache.org
Subject svn commit: r1293397 - in /qpid/trunk/qpid: cpp/src/ cpp/src/qpid/ha/ cpp/src/tests/ tools/src/py/
Date Fri, 24 Feb 2012 20:05:48 GMT
Author: aconway
Date: Fri Feb 24 20:05:47 2012
New Revision: 1293397

URL: http://svn.apache.org/viewvc?rev=1293397&view=rev
Log:
QPID-3603: Improved command-based qpid-ha tool and ha config option names.

Added:
    qpid/trunk/qpid/tools/src/py/qpid-ha   (with props)
Removed:
    qpid/trunk/qpid/tools/src/py/qpid-ha-tool
Modified:
    qpid/trunk/qpid/cpp/src/Makefile.am
    qpid/trunk/qpid/cpp/src/qpid/ha/HaBroker.cpp
    qpid/trunk/qpid/cpp/src/qpid/ha/HaBroker.h
    qpid/trunk/qpid/cpp/src/qpid/ha/HaPlugin.cpp
    qpid/trunk/qpid/cpp/src/qpid/ha/Settings.h
    qpid/trunk/qpid/cpp/src/qpid/ha/management-schema.xml
    qpid/trunk/qpid/cpp/src/tests/ha_tests.py
    qpid/trunk/qpid/cpp/src/tests/test_env.sh.in

Modified: qpid/trunk/qpid/cpp/src/Makefile.am
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/Makefile.am?rev=1293397&r1=1293396&r2=1293397&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/Makefile.am (original)
+++ qpid/trunk/qpid/cpp/src/Makefile.am Fri Feb 24 20:05:47 2012
@@ -102,15 +102,16 @@ $(srcdir)/rubygen.cmake: $(rgen_generato
 
 # Management generator.
 mgen_dir=$(top_srcdir)/managementgen
-mgen_cmd=$(mgen_dir)/qmf-gen -m $(srcdir)/managementgen.mk \
-	-c $(srcdir)/managementgen.cmake -q -b -o qmf \
-	$(top_srcdir)/../specs/management-schema.xml \
+mgen_xml=$(top_srcdir)/../specs/management-schema.xml \
 	$(srcdir)/qpid/acl/management-schema.xml \
 	$(srcdir)/qpid/cluster/management-schema.xml \
 	$(srcdir)/qpid/ha/management-schema.xml
+mgen_cmd=$(mgen_dir)/qmf-gen -m $(srcdir)/managementgen.mk \
+	-c $(srcdir)/managementgen.cmake -q -b -o qmf \
+	$(mgen_xml)
 
 $(srcdir)/managementgen.mk $(mgen_broker_cpp) $(dist_qpid_management_HEADERS): mgen.timestamp
-mgen.timestamp: $(mgen_generator)
+mgen.timestamp: $(mgen_generator) $(mgen_xml)
 	$(mgen_cmd); touch $@
 $(mgen_generator):
 

Modified: qpid/trunk/qpid/cpp/src/qpid/ha/HaBroker.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/ha/HaBroker.cpp?rev=1293397&r1=1293396&r2=1293397&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/ha/HaBroker.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/ha/HaBroker.cpp Fri Feb 24 20:05:47 2012
@@ -27,8 +27,9 @@
 #include "qpid/broker/Broker.h"
 #include "qpid/management/ManagementAgent.h"
 #include "qmf/org/apache/qpid/ha/Package.h"
-#include "qmf/org/apache/qpid/ha/ArgsHaBrokerSetClientAddresses.h"
-#include "qmf/org/apache/qpid/ha/ArgsHaBrokerSetBrokerAddresses.h"
+#include "qmf/org/apache/qpid/ha/ArgsHaBrokerSetBrokers.h"
+#include "qmf/org/apache/qpid/ha/ArgsHaBrokerSetPublicBrokers.h"
+#include "qmf/org/apache/qpid/ha/ArgsHaBrokerSetExpectedBackups.h"
 #include "qpid/log/Statement.h"
 
 namespace qpid {
@@ -88,18 +89,19 @@ Manageable::status_t HaBroker::Managemen
           }
           break;
       }
-      case _qmf::HaBroker::METHOD_SETCLIENTADDRESSES: {
-          setClientUrl(
-              Url(dynamic_cast<_qmf::ArgsHaBrokerSetClientAddresses&>(args).
-                  i_clientAddresses), l);
+      case _qmf::HaBroker::METHOD_SETBROKERS: {
+          setBrokerUrl(Url(dynamic_cast<_qmf::ArgsHaBrokerSetBrokers&>(args).i_url),
l);
           break;
       }
-      case _qmf::HaBroker::METHOD_SETBROKERADDRESSES: {
-          setBrokerUrl(
-              Url(dynamic_cast<_qmf::ArgsHaBrokerSetBrokerAddresses&>(args)
-                  .i_brokerAddresses), l);
+      case _qmf::HaBroker::METHOD_SETPUBLICBROKERS: {
+          setClientUrl(Url(dynamic_cast<_qmf::ArgsHaBrokerSetPublicBrokers&>(args).i_url),
l);
           break;
       }
+      case _qmf::HaBroker::METHOD_SETEXPECTEDBACKUPS: {
+          setExpectedBackups(dynamic_cast<_qmf::ArgsHaBrokerSetExpectedBackups&>(args).i_expectedBackups,
l);
+        break;
+    }
+
       default:
         return Manageable::STATUS_UNKNOWN_METHOD;
     }
@@ -115,7 +117,7 @@ void HaBroker::setClientUrl(const Url& u
 void HaBroker::updateClientUrl(const sys::Mutex::ScopedLock&) {
     Url url = clientUrl.empty() ? brokerUrl : clientUrl;
     assert(!url.empty());
-    mgmtObject->set_clientAddresses(url.str());
+    mgmtObject->set_publicBrokers(url.str());
     knownBrokers.clear();
     knownBrokers.push_back(url);
     QPID_LOG(debug, "HA: Setting client URL to: " << url);
@@ -125,12 +127,17 @@ void HaBroker::setBrokerUrl(const Url& u
     if (url.empty()) throw Exception("Invalid empty URL for HA broker failover");
     QPID_LOG(debug, "HA: Setting broker URL to: " << url);
     brokerUrl = url;
-    mgmtObject->set_brokerAddresses(brokerUrl.str());
+    mgmtObject->set_brokers(brokerUrl.str());
     if (backup.get()) backup->setBrokerUrl(brokerUrl);
     // Updating broker URL also updates defaulted client URL:
     if (clientUrl.empty()) updateClientUrl(l);
 }
 
+void HaBroker::setExpectedBackups(size_t n, const sys::Mutex::ScopedLock&) {
+    expectedBackups = n;
+    mgmtObject->set_expectedBackups(n);
+}
+
 std::vector<Url> HaBroker::getKnownBrokers() const {
     return knownBrokers;
 }

Modified: qpid/trunk/qpid/cpp/src/qpid/ha/HaBroker.h
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/ha/HaBroker.h?rev=1293397&r1=1293396&r2=1293397&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/ha/HaBroker.h (original)
+++ qpid/trunk/qpid/cpp/src/qpid/ha/HaBroker.h Fri Feb 24 20:05:47 2012
@@ -55,6 +55,7 @@ class HaBroker : public management::Mana
   private:
     void setClientUrl(const Url&, const sys::Mutex::ScopedLock&);
     void setBrokerUrl(const Url&, const sys::Mutex::ScopedLock&);
+    void setExpectedBackups(size_t, const sys::Mutex::ScopedLock&);
     void updateClientUrl(const sys::Mutex::ScopedLock&);
     bool isPrimary(const sys::Mutex::ScopedLock&) { return !backup.get(); }
     std::vector<Url> getKnownBrokers() const;
@@ -67,6 +68,7 @@ class HaBroker : public management::Mana
     qmf::org::apache::qpid::ha::HaBroker* mgmtObject;
     Url clientUrl, brokerUrl;
     std::vector<Url> knownBrokers;
+    size_t expectedBackups;
 };
 }} // namespace qpid::ha
 

Modified: qpid/trunk/qpid/cpp/src/qpid/ha/HaPlugin.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/ha/HaPlugin.cpp?rev=1293397&r1=1293396&r2=1293397&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/ha/HaPlugin.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/ha/HaPlugin.cpp Fri Feb 24 20:05:47 2012
@@ -31,12 +31,20 @@ struct Options : public qpid::Options {
     Settings& settings;
     Options(Settings& s) : qpid::Options("HA Options"), settings(s) {
         addOptions()
-            ("ha-enable", optValue(settings.enabled, "yes|no"), "Enable High Availability
features")
-            ("ha-client-url", optValue(settings.clientUrl,"URL"), "URL that clients use to
connect and fail over.")
-            ("ha-broker-url", optValue(settings.brokerUrl,"URL"), "URL that backup brokers
use to connect and fail over.")
-            ("ha-username", optValue(settings.username, "USER"), "Username for connections
between brokers")
-            ("ha-password", optValue(settings.password, "PASS"), "Password for connections
between brokers")
-            ("ha-mechanism", optValue(settings.mechanism, "MECH"), "Authentication mechanism
for connections between brokers")
+            ("ha-cluster", optValue(settings.enabled, "yes|no"),
+             "Join a HA active/passive cluster.")
+            ("ha-brokers", optValue(settings.brokerUrl,"URL"),
+             "URL that backup brokers use to connect and fail over.")
+            ("ha-public-brokers", optValue(settings.clientUrl,"URL"),
+             "URL that clients use to connect and fail over, defaults to ha-brokers.")
+            ("ha-expected-backups", optValue(settings.expectedBackups, "N"),
+             "Number of backups expected to be active in the HA cluster.")
+            ("ha-username", optValue(settings.username, "USER"),
+             "Username for connections between HA brokers")
+            ("ha-password", optValue(settings.password, "PASS"),
+             "Password for connections between HA brokers")
+            ("ha-mechanism", optValue(settings.mechanism, "MECH"),
+             "Authentication mechanism for connections between HA brokers")
             ;
     }
 };

Modified: qpid/trunk/qpid/cpp/src/qpid/ha/Settings.h
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/ha/Settings.h?rev=1293397&r1=1293396&r2=1293397&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/ha/Settings.h (original)
+++ qpid/trunk/qpid/cpp/src/qpid/ha/Settings.h Fri Feb 24 20:05:47 2012
@@ -33,10 +33,11 @@ namespace ha {
 class Settings
 {
   public:
-    Settings() : enabled(false) {}
+    Settings() : enabled(false), expectedBackups(0) {}
     bool enabled;
     std::string clientUrl;
     std::string brokerUrl;
+    size_t expectedBackups;
     std::string username, password, mechanism;
   private:
 };

Modified: qpid/trunk/qpid/cpp/src/qpid/ha/management-schema.xml
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/ha/management-schema.xml?rev=1293397&r1=1293396&r2=1293397&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/ha/management-schema.xml (original)
+++ qpid/trunk/qpid/cpp/src/qpid/ha/management-schema.xml Fri Feb 24 20:05:47 2012
@@ -22,16 +22,30 @@
   <!-- Monitor and control HA status of a broker. -->
   <class name="HaBroker">
     <property name="name"   type="sstr" access="RC" index="y" desc="Primary Key"/>
+
     <property name="status" type="sstr" desc="HA status: primary or backup"/>
-    <property name="clientAddresses" type="sstr" desc="List of addresses used by clients
to connect to the HA cluster."/>
-    <property name="brokerAddresses" type="sstr" desc="List of addresses used by HA brokers
to connect to each other."/>
+
+    <property name="brokers" type="sstr"
+	      desc="Multiple-address URL used by HA brokers to connect to each other."/>
+
+    <property name="publicBrokers" type="sstr"
+	      desc="Multiple-address URL used by clients to connect to the HA brokers."/>
+
+    <property name="expectedBackups" type="uint16"
+	      desc="Number of HA backup brokers expected."/>>
 
     <method name="promote" desc="Promote a backup broker to primary."/>
-    <method name="setClientAddresses" desc="Set HA client addresses">
-      <arg name="clientAddresses" type="sstr" dir="I"/>
+
+    <method name="setBrokers" desc="Set URL for HA brokers to connect to each other.">
+      <arg name="url" type="sstr" dir="I"/>
+    </method>
+
+    <method name="setPublicBrokers" desc="Set URL for clients to connect to  HA brokers">
+      <arg name="url" type="sstr" dir="I"/>
     </method>
-    <method name="setBrokerAddresses" desc="Set HA broker addresses">
-      <arg name="brokerAddresses" type="sstr" dir="I"/>
+
+    <method name="setExpectedBackups" desc="Set number of backups expected">
+      <arg name="expectedBackups" type="uint16" dir="I"/>
     </method>
   </class>
 

Modified: qpid/trunk/qpid/cpp/src/tests/ha_tests.py
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/tests/ha_tests.py?rev=1293397&r1=1293396&r2=1293397&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/tests/ha_tests.py (original)
+++ qpid/trunk/qpid/cpp/src/tests/ha_tests.py Fri Feb 24 20:05:47 2012
@@ -34,20 +34,20 @@ class HaBroker(Broker):
         args=["--load-module", BrokerTest.ha_lib,
               # FIXME aconway 2012-02-13: workaround slow link failover.
               "--link-maintenace-interval=0.1",
-              "--ha-enable=yes"]
-        if broker_url: args += [ "--ha-broker-url", broker_url ]
+              "--ha-cluster=yes"]
+        if broker_url: args += [ "--ha-brokers", broker_url ]
         Broker.__init__(self, test, args, **kwargs)
 
     def promote(self):
-        assert os.system("$QPID_HA_TOOL_EXEC --promote %s"%(self.host_port())) == 0
+        assert os.system("$QPID_HA_EXEC promote -b %s"%(self.host_port())) == 0
 
     def set_client_url(self, url):
         assert os.system(
-            "$QPID_HA_TOOL_EXEC --client-addresses=%s %s"%(url,self.host_port())) == 0
+            "$QPID_HA_EXEC set --public-brokers=%s -b %s"%(url,self.host_port())) == 0
 
     def set_broker_url(self, url):
         assert os.system(
-            "$QPID_HA_TOOL_EXEC --broker-addresses=%s %s"%(url, self.host_port())) == 0
+            "$QPID_HA_EXEC set --brokers=%s -b %s"%(url, self.host_port())) == 0
 
 def set_broker_urls(brokers):
     url = ",".join([b.host_port() for b in brokers])
@@ -475,10 +475,10 @@ class LongTests(BrokerTest):
 
 if __name__ == "__main__":
     shutil.rmtree("brokertest.tmp", True)
-    qpid_ha_tool = os.getenv("QPID_HA_TOOL_EXEC")
-    if  qpid_ha_tool and os.path.exists(qpid_ha_tool):
+    qpid_ha = os.getenv("QPID_HA_EXEC")
+    if  qpid_ha and os.path.exists(qpid_ha):
         os.execvp("qpid-python-test",
                   ["qpid-python-test", "-m", "ha_tests"] + sys.argv[1:])
     else:
-        print "Skipping ha_tests, qpid_ha_tool not available"
+        print "Skipping ha_tests, qpid_ha not available"
 

Modified: qpid/trunk/qpid/cpp/src/tests/test_env.sh.in
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/tests/test_env.sh.in?rev=1293397&r1=1293396&r2=1293397&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/tests/test_env.sh.in (original)
+++ qpid/trunk/qpid/cpp/src/tests/test_env.sh.in Fri Feb 24 20:05:47 2012
@@ -44,7 +44,7 @@ export PYTHONPATH=$srcdir:$PYTHON_DIR:$P
 export QPID_CONFIG_EXEC=$PYTHON_COMMANDS/qpid-config
 export QPID_ROUTE_EXEC=$PYTHON_COMMANDS/qpid-route
 export QPID_CLUSTER_EXEC=$PYTHON_COMMANDS/qpid-cluster
-export QPID_HA_TOOL_EXEC=$PYTHON_COMMANDS/qpid-ha-tool
+export QPID_HA_EXEC=$PYTHON_COMMANDS/qpid-ha
 
 # Executables
 export QPIDD_EXEC=$top_builddir/src/qpidd

Added: qpid/trunk/qpid/tools/src/py/qpid-ha
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/tools/src/py/qpid-ha?rev=1293397&view=auto
==============================================================================
--- qpid/trunk/qpid/tools/src/py/qpid-ha (added)
+++ qpid/trunk/qpid/tools/src/py/qpid-ha Fri Feb 24 20:05:47 2012
@@ -0,0 +1,234 @@
+#!/usr/bin/env python
+
+#
+# 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.
+#
+
+import qmf.console, optparse, sys
+from qpid.management import managementChannel, managementClient
+from qpid.messaging import Connection
+from qpid.messaging import Message as QpidMessage
+try:
+    from uuid import uuid4
+except ImportError:
+    from qpid.datatypes import uuid4
+
+# Utility for doing fast qmf2 operations on a broker.
+class QmfBroker(object):
+    def __init__(self, conn):
+        self.conn = conn
+        self.sess = self.conn.session()
+        self.reply_to = "qmf.default.topic/direct.%s;{node:{type:topic}, link:{x-declare:{auto-delete:True,exclusive:True}}}"
% \
+            str(uuid4())
+        self.reply_rx = self.sess.receiver(self.reply_to)
+        self.reply_rx.capacity = 10
+        self.tx = self.sess.sender("qmf.default.direct/broker")
+        self.next_correlator = 1
+
+    def close(self):
+        self.conn.close()
+
+    def __repr__(self):
+        return "Qpid Broker: %s" % self.url
+
+    def _method(self, method, arguments, addr="org.apache.qpid.broker:broker:amqp-broker"):
+        props = {'method'             : 'request',
+                 'qmf.opcode'         : '_method_request',
+                 'x-amqp-0-10.app-id' : 'qmf2'}
+        correlator = str(self.next_correlator)
+        self.next_correlator += 1
+
+        content = {'_object_id'   : {'_object_name' : addr},
+                   '_method_name' : method,
+                   '_arguments'   : arguments}
+
+        message = QpidMessage(content, reply_to=self.reply_to, correlation_id=correlator,
+                              properties=props, subject="broker")
+        self.tx.send(message)
+        response = self.reply_rx.fetch(10)
+        if response.properties['qmf.opcode'] == '_exception':
+            raise Exception("Exception from Agent: %r" % response.content['_values'])
+        if response.properties['qmf.opcode'] != '_method_response':
+            raise Exception("bad response: %r" % response.properties)
+        return response.content['_arguments']
+
+    def _sendRequest(self, opcode, content):
+        props = {'method'             : 'request',
+                 'qmf.opcode'         : opcode,
+                 'x-amqp-0-10.app-id' : 'qmf2'}
+        correlator = str(self.next_correlator)
+        self.next_correlator += 1
+        message = QpidMessage(content, reply_to=self.reply_to, correlation_id=correlator,
+                              properties=props, subject="broker")
+        self.tx.send(message)
+        return correlator
+
+    def _doClassQuery(self, class_name):
+        query = {'_what'      : 'OBJECT',
+                 '_schema_id' : {'_class_name' : class_name}}
+        correlator = self._sendRequest('_query_request', query)
+        response = self.reply_rx.fetch(10)
+        if response.properties['qmf.opcode'] != '_query_response':
+            raise Exception("bad response")
+        items = []
+        done = False
+        while not done:
+            for item in response.content:
+                items.append(item['_values'])
+            if 'partial' in response.properties:
+                response = self.reply_rx.fetch(10)
+            else:
+                done = True
+        return items
+
+    def _doNameQuery(self, class_name, object_name, package_name='org.apache.qpid.broker'):
+        query = {'_what'      : 'OBJECT',
+                 '_object_id' : {'_object_name' : "%s:%s:%s" % (package_name, class_name,
object_name)}}
+        correlator = self._sendRequest('_query_request', query)
+        response = self.reply_rx.fetch(10)
+        if response.properties['qmf.opcode'] != '_query_response':
+            raise Exception("bad response")
+        items = []
+        done = False
+        while not done:
+            for item in response.content:
+                items.append(item['_values'])
+            if 'partial' in response.properties:
+                response = self.reply_rx.fetch(10)
+            else:
+                done = True
+        if len(items) == 1:
+            return items[0]
+        return None
+
+    def _getAllBrokerObjects(self, cls):
+        items = self._doClassQuery(cls.__name__.lower())
+        objs = []
+        for item in items:
+            objs.append(cls(self, item))
+        return objs
+
+    def _getBrokerObject(self, cls, name):
+        obj = self._doNameQuery(cls.__name__.lower(), name)
+        if obj:
+            return cls(self, obj)
+        return None
+
+    def get_ha_broker(self):
+        ha_brokers = self._doClassQuery("habroker")
+        if (not ha_brokers): raise Exception("Broker does not have HA enabled.")
+        return ha_brokers[0]
+
+HA_BROKER = "org.apache.qpid.ha:habroker:ha-broker"
+
+class Command:
+    commands = {}
+
+    def __init__(self, name, help, args=""):
+        Command.commands[name] = self
+        self.name = name
+        usage="%s [options]%s\n\n%s"%(name, args, help)
+        self.help = help
+        self.op=optparse.OptionParser(usage)
+        self.op.add_option("-b", "--broker", metavar="<url>", help="Connect to broker
at <url>")
+
+    def execute(self, command):
+        opts, args = self.op.parse_args(command)
+        broker = opts.broker or "localhost:5672"
+        # FIXME aconway 2012-02-23: enforce not doing primary-only operations on a backup
& vice versa
+        connection = Connection.establish(broker, client_properties={"qpid.ha-admin":1})
+        try: self.do_execute(QmfBroker(connection), opts, args)
+        finally: connection.close()
+
+    def do_execute(self, qmf_broker, opts, args):
+        raise Exception("Command '%s' is not yet implemented"%self.name)
+
+def print_all_help(name):
+    print "usage: %s <command> [<arguments>]\n\nCommands are:\n"%name
+    for c in Command.commands:
+        help = Command.commands[c].help
+        print "  %-12s %s."%(c, help.split(".")[0])
+    print "\nFor help with a command: %s <command> --help\n"%name
+
+
+class PromoteCmd(Command):
+    def __init__(self):
+        Command.__init__(self, "promote","Promote broker from backup to primary")
+    def do_execute(self, qmf_broker, opts, args):
+        qmf_broker._method("promote", {}, HA_BROKER)
+PromoteCmd()
+
+class ReadyCmd(Command):
+    def __init__(self):
+        Command.__init__(self, "ready", "Test if a backup broker is ready.\nReturn 0 if broker
is a ready backup, non-0 otherwise.")
+        self.op.add_option(
+            "--wait", type="int", metavar="<seconds>",
+            help="Wait up to <seconds> for broker to be ready. 0 means wait forever.")
+ReadyCmd()
+
+class ReplicateCmd(Command):
+    def __init__(self):
+        Command.__init__(self, "replicate", "Replicate <queue> from <broker>
to the current broker.", "<queue> <broker>")
+ReplicateCmd()
+
+class SetCmd(Command):
+    def __init__(self):
+        Command.__init__(self, "set", "Set HA configuration settings")
+        def add(optname, metavar, type, help):
+            self.op.add_option(optname, metavar=metavar, type=type, help=help, action="store")
+        add("--brokers", "<url>", "string", "HA brokers use <url> to connect
to each other")
+        add("--public-brokers", "<url>", "string", "Clients use <url> to connect
to HA brokers")
+        add("--backups", "<n>", "int", "Expect <n> backups to be running")
+
+    def do_execute(self, qmf_broker, opts, args):
+        if (opts.brokers): qmf_broker._method("setBrokers", {"url":opts.brokers}, HA_BROKER)
+        if (opts.public_brokers): qmf_broker._method("setPublicBrokers", {"url":opts.public_brokers},
HA_BROKER)
+        if (opts.backups): qmf_broker._method("setExpectedBackups", {"expectedBackups":opts.backups},
HA_BROKER)
+SetCmd()
+
+class QueryCmd(Command):
+    def __init__(self):
+        Command.__init__(self, "query", "Print HA configuration settings")
+
+    def do_execute(self, qmf_broker, opts, args):
+        hb = qmf_broker.get_ha_broker()
+        for x in [("Status:", "status"),
+                  ("Brokers URL:", "brokers"),
+                  ("Public URL:", "publicBrokers")]:
+            print "%-16s%s"%(x[0], hb[x[1]])
+
+QueryCmd()
+
+def main(argv):
+    try:
+        command=argv[1:]
+        if command and command[0] == "--help-all":
+            for c in Command.commands.itervalues():
+                c.op.print_help(); print
+            return 1
+        if not command or not command[0] in Command.commands:
+            print_all_help(argv[0]);
+            return 1;
+        Command.commands[command[0]].execute(command)
+    except Exception, e:
+        raise                           # FIXME aconway 2012-02-23:
+        print e
+        return 1
+
+if __name__ == "__main__":
+    sys.exit(main(sys.argv))

Propchange: qpid/trunk/qpid/tools/src/py/qpid-ha
------------------------------------------------------------------------------
    svn:executable = *



---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:commits-subscribe@qpid.apache.org


Mime
View raw message