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

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

Issue 2220373003: Allow botlist API call to respond to quarantined: and is_dead: (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-py@master
Patch Set: Change BotsRequest to have quarantined and is_dead Created 4 years, 4 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 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
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 q = q.filter(bot_management.BotInfo.dimensions_flat == d)
631
632 if request.quarantined == 'true':
633 q = q.filter(bot_management.BotInfo.quarantined == True)
634 elif request.quarantined == 'false':
635 q = q.filter(bot_management.BotInfo.quarantined == False)
636
637 dt = datetime.timedelta(
638 seconds=config.settings().bot_death_timeout_secs)
639 timeout = now - dt
640 if request.is_dead == 'true':
641 q = q.filter(bot_management.BotInfo.last_seen_ts < timeout)
642 elif request.is_dead == 'false':
643 q = q.filter(bot_management.BotInfo.last_seen_ts > timeout)
631 bots, cursor = datastore_utils.fetch_page(q, request.limit, request.cursor) 644 bots, cursor = datastore_utils.fetch_page(q, request.limit, request.cursor)
632 return swarming_rpcs.BotList( 645 return swarming_rpcs.BotList(
633 cursor=cursor, 646 cursor=cursor,
634 death_timeout=config.settings().bot_death_timeout_secs, 647 death_timeout=config.settings().bot_death_timeout_secs,
635 items=[message_conversion.bot_info_to_rpc(bot, now) for bot in bots], 648 items=[message_conversion.bot_info_to_rpc(bot, now) for bot in bots],
636 now=now) 649 now=now)
637 650
638 @gae_ts_mon.instrument_endpoint() 651 @gae_ts_mon.instrument_endpoint()
639 @auth.endpoints_method( 652 @auth.endpoints_method(
640 swarming_rpcs.BotsRequest, swarming_rpcs.BotsCount, 653 swarming_rpcs.BotsRequest, swarming_rpcs.BotsCount,
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
683 def get_routes(): 696 def get_routes():
684 return ( 697 return (
685 endpoints_webapp2.api_routes(SwarmingServerService) + 698 endpoints_webapp2.api_routes(SwarmingServerService) +
686 endpoints_webapp2.api_routes(SwarmingTaskService) + 699 endpoints_webapp2.api_routes(SwarmingTaskService) +
687 endpoints_webapp2.api_routes(SwarmingTasksService) + 700 endpoints_webapp2.api_routes(SwarmingTasksService) +
688 endpoints_webapp2.api_routes(SwarmingBotService) + 701 endpoints_webapp2.api_routes(SwarmingBotService) +
689 endpoints_webapp2.api_routes(SwarmingBotsService) + 702 endpoints_webapp2.api_routes(SwarmingBotsService) +
690 # components.config endpoints for validation and configuring of luci-config 703 # components.config endpoints for validation and configuring of luci-config
691 # service URL. 704 # service URL.
692 endpoints_webapp2.api_routes(config.ConfigApi)) 705 endpoints_webapp2.api_routes(config.ConfigApi))
OLDNEW
« no previous file with comments | « no previous file | appengine/swarming/handlers_endpoints_test.py » ('j') | appengine/swarming/swarming_rpcs.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698