[rhmessaging-commits] rhmessaging commits: r1330 - in mgmt/mint: python/mint and 1 other directory.

rhmessaging-commits at lists.jboss.org rhmessaging-commits at lists.jboss.org
Fri Nov 16 17:53:21 EST 2007


Author: nunofsantos
Date: 2007-11-16 17:53:21 -0500 (Fri, 16 Nov 2007)
New Revision: 1330

Modified:
   mgmt/mint/python/mint/__init__.py
   mgmt/mint/python/mint/schema.py
   mgmt/mint/schemaparser.py
Log:
refactored callback handlers to make them type generic

Modified: mgmt/mint/python/mint/__init__.py
===================================================================
--- mgmt/mint/python/mint/__init__.py	2007-11-16 21:59:23 UTC (rev 1329)
+++ mgmt/mint/python/mint/__init__.py	2007-11-16 22:53:21 UTC (rev 1330)
@@ -48,11 +48,8 @@
     self.connectedBrokers = dict()
     
   def sanitizeDict(self, d):
-    for k in d.iterkeys():
-      if (k == "id"):
-        d[self.convertIdKey(k)] = d.pop(k)
-      elif (k.endswith("Ref")):
-        d[self.convertRefKey(k)] = d.pop(k)
+    if ("id" in d):
+      d[self.convertIdKey("id")] = d.pop("id")
     return d
 
   def convertIdKey(self, k):
@@ -61,66 +58,58 @@
   def convertRefKey(self, k):
     return k.replace("Ref", "")
 
+  def findParentKey(self, d):
+    for key in d.keys():
+      if (key.endswith("Ref")):
+        return key
+    return ""
+    
   def configCallback(self, broker, objectName, list, timestamps):
     print "\nCONFIG---------------------------------------------------"
     print objectName
-    result = None
     d = self.sanitizeDict(dict(list))
     connectedBroker = self.connectedBrokers[broker]
     d["managedBroker"] = broker
     d["recTime"] = datetime.fromtimestamp(timestamps[0]/1000000000)
     d["creationTime"] = datetime.fromtimestamp(timestamps[1]/1000000000)
     print d
-
-    if (objectName == "queue"):
-      d["vhost"] = connectedBroker.getByOriginalId(schema.Vhost, d.pop(self.convertRefKey("vhostRef")))
-      queue = connectedBroker.getByOriginalId(schema.Queue, d["idOriginal"], create=True)
-      queue.set(**d)
-      result = queue
-    elif (objectName == "vhost"):
-      d["broker"] = connectedBroker.getByOriginalId(schema.Broker, d.pop(self.convertRefKey("brokerRef")))
-      vhost = connectedBroker.getByOriginalId(schema.Vhost, d["idOriginal"], create=True)
-      vhost.set(**d)
-      result = vhost
-    elif (objectName == "broker"):
-#FIX
-      d.pop(self.convertRefKey("systemRef"))
-#      d["system"] = connectedBroker.getByOriginalId(System, 0)
+    ###FIX
+    if (objectName == "broker"):
+      # needs special handling until schema is sendind info about systems
+      d.pop("systemRef")
+      # d["system"] = connectedBroker.getByOriginalId(System, 0)
       d["system"] = schema.System.selectBy(idOriginal=0)[:1][0]
       connectedBroker.objs.set(0, d["system"])
-#FIX
-      broker = connectedBroker.getByOriginalId(schema.Broker, d["idOriginal"], create=True)
-      broker.set(**d)
-      result = broker
-      print "END CONFIG---------------------------------------------------\n"
-    return result
+    else:
+      parentKey = self.findParentKey(d)
+      d[self.convertRefKey(parentKey)] = connectedBroker.getByOriginalId(schema.Vhost, d.pop(parentKey))
+    ###FIX
+    obj = connectedBroker.getByOriginalId(schema.schemaNameToClassMap[objectName], d["idOriginal"], create=True)
+    obj.set(**d)
+    print "END CONFIG---------------------------------------------------\n"
+    return obj
 
   def instCallback(self, broker, objectName, list, timestamps):
     print "\nINST---------------------------------------------------"
     print objectName
