[rhmessaging-commits] rhmessaging commits: r1643 - in mgmt/cumin/python: wooly and 1 other directory.

rhmessaging-commits at lists.jboss.org rhmessaging-commits at lists.jboss.org
Tue Feb 5 18:00:19 EST 2008


Author: justi9
Date: 2008-02-05 18:00:19 -0500 (Tue, 05 Feb 2008)
New Revision: 1643

Modified:
   mgmt/cumin/python/cumin/broker.py
   mgmt/cumin/python/cumin/broker.strings
   mgmt/cumin/python/cumin/brokergroup.py
   mgmt/cumin/python/cumin/brokergroup.strings
   mgmt/cumin/python/cumin/client.py
   mgmt/cumin/python/cumin/client.strings
   mgmt/cumin/python/cumin/exchange.py
   mgmt/cumin/python/cumin/exchange.strings
   mgmt/cumin/python/cumin/page.strings
   mgmt/cumin/python/cumin/queue.py
   mgmt/cumin/python/cumin/queue.strings
   mgmt/cumin/python/cumin/system.py
   mgmt/cumin/python/cumin/system.strings
   mgmt/cumin/python/cumin/widgets.py
   mgmt/cumin/python/wooly/tables.py
Log:
Fixes the problem where null values or sorted into places we didn't
want them.

Revamps sqltable to use a sql string from the module strings file,
rather than more complex thing I was doing before.



Modified: mgmt/cumin/python/cumin/broker.py
===================================================================
--- mgmt/cumin/python/cumin/broker.py	2008-02-05 00:10:22 UTC (rev 1642)
+++ mgmt/cumin/python/cumin/broker.py	2008-02-05 23:00:19 UTC (rev 1643)
@@ -20,11 +20,6 @@
     def __init__(self, app, name):
         super(BrokerSet, self).__init__(app, name)
 
-        self.table_sql = "broker_registration as b"
-
-        self.add_sql_column("id", "b.id")
-        self.add_sql_column("name", "b.name")
-
         self.ids = CheckboxIdColumn(app, "id")
         self.add_column(self.ids)
         self.add_form_parameter(self.ids)
@@ -484,7 +479,7 @@
         return "Brokers %s" % fmt_count(BrokerRegistration.select().count())
 
     class BrowserBrokers(BrokerSet):
-        def get_where_sql(self, session):
+        def render_sql_where(self, session, object):
             elems = list()
             group = self.parent.group.get(session)
             #profile = self.parent.profile.get(session)
@@ -494,16 +489,13 @@
                 subquery = \
                     "select 1 from broker_group_mapping " + \
                     "where broker_group_id = %i "  % group.id + \
-                    "and broker_registration_id = b.id"
+                    "and broker_registration_id = br.id"
 
                 elems.append("exists (%s)" % subquery)
 
             if elems:
                 return "where %s" % " and ".join(elems)
 
-        def render_none(self, session, model):
-            return fmt_none()
-
     def render_add_broker_href(self, session, model):
         branch = session.branch()
         self.frame().show_broker_add(branch)

Modified: mgmt/cumin/python/cumin/broker.strings
===================================================================
--- mgmt/cumin/python/cumin/broker.strings	2008-02-05 00:10:22 UTC (rev 1642)
+++ mgmt/cumin/python/cumin/broker.strings	2008-02-05 23:00:19 UTC (rev 1643)
@@ -1,3 +1,15 @@
+[BrokerSet.sql]
+select br.id, br.name
+from broker_registration as br
+{sql_where}
+{sql_orderby}
+{sql_limit}
+
+[BrokerSet.count_sql]
+select count(*)
+from broker_registration as br
+{sql_where}
+
 [BrokerSet.html]
 <form id="{id}" method="post" action="?">
   <!-- <select onchange="document.getElementById('{id}.submit').submit()"> -->

Modified: mgmt/cumin/python/cumin/brokergroup.py
===================================================================
--- mgmt/cumin/python/cumin/brokergroup.py	2008-02-05 00:10:22 UTC (rev 1642)
+++ mgmt/cumin/python/cumin/brokergroup.py	2008-02-05 23:00:19 UTC (rev 1643)
@@ -10,7 +10,16 @@
 
 strings = StringCatalog(__file__)
 
-class BrokerGroupSet(SQLObjectItemSet):
+class BrokerGroupSet(CuminTable):
+    def __init__(self, app, name):
+        super(BrokerGroupSet, self).__init__(app, name)
+
+        col = self.NameColumn(app, "name")
+        self.add_column(col)
+
+        #col = self.StatusColumn(app, "status")
+        #self.add_column(col)
+
     def get_title(self, session, model):
         return "Broker Groups %s" % fmt_count(BrokerGroup.select().count())
 
