[rhmessaging-commits] rhmessaging commits: r2121 - mgmt/mint/python/mint.

rhmessaging-commits at lists.jboss.org rhmessaging-commits at lists.jboss.org
Tue Jun 3 17:51:10 EDT 2008


Author: nunofsantos
Date: 2008-06-03 17:51:09 -0400 (Tue, 03 Jun 2008)
New Revision: 2121

Modified:
   mgmt/mint/python/mint/__init__.py
Log:
upon Schema Mismatch error, reattempt without missing attribute -- supports multiple missing attributes now

Modified: mgmt/mint/python/mint/__init__.py
===================================================================
--- mgmt/mint/python/mint/__init__.py	2008-06-03 20:29:57 UTC (rev 2120)
+++ mgmt/mint/python/mint/__init__.py	2008-06-03 21:51:09 UTC (rev 2121)
@@ -350,8 +350,8 @@
     self.debug = debug
 
   def log(self, message):
-    #if (self.debug):
-    print message
+    if (self.debug):
+      print message
     
   def sanitizeDict(self, d):
     if ("id" in d):
@@ -360,7 +360,7 @@
       d["clientConnectionRef"] = d.pop("connectionRef")
     #XXX FIX -- fix handling of field tables
     if ("arguments" in d):
-      print d.pop("arguments")
+      d.pop("arguments")
     #XXX FIX -- fix handling of field tables
     return d
 
@@ -430,8 +430,11 @@
       if (not obj):
         self.log("Couldn't find type %s id %s" % (objectName, d["idOriginal"]))
         return 
-      obj.set(**d)
-      obj.syncUpdate()
+
+      obj = self.updateObjWithDict(obj, d)
+      if (not obj):
+        return
+
     except TypeError, detail:
       self.log("TypeError: Schema mismatch: %s" % detail)
       return
@@ -464,62 +467,34 @@
         self.log("Couldn't find type %s id %s" % (objectName, d[self.convertIdKey("id")]))
         print "lion", classInfo, list
         return
-
+      
       origObjName = objectName[0].lower() + objectName[1:]
       d[origObjName] = obj
       objNameStats = eval("schema.%sStats" % (schema.schemaNameToClassMap[objectName].__name__))
       objStats = objNameStats.__new__(objNameStats)
       objStats.__init__()
-
+      
       if (not objStats):
         self.log("Couldn't find type %s id %s" % (objNameStats, d[self.convertIdKey("id")]))
         return
-
-      objStats.set(**d)
-      objStats.syncUpdate()
-    except TypeError, detail:
-      self.log("TypeError: Schema mismatch: %s" % detail)
-      detailString = detail.__str__()
-      errorString = "got an unexpected keyword argument "
-      index = detailString.index(errorString)
-      if (index >= 0):
-        # argument in dict is not in schema, so remove it and re-attempt
-        index += len(errorString)
-        missingAttrib = detailString[index:]
-        self.log("Reattempting without %s attribute" % missingAttrib)
-        d.pop(missingAttrib)
-        objStats.set(**d)
-        objStats.syncUpdate()
-      else:
+      
+      objStats = self.updateObjWithDict(objStats, d)
+      if (not objStats):
         return
-    except KeyError, detail:
-      self.log("KeyError: Schema mismatch: %s" % detail)
-      return 
 
-    try:
       d = dict()
+      d["statsPrev"] = obj.statsCurr
+      d["statsCurr"] = objStats
       if (timestamps[2] != 0):
         d["deletionTime"] = datetime.fromtimestamp(timestamps[2]/1000000000)
-      d["statsPrev"] = obj.statsCurr
-      d["statsCurr"] = objStats
 
-      obj.set(**d)
-      obj.syncUpdate()
+      obj = self.updateObjWithDict(obj, d)
+      if (not obj):
+        return
+
     except TypeError, detail:
       self.log("TypeError: Schema mismatch: %s" % detail)
-      detailString = detail.__str__()
-      errorString = "got an unexpected keyword argument "
-      index = detailString.index(errorString)
-      if (index >= 0):
-        # argument in dict is not in schema, so remove it and re-attempt
-        index += len(errorString)
-        missingAttrib = detailString[index:]
-        self.log("Reattempting without %s attribute" % missingAttrib)
-        d.pop(missingAttrib)
-        obj.set(**d)
-        obj.syncUpdate()
-      else:
-        return
+      return
     except KeyError, detail:
       self.log("KeyError: Schema mismatch: %s" % detail)
       return 
@@ -527,6 +502,37 @@
     self.log("END INST---------------------------------------------------\n")
     return objStats
 
+  def updateObjWithDict(self, obj, d):
+    updateDone = False
+    reattemptCount = 0
+    while not updateDone:
+      try:
+        obj.set(**d)
+        obj.syncUpdate()
+        updateDone = True
+        if (reattemptCount > 0):
+          self.log("Reattempts successful")
+      except TypeError, detail:
+        self.log("TypeError: Schema mismatch: %s" % detail)
+        detailString = detail.__str__()
+        errorString = "got an unexpected keyword argument "
+        index = detailString.index(errorString)
+        if (index >= 0):
+          # argument in dict is not in schema, so remove it and re-attempt
+          index += len(errorString)
+          missingAttrib = detailString[index:]
+          self.log("Reattempting without %s attribute" % missingAttrib)
+          d.pop(missingAttrib)
+          reattemptCount += 1
+        else:
+          # can't recover
+          self.log("Non-recoverable schema mismatch, information lost")
+          return None
+      except KeyError, detail:
+        self.log("KeyError: Schema mismatch: %s" % detail)
+        return None
+    return obj
+
   def methodCallback(self, brokerId, methodId, errorNo, errorText, args):
     self.log("\nMETHOD---------------------------------------------------")
     self.log("MethodId=%d" % (methodId))




More information about the rhmessaging-commits mailing list