Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Schedulers are only active on one master at a time. This commit adds support for schedulers to be configured and started (as Twisted services), but not active. The scheduler objects poll regularly and become active if the scheduler is not active on any other master. When a master shuts down - either normally or due to a heartbeat timeout - it drops ownership of all schedulers for which it was active. Other than that, this adds some basic endpoints and reflects the findSchedulerById and setSchedulerMaster db methods as update methods.
- Loading branch information
Showing
32 changed files
with
966 additions
and
299 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
# This file is part of Buildbot. Buildbot is free software: you can | ||
# redistribute it and/or modify it under the terms of the GNU General Public | ||
# License as published by the Free Software Foundation, version 2. | ||
# | ||
# This program is distributed in the hope that it will be useful, but WITHOUT | ||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | ||
# details. | ||
# | ||
# You should have received a copy of the GNU General Public License along with | ||
# this program; if not, write to the Free Software Foundation, Inc., 51 | ||
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
# | ||
# Copyright Buildbot Team Members | ||
|
||
from twisted.internet import defer | ||
from buildbot.data import base | ||
|
||
class Db2DataMixin(object): | ||
|
||
@defer.inlineCallbacks | ||
def db2data(self, dbdict): | ||
master = None | ||
if dbdict['masterid'] is not None: | ||
master = yield self.master.data.get({}, | ||
('master', dbdict['masterid'])) | ||
data = { | ||
'schedulerid': dbdict['id'], | ||
'name': dbdict['name'], | ||
'master': master, | ||
'link': base.Link(('scheduler', str(dbdict['id']))), | ||
} | ||
defer.returnValue(data) | ||
|
||
|
||
class SchedulerEndpoint(Db2DataMixin, base.Endpoint): | ||
|
||
pathPatterns = [ | ||
( 'scheduler', 'i:schedulerid' ), | ||
( 'master', 'i:masterid', 'scheduler', 'i:schedulerid' ), | ||
] | ||
|
||
@defer.inlineCallbacks | ||
def get(self, options, kwargs): | ||
dbdict = yield self.master.db.schedulers.getScheduler( | ||
kwargs['schedulerid']) | ||
if 'masterid' in kwargs: | ||
if dbdict['masterid'] != kwargs['masterid']: | ||
return | ||
yield defer.returnValue((yield self.db2data(dbdict)) | ||
if dbdict else None) | ||
|
||
|
||
class SchedulersEndpoint(Db2DataMixin, base.Endpoint): | ||
|
||
pathPatterns = [ | ||
( 'scheduler', ), | ||
( 'master', 'i:masterid', 'scheduler', ), | ||
] | ||
rootLinkName = 'schedulers' | ||
|
||
@defer.inlineCallbacks | ||
def get(self, options, kwargs): | ||
schedulers = yield self.master.db.schedulers.getSchedulers( | ||
masterid=kwargs.get('masterid')) | ||
yield defer.returnValue( | ||
[ (yield self.db2data(schdict)) for schdict in schedulers ]) | ||
|
||
def startConsuming(self, callback, options, kwargs): | ||
return self.master.mq.startConsuming(callback, | ||
('scheduler', None, None)) | ||
|
||
|
||
class SchedulerResourceType(base.ResourceType): | ||
|
||
type = "scheduler" | ||
endpoints = [ SchedulerEndpoint, SchedulersEndpoint ] | ||
keyFields = [ 'schedulerid' ] | ||
|
||
@base.updateMethod | ||
def findSchedulerId(self, name): | ||
return self.master.db.schedulers.findSchedulerId(name) | ||
|
||
@base.updateMethod | ||
def setSchedulerMaster(self, schedulerid, masterid): | ||
# the db method raises the same exception as documented | ||
return self.master.db.schedulers.setSchedulerMaster( | ||
schedulerid, masterid) | ||
|
||
@defer.inlineCallbacks | ||
def _masterDeactivated(self, masterid): | ||
schedulers = yield self.master.db.schedulers.getSchedulers( | ||
masterid=masterid) | ||
for sch in schedulers: | ||
yield self.master.db.schedulers.setSchedulerMaster(sch['id'], None) |
Oops, something went wrong.