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

rhmessaging-commits at lists.jboss.org rhmessaging-commits at lists.jboss.org
Thu Nov 13 10:56:24 EST 2008


Author: eallen
Date: 2008-11-13 10:56:24 -0500 (Thu, 13 Nov 2008)
New Revision: 2799

Modified:
   mgmt/trunk/cumin/python/cumin/model.py
Log:
Add classmethod "get(id)" to Pool object so it can function similar to SQLTable objects.
Add pool slot visualization. Needs to combined with system slot visualization eventually.

Modified: mgmt/trunk/cumin/python/cumin/model.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/model.py	2008-11-13 15:51:43 UTC (rev 2798)
+++ mgmt/trunk/cumin/python/cumin/model.py	2008-11-13 15:56:24 UTC (rev 2799)
@@ -495,8 +495,8 @@
             stat.write_xml(writer, object)
 
     def write_xml(self, writer, object):
-        writer.write("<%s id=\"%i\" name=\"%s\">" % \
-                         (self.cumin_name, object.id,
+        writer.write("<%s id=\"%s\" name=\"%s\">" % \
+                         (self.cumin_name, str(object.id),
                           self.get_object_name(object)))
 
         self.write_event_xml(writer, object)
@@ -1840,7 +1840,14 @@
         self.id = self.collector.Pool
         self.name = self.collector.Name
         
+    def get(cls, id):
+        for coll in Collector.select("pool='%s'" % id):
+            return Pool(coll)
+    get = classmethod(get)
+        
 from job import JobSet
+from pool import PoolSlotSet
+
 class CuminPool(CuminClass):
     def __init__(self, model):
         super(CuminPool, self).__init__(model, "pool", Pool)
@@ -1849,27 +1856,30 @@
         prop.title = "Collector ID"
         prop.summary = True
 
-        stat = CuminStat(self, "Running")
+        stat = self.PercentStat(self, "Running")
         stat.title = "Running Jobs"
 
-        stat = CuminStat(self, "Completed")
+        stat = self.PercentStat(self, "Completed")
         stat.title = "Completed Jobs"
 
-        stat = CuminStat(self, "Idle")
+        stat = self.PercentStat(self, "Idle")
         stat.title = "Idle Jobs"
 
-        stat = CuminStat(self, "Held")
+        stat = self.PercentStat(self, "Held")
         stat.title = "Held Jobs"
 
-        stat = CuminStat(self, "Removed")
+        stat = self.PercentStat(self, "Removed")
         stat.title = "Removed Jobs"
 
-        stat = CuminStat(self, "Jobs")
+        stat = self.PercentStat(self, "Jobs")
         stat.title = "Total Jobs"
 
         action = self.VisJobs(self, "jobs")
         action.navigable = False
 
+        action = self.VisSlots(self, "slots")
+        action.navigable = False
+
     def init(self):
         self.frame = self.model.frame.pool
 
@@ -1884,6 +1894,102 @@
 
         return title
 
+    class PercentStat(CuminStat):
+        def value_text(self, pool):
+            state = self.name
+
+            if state == "Jobs":
+                return str(Job.select().count())
+            value = self.get_value(pool, state)
+            return str(value)
+            
+        def get_value(self, pool, state):
+            elems = list()
+            istate = JobStatusInfo.get_status_int(state)
+            elems.append("job_status = %i" % istate)
+            elems.append("s.pool = '%s'" % pool.id)
+    
+            # manually removed jobs will have a state of Idle
+            # with a deletion_time
+            if state == "Idle":
+                elems.append("job.deletion_time is null")
+            where = " and ".join(elems)
+    
+            # manually removed jobs will have a state of Idle
+            # with a deletion_time
+            if state == "Removed":
+                removed = "(job.deletion_time is not null and job_status = %i)" % JobStatusInfo.get_status_int("Idle") 
+                where = " or ".join((where, removed))
+                
+            jn = "inner join scheduler as s on s.id = scheduler_id"
+            return Job.select(where, join=jn).count()
+    
+        def rate_text(self, pool):
+            state = self.name
+            return self.get_item_rate(pool, state)
+            
+        def get_item_rate(self, pool, state):
+            jobs = Job.select().count()
+
+            if state == "Jobs":
+                value = jobs
+            else:
+                value = self.get_value(pool, state)
+            if jobs:
+                percent = (value*1.0) / (jobs*1.0) * 100.0
+            return jobs and "%2.2f" % percent or "-"
+        
+    class VisSlots(CuminAction):
+        # list of status/colors in the order we want them displayed
+        # in the legend
+        load_colors = [("Idle", "clear"), 
+                       ("Busy", "green"),
+                       ("Suspended", "red"),
+                       ("Vacating", "red"),
+                       ("Killing", "blue"),
+                       ("Benchmarking", "yellow")]
+
+        def __init__(self, cls, name):
+            super(CuminPool.VisSlots, self).__init__(cls, name)
+            
+            self.slot_set = self.ModelPoolSlotSet(cls.model.app, name)
+            
+        def get_xml_response(self, session, pool, *args):
+            slots = self.get_slots(session, pool)
+            writer = Writer()
+            writer.write("<slots>")
+            for slot in slots:
+                writer.write("<slot id='%i' name='%s' machine='%s' job='%s' color='%s'/>" % \
+                    (slot["id"], 
+                     slot["name"],
+                     slot["machine"], 
+                     slot["job_id"], 
+                     self.get_color(slot)))
+            writer.write("</slots>")
+            return writer.to_string()
+
+        def get_slots(self, session, pool):
+            cursor = self.slot_set.do_get_items(session, pool)
+            slot_list = self.slot_set.cursor_to_rows(cursor)
+            return slot_list
+
+        class ModelPoolSlotSet(PoolSlotSet):
+            def render_sql_limit(self, session, *args):
+                pass
+            
+            def render_sql_orderby(self, session, *args):
+                return "order by name asc"
+
+        def get_color(self, slot):
+            activity = slot["activity"]
+            for status, color in self.load_colors:
+                if status == activity:
+                    return color
+            return "black"  
+
+        def get_colors(self):
+            return self.load_colors
+        
     class VisJobs(CuminAction):
         def __init__(self, cls, name):
             super(CuminPool.VisJobs, self).__init__(cls, name)
@@ -1891,7 +1997,6 @@
             self.job_set = self.ModelSystemJobSet(cls.model.app, name)
             
         def get_xml_response(self, session, pool, *args):
-            pool = self.model.get_main_pool()
             jobs = self.get_jobs(session, pool)
             writer = Writer()
             writer.write("<jobs>")




More information about the rhmessaging-commits mailing list