Author: nunofsantos
Date: 2007-11-13 13:26:00 -0500 (Tue, 13 Nov 2007)
New Revision: 1301
Modified:
mgmt/mint/model.py
mgmt/mint/schemaparser.py
Log:
include changes to MgmtSchema.xml, handle method calls with args
Modified: mgmt/mint/model.py
===================================================================
--- mgmt/mint/model.py 2007-11-13 17:28:13 UTC (rev 1300)
+++ mgmt/mint/model.py 2007-11-13 18:26:00 UTC (rev 1301)
@@ -7,16 +7,17 @@
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:
- queues = MgmtQueue.selectBy(idOriginal=id)[:1]
- queue = queues[0]
+ queue = MgmtQueue.selectBy(idOriginal=id)[:1][0]
except IndexError:
if (create): queue = MgmtQueue(idOriginal=id)
return queue
@@ -24,8 +25,7 @@
def getQueueByName(self, name, vhost, create=False):
queue = None
try:
- queues = MgmtQueue.selectBy(name=name, mgmtVhost=vhost)[:1]
- queue = queues[0]
+ queue = MgmtQueue.selectBy(name=name, mgmtVhost=vhost)[:1][0]
except IndexError:
if (create): queue = MgmtQueue(name=name, mgmtVhost=vhost)
return queue
@@ -33,8 +33,7 @@
def getVhostByName(self, name, broker, create=False):
vhost = None
try:
- vhosts = MgmtVhost.selectBy(name=name, mgmtBroker=broker)[:1]
- vhost = vhosts[0]
+ vhost = MgmtVhost.selectBy(name=name, mgmtBroker=broker)[:1][0]
except IndexError:
if (create): vhost = MgmtVhost(name=name, mgmtBroker=broker)
return vhost
@@ -42,8 +41,7 @@
def getVhostByOriginalId(self, id, create=False):
vhost = None
try:
- vhosts = MgmtVhost.selectBy(idOriginal=id)[:1]
- vhost = vhosts[0]
+ vhost = MgmtVhost.selectBy(idOriginal=id)[:1][0]
except IndexError:
if (create): vhost = MgmtVhost(idOriginal=id)
return vhost
@@ -51,8 +49,7 @@
def getBrokerByPort(self, port, system, create=False):
broker = None
try:
- brokers = MgmtBroker.selectBy(port=port, mgmtSystem=system)[:1]
- broker = brokers[0]
+ broker = MgmtBroker.selectBy(port=port, mgmtSystem=system)[:1][0]
except IndexError:
if (create): broker = MgmtBroker(port=port, mgmtSystem=system)
return broker
@@ -60,8 +57,7 @@
def getBrokerByOriginalId(self, id, create=False):
broker = None
try:
- brokers = MgmtBroker.selectBy(idOriginal=id)[:1]
- broker = brokers[0]
+ broker = MgmtBroker.selectBy(idOriginal=id)[:1][0]
except IndexError:
if (create): broker = MgmtBroker(idOriginal=id)
return broker
@@ -69,8 +65,7 @@
def getSystemByOriginalId(self, id, create=False):
system = None
try:
- systems = MgmtSystem.selectBy(idOriginal=id)[:1]
- system = systems[0]
+ system = MgmtSystem.selectBy(idOriginal=id)[:1][0]
except IndexError:
if (create): system = MgmtSystem(idOriginal=id)
return system
@@ -103,31 +98,30 @@
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"):
+ if (objectName == "queue"):
print "* QUEUE"
queue = self.getQueueByName(d["name"],
self.getVhostByOriginalId(d.pop(self.convertKey("vhostRef"))), True)
queue.set(**d)
- print queue.id
- print " -> " + queue.name
+ print "queue id = %d" % (queue.id)
result = queue
- elif (objectName == "Vhost"):
+ elif (objectName == "vhost"):
print "* VHOST"
vhost = self.getVhostByName(d["name"],
self.getBrokerByOriginalId(d.pop(self.convertKey("brokerRef"))), True)
vhost.set(**d)
- print vhost.id
- print " -> " + vhost.name
+ print "vhost id = %d" % (vhost.id)
result = vhost
- elif (objectName == "Broker"):
+ elif (objectName == "broker"):
print "* BROKER"
d.pop(self.convertKey("systemRef"))
- broker = self.getBrokerByPort(d["port"],
self.getSystemByOriginalId("123456789"), True)
+ broker = self.getBrokerByPort(d["port"],
self.getSystemByOriginalId("0"), True)
broker.set(**d)
- print broker.id
+ broker.sync()
+ print "broker id = %d" % (broker.id)
result = broker
print "END CONFIG---------------------------------------------------\n"
return result
@@ -139,7 +133,7 @@
print list
result = None
d = self.sanitizeDict(dict(list))
- if (objectName == "Queue"):
+ if (objectName == "queue"):
print "* QUEUE"
queue = self.getQueueByOriginalId(d[self.convertKey("id")])
d["mgmtQueue"] = queue.id
@@ -153,32 +147,39 @@
queue.set(**d)
print queue.id
result = queueStats
- elif (objectName == "Vhost"):
+ elif (objectName == "vhost"):
print "* VHOST"
- elif (objectName == "Broker"):
+ elif (objectName == "broker"):
print "* BROKER"
print "END INST---------------------------------------------------\n"
return result
- def methodCallback(self, broker, methodId, error, args):
+ def methodCallback(self, broker, methodId, errorNo, errorText, args):
print "\nMETHOD---------------------------------------------------"
print "broker=" + broker
- print methodId
- print error
+ print "MethodId=%d" % (methodId)
+ print "Error: %d %s" % (errorNo, errorText)
print args
- methodCallback = self.outstandingMethodCalls.pop(methodId)
- print methodCallback
- eval(methodCallback)
+ method = self.outstandingMethodCalls.pop(methodId)
+ method(errorText, args)
print "END METHOD---------------------------------------------------\n"
- def addManagedBroker(self, broker, label):
+ 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()
Modified: mgmt/mint/schemaparser.py
===================================================================
--- mgmt/mint/schemaparser.py 2007-11-13 17:28:13 UTC (rev 1300)
+++ mgmt/mint/schemaparser.py 2007-11-13 18:26:00 UTC (rev 1301)
@@ -130,7 +130,7 @@
# generate foreign keys
refName = self.attrNameFromDbColumn(refName, "Mgmt", "Ref")
# add missing attribute (not added correctly with SqlObject 0.7.7; may need to be
removed in later versions)
- self.pythonOutput += " _SO_class_%s = %s()\n" %
(self.style.pythonAttrToDBColumn(refName).capitalize(), refName)
+ self.pythonOutput += " _SO_class_%s = None\n" %
(self.style.pythonAttrToDBColumn(refName).capitalize())
self.additional += "\n%s.sqlmeta.addJoin(MultipleJoin('%s" %
(refName, name)
self.additional += "', joinMethodName='all%ss'))" %
(name.replace("Mgmt", ""))
@@ -139,6 +139,7 @@
if (schemaName != ""):
self.pythonOutput += " schemaId = %d\n" % int(schemaId)
self.pythonOutput += " schemaName = \"%s\"\n" % schemaName
+ self.pythonOutput += " managedBroker = None\n"
self.pythonOutput += " class sqlmeta:\n"
self.pythonOutput += " fromDatabase = True\n"
@@ -147,11 +148,22 @@
comment = ' """' + elem["@desc"] +
'"""\n'
else:
comment = ""
- self.pythonOutput += " def %s(self, managedBroker, model,
callbackMethod):\n" % (elem["@name"])
+
+ formalArgs = ", "
+ actualArgs = " actualArgs = dict()\n"
+ for arg in elem.query["arg"]:
+ formalArgs += "%s, " % (arg["@name"])
+ actualArgs += " actualArgs[\"%s\"] = %s\n" %
(arg["@name"], arg["@name"])
+ if (formalArgs != ", "):
+ formalArgs = formalArgs[:-2]
+ else:
+ formalArgs = ""
+ self.pythonOutput += " def %s(self, model, callbackMethod%s):\n" %
(elem["@name"], formalArgs)
self.pythonOutput += comment
+ self.pythonOutput += actualArgs
self.pythonOutput += " methodId =
model.registerCallback(callbackMethod)\n"
- self.pythonOutput += " managedBroker.method(self.schemaId, methodId,
self.schemaName, \"%s\", packageName=\"qpid\", " %
(elem["@name"])
- self.pythonOutput += "args=())\n"
+ self.pythonOutput += " self.managedBroker.method(methodId, self.idOriginal,
self.schemaName, \"%s\", " % (elem["@name"])
+ self.pythonOutput += "args=actualArgs, packageName=\"qpid\")\n"
def endClass(self, name=""):
if (self.additional != ""):
@@ -159,7 +171,7 @@
self.additional = ""
if (name != "" and not name.endswith("Stats")):
# add missing attribute (not added correctly with SqlObject 0.7.7; may need to be
removed in later versions)
- self.pythonOutput += " _SO_class_%s_stats = %sStats()\n" %
(self.style.pythonAttrToDBColumn(name).capitalize(), name)
+ self.pythonOutput += " _SO_class_%s_stats = None\n" %
(self.style.pythonAttrToDBColumn(name).capitalize())
def getCode(self):
return self.pythonOutput