Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'BuildslaveDatabase' of git://github.com/jaredgrubb/buil…
…dbot
- Loading branch information
Showing
18 changed files
with
656 additions
and
37 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
# 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 | ||
|
||
import sqlalchemy as sa | ||
from buildbot.db import base | ||
|
||
class BuildslavesConnectorComponent(base.DBConnectorComponent): | ||
# Documentation is in developer/database.rst | ||
|
||
def getBuildslaves(self): | ||
def thd(conn): | ||
tbl = self.db.model.buildslaves | ||
rows = conn.execute(tbl.select()).fetchall() | ||
|
||
dicts = [] | ||
if rows: | ||
for row in rows: | ||
dicts.append({ | ||
'slaveid': row.id, | ||
'name': row.name | ||
}) | ||
return dicts | ||
d = self.db.pool.do(thd) | ||
return d | ||
|
||
def getBuildslaveByName(self, name): | ||
def thd(conn): | ||
tbl = self.db.model.buildslaves | ||
res = conn.execute(tbl.select(whereclause=(tbl.c.name == name))) | ||
row = res.fetchone() | ||
|
||
rv = None | ||
if row: | ||
rv = self._bdictFromRow(row) | ||
res.close() | ||
return rv | ||
return self.db.pool.do(thd) | ||
|
||
def updateBuildslave(self, name, slaveinfo, _race_hook=None): | ||
def thd(conn): | ||
transaction = conn.begin() | ||
|
||
tbl = self.db.model.buildslaves | ||
|
||
# first try update, then try insert | ||
q = tbl.update(whereclause=(tbl.c.name == name)) | ||
res = conn.execute(q, info=slaveinfo) | ||
|
||
if res.rowcount == 0: | ||
_race_hook and _race_hook(conn) | ||
|
||
# the update hit 0 rows, so try inserting a new one | ||
try: | ||
q = tbl.insert() | ||
res = conn.execute(q, | ||
name=name, | ||
info=slaveinfo) | ||
except (sa.exc.IntegrityError, sa.exc.ProgrammingError): | ||
# someone else beat us to the punch inserting this row; | ||
# let them win. | ||
transaction.rollback() | ||
return | ||
|
||
transaction.commit() | ||
return self.db.pool.do(thd) | ||
|
||
def _bdictFromRow(self, row): | ||
return { | ||
'slaveid': row.id, | ||
'name': row.name, | ||
'slaveinfo': row.info | ||
} |
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
33 changes: 33 additions & 0 deletions
33
master/buildbot/db/migrate/versions/024_add_buildslaves_table.py
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,33 @@ | ||
# 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 | ||
|
||
import sqlalchemy as sa | ||
from buildbot.db.types.json import JsonObject | ||
|
||
def upgrade(migrate_engine): | ||
|
||
metadata = sa.MetaData() | ||
metadata.bind = migrate_engine | ||
|
||
buildslaves = sa.Table("buildslaves", metadata, | ||
sa.Column("id", sa.Integer, primary_key=True), | ||
sa.Column("name", sa.String(256), nullable=False), | ||
sa.Column("info", JsonObject, nullable=False), | ||
) | ||
buildslaves.create() | ||
|
||
idx = sa.Index('buildslaves_name', buildslaves.c.name) | ||
idx.create() | ||
|
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
Empty file.
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,35 @@ | ||
# 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 buildbot.util import json | ||
from sqlalchemy.types import TypeDecorator, Text | ||
|
||
class JsonObject(TypeDecorator): | ||
"""Represents an immutable json-encoded string.""" | ||
|
||
impl = Text | ||
|
||
def process_bind_param(self, value, dialect): | ||
if value is not None: | ||
value = json.dumps(value) | ||
|
||
return value | ||
|
||
def process_result_value(self, value, dialect): | ||
if value is not None: | ||
value = json.loads(value) | ||
else: | ||
value = {} | ||
return value |
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
Oops, something went wrong.