| OLD | NEW |
| 1 # coding: utf-8 | 1 # coding: utf-8 |
| 2 # Copyright 2014 The LUCI Authors. All rights reserved. | 2 # Copyright 2014 The LUCI Authors. All rights reserved. |
| 3 # Use of this source code is governed under the Apache License, Version 2.0 | 3 # Use of this source code is governed under the Apache License, Version 2.0 |
| 4 # that can be found in the LICENSE file. | 4 # that can be found in the LICENSE file. |
| 5 | 5 |
| 6 """Tasks definition. | 6 """Tasks definition. |
| 7 | 7 |
| 8 Each user request creates a new TaskRequest. The TaskRequest instance saves the | 8 Each user request creates a new TaskRequest. The TaskRequest instance saves the |
| 9 metadata of the request, e.g. who requested it, when why, etc. It links to the | 9 metadata of the request, e.g. who requested it, when why, etc. It links to the |
| 10 actual data of the request in a TaskProperties. The TaskProperties represents | 10 actual data of the request in a TaskProperties. The TaskProperties represents |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 | 285 |
| 286 # The hash of an isolated archive. | 286 # The hash of an isolated archive. |
| 287 isolated = ndb.StringProperty(validator=_validate_isolated, indexed=False) | 287 isolated = ndb.StringProperty(validator=_validate_isolated, indexed=False) |
| 288 # The hostname of the isolated server to use. | 288 # The hostname of the isolated server to use. |
| 289 isolatedserver = ndb.StringProperty( | 289 isolatedserver = ndb.StringProperty( |
| 290 validator=_validate_url, indexed=False) | 290 validator=_validate_url, indexed=False) |
| 291 # Namespace on the isolate server. | 291 # Namespace on the isolate server. |
| 292 namespace = ndb.StringProperty(validator=_validate_namespace, indexed=False) | 292 namespace = ndb.StringProperty(validator=_validate_namespace, indexed=False) |
| 293 | 293 |
| 294 def _pre_put_hook(self): | 294 def _pre_put_hook(self): |
| 295 # TODO(maruel): Get default value from config |
| 296 # IsolateSettings.default_server. |
| 295 super(FilesRef, self)._pre_put_hook() | 297 super(FilesRef, self)._pre_put_hook() |
| 296 if not self.isolatedserver or not self.namespace: | 298 if not self.isolatedserver or not self.namespace: |
| 297 raise datastore_errors.BadValueError( | 299 raise datastore_errors.BadValueError( |
| 298 'isolate server and namespace are required') | 300 'isolate server and namespace are required') |
| 299 | 301 |
| 300 | 302 |
| 301 class SecretBytes(ndb.Model): | 303 class SecretBytes(ndb.Model): |
| 302 """Defines an optional secret byte string logically defined with the | 304 """Defines an optional secret byte string logically defined with the |
| 303 TaskProperties. | 305 TaskProperties. |
| 304 | 306 |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 504 def _pre_put_hook(self): | 506 def _pre_put_hook(self): |
| 505 super(TaskProperties, self)._pre_put_hook() | 507 super(TaskProperties, self)._pre_put_hook() |
| 506 if self.commands: | 508 if self.commands: |
| 507 raise datastore_errors.BadValueError( | 509 raise datastore_errors.BadValueError( |
| 508 'commands is not supported anymore') | 510 'commands is not supported anymore') |
| 509 if not self.is_terminate: | 511 if not self.is_terminate: |
| 510 isolated_input = self.inputs_ref and self.inputs_ref.isolated | 512 isolated_input = self.inputs_ref and self.inputs_ref.isolated |
| 511 if not self.command and not isolated_input: | 513 if not self.command and not isolated_input: |
| 512 raise datastore_errors.BadValueError( | 514 raise datastore_errors.BadValueError( |
| 513 'use at least one of command or inputs_ref.isolated') | 515 'use at least one of command or inputs_ref.isolated') |
| 516 if self.command and self.extra_args: |
| 517 raise datastore_errors.BadValueError( |
| 518 'can\'t use both command and extra_args') |
| 514 if self.extra_args and not isolated_input: | 519 if self.extra_args and not isolated_input: |
| 515 raise datastore_errors.BadValueError( | 520 raise datastore_errors.BadValueError( |
| 516 'extra_args require inputs_ref.isolated') | 521 'extra_args require inputs_ref.isolated') |
| 517 if self.inputs_ref: | 522 if self.inputs_ref: |
| 518 self.inputs_ref._pre_put_hook() | 523 self.inputs_ref._pre_put_hook() |
| 519 | 524 |
| 520 # Validate caches. | 525 # Validate caches. |
| 521 cache_names = set() | 526 cache_names = set() |
| 522 cache_paths = set() | 527 cache_paths = set() |
| 523 for c in self.caches: | 528 for c in self.caches: |
| (...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 942 init_new_request(request, allow_high_priority, original_secret_bytes) | 947 init_new_request(request, allow_high_priority, original_secret_bytes) |
| 943 return request | 948 return request |
| 944 | 949 |
| 945 | 950 |
| 946 def validate_priority(priority): | 951 def validate_priority(priority): |
| 947 """Throws ValueError if priority is not a valid value.""" | 952 """Throws ValueError if priority is not a valid value.""" |
| 948 if 0 > priority or MAXIMUM_PRIORITY < priority: | 953 if 0 > priority or MAXIMUM_PRIORITY < priority: |
| 949 raise datastore_errors.BadValueError( | 954 raise datastore_errors.BadValueError( |
| 950 'priority (%d) must be between 0 and %d (inclusive)' % | 955 'priority (%d) must be between 0 and %d (inclusive)' % |
| 951 (priority, MAXIMUM_PRIORITY)) | 956 (priority, MAXIMUM_PRIORITY)) |
| OLD | NEW |