Author: aconway
Date: Fri Feb 17 14:14:33 2012
New Revision: 1245537

URL: http://svn.apache.org/viewvc?rev=1245537&view=rev
Log:
QPID-3603: Rename qpid-ha-status to qpid-ha-tool, get/set client & broker URLs

Added:
    qpid/branches/qpid-3603-7/qpid/tools/src/py/qpid-ha-tool   (with props)
Removed:
    qpid/branches/qpid-3603-7/qpid/tools/src/py/qpid-ha-status
Modified:
    qpid/branches/qpid-3603-7/qpid/cpp/src/qpid/Url.cpp
    qpid/branches/qpid-3603-7/qpid/cpp/src/qpid/ha/HaBroker.cpp
    qpid/branches/qpid-3603-7/qpid/cpp/src/qpid/ha/management-schema.xml
    qpid/branches/qpid-3603-7/qpid/cpp/src/tests/ha_tests.py

Modified: qpid/branches/qpid-3603-7/qpid/cpp/src/qpid/Url.cpp
URL: 
http://svn.apache.org/viewvc/qpid/branches/qpid-3603-7/qpid/cpp/src/qpid/Url.cpp?rev=1245537&r1=1245536&r2=1245537&view=diff
==============================================================================
--- qpid/branches/qpid-3603-7/qpid/cpp/src/qpid/Url.cpp (original)
+++ qpid/branches/qpid-3603-7/qpid/cpp/src/qpid/Url.cpp Fri Feb 17 14:14:33 2012
@@ -255,6 +255,7 @@ void Url::parse(const char* url) {
 }
 
 void Url::parseNoThrow(const char* url) {
+    clear();
     cache.clear();
     if (!UrlParser(*this, url).parse())
         clear();

Modified: qpid/branches/qpid-3603-7/qpid/cpp/src/qpid/ha/HaBroker.cpp
URL: 
http://svn.apache.org/viewvc/qpid/branches/qpid-3603-7/qpid/cpp/src/qpid/ha/HaBroker.cpp?rev=1245537&r1=1245536&r2=1245537&view=diff
==============================================================================
--- qpid/branches/qpid-3603-7/qpid/cpp/src/qpid/ha/HaBroker.cpp (original)
+++ qpid/branches/qpid-3603-7/qpid/cpp/src/qpid/ha/HaBroker.cpp Fri Feb 17 
14:14:33 2012
@@ -27,6 +27,8 @@
 #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 "qpid/log/Statement.h"
 
 namespace qpid {
@@ -82,22 +84,28 @@ HaBroker::~HaBroker() {}
 Manageable::status_t HaBroker::ManagementMethod (uint32_t methodId, Args& 
args, string&) {
     sys::Mutex::ScopedLock l(lock);
     switch (methodId) {
-      case _qmf::HaBroker::METHOD_SETSTATUS: {
-          std::string status = 
dynamic_cast<_qmf::ArgsHaBrokerSetStatus&>(args).i_status;
-          if (status == PRIMARY) {
-              if (backup.get()) {
-                  // FIXME aconway 2012-01-26: create primary state before 
resetting backup
-                  // as it allows client connections.
-                  backup.reset();
-                  QPID_LOG(notice, "HA: Primary promoted from backup");
-              }
-          } else if (status == BACKUP) {
-              if (!backup.get())
-                  throw Exception("HA: Primary cannot be demoted");
-          } else {
-              throw Exception("Invalid HA status: "+status);
+      case _qmf::HaBroker::METHOD_PROMOTE: {
+          if (backup.get()) {   // I am a backup
+              // FIXME aconway 2012-01-26: create primary state before 
resetting backup
+              // as that allows client connections.
+              backup.reset();
+              QPID_LOG(notice, "HA: Primary promoted from backup");
+              mgmtObject->set_status(PRIMARY);
           }
-          mgmtObject->set_status(status);
+          break;
+      }
+      case _qmf::HaBroker::METHOD_SETCLIENTADDRESSES: {
+          QPID_LOG(critical, "FIXME" << "before " <<  clientUrl)
+          clientUrl = 
dynamic_cast<_qmf::ArgsHaBrokerSetClientAddresses&>(args).i_clientAddresses;
+          QPID_LOG(critical, "FIXME" << "after " <<  clientUrl)
+          // FIXME aconway 2012-01-30: upate status for new URL
+          mgmtObject->set_clientAddresses(clientUrl.str());
+          break;
+      }
+      case _qmf::HaBroker::METHOD_SETBROKERADDRESSES: {
+          brokerUrl = 
dynamic_cast<_qmf::ArgsHaBrokerSetBrokerAddresses&>(args).i_brokerAddresses;
+          // FIXME aconway 2012-01-30: upate status for new URL
+          mgmtObject->set_brokerAddresses(brokerUrl.str());
           break;
       }
       default:

Modified: qpid/branches/qpid-3603-7/qpid/cpp/src/qpid/ha/management-schema.xml
URL: 
http://svn.apache.org/viewvc/qpid/branches/qpid-3603-7/qpid/cpp/src/qpid/ha/management-schema.xml?rev=1245537&r1=1245536&r2=1245537&view=diff
==============================================================================
--- qpid/branches/qpid-3603-7/qpid/cpp/src/qpid/ha/management-schema.xml 
(original)
+++ qpid/branches/qpid-3603-7/qpid/cpp/src/qpid/ha/management-schema.xml Fri 
Feb 17 14:14:33 2012
@@ -21,14 +21,17 @@
 
   <!-- Monitor and control HA status of a broker. -->
   <class name="HaBroker">
-    <property name="status" type="sstr" desc="HA status: primary, backup"/>
+    <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."/>
 
-    <method name="setStatus" desc="Set HA status: primary, backup">
-      <arg name="status" type="sstr" dir="I"/>
+    <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>
+    <method name="setBrokerAddresses" desc="Set HA broker addresses">
+      <arg name="brokerAddresses" type="sstr" dir="I"/>
     </method>
-
-    <property name="clientUrl" type="sstr" desc="URL used by clients to 
connect to the cluster."/>
-    <property name="brokerUrl" type="sstr" desc="URL used by brokers to 
connect to other brokers in the cluster."/>
   </class>
 
 </schema>

Modified: qpid/branches/qpid-3603-7/qpid/cpp/src/tests/ha_tests.py
URL: 
http://svn.apache.org/viewvc/qpid/branches/qpid-3603-7/qpid/cpp/src/tests/ha_tests.py?rev=1245537&r1=1245536&r2=1245537&view=diff
==============================================================================
--- qpid/branches/qpid-3603-7/qpid/cpp/src/tests/ha_tests.py (original)
+++ qpid/branches/qpid-3603-7/qpid/cpp/src/tests/ha_tests.py Fri Feb 17 
14:14:33 2012
@@ -57,7 +57,7 @@ class ShortTests(BrokerTest):
         bs.connection.close()
 
     def promote(self, broker):
-        os.system("qpid-ha-status %s primary"%(broker.host_port()))
+        os.system("qpid-ha-tool --promote %s"%(broker.host_port()))
 
     def assert_missing(self, session, address):
         try:

Added: qpid/branches/qpid-3603-7/qpid/tools/src/py/qpid-ha-tool
URL: 
http://svn.apache.org/viewvc/qpid/branches/qpid-3603-7/qpid/tools/src/py/qpid-ha-tool?rev=1245537&view=auto
==============================================================================
--- qpid/branches/qpid-3603-7/qpid/tools/src/py/qpid-ha-tool (added)
+++ qpid/branches/qpid-3603-7/qpid/tools/src/py/qpid-ha-tool Fri Feb 17 
14:14:33 2012
@@ -0,0 +1,71 @@
+#!/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
+
+op=optparse.OptionParser(usage="Usage: %prog [options] [broker-address]")
+
+op.add_option("-p", "--promote", action="store_true",
+             help="Promote a backup broker to become the primary.")
+op.add_option("-c", "--client-addresses", action="store", type="string",
+             help="Set list of addresses used by clients to connect to the HA 
cluster.")
+op.add_option("-b", "--broker-addresses", action="store", type="string",
+             help="Set list of addresses used by HA brokers to connect to each 
other.")
+op.add_option("-q", "--query", action="store_true",
+             help="Show the current HA settings on the broker.")
+
+class HaBroker:
+    def __init__(self, broker):
+        self.session = qmf.console.Session()
+       self.qmf_broker = self.session.addBroker(broker, 
client_properties={"qpid.ha-admin":1})
+       ha_brokers = self.session.getObjects(_class="habroker", 
_package="org.apache.qpid.ha")
+       if (not ha_brokers): raise Exception("Broker does not have HA enabled.")
+       self.ha_broker = ha_brokers[0]
+
+    def query(self):
+       self.ha_broker.update()
+       print "status=", self.ha_broker.status
+       print "client-addresses=", self.ha_broker.clientAddresses
+       print "broker-addresses=", self.ha_broker.brokerAddresses
+
+def main(argv):
+    try:
+       opts, args = op.parse_args(argv)
+       if len(args) >1: broker = args[1]
+       else: broker = "localhost:5672"
+       hb = HaBroker(broker)
+       try:
+           action=False
+           if opts.promote: hb.ha_broker.promote(); action=True
+           if opts.client_addresses: 
hb.ha_broker.setClientAddresses(opts.client_addresses); action=True
+           if opts.broker_addresses: 
hb.ha_broker.setBrokerAddresses(opts.broker_addresses); action=True
+           if opts.query or not action: hb.query()
+           return 0
+       finally:
+           hb.session.close()          # Avoid errors shutting down threads.
+    except Exception, e:
+       raise                           # FIXME aconway 2012-01-30:
+        print e
+        return -1
+
+if __name__ == "__main__":
+    sys.exit(main(sys.argv))

Propchange: qpid/branches/qpid-3603-7/qpid/tools/src/py/qpid-ha-tool
------------------------------------------------------------------------------
    svn:executable = *



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

Reply via email to