def push(self, event, **objs): """Push a new event. The new event will be either: - Queued in memory to reduce network usage - Queued to disk when the sink server is down - Pushed (along the other queued items) to the server """ if self.blackList and event in self.blackList: return # First, generate the packet. packet = {} packet['id'] = self.state['next_id'] self.state['next_id'] += 1 packet['timestamp'] = str(datetime.datetime.utcnow()) packet['project'] = self.status.getTitle() packet['started'] = self.state['started'] packet['event'] = event packet['payload'] = {} for obj_name, obj in objs.items(): if hasattr(obj, 'asDict'): obj = obj.asDict() if self.filter: obj = FilterOut(obj) packet['payload'][obj_name] = obj self.queue.pushItem(packet) if self.task is None or not self.task.active(): # No task queued since it was probably idle, let's queue a task. return self.queueNextServerPush()
def content(self, request, cxt): s = self.getStatus(request) slave_params = { "build_steps": ["0"], "build_props": ["0"], "builders": ["0"] } slaves = s.getSlaves() slaves_array = [SlaveJsonResource(s, ss.slave_status).asDict(request, params=slave_params) for ss in slaves.values()] slaves_dict = FilterOut(slaves_array) cxt['instant_json']["slaves"] = {"url": s.getBuildbotURL() + path_to_json_slaves(), "data": json.dumps(slaves_dict, separators=(',', ':')), "waitForPush": s.master.config.autobahn_push, "pushFilters": { "buildStarted": {}, "buildFinished": {}, "stepStarted": {}, "stepFinished": {}, "slaveConnected": {}, "slaveDisconnected": {}, }} template = request.site.buildbot_service.templates.get_template("buildslaves.html") return template.render(**cxt)
def getSlavesJsonResource(self, filters, url, slaves_dict): if not slaves_dict: return {} slaves_dict = FilterOut(slaves_dict) if "sources" in filters: del filters["sources"] return {"url": url, "data": json.dumps(slaves_dict, separators=(',', ':')), "waitForPush": self.status.master.config.autobahn_push, "pushFilters": {"buildStarted": filters, "buildFinished": filters, "stepStarted": filters, "stepFinished": filters, "slaveConnected": filters, "slaveDisconnected": filters,}}
def content(self, req, cxt): b = self.builder_status master = self.getBuildmaster(req) # Grab all the parameters which are prefixed with 'property.'. # We'll use these to filter the builds and build requests we # show below. props = {} prop_prefix = 'property.' for arg, val in req.args.iteritems(): if arg.startswith(prop_prefix): props[arg[len(prop_prefix):]] = val[0] def prop_match(oprops): for key, val in props.iteritems(): if key not in oprops or val != str(oprops[key]): return False return True project = cxt['selectedproject'] = b.getProject() cxt['name'] = b.getName() cxt['friendly_name'] = b.getFriendlyName() cxt['description'] = b.getDescription() req.setHeader('Cache-Control', 'no-cache') codebases = {} getCodebasesArg(request=req, codebases=codebases) num_builds = int(req.args.get('numbuilds', [self.numbuilds])[0]) cxt['builder_url'] = path_to_builder(req, b, codebases=True) cxt['path_to_codebases'] = path_to_codebases(req, project) cxt['path_to_builders'] = path_to_builders(req, project) cxt['builder_name'] = b.getName() cxt['rt_update'] = req.args filters = { "project": self.builder_status.project, "builderName": b.getName(), "sources": codebases } project_params = { "build_steps": ["0"], "build_props": ["0"] } project_json = SingleProjectBuilderJsonResource(self.status, self.builder_status, latest_rev=True) project_dict = yield project_json.asDict(req, params=project_params) url = self.status.getBuildbotURL() + path_to_json_project_builder(req, project, self.builder_status.name) filtered_tags = filter_tags_by_codebases(project_dict['tags'], codebases, master.config.tag_as_branch_regex, master.config.regex_branches) cxt['instant_json']['project'] = {"url": url, "data": json.dumps(project_dict, separators=(',', ':')), "tags": filtered_tags, "waitForPush": self.status.master.config.autobahn_push, "pushFilters": { "buildStarted": filters, "buildFinished": filters, "stepStarted": filters, "stepFinished": filters, }} pending_json = SinglePendingBuildsJsonResource(self.status, self.builder_status) pending_dict = yield pending_json.asDict(req) pending_url = self.status.getBuildbotURL() + path_to_json_pending(req, self.builder_status.name) cxt['instant_json']['pending_builds'] = {"url": pending_url, "data": json.dumps(pending_dict, separators=(',', ':')), "waitForPush": self.status.master.config.autobahn_push, "pushFilters": { "buildStarted": filters, "requestSubmitted": filters, "requestCancelled": filters, }} builds_params = { "steps": ["0"], } builds_json = PastBuildsJsonResource(self.status, num_builds, builder_status=self.builder_status) builds_dict = yield builds_json.asDict(req, params=builds_params) builds_url = self.status.getBuildbotURL() + path_to_json_past_builds(req, self.builder_status.name, num_builds, filter_data=True) cxt['instant_json']['builds'] = {"url": builds_url, "data": json.dumps(builds_dict, separators=(',', ':')), "waitForPush": self.status.master.config.autobahn_push, "pushFilters": { "buildFinished": filters }} slave_params = { "build_steps": ["0"], "build_props": ["0"], "builders": ["0"] } slaves = b.getSlaves() slaves_array = [SlaveJsonResource(self.status, ss).asDict(req, params=slave_params) for ss in slaves] slaves_dict = FilterOut(slaves_array) url = self.status.getBuildbotURL() + path_to_json_builder_slaves(self.builder_status.getName()) cxt['instant_json']["slaves"] = self.getSlavesJsonResource(filters, url, slaves_dict) startslaves = BuilderStartSlavesJsonResources(self.status, self.builder_status) startslaves_dict = yield startslaves.asDict(req) url = self.status.getBuildbotURL() + \ path_to_json_builder_startslaves(self.builder_status.getName()) + "?filter=1" cxt['instant_json']["start_slaves"] = self.getSlavesJsonResource(filters, url, startslaves_dict) cxt['numbuilds'] = int(req.args.get('numbuilds', [self.numbuilds])[0]) buildForceContext(cxt, req, self.getBuildmaster(req), b.getName()) template = req.site.buildbot_service.templates.get_template("builder.html") defer.returnValue(template.render(**cxt))