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

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

Issue 2198063002: Add bots.count endpoint (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-py@master
Patch Set: copypasta 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
« no previous file with comments | « no previous file | appengine/swarming/swarming_rpcs.py » ('j') | appengine/swarming/swarming_rpcs.py » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 617 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 bots, cursor = datastore_utils.fetch_page(q, request.limit, request.cursor) 631 bots, cursor = datastore_utils.fetch_page(q, request.limit, request.cursor)
632 return swarming_rpcs.BotList( 632 return swarming_rpcs.BotList(
633 cursor=cursor, 633 cursor=cursor,
634 death_timeout=config.settings().bot_death_timeout_secs, 634 death_timeout=config.settings().bot_death_timeout_secs,
635 items=[message_conversion.bot_info_to_rpc(bot, now) for bot in bots], 635 items=[message_conversion.bot_info_to_rpc(bot, now) for bot in bots],
636 now=now) 636 now=now)
637 637
638 @gae_ts_mon.instrument_endpoint()
639 @auth.endpoints_method(
640 swarming_rpcs.BotsRequest, swarming_rpcs.BotsCount,
641 http_method='GET')
642 @auth.require(acl.is_privileged_user)
643 def count(self, request):
644 """Counts number of bots with given dimensions."""
645 logging.info('%s', request)
646 now = utils.utcnow()
647 q = bot_management.BotInfo.query().order(bot_management.BotInfo.key)
M-A Ruel 2016/08/01 15:33:14 order is not needed for counting.
kjlubick 2016/08/01 17:26:32 Done.
648 for d in request.dimensions:
649 if not ':' in d:
M-A Ruel 2016/08/01 15:33:14 this check is not needed because you already check
kjlubick 2016/08/01 17:26:32 Done.
650 raise endpoints.BadRequestException('Invalid dimensions')
M-A Ruel 2016/08/01 15:33:14 ...: %s' % d) ?
kjlubick 2016/08/01 17:26:31 Done.
651 parts = d.split(':', 1)
652 if len(parts) != 2 or any(i.strip() != i or not i for i in parts):
653 raise endpoints.BadRequestException('Invalid dimensions')
654 q = q.filter(bot_management.BotInfo.dimensions_flat == d)
655 bots, cursor = datastore_utils.fetch_page(q)
M-A Ruel 2016/08/01 15:33:14 you don't need to fetch a page, just count, see li
kjlubick 2016/08/01 17:26:32 Done.
656 return swarming_rpcs.BotsCount(
657 count=len(bots),
658 now=now)
659
638 660
639 def get_routes(): 661 def get_routes():
640 return ( 662 return (
641 endpoints_webapp2.api_routes(SwarmingServerService) + 663 endpoints_webapp2.api_routes(SwarmingServerService) +
642 endpoints_webapp2.api_routes(SwarmingTaskService) + 664 endpoints_webapp2.api_routes(SwarmingTaskService) +
643 endpoints_webapp2.api_routes(SwarmingTasksService) + 665 endpoints_webapp2.api_routes(SwarmingTasksService) +
644 endpoints_webapp2.api_routes(SwarmingBotService) + 666 endpoints_webapp2.api_routes(SwarmingBotService) +
645 endpoints_webapp2.api_routes(SwarmingBotsService) + 667 endpoints_webapp2.api_routes(SwarmingBotsService) +
646 # components.config endpoints for validation and configuring of luci-config 668 # components.config endpoints for validation and configuring of luci-config
647 # service URL. 669 # service URL.
648 endpoints_webapp2.api_routes(config.ConfigApi)) 670 endpoints_webapp2.api_routes(config.ConfigApi))
OLDNEW
« no previous file with comments | « no previous file | appengine/swarming/swarming_rpcs.py » ('j') | appengine/swarming/swarming_rpcs.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698