[rhmessaging-commits] rhmessaging commits: r4150 - in mgmt/newdata: cumin/python/cumin/grid and 2 other directories.

rhmessaging-commits at lists.jboss.org rhmessaging-commits at lists.jboss.org
Mon Jul 26 16:34:27 EDT 2010


Author: justi9
Date: 2010-07-26 16:34:27 -0400 (Mon, 26 Jul 2010)
New Revision: 4150

Modified:
   mgmt/newdata/cumin/python/cumin/grid/job.py
   mgmt/newdata/cumin/python/cumin/grid/submission.py
   mgmt/newdata/cumin/python/cumin/main.py
   mgmt/newdata/cumin/python/cumin/main.strings
   mgmt/newdata/cumin/python/cumin/messaging/binding.py
   mgmt/newdata/cumin/python/cumin/messaging/broker.py
   mgmt/newdata/cumin/python/cumin/messaging/connection.py
   mgmt/newdata/cumin/python/cumin/objectselector.py
   mgmt/newdata/cumin/python/cumin/sqladapter.py
   mgmt/newdata/cumin/python/cumin/widgets.py
   mgmt/newdata/wooly/python/wooly/datatable.py
Log:
 * For the sake of simpler queries that are also faster, use message
   depth instead of recent enqueues for the queue top table

 * Use existing sort facilities on objecttable instead of custom ones
   on TopTables

 * Fix an object-initialization ordering problem that prevented table
   columns from picking up formats; generally try to make this less
   confusing

 * Correct some naming in objecttable

 * Only set the default sort if it hasn't already been set

 * In DataTable, apply field formats if prsesent; format floats with
   "%0.02f" by default


Modified: mgmt/newdata/cumin/python/cumin/grid/job.py
===================================================================
--- mgmt/newdata/cumin/python/cumin/grid/job.py	2010-07-26 20:12:01 UTC (rev 4149)
+++ mgmt/newdata/cumin/python/cumin/grid/job.py	2010-07-26 20:34:27 UTC (rev 4150)
@@ -130,9 +130,11 @@
 class JobSelector(ObjectSelector):
     def __init__(self, app, name, submission):
         cls = app.model.com_redhat_cumin_grid.JobSummary
-        adapter = JobSummariesAdapter(app, cls)
-        super(JobSelector, self).__init__(app, name, cls, adapter)
 
+        super(JobSelector, self).__init__(app, name, cls)
+
+        self.adapter = JobSummariesAdapter(app, cls)
+
         self.submission = submission
         frame = "main.grid.pool.submission.job"
         self.job_id_col = self.JobIdColumn(app, "job", cls.GlobalJobId, cls.JobId, frame)
@@ -143,7 +145,7 @@
 
         self.add_attribute_column(cls.Cmd)
 
-        self.job_id_column = ObjectAttributeColumn(app, cls.JobId.name, cls.JobId)
+        self.job_id_column = ObjectTableColumn(app, cls.JobId.name, cls.JobId)
         self.job_id_column.visible = False
         self.add_column(self.job_id_column)
 
@@ -183,7 +185,7 @@
             submission = self.parent.submission.get(session)
             return frame.get_href(session, submission._id, job_id)
 
-    class Status(ObjectAttributeColumn):
+    class Status(ObjectTableColumn):
         def render_cell_content(self, session, record):
             status = self.field.get_content(session, record)
             return JobStatusInfo.get_status_string(status)

Modified: mgmt/newdata/cumin/python/cumin/grid/submission.py
===================================================================
--- mgmt/newdata/cumin/python/cumin/grid/submission.py	2010-07-26 20:12:01 UTC (rev 4149)
+++ mgmt/newdata/cumin/python/cumin/grid/submission.py	2010-07-26 20:34:27 UTC (rev 4150)
@@ -56,10 +56,11 @@
 class SubmissionSelector(ObjectSelector):
     def __init__(self, app, name):
         cls = app.model.com_redhat_grid.Submission
-        data = SubmissionData(app)
 
-        super(SubmissionSelector, self).__init__(app, name, cls, data)
+        super(SubmissionSelector, self).__init__(app, name, cls)
 
+        self.adapter = SubmissionData(app)
+
         self.add_attribute_column(cls.Idle)
         self.add_attribute_column(cls.Running)
         self.add_attribute_column(cls.Completed)
@@ -79,7 +80,7 @@
         self.insert_column(1, col)
 
         attr = self.cls.Owner
-        col = ObjectAttributeColumn(app, attr.name, attr)
+        col = ObjectTableColumn(app, attr.name, attr)
         self.insert_column(2, col)
 
 class SubmissionAdd(ObjectTask):

