| 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-list-data> | 9 <bot-list-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 Usage: | 14 Usage: |
| 15 | 15 |
| 16 <bot-list-data></bot-list-data> | 16 <bot-list-data></bot-list-data> |
| 17 | 17 |
| 18 Properties: | 18 Properties: |
| 19 // inputs | 19 // inputs |
| 20 auth_headers: Object, the OAuth2 header to include in the request. This | 20 auth_headers: Object, the OAuth2 header to include in the request. This |
| 21 should come from swarming-app. | 21 should come from swarming-app. |
| 22 query_params: Object, The query params that will filter the query | 22 |
| 23 server-side. This can have dimensions:Array<String>, quarantined:String | |
| 24 and is_dead: String. For example: | |
| 25 { | |
| 26 "dimensions": ["pool:Skia", "device_type:Sprout"], | |
| 27 "quarantined": "FALSE", // optional | |
| 28 "is_dead": "TRUE", // optional | |
| 29 } | |
| 30 For a full list of dimensions in the fleet, see the API call: | |
| 31 https://[swarming_url]/_ah/api/swarming/v1/bots/dimensions | |
| 32 // outputs | 23 // outputs |
| 33 bots: Array<Object>, all bots returned by the server. This is an Object | 24 bots: Array<Object>, all bots returned by the server. This is an Object |
| 34 with at least the following structure: | 25 with at least the following structure: |
| 35 dimensions: Array<Object>: Has key:String and value:Array<String> | 26 dimensions: Array<Object>: Has key:String and value:Array<String> |
| 36 task_id: String | 27 task_id: String |
| 37 external_ip: String | 28 external_ip: String |
| 38 is_dead: Object: Is usually Boolean, but could be message string | 29 is_dead: Object: Is usually Boolean, but could be message string |
| 39 quarantined: Object: Is usually Boolean, but could be message string | 30 quarantined: Object: Is usually Boolean, but could be message string |
| 40 bot_id: String | 31 bot_id: String |
| 41 state: String, Stringified JSON that has many pieces of information, like | 32 state: String, Stringified JSON that has many pieces of information, like |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 behaviors: [ | 88 behaviors: [ |
| 98 SwarmingBehaviors.BotListBehavior, | 89 SwarmingBehaviors.BotListBehavior, |
| 99 ], | 90 ], |
| 100 | 91 |
| 101 properties: { | 92 properties: { |
| 102 // inputs | 93 // inputs |
| 103 auth_headers: { | 94 auth_headers: { |
| 104 type: Object, | 95 type: Object, |
| 105 observer: "signIn", | 96 observer: "signIn", |
| 106 }, | 97 }, |
| 107 query_params: { | |
| 108 type: Object, | |
| 109 observer: "_request", | |
| 110 }, | |
| 111 | 98 |
| 112 //outputs | 99 //outputs |
| 113 bots: { | 100 bots: { |
| 114 type: Array, | 101 type: Array, |
| 115 computed: "_bots(_list)", | 102 computed: "parseBots(_list)", |
| 116 notify: true, | 103 notify: true, |
| 117 }, | 104 }, |
| 118 busy: { | 105 busy: { |
| 119 type: Boolean, | 106 type: Boolean, |
| 120 computed: "_or(_busy1,_busy2,_busy3)", | 107 computed: "_or(_busy2,_busy1)", |
| 121 notify: true, | 108 notify: true, |
| 122 }, | 109 }, |
| 123 dimensions: { | 110 dimensions: { |
| 124 type: Array, | 111 type: Array, |
| 125 computed: "_makeArray(_dimensions)", | 112 computed: "_makeArray(_dimensions)", |
| 126 notify: true, | 113 notify: true, |
| 127 }, | 114 }, |
| 128 fleet: { | 115 fleet: { |
| 129 type: Object, | 116 type: Object, |
| 130 computed: "_fleet(_count)", | 117 computed: "_fleet(_count)", |
| 131 notify: true, | 118 notify: true, |
| 132 }, | 119 }, |
| 133 primary_map: { | 120 primary_map: { |
| 134 type: Object, | 121 type: Object, |
| 135 computed: "_primaryMap(_dimensions)", | 122 computed: "_primaryMap(_dimensions)", |
| 136 notify: true, | 123 notify: true, |
| 137 }, | 124 }, |
| 138 primary_arr: { | 125 primary_arr: { |
| 139 type: Array, | 126 type: Array, |
| 140 //BOT_PROPERTIES is inherited from BotListBehavior | 127 //BOT_PROPERTIES is inherited from BotListBehavior |
| 141 computed: "_primaryArr(dimensions, BOT_PROPERTIES)", | 128 computed: "_primaryArr(dimensions, BOT_PROPERTIES)", |
| 142 notify: true, | 129 notify: true, |
| 143 }, | 130 }, |
| 144 | 131 |
| 145 // private | 132 // private |
| 146 _busy1: { | 133 _busy1: { |
| 147 type: Boolean, | 134 type: Boolean, |
| 148 value: false | 135 value: false |
| 149 }, | 136 }, |
| 150 _busy2: { | 137 _busy2: { |
| 151 type: Boolean, | 138 type: Boolean, |
| 152 value: false | 139 value: false |
| 153 }, | 140 }, |
| 154 _busy3: { | |
| 155 type: Boolean, | |
| 156 value: false | |
| 157 }, | |
| 158 _count: { | 141 _count: { |
| 159 type: Object, | 142 type: Object, |
| 160 }, | 143 }, |
| 161 _dimensions: { | 144 _dimensions: { |
| 162 type: Object, | 145 type: Object, |
| 163 }, | 146 }, |
| 164 _list: { | 147 _list: { |
| 165 type: Object, | 148 type: Object, |
| 166 }, | 149 }, |
| 167 }, | 150 }, |
| 168 | 151 |
| 169 signIn: function(){ | 152 signIn: function(){ |
| 170 this._getJsonAsync("_count", "/_ah/api/swarming/v1/bots/count", | 153 this._getJsonAsync("_count", "/_ah/api/swarming/v1/bots/count", |
| 171 "_busy2", this.auth_headers); | 154 "_busy2", this.auth_headers); |
| 172 this._getJsonAsync("_dimensions","/_ah/api/swarming/v1/bots/dimensions", | 155 this._getJsonAsync("_dimensions","/_ah/api/swarming/v1/bots/dimensions", |
| 173 "_busy3", this.auth_headers); | 156 "_busy1", this.auth_headers); |
| 174 | |
| 175 this._request(); | |
| 176 }, | 157 }, |
| 177 | 158 |
| 178 _bots: function(){ | 159 parseBots: function(json){ |
| 179 if (!this._list || !this._list.items) { | 160 if (!json || !json.items) { |
| 180 return []; | 161 return []; |
| 181 } | 162 } |
| 182 // Do any preprocessing here | 163 // Do any preprocessing here |
| 183 this._list.items.forEach(function(bot){ | 164 json.items.forEach(function(bot){ |
| 184 // Parse the state, which is a JSON string. This contains a lot of | 165 // Parse the state, which is a JSON string. This contains a lot of |
| 185 // interesting information like details about the devices attached. | 166 // interesting information like details about the devices attached. |
| 186 bot.state = bot.state || "{}"; | 167 bot.state = bot.state || "{}"; |
| 187 bot.state = JSON.parse(bot.state); | 168 bot.state = JSON.parse(bot.state); |
| 188 // get the disks in an easier to deal with format, sorted by size. | 169 // get the disks in an easier to deal with format, sorted by size. |
| 189 var disks = bot.state.disks || {}; | 170 var disks = bot.state.disks || {}; |
| 190 var keys = Object.keys(disks); | 171 var keys = Object.keys(disks); |
| 191 if (!keys.length) { | 172 if (!keys.length) { |
| 192 bot.disks = [{"id": "unknown", "mb": 0}]; | 173 bot.disks = [{"id": "unknown", "mb": 0}]; |
| 193 } else { | 174 } else { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 221 bot.state.devices = devices; | 202 bot.state.devices = devices; |
| 222 | 203 |
| 223 if (bot.last_seen_ts) { | 204 if (bot.last_seen_ts) { |
| 224 bot.last_seen_ts = new Date(bot.last_seen_ts); | 205 bot.last_seen_ts = new Date(bot.last_seen_ts); |
| 225 } | 206 } |
| 226 if (bot.first_seen_ts) { | 207 if (bot.first_seen_ts) { |
| 227 bot.first_seen_ts = new Date(bot.first_seen_ts); | 208 bot.first_seen_ts = new Date(bot.first_seen_ts); |
| 228 } | 209 } |
| 229 | 210 |
| 230 }.bind(this)); | 211 }.bind(this)); |
| 231 return this._list.items; | 212 return json.items; |
| 232 }, | 213 }, |
| 233 | 214 |
| 234 _fleet: function() { | 215 _fleet: function() { |
| 235 if (!this._count) { | 216 if (!this._count) { |
| 236 return {}; | 217 return {}; |
| 237 } | 218 } |
| 238 return { | 219 return { |
| 239 all: this._count.count || -1, | 220 all: this._count.count || -1, |
| 240 alive: (this._count.count - this._count.dead) || -1, | 221 alive: (this._count.count - this._count.dead) || -1, |
| 241 busy: this._count.busy || -1, | 222 busy: this._count.busy || -1, |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 // Create custom filter options | 275 // Create custom filter options |
| 295 pMap["disk_space"] = []; | 276 pMap["disk_space"] = []; |
| 296 pMap["task"] = ["busy", "idle"]; | 277 pMap["task"] = ["busy", "idle"]; |
| 297 pMap["status"] = ["alive", "dead", "quarantined"]; | 278 pMap["status"] = ["alive", "dead", "quarantined"]; |
| 298 | 279 |
| 299 // No need to sort any of this, bot-filters sorts secondary items | 280 // No need to sort any of this, bot-filters sorts secondary items |
| 300 // automatically, especially when the user types a query. | 281 // automatically, especially when the user types a query. |
| 301 return pMap; | 282 return pMap; |
| 302 }, | 283 }, |
| 303 | 284 |
| 304 _request: function() { | |
| 305 // wait until the user has logged in and the filters have loaded before
requesting this to avoid double or even triple requests. | |
| 306 if (!this.auth_headers || !this.query_params) { | |
| 307 return; | |
| 308 } | |
| 309 this._getJsonAsync("_list", "/_ah/api/swarming/v1/bots/list", | |
| 310 "_busy1", this.auth_headers, this.query_params); | |
| 311 }, | |
| 312 | |
| 313 }); | 285 }); |
| 314 })(); | 286 })(); |
| 315 </script> | 287 </script> |
| 316 </dom-module> | 288 </dom-module> |
| OLD | NEW |