Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1853)

Unified Diff: appengine/swarming/server/task_request.py

Issue 1939343002: swarming: change meaning of inputs_ref (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-py@master
Patch Set: sort dict keys Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: appengine/swarming/server/task_request.py
diff --git a/appengine/swarming/server/task_request.py b/appengine/swarming/server/task_request.py
index 3182acca3b6d7d0bd4d9358eda3f0233ece01ca8..5c2751ee6821837c52b2068d6f731f5c2f89c0dc 100644
--- a/appengine/swarming/server/task_request.py
+++ b/appengine/swarming/server/task_request.py
@@ -223,7 +223,15 @@ def _validate_package_version(prop, value):
class FilesRef(ndb.Model):
"""Defines a data tree reference, normally a reference to a .isolated file."""
- # The hash of an isolated archive.
+
+ # Specifies FilesRef mode.
M-A Ruel 2016/05/11 14:41:41 This is not needed?
nodir 2016/05/11 16:04:29 Done.
+ # if True, this instance is a reference to a tree, as class docstring says.
+ # if False, this instance is isolate input/output settings in TaskProperties.
+ # TODO(maruel): refactor this class, get rid of this.
+ is_ref = True
+
+ # if is_ref, the hash of an isolated archive.
+ # otherwise, the hash of the input isolated archive.
isolated = ndb.StringProperty(validator=_validate_isolated, indexed=False)
# The hostname of the isolated server to use.
isolatedserver = ndb.StringProperty(
@@ -233,9 +241,14 @@ class FilesRef(ndb.Model):
def _pre_put_hook(self):
super(FilesRef, self)._pre_put_hook()
- if not self.isolated or not self.isolatedserver or not self.namespace:
- raise datastore_errors.BadValueError(
- 'isolated requires server and namespace')
+ if self.is_ref:
M-A Ruel 2016/05/11 14:41:41 Remove this part, self.isolated can be None.
nodir 2016/05/11 16:04:29 Done. Now is_ref is not used, so I've removed it.
+ if not self.isolated or not self.isolatedserver or not self.namespace:
+ raise datastore_errors.BadValueError(
+ 'isolated requires server and namespace')
+ else:
+ if not self.isolatedserver or not self.namespace:
+ raise datastore_errors.BadValueError(
+ 'isolate server and namespace are required')
class CipdPackage(ndb.Model):
@@ -266,9 +279,16 @@ class TaskProperties(ndb.Model):
This model is immutable.
New-style TaskProperties supports invocation of run_isolated. When this
- behavior is desired, the member .inputs_ref must be suppled. .extra_args can
- be supplied to pass extraneous arguments.
+ behavior is desired, the member .inputs_ref.isolated must be supplied.
M-A Ruel 2016/05/11 14:41:41 Strictly speaking, it could still be missing when
nodir 2016/05/11 16:04:29 Done.
+ .extra_args can be supplied to pass extraneous arguments.
"""
+
+ # TODO(maruel): convert inputs_ref and _TaskResultCommon.outputs_ref as:
+ # - input = String which is the isolated input, if any
+ # - isolated_server = <server, metadata e.g. namespace> which is a
+ # simplified version of FilesRef
+ # - _TaskResultCommon.output = String which is isolated output, if any.
+
# Hashing algorithm used to hash TaskProperties to create its key.
HASHING_ALGO = hashlib.sha1
@@ -276,12 +296,18 @@ class TaskProperties(ndb.Model):
# TODO(maruel): Remove after 2016-06-01.
commands = datastore_utils.DeterministicJsonProperty(
json_type=list, indexed=False)
- # Command to run. This is only relevant when self._inputs_ref is None. This is
- # what is called 'raw commands', in the sense that no inputs files are
+ # Command to run. This is only relevant when self.inputs_ref.isolated is None.
+ # This is what is called 'raw commands', in the sense that no inputs files are
# declared.
command = ndb.StringProperty(repeated=True, indexed=False)
- # File inputs of the task. Only inputs_ref or command&data can be specified.
+ # Isolate server, namespace and input isolate hash.
+ #
+ # Despite its name, contains isolate server URL and namespace for isolated
+ # output too. See TODO at the top of this class.
+ # May be non-None even if task input is not isolated.
+ #
+ # Only inputs_ref.isolated or command&data can be specified.
M-A Ruel 2016/05/11 14:41:41 data doesn't exist anymore, it's a left over so re
nodir 2016/05/11 16:04:29 Done.
inputs_ref = ndb.LocalStructuredProperty(FilesRef)
# A list of CIPD packages to install $CIPD_PATH and $PATH before task
@@ -304,7 +330,7 @@ class TaskProperties(ndb.Model):
validator=_validate_timeout, required=True, indexed=False)
# Extra arguments to supply to the command `python run_isolated ...`. Can only
- # be set if inputs_ref is set.
+ # be set if inputs_ref.isolated is set.
extra_args = ndb.StringProperty(repeated=True, indexed=False)
# Grace period is the time between signaling the task it timed out and killing
@@ -330,7 +356,7 @@ class TaskProperties(ndb.Model):
not self.commands and
not self.command and
self.dimensions.keys() == [u'id'] and
- not self.inputs_ref and
+ not (self.inputs_ref and self.inputs_ref.isolated) and
not self.env and
not self.execution_timeout_secs and
not self.extra_args and
@@ -363,11 +389,15 @@ class TaskProperties(ndb.Model):
raise datastore_errors.BadValueError(
'commands is not supported anymore')
if not self.is_terminate:
- if bool(self.command) == bool(self.inputs_ref):
- raise datastore_errors.BadValueError('use one of command or inputs_ref')
- if self.extra_args and not self.inputs_ref:
- raise datastore_errors.BadValueError('extra_args require inputs_ref')
+ isolated_input = self.inputs_ref and self.inputs_ref.isolated
+ if bool(self.command) == bool(isolated_input):
+ raise datastore_errors.BadValueError(
+ 'use one of command or inputs_ref.isolated')
+ if self.extra_args and not isolated_input:
+ raise datastore_errors.BadValueError(
+ 'extra_args require inputs_ref.isolated')
if self.inputs_ref:
+ self.inputs_ref.is_ref = False
self.inputs_ref._pre_put_hook()
package_names = set()
@@ -387,7 +417,6 @@ class TaskProperties(ndb.Model):
'use instance IDs or tags as package versions')
-
class TaskRequest(ndb.Model):
"""Contains a user request.

Powered by Google App Engine
This is Rietveld 408576698