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

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

Issue 2463483002: swarming: allow privileged users to schedule high priority tasks (Closed)
Patch Set: Created 4 years, 1 month 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 under the Apache License, Version 2.0 2 # Use of this source code is governed under the Apache License, Version 2.0
3 # that can be found in the LICENSE file. 3 # that can be 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 logging 8 import logging
9 import os 9 import os
10 10
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 The task will be enqueued in the tasks list and will be executed at the 336 The task will be enqueued in the tasks list and will be executed at the
337 earliest opportunity by a bot that has at least the dimensions as described 337 earliest opportunity by a bot that has at least the dimensions as described
338 in the task request. 338 in the task request.
339 """ 339 """
340 logging.info('%s', request) 340 logging.info('%s', request)
341 341
342 try: 342 try:
343 request = message_conversion.new_task_request_from_rpc( 343 request = message_conversion.new_task_request_from_rpc(
344 request, utils.utcnow()) 344 request, utils.utcnow())
345 apply_property_defaults(request.properties) 345 apply_property_defaults(request.properties)
346 task_request.init_new_request(request, acl.is_bot_or_admin()) 346 task_request.init_new_request(
347 request, acl.can_schedule_high_priority_tasks())
347 except (datastore_errors.BadValueError, TypeError, ValueError) as e: 348 except (datastore_errors.BadValueError, TypeError, ValueError) as e:
348 raise endpoints.BadRequestException(e.message) 349 raise endpoints.BadRequestException(e.message)
349 350
350 result_summary = task_scheduler.schedule_request(request) 351 result_summary = task_scheduler.schedule_request(request)
351 352
352 previous_result = None 353 previous_result = None
353 if result_summary.deduped_from: 354 if result_summary.deduped_from:
354 previous_result = message_conversion.task_result_to_rpc( 355 previous_result = message_conversion.task_result_to_rpc(
355 result_summary, False) 356 result_summary, False)
356 357
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 # TODO(maruel): Disallow a terminate task when there's one currently 595 # TODO(maruel): Disallow a terminate task when there's one currently
595 # pending or if the bot is considered 'dead', e.g. no contact since 10 596 # pending or if the bot is considered 'dead', e.g. no contact since 10
596 # minutes. 597 # minutes.
597 logging.info('%s', request) 598 logging.info('%s', request)
598 bot_id = unicode(request.bot_id) 599 bot_id = unicode(request.bot_id)
599 bot_key = bot_management.get_info_key(bot_id) 600 bot_key = bot_management.get_info_key(bot_id)
600 get_or_raise(bot_key) # raises 404 if there is no such bot 601 get_or_raise(bot_key) # raises 404 if there is no such bot
601 try: 602 try:
602 # Craft a special priority 0 task to tell the bot to shutdown. 603 # Craft a special priority 0 task to tell the bot to shutdown.
603 request = task_request.create_termination_task( 604 request = task_request.create_termination_task(
604 bot_id, acl.is_bot_or_admin()) 605 bot_id, acl.can_schedule_high_priority_tasks())
605 except (datastore_errors.BadValueError, TypeError, ValueError) as e: 606 except (datastore_errors.BadValueError, TypeError, ValueError) as e:
606 raise endpoints.BadRequestException(e.message) 607 raise endpoints.BadRequestException(e.message)
607 608
608 result_summary = task_scheduler.schedule_request(request) 609 result_summary = task_scheduler.schedule_request(request)
609 return swarming_rpcs.TerminateResponse( 610 return swarming_rpcs.TerminateResponse(
610 task_id=task_pack.pack_result_summary_key(result_summary.key)) 611 task_id=task_pack.pack_result_summary_key(result_summary.key))
611 612
612 @gae_ts_mon.instrument_endpoint() 613 @gae_ts_mon.instrument_endpoint()
613 @auth.endpoints_method( 614 @auth.endpoints_method(
614 BotTasksRequest, swarming_rpcs.BotTasks, 615 BotTasksRequest, swarming_rpcs.BotTasks,
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
729 def get_routes(): 730 def get_routes():
730 return ( 731 return (
731 endpoints_webapp2.api_routes(SwarmingServerService) + 732 endpoints_webapp2.api_routes(SwarmingServerService) +
732 endpoints_webapp2.api_routes(SwarmingTaskService) + 733 endpoints_webapp2.api_routes(SwarmingTaskService) +
733 endpoints_webapp2.api_routes(SwarmingTasksService) + 734 endpoints_webapp2.api_routes(SwarmingTasksService) +
734 endpoints_webapp2.api_routes(SwarmingBotService) + 735 endpoints_webapp2.api_routes(SwarmingBotService) +
735 endpoints_webapp2.api_routes(SwarmingBotsService) + 736 endpoints_webapp2.api_routes(SwarmingBotsService) +
736 # components.config endpoints for validation and configuring of luci-config 737 # components.config endpoints for validation and configuring of luci-config
737 # service URL. 738 # service URL.
738 endpoints_webapp2.api_routes(config.ConfigApi)) 739 endpoints_webapp2.api_routes(config.ConfigApi))
OLDNEW
« no previous file with comments | « no previous file | appengine/swarming/handlers_frontend.py » ('j') | appengine/swarming/server/acl.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698