summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Conway <aconway@apache.org>2010-04-06 15:28:39 +0000
committerAlan Conway <aconway@apache.org>2010-04-06 15:28:39 +0000
commite70e9f746a726130b848f45563b28a015b4e3fa2 (patch)
tree7ff6d65eca60a1d98eb6aa7b5c4ce28da8aeb6a5
parentb8606dba4f8edc95bf5af7ace7090ca5f9f796b7 (diff)
downloadqpid-python-e70e9f746a726130b848f45563b28a015b4e3fa2.tar.gz
Added qpid-cluster-store tool to examine & modify cluster store status.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@931185 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--python/qpid/datatypes.py6
-rwxr-xr-xtools/setup.py1
-rwxr-xr-xtools/src/py/qpid-cluster-store73
3 files changed, 80 insertions, 0 deletions
diff --git a/python/qpid/datatypes.py b/python/qpid/datatypes.py
index e4cbcb7f10..fc267c48ef 100644
--- a/python/qpid/datatypes.py
+++ b/python/qpid/datatypes.py
@@ -313,6 +313,12 @@ class UUID:
def __init__(self, bytes):
self.bytes = bytes
+ @staticmethod
+ def parse(str):
+ fields=str.split("-")
+ fields[4:5] = [fields[4][:4], fields[4][4:]]
+ return UUID(struct.pack("!LHHHHL", *[int(x,16) for x in fields]))
+
def __cmp__(self, other):
if isinstance(other, UUID):
return cmp(self.bytes, other.bytes)
diff --git a/tools/setup.py b/tools/setup.py
index 1f50428edc..96f8652296 100755
--- a/tools/setup.py
+++ b/tools/setup.py
@@ -24,6 +24,7 @@ setup(name="qpid-tools",
author="Apache Qpid",
author_email="dev@qpid.apache.org",
scripts=["src/py/qpid-cluster",
+ "src/py/qpid-cluster-store",
"src/py/qpid-config",
"src/py/qpid-printevents",
"src/py/qpid-queue-stats",
diff --git a/tools/src/py/qpid-cluster-store b/tools/src/py/qpid-cluster-store
new file mode 100755
index 0000000000..4599f613d9
--- /dev/null
+++ b/tools/src/py/qpid-cluster-store
@@ -0,0 +1,73 @@
+#!/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.
+#
+
+from qpid.datatypes import uuid4, UUID
+import optparse, os.path, sys
+
+op = optparse.OptionParser(
+ usage="usage: %prog [options] DATADIR",
+ description="View or modify cluster store status for broker with data-directory DATADIR")
+op.add_option("-d", "--display", default=False, action="store_true", help="display store status." )
+op.add_option("-c", "--mark-clean", default=False, action="store_true", help="mark the store as clean." )
+
+class ClusterStoreStatus:
+ """Load/save/display store status file"""
+
+ null_uuid=UUID('\0'*16)
+
+ def __init__(self, file):
+ self.file = file
+ self.read()
+
+ def read(self):
+ f = open(self.file)
+ try: self.cluster_id, self.shutdown_id = [UUID.parse(s) for s in f.readlines()]
+ finally: f.close()
+
+ def write(self):
+ f = open(self.file,"w")
+ try:
+ for u in [self.cluster_id, self.shutdown_id]: f.write(str(u)+"\n")
+ finally: f.close()
+
+ def status(self):
+ if (self.cluster_id == self.null_uuid): return "empty"
+ if (self.shutdown_id == self.null_uuid): return "dirty"
+ return "clean"
+
+ def __str__(self):
+ return "status: %s\ncluster-id: %s\nshutdown_id: %s" % (
+ self.status(), self.cluster_id, self.shutdown_id)
+
+ def mark_clean(self):
+ self.shutdown_id = uuid4()
+ self.write()
+
+def main():
+ opts, args = op.parse_args()
+ if len(args) != 1: op.error("incorrect number of arguments")
+ try: status = ClusterStoreStatus(args[0]+"/cluster/store.status")
+ except Exception,e: print e; return 1
+ if opts.display: print status
+ if opts.mark_clean: status.mark_clean(); print status
+ return 0
+
+if __name__ == "__main__": sys.exit(main())