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

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: fix import google.protobuf 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 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 swarming_rpcs.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 cipd_input = properties.cipd_input
94 if cipd_input and not cipd_input.settings and cfg.HasField('cipd'):
95 cipd_input.settings = cfg.cipd.SerializeToString()
96
97
80 ### API 98 ### API
81 99
82 100
83 swarming_api = auth.endpoints_api( 101 swarming_api = auth.endpoints_api(
84 name='swarming', 102 name='swarming',
85 version='v1', 103 version='v1',
86 description= 104 description=
87 'API to interact with the Swarming service. Permits to create, ' 105 'API to interact with the Swarming service. Permits to create, '
88 'view and cancel tasks, query tasks and bots') 106 'view and cancel tasks, query tasks and bots')
89 107
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 282
265 The task will be enqueued in the tasks list and will be executed at the 283 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 284 earliest opportunity by a bot that has at least the dimensions as described
267 in the task request. 285 in the task request.
268 """ 286 """
269 logging.info('%s', request) 287 logging.info('%s', request)
270 288
271 if request.properties is None: 289 if request.properties is None:
272 raise endpoints.BadRequestException('properties are required') 290 raise endpoints.BadRequestException('properties are required')
273 291
274 # Apply isolate defaults. 292 apply_property_defaults(request.properties)
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 293
286 try: 294 try:
287 request = message_conversion.new_task_request_from_rpc( 295 request = message_conversion.new_task_request_from_rpc(
288 request, utils.utcnow()) 296 request, utils.utcnow())
289 posted_request = task_request.make_request(request, acl.is_bot_or_admin()) 297 posted_request = task_request.make_request(request, acl.is_bot_or_admin())
290 except (datastore_errors.BadValueError, TypeError, ValueError) as e: 298 except (datastore_errors.BadValueError, TypeError, ValueError) as e:
291 raise endpoints.BadRequestException(e.message) 299 raise endpoints.BadRequestException(e.message)
292 300
293 result_summary = task_scheduler.schedule_request(posted_request) 301 result_summary = task_scheduler.schedule_request(posted_request)
294 302
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 parts = d.split(':', 1) 622 parts = d.split(':', 1)
615 if len(parts) != 2 or any(i.strip() != i or not i for i in parts): 623 if len(parts) != 2 or any(i.strip() != i or not i for i in parts):
616 raise endpoints.BadRequestException('Invalid dimensions') 624 raise endpoints.BadRequestException('Invalid dimensions')
617 q = q.filter(bot_management.BotInfo.dimensions_flat == d) 625 q = q.filter(bot_management.BotInfo.dimensions_flat == d)
618 bots, cursor = datastore_utils.fetch_page(q, request.limit, request.cursor) 626 bots, cursor = datastore_utils.fetch_page(q, request.limit, request.cursor)
619 return swarming_rpcs.BotList( 627 return swarming_rpcs.BotList(
620 cursor=cursor, 628 cursor=cursor,
621 death_timeout=config.settings().bot_death_timeout_secs, 629 death_timeout=config.settings().bot_death_timeout_secs,
622 items=[message_conversion.bot_info_to_rpc(bot, now) for bot in bots], 630 items=[message_conversion.bot_info_to_rpc(bot, now) for bot in bots],
623 now=now) 631 now=now)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698