Author: eallen
Date: 2008-12-05 14:09:53 -0500 (Fri, 05 Dec 2008)
New Revision: 2936
Modified:
mgmt/trunk/cumin/python/cumin/model.py
mgmt/trunk/cumin/python/cumin/pool.py
mgmt/trunk/cumin/python/cumin/pool.strings
Log:
Consolidated pool job stats into a single query.
Modified: mgmt/trunk/cumin/python/cumin/model.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/model.py 2008-12-05 17:53:11 UTC (rev 2935)
+++ mgmt/trunk/cumin/python/cumin/model.py 2008-12-05 19:09:53 UTC (rev 2936)
@@ -3,7 +3,7 @@
from job import *
from mint.schema import *
from parameters import *
-from pool import PoolSlotSet, PoolMachineSet
+from pool import PoolSlotSet, PoolMachineSet, PoolJobStats
from struct import unpack, calcsize
from system import SystemSlotSet
from time import *
@@ -106,7 +106,7 @@
return count
- def write_xml(self, writer, objects):
+ def write_xml(self, session, writer, objects):
writer.write("<model>")
pcount = self.count_invocations("pending")
@@ -119,7 +119,7 @@
for object in objects:
cls = self.get_class_by_object(object)
- cls.write_xml(writer, object)
+ cls.write_xml(session, writer, object)
writer.write("</model>")
@@ -495,17 +495,17 @@
def write_event_xml(self, writer, object):
writer.write("<events errors=\"%i\"
warnings=\"%i\"/>" % (0, 0))
- def write_stat_xml(self, writer, object):
+ def write_stat_xml(self, session, writer, object):
for stat in self.stats:
stat.write_xml(writer, object)
- def write_xml(self, writer, object):
+ def write_xml(self, session, writer, object):
writer.write("<%s id=\"%s\" name=\"%s\">" %
\
(self.cumin_name, str(object.id),
self.get_object_name(object)))
self.write_event_xml(writer, object)
- self.write_stat_xml(writer, object)
+ self.write_stat_xml(session, writer, object)
writer.write("</%s>" % self.cumin_name)
@@ -1880,22 +1880,22 @@
prop.title = "Collector ID"
prop.summary = True
- stat = self.PercentStat(self, "Running")
+ stat = self.PercentStat(self, "running")
stat.title = "Running Jobs"
- stat = self.PercentStat(self, "Completed")
+ stat = self.PercentStat(self, "completed")
stat.title = "Completed Jobs"
- stat = self.IdlePercentStat(self, "Idle")
+ stat = self.PercentStat(self, "idle")
stat.title = "Idle Jobs"
- stat = self.PercentStat(self, "Held")
+ stat = self.PercentStat(self, "held")
stat.title = "Held Jobs"
- stat = self.RemovedPercentStat(self, "Removed")
+ stat = self.PercentStat(self, "removed")
stat.title = "Removed Jobs"
- stat = self.JobsPercentStat(self, "Jobs")
+ stat = self.PercentStat(self, "total")
stat.title = "Total Jobs"
action = self.PoolSlotVisualization(self, "slots")
@@ -1904,6 +1904,9 @@
action = self.VisMachine(self, "machines")
action.navigable = False
+ self.fake_stats = self.FakeJobStats(self, "fakestats")
+ self.fake_stats.navigable = False
+
def init(self):
self.frame = self.model.frame.pool
@@ -1933,78 +1936,26 @@
</ul>"""
return html % (href, self.title)
+
+ def write_stat_xml(self, session, writer, object):
+ record = self.fake_stats.get_stat_record(session, object)
+ for stat in self.stats:
+ stat.write_xml(writer, record)
+
class PercentStat(CuminStat):
- def value_text(self, pool):
+ def value_text(self, record):
state = self.name
- value = self.get_value(pool, state)
+ value = record[state]
return str(value)
- def get_sql_and_elem(self):
- pass
-
- def get_sql_or_elem(self):
- pass
-
- def get_status_elem(self, state):
- istate = JobStatusInfo.get_status_int(state)
- return "job_status = %i" % istate
-
- def get_value(self, pool, state):
- elems = list()
- status_elem = self.get_status_elem(state)
- if status_elem:
- elems.append(status_elem)
-
- and_elem = self.get_sql_and_elem()
- if and_elem:
- elems.append(and_elem)
-
- or_elem = self.get_sql_or_elem()
-
- return self.do_select(pool, elems, or_elem)
-
- def do_select(self, pool, and_elems, or_elem):
- and_elems.append("s.pool = '%s'" % pool.id)
- where = " and ".join(and_elems)
-
- if or_elem:
- where = " or ".join((where, or_elem))
-
- jn = "inner join scheduler as s on s.id = scheduler_id"
- return Job.select(where, join=jn).count()
-
- def rate_text(self, pool):
+ def rate_text(self, record):
state = self.name
- return self.get_item_rate(pool, state)
+ value = record[state]
+ total = record["total"]
+ if total:
+ percent = float(value) / float(total) * 100.0
+ return total and "%2.2f" % percent or "-"
- def get_item_rate(self, pool, state):
- jobs = self.do_select(pool, list(), None)
-
- value = self.get_value(pool, state)
- if jobs:
- percent = float(value) / float(jobs) * 100.0
- return jobs and "%2.2f" % percent or "-"
-
-
- class JobsPercentStat(PercentStat):
- def get_status_elem(self, state):
- return None
-
- def rate_text(self, pool):
- return "100.00"
-
- class IdlePercentStat(PercentStat):
- def get_sql_and_elem(self):
- # manually removed jobs will have a state of Idle
- # with a qmf_delete_time
- return "job.qmf_delete_time is null"
-
- class RemovedPercentStat(PercentStat):
- def get_sql_or_elem(self):
- # if a job is idle, but has a qmf_delete_time, it's actually Removed
- return "(job.qmf_delete_time is not null and job_status = %i)" %
\
- JobStatusInfo.get_status_int("Idle")
-
class PoolSlotVisualization(SlotVisualization):
def __init__(self, cls, name):
super(CuminPool.PoolSlotVisualization, self).__init__(cls, name)
@@ -2057,7 +2008,16 @@
def render_sql_orderby(self, session, *args):
return "order by machine, name asc"
+ class FakeJobStats(CuminAction):
+ def __init__(self, cls, name):
+ super(CuminPool.FakeJobStats, self).__init__(cls, name)
+ self.itemset = PoolJobStats(cls.model.app, "stats")
+
+ def get_stat_record(self, session, pool):
+ cursor = self.itemset.get_items(session, pool)
+ return self.itemset.cursor_to_rows(cursor)[0]
+
class VisMachine(Visualization):
load_colors = [("Idle", "clear"),
("> 0%", "green"),
@@ -2855,7 +2815,7 @@
for id in self.__ids.get(session):
objects.append(cls.mint_class.get(id))
- self.app.model.write_xml(writer, objects)
+ self.app.model.write_xml(session, writer, objects)
return writer.to_string()
Modified: mgmt/trunk/cumin/python/cumin/pool.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/pool.py 2008-12-05 17:53:11 UTC (rev 2935)
+++ mgmt/trunk/cumin/python/cumin/pool.py 2008-12-05 19:09:53 UTC (rev 2936)
@@ -194,7 +194,7 @@
def render_script(self, session, pool):
data = "model.xml?class=pool;id=%s" % pool.id
- return "wooly.setIntervalUpdate('%s', updatePool, 3000)" %
data
+ return "wooly.setIntervalUpdate('%s', updatePool, 6000)" %
data
def set_collector_tab(self, session):
self.__tabs.set_selected_mode(session, self.colls)
@@ -468,7 +468,29 @@
class PoolStatSet(StatSet):
def render_rate_text(self, session, args):
return "Percentage"
+
+ def do_get_items(self, session, pool):
+ stats = super(PoolStatSet, self).do_get_items(session, pool)
+ action = self.app.model.pool.fakestats
+ record = action.get_stat_record(session, pool)
+
+ fake_stats = list()
+ for stat in stats:
+ fake_stats.append((stat[0], record))
+
+ return fake_stats
+
+class PoolJobStats(CuminTable):
+ def render_sql_where(self, session, pool):
+ elems = list()
+ elems.append("s.pool = %(pool)s")
+ return "where %s" % " and ".join(elems)
+
+ def get_sql_values(self, session, pool):
+ values = {"pool": pool.id}
+ return values
+
class PoolStatus(CuminStatus):
def __init__(self, app, name):
super(PoolStatus, self).__init__(app, name)
Modified: mgmt/trunk/cumin/python/cumin/pool.strings
===================================================================
--- mgmt/trunk/cumin/python/cumin/pool.strings 2008-12-05 17:53:11 UTC (rev 2935)
+++ mgmt/trunk/cumin/python/cumin/pool.strings 2008-12-05 19:09:53 UTC (rev 2936)
@@ -16,6 +16,24 @@
from
(select 1 from collector group by pool) as l
+[PoolJobStats.sql]
+select
+ sum( case when job_status=2 then 1 else 0 end) as running,
+ sum( case when job_status=4 then 1 else 0 end) as completed,
+ sum( case when job_status=5 then 1 else 0 end) as held,
+ sum( case when job_status=1 and j.qmf_delete_time is null then 1 else 0 end) as idle,
+ sum( case when job_status=3 or (job_status=1 and j.qmf_delete_time is not null) then 1
else 0 end) as removed,
+ sum( 1 ) as total,
+ s.pool
+from job as j
+left outer join scheduler as s on s.id = j.scheduler_id
+{sql_where}
+group by s.pool
+
+[PoolJobStats.count_sql]
+1
+
+
[PoolView.javascript]
function updatePool(data) {
var model = data.objectify();