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.deferredGenerator
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 wfd = defer.waitForDeferred( 66 defer.maybeDeferred(lambda : 67 sch.disownServiceParent())) 68 yield wfd 69 wfd.getResult() 70 sch.master = None 71 72 # .. then additions 73 74 for sch_name in added_names: 75 log.msg("adding scheduler '%s'" % (sch_name,)) 76 sch = new_by_name[sch_name] 77 78 # get the scheduler's objectid 79 class_name = '%s.%s' % (sch.__class__.__module__, 80 sch.__class__.__name__) 81 wfd = defer.waitForDeferred( 82 self.master.db.state.getObjectId( 83 sch.name, class_name)) 84 yield wfd 85 objectid = wfd.getResult() 86 87 # set up the scheduler 88 sch.objectid = objectid 89 sch.master = self.master 90 91 # *then* attacah and start it 92 sch.setServiceParent(self) 93 94 metrics.MetricCountEvent.log("num_schedulers", len(list(self)), 95 absolute=True) 96 97 # reconfig any newly-added schedulers, as well as existing 98 wfd = defer.waitForDeferred( 99 config.ReconfigurableServiceMixin.reconfigService(self, 100 new_config)) 101 yield wfd 102 wfd.getResult() 103 104 timer.stop()
105