Modified: mgmt/newdata/cumin/python/cumin/main.py
===================================================================
--- mgmt/newdata/cumin/python/cumin/main.py	2010-07-26 20:12:01 UTC (rev 4149)
+++ mgmt/newdata/cumin/python/cumin/main.py	2010-07-26 20:34:27 UTC (rev 4150)
@@ -280,44 +280,41 @@
 class TopQueueTable(TopTable):
     def __init__(self, app, name):
         cls = app.model.org_apache_qpid_broker.Queue
-        adapter = TopQueueAdapter(app, cls)
+        super(TopQueueTable, self).__init__(app, name, cls)
 
-        super(TopQueueTable, self).__init__(app, name, adapter)
-
-        col = self.Name(app, "name")
+        frame = "main.messaging.broker.queue"
+        col = self.NameColumn(app, "name", cls.name, cls._id, frame)
         self.add_column(col)
 
-        col = self.MsgEnqueuesColumn(app, cls.msgTotalEnqueues.name,
-                                    cls.msgTotalEnqueues)
-        self.add_column(col)
+        col = self.add_attribute_column(cls.msgDepth)
 
-    class MsgEnqueuesColumn(DataTableColumn):
-        def render_header_content(self, session):
-            return "Recent Enqueues / sec"
+        self.sort.default = col.name
 
-        def render_cell_content(self, session, record):
-            return "%.1f" % float(record[1])
+    def init(self):
+        super(TopQueueTable, self).init()
 
-        def render_text_align(self, session):
-            # type is str: "count64"
-            return "right"
+        self.adapter.vhost_id_field = ObjectSqlField \
+            (self.adapter, self.cls.vhostRef)
 
-    class Name(LinkColumn):
-        def render_header_content(self, session):
-            return "Name"
+        SqlComparisonFilter(self.adapter.query,
+                            self.cls.msgDepth.sql_column,
+                            "null",
+                            "is not")
 
+    class NameColumn(ObjectLinkColumn):
         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)
+            frame = self.page.main.messaging.broker
+            adapter = self.table.adapter
+
+            frame.id.set(branch, record[adapter.vhost_id_field.index])
+            frame.queue.id.set(branch, record[adapter.id_field.index])
+            frame.queue.view.show(branch)
+
             return branch.marshal()
 
-        def render_cell_content(self, session, record):
-            return record[0]
-
-class TopSystemTable(TopObjectTable):
+class TopSystemTable(TopTable):
     def __init__(self, app, name):
         cls = app.model.com_redhat_sesame.Sysimage
 
@@ -327,15 +324,19 @@
         col = ObjectLinkColumn(app, "name", cls.nodeName, cls._id, frame)
         self.add_column(col)
 
-        attr = cls.loadAverage1Min
-        col = TopObjectAttributeColumn(self.app, attr.name, attr)
-        self.add_column(col)
-        self.sort_col = attr.name
+        col = self.add_attribute_column(cls.loadAverage1Min)
 
-        self.header = TopTableHeader(app, "header")
-        self.replace_child(self.header)
+        self.sort.default = col.name
 
-class TopSubmissionTable(TopObjectTable):
+    def init(self):
+        super(TopSystemTable, self).init()
+
+        SqlComparisonFilter(self.adapter.query,
+                            self.cls.loadAverage1Min.sql_column,
+                            "null",
+                            "is not")
+
+class TopSubmissionTable(TopTable):
     def __init__(self, app, name):
         cls = app.model.com_redhat_grid.Submission
 
@@ -347,8 +348,9 @@
         col = self.DurationColumn(app, cls._qmf_create_time.name,
                                   cls._qmf_create_time)
         self.add_column(col)
-        self.sort_col = cls._qmf_create_time.name
 
+        self.sort.default = col.name
+
     def init(self):
         super(TopSubmissionTable, self).init()
 
@@ -370,7 +372,7 @@
             self.page.main.grid.pool.submission.view.show(session)
             return branch.marshal()
 
-    class DurationColumn(TopObjectAttributeColumn):
+    class DurationColumn(TopTableColumn):
         def render_header_content(self, session):
             return "Duration"
 

Modified: mgmt/newdata/cumin/python/cumin/main.strings
===================================================================
--- mgmt/newdata/cumin/python/cumin/main.strings	2010-07-26 20:12:01 UTC (rev 4149)
+++ mgmt/newdata/cumin/python/cumin/main.strings	2010-07-26 20:34:27 UTC (rev 4150)
@@ -24,7 +24,7 @@
       <tr>
         <td>
 <div class="fullpageable">
