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 626 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 637 | 637 |
| 638 @gae_ts_mon.instrument_endpoint() | 638 @gae_ts_mon.instrument_endpoint() |
| 639 @auth.endpoints_method( | 639 @auth.endpoints_method( |
| 640 swarming_rpcs.BotsRequest, swarming_rpcs.BotsCount, | 640 swarming_rpcs.BotsRequest, swarming_rpcs.BotsCount, |
| 641 http_method='GET') | 641 http_method='GET') |
| 642 @auth.require(acl.is_privileged_user) | 642 @auth.require(acl.is_privileged_user) |
| 643 def count(self, request): | 643 def count(self, request): |
| 644 """Counts number of bots with given dimensions.""" | 644 """Counts number of bots with given dimensions.""" |
| 645 logging.info('%s', request) | 645 logging.info('%s', request) |
| 646 now = utils.utcnow() | 646 now = utils.utcnow() |
| 647 q = bot_management.BotInfo.query().order() | 647 q = bot_management.BotInfo.query() |
| 648 for d in request.dimensions: | 648 for d in request.dimensions: |
| 649 parts = d.split(':', 1) | 649 parts = d.split(':', 1) |
| 650 if len(parts) != 2 or any(i.strip() != i or not i for i in parts): | 650 if len(parts) != 2 or any(i.strip() != i or not i for i in parts): |
| 651 raise endpoints.BadRequestException('Invalid dimensions: %s' % d) | 651 raise endpoints.BadRequestException('Invalid dimensions: %s' % d) |
| 652 q = q.filter(bot_management.BotInfo.dimensions_flat == d) | 652 q = q.filter(bot_management.BotInfo.dimensions_flat == d) |
| 653 f_count = q.count_async() | 653 f_count = q.count_async() |
| 654 dt = datetime.timedelta(seconds=config.settings().bot_death_timeout_secs) | 654 dt = datetime.timedelta(seconds=config.settings().bot_death_timeout_secs) |
| 655 timeout = now - dt | 655 timeout = now - dt |
| 656 f_dead = q.filter( | 656 f_dead = q.filter( |
| 657 bot_management.BotInfo.last_seen_ts < timeout).count_async() | 657 bot_management.BotInfo.last_seen_ts < timeout).count_async() |
| 658 f_quarantined = q.filter( | 658 f_quarantined = q.filter( |
| 659 bot_management.BotInfo.quarantined == True).count_async() | 659 bot_management.BotInfo.quarantined == True).count_async() |
| 660 f_busy = q.filter(bot_management.BotInfo.is_busy == True).count_async() | 660 f_busy = q.filter(bot_management.BotInfo.is_busy == True).count_async() |
| 661 return swarming_rpcs.BotsCount( | 661 return swarming_rpcs.BotsCount( |
| 662 count=f_count.get_result(), | 662 count=f_count.get_result(), |
| 663 quarantined=f_quarantined.get_result(), | 663 quarantined=f_quarantined.get_result(), |
| 664 dead=f_dead.get_result(), | 664 dead=f_dead.get_result(), |
| 665 busy=f_busy.get_result(), | 665 busy=f_busy.get_result(), |
| 666 now=now) | 666 now=now) |
| 667 | 667 |
| 668 @gae_ts_mon.instrument_endpoint() | |
| 669 @auth.endpoints_method( | |
| 670 message_types.VoidMessage, swarming_rpcs.BotsDimensions, | |
| 671 http_method='GET') | |
| 672 @auth.require(acl.is_privileged_user) | |
| 673 def dimensions(self, request): | |
| 674 """Returns the cached set of dimensions currently in use in the fleet.""" | |
| 675 logging.warn('%s', request) | |
|
M-A Ruel
2016/08/04 21:01:15
info
kjlubick
2016/08/05 14:17:26
Done.
| |
| 676 agg = ndb.Key(bot_management.DimensionAggregation, "current") | |
|
M-A Ruel
2016/08/04 21:01:15
single quote
kjlubick
2016/08/05 14:17:26
Done.
| |
| 677 dims = agg.get() | |
| 678 logging.info(dims) | |
|
M-A Ruel
2016/08/04 21:01:15
don't
kjlubick
2016/08/05 14:17:26
Done.
| |
| 679 fd = [] | |
|
M-A Ruel
2016/08/04 21:01:15
use list comprehension
kjlubick
2016/08/05 14:17:26
Done.
| |
| 680 for d in dims.dimensions: | |
| 681 fd.append(swarming_rpcs.StringListPair( | |
| 682 key=d.dimension, | |
| 683 value=d.values)) | |
| 684 logging.info(fd) | |
|
M-A Ruel
2016/08/04 21:01:15
remove
kjlubick
2016/08/05 14:17:26
Done.
| |
| 685 return swarming_rpcs.BotsDimensions( | |
| 686 fleet_dimensions=fd) | |
|
M-A Ruel
2016/08/04 21:01:15
bot_dimensions?
kjlubick
2016/08/05 14:17:26
Well, it's not the dimensions for just one bot. b
M-A Ruel
2016/08/05 14:36:04
bots_dimensions is better. We don't use the word "
| |
| 687 | |
| 668 | 688 |
| 669 def get_routes(): | 689 def get_routes(): |
| 670 return ( | 690 return ( |
| 671 endpoints_webapp2.api_routes(SwarmingServerService) + | 691 endpoints_webapp2.api_routes(SwarmingServerService) + |
| 672 endpoints_webapp2.api_routes(SwarmingTaskService) + | 692 endpoints_webapp2.api_routes(SwarmingTaskService) + |
| 673 endpoints_webapp2.api_routes(SwarmingTasksService) + | 693 endpoints_webapp2.api_routes(SwarmingTasksService) + |
| 674 endpoints_webapp2.api_routes(SwarmingBotService) + | 694 endpoints_webapp2.api_routes(SwarmingBotService) + |
| 675 endpoints_webapp2.api_routes(SwarmingBotsService) + | 695 endpoints_webapp2.api_routes(SwarmingBotsService) + |
| 676 # components.config endpoints for validation and configuring of luci-config | 696 # components.config endpoints for validation and configuring of luci-config |
| 677 # service URL. | 697 # service URL. |
| 678 endpoints_webapp2.api_routes(config.ConfigApi)) | 698 endpoints_webapp2.api_routes(config.ConfigApi)) |
| OLD | NEW |