Author: eallen
Date: 2008-10-08 14:30:55 -0400 (Wed, 08 Oct 2008)
New Revision: 2607
Modified:
mgmt/trunk/cumin/python/cumin/job.py
mgmt/trunk/cumin/python/cumin/limits.py
mgmt/trunk/cumin/python/cumin/model.py
Log:
Moving method calls to model.py in case we want to call them using call.xml in the
future.
Modified: mgmt/trunk/cumin/python/cumin/job.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/job.py 2008-10-08 15:46:34 UTC (rev 2606)
+++ mgmt/trunk/cumin/python/cumin/job.py 2008-10-08 18:30:55 UTC (rev 2607)
@@ -529,25 +529,8 @@
return items
def get_raw_ads(self, session, job):
- self.job_ads = {"":{"VALUE": "", "TYPE":
0}}
- self.got_data = False
-
- def completion(status, job_ads):
- self.job_ads = job_ads["JobAd"]
- self.got_data = True
-
- def predicate():
- return self.got_data
-
- try:
- model = self.app.model
- job.GetAd(model.data, completion, self.job_ads)
- except:
- return self.job_ads
-
- # wait for up to 20 seconds for completion to be called
- wait(predicate, timeout=20)
- return self.job_ads
+ action = self.app.model.job.getad
+ return action.do_invoke(job)
def gen_items(self, session, job):
job_ads = self.get_raw_ads(session, job)
@@ -836,48 +819,18 @@
is_tail = self.first_last.get(session) == "t"
return is_tail and "<script language=\"javascript\"
type=\"text/javascript\">addEvent(window, \"load\",
outputEnd);</script>" or ""
- def render_the_output(self, session, *args):
- self.job_output = None
- self.got_data = False
-
- def completion(status, job_output):
- if "Data" in job_output:
- raw = job_output["Data"]
- self.job_output = fix_raw(raw)
- self.got_data = True
-
- def predicate():
- return self.got_data
-
- def fix_raw(raw):
- """ remove the last partial line from the buffer
-
- This is done because the buffer ends with non-ascii junk characters
- """
- lindex = -1
- ord_nl = ord('\n')
- while ord(raw[-lindex:][0]) != ord_nl:
- lindex = lindex + 1
- return raw[:-lindex]
-
+ def render_the_output(self, session, job):
first_last = self.first_last.get(session)
- start = first_last == "t" and -2048 or 0
- end = first_last == "t" and 0 or 2048
+ if first_last == "t":
+ start = -2048
+ end = 0
+ else:
+ start = 0
+ end = 2048
file = self.which_file.get_current_file_name(session)
if file:
- try:
- model = self.app.model
- job = args[0]
- data = dict()
- job.Fetch(model.data, completion, file, start, end, data)
- # wait for up to 20 seconds for completion to be called
- wait(predicate, timeout=20)
- if not self.got_data:
- self.job_output = "Unable to get file at %s. Reason: time
out" % file
- except Exception, e:
- self.job_output = "Unable to get file at %s. Reason: %s" %
(file, e)
-
- return self.job_output and escape_entity(self.job_output)
+ action = self.app.model.job.fetch
+ return action.do_invoke(job, file, start, end)
class FetchButton(FormButton):
def render_content(self, session):
Modified: mgmt/trunk/cumin/python/cumin/limits.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/limits.py 2008-10-08 15:46:34 UTC (rev 2606)
+++ mgmt/trunk/cumin/python/cumin/limits.py 2008-10-08 18:30:55 UTC (rev 2607)
@@ -41,25 +41,8 @@
negotiator.Reconfig(self.app.model.data, completion)
def get_raw_limits(self, session, negotiator):
- self.lim = dict()
- self.got_data = False
-
- def completion(status, data):
- self.lim = data["Limits"]
- self.got_data = True
-
- def predicate():
- return self.got_data
-
- try:
- model = self.app.model
- negotiator.GetLimits(model.data, completion, self.lim)
- except:
- return self.lim
-
- # wait for up to 20 seconds for completion to be called
- wait(predicate, timeout=5)
- return self.lim
+ action = self.app.model.negotiator.GetLimits
+ return action.do_invoke(negotiator)
class LimitsSet(ItemTable, LimitActions):
def __init__(self, app, name):
Modified: mgmt/trunk/cumin/python/cumin/model.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/model.py 2008-10-08 15:46:34 UTC (rev 2606)
+++ mgmt/trunk/cumin/python/cumin/model.py 2008-10-08 18:30:55 UTC (rev 2607)
@@ -1865,6 +1865,12 @@
action = self.SetAttribute(self, "setattribute")
action.navigable = False
+ action = self.GetAd(self, "getad")
+ action.navigable = False
+
+ action = self.Fetch(self, "fetch")
+ action.navigable = False
+
def get_title(self, session):
return "Job"
@@ -1924,6 +1930,58 @@
return escape_amp(fmt_olink(branch, scheduler, name=scheduler.Name))
+ class GetAd(CuminAction):
+ def do_invoke(self, job):
+ self.job_ads = {"":{"VALUE": "",
"TYPE": 0}}
+ self.got_data = False
+
+ def completion(status, job_ads):
+ self.job_ads = job_ads["JobAd"]
+ self.got_data = True
+
+ def predicate():
+ return self.got_data
+
+ try:
+ job.GetAd(self.cumin_model.data, completion, self.job_ads)
+ except:
+ return self.job_ads
+
+ # wait for up to 20 seconds for completion to be called
+ wait(predicate, timeout=20)
+ return self.job_ads
+
+ class Fetch(CuminAction):
+ def do_invoke(self, job, file, start, end):
+ self.job_output = None
+ self.got_data = False
+
+ def completion(status, job_output):
+ if "Data" in job_output:
+ raw = job_output["Data"]
+ #remove the last partial line from the buffer
+ lindex = -1
+ ord_nl = ord('\n')
+ while ord(raw[-lindex:][0]) != ord_nl:
+ lindex = lindex + 1
+ self.job_output = raw[:-lindex]
+ self.got_data = True
+
+ def predicate():
+ return self.got_data
+
+ try:
+ data = dict()
+ job.Fetch(self.cumin_model.data, completion, file, start, end, data)
+ # wait for up to 20 seconds for completion to be called
+ wait(predicate, timeout=20)
+ if not self.got_data:
+ self.job_output = "Unable to get file at %s. Reason: time
out" % file
+ except Exception, e:
+ self.job_output = "Unable to get file at %s. Reason: %s" %
(file, e)
+
+ return self.job_output and escape_entity(self.job_output)
+
class Hold(CuminAction):
def show(self, session, job):
frame = self.cumin_class.get_pool_frame(session)
@@ -2213,7 +2271,11 @@
action = self.Stop(self, "stop")
action.summary = True
+ action = self.GetLimits(self, "GetLimits")
+ action.navigable = False
+
action = self.GetLimitCount(self, "GetLimitCount")
+ action.navigable = False
def get_title(self, session):
return "Negotiator"
@@ -2258,11 +2320,12 @@
negotiator.Stop(self.cumin_model.data, completion)
class GetLimitCount(CuminAction):
- def __init__(self, cls, name):
- super(CuminNegotiator.GetLimitCount, self).__init__(cls, name)
+ def do_invoke(self, negotiator):
+ action = self.cumin_model.negotiator.GetLimits
+ limits = action.do_invoke(negotiator)
+ return "<count value=\"%i\" />" % len(limits)
- self.navigable = False
-
+ class GetLimits(CuminAction):
def do_invoke(self, negotiator):
self.lim = dict()
self.got_data = False
@@ -2281,7 +2344,7 @@
# wait for up to 5 seconds for completion to be called
wait(predicate, timeout=5)
- return "<count value=\"%i\" />" % len(self.lim)
+ return self.lim
class ModelPage(Page):
def __init__(self, app, name):