You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by cc...@apache.org on 2007/12/14 21:22:32 UTC

svn commit: r604286 - in /incubator/qpid/trunk/qpid/python: mgmt-cli/main.py mgmt-cli/managementdata.py qpid/management.py

Author: cctrieloff
Date: Fri Dec 14 12:22:30 2007
New Revision: 604286

URL: http://svn.apache.org/viewvc?rev=604286&view=rev
Log:

patch from tross 
QPID-706

Added implementation for the "Call" command to invoke methods on management objects.
Fixed a bug in qpid/management.py caused by replies to methods with no arguments.


Modified:
    incubator/qpid/trunk/qpid/python/mgmt-cli/main.py
    incubator/qpid/trunk/qpid/python/mgmt-cli/managementdata.py
    incubator/qpid/trunk/qpid/python/qpid/management.py

Modified: incubator/qpid/trunk/qpid/python/mgmt-cli/main.py
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/python/mgmt-cli/main.py?rev=604286&r1=604285&r2=604286&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/python/mgmt-cli/main.py (original)
+++ incubator/qpid/trunk/qpid/python/mgmt-cli/main.py Fri Dec 14 12:22:30 2007
@@ -48,11 +48,12 @@
     print "    list                            - Print summary of existing objects by class"
     print "    list <className>                - Print list of objects of the specified class"
     print "    list <className> all            - Print contents of all objects of specified class"
+    print "    list <className> active         - Print contents of all non-deleted objects of specified class"
     print "    list <className> <list-of-IDs>  - Print contents of one or more objects"
     print "        list is space-separated, ranges may be specified (i.e. 1004-1010)"
     print "    call <ID> <methodName> [<args>] - Invoke a method on an object"
     print "    schema                          - Print summary of object classes seen on the target"
-    print "    schema [className]              - Print details of an object class"
+    print "    schema <className>              - Print details of an object class"
     print "    set time-format short           - Select short timestamp format (default)"
     print "    set time-format long            - Select long timestamp format"
     print "    quit or ^D                      - Exit the program"

Modified: incubator/qpid/trunk/qpid/python/mgmt-cli/managementdata.py
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/python/mgmt-cli/managementdata.py?rev=604286&r1=604285&r2=604286&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/python/mgmt-cli/managementdata.py (original)
+++ incubator/qpid/trunk/qpid/python/mgmt-cli/managementdata.py Fri Dec 14 12:22:30 2007
@@ -90,9 +90,16 @@
     finally:
       self.lock.release ()
 
-  def methodReply (self, broker, methodId, status, sText, args):
+  def methodReply (self, broker, sequence, status, sText, args):
     """ Callback for method-reply messages """
-    pass
+    self.lock.acquire ()
+    try:
+      line = "Call Result: " + self.methodsPending[sequence] + \
+             "  " + str (status) + " (" + sText + ")"
+      print line, args
+      del self.methodsPending[sequence]
+    finally:
+      self.lock.release ()
 
   def schemaHandler (self, context, className, configs, insts, methods, events):
     """ Callback for schema updates """
@@ -106,11 +113,13 @@
     self.broker.instrumentationListener (1,    self.dataHandler)
     self.broker.methodListener          (None, self.methodReply)
     self.broker.schemaListener          (None, self.schemaHandler)
-    self.lock   = Lock ()
-    self.tables = {}
-    self.schema = {}
-    self.baseId = 0
-    self.disp   = disp
+    self.lock           = Lock ()
+    self.tables         = {}
+    self.schema         = {}
+    self.baseId         = 0
+    self.disp           = disp
+    self.methodSeq      = 1
+    self.methodsPending = {}
     self.broker.start ()
 
   def close (self):
@@ -186,6 +195,11 @@
       for id in self.tables[className]:
         list.append (id - self.baseId)
 
+    elif tokens[0] == "active":
+      for id in self.tables[className]:
+        if self.tables[className][id][0][2] == 0:
+          list.append (id - self.baseId)
+
     else:
       for token in tokens:
         if token.find ("-") != -1:
