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['brid']) if not breq: breq = yield BuildRequest.fromBrdict(self.master, brdict) if breq: self.breqCache[brdict['brid']] = breq defer.returnValue(breq)
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 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 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)
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)