@@ -19,28 +28,16 @@
         self.frame().show_broker_group_add(branch)
         return branch.marshal()
 
-    def do_get_items(self, session, model):
-        return BrokerGroup.select()
+    class NameColumn(SqlTableColumn):
+        def get_title(self, session, model):
+            return "Name"
 
-    def render_item_link(self, session, group):
-        branch = session.branch()
-        self.frame().show_broker_group(branch, group).show_view(branch)
-        return fmt_olink(branch, group)
+        def render_content(self, session, data):
+            group = Identifiable(data["id"])
+            branch = session.branch()
+            self.app.model.broker_group.show(branch, group).show_view(branch)
+            return fmt_olink(branch, group, name=data["name"])
 
-    def render_item_config(self, session, group):
-        return group.brokers.count()
-
-    def render_item_status(self, session, group):
-        writer = Writer()
-        
-        for broker in group.brokers:
-            writer.write(fmt_ostatus(broker))
-
-        return writer.to_string()
-
-    def render_none(self, session, group):
-        return fmt_none()
-
 class BrokerGroupFrame(CuminFrame):
     def __init__(self, app, name):
         super(BrokerGroupFrame, self).__init__(app, name)
@@ -90,19 +87,14 @@
             return "Brokers %s" % \
                 fmt_count(self.get_item_count(session, group))
 
-        def get_where_sql(self, session):
-            # XXX ugh, get rid of None arg
-            group = self.frame().get_object(session, None)
+        def render_sql_where(self, session, group):
             subquery = \
                 "select 1 from broker_group_mapping " + \
                 "where broker_group_id = %i " % group.id + \
-                "and broker_registration_id = b.id"
+                "and broker_registration_id = br.id"
 
             return "where exists (%s)" % subquery
 
-        def render_none(self, session, model):
-            return fmt_none()
-
 class BrokerGroupForm(CuminForm):
     def __init__(self, app, name):
         super(BrokerGroupForm, self).__init__(app, name)

Modified: mgmt/cumin/python/cumin/brokergroup.strings
===================================================================
--- mgmt/cumin/python/cumin/brokergroup.strings	2008-02-05 00:10:22 UTC (rev 1642)
+++ mgmt/cumin/python/cumin/brokergroup.strings	2008-02-05 23:00:19 UTC (rev 1643)
@@ -1,3 +1,12 @@
+[BrokerGroupSet.sql]
+select bg.id, bg.name
+from broker_group as bg
+{sql_orderby}
+{sql_limit}
+
+[BrokerGroupSet.count_sql]
+select count(*) from broker_group
+
 [BrokerGroupSet.html]
 <ul class="actions">
   <li><a class="nav" href="{group_add_href}">Add Broker Group</a></li>
@@ -4,22 +13,18 @@
 </ul>
 
 <table class="mobjects">
-  <tr>
-    <th>Name</th>
-    <th>Brokers</th>
-    <th>Status</th>
-  </tr>
-
-  {items}
+  <thead>
+    <tr>
+      <th class="setnav" colspan="0">
+        <div class="rfloat">{page}</div>
+        {count}
+      </th>
+    </tr>
+    <tr>{headers}</tr>
+  </thead>
+  <tbody>{items}</tbody>
 </table>
 
-[BrokerGroupSet.item_html]
-<tr>
-  <td>{item_link}</td>
-  <td>{item_config}</td>
-  <td>{item_status}</td>
-</tr>
-
 [BrokerGroupView.html]
 {status}
 

Modified: mgmt/cumin/python/cumin/client.py
===================================================================
--- mgmt/cumin/python/cumin/client.py	2008-02-05 00:10:22 UTC (rev 1642)
+++ mgmt/cumin/python/cumin/client.py	2008-02-05 23:00:19 UTC (rev 1643)
@@ -15,26 +15,6 @@
     def __init__(self, app, name):
         super(ClientSet, self).__init__(app, name)
 
