[rhmessaging-commits] rhmessaging commits: r3907 - in mgmt/newdata/cumin/python/cumin: messaging and 1 other directory.

rhmessaging-commits at lists.jboss.org rhmessaging-commits at lists.jboss.org
Wed Apr 14 08:35:30 EDT 2010


Author: eallen
Date: 2010-04-14 08:35:29 -0400 (Wed, 14 Apr 2010)
New Revision: 3907

Modified:
   mgmt/newdata/cumin/python/cumin/main.py
   mgmt/newdata/cumin/python/cumin/messaging/queue.py
Log:
Added TopQueueTable back into the main Overview tab

Modified: mgmt/newdata/cumin/python/cumin/main.py
===================================================================
--- mgmt/newdata/cumin/python/cumin/main.py	2010-04-14 12:33:15 UTC (rev 3906)
+++ mgmt/newdata/cumin/python/cumin/main.py	2010-04-14 12:35:29 UTC (rev 3907)
@@ -14,6 +14,7 @@
 
 from config import *
 from model import *
+from objectselector import *
 from objecttask import *
 from sqladapter import *
 from table import *
@@ -168,6 +169,9 @@
     def __init__(self, app, name):
         super(OverviewView, self).__init__(app, name)
 
+        queues = TopQueueTable(app, "queues")
+        self.add_child(queues)
+
         # XXX
 
         #queues = messaging.queue.TopQueueSet(app, "queues")
@@ -188,3 +192,157 @@
 
 class ConfigurationNotice(Widget):
     pass
+
+class TopQueueAdapter(SqlAdapter):
+    def __init__(self, app, cls):
+        super(TopQueueAdapter, self).__init__(app, cls.sql_table)
+        self.cls = cls
+
+    """
+select 
+    "Queue"."name", 
+    ((sum("Queue"."msgTotalEnqueues") - 
+            sum(s."msgTotalEnqueues")) / (count(1)-1)) / 30 as avg_60, 
+    "Vhost"."_brokerRef_id", 
+    "Queue"."_id" 
+from "org.apache.qpid.broker"."Queue" 
+inner join (
+    select 
+        "Queue_samples"."_parent_id", 
+        "Queue_samples"."msgTotalEnqueues" 
+    from "org.apache.qpid.broker"."Queue_samples" 
+    where "Queue_samples"."_qmf_update_time" >= now() - interval '60 seconds') as s on "Queue"."_id" = s._parent_id 
+inner join "org.apache.qpid.broker"."Vhost" on "Queue"."_vhostRef_id" = "Vhost"."_id" 
+group by "Queue".name, "Queue"._id, "Vhost"."_brokerRef_id" having count(1) > 1 
+order by avg_60 desc 
+limit 5 offset 0
+    """
+
+    def init(self):
+        super(TopQueueAdapter, self).init()
+
+        name_col = self.table._columns_by_name["name"]
+        avg_over_last_60_seconds_col = """((sum("Queue"."msgTotalEnqueues") - 
+            sum(s."msgTotalEnqueues")) / (count(1)-1)) / 30 as avg_60"""
+        queue_id_col = self.table._columns_by_name["_id"]
+        vhostRef_col = self.table._columns_by_name["_vhostRef_id"]
+        vhost_table = self.app.rosemary.org_apache_qpid_broker.Vhost.sql_table
+        vhost_id_col = vhost_table._columns_by_name["_id"]
+        vhost_brokerRef_col = vhost_table._columns_by_name["_brokerRef_id"]
+
+        self.columns.append(name_col)
+        self.columns.append(avg_over_last_60_seconds_col)
+        self.columns.append(vhost_brokerRef_col)
+        self.columns.append(queue_id_col)
+
+        sub_query = "(%s) as s" % self.get_sub_query_text()
+        SqlInnerJoin(self.query, sub_query,
+                     queue_id_col, "s._parent_id")
+
+        SqlInnerJoin(self.query, vhost_table,
+             vhostRef_col, vhost_id_col)
+
+    def get_sub_query_text(self):
+        samples_table = self.cls.sql_samples_table
+        subquery = SqlQuery(samples_table)
+        parent_col = samples_table._columns_by_name["_parent_id"]
+        updated_col = samples_table._columns_by_name["_qmf_update_time"]
+        enqueues_col = samples_table._columns_by_name["msgTotalEnqueues"]
+
+        when = "now() - interval '60 seconds'"
+        SqlComparisonFilter(subquery, updated_col, when, ">=")
+
+        columns = list()
+        columns.append(parent_col)
+        columns.append(enqueues_col)
+
+        return subquery.emit(columns)
+
+    def get_data(self, values, options):
+        options.sort_column = "avg_60"
+        options.sort_ascending = False
+
+        options.group_column = "%s, %s, %s" % ("\"Queue\".name", "\"Queue\"._id", "\"Vhost\".\"_brokerRef_id\"")
+        having = SqlComparisonFilter(None, "count(1)", "1", ">")
+        options.group_having.append(having)
+
+        try:
+            data = super(TopQueueAdapter, self).get_data(values, options)
+        except:
+            data = []
+        return data
+
+    def get_sql_options(self, options):
+        return options
+
+class TopQueueTable(DataTable, Form):
+    def __init__(self, app, name):
+        cls = app.rosemary.org_apache_qpid_broker.Queue
+        adapter = TopQueueAdapter(app, cls)
+
+        super(TopQueueTable, self).__init__(app, name, adapter)
+
+        col = self.Name(app, "name")
+        self.add_column(col)
+
+        col = self.MsgEnqueuesColumn(app, cls.msgTotalEnqueues.name,
+                                    cls.msgTotalEnqueues)
+        self.add_column(col)
+
+        self.header = TopTableHeader(app, "header")
+        self.replace_child(self.header)
+
+        self.footer = TopTableFooter(app, "footer")
+        self.replace_child(self.footer)
+
+        self.update_enabled = True
+
+    def get_data_options(self, session):
+        options = SqlQueryOptions()
+
+        options.limit = 5
+        options.offset = 0
+
+        return options
+
+    def get_count(self, session):
+        # avoid extra sql call since we don't show the record count
+        return 0
+
+    class MsgEnqueuesColumn(DataTableColumn):
+        def render_header_content(self, session):
+            return "Recent Enqueues / sec"
+
+        def render_cell_content(self, session, record):
+            return "%.1f" % float(record[1])
+
+        def render_text_align(self, session):
+            # type is str: "count64"
+            return "right"
+
+    class Name(LinkColumn):
+        def render_header_content(self, session):
+            return "Name"
+
+        def render_cell_href(self, session, record):
+            branch = session.branch()
+
+            self.page.main.messaging.broker.id.set(branch, record[2])
+            self.page.main.messaging.broker.queue.id.set(branch, record[3])
+            self.page.main.messaging.broker.queue.view.show(branch)
+            return branch.marshal()
+
+        def render_cell_content(self, session, record):
+            return record[0]
+
+class TopTableHeader(TableHeader):
+    def __init__(self, app, name):
+        super(TopTableHeader, self).__init__(app, name)
+
+        self.font = Attribute(app, "font")
+        self.font.default = 0.9
+        self.add_attribute(self.font)
+
+class TopTableFooter(Widget):
+    def render(self, session):
+        return ""
\ No newline at end of file