-          <h2><img src="resource?name=queue-20.png"/> Busiest Message Queues</h2>
+          <h2><img src="resource?name=queue-20.png"/> Deepest Message Queues</h2>
 
           <div class="iblock">{queues}</div>
 </div>

Modified: mgmt/newdata/cumin/python/cumin/messaging/binding.py
===================================================================
--- mgmt/newdata/cumin/python/cumin/messaging/binding.py	2010-07-26 20:12:01 UTC (rev 4149)
+++ mgmt/newdata/cumin/python/cumin/messaging/binding.py	2010-07-26 20:34:27 UTC (rev 4150)
@@ -87,9 +87,9 @@
         exchange = app.model.org_apache_qpid_broker.Exchange
         queue = app.model.org_apache_qpid_broker.Queue
 
-        data = BindingData(app)
+        super(BindingSelector, self).__init__(app, name, binding)
 
-        super(BindingSelector, self).__init__(app, name, binding, data)
+        self.adapter = BindingData(app)
 
         frame = "main.messaging.broker.binding"
         col = ObjectLinkColumn \

Modified: mgmt/newdata/cumin/python/cumin/messaging/broker.py
===================================================================
--- mgmt/newdata/cumin/python/cumin/messaging/broker.py	2010-07-26 20:12:01 UTC (rev 4149)
+++ mgmt/newdata/cumin/python/cumin/messaging/broker.py	2010-07-26 20:34:27 UTC (rev 4150)
@@ -62,9 +62,9 @@
         system = app.model.org_apache_qpid_broker.System
         cluster = app.model.org_apache_qpid_cluster.Cluster
 
-        data = BrokerData(app)
+        super(BrokerSelector, self).__init__(app, name, broker)
 
-        super(BrokerSelector, self).__init__(app, name, broker, data)
+        self.adapter = BrokerData(app)
 
         self.group = SessionAttribute(self, "group")
 

Modified: mgmt/newdata/cumin/python/cumin/messaging/connection.py
===================================================================
--- mgmt/newdata/cumin/python/cumin/messaging/connection.py	2010-07-26 20:12:01 UTC (rev 4149)
+++ mgmt/newdata/cumin/python/cumin/messaging/connection.py	2010-07-26 20:34:27 UTC (rev 4150)
@@ -99,7 +99,7 @@
         args = (item.remoteProcessName, item.remotePid)
         return "%s (%i)" % args
 
-class ConnectionProcessColumn(ObjectAttributeColumn):
+class ConnectionProcessColumn(ObjectTableColumn):
     def __init__(self, app, name, attr, pid_attr):
         super(ConnectionProcessColumn, self).__init__(app, name, attr)
 

Modified: mgmt/newdata/cumin/python/cumin/objectselector.py
===================================================================
--- mgmt/newdata/cumin/python/cumin/objectselector.py	2010-07-26 20:12:01 UTC (rev 4149)
+++ mgmt/newdata/cumin/python/cumin/objectselector.py	2010-07-26 20:34:27 UTC (rev 4150)
@@ -12,44 +12,43 @@
 strings = StringCatalog(__file__)
 
 class ObjectTable(DataTable):
-    def __init__(self, app, name, cls, adapter=None):
+    def __init__(self, app, name, cls):
+        super(ObjectTable, self).__init__(app, name)
+
         assert isinstance(cls, RosemaryClass), cls
 
-        if not adapter:
-            adapter = ObjectSqlAdapter(app, cls)
-
-        assert isinstance(adapter, DataAdapter), adapter
-
-        super(ObjectTable, self).__init__(app, name, adapter)
-
         self.cls = cls
 
         self.update_enabled = True
-
         self.ascending.default = True
 
         # (RosemaryAttribute this, RosemaryAttribute that, Attribute object)
         self.filter_specs = list()
 
     def init(self):
+        if not self.adapter:
+            self.adapter = ObjectSqlAdapter(self.app, self.cls)
+
         super(ObjectTable, self).init()
 
-        assert self.cls, self
-        assert self.adapter, self
-        #assert self.adapter.id_field, self
+        for this, that, fobj in self.filter_specs:
+            self.adapter.add_value_filter(this)
 
-        for col in self.columns:
-            if col.sortable:
-                self.sort.default = col.name
+        if self.sort.default is None:
+            for col in self.columns:
+                if col.sortable:
+                    self.sort.default = col.name
+                    break
 