-        self.table_sql = "client as l"
-
-        self.add_sql_join("client_stats as c", "c.id", "l.stats_curr_id")
-        self.add_sql_join("client_stats as p", "p.id", "l.stats_prev_id")
-
-        self.add_sql_column("id", "l.id")
-        self.add_sql_column("addr", "l.address")
-        self.add_sql_column("bs",
-                            "(c.bytes_from_client - p.bytes_from_client)" +
-                            " / (extract(epoch from (c.rec_time - p.rec_time)) + 0.0001)");
-        self.add_sql_column("fs",
-                            "(c.frames_from_client - p.frames_from_client)" +
-                            " / (extract(epoch from (c.rec_time - p.rec_time)) + 0.0001)");
-        self.add_sql_column("br",
-                            "(c.bytes_to_client - p.bytes_to_client)" +
-                            " / (extract(epoch from (c.rec_time - p.rec_time)) + 0.0001)");
-        self.add_sql_column("fr",
-                            "(c.frames_to_client - p.frames_to_client)" +
-                            " / (extract(epoch from (c.rec_time - p.rec_time)) + 0.0001)");
-
         self.ids = CheckboxIdColumn(app, "id")
         self.add_column(self.ids)
 
@@ -71,20 +51,10 @@
     def get_unit_plural(self, session):
         return self.unit.get(session) == "b" and "Bytes" or "Frames"
 
-    def get_where_sql(self, session):
+    def render_sql_where(self, session, vhost):
         elems = list()
         elems.append("l.vhost_id = %(id)r")
-
-        phase = self.__phase.get(session)
-
-        if phase == "a":
-            elems.append("c.rec_time > now() - interval '10 minutes'")
-        elif phase == "i":
-            elems.append("(c.rec_time <= now() - interval '10 minutes'" +
-                         " and l.deletion_time is null)")
-        else:
-            elems.append("l.deletion_time is not null")
-        
+        elems.append(self.__phase.get_sql_constraint(session, vhost))
         return "where %s" % " and ".join(elems)
 
     def get_sql_values(self, session, vhost):
@@ -126,7 +96,7 @@
             #return fmt_link(branch.marshal(), client.sessions.count())
             return "XXX"
 
-    class SentColumn(SqlTableColumn):
+    class SentColumn(NullSortColumn):
         def get_title(self, session, vhost):
             return "%s Sent" % self.parent.get_unit_plural(session)
 
@@ -137,7 +107,7 @@
         def render_value(self, session, value):
             return fmt_rate(value, "", "sec")
 
-    class ReceivedColumn(SqlTableColumn):
+    class ReceivedColumn(NullSortColumn):
         def get_title(self, session, vhost):
             return "%s Received" % self.parent.get_unit_plural(session)
 
@@ -359,16 +329,6 @@
     def __init__(self, app, name):
         super(ClientSessionSet, self).__init__(app, name)
 
-        self.table_sql = "session as s"
-
-        self.add_sql_join("session_stats as c", "c.id", "s.stats_curr_id")
-        self.add_sql_join("session_stats as p", "p.id", "s.stats_curr_id")
-
-        self.add_sql_column("id", "s.id")
-        self.add_sql_column("name", "s.name")
-        self.add_sql_column("expires", "c.expire_time")
-        self.add_sql_column("status", "c.attached")
-
         self.ids = CheckboxIdColumn(app, "id")
         self.add_column(self.ids)
 
@@ -395,20 +355,10 @@
     def get_title(self, session, client):
         return "Sessions %s" % fmt_count(client.sessions.count())
 
-    def get_where_sql(self, session):
+    def render_sql_where(self, session, client):
         elems = list()
         elems.append("s.client_id = %(id)r")
-
-        phase = self.__phase.get(session)
-
-        if phase == "a":
-            elems.append("c.rec_time > now() - interval '10 minutes'")
-        elif phase == "i":
-            elems.append("(c.rec_time <= now() - interval '10 minutes'" +
-                         " and s.deletion_time is null)")
-        else:
-            elems.append("s.deletion_time is not null")
-        
+        elems.append(self.__phase.get_sql_constraint(session, client))
         return "where %s" % " and ".join(elems)
 
     def get_sql_values(self, session, client):

Modified: mgmt/cumin/python/cumin/client.strings
===================================================================
--- mgmt/cumin/python/cumin/client.strings	2008-02-05 00:10:22 UTC (rev 1642)
+++ mgmt/cumin/python/cumin/client.strings	2008-02-05 23:00:19 UTC (rev 1643)
@@ -1,3 +1,32 @@
+[ClientSet.sql]
+select
+  l.id,
+  l.address as addr,
+  (c.bytes_from_client - p.bytes_from_client)
+   / (extract(epoch from (c.rec_time - p.rec_time)) + 0.0001) as bs,
+  case when p.bytes_from_client is null then true else false end as bs_is_null,
+  (c.frames_from_client - p.frames_from_client)
+   / (extract(epoch from (c.rec_time - p.rec_time)) + 0.0001) as fs,
+  case when p.frames_from_client is null then true else false end as fs_is_null,
+  (c.bytes_to_client - p.bytes_to_client)
+   / (extract(epoch from (c.rec_time - p.rec_time)) + 0.0001) as br,
+  case when p.bytes_to_client is null then true else false end as br_is_null,
+  (c.frames_to_client - p.frames_to_client)
+   / (extract(epoch from (c.rec_time - p.rec_time)) + 0.0001) as fr,
+  case when p.frames_to_client is null then true else false end as fr_is_null
+from client as l
+left outer join client_stats as c on c.id = l.stats_curr_id
+left outer join client_stats as p on p.id = l.stats_prev_id
+{sql_where}
+{sql_orderby}
+{sql_limit}
+
+[ClientSet.count_sql]
+select count(*)
+from client as l
+left outer join client_stats as c on c.id = l.stats_curr_id
+{sql_where}
+
 [ClientSet.html]
 <form id="{id}" method="post" action="?">
   <div class="rfloat">{phase}</div>
