def removeQueuedBuilds(self, removed_builders): if len(removed_builders): log.msg( "removing %d builds from the build queue, the builder(s) was removed" % len(removed_builders)) for brdict in removed_builders: br = yield BuildRequest.fromBrdict(self.master, brdict) brc = BuildRequestControl(None, br) yield brc.cancel()
def _getBuildRequestForBrdict(self, brdict): # Turn a brdict into a BuildRequest into a brdict. This is useful # for API like 'nextBuild', which operate on BuildRequest objects. breq = self.breqCache.get(brdict['buildrequestid']) if not breq: breq = yield BuildRequest.fromBrdict(self.master, brdict) if breq: self.breqCache[brdict['buildrequestid']] = breq defer.returnValue(breq)
def get_incomplete_build_requests(self): """Returns not yet completed build requests from the database as Deferred. """ build_request_dicts = yield self.master.db.buildrequests.getBuildRequests( complete=False) requests = [] for brdict in build_request_dicts: # TODO(nodir): optimize: run these queries in parallel. req = yield BuildRequest.fromBrdict(self.master, brdict) requests.append(BuildRequestGateway(self.master, build_request=req)) returnValue(requests)
def _txn_getBuildRequestWithNumber(self, t, brid): assert isinstance(brid, (int, long)) t.execute(self.quoteq("SELECT br.buildsetid, bs.reason," " bs.sourcestampid, br.buildername," " bs.submitted_at, br.priority" " FROM buildrequests AS br, buildsets AS bs" " WHERE br.id=? AND br.buildsetid=bs.id"), (brid,)) r = t.fetchall() if not r: return None (bsid, reason, ssid, builder_name, submitted_at, priority) = r[0] ss = self.getSourceStampNumberedNow(ssid, t) properties = self.get_properties_from_db("buildset_properties", "buildsetid", bsid, t) br = BuildRequest(reason, ss, builder_name, properties) br.submittedAt = submitted_at br.priority = priority br.id = brid br.bsid = bsid return br
def testGoodStep(self): f = BuildFactory() f.addStep(SetProperty(command=["echo", "value"], property="propname")) ss = SourceStamp() req = BuildRequest("Testing", ss, None) b = f.newBuild([req]) b.build_status = FakeBuildStatus() b.slavebuilder = FakeSlaveBuilder() # This shouldn't raise an exception b.setupBuild(None)
def get_incomplete_build_requests(self): """Returns not yet completed build requests from the database as Deferred. Does not return build requests for non-existing builders. """ build_request_dicts = yield self.master.db.buildrequests.getBuildRequests( complete=False, buildername=self.master.getStatus().getBuilderNames()) requests = [] for brdict in build_request_dicts: # TODO(nodir): optimize: run these queries in parallel. req = yield BuildRequest.fromBrdict(self.master, brdict) requests.append(BuildRequestGateway(self.master, build_request=req)) returnValue(requests)
def partial_build_dict(self, master, buildrequest): brdict = yield master.db.buildrequests.getBuildRequest(buildrequest['buildrequestid']) bdict = {} props = Properties() buildrequest = yield BuildRequest.fromBrdict(master, brdict) builder = yield master.botmaster.getBuilderById(brdict['builderid']) Build.setupPropertiesKnownBeforeBuildStarts(props, [buildrequest], builder) Build.setupBuildProperties(props, [buildrequest]) bdict['properties'] = props.asDict() yield utils.get_details_for_buildrequest(master, brdict, bdict) return bdict
def _getBuildRequest(self, master, brdict, buildSets, buildSetsProperties, sources): buildSetId = brdict['buildsetid'] assert buildSetId in buildSets # schema should guarantee this buildset = buildSets[buildSetId] # fetch the buildset properties, and convert to Properties buildSetProperties = {} if buildSetId in buildSetsProperties: buildSetProperties = buildSetsProperties[buildSetId] props = properties.Properties.fromDict(buildSetProperties) return BuildRequest.makeBuildRequest(master, brdict, buildset, props, sources)
def _txn_getBuildRequestWithNumber(self, t, brid): assert isinstance(brid, (int, long)) t.execute( self.quoteq("SELECT br.buildsetid, bs.reason," " bs.sourcestampid, br.buildername," " bs.submitted_at, br.priority" " FROM buildrequests AS br, buildsets AS bs" " WHERE br.id=? AND br.buildsetid=bs.id"), (brid, )) r = t.fetchall() if not r: return None (bsid, reason, ssid, builder_name, submitted_at, priority) = r[0] ss = self.getSourceStampNumberedNow(ssid, t) properties = self.get_properties_from_db("buildset_properties", "buildsetid", bsid, t) br = BuildRequest.oldConstructor(reason, ss, builder_name, properties) br.submittedAt = submitted_at br.priority = priority br.id = brid br.bsid = bsid return br
def performAction(self, req): status = self.getStatus(req) master = req.site.buildbot_service.master c = interfaces.IControl(self.getBuildmaster(req)) buildrequest = [int(b) for b in req.args.get("cancelselected", []) if b] brdicts = yield master.db.buildrequests.getBuildRequestInQueue(brids=buildrequest) for brdict in brdicts: br = yield BuildRequest.fromBrdict( master, brdict) b = master.botmaster.builders[brdict['buildername']] brc = BuildRequestControl(b, br) yield brc.cancel() # go back to the buildqueue page pending_builds_url = req.args.get("pending_builds_url", None) if pending_builds_url: defer.returnValue(pending_builds_url[0]) elif req.args.has_key("ajax"): defer.returnValue(path_to_buildqueue_json(req)) else: defer.returnValue(path_to_buildqueue(req))
def _ensure_build_request(self): if self.build_request: return assert self.brid brdict = yield self.master.db.buildrequests.getBuildRequest(self.brid) self.build_request = yield BuildRequest.fromBrdict(self.master, brdict)
def buildFinished(self, build, sb, bids): """ This is called when the Build has finished (either success or failure). Any exceptions during the build are reported with results=FAILURE, not with an errback. By the time we get here, the Build has already released the slave, which will trigger a check for any now-possible build requests (maybeStartBuilds) """ start = time.time() buildFinishedLog = { 'name': 'buildFinished', 'description': 'Called when a Build has finished', 'number': build.build_status.number, } # List all known build requests tied to this `build` breqs = {br.id: br for br in build.requests} # Prevent new merged builds from coming in while we are finishing lock_keys = [int(brid) for brid in sorted(breqs.keys())] build_merging_locks = self.master.buildrequest_merger.getMergingLocks( lock_keys) for lock in build_merging_locks: yield lock.acquire() locks_acquired_start = time.time() buildFinishedLog['elapsed_acquiring_locks'] = time.time() - start try: # Look for additional build requests that might have been merged into # these known build requests getBuildRequestsStart = time.time() otherBrdicts = yield self.master.db.buildrequests.getBuildRequests( mergebrids=list(breqs.keys())) otherBreqs = [] buildFinishedLog['elapsed_getBuildRequests'] = time.time( ) - getBuildRequestsStart for brdict in otherBrdicts: breq = yield BuildRequest.fromBrdict(self.master, brdict) otherBreqs.append(breq) # Include the missing ones for br in otherBreqs: breqs.setdefault(br.id, br) buildFinishedLog['brids'] = sorted(breqs.keys()) d = yield self.finishBuildRequests( brids=list(breqs.keys()), requests=list(breqs.values()), build=build, bids=bids, ) finally: for lock in build_merging_locks: yield lock.release() buildFinishedLog['elapsed_using_locks'] = time.time( ) - locks_acquired_start log.msg(json.dumps(buildFinishedLog)) self.building.remove(build) if sb.slave: sb.slave.releaseLocks() self.updateBigStatus() defer.returnValue(d)