Chromium Code Reviews| 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 | 56 |
| 42 behaviors: [ | 57 behaviors: [ |
| 43 SwarmingBehaviors.CommonBehavior, | 58 SwarmingBehaviors.CommonBehavior, |
| 44 ], | 59 ], |
| 45 | 60 |
| 46 properties: { | 61 properties: { |
| 47 // inputs | 62 // inputs |
| 48 auth_headers: { | 63 auth_headers: { |
| 49 type: Object, | 64 type: Object, |
| 50 }, | 65 }, |
| 51 task_id: { | 66 task_id: { |
| 52 type: String, | 67 type: String, |
| 53 }, | 68 }, |
| 54 | 69 |
| 55 // outputs | 70 // outputs |
| 56 busy: { | 71 busy: { |
| 57 type: Boolean, | 72 type: Boolean, |
| 58 computed: "_or(_busy1,_busy2,_busy3)", | 73 computed: "_or(_busy1,_busy2,_busy3)", |
| 59 notify: true, | 74 notify: true, |
| 60 }, | 75 }, |
| 61 request: { | 76 request: { |
| 62 type: Object, | 77 type: Object, |
| 63 computed: "_parseRequest(_request)", | 78 computed: "_parseRequest(_request)", |
| 64 notify: true, | 79 notify: true, |
| 65 }, | 80 }, |
| 66 result: { | 81 result: { |
| 67 type: Array, | 82 type: Object, |
| 68 computed: "_parseResult(_result)", | 83 computed: "_parseResult(_result)", |
| 69 notify: true, | 84 notify: true, |
| 70 }, | 85 }, |
| 71 stdout: { | 86 stdout: { |
| 72 type: String, | 87 type: String, |
| 73 computed: "_parseStdout(_stdout)", | 88 computed: "_parseStdout(_stdout)", |
| 74 notify: true, | 89 notify: true, |
| 75 }, | 90 }, |
| 76 | 91 |
| 77 // private | 92 // private |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 118 "_busy1", this.auth_headers); | 133 "_busy1", this.auth_headers); |
| 119 this._getJsonAsync("_result", | 134 this._getJsonAsync("_result", |
| 120 baseUrl + "/result?include_performance_stats=true", | 135 baseUrl + "/result?include_performance_stats=true", |
| 121 "_busy2", this.auth_headers); | 136 "_busy2", this.auth_headers); |
| 122 this._getJsonAsync("_stdout", baseUrl + "/stdout", | 137 this._getJsonAsync("_stdout", baseUrl + "/stdout", |
| 123 "_busy3", this.auth_headers); | 138 "_busy3", this.auth_headers); |
| 124 }, TASK_ID_DEBOUNCE_MS); | 139 }, TASK_ID_DEBOUNCE_MS); |
| 125 }, | 140 }, |
| 126 | 141 |
| 127 _parseRequest: function(request) { | 142 _parseRequest: function(request) { |
| 128 console.log(request); | |
| 129 if (!request) { | 143 if (!request) { |
| 130 return {}; | 144 return {}; |
| 131 } | 145 } |
| 146 request.tagMap = {}; | |
| 147 request.tags = request.tags || []; | |
| 148 request.tags.forEach(function(tag) { | |
| 149 var split = tag.split(":", 1) | |
| 150 var key = split[0]; | |
| 151 var rest = tag.substring(key.length + 1); | |
| 152 request.tagMap[key] = rest; | |
| 153 }); | |
| 154 | |
| 155 TIMES.forEach(function(time) { | |
| 156 if (request[time]) { | |
| 157 request[time] = new Date(request[time]); | |
| 158 request["human_"+time] = sk.human.localeTime(request[time]); | |
| 159 } | |
| 160 }); | |
| 161 // request.properties.dimensions | |
| 162 request.properties = request.properties || {}; | |
| 163 if (request.properties.dimensions) { | |
| 164 request.properties.dimensions.forEach(function(dim){ | |
| 165 if (swarming.alias.has(dim.key)) { | |
| 166 dim.value = swarming.alias.apply(dim.value, dim.key); | |
| 167 } | |
| 168 }) | |
| 169 } | |
| 132 return request; | 170 return request; |
| 133 }, | 171 }, |
| 134 | 172 |
| 135 _parseResult: function(result) { | 173 _parseResult: function(result) { |
| 136 console.log(result); | |
| 137 if (!result) { | 174 if (!result) { |
| 138 return {}; | 175 return {}; |
| 139 } | 176 } |
| 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; | |
|
jcgregorio
2016/09/20 13:02:16
Where did 'now' come from?
kjlubick
2016/09/20 13:48:12
Forgot to define it. Apparently I did not have an
| |
| 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 } | |
| 140 return result; | 202 return result; |
| 141 }, | 203 }, |
| 142 | 204 |
| 143 _parseStdout: function(stdout) { | 205 _parseStdout: function(stdout) { |
| 144 console.log(stdout); | |
| 145 if (!stdout || !stdout.output) { | 206 if (!stdout || !stdout.output) { |
| 146 return ""; | 207 return ""; |
| 147 } | 208 } |
| 148 return stdout.output; | 209 return stdout.output; |
| 149 } | 210 } |
| 150 | 211 |
| 151 }); | 212 }); |
| 152 })(); | 213 })(); |
| 153 </script> | 214 </script> |
| 154 </dom-module> | 215 </dom-module> |
| OLD | NEW |