| Index: scripts/master/master_utils.py
|
| diff --git a/scripts/master/master_utils.py b/scripts/master/master_utils.py
|
| index 5c6f6bb88798abfd1a58edd2154c626f181baa7d..ab516a83a44dca76fc7b83e4851030a98562d713 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 there is no such slave, a slave is randomly
|
| + chosen with preference on slaves whose preferred builder has largest
|
| + currently available capacity. If several sets of slaves have equally large
|
| + capacity, a set is chosen arbitrarily dependent on internal dictionary order.
|
| + """
|
| +
|
| + def __init__(self, choice=random.choice):
|
| + # Allow overriding the choice function for testability.
|
| + self._choice = choice
|
| +
|
| + 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."""
|
|
|
|
|