| 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 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 Methods: | 35 Methods: |
| 36 signIn(): Force a signin of the user using OAuth. This happens | 36 signIn(): Force a signin of the user using OAuth. This happens |
| 37 automatically when auth_headers is set. | 37 automatically when auth_headers is set. |
| 38 | 38 |
| 39 Events: | 39 Events: |
| 40 None. | 40 None. |
| 41 --> | 41 --> |
| 42 | 42 |
| 43 <link rel="import" href="/res/imp/bower_components/iron-ajax/iron-ajax.html"> | 43 <link rel="import" href="/res/imp/bower_components/iron-ajax/iron-ajax.html"> |
| 44 | 44 |
| 45 <link rel="import" href="/res/imp/common/common-aliases.html"> |
| 46 |
| 45 <dom-module id="task-list-data"> | 47 <dom-module id="task-list-data"> |
| 46 <template> | 48 <template> |
| 47 <iron-ajax id="tasklist" | 49 <iron-ajax id="tasklist" |
| 48 url="/_ah/api/swarming/v1/tasks/list" | 50 url="/_ah/api/swarming/v1/tasks/list" |
| 49 headers="[[auth_headers]]" | 51 headers="[[auth_headers]]" |
| 50 params="[[query_params]]" | 52 params="[[query_params]]" |
| 51 handle-as="json" | 53 handle-as="json" |
| 52 last-response="{{_list}}" | 54 last-response="{{_list}}" |
| 53 loading="{{_busy1}}"> | 55 loading="{{_busy1}}"> |
| 54 </iron-ajax> | 56 </iron-ajax> |
| 55 <!-- TODO(kjlubick): Make more requests (like all tags) --> | 57 |
| 58 <iron-ajax id="tags" |
| 59 url="/_ah/api/swarming/v1/tasks/tags" |
| 60 headers="[[auth_headers]]" |
| 61 handle-as="json" |
| 62 last-response="{{_tags}}" |
| 63 loading="{{_busy2}}"> |
| 64 </iron-ajax> |
| 65 |
| 66 <iron-ajax id="dimensions" |
| 67 url="/_ah/api/swarming/v1/bots/dimensions" |
| 68 headers="[[auth_headers]]" |
| 69 handle-as="json" |
| 70 last-response="{{_dimensions}}" |
| 71 loading="{{_busy3}}"> |
| 72 </iron-ajax> |
| 56 | 73 |
| 57 </template> | 74 </template> |
| 58 <script> | 75 <script> |
| 59 (function(){ | 76 (function(){ |
| 60 Polymer({ | 77 Polymer({ |
| 61 is: 'task-list-data', | 78 is: 'task-list-data', |
| 62 | 79 |
| 63 behaviors: [SwarmingBehaviors.SwarmingBehavior], | 80 behaviors: [ |
| 81 SwarmingBehaviors.SwarmingBehavior, |
| 82 SwarmingBehaviors.Aliases, |
| 83 ], |
| 64 | 84 |
| 65 properties: { | 85 properties: { |
| 66 // inputs | 86 // inputs |
| 67 auth_headers: { | 87 auth_headers: { |
| 68 type: Object, | 88 type: Object, |
| 69 observer: "signIn", | 89 observer: "signIn", |
| 70 }, | 90 }, |
| 71 query_params: { | 91 query_params: { |
| 72 type: Object, | 92 type: Object, |
| 73 }, | 93 }, |
| 74 | 94 |
| 75 //outputs | 95 // outputs |
| 76 busy: { | 96 busy: { |
| 77 type: Boolean, | 97 type: Boolean, |
| 78 computed: "_or(_busy1)", | 98 computed: "_or(_busy1,_busy2,_busy3)", |
| 99 notify: true, |
| 100 }, |
| 101 primary_map: { |
| 102 type: Object, |
| 103 computed: "_primaryMap(_tags,_dimensions,_list)", |
| 104 notify: true, |
| 105 }, |
| 106 primary_arr: { |
| 107 type: Array, |
| 108 computed: "_primaryArr(primary_map)", |
| 79 notify: true, | 109 notify: true, |
| 80 }, | 110 }, |
| 81 tasks: { | 111 tasks: { |
| 82 type: Array, | 112 type: Array, |
| 83 computed: "_tasks(_list)", | 113 computed: "_tasks(_list)", |
| 84 notify: true, | 114 notify: true, |
| 115 }, |
| 116 |
| 117 // private |
| 118 _dimensions: { |
| 119 type: Object, |
| 85 } | 120 } |
| 86 }, | 121 }, |
| 122 |
| 87 signIn: function(){ | 123 signIn: function(){ |
| 88 // Auto on iron-ajax means to automatically re-make the request if | 124 // Auto on iron-ajax means to automatically re-make the request if |
| 89 // the url or the query params change. Auto does not trigger if the | 125 // the url or the query params change. Auto does not trigger if the |
| 90 // [auth] headers change, so we wait until the user is signed in | 126 // [auth] headers change, so we wait until the user is signed in |
| 91 // before making any requests. | 127 // before making any requests. |
| 92 this.$.tasklist.auto = true; | 128 this.$.tasklist.auto = true; |
| 129 this.$.tags.auto = true; |
| 130 this.$.dimensions.auto = true; |
| 131 }, |
| 132 |
| 133 _primaryArr: function(map) { |
| 134 var arr = Object.keys(map); |
| 135 arr.sort(); |
| 136 return arr; |
| 137 }, |
| 138 |
| 139 _primaryMap: function(tags, dims) { |
| 140 tags = (tags && tags.tasks_tags) || []; |
| 141 dims = (dims && dims.bots_dimensions) || []; |
| 142 // TODO(kjlubick) |
| 143 // Take fleet task_tags, add in dimensions from fleet, and tags from tas
ks. |
| 144 var pMap = {}; |
| 145 tags.forEach(function(t) { |
| 146 var values = t.value || []; |
| 147 pMap[t.key] = values.filter(function(v) { |
| 148 return v; |
| 149 }); |
| 150 }); |
| 151 |
| 152 // augment existing tags with aliased dimensions |
| 153 dims.forEach(function(d) { |
| 154 var vals = d.value; |
| 155 if (pMap[d.key]) { |
| 156 var existing = pMap[d.key]; |
| 157 existing.forEach(function(d) { |
| 158 if (vals.indexOf(d) === -1) { |
| 159 vals.push(d); |
| 160 } |
| 161 }); |
| 162 } |
| 163 if (this.DIMENSIONS_WITH_ALIASES.indexOf(d.key) === -1) { |
| 164 // value is an array of all seen values for the dimension d.key |
| 165 pMap[d.key] = vals; |
| 166 } else if (d.key === "gpu") { |
| 167 var gpus = []; |
| 168 vals.forEach(function(g){ |
| 169 var alias = this._gpuAlias(g); |
| 170 if (alias !== "unknown") { |
| 171 gpus.push(this._applyAlias(g, alias)); |
| 172 } else { |
| 173 gpus.push(g); |
| 174 } |
| 175 }.bind(this)); |
| 176 pMap["gpu"] = gpus; |
| 177 } else if (d.key === "device_type") { |
| 178 var devs = []; |
| 179 d.value.forEach(function(dt){ |
| 180 var alias = this._androidAlias(dt); |
| 181 if (alias !== "unknown") { |
| 182 devs.push(this._applyAlias(dt, alias)); |
| 183 } else { |
| 184 devs.push(dt); |
| 185 } |
| 186 }.bind(this)); |
| 187 pMap["device_type"] = devs; |
| 188 } else { |
| 189 console.log("Unknown alias type: ", d); |
| 190 } |
| 191 }.bind(this)); |
| 192 |
| 193 // Add some options that might not show up. |
| 194 pMap["android_devices"].push("0"); |
| 195 pMap["device_os"].push("none"); |
| 196 pMap["device_type"].push("none"); |
| 197 pMap["user"].push("none"); |
| 198 |
| 199 // Custom filter options |
| 200 pMap["name"] = []; |
| 201 pMap["state"] = ["RUNNING", "PENDING", "EXPIRED", "TIMED_OUT", "BOT_DIED
", "CANCELED", "COMPLETED", "Going", "Not Going", "Exceptional", "Done", "Abando
ned"]; |
| 202 |
| 203 return pMap; |
| 93 }, | 204 }, |
| 94 | 205 |
| 95 _tasks: function() { | 206 _tasks: function() { |
| 96 if (!this._list || !this._list.items) { | 207 if (!this._list || !this._list.items) { |
| 97 return []; | 208 return []; |
| 98 } | 209 } |
| 99 // Do any preprocessing here | 210 // Do any preprocessing here |
| 211 this._list.items.forEach(function(t) { |
| 212 var tagMap = {}; |
| 213 t.tags.forEach(function(tag) { |
| 214 var split = tag.split(":", 1) |
| 215 var key = split[0]; |
| 216 var rest = tag.substring(key.length + 1); |
| 217 tagMap[key] = rest; |
| 218 }); |
| 219 t.tagMap = tagMap; |
| 220 }); |
| 100 return this._list.items; | 221 return this._list.items; |
| 101 } | 222 } |
| 102 }); | 223 }); |
| 103 })(); | 224 })(); |
| 104 </script> | 225 </script> |
| 105 </dom-module> | 226 </dom-module> |
| OLD | NEW |