Author: eallen
Date: 2010-07-02 09:14:36 -0400 (Fri, 02 Jul 2010)
New Revision: 4065
Modified:
mgmt/newdata/cumin/model/qmf.xml
mgmt/newdata/cumin/python/cumin/grid/job.py
mgmt/newdata/cumin/python/cumin/model.py
mgmt/newdata/cumin/python/cumin/objectselector.py
mgmt/newdata/cumin/python/cumin/objecttask.py
Log:
Add Hold/Release/Remove selection tasks for Jobs
Modified: mgmt/newdata/cumin/model/qmf.xml
===================================================================
--- mgmt/newdata/cumin/model/qmf.xml 2010-07-02 13:12:54 UTC (rev 4064)
+++ mgmt/newdata/cumin/model/qmf.xml 2010-07-02 13:14:36 UTC (rev 4065)
@@ -8,6 +8,7 @@
<property name="JobStatus" type="sstr"/>
<property name="EnteredCurrentStatus" type="absTime"/>
<property name="GlobalJobId" type="sstr"/>
+ <property name="JobId" type="sstr"/>
</class>
</schema>
Modified: mgmt/newdata/cumin/python/cumin/grid/job.py
===================================================================
--- mgmt/newdata/cumin/python/cumin/grid/job.py 2010-07-02 13:12:54 UTC (rev 4064)
+++ mgmt/newdata/cumin/python/cumin/grid/job.py 2010-07-02 13:14:36 UTC (rev 4065)
@@ -82,6 +82,19 @@
return branch.marshal()
+class JobAdModes(ModeSet):
+ def __init__(self, app, name):
+ super(JobAdModes, self).__init__(app, name)
+
+ self.viewer = JobAdsViewer(app, "viewer")
+ self.add_mode(self.viewer)
+
+ self.editor = JobAdsEditor(app, "editor")
+ self.add_mode(self.editor)
+
+ def render_title(self, session):
+ return "Attributes"
+
class JobView(ObjectView):
def add_details_tab(self):
pass
@@ -96,6 +109,19 @@
rows = self.process_results(results)
return rows
+ def process_record(self, record):
+ field_data = list()
+ for column in self.columns:
+ try:
+ val = record[column.name]
+ except KeyError:
+ if column.name == "JobId":
+ val = "%d.%d" % (record['ClusterId'],
record['ProcId'])
+ else:
+ val = 0
+ field_data.append(val)
+ return field_data
+
def get_count(self, values):
submission = values["obj"]
results = self.app.model.get_submission_job_summaries(submission)
@@ -109,7 +135,7 @@
self.submission = submission
frame = "main.grid.pool.submission.job"
- self.job_id_col = self.JobIdColumn(app, "job", cls.GlobalJobId,
cls._id, frame)
+ self.job_id_col = self.JobIdColumn(app, "job", cls.GlobalJobId,
cls.JobId, frame)
self.add_column(self.job_id_col)
status_column = self.Status(app, "status", cls.JobStatus)
@@ -117,15 +143,24 @@
self.add_attribute_column(cls.Cmd)
- # CluserId.ProdId is the string needed to get the job ad from the jobserver
- self.proc_id_column = ObjectAttributeColumn(app, cls.ProcId.name, cls.ProcId)
- self.proc_id_column.visible = False
- self.add_column(self.proc_id_column)
+ self.job_id_column = ObjectAttributeColumn(app, cls.JobId.name, cls.JobId)
+ self.job_id_column.visible = False
+ self.add_column(self.job_id_column)
- self.cluster_id_column = ObjectAttributeColumn(app, cls.ClusterId.name,
cls.ClusterId)
- self.cluster_id_column.visible = False
- self.add_column(self.cluster_id_column)
+ JobSelectionHold(app, self, "held")
+ JobSelectionRelease(app, self, "released")
+ JobSelectionRemove(app, self, "removed")
+ def init_ids(self, app, cls):
+ item = Parameter(app, "item")
+
+ self.ids = ListParameter(app, "selection", item)
+ self.add_parameter(self.ids)
+
+ self.checkbox_column = ObjectCheckboxColumn \
+ (app, "id", cls.JobId, self.ids)
+ self.add_column(self.checkbox_column)
+
def render_title(self, session):
return "Jobs"
@@ -141,11 +176,7 @@
class JobIdColumn(ObjectLinkColumn):
def render_cell_href(self, session, record):
- index = self.parent.cluster_id_column.field.index
- cluster_id = record[index]
- index = self.parent.proc_id_column.field.index
- proc_id = record[index]
- job_id = "%d.%d" % (cluster_id, proc_id)
+ job_id = record[self.parent.job_id_column.field.index]
frame = self.page.page_widgets_by_path[self.frame_path]
submission = self.parent.submission.get(session)
@@ -156,19 +187,108 @@
status = self.field.get_content(session, record)
return JobStatusInfo.get_status_string(status)
-class JobAdModes(ModeSet):
- def __init__(self, app, name):
- super(JobAdModes, self).__init__(app, name)
+class JobSelectionTask(SelectionTask):
+ def __init__(self, app, selector, verb):
+ super(JobSelectionTask, self).__init__(app, selector)
- self.viewer = JobAdsViewer(app, "viewer")
- self.add_mode(self.viewer)
+ self.form = JobSelectionTaskForm(app, self.name, self, verb)
+ self.method = None
- self.editor = JobAdsEditor(app, "editor")
- self.add_mode(self.editor)
+ def do_invoke(self, invoc, job_id, scheduler, reason):
+ assert self.method
- def render_title(self, session):
- return "Attributes"
+ action = QmfCall(self.app)
+ results = action.execute(scheduler, self.method, job_id, reason)
+ if results.error:
+ raise results.error
+
+ invoc.status_code = results.status
+ invoc.end()
+
+ def do_enter(self, session, osession):
+ submission = self.selector.submission.get(osession)
+ self.form.submission_id.set(session, submission._id)
+
+class JobSelectionHold(JobSelectionTask):
+ def __init__(self, app, selector, verb):
+ super(JobSelectionHold, self).__init__(app, selector, verb)
+
+ self.method = "HoldJob"
+
+ def get_title(self, session):
+ return "Hold"
+
+class JobSelectionRelease(JobSelectionTask):
+ def __init__(self, app, selector, verb):
+ super(JobSelectionRelease, self).__init__(app, selector, verb)
+
+ self.method = "ReleaseJob"
+
+ def get_title(self, session):
+ return "Release"
+
+class JobSelectionRemove(JobSelectionTask):
+ def __init__(self, app, selector, verb):
+ super(JobSelectionRemove, self).__init__(app, selector, verb)
+
+ self.method = "RemoveJob"
+
+ def get_title(self, session):
+ return "Remove"
+
+class JobSelectionTaskForm(SelectionTaskForm):
+ def __init__(self, app, name, task, verb):
+ super(JobSelectionTaskForm, self).__init__(app, name, task)
+
+ self.submission_id = IntegerParameter(app, "sub")
+ self.add_parameter(self.submission_id)
+
+ self.content = ReasonField(app, "fields")
+ self.replace_child(self.content)
+
+ self.verb = verb
+
+ def get_selection(self, session):
+ ids = self.ids.get(session)
+
+ selection = list(ids)
+ self.selection.set(session, selection)
+
+ def get_reason(self, session, verb):
+ """ returns <verb> by username[: <user input reason>]
"""
+ reason = self.content.get(session)
+ if reason:
+ reason = [reason]
+ user = session.client_session.attributes["login_session"].user
+
+ verb_by = "%s by %s" % (verb, user.name)
+ reason.insert(0, verb_by)
+ return ": ".join(reason)
+
+ def process_submit(self, session):
+ selection = self.selection.get(session)
+ reason = self.get_reason(session, self.verb)
+
+ scheduler = self.get_scheduler(session)
+
+ self.task.invoke(session, selection, scheduler, reason)
+ self.task.exit_with_redirect(session)
+
+ def get_scheduler(self, session):
+ submission_id = self.submission_id.get(session)
+ cls = self.app.model.com_redhat_grid.Submission
+ submission = cls.get_object_by_id(session.cursor, submission_id)
+
+ cls = self.app.model.com_redhat_grid.JobServer
+ job_server = cls.get_object(session.cursor, _id=submission._jobserverRef_id)
+
+ pool = job_server.Pool
+ machine = job_server.Machine
+
+ cls = self.app.model.com_redhat_grid.Scheduler
+ return cls.get_object(session.cursor, Pool=pool, Machine=machine)
+
class JobAdsSet(PropertySet):
types = {0: "expression",
1: "integer",
@@ -618,7 +738,7 @@
def __init__(self, app, name, task, verb):
super(JobActionForm, self).__init__(app, name, task)
- self.reason = self.ReasonField(app, "reason")
+ self.reason = ReasonField(app, "reason")
self.add_field(self.reason)
self.job_id = Parameter(app, "job_id")
@@ -649,9 +769,9 @@
self.task.invoke(session, scheduler, job_id, reason)
self.task.exit_with_redirect(session)
- class ReasonField(StringField):
- def render_title(self, session):
- return "Reason"
+class ReasonField(StringField):
+ def render_title(self, session):
+ return "Reason"
class JobHold(JobAction):
def __init__(self, app, frame):
Modified: mgmt/newdata/cumin/python/cumin/model.py
===================================================================
--- mgmt/newdata/cumin/python/cumin/model.py 2010-07-02 13:12:54 UTC (rev 4064)
+++ mgmt/newdata/cumin/python/cumin/model.py 2010-07-02 13:14:36 UTC (rev 4065)
@@ -75,12 +75,12 @@
try:
try:
- store = self.limits_by_negotiator[negotiator]
+ store = self.limits_by_negotiator[negotiator._qmf_agent_id]
except KeyError:
store = NegotiatorLimitStore(self, negotiator)
store.start_updates()
- self.limits_by_negotiator[negotiator] = store
+ self.limits_by_negotiator[negotiator._qmf_agent_id] = store
sleep(1)
Modified: mgmt/newdata/cumin/python/cumin/objectselector.py
===================================================================
--- mgmt/newdata/cumin/python/cumin/objectselector.py 2010-07-02 13:12:54 UTC (rev 4064)
+++ mgmt/newdata/cumin/python/cumin/objectselector.py 2010-07-02 13:14:36 UTC (rev 4065)
@@ -78,15 +78,8 @@
def __init__(self, app, name, cls, adapter=None):
super(ObjectSelector, self).__init__(app, name, cls, adapter)
- item = IntegerParameter(app, "item")
+ self.init_ids(app, cls)
- self.ids = ListParameter(app, "selection", item)
- self.add_parameter(self.ids)
-
- self.checkbox_column = ObjectCheckboxColumn \
- (app, "id", cls._id, self.ids)
- self.add_column(self.checkbox_column)
-
self.switches = ObjectSelectorSwitches(app, "switches")
self.add_child(self.switches)
@@ -109,6 +102,16 @@
self.buttons.add_child(button)
button.init()
+ def init_ids(self, app, cls):
+ item = IntegerParameter(app, "item")
+
+ self.ids = ListParameter(app, "selection", item)
+ self.add_parameter(self.ids)
+
+ self.checkbox_column = ObjectCheckboxColumn \
+ (app, "id", cls._id, self.ids)
+ self.add_column(self.checkbox_column)
+
class ObjectAttributeColumn(DataTableColumn):
def __init__(self, app, name, attr):
super(ObjectAttributeColumn, self).__init__(app, name, None)
Modified: mgmt/newdata/cumin/python/cumin/objecttask.py
===================================================================
--- mgmt/newdata/cumin/python/cumin/objecttask.py 2010-07-02 13:12:54 UTC (rev 4064)
+++ mgmt/newdata/cumin/python/cumin/objecttask.py 2010-07-02 13:14:36 UTC (rev 4065)
@@ -337,6 +337,10 @@
self.replace_child(self.content)
def do_process(self, session):
+ self.get_selection(session)
+ super(SelectionTaskForm, self).do_process(session)
+
+ def get_selection(self, session):
selection = list()
self.selection.set(session, selection)
@@ -345,8 +349,6 @@
item = self.cls.get_object_by_id(session.cursor, id)
selection.append(item)
- super(SelectionTaskForm, self).do_process(session)
-
def process_submit(self, session):
selection = self.selection.get(session)