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

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: simplify cipd server/client embedding in task properties 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
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 if cfg.isolate.default_server and cfg.isolate.default_namespace:
87 properties.inputs_ref = properties.inputs_ref or task_request.FilesRef()
88 properties.inputs_ref.isolatedserver = (
89 properties.inputs_ref.isolatedserver or cfg.isolate.default_server)
90 properties.inputs_ref.namespace = (
91 properties.inputs_ref.namespace or cfg.isolate.default_namespace)
92
93 if cfg.HasField('cipd') and properties.cipd_input:
94 properties.cipd_input.server = (
95 properties.cipd_input.server or cfg.cipd.default_server)
96 properties.cipd_input.client_package = (
97 properties.cipd_input.client_package or task_request.CipdPackage())
98 properties.cipd_input.client_package.package_name = (
99 properties.cipd_input.client_package.package_name or
100 cfg.cipd.default_client_package.package_name)
101 properties.cipd_input.client_package.version = (
102 properties.cipd_input.client_package.version or
103 cfg.cipd.default_client_package.version)
104
105
80 ### API 106 ### API
81 107
82 108
83 swarming_api = auth.endpoints_api( 109 swarming_api = auth.endpoints_api(
84 name='swarming', 110 name='swarming',
85 version='v1', 111 version='v1',
86 description= 112 description=
87 'API to interact with the Swarming service. Permits to create, ' 113 'API to interact with the Swarming service. Permits to create, '
88 'view and cancel tasks, query tasks and bots') 114 'view and cancel tasks, query tasks and bots')
89 115
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 @auth.require(acl.is_bot_or_user) 287 @auth.require(acl.is_bot_or_user)
262 def new(self, request): 288 def new(self, request):
263 """Creates a new task. 289 """Creates a new task.
264 290
265 The task will be enqueued in the tasks list and will be executed at the 291 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 292 earliest opportunity by a bot that has at least the dimensions as described
267 in the task request. 293 in the task request.
268 """ 294 """
269 logging.info('%s', request) 295 logging.info('%s', request)
270 296
271 if request.properties is None:
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: 297 try:
287 request = message_conversion.new_task_request_from_rpc( 298 request = message_conversion.new_task_request_from_rpc(
288 request, utils.utcnow()) 299 request, utils.utcnow())
300 apply_property_defaults(request.properties)
289 posted_request = task_request.make_request(request, acl.is_bot_or_admin()) 301 posted_request = task_request.make_request(request, acl.is_bot_or_admin())
290 except (datastore_errors.BadValueError, TypeError, ValueError) as e: 302 except (datastore_errors.BadValueError, TypeError, ValueError) as e:
291 raise endpoints.BadRequestException(e.message) 303 raise endpoints.BadRequestException(e.message)
292 304
293 result_summary = task_scheduler.schedule_request(posted_request) 305 result_summary = task_scheduler.schedule_request(posted_request)
294 306
295 previous_result = None 307 previous_result = None
296 if result_summary.deduped_from: 308 if result_summary.deduped_from:
297 previous_result = message_conversion.task_result_to_rpc( 309 previous_result = message_conversion.task_result_to_rpc(
298 result_summary, False) 310 result_summary, False)
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 parts = d.split(':', 1) 626 parts = d.split(':', 1)
615 if len(parts) != 2 or any(i.strip() != i or not i for i in parts): 627 if len(parts) != 2 or any(i.strip() != i or not i for i in parts):
616 raise endpoints.BadRequestException('Invalid dimensions') 628 raise endpoints.BadRequestException('Invalid dimensions')
617 q = q.filter(bot_management.BotInfo.dimensions_flat == d) 629 q = q.filter(bot_management.BotInfo.dimensions_flat == d)
618 bots, cursor = datastore_utils.fetch_page(q, request.limit, request.cursor) 630 bots, cursor = datastore_utils.fetch_page(q, request.limit, request.cursor)
619 return swarming_rpcs.BotList( 631 return swarming_rpcs.BotList(
620 cursor=cursor, 632 cursor=cursor,
621 death_timeout=config.settings().bot_death_timeout_secs, 633 death_timeout=config.settings().bot_death_timeout_secs,
622 items=[message_conversion.bot_info_to_rpc(bot, now) for bot in bots], 634 items=[message_conversion.bot_info_to_rpc(bot, now) for bot in bots],
623 now=now) 635 now=now)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698