-                break
-
     def add_attribute_column(self, attr):
         assert isinstance(attr, RosemaryAttribute), attr
 
-        col = ObjectAttributeColumn(self.app, attr.name, attr)
+        col = ObjectTableColumn(self.app, attr.name, attr)
+
         self.add_column(col)
 
+        return col
+
     def add_filter(self, attribute, this, that=None):
         if not that:
             that = this
@@ -59,7 +58,6 @@
         assert isinstance(that, RosemaryAttribute), that
 
         self.filter_specs.append((this, that, attribute))
-        self.adapter.add_value_filter(this)
 
     def add_reference_filter(self, attribute, ref):
         assert isinstance(ref, RosemaryReference), ref
@@ -74,9 +72,6 @@
 
         for this, that, fobj in self.filter_specs:
             obj = fobj.get(session)
-
-            session.log("%r %r %r" % (this, obj, that))
-
             values[this.name] = getattr(obj, that.name)
 
         return values
@@ -84,9 +79,32 @@
     def render_title(self, session):
         return "%ss" % self.cls._title
 
+class ObjectTableColumn(DataTableColumn):
+    def __init__(self, app, name, attr):
+        super(ObjectTableColumn, self).__init__(app, name)
+
+        self.attr = attr
+
+    def init(self):
+        super(ObjectTableColumn, self).init()
+
+        assert self.table.adapter, self.table
+
+        try:
+            self.field = self.table.adapter.fields_by_attr[self.attr]
+        except KeyError:
+            # XXX do this instead:
+            #cls = self.table.adapter.default_field_cls
+            #self.field = cls(self.table.adapter, self.attr)
+
+            if isinstance(self.table.adapter, ObjectQmfAdapter):
+                self.field = ObjectQmfField(self.table.adapter, self.attr)
+            else:
+                self.field = ObjectSqlField(self.table.adapter, self.attr)
+
 class ObjectSelector(ObjectTable, Form):
-    def __init__(self, app, name, cls, adapter=None):
-        super(ObjectSelector, self).__init__(app, name, cls, adapter)
+    def __init__(self, app, name, cls):
+        super(ObjectSelector, self).__init__(app, name, cls)
 
         self.init_ids(app, cls)
 
@@ -125,24 +143,7 @@
             (app, "id", cls._id, self.ids)
         self.add_column(self.checkbox_column)
 
-class ObjectAttributeColumn(DataTableColumn):
-    def __init__(self, app, name, attr):
-        super(ObjectAttributeColumn, self).__init__(app, name, None)
-
-        self.attr = attr
-
-    def init(self):
-        super(ObjectAttributeColumn, self).init()
-
-        try:
-            self.field = self.table.adapter.fields_by_attr[self.attr]
-        except KeyError:
-            if isinstance(self.table.adapter, ObjectQmfAdapter):
-                self.field = ObjectQmfField(self.table.adapter, self.attr)
-            else:
-                self.field = ObjectSqlField(self.table.adapter, self.attr)
-
-class ObjectCheckboxColumn(ObjectAttributeColumn):
+class ObjectCheckboxColumn(ObjectTableColumn):
     def __init__(self, app, name, attr, selection):
         super(ObjectCheckboxColumn, self).__init__(app, name, attr)
 
@@ -175,7 +176,7 @@
         return record[self.parent.parent.field.index] in checks \
             and "checked=\"checked\"" or ""
 
-class ObjectLinkColumn(ObjectAttributeColumn, LinkColumn):
+class ObjectLinkColumn(ObjectTableColumn, LinkColumn):
     def __init__(self, app, name, attr, id_attr, frame_path):
         super(ObjectLinkColumn, self).__init__(app, name, attr)
 

Modified: mgmt/newdata/cumin/python/cumin/sqladapter.py
===================================================================
--- mgmt/newdata/cumin/python/cumin/sqladapter.py	2010-07-26 20:12:01 UTC (rev 4149)
+++ mgmt/newdata/cumin/python/cumin/sqladapter.py	2010-07-26 20:34:27 UTC (rev 4150)
@@ -13,10 +13,6 @@
         self.query = SqlQuery(self.table)
         self.columns = list()
 
-    def init(self):
-        for field in self.fields:
-            field.init()
-
     def get_count(self, values):
         # XXX urgh.  I want session in here
 

Modified: mgmt/newdata/cumin/python/cumin/widgets.py
===================================================================
--- mgmt/newdata/cumin/python/cumin/widgets.py	2010-07-26 20:12:01 UTC (rev 4149)
+++ mgmt/newdata/cumin/python/cumin/widgets.py	2010-07-26 20:34:27 UTC (rev 4150)
@@ -1542,35 +1542,11 @@
         exchanges = cls.get_selection(session.cursor, _vhostRef_id=vhostid)
         return self.base_get_items(session, exchanges)
 