@@ -128,6 +157,21 @@
 <h2>Bytes Received</h2>
 <div class="iblock chart">{received}</div>
 
+[ClientSessionSet.sql]
+select s.id, s.name, c.expire_time as expires, c.attached as status
+from session as s
+left outer join session_stats as c on c.id = s.stats_curr_id
+left outer join session_stats as p on p.id = s.stats_prev_id
+{sql_where}
+{sql_orderby}
+{sql_limit}
+
+[ClientSessionSet.count_sql]
+select count(*)
+from session as s
+left outer join session_stats as c on c.id = s.stats_curr_id
+{sql_where}
+
 [ClientSessionSet.html]
 <form id="{id}" method="post" action="?">
   <div class="rfloat">{phase}</div>

Modified: mgmt/cumin/python/cumin/exchange.py
===================================================================
--- mgmt/cumin/python/cumin/exchange.py	2008-02-05 00:10:22 UTC (rev 1642)
+++ mgmt/cumin/python/cumin/exchange.py	2008-02-05 23:00:19 UTC (rev 1643)
@@ -36,30 +36,6 @@
     def __init__(self, app, name):
         super(ExchangeSet, self).__init__(app, name)
 
-        self.table_sql = "exchange as e"
-
-        self.add_sql_join("exchange_stats as c", "c.id", "e.stats_curr_id")
-        self.add_sql_join("exchange_stats as p", "p.id", "e.stats_prev_id")
-
-        self.add_sql_column("id", "e.id")
-        self.add_sql_column("name", "e.name")
-        self.add_sql_column("producers", "c.producers")
-        self.add_sql_column("bindings", "c.bindings")
-        self.add_sql_column("mreceived",
-                            "(c.msg_receives - p.msg_receives)" +
-                            " / (extract(epoch from (c.rec_time - p.rec_time)) + 0.0001)");
-        self.add_sql_column("breceived",
-                            "(c.byte_receives - p.byte_receives)" +
-                            " / (extract(epoch from (c.rec_time - p.rec_time)) + 0.0001)");
-        self.add_sql_column("mrouted",
-                            "(c.msg_routes - p.msg_routes)" +
-                            " / (extract(epoch from (c.rec_time - p.rec_time)) + 0.0001)");
-        self.add_sql_column("brouted",
-                            "(c.byte_routes - p.byte_routes)" +
-                            " / (extract(epoch from (c.rec_time - p.rec_time)) + 0.0001)");
-        self.add_sql_column("mdropped", "c.msg_drops");
-        self.add_sql_column("bdropped", "c.byte_drops");
-
         col = self.NameColumn(app, "name")
         self.add_column(col)
 
@@ -92,20 +68,10 @@
     def get_title(self, session, vhost):
         return "Exchanges %s" % fmt_count(vhost.exchanges.count())
 
-    def get_where_sql(self, session):
+    def render_sql_where(self, session, vhost):
         elems = list()
         elems.append("e.vhost_id = %(id)r")
-
-        phase = self.phase.get(session)
-
-        if phase == "a":
-            elems.append("c.rec_time > now() - interval '10 minutes'")
-        elif phase == "i":
-            elems.append("(c.rec_time <= now() - interval '10 minutes'" +
-                         " and e.deletion_time is null)")
-        else:
-            elems.append("e.deletion_time is not null")
-        
+        elems.append(self.phase.get_sql_constraint(session, vhost))
         return "where %s" % " and ".join(elems)
 
     def get_sql_values(self, session, vhost):
@@ -147,7 +113,7 @@
             frame.show_view(branch).show_bindings(branch)
             return fmt_link(branch.marshal(), data["bindings"])
 
