 Chromium Code Reviews
 Chromium Code Reviews 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
    
  
    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| Index: appengine/swarming/server/bot_management.py | 
| diff --git a/appengine/swarming/server/bot_management.py b/appengine/swarming/server/bot_management.py | 
| index feff1773397b570f2ff84e94429fc4195d6db657..34aab8dd35a635a535a5c608efb1be3e7214fdef 100644 | 
| --- a/appengine/swarming/server/bot_management.py | 
| +++ b/appengine/swarming/server/bot_management.py | 
| @@ -28,16 +28,19 @@ | 
| entities which are generated from data provided by the bot itself. | 
| """ | 
| +import datetime | 
| import hashlib | 
| from google.appengine.ext import ndb | 
| +import swarming_rpcs | 
| from components import datastore_utils | 
| from components import utils | 
| from server import config | 
| from server import task_pack | 
| 
M-A Ruel
2016/08/09 20:23:13
remove one line
 
kjlubick
2016/08/09 20:44:44
Done.
 | 
| + | 
| # Margin of randomization of BOT_REBOOT_PERIOD_SECS. Per-bot period will be in | 
| # range [period * (1 - margin), period * (1 + margin)). | 
| BOT_REBOOT_PERIOD_RANDOMIZATION_MARGIN = 0.2 | 
| @@ -267,6 +270,32 @@ def get_settings_key(bot_id): | 
| return ndb.Key(BotSettings, 'settings', parent=get_root_key(bot_id)) | 
| +def filter_dimensions(q, dimensions): | 
| + """Filters a ndb.Query for BotInfo based on dimensions in the request.""" | 
| + for d in dimensions: | 
| + parts = d.split(':', 1) | 
| + if len(parts) != 2 or any(i.strip() != i or not i for i in parts): | 
| + raise ValueError('Invalid dimensions') | 
| + q = q.filter(BotInfo.dimensions_flat == d) | 
| + return q | 
| + | 
| + | 
| +def filter_availability(q, quarantined, is_dead, now): | 
| + """Filters a ndb.Query for BotInfo based on quarantined/is_dead.""" | 
| + val = swarming_rpcs.to_bool(quarantined) | 
| 
M-A Ruel
2016/08/09 20:23:13
actually that's a layering violation :/  Here only
 
kjlubick
2016/08/09 20:44:44
Done.
 | 
| + if val is not None: | 
| + q = q.filter(BotInfo.quarantined == val) | 
| + | 
| + dt = datetime.timedelta(seconds=config.settings().bot_death_timeout_secs) | 
| + timeout = now - dt | 
| + val = swarming_rpcs.to_bool(is_dead) | 
| + if val: | 
| + q = q.filter(BotInfo.last_seen_ts < timeout) | 
| + elif val is not None: | 
| + q = q.filter(BotInfo.last_seen_ts > timeout) | 
| + return q | 
| + | 
| + | 
| def bot_event( | 
| event_type, bot_id, external_ip, authenticated_as, dimensions, state, | 
| version, quarantined, task_id, task_name, **kwargs): |