-class TopTable(DataTable):
-    def __init__(self, app, name, adapter):
-        super(TopTable, self).__init__(app, name, adapter)
-
-        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_count(self, session):
-        # avoid extra sql call since we don't show the record count
-        return 0
-
-    def get_data_options(self, session):
-        options = SqlQueryOptions()
-
-        options.limit = 5
-        options.offset = 0
-
-        return options
-
-class TopObjectTable(ObjectTable):
+class TopTable(ObjectTable):
     def __init__(self, app, name, cls):
-        super(TopObjectTable, self).__init__(app, name, cls)
+        super(TopTable, self).__init__(app, name, cls)
 
-        col = ObjectAttributeColumn(app, cls._id.name, cls._id)
+        col = ObjectTableColumn(app, cls._id.name, cls._id)
         col.visible = False
         self.add_column(col)
 
@@ -1580,18 +1556,13 @@
         self.footer = TopTableFooter(app, "footer")
         self.replace_child(self.footer)
 
-        self.sort_col = None
+        self.header.limit.default = 5
+        self.ascending.default = False
 
     def get_count(self, session):
         # avoid extra sql call since we don't show the record count
         return 0
 
-    def get_data_options(self, session):
-        sort_col = self.sort_col or self.cls._id.name
-        self.sort.set(session, sort_col)
-        self.ascending.set(session, False)
-        return super(TopObjectTable, self).get_data_options(session)
-
 class TopTableHeader(TableHeader):
     def __init__(self, app, name):
         super(TopTableHeader, self).__init__(app, name)
@@ -1620,9 +1591,9 @@
     def render_class(self, session):
         return self.parent.name
 
-class TopObjectAttributeColumn(ObjectAttributeColumn):
-        def render_class(self, session):
-            return self.name
+class TopTableColumn(ObjectTableColumn):
+    def render_class(self, session):
+        return self.name
 
 class TopTableFooter(Widget):
     def render(self, session):

Modified: mgmt/newdata/wooly/python/wooly/datatable.py
===================================================================
--- mgmt/newdata/wooly/python/wooly/datatable.py	2010-07-26 20:12:01 UTC (rev 4149)
+++ mgmt/newdata/wooly/python/wooly/datatable.py	2010-07-26 20:34:27 UTC (rev 4150)
@@ -26,20 +26,31 @@
         self.adapter = adapter
         self.name = name
         self.type = type
+        self.format = None
 
         self.index = len(self.adapter.fields)
         self.adapter.fields.append(self)
         self.adapter.fields_by_name[self.name] = self
 
     def init(self):
-        pass
+        if self.format is None and self.type is float:
+            self.format = "%0.02f"
 
     def get_title(self, session):
         pass
 
     def get_content(self, session, record):
-        return record[self.index]
+        value = record[self.index]
 
+        if self.format is not None:
+            value = self.format % value
+
+        return value
+
+    def __repr__(self):
+        args = (self.__class__.__name__, self.name, self.type.__name__)
+        return "%s(%s,%s)" % args
+
 class DataAdapterOptions(object):
     def __init__(self):
         self.sort_field = None
@@ -50,10 +61,10 @@
         self.attributes = dict()
 
 class DataTable(Table):
-    def __init__(self, app, name, adapter):
+    def __init__(self, app, name):
         super(DataTable, self).__init__(app, name)
 
-        self.adapter = adapter
+        self.adapter = None
 
         self.data = Attribute(app, "data")
         self.add_attribute(self.data)
@@ -71,12 +82,11 @@
         self.replace_child(self.footer)
 
     def init(self):
-        assert self.adapter
+        super(DataTable, self).init()
 
+        assert isinstance(self.adapter, DataAdapter), self.adapter
         self.adapter.init()
 
-        super(DataTable, self).init()
-
     def get_data(self, session):
         values = self.get_data_values(session)
         options = self.get_data_options(session)
@@ -145,10 +155,10 @@
         return writer.to_string()
 
 class DataTableColumn(TableColumn):
-    def __init__(self, app, name, field):
+    def __init__(self, app, name):
         super(DataTableColumn, self).__init__(app, name)
 
-        self.field = field
+        self.field = None
 
     def render_text_align(self, session):
         if self.field.type in (long, int, float, complex):



More information about the rhmessaging-commits mailing list