-    result = None
     d = self.sanitizeDict(dict(list))
     connectedBroker = self.connectedBrokers[broker]
     d["recTime"] = datetime.fromtimestamp(timestamps[0]/1000000000)
     print d
-    if (objectName == "queue"):
-      queue = connectedBroker.getByOriginalId(schema.Queue, d[self.convertIdKey("id")])
-      d["queue"] = queue
-      queueStats = schema.QueueStats()
-      queueStats.set(**d)
-      d = dict()
-      if (timestamps[2] != 0):
-        d["deletionTime"] = datetime.fromtimestamp(timestamps[2]/1000000000)
-      d["statsPrev"] = queue.stats
-      d["stats"] = queueStats
-      queue.set(**d)
-      result = queueStats
-    elif (objectName == "vhost"):
-      pass
-    elif (objectName == "broker"):
-      pass
+    obj = connectedBroker.getByOriginalId(schema.schemaNameToClassMap[objectName], d[self.convertIdKey("id")])
+    d[objectName] = obj
+    objNameStats = eval("schema.%sStats" % (schema.schemaNameToClassMap[objectName].__name__))
+    objStats = objNameStats.__new__(objNameStats)
+    objStats.__init__()
+    objStats.set(**d)
+    d = dict()
+    if (timestamps[2] != 0):
+      d["deletionTime"] = datetime.fromtimestamp(timestamps[2]/1000000000)
+    d["statsPrev"] = obj.stats
+    d["stats"] = objStats
+    obj.set(**d)
     print "END INST---------------------------------------------------\n"
-    return result
+    return objStats
 
   def methodCallback(self, broker, methodId, errorNo, errorText, args):
     print "\nMETHOD---------------------------------------------------"
@@ -129,9 +118,10 @@
     print "Args: "
     print args
     method = self.outstandingMethodCalls.pop(methodId)
-    method(errorText, args)
+    result = method(errorText, args)
     print "END METHOD---------------------------------------------------\n"
-
+    return result
+  
   def connectToBroker(self, host, port):
     broker = ManagedBroker(host=host, port=port)
     label = "%s:%d" % (host, port)

Modified: mgmt/mint/python/mint/schema.py
===================================================================
--- mgmt/mint/python/mint/schema.py	2007-11-16 21:59:23 UTC (rev 1329)
+++ mgmt/mint/python/mint/schema.py	2007-11-16 22:53:21 UTC (rev 1330)
@@ -45,25 +45,29 @@
     actualArgs = dict()
     actualArgs["clusterName"] = clusterName
     methodId = model.registerCallback(callbackMethod)
-    model.getConnectedBroker(managedBrokerLabel).method(methodId, self.idOriginal, classToSchemaNameMap[self.__class__.__name__], "joinCluster", args=actualArgs, packageName="qpid")
+    model.getConnectedBroker(managedBrokerLabel).method(methodId, self.idOriginal, \
+      classToSchemaNameMap[self.__class__.__name__], "joinCluster", args=actualArgs, packageName="qpid")
 
   def leaveCluster(self, model, managedBrokerLabel, callbackMethod):
     actualArgs = dict()
     methodId = model.registerCallback(callbackMethod)
-    model.getConnectedBroker(managedBrokerLabel).method(methodId, self.idOriginal, classToSchemaNameMap[self.__class__.__name__], "leaveCluster", args=actualArgs, packageName="qpid")
+    model.getConnectedBroker(managedBrokerLabel).method(methodId, self.idOriginal, \
+      classToSchemaNameMap[self.__class__.__name__], "leaveCluster", args=actualArgs, packageName="qpid")
 
   def echo(self, model, managedBrokerLabel, callbackMethod, sequence, body):
     actualArgs = dict()
     actualArgs["sequence"] = sequence
     actualArgs["body"] = body
     methodId = model.registerCallback(callbackMethod)
