[rhmessaging-commits] rhmessaging commits: r3032 - mgmt/trunk/cumin/python/cumin.

rhmessaging-commits at lists.jboss.org rhmessaging-commits at lists.jboss.org
Tue Jan 6 09:58:25 EST 2009


Author: eallen
Date: 2009-01-06 09:58:24 -0500 (Tue, 06 Jan 2009)
New Revision: 3032

Modified:
   mgmt/trunk/cumin/python/cumin/model.py
   mgmt/trunk/cumin/python/cumin/pool.py
   mgmt/trunk/cumin/python/cumin/pool.strings
   mgmt/trunk/cumin/python/cumin/slot.py
   mgmt/trunk/cumin/python/cumin/stat.py
   mgmt/trunk/cumin/python/cumin/stat.strings
   mgmt/trunk/cumin/python/cumin/system.py
Log:
Consolidate sql for vis and the count of slots on the "Grid Slots (x)" tab so it gets called only once.
On Grid statistics page, only display the machine vis if slot vis won't fit. This is so the number of sql calls is kept to a minimum.

Modified: mgmt/trunk/cumin/python/cumin/model.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/model.py	2009-01-05 15:40:29 UTC (rev 3031)
+++ mgmt/trunk/cumin/python/cumin/model.py	2009-01-06 14:58:24 UTC (rev 3032)
@@ -584,8 +584,7 @@
     def get_boxes(self, session, object, *args):
         if args:
             self.itemset.set_args(session, *args)
-        cursor = self.itemset.get_items(session, object)
-        box_list = self.itemset.cursor_to_rows(cursor)
+        box_list = self.itemset.get_items(session, object)
         return box_list
 
     def get_color(self, session, box):
@@ -703,6 +702,11 @@
             super(CuminSystem.SystemSlotVisualization, self).__init__(cls, name)
             
             self.itemset = self.ModelSystemSlotSet(cls.model.app, "slot")
+            self.itemset.items.path = "CuminSystem.SystemSlotVisualization.slot"
+                        
+        def get_slot_count(self, session, system):
+            items = self.itemset.get_items(session, system)
+            return len(items)
             
         class ModelSystemSlotSet(SystemSlotSet):
             def render_sql_limit(self, session, *args):
@@ -746,7 +750,7 @@
                 master = Master.select("System = '%s'" % system_name)[0]
             except IndexError:
                 raise Exception("Master daemon not running")
-            master.Stop(self.model.data, completion, args["subsystem"])
+            #master.Stop(self.model.data, completion, args["subsystem"])
         
 class CuminBroker(RemoteClass):
     def __init__(self, model):
@@ -2021,6 +2025,7 @@
             super(CuminPool.PoolSlotVisualization, self).__init__(cls, name)
             
             self.itemset = self.ModelPoolSlotSet(cls.model.app, "slot")
+            self.itemset.items.path = "CuminPool.PoolSlotVisualization.slot"
 
         def set_machine(self, session, machine):
             self.itemset.set_machine(session, machine)
@@ -2073,7 +2078,8 @@
             super(CuminPool.FakeJobStats, self).__init__(cls, name)
 
             self.itemset = PoolJobStats(cls.model.app, "stats")
-
+            self.itemset.items.path = "CuminPool.FakeJobStats.stats"
+            
         def get_stat_record(self, session, pool):
             cursor = self.itemset.get_items(session, pool)
             rows = self.itemset.cursor_to_rows(cursor)
@@ -2085,10 +2091,10 @@
             super(CuminPool.PoolStatus, self).__init__(cls, name)
 
             self.itemset = self.StatusPoolSlotSet(cls.model.app, "stats")
+            self.itemset.items.path = "CuminPool.PoolStatus.stats"
 
         def get_stat_record(self, session, pool):
-            cursor = self.itemset.get_items(session, pool)
-            rows = self.itemset.cursor_to_rows(cursor)
+            rows = self.itemset.get_items(session, pool)
             if len(rows):
                 return rows[0]
 
