Author: eallen
Date: 2008-10-31 17:22:45 -0400 (Fri, 31 Oct 2008)
New Revision: 2720
Modified:
mgmt/trunk/cumin/python/cumin/model.py
mgmt/trunk/cumin/python/cumin/pool.py
mgmt/trunk/cumin/python/cumin/slot.py
mgmt/trunk/cumin/python/cumin/slot.strings
mgmt/trunk/cumin/python/cumin/stat.py
mgmt/trunk/cumin/python/cumin/stat.strings
mgmt/trunk/cumin/python/cumin/system.py
mgmt/trunk/cumin/python/cumin/system.strings
mgmt/trunk/cumin/python/cumin/util.py
Log:
During an ajax call, model will now use the appropriate SQLTable object to get it's
list of records instead of constructing it's own SQL.
Modified: mgmt/trunk/cumin/python/cumin/model.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/model.py 2008-10-31 21:18:52 UTC (rev 2719)
+++ mgmt/trunk/cumin/python/cumin/model.py 2008-10-31 21:22:45 UTC (rev 2720)
@@ -549,6 +549,7 @@
stat.title = "Load Avg"
stat.category = "general"
+from system import SystemSlotSet
class CuminSystem(RemoteClass):
def __init__(self, model):
super(CuminSystem, self).__init__(model, "system", System,
SystemStats)
@@ -598,30 +599,40 @@
"Vacating": "red",
"Killing": "blue",
"Benchmarking": "yellow" }
- def do_invoke(self, system, *args):
- slots = self.get_slots(system)[0]
+
+ def __init__(self, cls, name):
+ super(CuminSystem.VisSlots, self).__init__(cls, name)
+
+ self.slot_set = self.ModelSystemSlotSet(cls.model.app, name)
+
+ def get_xml_response(self, session, system, *args):
+ slots = self.get_slots(session, system)[0]
writer = Writer()
writer.write("<slots>")
for slot in slots:
writer.write("<slot id='%i' name='%s'
machine='%s' job='%s' color='%s'/>" % \
- (slot.sourceObjectId,
- slot.Name,
- slot.Machine,
- slot.JobId,
+ (slot["id"],
+ slot["name"],
+ slot["machine"],
+ slot["job_id"],
self.get_color(slot)))
writer.write("</slots>")
return writer.to_string()
- def get_slots(self, system):
- elems = list()
- elems.append("machine = '%s'" % system.nodeName)
- elems.append("rec_time > now() - interval '90
minutes'")
- elems.append("deletion_time is null")
- sql = " and ".join(elems)
- return (Slot.select(sql), )
+ def get_slots(self, session, system):
+ cursor = self.slot_set.do_get_items(session, system)
+ slot_list = self.slot_set.cursor_to_rows(cursor)
+ return (slot_list, )
+ class ModelSystemSlotSet(SystemSlotSet):
+ 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.statsCurr.Activity
+ activity = slot["activity"]
if activity in self.load_colors:
return self.load_colors[activity]
return "black"
@@ -1772,6 +1783,7 @@
self.id = self.collector.Pool
self.name = self.collector.Name
+from job import JobSet
class CuminPool(CuminClass):
def __init__(self, model):
super(CuminPool, self).__init__(model, "pool", Pool)
@@ -1816,34 +1828,42 @@
return title
class VisJobs(CuminAction):
- def do_invoke(self, pool, *args):
+ def __init__(self, cls, name):
+ super(CuminPool.VisJobs, self).__init__(cls, name)
+
+ 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(pool)[0]
+ jobs = self.get_jobs(session, pool)[0]
writer = Writer()
writer.write("<jobs>")
for job in jobs:
status = self.get_status(job)
writer.write("<job id='%i' name='%s'
submitter='%s' status='%s' color='%s'/>" % \
- (job.sourceObjectId,
- job.CustomId,
- job.submitter.Name,
+ (job["id"],
+ job["custom_id"],
+ job["submitter"],
JobStatusInfo.get_status_string(status),
self.get_color(job)))
writer.write("</jobs>")
return writer.to_string()
- def get_jobs(self, pool):
- elems = list()
- #elems.append("job.rec_time > now() - interval '90
minutes'")
- #elems.append("job.deletion_time is null and job_status != %i" %
JobStatusInfo.get_status_int("Removed"))
- elems.append("s.pool = '%s'" % pool.id)
- sql = " and ".join(elems)
- jn = "inner join scheduler as s on s.id = scheduler_id"
- return (Job.select(sql, join=jn).orderBy("custom_id"), )
+ def get_jobs(self, session, pool):
+ cursor = self.job_set.do_get_items(session, pool)
+ job_list = self.job_set.cursor_to_rows(cursor)
+ return (job_list, )
+ class ModelSystemJobSet(JobSet):
+ def render_sql_limit(self, session, *args):
+ pass
+
+ def render_sql_orderby(self, session, *args):
+ return "order by custom_id asc"
+
def get_status(self, job):
- status = job.JobStatus
- if status != JobStatusInfo.get_status_int("Completed") and
job.deletionTime:
+ status = job["job_status"]
+ if status != JobStatusInfo.get_status_int("Completed") and
job["deletion_time"]:
status = JobStatusInfo.get_status_int("Removed")
return status
@@ -2194,7 +2214,7 @@
return self.job_ads
class Fetch(CuminAction):
- def do_invoke(self, job, *args):
+ def get_xml_response(self, session, job, *args):
file, start, end, tail = args
self.job_output = None
self.got_data = False
@@ -2337,6 +2357,9 @@
prop.title = "Machine"
prop.summary = True
+ prop = CuminProperty(self, "System")
+ prop.title = "System"
+
stat = CuminStat(self, "NumUsers")
stat.title = "Users"
@@ -2552,7 +2575,7 @@
return "Stop"
class GetLimitCount(CuminAction):
- def do_invoke(self, negotiator):
+ def get_xml_response(self, session, negotiator):
action = self.model.negotiator.GetLimits
limits = action.do_invoke(negotiator)
error = "False"
@@ -2656,7 +2679,7 @@
for action in cls.actions:
if action.name == method:
args = xargs and xargs.split("&") or list()
- data = action.do_invoke(object, *args)
+ data = action.get_xml_response(session, object, *args)
self.write_xml(writer, data)
return writer.to_string()
Modified: mgmt/trunk/cumin/python/cumin/pool.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/pool.py 2008-10-31 21:18:52 UTC (rev 2719)
+++ mgmt/trunk/cumin/python/cumin/pool.py 2008-10-31 21:22:45 UTC (rev 2720)
@@ -262,14 +262,11 @@
def get_args(self, session):
pool = self.frame.get_args(session)[0]
action = self.app.model.pool.jobs
- return action.get_jobs(pool)
+ return action.get_jobs(session, pool)
def render_title(self, session, jobs):
return ""
- def get_object_count(self, session, jobs):
- return jobs.count()
-
def render_override_style(self, session, jobs):
count = self.get_object_count(session, jobs)
if count > 100:
@@ -287,11 +284,12 @@
return ""
def render_cell_id(self, session, count, job):
- return "%i" % job.sourceObjectId
+ return "%i" % job["id"]
def render_href(self, session, count, job):
branch = session.branch()
- return self.page.main.pool.job.get_href(branch, job)
+ ojob = Job.get(job["id"])
+ return self.page.main.pool.job.get_href(branch, ojob)
def get_url(self, session):
pool = self.parent.frame.get_args(session)[0]
Modified: mgmt/trunk/cumin/python/cumin/slot.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/slot.py 2008-10-31 21:18:52 UTC (rev 2719)
+++ mgmt/trunk/cumin/python/cumin/slot.py 2008-10-31 21:22:45 UTC (rev 2720)
@@ -17,7 +17,21 @@
col = self.Name(app, "name")
self.add_column(col)
+
+ col = self.Machine(app, "machine")
+ self.add_column(col)
+ col = self.System(app, "system")
+ self.add_column(col)
+
class Name(SqlTableColumn):
def render_title(self, session, data):
return "Name"
+
+ class Machine(SqlTableColumn):
+ def render_title(self, session, data):
+ return "Machine"
+
+ class System(SqlTableColumn):
+ def render_title(self, session, data):
+ return "System"
Modified: mgmt/trunk/cumin/python/cumin/slot.strings
===================================================================
--- mgmt/trunk/cumin/python/cumin/slot.strings 2008-10-31 21:18:52 UTC (rev 2719)
+++ mgmt/trunk/cumin/python/cumin/slot.strings 2008-10-31 21:22:45 UTC (rev 2720)
@@ -1,7 +1,11 @@
[SlotSet.sql]
select
s.id,
- s.name
+ s.name,
+ s.machine,
+ s.system,
+ s.job_id,
+ c.activity as activity
from slot as s
left outer join slot_stats as c on c.id = s.stats_curr_id
left outer join slot_stats as p on p.id = s.stats_prev_id
Modified: mgmt/trunk/cumin/python/cumin/stat.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/stat.py 2008-10-31 21:18:52 UTC (rev 2719)
+++ mgmt/trunk/cumin/python/cumin/stat.py 2008-10-31 21:22:45 UTC (rev 2720)
@@ -167,7 +167,7 @@
self.stats_tmpl.render(writer, session, count, object)
return writer.to_string()
- def get_object_count(self, objects):
+ def get_object_count(self, session, objects):
return len(objects)
def render_override_style(self, session, objects):
Modified: mgmt/trunk/cumin/python/cumin/stat.strings
===================================================================
--- mgmt/trunk/cumin/python/cumin/stat.strings 2008-10-31 21:18:52 UTC (rev 2719)
+++ mgmt/trunk/cumin/python/cumin/stat.strings 2008-10-31 21:22:45 UTC (rev 2720)
@@ -277,7 +277,7 @@
font-size: 0.8em;
position: absolute;
top: 120%;
- width: 25em;
+/* width: 25em; */
padding: 1em;
background-color: #ffffaa;
background-image: url(resource?name=shade.png);
@@ -338,12 +338,15 @@
onmouseout="document.getElementById('note_{cell_id}').style.display='none';">
<a href="{href}"><button id="button_{cell_id}"
class="btn {color}" >{contents}</button></a>
<div id="note_{cell_id}" class="sticky_note position">
- <div class="sticky_names">
- {sticky_names}
- </div>
- <div class="sticky_values">
- {sticky_values}
- </div>
+ <table cellpadding="0" cellspacing="0">
+ <tr>
+ <td><div class="sticky_names">
+ {sticky_names}
+ </div></td>
+ <td><div class="sticky_values">
+ {sticky_values}
+ </div></td>
+ </tr></table>
<div style="clear:left;"><!-- --></div>
</div>
</div>
Modified: mgmt/trunk/cumin/python/cumin/system.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/system.py 2008-10-31 21:18:52 UTC (rev 2719)
+++ mgmt/trunk/cumin/python/cumin/system.py 2008-10-31 21:22:45 UTC (rev 2720)
@@ -62,14 +62,11 @@
def get_args(self, session):
system = self.frame.get_args(session)[0]
action = self.app.model.system.slots
- return action.get_slots(system)
+ return action.get_slots(session, system)
def render_title(self, session, slots):
return "Slot Utilization"
- def get_object_count(self, session, slots):
- return slots.count()
-
def get_colors(self, session):
action = self.app.model.system.slots
return action.get_colors()
@@ -90,7 +87,7 @@
return self.page.main.pool.job.get_href(branch, job)
def render_cell_id(self, session, count, slot):
- return "%i" % slot.sourceObjectId
+ return "%i" % slot["id"]
def get_url(self, session):
system = self.parent.frame.get_args(session)[0]
@@ -133,9 +130,10 @@
return "Grid Jobs %s" % fmt_count(self.get_item_count(session,
system))
def render_sql_where(self, session, system):
- phase_sql = self.get_phase_sql(session)
- sql = "s.system = %(nodeName)s"
- return "where %s" % " and ".join([phase_sql, sql])
+ elems = list()
+ #elems.append("s.system = %(nodeName)s")
+ elems.append(self.get_phase_sql(session))
+ return "where %s" % " and ".join(elems)
def get_sql_values(self, session, system):
return {"nodeName": system.nodeName}
@@ -151,8 +149,7 @@
def render_sql_where(self, session, system):
elems = list()
- elems.append("machine = %(nodeName)s")
- elems.append("s.rec_time > now() - interval '90 minutes'")
+ #elems.append("machine = %(nodeName)s")
elems.append("deletion_time is null")
return "where %s" % " and ".join(elems)
Modified: mgmt/trunk/cumin/python/cumin/system.strings
===================================================================
--- mgmt/trunk/cumin/python/cumin/system.strings 2008-10-31 21:18:52 UTC (rev 2719)
+++ mgmt/trunk/cumin/python/cumin/system.strings 2008-10-31 21:22:45 UTC (rev 2720)
@@ -48,3 +48,27 @@
setTimeout("get_slot_grid()", 1000);
}
+[SystemJobSet.html]
+ <div class="rfloat">{phase}</div>
+<form id="{id}" style="clear:right;" method="post"
action="?">
+
+ <div class="sactions">
+ {job_search}
+ <h2>Act on Selected Jobs:</h2>
+ {hold} {release} {remove}
+ </div>
+
+ <table class="mobjects">
+ <thead>
+ <tr>
+ <th class="setnav" colspan="{column_count}">
+ <div class="rfloat">{page}</div>
+ {count}
+ </th>
+ </tr>
+ <tr>{headers}</tr>
+ </thead>
+ <tbody>{items}</tbody>
+ </table>
+ <div>{hidden_inputs}</div>
+</form>
Modified: mgmt/trunk/cumin/python/cumin/util.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/util.py 2008-10-31 21:18:52 UTC (rev 2719)
+++ mgmt/trunk/cumin/python/cumin/util.py 2008-10-31 21:22:45 UTC (rev 2720)
@@ -85,3 +85,38 @@
salt = "".join(sample(password_chars, 2))
return crypt(password, salt)
+
+def parse(text, begin_delim="{", end_delim="}"):
+ strings = list()
+
+ start = 0
+ end = text.find(begin_delim)
+
+ while True:
+ if (end == -1):
+ strings.append(text[start:])
+ break
+
+ strings.append(text[start:end])
+
+ ccurly = text.find(end_delim, end + 1)
+
+ if ccurly == -1:
+ start = end
+ end = -1
+ else:
+ ocurly = text.find(begin_delim, end + 1)
+
+ if ocurly == -1:
+ start = end
+ end = ccurly + 1
+ elif ocurly < ccurly:
+ start = end
+ end = ocurly
+ else:
+ strings.append(begin_delim + text[end + 1:ccurly] + end_delim)
+
+ start = ccurly + 1
+ end = ocurly
+
+ return strings