Author: justi9
Date: 2010-07-14 13:17:03 -0400 (Wed, 14 Jul 2010)
New Revision: 4119
Modified:
mgmt/newdata/cumin/python/cumin/grid/submission.py
Log:
Add extended-attr parsing to job submission
Modified: mgmt/newdata/cumin/python/cumin/grid/submission.py
===================================================================
--- mgmt/newdata/cumin/python/cumin/grid/submission.py 2010-07-14 17:16:03 UTC (rev 4118)
+++ mgmt/newdata/cumin/python/cumin/grid/submission.py 2010-07-14 17:17:03 UTC (rev 4119)
@@ -88,17 +88,19 @@
stdin=None,
stdout=None,
stderr=None,
- extra_attrs={}):
- # XXX
- # user_name = invoc.user.name
- user_name = "gridmonkey"
-
+ attrs={}):
ad = dict()
ad["Submission"] = description
ad["Cmd"] = executable
- ad["Owner"] = user_name
+ ad["Owner"] = invoc.user.name
+ # XXX Temporary measure until the other end does more defaulting
+ ad["Args"] = ""
+ ad["JobUniverse"] = 5
+ ad["Requirements"] = "TRUE"
+ ad["Iwd"] = "/tmp"
+
def put(name, value):
if value:
ad[name] = value
@@ -108,7 +110,7 @@
put("Requirements", requirements)
put("JobUniverse", universe)
- for name, value in extra_attrs:
+ for name, value in attrs.items():
put(name, value)
descriptors = dict()
@@ -182,16 +184,18 @@
def process_submit(self, session):
self.validate(session)
+ attrs = self.parse_attributes(session)
+
if not self.errors.get(session):
scheduler = self.scheduler.get(session)
description = self.description.get(session)
command = self.command.get(session)
requirements = self.requirements.get(session)
+ universe = self.universe.get(session)
directory = self.directory.get(session)
stdin = self.stdin.get(session)
stdout = self.stdout.get(session)
stderr = self.stderr.get(session)
- universe = self.universe.get(session)
tokens = shlex.split(command)
@@ -204,14 +208,66 @@
executable,
arguments=arguments,
requirements=requirements,
+ universe=universe,
iwd=directory,
stdin=stdin,
stdout=stdout,
stderr=stderr,
- universe=universe)
+ attrs=attrs)
self.task.exit_with_redirect(session)
+ def parse_attributes(self, session):
+ attrs = dict()
+
+ text = self.attributes_.get(session)
+ text = text.strip()
+
+ for line in text.split("\n"):
+ line = line.strip()
+
+ if not line:
+ continue
+
+ try:
+ name, value = self.parse_attribute(line)
+ except:
+ error = FormError("Failed parsing attribute: %s" % line)
+ self.errors.get(session).append(error)
+
+ continue
+
+ attrs[name] = value
+
+ return attrs
+
+ def parse_attribute(self, line):
+ name, value = line.split("=", 1)
+
+ name = name.strip()
+ value = self.unmarshal_value(value.strip())
+
+ return name, value
+
+ def unmarshal_value(self, value):
+ if value.lower() == "true":
+ return True
+
+ if value.lower() == "false":
+ return False
+
+ try:
+ return int(value)
+ except ValueError:
+ pass
+
+ try:
+ return float(value)
+ except ValueError:
+ pass
+
+ return value
+
class TemplateField(FormField):
def __init__(self, app, name):
super(SubmissionAddForm.TemplateField, self).__init__(app, name)
@@ -258,9 +314,12 @@
self.input = self.UniverseOptions(app, "input", self.param)
self.add_child(self.input)
+ def render_title(self, session):
+ return "Universe"
+
class UniverseOptions(OptionInputSet):
def get_items(self, session):
- return ((None, "[Default]"),
+ return ((None, "Default"),
(5, "VANILLA"),
(7, "SCHEDULER"),
(9, "GRID"),
@@ -269,9 +328,6 @@
(12, "LOCAL"),
(13, "VM"))
- def render_title(self, session):
- return "Universe"
-
def render_item_value(self, session, item):
return item[0]