Author: tross
Date: Thu Feb 23 18:26:25 2012
New Revision: 1292880

URL: http://svn.apache.org/viewvc?rev=1292880&view=rev
Log:
QPID-2894 - Added ACL stats to qpid-stat and a reload-file action to 
qpid-config.
            Ported the ACL tests to use the faster API.

Modified:
    qpid/trunk/qpid/cpp/src/tests/acl.py
    qpid/trunk/qpid/tools/src/py/qpid-config
    qpid/trunk/qpid/tools/src/py/qpid-stat
    qpid/trunk/qpid/tools/src/py/qpidtoollibs/broker.py
    qpid/trunk/qpid/tools/src/py/qpidtoollibs/disp.py

Modified: qpid/trunk/qpid/cpp/src/tests/acl.py
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/tests/acl.py?rev=1292880&r1=1292879&r2=1292880&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/tests/acl.py (original)
+++ qpid/trunk/qpid/cpp/src/tests/acl.py Thu Feb 23 18:26:25 2012
@@ -48,8 +48,12 @@ class ACLTests(TestBase010):
         return connection.session(str(uuid4()))
 
     def reload_acl(self):
-        acl = self.qmf.getObjects(_class="acl")[0]    
-        return acl.reloadACLFile()
+        result = None
+        try:
+            self.broker_access.reloadAclFile()
+        except Exception, e:
+            result = str(e)
+        return result
 
     def get_acl_file(self):
         return ACLFile(self.config.defines.get("policy-file", 
"data_dir/policy.acl"))
@@ -59,7 +63,7 @@ class ACLTests(TestBase010):
         aclf.write('acl allow all all\n')
         aclf.close()
         TestBase010.setUp(self)
-        self.startQmf()
+        self.startBrokerAccess()
         self.reload_acl()
 
     def tearDown(self):
@@ -84,7 +88,7 @@ class ACLTests(TestBase010):
         aclf.close()        
         
         result = self.reload_acl()
-        if (result.text.find("format error",0,len(result.text)) != -1):
+        if (result):
             self.fail(result) 
         
         session = self.get_session('bob','bob')
@@ -111,7 +115,7 @@ class ACLTests(TestBase010):
         aclf.close()        
         
         result = self.reload_acl()
-        if (result.text.find("format error",0,len(result.text)) != -1):
+        if (result):
             self.fail(result)       
         
         session = self.get_session('bob','bob')
@@ -144,7 +148,7 @@ class ACLTests(TestBase010):
         aclf.close()        
         
         result = self.reload_acl()       
