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

Unified 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, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | appengine/swarming/swarming_rpcs.py » ('j') | appengine/swarming/swarming_rpcs.py » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: appengine/swarming/handlers_endpoints.py
diff --git a/appengine/swarming/handlers_endpoints.py b/appengine/swarming/handlers_endpoints.py
index ef39512802e46fa7c7c6bc8ed55934f9f246d0d0..6b2f436e4d8637840624bf735f1432be543aa5a1 100644
--- a/appengine/swarming/handlers_endpoints.py
+++ b/appengine/swarming/handlers_endpoints.py
@@ -635,6 +635,28 @@ class SwarmingBotsService(remote.Service):
items=[message_conversion.bot_info_to_rpc(bot, now) for bot in bots],
now=now)
+ @gae_ts_mon.instrument_endpoint()
+ @auth.endpoints_method(
+ swarming_rpcs.BotsRequest, swarming_rpcs.BotsCount,
+ http_method='GET')
+ @auth.require(acl.is_privileged_user)
+ def count(self, request):
+ """Counts number of bots with given dimensions."""
+ logging.info('%s', request)
+ now = utils.utcnow()
+ 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.
+ for d in request.dimensions:
+ 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.
+ raise endpoints.BadRequestException('Invalid dimensions')
M-A Ruel 2016/08/01 15:33:14 ...: %s' % d) ?
kjlubick 2016/08/01 17:26:31 Done.
+ parts = d.split(':', 1)
+ if len(parts) != 2 or any(i.strip() != i or not i for i in parts):
+ raise endpoints.BadRequestException('Invalid dimensions')
+ q = q.filter(bot_management.BotInfo.dimensions_flat == d)
+ 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.
+ return swarming_rpcs.BotsCount(
+ count=len(bots),
+ now=now)
+
def get_routes():
return (
« 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