-    model.getConnectedBroker(managedBrokerLabel).method(methodId, self.idOriginal, classToSchemaNameMap[self.__class__.__name__], "echo", args=actualArgs, packageName="qpid")
+    model.getConnectedBroker(managedBrokerLabel).method(methodId, self.idOriginal, \
+      classToSchemaNameMap[self.__class__.__name__], "echo", args=actualArgs, packageName="qpid")
 
   def crash(self, model, managedBrokerLabel, callbackMethod):
     """Temporary test method to crash the broker"""
     actualArgs = dict()
     methodId = model.registerCallback(callbackMethod)
-    model.getConnectedBroker(managedBrokerLabel).method(methodId, self.idOriginal, classToSchemaNameMap[self.__class__.__name__], "crash", args=actualArgs, packageName="qpid")
+    model.getConnectedBroker(managedBrokerLabel).method(methodId, self.idOriginal, \
+      classToSchemaNameMap[self.__class__.__name__], "crash", args=actualArgs, packageName="qpid")
 
 class BrokerStats(SQLObject):
   idOriginal = BigIntCol(default=None)
@@ -105,14 +109,16 @@
     """Discard all messages on queue"""
     actualArgs = dict()
     methodId = model.registerCallback(callbackMethod)
-    model.getConnectedBroker(managedBrokerLabel).method(methodId, self.idOriginal, classToSchemaNameMap[self.__class__.__name__], "purge", args=actualArgs, packageName="qpid")
+    model.getConnectedBroker(managedBrokerLabel).method(methodId, self.idOriginal, \
+      classToSchemaNameMap[self.__class__.__name__], "purge", args=actualArgs, packageName="qpid")
 
   def increaseDiskSize(self, model, managedBrokerLabel, callbackMethod, pages):
     """Increase number of disk pages allocated for this queue"""
     actualArgs = dict()
     actualArgs["pages"] = pages
     methodId = model.registerCallback(callbackMethod)
-    model.getConnectedBroker(managedBrokerLabel).method(methodId, self.idOriginal, classToSchemaNameMap[self.__class__.__name__], "increaseDiskSize", args=actualArgs, packageName="qpid")
+    model.getConnectedBroker(managedBrokerLabel).method(methodId, self.idOriginal, \
+      classToSchemaNameMap[self.__class__.__name__], "increaseDiskSize", args=actualArgs, packageName="qpid")
 
 class QueueStats(SQLObject):
   idOriginal = BigIntCol(default=None)
@@ -223,12 +229,14 @@
   def close(self, model, managedBrokerLabel, callbackMethod):
     actualArgs = dict()
     methodId = model.registerCallback(callbackMethod)
-    model.getConnectedBroker(managedBrokerLabel).method(methodId, self.idOriginal, classToSchemaNameMap[self.__class__.__name__], "close", args=actualArgs, packageName="qpid")
+    model.getConnectedBroker(managedBrokerLabel).method(methodId, self.idOriginal, \
+      classToSchemaNameMap[self.__class__.__name__], "close", args=actualArgs, packageName="qpid")
 
   def detach(self, model, managedBrokerLabel, callbackMethod):
     actualArgs = dict()
     methodId = model.registerCallback(callbackMethod)
-    model.getConnectedBroker(managedBrokerLabel).method(methodId, self.idOriginal, classToSchemaNameMap[self.__class__.__name__], "detach", args=actualArgs, packageName="qpid")
+    model.getConnectedBroker(managedBrokerLabel).method(methodId, self.idOriginal, \
+      classToSchemaNameMap[self.__class__.__name__], "detach", args=actualArgs, packageName="qpid")
 
 class ClientStats(SQLObject):
   idOriginal = BigIntCol(default=None)
@@ -256,22 +264,26 @@
   def solicitAck(self, model, managedBrokerLabel, callbackMethod):
     actualArgs = dict()
     methodId = model.registerCallback(callbackMethod)
