From f14233c6bf07cb42c4cb0f4a0de576febed7c488 Mon Sep 17 00:00:00 2001 From: Alan Conway Date: Fri, 17 Feb 2012 14:14:33 +0000 Subject: QPID-3603: Rename qpid-ha-status to qpid-ha-tool, get/set client & broker URLs git-svn-id: https://svn.apache.org/repos/asf/qpid/branches/qpid-3603-7@1245537 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/cpp/src/qpid/Url.cpp | 1 + qpid/cpp/src/qpid/ha/HaBroker.cpp | 38 +++++++++------ qpid/cpp/src/qpid/ha/management-schema.xml | 15 +++--- qpid/cpp/src/tests/ha_tests.py | 2 +- qpid/tools/src/py/qpid-ha-status | 78 ------------------------------ qpid/tools/src/py/qpid-ha-tool | 71 +++++++++++++++++++++++++++ 6 files changed, 105 insertions(+), 100 deletions(-) delete mode 100755 qpid/tools/src/py/qpid-ha-status create mode 100755 qpid/tools/src/py/qpid-ha-tool diff --git a/qpid/cpp/src/qpid/Url.cpp b/qpid/cpp/src/qpid/Url.cpp index f699b60c17..2061499ec3 100644 --- a/qpid/cpp/src/qpid/Url.cpp +++ b/qpid/cpp/src/qpid/Url.cpp @@ -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(); diff --git a/qpid/cpp/src/qpid/ha/HaBroker.cpp b/qpid/cpp/src/qpid/ha/HaBroker.cpp index 0e342bd17c..a53afa82fe 100644 --- a/qpid/cpp/src/qpid/ha/HaBroker.cpp +++ b/qpid/cpp/src/qpid/ha/HaBroker.cpp @@ -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: diff --git a/qpid/cpp/src/qpid/ha/management-schema.xml b/qpid/cpp/src/qpid/ha/management-schema.xml index 0fd18a10d4..47b8880b35 100644 --- a/qpid/cpp/src/qpid/ha/management-schema.xml +++ b/qpid/cpp/src/qpid/ha/management-schema.xml @@ -21,14 +21,17 @@ - + + + - - + + + + + + - - - diff --git a/qpid/cpp/src/tests/ha_tests.py b/qpid/cpp/src/tests/ha_tests.py index bba3bc223a..c213e6a4ff 100755 --- a/qpid/cpp/src/tests/ha_tests.py +++ b/qpid/cpp/src/tests/ha_tests.py @@ -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: diff --git a/qpid/tools/src/py/qpid-ha-status b/qpid/tools/src/py/qpid-ha-status deleted file mode 100755 index 20804b678d..0000000000 --- a/qpid/tools/src/py/qpid-ha-status +++ /dev/null @@ -1,78 +0,0 @@ -#!/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 - -usage=""" -Usage: qpid-ha-status [broker-address] [status] -If status is specified, sets the HA status of the broker. Otherwise prints the current HA status. Status must be one of: primary, backup, solo. -""" - -STATUS_VALUES=["primary", "backup"] - -def is_valid_status(value): return value in STATUS_VALUES - -def validate_status(value): - if not is_valid_status(value): - raise Exception("Invalid HA status value: %s"%(value)) - -class HaBroker: - def __init__(self, broker, session): - self.session = 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 get_status(self): - return self.ha_broker.status - - def set_status(self, value): - validate_status(value) - self.ha_broker.setStatus(value) - -def parse_args(args): - broker, status = "localhost:5672", None - if args and is_valid_status(args[-1]): - status = args[-1] - args.pop() - if args: broker = args[0] - return broker, status - -def main(): - try: - session = qmf.console.Session() - try: - broker, status = parse_args(sys.argv[1:]) - hb = HaBroker(broker, session) - if status: hb.set_status(status) - else: print hb.get_status() - finally: - session.close() - return 0 - except Exception, e: - print e - return -1 - -if __name__ == "__main__": - sys.exit(main()) diff --git a/qpid/tools/src/py/qpid-ha-tool b/qpid/tools/src/py/qpid-ha-tool new file mode 100755 index 0000000000..5b6d85c7bd --- /dev/null +++ b/qpid/tools/src/py/qpid-ha-tool @@ -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)) -- cgit v1.2.1