| 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 <bot-page-data> | 9 <bot-page-data> |
| 10 | 10 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 busy: Boolean, if we are fetching any data from the server. | 22 busy: Boolean, if we are fetching any data from the server. |
| 23 events: Array<Object>, The most recent events that pertain to this bot. | 23 events: Array<Object>, The most recent events that pertain to this bot. |
| 24 Contains the following fields: "event_type", "message", "ts" (timestamp)
, | 24 Contains the following fields: "event_type", "message", "ts" (timestamp)
, |
| 25 "quarantined", "version". | 25 "quarantined", "version". |
| 26 tasks: Array<Object>, The most recent tasks done by this bot. | 26 tasks: Array<Object>, The most recent tasks done by this bot. |
| 27 Contains the following fields: "abandoned_ts", "bot_version", "duration"
, | 27 Contains the following fields: "abandoned_ts", "bot_version", "duration"
, |
| 28 "failure", "internal_failure", "modified_ts", "name", "started_ts", | 28 "failure", "internal_failure", "modified_ts", "name", "started_ts", |
| 29 "state", "task_id", "try_number". | 29 "state", "task_id", "try_number". |
| 30 | 30 |
| 31 Methods: | 31 Methods: |
| 32 parseEvents(json): Given the json returned by the server on a request to |
| 33 api/swarming/v1/bot/[botid]/events, return an array of event Objects. |
| 34 |
| 35 parseTasks(json): Given the json returned by the server on a request to |
| 36 api/swarming/v1/bot/[botid]/events, return an array of task Objects. |
| 37 |
| 32 request(): Force a fetch of the data. This happens automatically when | 38 request(): Force a fetch of the data. This happens automatically when |
| 33 auth_headers is set or bot_id is changed. | 39 auth_headers is set or bot_id is changed. |
| 34 | 40 |
| 35 Events: | 41 Events: |
| 36 None. | 42 reload: When this element is making a request for data. Other data sources |
| 43 should also reload themselves. |
| 37 --> | 44 --> |
| 38 | 45 |
| 39 | 46 |
| 40 <link rel="import" href="bot-page-shared-behavior.html"> | 47 <link rel="import" href="bot-page-shared-behavior.html"> |
| 41 | 48 |
| 42 <dom-module id="bot-page-data"> | 49 <dom-module id="bot-page-data"> |
| 43 <script> | 50 <script> |
| 44 (function(){ | 51 (function(){ |
| 45 // Time to wait before requesting a new bot. This is to allow a user to | 52 // Time to wait before requesting a new bot. This is to allow a user to |
| 46 // type in a name and not have it make one set of requests for each | 53 // type in a name and not have it make one set of requests for each |
| (...skipping 28 matching lines...) Expand all Loading... |
| 75 auth_headers: { | 82 auth_headers: { |
| 76 type: Object, | 83 type: Object, |
| 77 }, | 84 }, |
| 78 bot_id: { | 85 bot_id: { |
| 79 type: String, | 86 type: String, |
| 80 }, | 87 }, |
| 81 | 88 |
| 82 // outputs | 89 // outputs |
| 83 busy: { | 90 busy: { |
| 84 type: Boolean, | 91 type: Boolean, |
| 85 computed: "_or(_busy1,_busy2,_busy3)", | 92 computed: "_or(_busy1)", |
| 86 notify: true, | 93 notify: true, |
| 87 }, | 94 }, |
| 88 bot: { | 95 bot: { |
| 89 type: Object, | 96 type: Object, |
| 90 computed: "_parseBot(_bot)", | 97 computed: "_parseBot(_bot)", |
| 91 notify: true, | 98 notify: true, |
| 92 }, | 99 }, |
| 93 events: { | |
| 94 type: Array, | |
| 95 computed: "_parseEvents(_events)", | |
| 96 notify: true, | |
| 97 }, | |
| 98 tasks: { | |
| 99 type: Array, | |
| 100 computed: "_parseTasks(_tasks)", | |
| 101 notify: true, | |
| 102 }, | |
| 103 | 100 |
| 104 // private | 101 // private |
| 105 _busy1: { | 102 _busy1: { |
| 106 type: Boolean, | 103 type: Boolean, |
| 107 value: false | 104 value: false |
| 108 }, | 105 }, |
| 109 _busy2: { | |
| 110 type: Boolean, | |
| 111 value: false | |
| 112 }, | |
| 113 _busy3: { | |
| 114 type: Boolean, | |
| 115 value: false | |
| 116 }, | |
| 117 _bot: { | 106 _bot: { |
| 118 type: Object, | 107 type: Object, |
| 119 }, | 108 }, |
| 120 _events: { | 109 _events: { |
| 121 type: Object, | 110 type: Object, |
| 122 }, | 111 }, |
| 123 _tasks: { | 112 _tasks: { |
| 124 type: Object, | 113 type: Object, |
| 125 }, | 114 }, |
| 126 }, | 115 }, |
| 127 | 116 |
| 128 observers: [ | 117 observers: [ |
| 129 "request(auth_headers,bot_id)", | 118 "request(auth_headers,bot_id)", |
| 130 ], | 119 ], |
| 131 | 120 |
| 132 request: function(){ | 121 request: function(){ |
| 133 if (!this.bot_id || !this.auth_headers) { | 122 if (!this.bot_id || !this.auth_headers) { |
| 134 return; | 123 return; |
| 135 } | 124 } |
| 136 if (lastRequest) { | 125 if (lastRequest) { |
| 137 this.cancelAsync(lastRequest); | 126 this.cancelAsync(lastRequest); |
| 138 } | 127 } |
| 139 | 128 |
| 140 lastRequest = this.async(function(){ | 129 lastRequest = this.async(function(){ |
| 141 lastRequest = undefined; | 130 lastRequest = undefined; |
| 142 var baseUrl = "/_ah/api/swarming/v1/bot/"+this.bot_id; | 131 var baseUrl = "/_ah/api/swarming/v1/bot/"+this.bot_id; |
| 143 this._getJsonAsync("_bot", baseUrl + "/get", | 132 this._getJsonAsync("_bot", baseUrl + "/get", |
| 144 "_busy1", this.auth_headers); | 133 "_busy1", this.auth_headers); |
| 145 // We limit the fields on these two queries to make them faster. | 134 this.fire("reload", {id: this.bot_id}); |
| 146 this._getJsonAsync("_events", | |
| 147 baseUrl + "/events?fields=items(event_type%2Cmessage%2Cquarantined%2
Ctask_id%2Cts%2Cversion)", | |
| 148 "_busy2", this.auth_headers); | |
| 149 this._getJsonAsync("_tasks", | |
| 150 baseUrl + "/tasks?fields=items(abandoned_ts%2Cbot_version%2Ccomplete
d_ts%2Cduration%2Cexit_code%2Cfailure%2Cinternal_failure%2Cmodified_ts%2Cname%2C
started_ts%2Cstate%2Ctask_id%2Ctry_number)", | |
| 151 "_busy3", this.auth_headers); | |
| 152 }, BOT_ID_DEBOUNCE_MS); | 135 }, BOT_ID_DEBOUNCE_MS); |
| 153 | 136 |
| 154 }, | 137 }, |
| 155 | 138 |
| 156 _parseBot: function(bot) { | 139 _parseBot: function(bot) { |
| 157 if (!bot) { | 140 if (!bot) { |
| 158 return {}; | 141 return {}; |
| 159 } | 142 } |
| 160 // Do any preprocessing here | 143 // Do any preprocessing here |
| 161 bot.state = bot.state || "{}"; | 144 bot.state = bot.state || "{}"; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 188 | 171 |
| 189 BOT_TIMES.forEach(function(time) { | 172 BOT_TIMES.forEach(function(time) { |
| 190 if (bot[time]) { | 173 if (bot[time]) { |
| 191 bot[time] = new Date(bot[time]); | 174 bot[time] = new Date(bot[time]); |
| 192 bot["human_"+time] = formatDate(bot[time]); | 175 bot["human_"+time] = formatDate(bot[time]); |
| 193 } | 176 } |
| 194 }); | 177 }); |
| 195 return bot; | 178 return bot; |
| 196 }, | 179 }, |
| 197 | 180 |
| 198 _parseEvents: function(events) { | 181 parseEvents: function(events) { |
| 199 if (!events || !events.items) { | 182 if (!events || !events.items) { |
| 200 return []; | 183 return []; |
| 201 } | 184 } |
| 202 var events = events.items; | 185 var events = events.items; |
| 203 events.forEach(function(event){ | 186 events.forEach(function(event){ |
| 204 // Do any preprocessing here | 187 // Do any preprocessing here |
| 205 if (event.ts) { | 188 if (event.ts) { |
| 206 event.ts = new Date(event.ts); | 189 event.ts = new Date(event.ts); |
| 207 event.human_ts = formatDate(event.ts); | 190 event.human_ts = formatDate(event.ts); |
| 208 } | 191 } |
| 209 }); | 192 }); |
| 210 | 193 |
| 211 // Sort the most recent events first. | 194 // Sort the most recent events first. |
| 212 events.sort(function(a,b) { | 195 events.sort(function(a,b) { |
| 213 return b.ts - a.ts; | 196 return b.ts - a.ts; |
| 214 }); | 197 }); |
| 215 | 198 |
| 216 return events; | 199 return events; |
| 217 }, | 200 }, |
| 218 | 201 |
| 219 _parseTasks: function(tasks) { | 202 parseTasks: function(tasks) { |
| 220 if (!tasks || !tasks.items) { | 203 if (!tasks || !tasks.items) { |
| 221 return []; | 204 return []; |
| 222 } | 205 } |
| 223 var tasks = tasks.items; | 206 var tasks = tasks.items; |
| 224 | 207 |
| 225 tasks.forEach(function(task){ | 208 tasks.forEach(function(task){ |
| 226 // Do any preprocessing here | 209 // Do any preprocessing here |
| 227 TASK_TIMES.forEach(function(time) { | 210 TASK_TIMES.forEach(function(time) { |
| 228 if (task[time]) { | 211 if (task[time]) { |
| 229 task[time] = new Date(task[time]); | 212 task[time] = new Date(task[time]); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 254 return b.started_ts - a.started_ts; | 237 return b.started_ts - a.started_ts; |
| 255 }); | 238 }); |
| 256 | 239 |
| 257 return tasks; | 240 return tasks; |
| 258 } | 241 } |
| 259 | 242 |
| 260 }); | 243 }); |
| 261 })(); | 244 })(); |
| 262 </script> | 245 </script> |
| 263 </dom-module> | 246 </dom-module> |
| OLD | NEW |