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

Side by Side Diff: appengine/swarming/server/bot_management.py

Issue 2212073002: Add endpoint and cron job to aggregate all dimensions and values (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-py@master
Patch Set: reuse KEY 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
OLDNEW
1 # Copyright 2014 The LUCI Authors. All rights reserved. 1 # Copyright 2014 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 """Swarming bot management, e.g. list of known bots and their state. 5 """Swarming bot management, e.g. list of known bots and their state.
6 6
7 +---------+ 7 +---------+
8 |BotRoot | 8 |BotRoot |
9 |id=bot_id| 9 |id=bot_id|
10 +---------+ 10 +---------+
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 204
205 Parent is BotRoot. Key id is 'settings'. 205 Parent is BotRoot. Key id is 'settings'.
206 206
207 This entity must always be updated in a transaction. 207 This entity must always be updated in a transaction.
208 """ 208 """
209 # If set to True, no task is handed out to this bot due to the bot being in a 209 # If set to True, no task is handed out to this bot due to the bot being in a
210 # broken situation. 210 # broken situation.
211 quarantined = ndb.BooleanProperty() 211 quarantined = ndb.BooleanProperty()
212 212
213 213
214 class DimensionValues(ndb.Model):
215 dimension = ndb.StringProperty()
216 values = ndb.StringProperty(repeated=True)
217
218
219 class DimensionAggregation(ndb.Model):
220 """Has all dimensions that are currently in use."""
221 dimensions = ndb.LocalStructuredProperty(DimensionValues, repeated=True)
222
223 ts = ndb.DateTimeProperty()
224
225 # We only store one of these entities. Use this key to refer to any instance.
226 KEY = ndb.Key('DimensionAggregation', 'current')
227
228
214 ### Private APIs. 229 ### Private APIs.
215 230
216 231
217 ### Public APIs. 232 ### Public APIs.
218 233
219 234
220 def dimensions_to_flat(dimensions): 235 def dimensions_to_flat(dimensions):
221 out = [] 236 out = []
222 for k, values in dimensions.iteritems(): 237 for k, values in dimensions.iteritems():
223 for v in values: 238 for v in values:
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 Returns: 368 Returns:
354 Tuple (True to restart, text message explaining the reason). 369 Tuple (True to restart, text message explaining the reason).
355 """ 370 """
356 # Periodically reboot bots to workaround OS level leaks (especially on Win). 371 # Periodically reboot bots to workaround OS level leaks (especially on Win).
357 running_time = state.get('running_time', 0) 372 running_time = state.get('running_time', 0)
358 assert isinstance(running_time, (int, float)) 373 assert isinstance(running_time, (int, float))
359 period = get_bot_reboot_period(bot_id, state) 374 period = get_bot_reboot_period(bot_id, state)
360 if period and running_time > period: 375 if period and running_time > period:
361 return True, 'Periodic reboot: running longer than %ds' % period 376 return True, 'Periodic reboot: running longer than %ds' % period
362 return False, '' 377 return False, ''
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698