-    model.getConnectedBroker(managedBrokerLabel).method(methodId, self.idOriginal, classToSchemaNameMap[self.__class__.__name__], "solicitAck", args=actualArgs, packageName="qpid")
+    model.getConnectedBroker(managedBrokerLabel).method(methodId, self.idOriginal, \
+      classToSchemaNameMap[self.__class__.__name__], "solicitAck", args=actualArgs, packageName="qpid")
 
   def detach(self, model, managedBrokerLabel, callbackMethod):
     actualArgs = dict()
     methodId = model.registerCallback(callbackMethod)
-    model.getConnectedBroker(managedBrokerLabel).method(methodId, self.idOriginal, classToSchemaNameMap[self.__class__.__name__], "detach", args=actualArgs, packageName="qpid")
+    model.getConnectedBroker(managedBrokerLabel).method(methodId, self.idOriginal, \
+      classToSchemaNameMap[self.__class__.__name__], "detach", args=actualArgs, packageName="qpid")
 
   def resetLifespan(self, model, managedBrokerLabel, callbackMethod):
     actualArgs = dict()
     methodId = model.registerCallback(callbackMethod)
-    model.getConnectedBroker(managedBrokerLabel).method(methodId, self.idOriginal, classToSchemaNameMap[self.__class__.__name__], "resetLifespan", args=actualArgs, packageName="qpid")
+    model.getConnectedBroker(managedBrokerLabel).method(methodId, self.idOriginal, \
+      classToSchemaNameMap[self.__class__.__name__], "resetLifespan", args=actualArgs, packageName="qpid")
 
   def close(self, model, managedBrokerLabel, callbackMethod):
     actualArgs = dict()
     methodId = model.registerCallback(callbackMethod)
-    model.getConnectedBroker(managedBrokerLabel).method(methodId, self.idOriginal, classToSchemaNameMap[self.__class__.__name__], "close", args=actualArgs, packageName="qpid")
+    model.getConnectedBroker(managedBrokerLabel).method(methodId, self.idOriginal, \
+      classToSchemaNameMap[self.__class__.__name__], "close", args=actualArgs, packageName="qpid")
 
 class SessionStats(SQLObject):
   idOriginal = BigIntCol(default=None)
@@ -297,17 +309,20 @@
     actualArgs = dict()
     actualArgs["strength"] = strength
     methodId = model.registerCallback(callbackMethod)
-    model.getConnectedBroker(managedBrokerLabel).method(methodId, self.idOriginal, classToSchemaNameMap[self.__class__.__name__], "throttle", args=actualArgs, packageName="qpid")
+    model.getConnectedBroker(managedBrokerLabel).method(methodId, self.idOriginal, \
+      classToSchemaNameMap[self.__class__.__name__], "throttle", args=actualArgs, packageName="qpid")
 
   def stop(self, model, managedBrokerLabel, callbackMethod):
     actualArgs = dict()
     methodId = model.registerCallback(callbackMethod)
-    model.getConnectedBroker(managedBrokerLabel).method(methodId, self.idOriginal, classToSchemaNameMap[self.__class__.__name__], "stop", args=actualArgs, packageName="qpid")
+    model.getConnectedBroker(managedBrokerLabel).method(methodId, self.idOriginal, \
+      classToSchemaNameMap[self.__class__.__name__], "stop", args=actualArgs, packageName="qpid")
 
   def start(self, model, managedBrokerLabel, callbackMethod):
     actualArgs = dict()
     methodId = model.registerCallback(callbackMethod)
-    model.getConnectedBroker(managedBrokerLabel).method(methodId, self.idOriginal, classToSchemaNameMap[self.__class__.__name__], "start", args=actualArgs, packageName="qpid")
+    model.getConnectedBroker(managedBrokerLabel).method(methodId, self.idOriginal, \
+      classToSchemaNameMap[self.__class__.__name__], "start", args=actualArgs, packageName="qpid")
 
 class DestinationStats(SQLObject):
   idOriginal = BigIntCol(default=None)