@@ -2117,6 +2123,7 @@
             super(CuminPool.VisMachine, self).__init__(cls, name)
 
             self.itemset = PoolMachineSet(cls.model.app, "machine")
+            self.itemset.items.path = "CuminPool.VisMachine.machine"
 
         def get_field_tuples(self, session):
             return [("machine", "Machine"), ("busy", "Busy Slots"), ("idle", "Idle Slots")]

Modified: mgmt/trunk/cumin/python/cumin/pool.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/pool.py	2009-01-05 15:40:29 UTC (rev 3031)
+++ mgmt/trunk/cumin/python/cumin/pool.py	2009-01-06 14:58:24 UTC (rev 3032)
@@ -310,24 +310,21 @@
         stats = PoolStatSet(app, "general", "general")
         self.add_child(stats)
 
+        self.machine_grid = self.MachineVisualization(app, "machine_grid")
+        self.add_child(self.machine_grid)
+
         self.slot_grid = self.SlotVisualization(app, "slot_grid")
         self.add_child(self.slot_grid)
 
-        self.machine_grid = self.MachineVisualization(app, "machine_grid")
-        self.add_child(self.machine_grid)
-
         self.all_fits = Attribute(app, "can_show_all")
         self.add_attribute(self.all_fits)
         
         self.machine_param = Parameter(app, "machine_param")
         self.add_parameter(self.machine_param)
     
-        self.show_all_slots = self.ShowAllSlots(app, "show_all_slots")
-        self.add_child(self.show_all_slots)
-            
     def process(self, session):
         super(PoolStats, self).process(session)
-        all_slots = self.show_all_slots.get(session)
+        all_slots = self.slot_grid.show_all_slots.get(session)
         machine = self.machine_param.get(session)
         all_fits = True
         
@@ -348,15 +345,17 @@
     def render_title(self, session):
         return "Statistics"
     
-    def render_slot_title(self, session):
-        pool = self.frame.get_args(session)[0]
-        machine = self.slot_grid.get_machine(session)
-        return machine and "Slots on (%s)" % machine or "Slots on %s" % pool.name
-
     def render_machine_title(self, session):
-        pool = self.frame.get_args(session)[0]
-        return "Machines on %s" % pool.name
+        slots_fit = self.all_fits.get(session)
+        if not slots_fit:
+            pool = self.frame.get_args(session)[0]
+            return "Machines on %s" % pool.name
     
+    def render_machine_help(self, session):
+        slots_fit = self.all_fits.get(session)
+        if not slots_fit:
+            return "Select a Machine to view its slots"    
+    
     def render_slot_job_url(self, session):
         job = Identifiable("XXX")
         return self.page.main.pool.job.get_href(session, job)
@@ -365,13 +364,23 @@
         def __init__(self, app, name):
             super(PoolStats.SlotVisualization, self).__init__(app, name)
 
+            self.show_all_slots = self.ShowAllSlots(app, "show_all_slots")
+            self.add_child(self.show_all_slots)
+            
+        def render(self, session, *args):
+            slots_fit = self.parent.all_fits.get(session)
+            if slots_fit:
+                return super(PoolStats.SlotVisualization, self).render(session, *args)
+            
         def get_cells(self, session):
             pool = self.frame.get_args(session)[0]
             action = self.app.model.pool.slots
             return action.get_boxes(session, pool)
         
         def render_title(self, session):
-            return ""
+            pool = self.frame.get_args(session)[0]
+            machine = self.get_machine(session)
+            return machine and "Slots on (%s)" % machine or "Slots on %s" % pool.name
 
         def set_machine(self, session, machine):
             action = self.app.model.pool.slots
@@ -399,12 +408,42 @@
             pool = self.parent.frame.get_args(session)[0]
             machine = self.get_machine(session)
             return "call.xml?class=pool;id=%s;method=slots;xargs=%s" % (pool.id, machine)
-        
+
         def get_sticky_info(self, session):
             action = self.app.model.pool.slots
             return action.get_field_tuples(session)
 
