Author: aconway
Date: Thu Jan 19 23:01:34 2012
New Revision: 1233630
URL: http://svn.apache.org/viewvc?rev=1233630&view=rev
Log:
QPID-3603: Add management interface and commmand line tool to set HA status.
- Fixed management generation to use full name in #ifdef guards.
- Added src/qpid/ha/management-schema.xml with new management interface.
- Added qpid-ha-status tool to read/set HA status.
Added:
qpid/branches/qpid-3603-2/qpid/cpp/src/ha.mk (contents, props changed)
- copied, changed from r1233629,
qpid/branches/qpid-3603-2/qpid/tools/setup.py
qpid/branches/qpid-3603-2/qpid/cpp/src/qpid/ha/
qpid/branches/qpid-3603-2/qpid/cpp/src/qpid/ha/HaBroker.cpp (with props)
qpid/branches/qpid-3603-2/qpid/cpp/src/qpid/ha/HaBroker.h (with props)
qpid/branches/qpid-3603-2/qpid/cpp/src/qpid/ha/HaPlugin.cpp (with props)
qpid/branches/qpid-3603-2/qpid/cpp/src/qpid/ha/Settings.h (with props)
qpid/branches/qpid-3603-2/qpid/cpp/src/qpid/ha/management-schema.xml
(with props)
qpid/branches/qpid-3603-2/qpid/tools/src/py/qpid-ha-status (with props)
Modified:
qpid/branches/qpid-3603-2/qpid/cpp/managementgen/qmfgen/schema.py
qpid/branches/qpid-3603-2/qpid/cpp/managementgen/qmfgen/templates/Class.h
qpid/branches/qpid-3603-2/qpid/cpp/src/Makefile.am
qpid/branches/qpid-3603-2/qpid/tools/setup.py
Modified: qpid/branches/qpid-3603-2/qpid/cpp/managementgen/qmfgen/schema.py
URL:
http://svn.apache.org/viewvc/qpid/branches/qpid-3603-2/qpid/cpp/managementgen/qmfgen/schema.py?rev=1233630&r1=1233629&r2=1233630&view=diff
==============================================================================
--- qpid/branches/qpid-3603-2/qpid/cpp/managementgen/qmfgen/schema.py (original)
+++ qpid/branches/qpid-3603-2/qpid/cpp/managementgen/qmfgen/schema.py Thu Jan
19 23:01:34 2012
@@ -1498,6 +1498,10 @@ class SchemaClass:
def genNamePackageLower (self, stream, variables):
stream.write (self.packageName.lower ())
+ def genPackageNameUpper (self, stream, variables):
+ up = "_".join(self.packageName.split("."))
+ stream.write (up.upper())
+
def genNameUpper (self, stream, variables):
stream.write (self.name.upper ())
@@ -1642,6 +1646,7 @@ class SchemaPackage:
def genNamespace (self, stream, variables):
stream.write("::".join(self.packageName.split(".")))
+
def genOpenNamespaces (self, stream, variables):
for item in self.packageName.split("."):
stream.write ("namespace %s {\n" % item)
Modified:
qpid/branches/qpid-3603-2/qpid/cpp/managementgen/qmfgen/templates/Class.h
URL:
http://svn.apache.org/viewvc/qpid/branches/qpid-3603-2/qpid/cpp/managementgen/qmfgen/templates/Class.h?rev=1233630&r1=1233629&r2=1233630&view=diff
==============================================================================
--- qpid/branches/qpid-3603-2/qpid/cpp/managementgen/qmfgen/templates/Class.h
(original)
+++ qpid/branches/qpid-3603-2/qpid/cpp/managementgen/qmfgen/templates/Class.h
Thu Jan 19 23:01:34 2012
@@ -1,6 +1,6 @@
/*MGEN:commentPrefix=//*/
-#ifndef _MANAGEMENT_/*MGEN:Class.NameUpper*/_
-#define _MANAGEMENT_/*MGEN:Class.NameUpper*/_
+#ifndef _MANAGEMENT_/*MGEN:Class.PackageNameUpper*/_/*MGEN:Class.NameUpper*/_
+#define _MANAGEMENT_/*MGEN:Class.PackageNameUpper*/_/*MGEN:Class.NameUpper*/_
//
// Licensed to the Apache Software Foundation (ASF) under one
Modified: qpid/branches/qpid-3603-2/qpid/cpp/src/Makefile.am
URL:
http://svn.apache.org/viewvc/qpid/branches/qpid-3603-2/qpid/cpp/src/Makefile.am?rev=1233630&r1=1233629&r2=1233630&view=diff
==============================================================================
--- qpid/branches/qpid-3603-2/qpid/cpp/src/Makefile.am (original)
+++ qpid/branches/qpid-3603-2/qpid/cpp/src/Makefile.am Thu Jan 19 23:01:34 2012
@@ -105,7 +105,8 @@ mgen_cmd=$(mgen_dir)/qmf-gen -m $(srcdir
-c $(srcdir)/managementgen.cmake -q -b -o qmf \
$(top_srcdir)/../specs/management-schema.xml \
$(srcdir)/qpid/acl/management-schema.xml \
- $(srcdir)/qpid/cluster/management-schema.xml
+ $(srcdir)/qpid/cluster/management-schema.xml \
+ $(srcdir)/qpid/ha/management-schema.xml
$(srcdir)/managementgen.mk $(mgen_broker_cpp) $(dist_qpid_management_HEADERS):
mgen.timestamp
mgen.timestamp: $(mgen_generator)
@@ -210,6 +211,7 @@ dmoduleexec_LTLIBRARIES =
cmoduleexec_LTLIBRARIES =
include cluster.mk
+include ha.mk
include acl.mk
include qmf.mk
include qmfc.mk
Copied: qpid/branches/qpid-3603-2/qpid/cpp/src/ha.mk (from r1233629,
qpid/branches/qpid-3603-2/qpid/tools/setup.py)
URL:
http://svn.apache.org/viewvc/qpid/branches/qpid-3603-2/qpid/cpp/src/ha.mk?p2=qpid/branches/qpid-3603-2/qpid/cpp/src/ha.mk&p1=qpid/branches/qpid-3603-2/qpid/tools/setup.py&r1=1233629&r2=1233630&rev=1233630&view=diff
==============================================================================
--- qpid/branches/qpid-3603-2/qpid/tools/setup.py (original)
+++ qpid/branches/qpid-3603-2/qpid/cpp/src/ha.mk Thu Jan 19 23:01:34 2012
@@ -1,4 +1,3 @@
-#!/usr/bin/env python
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
@@ -7,9 +6,9 @@
# 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
@@ -17,21 +16,17 @@
# specific language governing permissions and limitations
# under the License.
#
-from distutils.core import setup
+#
+# HA plugin makefile fragment, to be included in Makefile.am
+#
+
+dmoduleexec_LTLIBRARIES += ha.la
+
+ha_la_SOURCES = \
+ qpid/ha/HaPlugin.cpp \
+ qpid/ha/HaBroker.cpp \
+ qpid/ha/HaBroker.h \
+ qpid/ha/Settings.h
-setup(name="qpid-tools",
- version="0.15",
- author="Apache Qpid",
- author_email="[email protected]",
- scripts=["src/py/qpid-cluster",
- "src/py/qpid-cluster-store",
- "src/py/qpid-config",
- "src/py/qpid-printevents",
- "src/py/qpid-queue-stats",
- "src/py/qpid-route",
- "src/py/qpid-stat",
- "src/py/qpid-tool",
- "src/py/qmf-tool"],
- url="http://qpid.apache.org/",
- license="Apache Software License",
- description="Diagnostic and management tools for Apache Qpid brokers.")
+ha_la_LIBADD = libqpidbroker.la
+ha_la_LDFLAGS = $(PLUGINLDFLAGS)
Added: qpid/branches/qpid-3603-2/qpid/cpp/src/qpid/ha/HaBroker.cpp
URL:
http://svn.apache.org/viewvc/qpid/branches/qpid-3603-2/qpid/cpp/src/qpid/ha/HaBroker.cpp?rev=1233630&view=auto
==============================================================================
--- qpid/branches/qpid-3603-2/qpid/cpp/src/qpid/ha/HaBroker.cpp (added)
+++ qpid/branches/qpid-3603-2/qpid/cpp/src/qpid/ha/HaBroker.cpp Thu Jan 19
23:01:34 2012
@@ -0,0 +1,58 @@
+/*
+ *
+ * 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.
+ *
+ */
+#include "HaBroker.h"
+#include "qpid/broker/Broker.h"
+#include "qpid/management/ManagementAgent.h"
+#include "qmf/org/apache/qpid/ha/Package.h"
+
+namespace qpid {
+namespace ha {
+
+namespace _qmf = ::qmf::org::apache::qpid::ha;
+using namespace management;
+using namespace std;
+
+HaBroker::HaBroker(broker::Broker& b) : broker(b), mgmtObject(0) {
+ ManagementAgent* ma = broker.getManagementAgent();
+ if (ma) {
+ _qmf::Package packageInit(ma);
+ mgmtObject = new _qmf::HaBroker(ma, this);
+ // FIXME aconway 2011-11-11: Placeholder - initialize cluster role.
+ mgmtObject->set_status("solo");
+ ma->addObject(mgmtObject);
+ }
+}
+
+Manageable::status_t HaBroker::ManagementMethod (uint32_t methodId, Args&
args, string&) {
+ switch (methodId) {
+ case _qmf::HaBroker::METHOD_SETSTATUS: {
+ std::string status =
dynamic_cast<_qmf::ArgsHaBrokerSetStatus&>(args).i_status;
+ // FIXME aconway 2011-11-11: placeholder, validate & execute status
change.
+ mgmtObject->set_status(status);
+ break;
+ }
+ default:
+ return Manageable::STATUS_UNKNOWN_METHOD;
+ }
+ return Manageable::STATUS_OK;
+}
+
+}} // namespace qpid::ha
Propchange: qpid/branches/qpid-3603-2/qpid/cpp/src/qpid/ha/HaBroker.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: qpid/branches/qpid-3603-2/qpid/cpp/src/qpid/ha/HaBroker.cpp
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: qpid/branches/qpid-3603-2/qpid/cpp/src/qpid/ha/HaBroker.h
URL:
http://svn.apache.org/viewvc/qpid/branches/qpid-3603-2/qpid/cpp/src/qpid/ha/HaBroker.h?rev=1233630&view=auto
==============================================================================
--- qpid/branches/qpid-3603-2/qpid/cpp/src/qpid/ha/HaBroker.h (added)
+++ qpid/branches/qpid-3603-2/qpid/cpp/src/qpid/ha/HaBroker.h Thu Jan 19
23:01:34 2012
@@ -0,0 +1,57 @@
+#ifndef QPID_HA_BROKER_H
+#define QPID_HA_BROKER_H
+
+/*
+ *
+ * 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.
+ *
+ */
+
+#include "qmf/org/apache/qpid/ha/HaBroker.h"
+#include "qmf/org/apache/qpid/ha/ArgsHaBrokerSetStatus.h"
+
+#include "qpid/management/Manageable.h"
+
+namespace qpid {
+namespace broker {
+class Broker;
+}
+namespace ha {
+
+/**
+ * HA state and actions associated with a broker.
+ *
+ * THREAD SAFE: may be called in arbitrary broker IO or timer threads.
+ */
+class HaBroker : public management::Manageable
+{
+ public:
+ HaBroker(broker::Broker&);
+
+ // Implement Manageable.
+ qpid::management::ManagementObject* GetManagementObject() const { return
mgmtObject; }
+ management::Manageable::status_t ManagementMethod (
+ uint32_t methodId, management::Args& args, std::string& text);
+
+ private:
+ broker::Broker& broker;
+ qmf::org::apache::qpid::ha::HaBroker* mgmtObject;
+};
+}} // namespace qpid::ha
+
+#endif /*!QPID_HA_BROKER_H*/
Propchange: qpid/branches/qpid-3603-2/qpid/cpp/src/qpid/ha/HaBroker.h
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: qpid/branches/qpid-3603-2/qpid/cpp/src/qpid/ha/HaBroker.h
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: qpid/branches/qpid-3603-2/qpid/cpp/src/qpid/ha/HaPlugin.cpp
URL:
http://svn.apache.org/viewvc/qpid/branches/qpid-3603-2/qpid/cpp/src/qpid/ha/HaPlugin.cpp?rev=1233630&view=auto
==============================================================================
--- qpid/branches/qpid-3603-2/qpid/cpp/src/qpid/ha/HaPlugin.cpp (added)
+++ qpid/branches/qpid-3603-2/qpid/cpp/src/qpid/ha/HaPlugin.cpp Thu Jan 19
23:01:34 2012
@@ -0,0 +1,68 @@
+/*
+ *
+ * Copyright (c) 2006 The Apache Software Foundation
+ *
+ * Licensed 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.
+ *
+ */
+#include "HaBroker.h"
+#include "Settings.h"
+#include "qpid/Plugin.h"
+#include "qpid/Options.h"
+#include "qpid/broker/Broker.h"
+
+
+namespace qpid {
+namespace ha {
+
+using namespace std;
+
+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")
+ ;
+ }
+};
+
+struct HaPlugin : public Plugin {
+
+ Settings settings;
+ Options options;
+ auto_ptr<HaBroker> haBroker;
+
+ HaPlugin() : options(settings) {}
+
+ Options* getOptions() { return &options; }
+
+ void earlyInitialize(Plugin::Target& ) {}
+
+ void initialize(Plugin::Target& target) {
+ broker::Broker* broker = dynamic_cast<broker::Broker*>(&target);
+ if (broker && settings.enabled) {
+ QPID_LOG(info, "HA plugin enabled");
+ haBroker.reset(new ha::HaBroker(*broker));
+ } else
+ QPID_LOG(info, "HA plugin disabled");
+ }
+};
+
+static HaPlugin instance; // Static initialization.
+
+}} // namespace qpid::ha
Propchange: qpid/branches/qpid-3603-2/qpid/cpp/src/qpid/ha/HaPlugin.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: qpid/branches/qpid-3603-2/qpid/cpp/src/qpid/ha/HaPlugin.cpp
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: qpid/branches/qpid-3603-2/qpid/cpp/src/qpid/ha/Settings.h
URL:
http://svn.apache.org/viewvc/qpid/branches/qpid-3603-2/qpid/cpp/src/qpid/ha/Settings.h?rev=1233630&view=auto
==============================================================================
--- qpid/branches/qpid-3603-2/qpid/cpp/src/qpid/ha/Settings.h (added)
+++ qpid/branches/qpid-3603-2/qpid/cpp/src/qpid/ha/Settings.h Thu Jan 19
23:01:34 2012
@@ -0,0 +1,48 @@
+#ifndef QPID_HA_SETTINGS_H
+#define QPID_HA_SETTINGS_H
+
+/*
+ *
+ * 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.
+ *
+ */
+
+#include <string>
+
+namespace qpid {
+namespace ha {
+
+using std::string;
+
+/**
+ * Configurable settings for HA.
+ */
+class Settings
+{
+ public:
+ Settings() : enabled(false) {}
+ bool enabled;
+ string status; // primary, backup, solo
+ string clientUrl;
+ string brokerUrl;
+ string username, password, mechanism;
+ private:
+};
+}} // namespace qpid::ha
+
+#endif /*!QPID_HA_SETTINGS_H*/
Propchange: qpid/branches/qpid-3603-2/qpid/cpp/src/qpid/ha/Settings.h
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: qpid/branches/qpid-3603-2/qpid/cpp/src/qpid/ha/Settings.h
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: qpid/branches/qpid-3603-2/qpid/cpp/src/qpid/ha/management-schema.xml
URL:
http://svn.apache.org/viewvc/qpid/branches/qpid-3603-2/qpid/cpp/src/qpid/ha/management-schema.xml?rev=1233630&view=auto
==============================================================================
--- qpid/branches/qpid-3603-2/qpid/cpp/src/qpid/ha/management-schema.xml (added)
+++ qpid/branches/qpid-3603-2/qpid/cpp/src/qpid/ha/management-schema.xml Thu
Jan 19 23:01:34 2012
@@ -0,0 +1,34 @@
+<schema package="org.apache.qpid.ha">
+
+ <!--
+ 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.
+ -->
+
+ <!-- Monitor and control HA status of a broker. -->
+ <class name="HaBroker">
+ <property name="status" type="sstr" desc="HA statu: PRIMARY, BACKUP,
SOLO"/>
+
+ <method name="setStatus" desc="Set HA status: PRIMARY, BACKUP, SOLO">
+ <arg name="status" 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>
Propchange: qpid/branches/qpid-3603-2/qpid/cpp/src/qpid/ha/management-schema.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: qpid/branches/qpid-3603-2/qpid/cpp/src/qpid/ha/management-schema.xml
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange: qpid/branches/qpid-3603-2/qpid/cpp/src/qpid/ha/management-schema.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Modified: qpid/branches/qpid-3603-2/qpid/tools/setup.py
URL:
http://svn.apache.org/viewvc/qpid/branches/qpid-3603-2/qpid/tools/setup.py?rev=1233630&r1=1233629&r2=1233630&view=diff
==============================================================================
--- qpid/branches/qpid-3603-2/qpid/tools/setup.py (original)
+++ qpid/branches/qpid-3603-2/qpid/tools/setup.py Thu Jan 19 23:01:34 2012
@@ -31,7 +31,8 @@ setup(name="qpid-tools",
"src/py/qpid-route",
"src/py/qpid-stat",
"src/py/qpid-tool",
- "src/py/qmf-tool"],
+ "src/py/qmf-tool",
+ "src/py/qpid-ha-status"],
url="http://qpid.apache.org/",
license="Apache Software License",
description="Diagnostic and management tools for Apache Qpid brokers.")
Added: qpid/branches/qpid-3603-2/qpid/tools/src/py/qpid-ha-status
URL:
http://svn.apache.org/viewvc/qpid/branches/qpid-3603-2/qpid/tools/src/py/qpid-ha-status?rev=1233630&view=auto
==============================================================================
--- qpid/branches/qpid-3603-2/qpid/tools/src/py/qpid-ha-status (added)
+++ qpid/branches/qpid-3603-2/qpid/tools/src/py/qpid-ha-status Thu Jan 19
23:01:34 2012
@@ -0,0 +1,80 @@
+#!/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", "solo"]
+
+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
+ try:
+ self.qmf_broker = self.session.addBroker(broker)
+ except Exception, e:
+ raise Exception("Can't connect to %s: %s"%(broker,e))
+ 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())
Propchange: qpid/branches/qpid-3603-2/qpid/tools/src/py/qpid-ha-status
------------------------------------------------------------------------------
svn:executable = *
---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project: http://qpid.apache.org
Use/Interact: mailto:[email protected]