Author: eallen
Date: 2008-12-10 15:03:04 -0500 (Wed, 10 Dec 2008)
New Revision: 2966
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.strings
Log:
Make pool status (x of x active) auto update using model.xml
Modified: mgmt/trunk/cumin/python/cumin/model.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/model.py 2008-12-10 20:00:18 UTC (rev 2965)
+++ mgmt/trunk/cumin/python/cumin/model.py 2008-12-10 20:03:04 UTC (rev 2966)
@@ -4,6 +4,7 @@
from mint.schema import *
from parameters import *
from pool import PoolSlotSet, PoolMachineSet, PoolJobStats
+from slot import SlotStatSet
from struct import unpack, calcsize
from system import SystemSlotSet
from time import *
@@ -1898,6 +1899,12 @@
stat = self.PercentStat(self, "total")
stat.title = "Total Jobs"
+ stat = self.StatusStat(self, "active")
+ stat.category = "status"
+
+ stat = self.StatusStat(self, "all")
+ stat.category = "status"
+
action = self.PoolSlotVisualization(self, "slots")
action.navigable = False
@@ -1909,7 +1916,10 @@
self.fake_stats = self.FakeJobStats(self, "fakestats")
self.fake_stats.navigable = False
-
+
+ self.status = self.PoolStatus(self, "poolstatus")
+ self.status.navigable = False
+
def init(self):
self.frame = self.model.frame.pool
@@ -1935,18 +1945,33 @@
branch = session.branch()
self.model.frame.view.show(branch)
return branch.marshal()
-
+
def write_stat_xml(self, session, writer, object):
- record = self.fake_stats.get_stat_record(session, object)
+ record = self.fake_stats.get_stat_record(session, object)
for stat in self.stats:
- stat.write_xml(writer, record)
+ if stat.category == "general":
+ stat.write_xml(writer, record)
+ record = self.status.get_stat_record(session, object)
+ for stat in self.stats:
+ if stat.category == "status":
+ stat.write_xml(writer, record)
+
+ class StatusStat(CuminStat):
+ def value_text(self, record):
+ state = self.name
+ value = record[state]
+ return str(value)
+
+ def rate_text(self, record):
+ return ""
+
class PercentStat(CuminStat):
def value_text(self, record):
state = self.name
value = record[state]
return str(value)
-
+
def rate_text(self, record):
state = self.name
value = record[state]
@@ -1954,7 +1979,7 @@
if total:
percent = float(value) / float(total) * 100.0
return total and "%2.2f" % percent or "-"
-
+
class PoolSlotVisualization(SlotVisualization):
def __init__(self, cls, name):
super(CuminPool.PoolSlotVisualization, self).__init__(cls, name)
@@ -2000,13 +2025,13 @@
if machine:
values["machine"] = machine
return values
-
+
def render_sql_limit(self, session, *args):
pass
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)
@@ -2016,7 +2041,31 @@
def get_stat_record(self, session, pool):
cursor = self.itemset.get_items(session, pool)
return self.itemset.cursor_to_rows(cursor)[0]
-
+
+ class PoolStatus(CuminAction):
+ def __init__(self, cls, name):
+ super(CuminPool.PoolStatus, self).__init__(cls, name)
+
+ self.itemset = self.StatusPoolSlotSet(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 StatusPoolSlotSet(SlotStatSet):
+ def render_sql_where(self, session, pool):
+ elems = list()
+ elems.append("s.pool = %(pool)s")
+ recent = self.get_recent_sql_where(session)
+ if recent:
+ elems.append(recent)
+
+ return "where %s" % " and ".join(elems)
+
+ def get_sql_values(self, session, pool):
+ values = {"pool": pool.id}
+ return values
+
class VisMachine(Visualization):
load_colors = [("Idle", "clear"),
("> 0%", "green"),
Modified: mgmt/trunk/cumin/python/cumin/pool.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/pool.py 2008-12-10 20:00:18 UTC (rev 2965)
+++ mgmt/trunk/cumin/python/cumin/pool.py 2008-12-10 20:03:04 UTC (rev 2966)
@@ -194,7 +194,7 @@
def render_script(self, session, pool):
data = "model.xml?class=pool;id=%s" % pool.id
- return "wooly.setIntervalUpdate('%s', updatePool, 6000)" %
data
+ return "wooly.setIntervalUpdate('%s', updatePool, 4000)" %
data
def set_collector_tab(self, session):
self.__tabs.set_selected_mode(session, self.colls)
@@ -492,33 +492,12 @@
return values
class PoolStatus(CuminStatus):
- def __init__(self, app, name):
- super(PoolStatus, self).__init__(app, name)
-
- self.slotset = self.StatusPoolSlotSet(app, "status")
-
def render_title(self, session, pool):
return "Pool Status"
def render_status(self, session, pool):
- cursor = self.slotset.get_items(session, pool)
- slot_list = self.slotset.cursor_to_rows(cursor)
- # should be only one record
- data = slot_list[0]
- idle = data["idle"]
- total = data["total"]
- return "%i of %i slots active" % (total - idle, total)
+ action = self.app.model.pool.poolstatus
+ record = action.get_stat_record(session, pool)
- class StatusPoolSlotSet(SlotStatSet):
- def render_sql_where(self, session, pool):
- elems = list()
- elems.append("s.pool = %(pool)s")
- recent = self.get_recent_sql_where(session)
- if recent:
- elems.append(recent)
-
- return "where %s" % " and ".join(elems)
-
- def get_sql_values(self, session, pool):
- values = {"pool": pool.id}
- return values
+ return "<div><span>%i</span> of
<span>%i</span> active</div>" % \
+ (record["active"], record["all"])
Modified: mgmt/trunk/cumin/python/cumin/pool.strings
===================================================================
--- mgmt/trunk/cumin/python/cumin/pool.strings 2008-12-10 20:00:18 UTC (rev 2965)
+++ mgmt/trunk/cumin/python/cumin/pool.strings 2008-12-10 20:03:04 UTC (rev 2966)
@@ -51,12 +51,27 @@
//throw new Error();
}
+
+[PoolStatus.javascript]
+function updatePoolStatus(id, pool) {
+
+ var s = pool.stat;
+ var sdata = {"div": {"span": [s.active.value, s.all.value]}};
+
+ wooly.doc().elembyid(id).update(sdata);
+}
+
[PoolStatus.html]
<div id="{id}" class="CuminStatus {color}">
<h2>{title}</h2>
- <div>{status}</div>
+ {status}
</div>
+<script type="text/javascript">
+<![CDATA[
+ cumin.objectListeners["{id}"] = updatePoolStatus;
+]]>
+</script>
[PoolStats.css]
div.vistats {
Modified: mgmt/trunk/cumin/python/cumin/slot.strings
===================================================================
--- mgmt/trunk/cumin/python/cumin/slot.strings 2008-12-10 20:00:18 UTC (rev 2965)
+++ mgmt/trunk/cumin/python/cumin/slot.strings 2008-12-10 20:03:04 UTC (rev 2966)
@@ -20,8 +20,8 @@
[SlotStatSet.sql]
select
- sum(case activity when 'Idle' then 1 else 0 end) as idle,
- sum(1) as total
+ sum(case activity when 'Idle' then 0 else 1 end) as active,
+ sum(1) as all
from (select
s.name,
s.pool,