@@ -351,7 +366,8 @@
   def close(self, model, managedBrokerLabel, callbackMethod):
     actualArgs = dict()
     methodId = model.registerCallback(callbackMethod)
-    model.getConnectedBroker(managedBrokerLabel).method(methodId, self.idOriginal, classToSchemaNameMap[self.__class__.__name__], "close", args=actualArgs, packageName="qpid")
+    model.getConnectedBroker(managedBrokerLabel).method(methodId, self.idOriginal, \
+      classToSchemaNameMap[self.__class__.__name__], "close", args=actualArgs, packageName="qpid")
 
 class ConsumerStats(SQLObject):
   idOriginal = BigIntCol(default=None)
@@ -364,14 +380,26 @@
   unackedMessagesHigh = IntCol(default=None)
 
 classToSchemaNameMap = dict()
+schemaNameToClassMap = dict()
 classToSchemaNameMap['System'] = 'system'
+schemaNameToClassMap['system'] = System
 classToSchemaNameMap['Broker'] = 'broker'
+schemaNameToClassMap['broker'] = Broker
 classToSchemaNameMap['Vhost'] = 'vhost'
+schemaNameToClassMap['vhost'] = Vhost
 classToSchemaNameMap['Queue'] = 'queue'
+schemaNameToClassMap['queue'] = Queue
 classToSchemaNameMap['Exchange'] = 'exchange'
+schemaNameToClassMap['exchange'] = Exchange
 classToSchemaNameMap['Binding'] = 'binding'
+schemaNameToClassMap['binding'] = Binding
 classToSchemaNameMap['Client'] = 'client'
+schemaNameToClassMap['client'] = Client
 classToSchemaNameMap['Session'] = 'session'
+schemaNameToClassMap['session'] = Session
 classToSchemaNameMap['Destination'] = 'destination'
+schemaNameToClassMap['destination'] = Destination
 classToSchemaNameMap['Producer'] = 'producer'
+schemaNameToClassMap['producer'] = Producer
 classToSchemaNameMap['Consumer'] = 'consumer'
+schemaNameToClassMap['consumer'] = Consumer

Modified: mgmt/mint/schemaparser.py
===================================================================
--- mgmt/mint/schemaparser.py	2007-11-16 21:59:23 UTC (rev 1329)
+++ mgmt/mint/schemaparser.py	2007-11-16 22:53:21 UTC (rev 1330)
@@ -14,6 +14,7 @@
     self.pythonOutput += "sqlhub.processConnection = conn\n\n"
     self.additional = ""
     self.final = "\nclassToSchemaNameMap = dict()\n"
+    self.final += "schemaNameToClassMap = dict()\n"
     # mapping between xml schema types and database column types
     # see xml/MintTypes.xml
     self.dataTypesMap = dict()
@@ -84,6 +85,7 @@
       self.generateForeignKeyAttrib("stats", statsPythonName)
       self.generateForeignKeyAttrib("statsPrev", statsPythonName)
       self.final += "classToSchemaNameMap['%s'] = '%s'\n" % (pythonName, schemaName)
+      self.final += "schemaNameToClassMap['%s'] = %s\n" % (schemaName, pythonName)
       
   def generateMethod(self, elem):
     if (elem["@desc"] != None):
@@ -103,7 +105,8 @@
     self.pythonOutput += comment
     self.pythonOutput += actualArgs
     self.pythonOutput += "    methodId = model.registerCallback(callbackMethod)\n"
-    self.pythonOutput += "    model.getConnectedBroker(managedBrokerLabel).method(methodId, self.idOriginal, classToSchemaNameMap[self.__class__.__name__], \"%s\", " % (elem["@name"])
+    self.pythonOutput += "    model.getConnectedBroker(managedBrokerLabel).method(methodId, self.idOriginal, \\\n"
+    self.pythonOutput += "      classToSchemaNameMap[self.__class__.__name__], \"%s\", " % (elem["@name"])
     self.pythonOutput += "args=actualArgs, packageName=\"qpid\")\n"
 
   def endClass(self):




More information about the rhmessaging-commits mailing list