-        if (result.text.find("Insufficient tokens for acl 
definition",0,len(result.text)) == -1):
+        if (result.find("Insufficient tokens for acl 
definition",0,len(result)) == -1):
             self.fail("ACL Reader should reject the acl file due to empty 
group name")    
 
     def test_illegal_acl_formats(self):
@@ -157,7 +161,7 @@ class ACLTests(TestBase010):
         aclf.close()
         
         result = self.reload_acl()       
-        if (result.text.find("Unknown ACL permission",0,len(result.text)) == 
-1):
+        if (result.find("Unknown ACL permission",0,len(result)) == -1):
             self.fail(result)        
         
     def test_illegal_extension_lines(self):
@@ -173,13 +177,13 @@ class ACLTests(TestBase010):
         aclf.close()        
         
         result = self.reload_acl()       
-        if (result.text.find("contains an illegal 
extension",0,len(result.text)) == -1):
+        if (result.find("contains an illegal extension",0,len(result)) == -1):
             self.fail(result)
 
-        if (result.text.find("Non-continuation line must start with \"group\" 
or \"acl\"",0,len(result.text)) == -1):
+        if (result.find("Non-continuation line must start with \"group\" or 
\"acl\"",0,len(result)) == -1):
             self.fail(result)
 
-    def test_llegal_extension_lines(self):
+    def test_illegal_extension_lines(self):
         """
         Test proper extention lines
         """
@@ -192,7 +196,7 @@ class ACLTests(TestBase010):
         aclf.close()
          
         result = self.reload_acl()
-        if (result.text.find("ACL format error",0,len(result.text)) != -1):
+        if (result):
             self.fail(result)
 
     def test_user_realm(self):
@@ -207,7 +211,7 @@ class ACLTests(TestBase010):
         aclf.close()
          
         result = self.reload_acl()
-        if (result.text.find("Username 'bob' must contain a 
realm",0,len(result.text)) == -1):
+        if (result.find("Username 'bob' must contain a realm",0,len(result)) 
== -1):
             self.fail(result)
 
     def test_allowed_chars_for_username(self):
@@ -223,7 +227,7 @@ class ACLTests(TestBase010):
         aclf.close()
          
         result = self.reload_acl()
-        if (result.text.find("ACL format error",0,len(result.text)) != -1):
+        if (result):
             self.fail(result)
 
         aclf = self.get_acl_file()
@@ -232,7 +236,7 @@ class ACLTests(TestBase010):
         aclf.close() 
 
         result = self.reload_acl()
-        if (result.text.find("Username \"joe$h...@example.com\" contains 
illegal characters",0,len(result.text)) == -1):
+        if (result.find("Username \"joe$h...@example.com\" contains illegal 
characters",0,len(result)) == -1):
             self.fail(result)
 
    #=====================================
@@ -252,7 +256,7 @@ class ACLTests(TestBase010):
         result = self.reload_acl()       
         expected = "ding is not a valid value for 'policytype', possible 
values are one of" \
                    " { 'ring' 'ring_strict' 'flow_to_disk' 'reject' }"; 
-        if (result.text != expected): 
+        if (result.find(expected) == -1):
             self.fail(result)        
 
     def test_illegal_queue_size(self):
@@ -268,7 +272,7 @@ class ACLTests(TestBase010):
         result = self.reload_acl()       
         expected = "-1 is not a valid value for 'maxqueuesize', " \
                    "values should be between 0 and 9223372036854775807"; 
-        if (result.text != expected): 
+        if (result.find(expected) == -1):
             self.fail(result) 
 
         aclf = self.get_acl_file()
@@ -279,7 +283,7 @@ class ACLTests(TestBase010):
         result = self.reload_acl()       
         expected = "9223372036854775808 is not a valid value for 
'maxqueuesize', " \
                    "values should be between 0 and 9223372036854775807";
-        if (result.text != expected): 
+        if (result.find(expected) == -1):
             self.fail(result) 
 
 
@@ -296,7 +300,7 @@ class ACLTests(TestBase010):
         result = self.reload_acl()       
         expected = "-1 is not a valid value for 'maxqueuecount', " \
                    "values should be between 0 and 9223372036854775807"; 
-        if (result.text != expected): 
+        if (result.find(expected) == -1):
             self.fail(result) 
 
         aclf = self.get_acl_file()
@@ -307,7 +311,7 @@ class ACLTests(TestBase010):
         result = self.reload_acl()       
         expected = "9223372036854775808 is not a valid value for 
'maxqueuecount', " \
                    "values should be between 0 and 9223372036854775807";
-        if (result.text != expected): 
+        if (result.find(expected) == -1):
             self.fail(result) 
 
 
@@ -330,7 +334,7 @@ class ACLTests(TestBase010):
         aclf.close()        
         
         result = self.reload_acl()
-        if (result.text.find("format error",0,len(result.text)) != -1):
+        if (result):
             self.fail(result) 
         
         session = self.get_session('bob','bob')
@@ -436,7 +440,7 @@ class ACLTests(TestBase010):
         aclf.close()        
         
         result = self.reload_acl()
-        if (result.text.find("format error",0,len(result.text)) != -1):
+        if (result):
             self.fail(result)     
         
         session = self.get_session('bob','bob')
@@ -556,7 +560,7 @@ class ACLTests(TestBase010):
         aclf.close()        
         
         result = self.reload_acl()
-        if (result.text.find("format error",0,len(result.text)) != -1):
+        if (result):
             self.fail(result)        
         
         session = self.get_session('bob','bob')
@@ -687,7 +691,7 @@ class ACLTests(TestBase010):
         aclf.close()        
         
         result = self.reload_acl()
-        if (result.text.find("format error",0,len(result.text)) != -1):
+        if (result):
             self.fail(result)        
         
         session = self.get_session('bob','bob')
@@ -805,7 +809,7 @@ class ACLTests(TestBase010):
         aclf.close()
 
         result = self.reload_acl()
-        if (result.text.find("format error",0,len(result.text)) != -1):
+        if (result):
             self.fail(result)
 
         bob = BrokerAdmin(self.config.broker, "bob", "bob")
@@ -844,7 +848,7 @@ class ACLTests(TestBase010):
         aclf.close()        
         
         result = self.reload_acl()
-        if (result.text.find("format error",0,len(result.text)) != -1):
+        if (result):
             self.fail(result)        
         
         session = self.get_session('bob','bob')
@@ -892,7 +896,7 @@ class ACLTests(TestBase010):
         aclf.close()        
         
         result = self.reload_acl()
-        if (result.text.find("format error",0,len(result.text)) != -1):
+        if (result):
             self.fail(result)        
         
         session = self.get_session('bob','bob')
@@ -937,7 +941,7 @@ class ACLTests(TestBase010):
         aclf.close()        
         
         result = self.reload_acl()
-        if (result.text.find("format error",0,len(result.text)) != -1):
+        if (result):
             self.fail(result)        
         
         session = self.get_session('bob','bob')
@@ -988,7 +992,7 @@ class ACLTests(TestBase010):
         aclf.close()        
         
         result = self.reload_acl()
-        if (result.text.find("format error",0,len(result.text)) != -1):
+        if (result):
             self.fail(result)        
         
         session = self.get_session('bob','bob')
@@ -1056,7 +1060,7 @@ class ACLTests(TestBase010):
         aclf.close()
 
         result = self.reload_acl()
-        if (result.text.find("format error",0,len(result.text)) != -1):
+        if (result):
             self.fail(result)
 
         ts = None

Modified: qpid/trunk/qpid/tools/src/py/qpid-config
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/tools/src/py/qpid-config?rev=1292880&r1=1292879&r2=1292880&view=diff
==============================================================================
--- qpid/trunk/qpid/tools/src/py/qpid-config (original)
+++ qpid/trunk/qpid/tools/src/py/qpid-config Thu Feb 23 18:26:25 2012
@@ -42,7 +42,8 @@ Usage:  qpid-config [OPTIONS]
         qpid-config [OPTIONS] bind   <exchange-name> <queue-name> [binding-key]
                   <for type xml>     [-f -|filename]
                   <for type header>  [all|any] k1=v1 [, k2=v2...]
-        qpid-config [OPTIONS] unbind <exchange-name> <queue-name> 
[binding-key]"""
+        qpid-config [OPTIONS] unbind <exchange-name> <queue-name> [binding-key]
+        qpid-config [OPTIONS] reload-acl"""
 
 description = """
 Examples:
@@ -624,6 +625,15 @@ class BrokerManager:
             key = args[2]
         self.broker.unbind(ename, qname, key)
 
+    def ReloadAcl(self):
+        try:
+            self.broker.reloadAclFile()
+        except Exception, e:
+            if str(e).find('No object found') != -1:
+                print "Failed: ACL Module Not Loaded in Broker"
+            else:
+                raise
+
     def findById(self, items, id):
         for item in items:
             if item.name == id:
@@ -684,6 +694,8 @@ def main(argv=None):
                 bm.Bind(args[1:])
             elif cmd == "unbind":
                 bm.Unbind(args[1:])
+            elif cmd == "reload-acl":
+                bm.ReloadAcl()
             else:
                 Usage()
     except KeyboardInterrupt:

Modified: qpid/trunk/qpid/tools/src/py/qpid-stat
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/tools/src/py/qpid-stat?rev=1292880&r1=1292879&r2=1292880&view=diff
==============================================================================
--- qpid/trunk/qpid/tools/src/py/qpid-stat (original)
+++ qpid/trunk/qpid/tools/src/py/qpid-stat Thu Feb 23 18:26:25 2012
@@ -31,7 +31,7 @@ home = os.environ.get("QPID_TOOLS_HOME",
 sys.path.append(os.path.join(home, "python"))
 
 from qpidtoollibs.broker import BrokerAgent
-from qpidtoollibs.disp import Display, Header, Sorter
+from qpidtoollibs.disp import Display, Header, Sorter, YN, Commas, TimeLong
 
 
 class Config:
@@ -63,12 +63,13 @@ def OptionsAndArguments(argv):
     parser.add_option_group(group1)
 
     group2 = OptionGroup(parser, "Display Options")
-    group2.add_option("-g", "--general", help="Show General Broker Stats", 
action="store_const", const="g", dest="show")
-    group2.add_option("-c", "--connections", help="Show Connections",      
action="store_const", const="c", dest="show")
-    group2.add_option("-e", "--exchanges", help="Show Exchanges",          
action="store_const", const="e", dest="show")
-    group2.add_option("-q", "--queues", help="Show Queues",                
action="store_const", const="q", dest="show")
-    group2.add_option("-u", "--subscriptions", help="Show Subscriptions",  
action="store_const", const="u", dest="show")
-    group2.add_option("-m", "--memory", help="Show Broker Memory Stats",   
action="store_const", const="m", dest="show")
+    group2.add_option("-g", "--general", help="Show General Broker Stats",  
action="store_const", const="g",   dest="show")
+    group2.add_option("-c", "--connections", help="Show Connections",       
action="store_const", const="c",   dest="show")
+    group2.add_option("-e", "--exchanges", help="Show Exchanges",           
action="store_const", const="e",   dest="show")
+    group2.add_option("-q", "--queues", help="Show Queues",                 
action="store_const", const="q",   dest="show")
+    group2.add_option("-u", "--subscriptions", help="Show Subscriptions",   
action="store_const", const="u",   dest="show")
+    group2.add_option("-m", "--memory", help="Show Broker Memory Stats",    
action="store_const", const="m",   dest="show")
+    group2.add_option(      "--acl", help="Show Access Control List Stats", 
action="store_const", const="acl", dest="show")
     group2.add_option("-S", "--sort-by",  metavar="<colname>",                 
  help="Sort by column name")
     group2.add_option("-I", "--increasing", action="store_true", 
default=False,  help="Sort by increasing value (default = decreasing)")
     group2.add_option("-L", "--limit", type="int", default=50, metavar="<n>",  
  help="Limit output to n rows")
@@ -173,7 +174,7 @@ class BrokerManager:
             hosts.append(bestUrl)
         return hosts
 
-    def displayBroker(self, subs):
+    def displayBroker(self):
         disp = Display(prefix="  ")
         heads = []
         heads.append(Header('uptime', Header.DURATION))
@@ -227,7 +228,7 @@ class BrokerManager:
         disp.formattedTable('Aggregate Broker Statistics:', heads, rows)
 
 
-    def displayConn(self, subs):
+    def displayConn(self):
         disp = Display(prefix="  ")
         heads = []
         heads.append(Header('client-addr'))
@@ -260,10 +261,10 @@ class BrokerManager:
             dispRows = rows
         disp.formattedTable(title, heads, dispRows)
 
-    def displaySession(self, subs):
+    def displaySession(self):
         disp = Display(prefix="  ")
 
-    def displayExchange(self, subs):
+    def displayExchange(self):
         disp = Display(prefix="  ")
         heads = []
         heads.append(Header("exchange"))
@@ -299,7 +300,7 @@ class BrokerManager:
             dispRows = rows
         disp.formattedTable(title, heads, dispRows)
 
-    def displayQueues(self, subs):
+    def displayQueues(self):
         disp = Display(prefix="  ")
         heads = []
         heads.append(Header("queue"))
@@ -340,7 +341,7 @@ class BrokerManager:
         disp.formattedTable(title, heads, dispRows)
 
 
-    def displayQueue(self, subs, name):
+    def displayQueue(self, name):
         queue = self.broker.getQueue(name)
         if not queue:
             print "Queue '%s' not found" % name
@@ -399,7 +400,7 @@ class BrokerManager:
         disp.formattedTable("Statistics:", heads, rows)
 
 
-    def displaySubscriptions(self, subs):
+    def displaySubscriptions(self):
         disp = Display(prefix="  ")
         heads = []
         heads.append(Header("subscr"))
@@ -452,6 +453,21 @@ class BrokerManager:
                 rows.append([k, v])
         disp.formattedTable('Broker Memory Statistics:', heads, rows)
 
+    def displayAcl(self):
+        acl = self.broker.getAcl()
+        if not acl:
+            print "ACL Policy Module is not installed"
+            return
+        disp = Display(prefix="  ")
+        heads = [Header('Statistic'), Header('Value')]
+        rows = []
+        rows.append(['policy-file',       acl.policyFile])
+        rows.append(['enforcing',         YN(acl.enforcingAcl)])
+        rows.append(['has-transfer-acls', YN(acl.transferAcl)])
+        rows.append(['last-acl-load',     TimeLong(acl.lastAclLoad)])
+        rows.append(['acl-denials',       Commas(acl.aclDenyCount)])
+        disp.formattedTable('ACL Policy Statistics:', heads, rows)
+
     def getExchangeMap(self):
         exchanges = self.broker.getAllExchanges()
         emap = {}
@@ -480,21 +496,22 @@ class BrokerManager:
             cmap[c.address] = c
         return cmap
 
-    def displayMain(self, names, main, subs):
-        if   main == 'g': self.displayBroker(subs)
-        elif main == 'c': self.displayConn(subs)
-        elif main == 's': self.displaySession(subs)
-        elif main == 'e': self.displayExchange(subs)
+    def displayMain(self, names, main):
+        if   main == 'g': self.displayBroker()
+        elif main == 'c': self.displayConn()
+        elif main == 's': self.displaySession()
+        elif main == 'e': self.displayExchange()
         elif main == 'q':
             if len(names) >= 1:
-                self.displayQueue(subs, names[0])
+                self.displayQueue(names[0])
             else:
-                self.displayQueues(subs)
-        elif main == 'u': self.displaySubscriptions(subs)
-        elif main == 'm': self.displayMemory(subs)
+                self.displayQueues()
+        elif main == 'u':   self.displaySubscriptions()
+        elif main == 'm':   self.displayMemory()
+        elif main == 'acl': self.displayAcl()
 
     def display(self, names):
-        self.displayMain(names, config._types[0], config._types[1:])
+        self.displayMain(names, config._types)
 
 
 def main(argv=None):

Modified: qpid/trunk/qpid/tools/src/py/qpidtoollibs/broker.py
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/tools/src/py/qpidtoollibs/broker.py?rev=1292880&r1=1292879&r2=1292880&view=diff
==============================================================================
--- qpid/trunk/qpid/tools/src/py/qpidtoollibs/broker.py (original)
+++ qpid/trunk/qpid/tools/src/py/qpidtoollibs/broker.py Thu Feb 23 18:26:25 2012
@@ -188,6 +188,12 @@ class BrokerAgent(object):
   def getAllLinks(self):
     return self._getAllBrokerObjects(Link)
 
+  def getAcl(self):
+    objects = self._getAllBrokerObjects(Acl)
+    if len(objects) > 0:
+      return objects[0]
+    return None # Acl module not loaded
+
   def echo(self, sequence, body):
     """Request a response to test the path to the management broker"""
     pass
@@ -263,6 +269,9 @@ class BrokerAgent(object):
             'strict':      True}
     self._method('delete', args)
 
+  def reloadAclFile(self):
+    self._method('reloadACLFile', {}, 
"org.apache.qpid.acl:acl:org.apache.qpid.broker:broker:amqp-broker")
+
   def create(self, _type, name, properties, strict):
     """Create an object of the specified type"""
     pass
@@ -373,3 +382,6 @@ class Link(BrokerObject):
   def __init__(self, broker, values):
     BrokerObject.__init__(self, broker, values)
 
+class Acl(BrokerObject):
+  def __init__(self, broker, values):
+    BrokerObject.__init__(self, broker, values)

Modified: qpid/trunk/qpid/tools/src/py/qpidtoollibs/disp.py
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/tools/src/py/qpidtoollibs/disp.py?rev=1292880&r1=1292879&r2=1292880&view=diff
==============================================================================
--- qpid/trunk/qpid/tools/src/py/qpidtoollibs/disp.py (original)
+++ qpid/trunk/qpid/tools/src/py/qpidtoollibs/disp.py Thu Feb 23 18:26:25 2012
@@ -21,6 +21,31 @@
 
 from time import strftime, gmtime
 
+def YN(val):
+  if val:
+    return 'Y'
+  return 'N'
+
+def Commas(value):
+  sval = str(value)
+  result = ""
+  while True:
+    if len(sval) == 0:
+      return result
+    left = sval[:-3]
+    right = sval[-3:]
+    result = right + result
+    if len(left) > 0:
+      result = ',' + result
+    sval = left
+
+def TimeLong(value):
+  return strftime("%c", gmtime(value / 1000000000))
+
+def TimeShort(value):
+  return strftime("%X", gmtime(value / 1000000000))
+
+
 class Header:
   """ """
   NONE = 1
@@ -59,9 +84,9 @@ class Header:
           return 'Y'
         return ''
       if self.format == Header.TIME_LONG:
-         return strftime("%c", gmtime(value / 1000000000))
+         return TimeLong(value)
       if self.format == Header.TIME_SHORT:
-         return strftime("%X", gmtime(value / 1000000000))
+         return TimeShort(value)
       if self.format == Header.DURATION:
         if value < 0: value = 0
         sec = value / 1000000000
@@ -78,17 +103,7 @@ class Header:
         result += "%ds" % (sec % 60)
         return result
       if self.format == Header.COMMAS:
-        sval = str(value)
-        result = ""
-        while True:
-          if len(sval) == 0:
-            return result
-          left = sval[:-3]
-          right = sval[-3:]
-          result = right + result
-          if len(left) > 0:
-            result = ',' + result
-          sval = left
+        return Commas(value)
     except:
       return "?"
 
@@ -206,11 +221,6 @@ class Display:
     result += "%ds" % (sec % 60)
     return result
 
-  def YN(self, val):
-    if val:
-      return 'Y'
-    return 'N'
-
 class Sortable:
   """ """
   def __init__(self, row, sortIndex):



---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:commits-subscr...@qpid.apache.org

Reply via email to