Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(15)

Side by Side Diff: appengine/swarming/elements/res/imp/botlist/bot-list-data.html

Issue 2227803002: Mirror filters and sort preferences to url-params (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-py@use-dimensions
Patch Set: Make limit a visible option Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
23 server-side. This can have dimensions:Array<String>, quarantined:String
24 and is_dead: String.
22 // outputs 25 // outputs
23 bots: Array<Object>, all bots returned by the botlist. This is an Object 26 bots: Array<Object>, all bots returned by the botlist. This is an Object
24 with at least the following structure: 27 with at least the following structure:
25 dimensions: Array<Object>: Has key:String and value:Array<String> 28 dimensions: Array<Object>: Has key:String and value:Array<String>
26 task_id: String 29 task_id: String
27 external_ip: String 30 external_ip: String
28 is_dead: Object: Is usually Boolean, but could be message string 31 is_dead: Object: Is usually Boolean, but could be message string
29 quarantined: Object: Is usually Boolean, but could be message string 32 quarantined: Object: Is usually Boolean, but could be message string
30 bot_id: String 33 bot_id: String
31 state: String, Stringified JSON that has many pieces of information, like 34 state: String, Stringified JSON that has many pieces of information, like
(...skipping 19 matching lines...) Expand all
51 54
52 <link rel="import" href="/res/imp/bower_components/iron-ajax/iron-ajax.html"> 55 <link rel="import" href="/res/imp/bower_components/iron-ajax/iron-ajax.html">
53 56
54 <link rel="import" href="bot-list-shared.html"> 57 <link rel="import" href="bot-list-shared.html">
55 58
56 <dom-module id="bot-list-data"> 59 <dom-module id="bot-list-data">
57 <template> 60 <template>
58 <iron-ajax id="botlist" 61 <iron-ajax id="botlist"
59 url="/_ah/api/swarming/v1/bots/list" 62 url="/_ah/api/swarming/v1/bots/list"
60 headers="[[auth_headers]]" 63 headers="[[auth_headers]]"
61 params="[[_botlistParams(dimensions.*)]]" 64 params="[[query_params]]"
62 handle-as="json" 65 handle-as="json"
63 last-response="{{_list}}" 66 last-response="{{_list}}"
64 loading="{{_busy1}}"> 67 loading="{{_busy1}}">
65 </iron-ajax> 68 </iron-ajax>
66 69
67 <iron-ajax id="dimensions" 70 <iron-ajax id="dimensions"
68 url="/_ah/api/swarming/v1/bots/dimensions" 71 url="/_ah/api/swarming/v1/bots/dimensions"
69 headers="[[auth_headers]]" 72 headers="[[auth_headers]]"
70 handle-as="json" 73 handle-as="json"
71 last-response="{{_dimensions}}" 74 last-response="{{_dimensions}}"
(...skipping 15 matching lines...) Expand all
87 is: 'bot-list-data', 90 is: 'bot-list-data',
88 91
89 behaviors: [SwarmingBehaviors.BotListBehavior], 92 behaviors: [SwarmingBehaviors.BotListBehavior],
90 93
91 properties: { 94 properties: {
92 // inputs 95 // inputs
93 auth_headers: { 96 auth_headers: {
94 type: Object, 97 type: Object,
95 observer: "signIn", 98 observer: "signIn",
96 }, 99 },
97 dimensions: { 100 query_params: {
98 type: Array, 101 type: Object,
stephana 2016/08/11 17:09:53 Does this need a default value ?
kjlubick 2016/08/11 20:00:21 No. Polymer best practices say to use default valu
stephana 2016/08/12 14:45:59 Acknowledged.
99 }, 102 },
100 103
101 //outputs 104 //outputs
102 bots: { 105 bots: {
103 type: Array, 106 type: Array,
104 computed: "_bots(_list)", 107 computed: "_bots(_list)",
105 notify: true, 108 notify: true,
106 }, 109 },
107 busy: { 110 busy: {
108 type: Boolean, 111 type: Boolean,
(...skipping 23 matching lines...) Expand all
132 }, 135 },
133 _dimensions: { 136 _dimensions: {
134 type: Object, 137 type: Object,
135 }, 138 },
136 _list: { 139 _list: {
137 type: Object, 140 type: Object,
138 }, 141 },
139 }, 142 },
140 143
141 signIn: function(){ 144 signIn: function(){
145 // Auto on iron-ajax means to automatically re-make the request if
146 // the url or the query params change. Auto does not trigger if the
147 // [auth] headers change, so we wait until the user is signed in
148 // before making any requests.
142 this.$.botlist.auto = true; 149 this.$.botlist.auto = true;
143 this.$.dimensions.auto = true; 150 this.$.dimensions.auto = true;
144 this.$.fleet.auto = true; 151 this.$.fleet.auto = true;
145 }, 152 },
146 153
147 _botlistParams: function() {
148 if (!this.dimensions) {
149 return {};
150 }
151 return {
152 dimensions: this.dimensions,
153 };
154 },
155
156 _bots: function(){ 154 _bots: function(){
157 if (!this._list || !this._list.items) { 155 if (!this._list || !this._list.items) {
158 return []; 156 return [];
159 } 157 }
160 // Do any preprocessing here 158 // Do any preprocessing here
161 this._list.items.forEach(function(bot){ 159 this._list.items.forEach(function(bot){
162 // Parse the state, which is a JSON string. This contains a lot of 160 // Parse the state, which is a JSON string. This contains a lot of
163 // interesting information like details about the devices attached. 161 // interesting information like details about the devices attached.
164 bot.state = JSON.parse(bot.state); 162 bot.state = JSON.parse(bot.state);
165 // get the disks in an easier to deal with format, sorted by size. 163 // get the disks in an easier to deal with format, sorted by size.
(...skipping 14 matching lines...) Expand all
180 178
181 }); 179 });
182 return this._list.items; 180 return this._list.items;
183 }, 181 },
184 182
185 _fleet: function() { 183 _fleet: function() {
186 if (!this._count) { 184 if (!this._count) {
187 return {}; 185 return {};
188 } 186 }
189 return { 187 return {
190 alive: this._count.count || -1, 188 all: this._count.count || -1,
189 alive: (this._count.count - this._count.dead) || -1,
191 busy: this._count.busy || -1, 190 busy: this._count.busy || -1,
192 idle: this._count.count && this._count.busy && 191 idle: (this._count.count - this._count.busy) || -1,
193 this._count.count - this._count.busy,
194 dead: this._count.dead || -1, 192 dead: this._count.dead || -1,
195 quarantined: this._count.quarantined || -1, 193 quarantined: this._count.quarantined || -1,
196 } 194 }
197 }, 195 },
198 196
199 _primaryArr: function(dimensions, properties) { 197 _primaryArr: function(dimensions, properties) {
200 return dimensions.concat(properties); 198 return dimensions.concat(properties);
201 }, 199 },
202 200
203 _primaryMap: function(dimensions){ 201 _primaryMap: function(dimensions){
204 // map will keep track of dimensions that we have seen at least once. 202 // pMap will have a list of columns to available values (primary key
205 // This will then basically get turned into an array to be used for 203 // to secondary values). This includes bot dimensions, but also
206 // filtering. 204 // includes state like disk_space, quarantined, busy, etc.
207 dimensions = dimensions.bots_dimensions; 205 dimensions = dimensions.bots_dimensions;
208 206
209 var pMap = {}; 207 var pMap = {};
210 dimensions.forEach(function(d){ 208 dimensions.forEach(function(d){
211 if (this.DIMENSIONS_WITH_ALIASES.indexOf(d.key) === -1) { 209 if (this.DIMENSIONS_WITH_ALIASES.indexOf(d.key) === -1) {
212 // value is an array of all seen values for the dimension d.key 210 // value is an array of all seen values for the dimension d.key
213 pMap[d.key] = d.value; 211 pMap[d.key] = d.value;
214 } else if (d.key === "gpu") { 212 } else if (d.key === "gpu") {
215 var gpus = []; 213 var gpus = [];
216 d.value.forEach(function(g){ 214 d.value.forEach(function(g){
(...skipping 24 matching lines...) Expand all
241 // Add some options that might not show up. 239 // Add some options that might not show up.
242 pMap["android_devices"].push("0"); 240 pMap["android_devices"].push("0");
243 pMap["device_os"].push("none"); 241 pMap["device_os"].push("none");
244 pMap["device_type"].push("none"); 242 pMap["device_type"].push("none");
245 243
246 pMap["id"] = []; 244 pMap["id"] = [];
247 245
248 // Create custom filter options 246 // Create custom filter options
249 pMap["disk_space"] = []; 247 pMap["disk_space"] = [];
250 pMap["task"] = ["busy", "idle"]; 248 pMap["task"] = ["busy", "idle"];
251 pMap["status"] = ["available", "dead", "quarantined"]; 249 pMap["status"] = ["alive", "dead", "quarantined"];
252 250
253 // No need to sort any of this, bot-filters sorts secondary items 251 // No need to sort any of this, bot-filters sorts secondary items
254 // automatically, especially when the user types a query. 252 // automatically, especially when the user types a query.
255 return pMap; 253 return pMap;
256 }, 254 },
257 255
258 }); 256 });
259 })(); 257 })();
260 </script> 258 </script>
261 </dom-module> 259 </dom-module>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698