+        class ShowAllSlots(StateSwitch):
+            def __init__(self, app, name):
+                super(PoolStats.SlotVisualization.ShowAllSlots, self).__init__(app, name)
+                
+                self.add_state("a", "All")
+                self.add_state("m", "Machine")
+        
+            def render(self, session):
+                state = self.get(session)
+                if state == "m":
+                    return super(PoolStats.SlotVisualization.ShowAllSlots, self).render(session)
+                
+            def render_href(self, session):
+                state = self.get(session)
+                if state == "m":
+                    branch = session.branch()
+                    self.set(branch, "a")
+                    return branch.marshal()
+                else:
+                    return "#"
+            
+            def render_class(self, session):
+                state = self.get(session)
+                return state == "a" and "disabled" or "enabled"
+                
     class MachineVisualization(StatUtilizationGrid):
+        def render(self, session, *args):
+            slots_fit = self.parent.all_fits.get(session)
+            if not slots_fit:
+                return super(PoolStats.MachineVisualization, self).render(session, *args)
+            
         def get_cells(self, session):
             pool = self.frame.get_args(session)[0]
             action = self.app.model.pool.machines
@@ -434,7 +473,7 @@
             machine = data["machine"]
             branch = session.branch()
             self.parent.machine_param.set(branch, machine)
-            self.parent.show_all_slots.set(branch, "m")
+            self.parent.slot_grid.show_all_slots.set(branch, "m")
             return branch.marshal()
 
         def get_url(self, session):
@@ -445,26 +484,6 @@
             action = self.app.model.pool.machines
             return action.get_field_tuples(session)
 
-    class ShowAllSlots(StateSwitch):
-        def __init__(self, app, name):
-            super(PoolStats.ShowAllSlots, self).__init__(app, name)
-            
-            self.add_state("a", "All")
-            self.add_state("m", "Machine")
-    
-        def render_href(self, session):
-            state = self.get(session)
-            if state == "m":
-                branch = session.branch()
-                self.set(branch, "a")
-                return branch.marshal()
-            else:
-                return "#"
-        
-        def render_class(self, session):
-            state = self.get(session)
-            return state == "a" and "disabled" or "enabled"
-            
 class PoolStatSet(StatSet):
     def render_rate_text(self, session, args):
         return "Percentage"

Modified: mgmt/trunk/cumin/python/cumin/pool.strings
===================================================================
--- mgmt/trunk/cumin/python/cumin/pool.strings	2009-01-05 15:40:29 UTC (rev 3031)
+++ mgmt/trunk/cumin/python/cumin/pool.strings	2009-01-06 14:58:24 UTC (rev 3032)
@@ -100,22 +100,32 @@
   </div>
 </div>
 <div style="float: left; margin-left: 4em;">
-   	<div class="vistats">
-  		<h2>{machine_title}</h2>
-  		<div class="machine_help">Select a Machine to view its slots</div>
 		{machine_grid}
-	</div>
-	<div class="vistats">
-   		<h2>{slot_title}</h2>
-   		{show_all_slots}
 		{slot_grid}
-  	</div>
 </div>
 <div style="clear:left;"><!-- --></div>
 <script type="text/javascript">
 var show_slot_job_url = "{slot_job_url}";
 </script>
 
+[SlotVisualization.html]
+{show_all_slots}
+<div class="vistats">
+  <h2>{title}</h2>
+  <div class="StatUtilizationGrid" id="{id}">
+    <div class="visualization">
+        <div id="StatGrid" class="StatGrid" style="width:{grid_width};">
+            {grid}
+            <div style="clear:left;"><!-- --></div>
+        </div>
+    </div>
+    <div id="legend_{name}" class="cell_legend">
+        {grid_legend}
+    </div>
+  </div>
+</div>
+{grid_updater}
+
 [ShowAllSlots.html]
     <div style="margin:1em;">
     	<a href="{href}"><button class="{class}" type="button" tabindex="100" >Show All Slots</button></a>

