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

Side by Side Diff: appengine/swarming/handlers_endpoints.py

Issue 1946253003: swarming: refactor cipd input (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-py@default-isolate-server
Patch Set: rebased 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 unified diff | Download patch
« no previous file with comments | « appengine/swarming/handlers_bot_test.py ('k') | appengine/swarming/handlers_endpoints_test.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2015 The LUCI Authors. All rights reserved. 1 # Copyright 2015 The LUCI Authors. All rights reserved.
2 # Use of this source code is governed by the Apache v2.0 license that can be 2 # Use of this source code is governed by the Apache v2.0 license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """This module defines Swarming Server endpoints handlers.""" 5 """This module defines Swarming Server endpoints handlers."""
6 6
7 import datetime 7 import datetime
8 import json 8 import json
9 import logging 9 import logging
10 10
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 raise endpoints.NotFoundException('%s not found.' % key.id()) 70 raise endpoints.NotFoundException('%s not found.' % key.id())
71 return result 71 return result
72 72
73 73
74 def get_result_entity(task_id): 74 def get_result_entity(task_id):
75 """Returns the entity (TaskResultSummary or TaskRunResult) for a given ID.""" 75 """Returns the entity (TaskResultSummary or TaskRunResult) for a given ID."""
76 key, _ = get_result_key(task_id) 76 key, _ = get_result_key(task_id)
77 return get_or_raise(key) 77 return get_or_raise(key)
78 78
79 79
80 def apply_property_defaults(properties):
81 """Fills ndb task properties with default values read from server settings."""
82 cfg = config.settings()
83 if not cfg:
84 return
85
86 cfg = config.settings()
87 if cfg.isolate.default_server and cfg.isolate.default_namespace:
88 properties.inputs_ref = properties.inputs_ref or task_request.FilesRef()
89 properties.inputs_ref.isolatedserver = (
90 properties.inputs_ref.isolatedserver or cfg.isolate.default_server)
91 properties.inputs_ref.namespace = (
92 properties.inputs_ref.namespace or cfg.isolate.default_namespace)
93
94 if cfg.HasField('cipd') and properties.cipd_input:
95 properties.cipd_input.server = (
96 properties.cipd_input.server or cfg.cipd.default_server)
97 properties.cipd_input.client_package = (
98 properties.cipd_input.client_package or task_request.CipdPackage())
99 properties.cipd_input.client_package.package_name = (
100 properties.cipd_input.client_package.package_name or
101 cfg.cipd.default_client_package.package_name)
102 properties.cipd_input.client_package.version = (
103 properties.cipd_input.client_package.version or
104 cfg.cipd.default_client_package.version)
105
106
80 ### API 107 ### API
81 108
82 109
83 swarming_api = auth.endpoints_api( 110 swarming_api = auth.endpoints_api(
84 name='swarming', 111 name='swarming',
85 version='v1', 112 version='v1',
86 description= 113 description=
87 'API to interact with the Swarming service. Permits to create, ' 114 'API to interact with the Swarming service. Permits to create, '
88 'view and cancel tasks, query tasks and bots') 115 'view and cancel tasks, query tasks and bots')
89 116
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 @auth.require(acl.is_bot_or_user) 288 @auth.require(acl.is_bot_or_user)
262 def new(self, request): 289 def new(self, request):
263 """Creates a new task. 290 """Creates a new task.
264 291
265 The task will be enqueued in the tasks list and will be executed at the 292 The task will be enqueued in the tasks list and will be executed at the
266 earliest opportunity by a bot that has at least the dimensions as described 293 earliest opportunity by a bot that has at least the dimensions as described
267 in the task request. 294 in the task request.
268 """ 295 """
269 logging.info('%s', request) 296 logging.info('%s', request)
270 297
271 if not request.properties:
272 raise endpoints.BadRequestException('properties are required')
273
274 # Apply isolate defaults.
275 cfg = config.settings()
276 if cfg.isolate.default_server and cfg.isolate.default_namespace:
277 request.properties.inputs_ref = (
278 request.properties.inputs_ref or swarming_rpcs.FilesRef())
279 request.properties.inputs_ref.isolatedserver = (
280 request.properties.inputs_ref.isolatedserver or
281 cfg.isolate.default_server)
282 request.properties.inputs_ref.namespace = (
283 request.properties.inputs_ref.namespace or
284 cfg.isolate.default_namespace)
285
286 try: 298 try:
287 request = message_conversion.new_task_request_from_rpc( 299 request = message_conversion.new_task_request_from_rpc(
288 request, utils.utcnow()) 300 request, utils.utcnow())
301 apply_property_defaults(request.properties)
289 posted_request = task_request.make_request(request, acl.is_bot_or_admin()) 302 posted_request = task_request.make_request(request, acl.is_bot_or_admin())
290 except (datastore_errors.BadValueError, TypeError, ValueError) as e: 303 except (datastore_errors.BadValueError, TypeError, ValueError) as e:
291 raise endpoints.BadRequestException(e.message) 304 raise endpoints.BadRequestException(e.message)
292 305
293 result_summary = task_scheduler.schedule_request(posted_request) 306 result_summary = task_scheduler.schedule_request(posted_request)
294 307
295 previous_result = None 308 previous_result = None
296 if result_summary.deduped_from: 309 if result_summary.deduped_from:
297 previous_result = message_conversion.task_result_to_rpc( 310 previous_result = message_conversion.task_result_to_rpc(
298 result_summary, False) 311 result_summary, False)
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 parts = d.split(':', 1) 627 parts = d.split(':', 1)
615 if len(parts) != 2 or any(i.strip() != i or not i for i in parts): 628 if len(parts) != 2 or any(i.strip() != i or not i for i in parts):
616 raise endpoints.BadRequestException('Invalid dimensions') 629 raise endpoints.BadRequestException('Invalid dimensions')
617 q = q.filter(bot_management.BotInfo.dimensions_flat == d) 630 q = q.filter(bot_management.BotInfo.dimensions_flat == d)
618 bots, cursor = datastore_utils.fetch_page(q, request.limit, request.cursor) 631 bots, cursor = datastore_utils.fetch_page(q, request.limit, request.cursor)
619 return swarming_rpcs.BotList( 632 return swarming_rpcs.BotList(
620 cursor=cursor, 633 cursor=cursor,
621 death_timeout=config.settings().bot_death_timeout_secs, 634 death_timeout=config.settings().bot_death_timeout_secs,
622 items=[message_conversion.bot_info_to_rpc(bot, now) for bot in bots], 635 items=[message_conversion.bot_info_to_rpc(bot, now) for bot in bots],
623 now=now) 636 now=now)
OLDNEW
« no previous file with comments | « appengine/swarming/handlers_bot_test.py ('k') | appengine/swarming/handlers_endpoints_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698