Trees | Indices | Help |
|
---|
|
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 import textwrap 17 from twisted.internet import defer 18 from twisted.python import log 19 from twisted.application import internet, service 20 from buildbot import config 21 from buildbot.db import enginestrategy 22 from buildbot.db import pool, model, changes, schedulers, sourcestamps, sourcestampsets 23 from buildbot.db import state, buildsets, buildrequests, builds, users 24 27 28 upgrade_message = textwrap.dedent("""\ 29 30 The Buildmaster database needs to be upgraded before this version of 31 buildbot can run. Use the following command-line 32 33 buildbot upgrade-master path/to/master 34 35 to upgrade the database, and try starting the buildmaster again. You may 36 want to make a backup of your buildmaster before doing so. 37 """).strip() 3840 # The connection between Buildbot and its backend database. This is 41 # generally accessible as master.db, but is also used during upgrades. 42 # 43 # Most of the interesting operations available via the connector are 44 # implemented in connector components, available as attributes of this 45 # object, and listed below. 46 47 # Period, in seconds, of the cleanup task. This master will perform 48 # periodic cleanup actions on this schedule. 49 CLEANUP_PERIOD = 3600 50103 10452 service.MultiService.__init__(self) 53 self.setName('db') 54 self.master = master 55 self.basedir = basedir 56 57 # not configured yet - we don't build an engine until the first 58 # reconfig 59 self.configured_url = None 60 61 # set up components 62 self._engine = None # set up in reconfigService 63 self.pool = None # set up in reconfigService 64 self.model = model.Model(self) 65 self.changes = changes.ChangesConnectorComponent(self) 66 self.schedulers = schedulers.SchedulersConnectorComponent(self) 67 self.sourcestamps = sourcestamps.SourceStampsConnectorComponent(self) 68 self.sourcestampsets = sourcestampsets.SourceStampSetsConnectorComponent(self) 69 self.buildsets = buildsets.BuildsetsConnectorComponent(self) 70 self.buildrequests = buildrequests.BuildRequestsConnectorComponent(self) 71 self.state = state.StateConnectorComponent(self) 72 self.builds = builds.BuildsConnectorComponent(self) 73 self.users = users.UsersConnectorComponent(self) 74 75 self.cleanup_timer = internet.TimerService(self.CLEANUP_PERIOD, 76 self._doCleanup) 77 self.cleanup_timer.setServiceParent(self)78 7981 db_url = self.configured_url = self.master.config.db['db_url'] 82 83 log.msg("Setting up database with URL %r" % (db_url,)) 84 85 # set up the engine and pool 86 self._engine = enginestrategy.create_engine(db_url, 87 basedir=self.basedir) 88 self.pool = pool.DBThreadPool(self._engine, verbose=verbose) 89 90 # make sure the db is up to date, unless specifically asked not to 91 if check_version: 92 d = self.model.is_current() 93 def check_current(res): 94 if not res: 95 for l in upgrade_message.split('\n'): 96 log.msg(l) 97 raise DatabaseNotReadyError()98 d.addCallback(check_current) 99 else: 100 d = defer.succeed(None) 101 102 return d106 # double-check -- the master ensures this in config checks 107 assert self.configured_url == new_config.db['db_url'] 108 109 return config.ReconfigurableServiceMixin.reconfigService(self, 110 new_config)111 112114 """ 115 Perform any periodic database cleanup tasks. 116 117 @returns: Deferred 118 """ 119 # pass on this if we're not configured yet 120 if not self.configured_url: 121 return 122 123 d = self.changes.pruneChanges(self.master.config.changeHorizon) 124 d.addErrback(log.err, 'while pruning changes') 125 return d126
Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Wed Nov 21 16:23:03 2012 | http://epydoc.sourceforge.net |