@@ -362,10 +376,8 @@
       titles = ("Element", "Type", "Unit", "Access", "Notes", "Description")
       self.disp.table ("Schema for class '%s':" % className, titles, rows)
 
-      for method in self.schema[className][2]:
-        mname = method[0]
-        mdesc = method[1]
-        args  = method[2]
+      for mname in self.schema[className][2]:
+        (mdesc, args) = self.schema[className][2][mname]
         caption = "\nMethod '%s' %s" % (mname, self.notNone (mdesc))
         rows = []
         for arg in args:
@@ -398,6 +410,33 @@
         return className
     return None
 
+  def callMethod (self, userOid, methodName, args):
+    self.lock.acquire ()
+    methodOk = True
+    try:
+      className = self.getClassForId (userOid + self.baseId)
+      if className == None:
+        raise ValueError ()
+
+      schemaMethod = self.schema[className][2][methodName]
+      if len (args) != len (schemaMethod[1]):
+        print "Wrong number of method args: Need %d, Got %d" % (len (schemaMethod[1]), len (args))
+        raise ValueError ()
+
+      namedArgs = {}
+      for idx in range (len (args)):
+        namedArgs[schemaMethod[1][idx][0]] = args[idx]
+
+      self.methodSeq = self.methodSeq + 1
+      self.methodsPending[self.methodSeq] = methodName
+    except:
+      methodOk = False
+      print "Error in call syntax"
+    self.lock.release ()
+    if methodOk:
+      self.broker.method (self.methodSeq, userOid + self.baseId, className,
+                          methodName, namedArgs)
+
   def do_list (self, data):
     tokens = data.split ()
     if len (tokens) == 0:
@@ -414,4 +453,12 @@
       self.schemaTable (data)
 
   def do_call (self, data):
-    print "Not yet implemented"
+    tokens = data.split ()
+    if len (tokens) < 2:
+      print "Not enough arguments supplied"
+      return
+    
+    userOid    = long (tokens[0])
+    methodName = tokens[1]
+    args       = tokens[2:]
+    self.callMethod (userOid, methodName, args)

Modified: incubator/qpid/trunk/qpid/python/qpid/management.py
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/python/qpid/management.py?rev=604286&r1=604285&r2=604286&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/python/qpid/management.py (original)
+++ incubator/qpid/trunk/qpid/python/qpid/management.py Fri Dec 14 12:22:30 2007
@@ -108,7 +108,7 @@
 
     configs = []
     insts   = []
-    methods = []
+    methods = {}
     events  = []
 
     configs.append (("id", 4, "", "", 1, 1, None, None, None, None, None))
@@ -195,7 +195,7 @@
 
         arg = (name, type, dir, unit, desc, min, max, maxlen, default)
         args.append (arg)
-      methods.append ((mname, mdesc, args))
+      methods[mname] = (mdesc, args)
 
 
     self.schema[(className,'C')] = configs
@@ -297,18 +297,19 @@
       return
 
     (userSequence, className, methodName) = data
+    args = {}
 
     if status == 0:
       ms = self.metadata.schema[(className,'M')]
       arglist = None
-      for (mname, mdesc, margs) in ms:
+      for mname in ms:
+        (mdesc, margs) = ms[mname]
         if mname == methodName:
           arglist = margs
       if arglist == None:
         msg.complete ()
         return
 
-      args = {}
       for arg in arglist:
         if arg[2].find("O") != -1:
           args[arg[0]] = self.metadata.decodeValue (codec, arg[1])
@@ -379,7 +380,8 @@
     
     ms = self.metadata.schema[(className,'M')]
     arglist = None
-    for (mname, mdesc, margs) in ms:
+    for mname in ms:
+      (mdesc, margs) = ms[mname]
       if mname == methodName:
         arglist = margs
     if arglist == None: