Author: eallen
Date: 2009-05-11 15:43:07 -0400 (Mon, 11 May 2009)
New Revision: 3375
Modified:
mgmt/trunk/cumin/python/cumin/grid/pool.py
mgmt/trunk/cumin/python/cumin/inventory/system.py
mgmt/trunk/cumin/python/cumin/model.py
mgmt/trunk/cumin/python/cumin/stat.py
mgmt/trunk/cumin/python/cumin/visualizations.py
Log:
Moved visualizations out of model
Modified: mgmt/trunk/cumin/python/cumin/grid/pool.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/grid/pool.py 2009-05-11 14:17:45 UTC (rev 3374)
+++ mgmt/trunk/cumin/python/cumin/grid/pool.py 2009-05-11 19:43:07 UTC (rev 3375)
@@ -19,6 +19,8 @@
from limit import LimitsSet, LimitsFrame
from slot import SlotSet, SlotStatSet, SlotFrame
+import cumin.model
+
strings = StringCatalog(__file__)
log = logging.getLogger("cumin.pool")
@@ -287,6 +289,21 @@
def filter(self, session, system, slots):
return slots
+class PoolVisualization(PoolSlotSet):
+ def __init__(self, vis, app, name):
+ super(PoolVisualization, self).__init__(app, name)
+ vis.add_visualization(self, name)
+
+ def get_info(self, session, id):
+ pool = model.Pool.get(id)
+ return self.get_items(session, pool)
+
+ def render_sql_limit(self, session, *args):
+ pass
+
+ def render_sql_orderby(self, session, *args):
+ return "order by machine, name asc"
+
class PoolStats(Widget):
def __init__(self, app, name):
super(PoolStats, self).__init__(app, name)
Modified: mgmt/trunk/cumin/python/cumin/inventory/system.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/inventory/system.py 2009-05-11 14:17:45 UTC (rev 3374)
+++ mgmt/trunk/cumin/python/cumin/inventory/system.py 2009-05-11 19:43:07 UTC (rev 3375)
@@ -201,11 +201,8 @@
def get_args(self, session):
return self.frame.get_args(session)
- def render_title(self, 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_title(self, session, *args):
+ return "Grid Slots %s" % fmt_count(self.get_item_count(session,
*args))
def render_sql_where(self, session, system):
elems = list()
@@ -219,6 +216,21 @@
def get_sql_values(self, session, system):
return {"nodeName": system.nodeName}
+class SystemVisualization(SystemSlotSet):
+ def __init__(self, vis, app, name):
+ super(SystemVisualization, self).__init__(app, name)
+ vis.add_visualization(self, name)
+
+ def get_info(self, session, id):
+ system = Sysimage.get(id)
+ return self.get_items(session, system)
+
+ def render_sql_limit(self, session, *args):
+ pass
+
+ def render_sql_orderby(self, session, *args):
+ return "order by machine, name asc"
+
class SystemServices(ItemSet):
def render_title(self, session, *args):
return "Services"
Modified: mgmt/trunk/cumin/python/cumin/model.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/model.py 2009-05-11 14:17:45 UTC (rev 3374)
+++ mgmt/trunk/cumin/python/cumin/model.py 2009-05-11 19:43:07 UTC (rev 3375)
@@ -8,9 +8,8 @@
from wooly.widgets import *
from grid.job import *
-from grid.pool import PoolSlotSet, PoolJobStats
+from grid.pool import PoolJobStats
from grid.slot import SlotStatSet
-from inventory.system import SystemSlotSet
from formats import *
from parameters import *
from util import *
@@ -218,7 +217,6 @@
self.summary = False
self.navigable = True
self.aggregate = False
- self.visualization = False
self.cumin_class.add_action(self)
@@ -547,11 +545,6 @@
def get_object_name(self, object):
return object.name
- def get_visualization_action(self):
- for action in self.actions:
- if action.visualization:
- return action
-
def write_event_xml(self, writer, object):
writer.write("<events errors=\"%i\"
warnings=\"%i\"/>" % (0, 0))
@@ -705,19 +698,6 @@
def get_object_name(self, slot):
return slot.Name
-class Visualization(CuminAction):
- def __init__(self, cls, name):
- super(Visualization, self).__init__(cls, name)
-
- self.itemset = None
-
- def get_boxes(self, session, object):
- if self.itemset:
- box_list = self.itemset.get_items(session, object)
- return box_list
- else:
- return ()
-
class CuminSystem(RemoteClass):
def __init__(self, model):
super(CuminSystem, self).__init__(model, "system", Sysimage,
SysimageStats)
@@ -767,10 +747,6 @@
stat = CuminStat(self, "procRunning")
stat.title = "Running processes"
- action = self.SystemSlotVisualization(self, "slots")
- action.navigable = False
- action.visualization = True
-
#action = CuminAction(self, "ping")
#action.title = "Send Ping"
#action.summary = True
@@ -793,24 +769,6 @@
text = value and "%0.2f" % value or ""
return text
- class SystemSlotVisualization(Visualization):
- def __init__(self, cls, name):
- 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):
- pass
-
- def render_sql_orderby(self, session, *args):
- return "order by machine, name asc"
-
class CuminMaster(RemoteClass):
def __init__(self, model):
super(CuminMaster, self).__init__(model, "master", Master,
MasterStats)
@@ -1993,40 +1951,15 @@
prop.title = "Collector"
prop.summary = True
- stat = self.PercentStat(self, "running")
- stat.title = "Running Jobs"
-
- stat = self.PercentStat(self, "completed")
- stat.title = "Completed Jobs"
-
- stat = self.PercentStat(self, "idle")
- stat.title = "Idle Jobs"
-
- stat = self.PercentStat(self, "held")
- stat.title = "Held Jobs"
-
- stat = self.PercentStat(self, "removed")
- stat.title = "Removed Jobs"
-
- stat = self.PercentStat(self, "total")
- stat.title = "Total Jobs"
-
stat = self.StatusStat(self, "idl")
stat.category = "status"
stat = self.StatusStat(self, "all")
stat.category = "status"
- action = self.PoolSlotVisualization(self, "slots")
- action.navigable = False
- action.visualization = True
-
action = self.SeeAllPools(self, "allpools")
action.summary = True
- self.fake_stats = self.FakeJobStats(self, "fakestats")
- self.fake_stats.navigable = False
-
self.status = self.PoolStatus(self, "poolstatus")
self.status.navigable = False
@@ -2078,64 +2011,6 @@
def rate_text(self, record):
return ""
- class PercentStat(CuminStat):
- def value_text(self, record):
- if record:
- state = self.name
- value = record[state]
- return str(value)
- return ""
-
- def rate_text(self, record):
- if record:
- state = self.name
- value = record[state]
- total = record["total"]
- if total:
- percent = float(value) / float(total) * 100.0
- return total and "%2.2f" % percent or "-"
- return ""
-
- class PoolSlotVisualization(Visualization):
- def __init__(self, cls, name):
- super(CuminPool.PoolSlotVisualization, self).__init__(cls, name)
-
- self.itemset = self.ModelPoolSlotSet(cls.model.app, "slot")
- self.itemset.items.path = "CuminPool.PoolSlotVisualization.slot"
-
- class ModelPoolSlotSet(PoolSlotSet):
- 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
-
- 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)
-
- 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)
- if len(rows):
- return rows[0]
-
class PoolStatus(CuminAction):
def __init__(self, cls, name):
super(CuminPool.PoolStatus, self).__init__(cls, name)
Modified: mgmt/trunk/cumin/python/cumin/stat.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/stat.py 2009-05-11 14:17:45 UTC (rev 3374)
+++ mgmt/trunk/cumin/python/cumin/stat.py 2009-05-11 19:43:07 UTC (rev 3375)
@@ -10,6 +10,7 @@
from formats import *
import tempfile
from datetime import timedelta, datetime
+from visualizations import CuminVisualization
strings = StringCatalog(__file__)
@@ -222,7 +223,9 @@
def __init__(self, app, name):
super(SlotMapPage, self).__init__(app, name)
- self.class_ = CuminClassParameter(app, "class")
+ self.vis = CuminVisualization(app)
+
+ self.class_ = Parameter(app, "class")
self.add_parameter(self.class_)
self.id = IntegerParameter(app, "id")
@@ -249,10 +252,10 @@
return "no-cache"
def get_args(self, session):
- cls = self.class_.get(session)
- if cls:
+ name = self.class_.get(session)
+ if name:
id = self.id.get(session)
- return (cls.mint_class.get(id),)
+ return (self.vis.get_itemset_by_name(name),)
else:
return (None,)
@@ -284,9 +287,7 @@
#print "starting rendering png at zoom %i, x %i, y %i" % (zl, zx, zy)
map = HeatMapChart(self.max_width, self.max_width)
- cls = self.class_.get(session)
- action = cls.get_visualization_action()
- slot_info = action.get_boxes(session, object)
+ slot_info = object.get_info(session, self.id.get(session))
if len(slot_info) == 0:
return ""
@@ -315,7 +316,7 @@
def __gen_filename(self, session, zl):
cls = self.class_.get(session)
id = self.id.get(session)
- return "-".join((cls.cumin_name, str(id), str(zl)))
+ return "-".join((cls, str(id), str(zl)))
def set_cookie(self, session, args):
cookie = "|".join((str(x) for x in args))
Modified: mgmt/trunk/cumin/python/cumin/visualizations.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/visualizations.py 2009-05-11 14:17:45 UTC (rev 3374)
+++ mgmt/trunk/cumin/python/cumin/visualizations.py 2009-05-11 19:43:07 UTC (rev 3375)
@@ -124,8 +124,9 @@
if info_index is not None:
#print "rendering slot info for %i" % info_index
cls = self.app.model.get_class_by_object(object)
- action = cls.get_visualization_action()
- slot_info = action.get_boxes(session, object)
+ vis = CuminVisualization(self.app)
+ itemset = vis.get_itemset_by_name(cls.cumin_name)
+ slot_info = itemset.get_info(session, object.id)
writer = Writer()
self.info_div_tmpl.render(writer, session, slot_info[info_index])
return writer.to_string()
@@ -153,3 +154,20 @@
def render_row_class(self, session, item):
return item[0] == "jid" and "class='hidden_row'"
or ""
+
+class CuminVisualization(object):
+ def __init__(self, app):
+ self.app = app
+ self.itemsets = dict()
+
+ from grid.pool import PoolVisualization
+ from inventory.system import SystemVisualization
+ PoolVisualization(self, app, "pool")
+ SystemVisualization(self, app, "system")
+
+ def get_itemset_by_name(self, name):
+ if name in self.itemsets:
+ return self.itemsets[name]
+
+ def add_visualization(self, itemset, name):
+ self.itemsets[name] = itemset