Author: justi9
Date: 2007-11-13 15:11:26 -0500 (Tue, 13 Nov 2007)
New Revision: 1305
Removed:
mgmt/mint/model.py
Log:
Remove model.py as its contents went into mint/python/mint/__init__.py.
Deleted: mgmt/mint/model.py
===================================================================
--- mgmt/mint/model.py 2007-11-13 20:01:06 UTC (rev 1304)
+++ mgmt/mint/model.py 2007-11-13 20:11:26 UTC (rev 1305)
@@ -1,185 +0,0 @@
-from qpid.management import ManagedBroker
-from schema import *
-from time import sleep
-from datetime import *
-from sqlobject import *
-
-class Model:
- currentMethodId = None
- outstandingMethodCalls = None
- managedBrokers = None
-
- def __init__(self):
- self.currentMethodId = 1
- self.outstandingMethodCalls = dict()
- self.managedBrokers = dict()
-
- def getQueueByOriginalId(self, id, create=False):
- queue = None
- try:
- queue = MgmtQueue.selectBy(idOriginal=id)[:1][0]
- except IndexError:
- if (create): queue = MgmtQueue(idOriginal=id)
- return queue
-
- def getQueueByName(self, name, vhost, create=False):
- queue = None
- try:
- queue = MgmtQueue.selectBy(name=name, mgmtVhost=vhost)[:1][0]
- except IndexError:
- if (create): queue = MgmtQueue(name=name, mgmtVhost=vhost)
- return queue
-
- def getVhostByName(self, name, broker, create=False):
- vhost = None
- try:
- vhost = MgmtVhost.selectBy(name=name, mgmtBroker=broker)[:1][0]
- except IndexError:
- if (create): vhost = MgmtVhost(name=name, mgmtBroker=broker)
- return vhost
-
- def getVhostByOriginalId(self, id, create=False):
- vhost = None
- try:
- vhost = MgmtVhost.selectBy(idOriginal=id)[:1][0]
- except IndexError:
- if (create): vhost = MgmtVhost(idOriginal=id)
- return vhost
-
- def getBrokerByPort(self, port, system, create=False):
- broker = None
- try:
- broker = MgmtBroker.selectBy(port=port, mgmtSystem=system)[:1][0]
- except IndexError:
- if (create): broker = MgmtBroker(port=port, mgmtSystem=system)
- return broker
-
- def getBrokerByOriginalId(self, id, create=False):
- broker = None
- try:
- broker = MgmtBroker.selectBy(idOriginal=id)[:1][0]
- except IndexError:
- if (create): broker = MgmtBroker(idOriginal=id)
- return broker
-
- def getSystemByOriginalId(self, id, create=False):
- system = None
- try:
- system = MgmtSystem.selectBy(idOriginal=id)[:1][0]
- except IndexError:
- if (create): system = MgmtSystem(idOriginal=id)
- return system
-
- def sanitizeDict(self, d):
- for k in d.iterkeys():
- if (k.endswith("Id")):
- d[self.convertKey(k)] = d.pop(k)
- elif (k == "id"):
- d[self.convertKey(k)] = d.pop(k)
- for k in d.iterkeys():
- if (k.endswith("Ref")):
- d[self.convertKey(k)] = d.pop(k)
- return d
-
- def convertKey(self, k):
- if (k == "id"):
- return k + "Original"
- if (k.endswith("Id")):
- return k + "ent"
- elif (k.endswith("Ref")):
- oldK = k
- k = k[0].upper() + k[1:]
- return "mgmt" + k.replace("Ref", "ID")
-
- def configCallback(self, broker, objectName, list, timestamps):
- print "\nCONFIG---------------------------------------------------"
- print "broker=" + broker
- print objectName
- print list
- result = None
- d = self.sanitizeDict(dict(list))
- d["managedBroker"] = self.managedBrokers[broker]
- print d
-
- d["recTime"] = datetime.fromtimestamp(timestamps[0]/1000000000)
- d["creationTime"] = datetime.fromtimestamp(timestamps[1]/1000000000)
- if (objectName == "queue"):
- print "* QUEUE"
- queue = self.getQueueByName(d["name"],
self.getVhostByOriginalId(d.pop(self.convertKey("vhostRef"))), True)
- queue.set(**d)
- print "queue id = %d" % (queue.id)
- result = queue
- elif (objectName == "vhost"):
- print "* VHOST"
- vhost = self.getVhostByName(d["name"],
self.getBrokerByOriginalId(d.pop(self.convertKey("brokerRef"))), True)
- vhost.set(**d)
- print "vhost id = %d" % (vhost.id)
- result = vhost
- elif (objectName == "broker"):
- print "* BROKER"
- d.pop(self.convertKey("systemRef"))
- broker = self.getBrokerByPort(d["port"],
self.getSystemByOriginalId("0"), True)
- broker.set(**d)
- broker.sync()
- print "broker id = %d" % (broker.id)
- result = broker
- print "END CONFIG---------------------------------------------------\n"
- return result
-
- def instCallback(self, broker, objectName, list, timestamps):
- print "\nINST---------------------------------------------------"
- print "broker=" + broker
- print objectName
- print list
- result = None
- d = self.sanitizeDict(dict(list))
- if (objectName == "queue"):
- print "* QUEUE"
- queue = self.getQueueByOriginalId(d[self.convertKey("id")])
- d["mgmtQueue"] = queue.id
- d["recTime"] = datetime.fromtimestamp(timestamps[0]/1000000000)
- queueStats = MgmtQueueStats()
- queueStats.set(**d)
- d = dict()
- if (timestamps[2] != 0):
- d["deletionTime"] = datetime.fromtimestamp(timestamps[2]/1000000000)
- d["mgmtQueueStats"] = queueStats
- queue.set(**d)
- print queue.id
- result = queueStats
- elif (objectName == "vhost"):
- print "* VHOST"
- elif (objectName == "broker"):
- print "* BROKER"
- print "END INST---------------------------------------------------\n"
- return result
-
- def methodCallback(self, broker, methodId, errorNo, errorText, args):
- print "\nMETHOD---------------------------------------------------"
- print "broker=" + broker
- print "MethodId=%d" % (methodId)
- print "Error: %d %s" % (errorNo, errorText)
- print args
- method = self.outstandingMethodCalls.pop(methodId)
- method(errorText, args)
- print "END METHOD---------------------------------------------------\n"
-
- def addManagedBroker(self, host, port):
- broker = ManagedBroker(host=host, port=port)
- label = "%s:%d" % (host, port)
- self.managedBrokers[label] = broker
- broker.configListener(label, self.configCallback)
- broker.instrumentationListener (label, self.instCallback)
- broker.methodListener (label, self.methodCallback)
- broker.start()
- return label
-
- def registerCallback(self, callback):
- self.currentMethodId += 1
- methodId = self.currentMethodId
- self.outstandingMethodCalls[methodId] = callback
- return methodId
-
- def allSystems(self):
- return MgmtSystem.select()
-