| OLD | NEW | 
|---|
| 1 <!-- | 1 <!-- | 
| 2   Copyright 2016 The LUCI Authors. All rights reserved. | 2   Copyright 2016 The LUCI Authors. All rights reserved. | 
| 3   Use of this source code is governed under the Apache License, Version 2.0 | 3   Use of this source code is governed under the Apache License, Version 2.0 | 
| 4   that can be found in the LICENSE file. | 4   that can be found in the LICENSE file. | 
| 5 | 5 | 
| 6   This in an HTML Import-able file that contains the definition | 6   This in an HTML Import-able file that contains the definition | 
| 7   of the following elements: | 7   of the following elements: | 
| 8 | 8 | 
| 9     <task-page-data> | 9     <task-page-data> | 
| 10 | 10 | 
| 11   This makes calls authenticated with Oauth 2 to the swarming apis.  It parses | 11   This makes calls authenticated with Oauth 2 to the swarming apis.  It parses | 
| 12   that data into usable data structures. | 12   that data into usable data structures. | 
| 13 | 13 | 
| 14   Properties: | 14   Properties: | 
|  | 15     // input | 
|  | 16     auth_headers: Object, the OAuth2 header to include in the request.  This | 
|  | 17         should come from swarming-app. | 
|  | 18     task_id: String, the id of the task to fetch data on. | 
|  | 19     // output | 
| 15     busy: Boolean, if we are fetching any data from the server. | 20     busy: Boolean, if we are fetching any data from the server. | 
| 16     TODO(kjlubick) | 21     request: Object, the task request. This contains information such as the | 
|  | 22        name, id, created_ts, tags, and dimensions.  See the sample data in | 
|  | 23        task-request-demo.json for a full rundown. | 
|  | 24     result: Object, the result or progress of the task. This contains informatio
     n such as the | 