Modified: mgmt/trunk/cumin/python/cumin/slot.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/slot.py	2009-01-05 15:40:29 UTC (rev 3031)
+++ mgmt/trunk/cumin/python/cumin/slot.py	2009-01-06 14:58:24 UTC (rev 3032)
@@ -19,6 +19,12 @@
             from slot as ss
             where s.name = ss.name))"""
 
+    def do_get_items(self, session, *args):
+        cursor = super(UniqueSlot, self).do_get_items(session, *args)
+        items = self.cursor_to_rows(cursor)
+        self.items.set(session, items)
+        return items
+
 class SlotSet(UniqueSlot):
     def __init__(self, app, name):
         super(SlotSet, self).__init__(app, name)
@@ -30,6 +36,18 @@
         def render_title(self, session, data):
             return "Name"
 
+    def render_items(self, session, *args):
+        """ overridden because a slotset query is expensive.
+            the rows are cached """
+            
+        rows = self.get_items(session, *args)
+        writer = Writer()
+
+        for row in rows:
+            self.item_tmpl.render(writer, session, row)
+        
+        return writer.to_string()
+
 class MachineSet(UniqueSlot):
     pass
 

Modified: mgmt/trunk/cumin/python/cumin/stat.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/stat.py	2009-01-05 15:40:29 UTC (rev 3031)
+++ mgmt/trunk/cumin/python/cumin/stat.py	2009-01-06 14:58:24 UTC (rev 3032)
@@ -164,6 +164,9 @@
     def render_name(self, session):
         return self.name
     
+    def render_vis_help(self, session):
+        pass
+    
     def will_it_fit(self, session):
         count = len(self.cells.get_items(session))
         columns = self.cells.calculate_columns(count)
@@ -209,7 +212,6 @@
 
         def do_get_items(self, session):
             cells = self.parent.get_cells(session)
-            self.items.set(session, cells)
             self.width.set(session, 
                            self.calculate_cell_width(len(cells)))
             return cells

Modified: mgmt/trunk/cumin/python/cumin/stat.strings
===================================================================
--- mgmt/trunk/cumin/python/cumin/stat.strings	2009-01-05 15:40:29 UTC (rev 3031)
+++ mgmt/trunk/cumin/python/cumin/stat.strings	2009-01-06 14:58:24 UTC (rev 3032)
@@ -294,9 +294,11 @@
 }
 
 [StatUtilizationGrid.html]
-<div class="StatUtilizationGrid" id="{id}">
+<div class="vistats">
+  <h2>{title}</h2>
+  <div class="vis_help">{vis_help}</div>
+  <div class="StatUtilizationGrid" id="{id}">
 	<div class="visualization">
-		<h2>{title}</h2>
 		<div id="StatGrid" class="StatGrid" style="width:{grid_width};">
 			{grid}
 			<div style="clear:left;"><!-- --></div>
@@ -305,6 +307,7 @@
 	<div id="legend_{name}" class="cell_legend">
 		{grid_legend}
 	</div>
+  </div>
 </div>
 {grid_updater}
 

Modified: mgmt/trunk/cumin/python/cumin/system.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/system.py	2009-01-05 15:40:29 UTC (rev 3031)
+++ mgmt/trunk/cumin/python/cumin/system.py	2009-01-06 14:58:24 UTC (rev 3032)
@@ -186,7 +186,7 @@
         def get_url(self, session):
             system = self.parent.frame.get_args(session)[0]
             return "call.xml?class=system;id=%i;method=slots" % system.id
-        
+
         def get_sticky_info(self, session):
             action = self.app.model.system.slots
             return action.get_field_tuples(session)
@@ -236,7 +236,10 @@
         return self.frame.get_args(session)
 
     def render_title(self, session, system):
-        return "Grid Slots %s" % fmt_count(self.get_item_count(session, system))
+        # dont' use self.get_item_count because it will cause a costly sql query
+        # instead, use the systemslotset in model so it will be cached
+        count = self.app.model.system.slots.get_slot_count(session, system)
+        return "Grid Slots %s" % fmt_count(count)
 
     def render_sql_where(self, session, system):
         elems = list()




More information about the rhmessaging-commits mailing list