Chromium Code Reviews| 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 ( |