|  | 25        modified_ts, duration, exit_code, information about the bot that picked | 
|  | 26        up the task, etc.  See the sample data in task-result-demo.json for a | 
|  | 27        full rundown. | 
|  | 28     stdout: String, the raw output of the task, if any.  See | 
|  | 29         task-stdout-demo.json for a full rundown. | 
| 17 | 30 | 
| 18   Methods: | 31   Methods: | 
| 19     request(): Force a fetch of the data. This happens automatically when | 32     request(): Force a fetch of the data. This happens automatically when | 
| 20         auth_headers is set or task_id is changed. | 33         auth_headers is set or task_id is changed. | 
| 21 | 34 | 
| 22   Events: | 35   Events: | 
| 23     None. | 36     None. | 
| 24 --> | 37 --> | 
| 25 | 38 | 
| 26 | 39 | 
| 27 <link rel="import" href="/res/imp/common/common-behavior.html"> | 40 <link rel="import" href="/res/imp/common/common-behavior.html"> | 
| 28 | 41 | 
| 29 <dom-module id="task-page-data"> | 42 <dom-module id="task-page-data"> | 
| 30   <script> | 43   <script> | 
| 31   (function(){ | 44   (function(){ | 
| 32     // Time to wait before requesting a new task. This is to allow a user to | 45     // Time to wait before requesting a new task. This is to allow a user to | 
| 33     // type in a name and not have it make one set of requests for each | 46     // type in a name and not have it make one set of requests for each | 
| 34     // keystroke. | 47     // keystroke. | 
| 35     var TASK_ID_DEBOUNCE_MS = 400; | 48     var TASK_ID_DEBOUNCE_MS = 400; | 
| 36     var lastRequest; | 49     var lastRequest; | 
| 37 | 50 | 
|  | 51     var TIMES = ["abandoned_ts", "completed_ts", "created_ts", "modified_ts", "s
     tarted_ts"]; | 
|  | 52 | 
| 38     Polymer({ | 53     Polymer({ | 
| 39       is: 'task-page-data', | 54       is: 'task-page-data', | 
| 40 | 55 | 
| 41       behaviors: [ | 56       behaviors: [ | 
| 42           SwarmingBehaviors.CommonBehavior, | 57           SwarmingBehaviors.CommonBehavior, | 
| 43       ], | 58       ], | 
| 44 | 59 | 
| 45       properties: { | 60       properties: { | 
| 46         // inputs | 61         // inputs | 
| 47         auth_headers: { | 62         auth_headers: { | 
| 48           type: Object, | 63           type: Object, | 
| 49         }, | 64         }, | 
| 50         task_id: { | 65         task_id: { | 
| 51           type: String, | 66           type: String, | 
| 52         }, | 67         }, | 
| 53 | 68 | 
| 54         // outputs | 69         // outputs | 
| 55         busy: { | 70         busy: { | 
| 56           type: Boolean, | 71           type: Boolean, | 
| 57           computed: "_or(_busy1,_busy2,_busy3)", | 72           computed: "_or(_busy1,_busy2,_busy3)", | 
| 58           notify: true, | 73           notify: true, | 
| 59         }, | 74         }, | 
| 60         request: { | 75         request: { | 
| 61           type: Object, | 76           type: Object, | 
| 62           computed: "_parseRequest(_request)", | 77           computed: "_parseRequest(_request)", | 
| 63           notify: true, | 78           notify: true, | 
| 64         }, | 79         }, | 
| 65         result: { | 80         result: { | 
| 66           type: Array, | 81           type: Object, | 
| 67           computed: "_parseResult(_result)", | 82           computed: "_parseResult(_result)", | 
| 68           notify: true, | 83           notify: true, | 
| 69         }, | 84         }, | 
| 70         stdout: { | 85         stdout: { | 
| 71           type: String, | 86           type: String, | 
| 72           computed: "_parseStdout(_stdout)", | 87           computed: "_parseStdout(_stdout)", | 
| 73           notify: true, | 88           notify: true, | 
| 74         }, | 89         }, | 
| 75 | 90 | 
| 76         // private | 91         // private | 
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 117             "_busy1", this.auth_headers); | 132             "_busy1", this.auth_headers); | 
| 118           this._getJsonAsync("_result", | 133           this._getJsonAsync("_result", | 
| 119             baseUrl + "/result?include_performance_stats=true", | 134             baseUrl + "/result?include_performance_stats=true", | 
| 120             "_busy2", this.auth_headers); | 135             "_busy2", this.auth_headers); | 
| 121           this._getJsonAsync("_stdout", baseUrl + "/stdout", | 136           this._getJsonAsync("_stdout", baseUrl + "/stdout", | 
| 122             "_busy3", this.auth_headers); | 137             "_busy3", this.auth_headers); | 
| 123         }, TASK_ID_DEBOUNCE_MS); | 138         }, TASK_ID_DEBOUNCE_MS); | 
| 124       }, | 139       }, | 
| 125 | 140 | 
| 126       _parseRequest: function(request) { | 141       _parseRequest: function(request) { | 
| 127         console.log(request); |  | 
| 128         if (!request) { | 142         if (!request) { | 
| 129           return {}; | 143           return {}; | 
| 130         } | 144         } | 
|  | 145         request.tagMap = {}; | 
|  | 146         request.tags = request.tags || []; | 
|  | 147         request.tags.forEach(function(tag) { | 
|  | 148           var split = tag.split(":", 1) | 
|  | 149           var key = split[0]; | 
|  | 150           var rest = tag.substring(key.length + 1); | 
|  | 151           request.tagMap[key] = rest; | 
|  | 152         }); | 
|  | 153 | 
|  | 154         TIMES.forEach(function(time) { | 
|  | 155           if (request[time]) { | 
|  | 156             request[time] = new Date(request[time]); | 
|  | 157             request["human_"+time] = sk.human.localeTime(request[time]); | 
|  | 158           } | 
|  | 159         }); | 
|  | 160         // request.properties.dimensions | 
|  | 161         request.properties = request.properties || {}; | 
|  | 162         if (request.properties.dimensions) { | 
|  | 163           request.properties.dimensions.forEach(function(dim){ | 
|  | 164             if (swarming.alias.has(dim.key)) { | 
|  | 165               dim.value = swarming.alias.apply(dim.value, dim.key); | 
|  | 166             } | 
|  | 167           }) | 
|  | 168         } | 
| 131         return request; | 169         return request; | 
| 132       }, | 170       }, | 
| 133 | 171 | 
| 134       _parseResult: function(result) { | 172       _parseResult: function(result) { | 
| 135         console.log(result); |  | 
| 136         if (!result) { | 173         if (!result) { | 
| 137           return {}; | 174           return {}; | 
| 138         } | 175         } | 
|  | 176         var now = new Date(); | 
|  | 177         TIMES.forEach(function(time) { | 
|  | 178           if (result[time]) { | 
|  | 179             result[time] = new Date(result[time]); | 
|  | 180             result["human_"+time] = sk.human.localeTime(result[time]); | 
|  | 181           } | 
|  | 182         }); | 
|  | 183         // Running tasks have no duration set, so we can figure it out. | 
|  | 184         if (!result.duration && result.state === "RUNNING" && result.started_ts)
     { | 
|  | 185           result.duration = (now - result.started_ts) / 1000; | 
|  | 186         } | 
|  | 187         // Make the duration human readable | 
|  | 188         if (result.duration){ | 
|  | 189           result.human_duration = this._humanDuration(result.duration); | 
|  | 190         } | 
|  | 191         // result.bot_dimensions | 
|  | 192         if (result.bot_dimensions) { | 
|  | 193           result.bot_dimensions.forEach(function(dim){ | 
|  | 194             if (swarming.alias.has(dim.key)) { | 
|  | 195               // dim.value is an array | 
|  | 196               dim.value.forEach(function(v, i){ | 
|  | 197                 dim.value[i] = swarming.alias.apply(v, dim.key); | 
|  | 198               }); | 
|  | 199             } | 
|  | 200           }) | 
|  | 201         } | 
| 139         return result; | 202         return result; | 
| 140       }, | 203       }, | 
| 141 | 204 | 
| 142       _parseStdout: function(stdout) { | 205       _parseStdout: function(stdout) { | 
| 143         console.log(stdout); |  | 
| 144         if (!stdout || !stdout.output) { | 206         if (!stdout || !stdout.output) { | 
| 145           return ""; | 207           return ""; | 
| 146         } | 208         } | 
| 147         return stdout.output; | 209         return stdout.output; | 
| 148       } | 210       } | 
| 149 | 211 | 
| 150     }); | 212     }); | 
| 151   })(); | 213   })(); | 
| 152   </script> | 214   </script> | 
| 153 </dom-module> | 215 </dom-module> | 
| OLD | NEW | 
|---|