| OLD | NEW |
| 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 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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, secret_bytes = message_conversion.new_task_request_from_rpc( | 343 request, secret_bytes = 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( | 346 task_request.init_new_request( |
| 347 request, acl.is_bot_or_admin(), secret_bytes) | 347 request, acl.can_schedule_high_priority_tasks(), secret_bytes) |
| 348 except (datastore_errors.BadValueError, TypeError, ValueError) as e: | 348 except (datastore_errors.BadValueError, TypeError, ValueError) as e: |
| 349 raise endpoints.BadRequestException(e.message) | 349 raise endpoints.BadRequestException(e.message) |
| 350 | 350 |
| 351 result_summary = task_scheduler.schedule_request(request, secret_bytes) | 351 result_summary = task_scheduler.schedule_request(request, secret_bytes) |
| 352 | 352 |
| 353 previous_result = None | 353 previous_result = None |
| 354 if result_summary.deduped_from: | 354 if result_summary.deduped_from: |
| 355 previous_result = message_conversion.task_result_to_rpc( | 355 previous_result = message_conversion.task_result_to_rpc( |
| 356 result_summary, False) | 356 result_summary, False) |
| 357 | 357 |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 595 # TODO(maruel): Disallow a terminate task when there's one currently | 595 # TODO(maruel): Disallow a terminate task when there's one currently |
| 596 # 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 |
| 597 # minutes. | 597 # minutes. |
| 598 logging.info('%s', request) | 598 logging.info('%s', request) |
| 599 bot_id = unicode(request.bot_id) | 599 bot_id = unicode(request.bot_id) |
| 600 bot_key = bot_management.get_info_key(bot_id) | 600 bot_key = bot_management.get_info_key(bot_id) |
| 601 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 |
| 602 try: | 602 try: |
| 603 # 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. |
| 604 request = task_request.create_termination_task( | 604 request = task_request.create_termination_task( |
| 605 bot_id, acl.is_bot_or_admin()) | 605 bot_id, acl.can_schedule_high_priority_tasks()) |
| 606 except (datastore_errors.BadValueError, TypeError, ValueError) as e: | 606 except (datastore_errors.BadValueError, TypeError, ValueError) as e: |
| 607 raise endpoints.BadRequestException(e.message) | 607 raise endpoints.BadRequestException(e.message) |
| 608 | 608 |
| 609 result_summary = task_scheduler.schedule_request(request, None) | 609 result_summary = task_scheduler.schedule_request(request, None) |
| 610 return swarming_rpcs.TerminateResponse( | 610 return swarming_rpcs.TerminateResponse( |
| 611 task_id=task_pack.pack_result_summary_key(result_summary.key)) | 611 task_id=task_pack.pack_result_summary_key(result_summary.key)) |
| 612 | 612 |
| 613 @gae_ts_mon.instrument_endpoint() | 613 @gae_ts_mon.instrument_endpoint() |
| 614 @auth.endpoints_method( | 614 @auth.endpoints_method( |
| 615 BotTasksRequest, swarming_rpcs.BotTasks, | 615 BotTasksRequest, swarming_rpcs.BotTasks, |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 730 def get_routes(): | 730 def get_routes(): |
| 731 return ( | 731 return ( |
| 732 endpoints_webapp2.api_routes(SwarmingServerService) + | 732 endpoints_webapp2.api_routes(SwarmingServerService) + |
| 733 endpoints_webapp2.api_routes(SwarmingTaskService) + | 733 endpoints_webapp2.api_routes(SwarmingTaskService) + |
| 734 endpoints_webapp2.api_routes(SwarmingTasksService) + | 734 endpoints_webapp2.api_routes(SwarmingTasksService) + |
| 735 endpoints_webapp2.api_routes(SwarmingBotService) + | 735 endpoints_webapp2.api_routes(SwarmingBotService) + |
| 736 endpoints_webapp2.api_routes(SwarmingBotsService) + | 736 endpoints_webapp2.api_routes(SwarmingBotsService) + |
| 737 # components.config endpoints for validation and configuring of luci-config | 737 # components.config endpoints for validation and configuring of luci-config |
| 738 # service URL. | 738 # service URL. |
| 739 endpoints_webapp2.api_routes(config.ConfigApi)) | 739 endpoints_webapp2.api_routes(config.ConfigApi)) |
| OLD | NEW |