Modified: mgmt/newdata/cumin/python/cumin/messaging/queue.py
===================================================================
--- mgmt/newdata/cumin/python/cumin/messaging/queue.py	2010-04-14 12:33:15 UTC (rev 3906)
+++ mgmt/newdata/cumin/python/cumin/messaging/queue.py	2010-04-14 12:35:29 UTC (rev 3907)
@@ -667,36 +667,3 @@
             self.task.invoke(session, queue, dest_queue, count)
             self.task.exit_with_redirect(session, queue)
 
-class TopQueueSet(TopTable):
-    def __init__(self, app, name):
-        super(TopQueueSet, self).__init__(app, name)
-
-        col = self.NameColumn(app, "name")
-        col.width = "60%"
-        self.add_column(col)
-
-        self.set_default_column(col)
-
-        col = self.EnqueuesColumn(app, "enqueues")
-        col.width = "35%"
-        col.align = "right"
-        self.add_column(col)
-
-    class NameColumn(TopTableColumn):
-        def render_title(self, session):
-            return "Name"
-
-        def render_content(self, session, data):
-            broker = Identifiable(data["broker_id"])
-            queue = Identifiable(data["id"])
-
-            branch = session.branch()
-            self.page.main.messaging.broker.object.set(branch, broker)
-            self.page.main.messaging.broker.queue.object.set(branch, queue)
-            self.page.main.messaging.broker.queue.show(branch)
-            return fmt_link \
-                (branch.marshal(), data["name"], link_title=data["name"])
-
-    class EnqueuesColumn(TopTableColumn):
-        def render_title(self, session):
-            return "Recent Enqueues"



More information about the rhmessaging-commits mailing list