diff --git a/treeherder/model/derived/jobs.py b/treeherder/model/derived/jobs.py index dc19479c4..98f1bf055 100644 --- a/treeherder/model/derived/jobs.py +++ b/treeherder/model/derived/jobs.py @@ -131,35 +131,45 @@ class JobsModel(TreeherderModelBase): return id_iter.get_column_data('id') - def get_result_set_list(self, page, limit): + def get_result_set_list(self, page, limit, **kwargs): """ Retrieve a list of ``result_sets`` (also known as ``pushes``) with associated revisions. No jobs Mainly used by the restful api to list the pushes in the UI """ + repl = [""] + if "pusher" in kwargs: + repl = [" WHERE `rev`.`author` = '{0}'".format(kwargs["pusher"])] + proc = "jobs.selects.get_result_set_list" push_dict = self.get_jobs_dhub().execute( proc=proc, placeholders=[page, limit], debug_show=self.DEBUG, return_type='iter', + replace=repl, ) return push_dict - def get_result_set_job_list(self, result_set_id): + def get_result_set_job_list(self, result_set_id, **kwargs): """ Retrieve a list of ``jobs`` and results for a result_set. Mainly used by the restful api to list the job results in the UI """ + repl = [""] + if "job_name" in kwargs: + repl = [" AND jt.`name` = '{0}'".format(kwargs["job_name"])] + proc = "jobs.selects.get_result_set_job_list" push_dict = self.get_jobs_dhub().execute( proc=proc, placeholders=[result_set_id], debug_show=self.DEBUG, return_type='iter', + replace=repl, ) return push_dict diff --git a/treeherder/model/sql/jobs.json b/treeherder/model/sql/jobs.json index 6a288ab3e..0f880ebb0 100644 --- a/treeherder/model/sql/jobs.json +++ b/treeherder/model/sql/jobs.json @@ -177,7 +177,9 @@ ON rs.id = rm.result_set_id LEFT JOIN revision as rev ON rm.revision_id = rev.id - LIMIT ?,?", + REP0 + LIMIT ?,? + ", "host": "read_host" }, "get_result_set_by_id":{ @@ -202,10 +204,13 @@ j.`job_guid`, j.`build_platform_id`, mp.`platform`, - m.`name`, - jt.`name`, - jt.`symbol`, - jt.`description`, + m.`name` as machine_name, + jt.`name` as jt_name, + jt.`symbol` as jt_symbol, + jt.`description` as jt_description, + jg.`name` as jg_name, + jg.`symbol` as jg_symbol, + jg.`description` as jg_description, j.`who`, j.`result_set_id`, j.`result`, @@ -219,7 +224,11 @@ ON j.`build_platform_id` = bp.id LEFT JOIN `treeherder`.`job_type` as jt ON j.`job_type_id` = jt.id - WHERE `result_set_id` = ?", + LEFT JOIN `treeherder`.`job_group` as jg + ON jt.`job_group_id` = jg.id + WHERE `result_set_id` = ? + REP0 + ", "host": "read_host" } } diff --git a/treeherder/webapp/api/views.py b/treeherder/webapp/api/views.py index b2cfd2fbd..7e30f28d5 100644 --- a/treeherder/webapp/api/views.py +++ b/treeherder/webapp/api/views.py @@ -146,9 +146,14 @@ class ResultSetViewSet(viewsets.ViewSet): """ try: page = request.QUERY_PARAMS.get('page', 0) + pusher = request.QUERY_PARAMS.get('pusher', None) + kwargs = {} + if pusher: + kwargs["pusher"] = pusher + jm = JobsModel(project) - objs = jm.get_result_set_list(page, 1000) + objs = jm.get_result_set_list(page, 1000, **kwargs) return Response(objs) except DatasetNotFoundError as e: return Response({"message": unicode(e)}, status=404) @@ -163,14 +168,20 @@ class ResultSetViewSet(viewsets.ViewSet): A color-based warning level based on the most severe level in the list of jobs. + + @@@ - This needs a better way. """ job_states = set([x["result"] for x in jobs]) if "busted" in job_states: return "red" + if "fail" in job_states: + return "red" elif "orange" in job_states: return "orange" elif "pending" in job_states: return "grey" + elif "retry" in job_states: + return "grey" elif "running" in job_states: return "grey" else: @@ -180,21 +191,34 @@ class ResultSetViewSet(viewsets.ViewSet): """ GET method implementation for detail view of ``resultset`` """ + job_name = request.QUERY_PARAMS.get('job_name', None) + kwargs = {} + if job_name: + kwargs["job_name"] = job_name + try: jm = JobsModel(project) rs = list(jm.get_result_set_by_id(pk))[0] - jobs_ungrouped = list(jm.get_result_set_job_list(pk)) + jobs_ungrouped = list(jm.get_result_set_job_list(pk, **kwargs)) # group these by their platforms for return jobs_sorted = sorted(jobs_ungrouped, key=lambda x: x["platform"]) import itertools - rs["jobs"] = [] + rs["platforms"] = [] + # job_groups by platform for k, g in itertools.groupby(jobs_sorted, key=lambda x: x["platform"]): - jobs = list(g) - rs["jobs"].append({ + job_groups = sorted(list(g), key=lambda x: x["jg_symbol"]) + platform = { "platform": k, - "warning_level": self.get_warning_level(jobs), - "jobs": jobs - }) + } + rs["platforms"].append(platform) + platform["groups"] = [] + for jg_k, jg_g in itertools.groupby(job_groups, key=lambda x: x["jg_symbol"]): + jobs = list(jg_g) + platform["groups"].append({ + "symbol": jg_k, + "warning_level": self.get_warning_level(jobs), + "jobs": jobs + }) return Response(rs) except DatasetNotFoundError as e: return Response(