diff options
| author | Alan Conway <aconway@apache.org> | 2010-04-06 15:28:39 +0000 |
|---|---|---|
| committer | Alan Conway <aconway@apache.org> | 2010-04-06 15:28:39 +0000 |
| commit | f2fa7ba12ad258ed925ef7daafb0fa57e340e0c9 (patch) | |
| tree | ea040c2e18ab5f07c2b2c1a534d4caf089fbc5f4 | |
| parent | 949a5cf0cb3605465ae115d809fe1919f1662500 (diff) | |
| download | qpid-python-f2fa7ba12ad258ed925ef7daafb0fa57e340e0c9.tar.gz | |
Added qpid-cluster-store tool to examine & modify cluster store status.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@931185 13f79535-47bb-0310-9956-ffa450edef68
| -rw-r--r-- | qpid/python/qpid/datatypes.py | 6 | ||||
| -rwxr-xr-x | qpid/tools/setup.py | 1 | ||||
| -rwxr-xr-x | qpid/tools/src/py/qpid-cluster-store | 73 |
3 files changed, 80 insertions, 0 deletions
diff --git a/qpid/python/qpid/datatypes.py b/qpid/python/qpid/datatypes.py index e4cbcb7f10..fc267c48ef 100644 --- a/qpid/python/qpid/datatypes.py +++ b/qpid/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/qpid/tools/setup.py b/qpid/tools/setup.py index 1f50428edc..96f8652296 100755 --- a/qpid/tools/setup.py +++ b/qpid/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/qpid/tools/src/py/qpid-cluster-store b/qpid/tools/src/py/qpid-cluster-store new file mode 100755 index 0000000000..4599f613d9 --- /dev/null +++ b/qpid/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()) |
