Package buildbot :: Package schedulers :: Module manager
[frames] | no frames]

Source Code for Module buildbot.schedulers.manager

 1  # This file is part of Buildbot.  Buildbot is free software: you can 
 2  # redistribute it and/or modify it under the terms of the GNU General Public 
 3  # License as published by the Free Software Foundation, version 2. 
 4  # 
 5  # This program is distributed in the hope that it will be useful, but WITHOUT 
 6  # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 
 7  # FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more 
 8  # details. 
 9  # 
10  # You should have received a copy of the GNU General Public License along with 
11  # this program; if not, write to the Free Software Foundation, Inc., 51 
12  # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 
13  # 
14  # Copyright Buildbot Team Members 
15   
16  from twisted.internet import defer 
17  from twisted.application import service 
18  from twisted.python import log, reflect 
19  from buildbot.process import metrics 
20  from buildbot import config, util 
21 22 -class SchedulerManager(config.ReconfigurableServiceMixin, 23 service.MultiService):
24 - def __init__(self, master):
25 service.MultiService.__init__(self) 26 self.setName('scheduler_manager') 27 self.master = master
28 29 @defer.inlineCallbacks
30 - def reconfigService(self, new_config):
31 timer = metrics.Timer("SchedulerManager.reconfigService") 32 timer.start() 33 34 old_by_name = dict((sch.name, sch) for sch in self) 35 old_set = set(old_by_name.iterkeys()) 36 new_by_name = new_config.schedulers 37 new_set = set(new_by_name.iterkeys()) 38 39 removed_names, added_names = util.diffSets(old_set, new_set) 40 41 # find any schedulers that don't know how to reconfig, and, if they 42 # have changed, add them to both removed and added, so that we 43 # run the new version. While we're at it, find any schedulers whose 44 # fully qualified class name has changed, and consider those a removal 45 # and re-add as well. 46 for n in old_set & new_set: 47 old = old_by_name[n] 48 new = new_by_name[n] 49 # detect changed class name 50 if reflect.qual(old.__class__) != reflect.qual(new.__class__): 51 removed_names.add(n) 52 added_names.add(n) 53 54 # compare using ComparableMixin if they don't support reconfig 55 elif not hasattr(old, 'reconfigService'): 56 if old != new: 57 removed_names.add(n) 58 added_names.add(n) 59 60 # removals first 61 62 for sch_name in removed_names: 63 log.msg("removing scheduler '%s'" % (sch_name,)) 64 sch = old_by_name[sch_name] 65 yield defer.maybeDeferred(lambda : 66 sch.disownServiceParent()) 67 sch.master = None 68 69 # .. then additions 70 71 for sch_name in added_names: 72 log.msg("adding scheduler '%s'" % (sch_name,)) 73 sch = new_by_name[sch_name] 74 75 # get the scheduler's objectid 76 class_name = '%s.%s' % (sch.__class__.__module__, 77 sch.__class__.__name__) 78 objectid = yield self.master.db.state.getObjectId( 79 sch.name, class_name) 80 81 # set up the scheduler 82 sch.objectid = objectid 83 sch.master = self.master 84 85 # *then* attacah and start it 86 sch.setServiceParent(self) 87 88 metrics.MetricCountEvent.log("num_schedulers", len(list(self)), 89 absolute=True) 90 91 # reconfig any newly-added schedulers, as well as existing 92 yield config.ReconfigurableServiceMixin.reconfigService(self, 93 new_config) 94 95 timer.stop()
96