[LNT] Add json support to machine overview page

Michael Zolotukhin mzolotukhin at apple.com
Mon Dec 15 13:06:31 PST 2014


Hi Chris,

How about this one?

Michael

Index: lnt/server/ui/views.py
===================================================================
--- lnt/server/ui/views.py	(revision 223085)
+++ lnt/server/ui/views.py	(working copy)
@@ -172,6 +172,26 @@
             order_by(ts.Run.start_time.desc()))
     associated_runs = associated_runs.items()
     associated_runs.sort()
+    if bool(request.args.get('json')):
+        json_obj = dict()
+        machine_obj = ts.query(ts.Machine).filter(ts.Machine.id == id).one()
+        json_obj['name'] = machine_obj.name
+        json_obj['id'] = machine_obj.id
+        runs = {}
+        tests = {}
+        for sample in ts.query(ts.Sample).filter(ts.Run.machine_id == id).all():
+            tests[sample.test.id] = sample.test.name
+            runs[sample.run.id] = (sample.run.order.llvm_project_revision,
+                                   sample.run.start_time,
+                                   sample.run.end_time)
+        json_obj['tests'] = []
+        for test_id in tests:
+            json_obj['tests'].append((test_id, tests[test_id]))
+        json_obj['runs'] = []
+        for run_id in runs:
+            (rev, start, end) = runs[run_id]
+            json_obj['runs'].append((run_id, rev, start, end))
+        return flask.jsonify(**json_obj)

     return render_template("v4_machine.html",
                            testsuite_name=g.testsuite_name, id=id,
Index: tests/server/ui/V4Pages.py
===================================================================
--- tests/server/ui/V4Pages.py	(revision 223085)
+++ tests/server/ui/V4Pages.py	(working copy)
@@ -38,6 +38,9 @@
     # Get a machine overview page.
     check_code(client, '/v4/nts/machine/1')

+    # Get a machine overview page in JSON format.
+    check_code(client, '/v4/nts/machine/1?json=true')
+
     # Get the order summary page.
     check_code(client, '/v4/nts/all_orders')

> On Dec 9, 2014, at 2:38 PM, Chris Matthews <chris.matthews at apple.com> wrote:
> 
> I think the query to add runs and tests needs to be joined to get only runs and tests referenced from this machine.  Also append the test and run IDs to the json object.
> 
>> On Dec 8, 2014, at 3:25 PM, Michael Zolotukhin <mzolotukhin at apple.com <mailto:mzolotukhin at apple.com>> wrote:
>> 
>> Hi,
>> 
>> This patch adds JSON-format for machine-overview page. Does it look good?
>> 
>> Thanks,
>> Michael
>> 
>> Index: lnt/server/ui/views.py
>> ===================================================================
>> --- lnt/server/ui/views.py	(revision 223085)
>> +++ lnt/server/ui/views.py	(working copy)
>> @@ -172,6 +172,20 @@
>>              order_by(ts.Run.start_time.desc()))
>>      associated_runs = associated_runs.items()
>>      associated_runs.sort()
>> +    if bool(request.args.get('json')):
>> +        json_obj = dict()
>> +        machine_obj = ts.query(ts.Machine).filter(ts.Machine.id == id).one()
>> +        json_obj['name'] = machine_obj.name
>> +        json_obj['id'] = machine_obj.id
>> +        json_obj['runs'] = []
>> +        for t in ts.query(ts.Run):
>> +            json_obj['runs'].append((t.order.llvm_project_revision,
>> +                                     t.start_time,
>> +                                     t.end_time))
>> +        json_obj['tests'] = []
>> +        for test in ts.query(ts.Test).all():
>> +            json_obj['tests'].append((test.name, test.id))
>> +        return flask.jsonify(**json_obj)
>> 
>>      return render_template("v4_machine.html",
>>                             testsuite_name=g.testsuite_name, id=id,
>> Index: tests/server/ui/V4Pages.py
>> ===================================================================
>> --- tests/server/ui/V4Pages.py	(revision 223085)
>> +++ tests/server/ui/V4Pages.py	(working copy)
>> @@ -38,6 +38,9 @@
>>      # Get a machine overview page.
>>      check_code(client, '/v4/nts/machine/1')
>> 
>> +    # Get a machine overview page in JSON format.
>> +    check_code(client, '/v4/nts/machine/1?json=true')
>> +
>>      # Get the order summary page.
>>      check_code(client, '/v4/nts/all_orders')
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20141215/9454d17d/attachment.html>


More information about the llvm-commits mailing list