-    class ReceivedColumn(SqlTableColumn):
+    class ReceivedColumn(NullSortColumn):
         def get_title(self, session, object):
             return "%s Received" % self.parent.unit.get_brief_plural(session)
 
@@ -158,7 +124,7 @@
         def render_value(self, session, value):
             return fmt_rate(value, "", "sec")
 
-    class RoutedColumn(SqlTableColumn):
+    class RoutedColumn(NullSortColumn):
         def get_title(self, session, object):
             return "%s Routed" % self.parent.unit.get_brief_plural(session)
 

Modified: mgmt/cumin/python/cumin/exchange.strings
===================================================================
--- mgmt/cumin/python/cumin/exchange.strings	2008-02-05 00:10:22 UTC (rev 1642)
+++ mgmt/cumin/python/cumin/exchange.strings	2008-02-05 23:00:19 UTC (rev 1643)
@@ -4,6 +4,39 @@
   {item_content}
 </div>
 
+[ExchangeSet.sql]
+select
+  e.id,
+  e.name,
+  c.producers,
+  c.bindings,
+  (c.msg_receives - p.msg_receives)
+   / (extract(epoch from (c.rec_time - p.rec_time)) + 0.0001) as mreceived,
+  case when p.msg_receives is null then true else false end as mreceived_is_null,
+  (c.byte_receives - p.byte_receives)
+   / (extract(epoch from (c.rec_time - p.rec_time)) + 0.0001) as breceived,
+  case when p.byte_receives is null then true else false end as breceived_is_null,
+  (c.msg_routes - p.msg_routes)
+   / (extract(epoch from (c.rec_time - p.rec_time)) + 0.0001) as mrouted,
+  case when p.msg_routes is null then true else false end as mrouted_is_null,
+  (c.byte_routes - p.byte_routes)
+   / (extract(epoch from (c.rec_time - p.rec_time)) + 0.0001) as brouted,
+  case when p.byte_routes is null then true else false end as brouted_is_null,
+  c.msg_drops as mdropped,
+  c.byte_drops as bdropped
+from exchange as e
+left outer join exchange_stats as c on c.id = e.stats_curr_id
+left outer join exchange_stats as p on p.id = e.stats_prev_id
+{sql_where}
+{sql_orderby}
+{sql_limit}
+
+[ExchangeSet.count_sql]
+select count(*)
+from exchange as e
+left outer join exchange_stats as c on c.id = e.stats_curr_id
+{sql_where}
+
 [ExchangeSet.css]
 ul.ExchangeSet li:before {
   content: url(resource?name=exchange-20.png);

Modified: mgmt/cumin/python/cumin/page.strings
===================================================================
--- mgmt/cumin/python/cumin/page.strings	2008-02-05 00:10:22 UTC (rev 1642)
+++ mgmt/cumin/python/cumin/page.strings	2008-02-05 23:00:19 UTC (rev 1643)
@@ -562,7 +562,7 @@
 #head {
   padding: 0;
   background-color: #666;
-  border-bottom: 2px solid #999;
+  border-bottom: 1px solid #999;
   border-top: 3px solid #000;
   color: #ddd;
 }
@@ -659,6 +659,13 @@
   content: "";
 }
 
