1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 from zope.interface import implements
17 from twisted.python import log
18 from twisted.internet import defer
19 from twisted.application import service
20 from buildbot import interfaces, config, util
21 from buildbot.process import metrics
22
23 -class ChangeManager(config.ReconfigurableServiceMixin, service.MultiService):
24 """
25 This is the master-side service which receives file change notifications
26 from version-control systems.
27
28 It is a Twisted service, which has instances of
29 L{buildbot.interfaces.IChangeSource} as child services. These are added by
30 the master with C{addSource}.
31 """
32
33 implements(interfaces.IEventSource)
34
35 name = "changemanager"
36
41
42 @defer.deferredGenerator
44 timer = metrics.Timer("ChangeManager.reconfigService")
45 timer.start()
46
47 removed, added = util.diffSets(
48 set(self),
49 new_config.change_sources)
50
51 if removed or added:
52 log.msg("adding %d new changesources, removing %d" %
53 (len(added), len(removed)))
54
55 for src in removed:
56 wfd = defer.waitForDeferred(
57 defer.maybeDeferred(
58 src.disownServiceParent))
59 yield wfd
60 wfd.getResult()
61 src.master = None
62
63 for src in added:
64 src.master = self.master
65 src.setServiceParent(self)
66
67 num_sources = len(list(self))
68 assert num_sources == len(new_config.change_sources)
69 metrics.MetricCountEvent.log("num_sources", num_sources, absolute=True)
70
71
72 wfd = defer.waitForDeferred(
73 config.ReconfigurableServiceMixin.reconfigService(self,
74 new_config))
75 yield wfd
76 wfd.getResult()
77
78 timer.stop()
79