Chromium Code Reviews| Index: scripts/master/master_utils.py |
| diff --git a/scripts/master/master_utils.py b/scripts/master/master_utils.py |
| index 5c6f6bb88798abfd1a58edd2154c626f181baa7d..3da4ae34085e0fdf4f6d96a6a2540d6abe2a84aa 100644 |
| --- a/scripts/master/master_utils.py |
| +++ b/scripts/master/master_utils.py |
| @@ -2,6 +2,7 @@ |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| +import collections |
| import os |
| import random |
| import re |
| @@ -669,6 +670,45 @@ class PreferredBuilderNextSlaveFunc(object): |
| return random.choice(preferred_slaves or slave_builders) |
| +class PreferredBuilderNextSlaveFuncNG(object): |
| + """ |
| + This object, when used as a Builder's 'nextSlave' function, will choose |
| + a slave whose 'preferred_builder' value is the same as the builder |
| + name. If there is no such slave, a slave is randomly chosen that doesn't |
| + prefer any builder if such a slave is available. If not, a slave is randomly |
|
tandrii(chromium)
2016/10/21 13:39:45
if such a slave is available => if any :)
Michael Achenbach
2016/10/21 13:56:23
Done.
|
| + chosen with preference on slaves with higher capacity. If several sets of |
|
tandrii(chromium)
2016/10/21 13:39:45
with preference on => preferring
and maybe
slave
Michael Achenbach
2016/10/21 13:56:24
Done.
|
| + slaves have equally high capacity, a set is chosen arbitrarily dependent on |
|
tandrii(chromium)
2016/10/21 13:39:45
i'd not be that specific, but whatever :)
Michael Achenbach
2016/10/21 13:56:23
Lets keep it.
|
| + internal dictionary order. |
| + """ |
| + |
| + def __init__(self, choice=random.choice): |
| + # Allow overriding the choice function for testability. |
| + self.choice = choice |
|
tandrii(chromium)
2016/10/21 13:39:45
nit: self._choice is nicer, IMO
Michael Achenbach
2016/10/21 13:56:24
Done.
|
| + |
| + def __call__(self, builder, slave_builders): |
| + if not slave_builders: |
| + return None |
| + |
| + prefs = collections.Counter( |
| + s.slave.properties.getProperty('preferred_builder') |
| + for s in slave_builders) |
| + if builder.name in prefs: |
| + # First choice: Slaves that prefer this builder. |
| + key = builder.name |
| + elif None in prefs: |
| + # Second choice: Slaves that don't prefer any builders. |
| + key = None |
| + else: |
| + # Third choice: Slaves that prefer other builders but have largest |
| + # capacity left. If several groups of slaves with equal capacity exist, |
| + # one group will be chosen arbitrarily, the actual slave will be chosen |
| + # randomly. |
| + key = prefs.most_common()[0][0] |
| + return self.choice( |
| + s for s in slave_builders |
| + if s.slave.properties.getProperty('preferred_builder') == key) |
| + |
| + |
| def SetMasterProcessName(): |
| """Sets the name of this process to the name of the master. Linux only.""" |