+#trans {
+  padding: 0;
+  marging: 0;
+  border-top: 1px solid #bbb;
+  border-bottom: 1px solid #ddd;
+}
+
 [MainFrame.javascript]
 function updateActions(id, model) {
     var pcount = model.invocations.pending;
@@ -718,6 +725,7 @@
   </div>
   <!-- <a id="logo" href="{href}"><img src="resource?name=rhm-32x14.png"/></a> -->
 </div>
+<div id="trans"></div>
 <div id="body">{mode}</div>
 <div id="foot"/>
 

Modified: mgmt/cumin/python/cumin/queue.py
===================================================================
--- mgmt/cumin/python/cumin/queue.py	2008-02-05 00:10:22 UTC (rev 1642)
+++ mgmt/cumin/python/cumin/queue.py	2008-02-05 23:00:19 UTC (rev 1643)
@@ -20,32 +20,6 @@
     def __init__(self, app, name):
         super(QueueSet, self).__init__(app, name)
 
-        self.table_sql = "queue as q"
-
-        self.add_sql_join("queue_stats as c", "c.id", "q.stats_curr_id")
-        self.add_sql_join("queue_stats as p", "p.id", "q.stats_prev_id")
-
-        self.add_sql_column("id", "q.id")
-        self.add_sql_column("name", "q.name")
-        self.add_sql_column("consumers", "c.consumers")
-        self.add_sql_column("bindings", "c.bindings")
-        self.add_sql_column("menqueued",
-                            "(c.msg_total_enqueues - p.msg_total_enqueues)" +
-                            " / (extract(epoch from (c.rec_time - p.rec_time)) + 0.0001)");
-        self.add_sql_column("benqueued",
-                            "(c.byte_total_enqueues - p.byte_total_enqueues)" +
-                            " / (extract(epoch from (c.rec_time - p.rec_time)) + 0.0001)");
-        self.add_sql_column("mdequeued",
-                            "(c.msg_total_dequeues - p.msg_total_dequeues)" +
-                            " / (extract(epoch from (c.rec_time - p.rec_time)) + 0.0001)");
-        self.add_sql_column("bdequeued",
-                            "(c.byte_total_dequeues - p.byte_total_dequeues)" +
-                            " / (extract(epoch from (c.rec_time - p.rec_time)) + 0.0001)");
-        self.add_sql_column("mdepth", "c.msg_depth")
-        self.add_sql_column("bdepth", "c.byte_depth")
-        self.add_sql_column("mdepthaccel", "1")
-        self.add_sql_column("bdepthaccel", "1")
-
         self.ids = CheckboxIdColumn(app, "id")
         self.add_column(self.ids)
 
@@ -86,20 +60,10 @@
     def get_title(self, session, vhost):
         return "Queues %s" % fmt_count(vhost.queues.count())
 
-    def get_where_sql(self, session):
+    def render_sql_where(self, session, vhost):
         elems = list()
         elems.append("q.vhost_id = %(id)r")
-
-        phase = self.phase.get(session)
-
-        if phase == "a":
-            elems.append("c.rec_time > now() - interval '10 minutes'")
-        elif phase == "i":
-            elems.append("(c.rec_time <= now() - interval '10 minutes'" +
-                         " and q.deletion_time is null)")
-        else:
-            elems.append("q.deletion_time is not null")
-        
+        elems.append(self.phase.get_sql_constraint(session, vhost))
         return "where %s" % " and ".join(elems)
 
     def get_sql_values(self, session, vhost):
@@ -153,7 +117,7 @@
             frame.show_view(branch).show_bindings(branch)
             return fmt_link(branch.marshal(), data["bindings"])
 
-    class EnqueuedColumn(SqlTableColumn):
+    class EnqueuedColumn(NullSortColumn):
         def get_title(self, session, object):
             return "%s Enqueued" % self.parent.unit.get_brief_plural(session)
 
@@ -164,7 +128,7 @@
         def render_value(self, session, value):
             return fmt_rate(value, "", "sec")
 
-    class DequeuedColumn(SqlTableColumn):
+    class DequeuedColumn(NullSortColumn):
         def get_title(self, session, object):
             return "%s Dequeued" % self.parent.unit.get_brief_plural(session)
 

Modified: mgmt/cumin/python/cumin/queue.strings
===================================================================
--- mgmt/cumin/python/cumin/queue.strings	2008-02-05 00:10:22 UTC (rev 1642)
+++ mgmt/cumin/python/cumin/queue.strings	2008-02-05 23:00:19 UTC (rev 1643)
@@ -1,3 +1,38 @@
+[QueueSet.sql]
+select
+  q.id,
+  q.name,
+  c.consumers,
+  c.bindings,
+  (c.msg_total_enqueues - p.msg_total_enqueues)
+   / (extract(epoch from (c.rec_time - p.rec_time)) + 0.0001) as menqueued,
+  case when p.msg_total_enqueues is null then true else false end as menqueued_is_null,
+  (c.byte_total_enqueues - p.byte_total_enqueues)
+   / (extract(epoch from (c.rec_time - p.rec_time)) + 0.0001) as benqueued,
+  case when p.byte_total_enqueues is null then true else false end as benqueued_is_null,
+  (c.msg_total_dequeues - p.msg_total_dequeues)
+   / (extract(epoch from (c.rec_time - p.rec_time)) + 0.0001) as mdequeued,
+  case when p.msg_total_dequeues is null then true else false end as mdequeued_is_null,
+  (c.byte_total_dequeues - p.byte_total_dequeues)
+   / (extract(epoch from (c.rec_time - p.rec_time)) + 0.0001) as bdequeued,
+  case when p.byte_total_dequeues is null then true else false end as bdequeued_is_null,
+  c.msg_depth as mdepth,
+  c.byte_depth as bdepth,
+  1 as mdepthaccel,
+  1 as bdepthaccel
+from queue as q
+left outer join queue_stats as c on c.id = q.stats_curr_id
+left outer join queue_stats as p on p.id = q.stats_prev_id
+{sql_where}
+{sql_orderby}
+{sql_limit}
+
+[QueueSet.count_sql]
+select count(*)
+from queue as q
+left outer join queue_stats as c on c.id = q.stats_curr_id
+{sql_where}
+
 [QueueSet.html]
 <form id="{id}" method="post" action="?">
   <div class="rfloat">{phase}</div>

Modified: mgmt/cumin/python/cumin/system.py
===================================================================
--- mgmt/cumin/python/cumin/system.py	2008-02-05 00:10:22 UTC (rev 1642)
+++ mgmt/cumin/python/cumin/system.py	2008-02-05 23:00:19 UTC (rev 1643)
@@ -13,11 +13,6 @@
     def __init__(self, app, name):
         super(SystemSet, self).__init__(app, name)
 
-        self.table_sql = "system as s"
-
-        self.add_sql_column("id", "s.id")
-        self.add_sql_column("name", "s.sys_id")
-
         self.ids = CheckboxIdColumn(app, "id")
         self.add_column(self.ids)
         self.add_form_parameter(self.ids)

Modified: mgmt/cumin/python/cumin/system.strings
===================================================================
--- mgmt/cumin/python/cumin/system.strings	2008-02-05 00:10:22 UTC (rev 1642)
+++ mgmt/cumin/python/cumin/system.strings	2008-02-05 23:00:19 UTC (rev 1643)
@@ -1,3 +1,12 @@
+[SystemSet.sql]
+select s.id, s.sys_id as name
+from system as s
+{sql_orderby}
+{sql_limit}
+
+[SystemSet.count_sql]
+select count(*) from system
+
 [SystemSet.html]
 <form id="{id}" method="post" action="?">
   <table class="mobjects">

Modified: mgmt/cumin/python/cumin/widgets.py
===================================================================
--- mgmt/cumin/python/cumin/widgets.py	2008-02-05 00:10:22 UTC (rev 1642)
+++ mgmt/cumin/python/cumin/widgets.py	2008-02-05 23:00:19 UTC (rev 1643)
@@ -254,6 +254,19 @@
         self.add_state("i", "Idle")
         self.add_state("d", "Deleted")
 
+    def get_sql_constraint(self, session, object):
+        phase = self.get(session)
+
+        if phase == "a":
+            sql = "c.rec_time > now() - interval '10 minutes'"
+        elif phase == "i":
+            sql = "(c.rec_time <= now() - interval '10 minutes'" + \
+                " and deletion_time is null)"
+        else:
+            sql = "deletion_time is not null"
+
+        return sql
+        
 class Paginator(ItemSet):
     def __init__(self, app, name):
         super(Paginator, self).__init__(app, name)
@@ -387,10 +400,18 @@
 
         self.paginator.set_count(session, self.get_item_count(session, object))
 
-    def get_limit_sql(self, session):
+    def render_sql_limit(self, session, object):
         start, end = self.paginator.get_bounds(session)
         return "limit %i offset %i" % (end - start, start)
 
+class NullSortColumn(SqlTableColumn):
+    def get_orderby_sql(self, session):
+        key = self.get_column_key(session)
+
+        if key:
+            dir = self.parent.is_reversed(session) and "desc" or "asc"
+            return "order by %s_is_null asc, %s %s" % (key, key, dir)
+
 class PaginatedItemSet(ItemSet):
     def __init__(self, app, name):
         super(PaginatedItemSet, self).__init__(app, name)

Modified: mgmt/cumin/python/wooly/tables.py
===================================================================
--- mgmt/cumin/python/wooly/tables.py	2008-02-05 00:10:22 UTC (rev 1642)
+++ mgmt/cumin/python/wooly/tables.py	2008-02-05 23:00:19 UTC (rev 1643)
@@ -118,78 +118,40 @@
     def __init__(self, app, name):
         super(SqlTable, self).__init__(app, name)
 
-        self.table_sql = None
-        self.where_sql = None
-        self.sql_joins = list()
-        self.sql_columns = list()
+        self.__sql_tmpl = Template(self, "sql")
+        self.__count_sql_tmpl = Template(self, "count_sql")
 
-    def add_sql_join(self, table_sql, column_sql, fk_column_sql):
-        join = self.SqlJoin(self, table_sql, column_sql, fk_column_sql)
-        self.sql_joins.append(join)
+    def render_sql(self, session, object):
+        writer = Writer()
+        self.__sql_tmpl.render(session, object, writer)
+        sql = writer.to_string()
 
-    def add_sql_column(self, name, sql):
-        col = self.SqlColumn(self, name, sql)
-        self.sql_columns.append(col)
+        #print "sql -----------------------"
+        #print sql
 
-    def get_sql_column(self, name):
-        for col in self.sql_columns:
-            if col.name == name:
-                return col
-
-    def get_select_sql(self, session):
-        if not self.sql_columns:
-            raise Exception()
-
-        cols = ", ".join([col.get_sql(session) for col in self.sql_columns])
-        sql = "select %s" % cols
-
         return sql
 
-    def get_from_sql(self, session):
-        if not self.table_sql:
-            raise Exception()
+    def render_sql_where(self, session, object):
+        pass
 
-        elems = list()
-
-        elems.append("from %s" % self.table_sql)
-
-        for join in self.sql_joins:
-            elems.append(join.get_sql(session))
-
-        return "\n".join(elems)
-
-    def get_where_sql(self, session):
-        return self.where_sql
-
-    def get_orderby_sql(self, session):
+    def render_sql_orderby(self, session, object):
         scol = self.get_selected_column(session)
 
         return scol.get_orderby_sql(session)
 
-    def get_limit_sql(self, session):
+    def render_sql_limit(self, session, object):
         return None
 
-    def get_sql(self, session):
-        elems = (self.get_select_sql(session),
-                 self.get_from_sql(session),
-                 self.get_where_sql(session),
-                 self.get_orderby_sql(session),
-                 self.get_limit_sql(session))
+    def render_count_sql(self, session, object):
+        writer = Writer()
+        self.__count_sql_tmpl.render(session, object, writer)
+        sql = writer.to_string()
 
-        sql = self.build_sql(elems)
-
         #print "sql -----------------------"
         #print sql
 
         return sql
 
-    def get_count_sql(self, session):
-        elems = ("select count(*)",
-                 self.get_from_sql(session),
-                 self.get_where_sql(session))
-
-        return self.build_sql(elems)
-
     def build_sql(self, elems):
         writer = Writer()
         
@@ -211,7 +173,7 @@
 
         if conn:
             cursor = conn.cursor()
-            sql = self.get_count_sql(session)
+            sql = self.render_count_sql(session, object)
             sql_values = self.get_sql_values(session, object)
 
             cursor.execute(sql, sql_values)
@@ -224,7 +186,7 @@
 
         if conn:
             cursor = conn.cursor()
-            sql = self.get_sql(session)
+            sql = self.render_sql(session, object)
             sql_values = self.get_sql_values(session, object)
 
             #print "SQL TEXT", sql
@@ -234,57 +196,29 @@
 
             return cursor
 
-    def render_cells(self, session, data):
-        data_map = dict()
+    def render_items(self, session, object):
+        cursor = self.get_items(session, object)
+        cols = [spec[0] for spec in cursor.description]
+        data = dict()
 
-        for col, datum in zip(self.sql_columns, data):
-            data_map[col.name] = datum
-
         writer = Writer()
 
-        for col in self.columns:
-            writer.write(col.render(session, data_map))
+        for tuple in cursor:
+            for col, datum in zip(cols, tuple):
+                data[col] = datum
 
+            self.item_tmpl.render(session, data, writer)
+
         return writer.to_string()
 
-    class SqlColumn(object):
-        def __init__(self, table, name, sql):
-            self.table = table
-            self.name = name
-            self.sql = sql
+    def render_cells(self, session, data):
+        writer = Writer()
 
-        def get_sql(self, session):
-            return "%s as %s" % (self.sql, self.name)
+        for col in self.columns:
+            writer.write(col.render(session, data))
 
-    class SqlJoin(object):
-        def __init__(self, table,
-                     table_sql=None, column_sql=None, fk_column_sql=None):
-            self.table = table
-            self.table_sql = table_sql
-            self.column_sql = column_sql
-            self.fk_column_sql = fk_column_sql
-            self.type_sql = "left outer join"
+        return writer.to_string()
 
-        def get_table_sql(self, session):
-            return self.table_sql
-
-        def get_column_sql(self, session):
-            return self.column_sql
-
-        def get_fk_column_sql(self, session):
-            return self.fk_column_sql
-
-        def get_type_sql(self, session):
-            return self.type_sql
-
-        def get_sql(self, session):
-            elems = (self.get_type_sql(session),
-                     self.get_table_sql(session),
-                     "on", self.get_column_sql(session),
-                     "=", self.get_fk_column_sql(session))
-
-            return " ".join(elems)
-
 class SqlTableColumn(ItemTableColumn):
     def get_orderby_sql(self, session):
         key = self.get_column_key(session)




More information about the rhmessaging-commits mailing list