Chromium Code Reviews| 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 | 9 |
| 10 from google.appengine.api import datastore_errors | 10 from google.appengine.api import datastore_errors |
| (...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 613 swarming_rpcs.BotsRequest, swarming_rpcs.BotList, | 613 swarming_rpcs.BotsRequest, swarming_rpcs.BotList, |
| 614 http_method='GET') | 614 http_method='GET') |
| 615 @auth.require(acl.is_privileged_user) | 615 @auth.require(acl.is_privileged_user) |
| 616 def list(self, request): | 616 def list(self, request): |
| 617 """Provides list of known bots. | 617 """Provides list of known bots. |
| 618 | 618 |
| 619 Deleted bots will not be listed. | 619 Deleted bots will not be listed. |
| 620 """ | 620 """ |
| 621 logging.info('%s', request) | 621 logging.info('%s', request) |
| 622 now = utils.utcnow() | 622 now = utils.utcnow() |
| 623 q = bot_management.BotInfo.query().order(bot_management.BotInfo.key) | 623 q = bot_management.BotInfo.query() |
| 624 for d in request.dimensions: | 624 for d in request.dimensions: |
| 625 if not ':' in d: | 625 if not ':' in d: |
| 626 raise endpoints.BadRequestException('Invalid dimensions') | 626 raise endpoints.BadRequestException('Invalid dimensions') |
| 627 parts = d.split(':', 1) | 627 parts = d.split(':', 1) |
| 628 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): |
| 629 raise endpoints.BadRequestException('Invalid dimensions') | 629 raise endpoints.BadRequestException('Invalid dimensions') |
| 630 q = q.filter(bot_management.BotInfo.dimensions_flat == d) | 630 if parts[0] == 'quarantined': |
|
M-A Ruel
2016/08/08 19:29:51
Please change BotsRequest with formal arguments in
kjlubick
2016/08/08 20:12:05
Done. Should I update BotsCount (line 657ish) to
M-A Ruel
2016/08/08 20:28:00
Yes it should match.
| |
| 631 if parts[1] == 'true': | |
| 632 q = q.filter(bot_management.BotInfo.quarantined == True) | |
| 633 elif parts[1] == 'false': | |
| 634 q = q.filter(bot_management.BotInfo.quarantined == False) | |
| 635 elif parts[0] == 'is_dead': | |
| 636 dt = datetime.timedelta( | |
| 637 seconds=config.settings().bot_death_timeout_secs) | |
| 638 timeout = now - dt | |
| 639 if parts[1] == 'true': | |
| 640 q = q.filter(bot_management.BotInfo.last_seen_ts < timeout) | |
| 641 elif parts[1] == 'false': | |
| 642 q = q.filter(bot_management.BotInfo.last_seen_ts > timeout) | |
| 643 else: | |
| 644 q = q.filter(bot_management.BotInfo.dimensions_flat == d) | |
| 631 bots, cursor = datastore_utils.fetch_page(q, request.limit, request.cursor) | 645 bots, cursor = datastore_utils.fetch_page(q, request.limit, request.cursor) |
| 632 return swarming_rpcs.BotList( | 646 return swarming_rpcs.BotList( |
| 633 cursor=cursor, | 647 cursor=cursor, |
| 634 death_timeout=config.settings().bot_death_timeout_secs, | 648 death_timeout=config.settings().bot_death_timeout_secs, |
| 635 items=[message_conversion.bot_info_to_rpc(bot, now) for bot in bots], | 649 items=[message_conversion.bot_info_to_rpc(bot, now) for bot in bots], |
| 636 now=now) | 650 now=now) |
| 637 | 651 |
| 638 @gae_ts_mon.instrument_endpoint() | 652 @gae_ts_mon.instrument_endpoint() |
| 639 @auth.endpoints_method( | 653 @auth.endpoints_method( |
| 640 swarming_rpcs.BotsRequest, swarming_rpcs.BotsCount, | 654 swarming_rpcs.BotsRequest, swarming_rpcs.BotsCount, |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 683 def get_routes(): | 697 def get_routes(): |
| 684 return ( | 698 return ( |
| 685 endpoints_webapp2.api_routes(SwarmingServerService) + | 699 endpoints_webapp2.api_routes(SwarmingServerService) + |
| 686 endpoints_webapp2.api_routes(SwarmingTaskService) + | 700 endpoints_webapp2.api_routes(SwarmingTaskService) + |
| 687 endpoints_webapp2.api_routes(SwarmingTasksService) + | 701 endpoints_webapp2.api_routes(SwarmingTasksService) + |
| 688 endpoints_webapp2.api_routes(SwarmingBotService) + | 702 endpoints_webapp2.api_routes(SwarmingBotService) + |
| 689 endpoints_webapp2.api_routes(SwarmingBotsService) + | 703 endpoints_webapp2.api_routes(SwarmingBotsService) + |
| 690 # components.config endpoints for validation and configuring of luci-config | 704 # components.config endpoints for validation and configuring of luci-config |
| 691 # service URL. | 705 # service URL. |
| 692 endpoints_webapp2.api_routes(config.ConfigApi)) | 706 endpoints_webapp2.api_routes(config.ConfigApi)) |
| OLD | NEW |