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

Side by Side Diff: scripts/master/master_utils.py

Issue 2427413005: Improve slave-preference function (Closed)
Patch Set: Presubmit Created 4 years, 1 month 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
« no previous file with comments | « no previous file | scripts/master/unittests/master_utils_test.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import collections
5 import os 6 import os
6 import random 7 import random
7 import re 8 import re
8 import sys 9 import sys
9 10
10 import buildbot 11 import buildbot
11 from buildbot import interfaces, util 12 from buildbot import interfaces, util
12 from buildbot.buildslave import BuildSlave 13 from buildbot.buildslave import BuildSlave
13 from buildbot.interfaces import IRenderable 14 from buildbot.interfaces import IRenderable
14 from buildbot.status import mail 15 from buildbot.status import mail
(...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 def __call__(self, builder, slave_builders): 663 def __call__(self, builder, slave_builders):
663 if not slave_builders: 664 if not slave_builders:
664 return None 665 return None
665 666
666 preferred_slaves = [ 667 preferred_slaves = [
667 s for s in slave_builders 668 s for s in slave_builders
668 if s.slave.properties.getProperty('preferred_builder') == builder.name] 669 if s.slave.properties.getProperty('preferred_builder') == builder.name]
669 return random.choice(preferred_slaves or slave_builders) 670 return random.choice(preferred_slaves or slave_builders)
670 671
671 672
673 class PreferredBuilderNextSlaveFuncNG(object):
674 """
675 This object, when used as a Builder's 'nextSlave' function, will choose
676 a slave whose 'preferred_builder' value is the same as the builder
677 name. If there is no such slave, a slave is randomly chosen that doesn't
678 prefer any builder. If there is no such slave, a slave is randomly
679 chosen with preference on slaves whose preferred builder has largest
680 currently available capacity. If several sets of slaves have equally large
681 capacity, a set is chosen arbitrarily dependent on internal dictionary order.
682 """
683
684 def __init__(self, choice=random.choice):
685 # Allow overriding the choice function for testability.
686 self._choice = choice
687
688 def __call__(self, builder, slave_builders):
689 if not slave_builders:
690 return None
691
692 prefs = collections.Counter(
693 s.slave.properties.getProperty('preferred_builder')
694 for s in slave_builders)
695 if builder.name in prefs:
696 # First choice: Slaves that prefer this builder.
697 key = builder.name
698 elif None in prefs:
699 # Second choice: Slaves that don't prefer any builders.
700 key = None
701 else:
702 # Third choice: Slaves that prefer other builders but have largest
703 # capacity left. If several groups of slaves with equal capacity exist,
704 # one group will be chosen arbitrarily, the actual slave will be chosen
705 # randomly.
706 key = prefs.most_common()[0][0]
707 return self._choice(
708 s for s in slave_builders
709 if s.slave.properties.getProperty('preferred_builder') == key)
710
711
672 def SetMasterProcessName(): 712 def SetMasterProcessName():
673 """Sets the name of this process to the name of the master. Linux only.""" 713 """Sets the name of this process to the name of the master. Linux only."""
674 714
675 if sys.platform != 'linux2': 715 if sys.platform != 'linux2':
676 return 716 return
677 717
678 command_line.set_command_line("master: %s" % GetMastername()) 718 command_line.set_command_line("master: %s" % GetMastername())
OLDNEW
« no previous file with comments | « no previous file | scripts/master/unittests/master_utils_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698