| 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 // outputs | 22 // outputs |
| 23 bots: Array<Object>, all bots returned by the botlist. | 23 bots: Array<Object>, all bots returned by the botlist. |
| 24 busy: Boolean, if the ajax request is in flight. | 24 busy: Boolean, if any ajax requests are in flight. |
| 25 fleet: Object, counts of all bots in the fleet. Contains "alive", "busy", |
| 26 "idle", "dead", and "quarantined". |
| 25 primary_map: Object, a mapping of primary keys to secondary items. | 27 primary_map: Object, a mapping of primary keys to secondary items. |
| 26 The primary keys are things that can be columns or sorted by. The | 28 The primary keys are things that can be columns or sorted by. The |
| 27 primary values (aka the secondary items) are things that can be filtered | 29 primary values (aka the secondary items) are things that can be filtered |
| 28 on. Primary consists of dimensions and state. Secondary contains the | 30 on. Primary consists of dimensions and state. Secondary contains the |
| 29 values primary things can be. | 31 values primary things can be. |
| 30 primary_arr: Array<String>, the display order of the primary keys. | 32 primary_arr: Array<String>, the display order of the primary keys. |
| 31 This is dimensions, then bot properties, then elements from bot.state. | 33 This is dimensions, then bot properties, then elements from bot.state. |
| 32 | 34 |
| 33 Methods: | 35 Methods: |
| 34 signIn(): Force a signin of the user using OAuth. This happens | 36 signIn(): Force a signin of the user using OAuth. This happens |
| 35 automatically when auth_headers is set. | 37 automatically when auth_headers is set. |
| 36 | 38 |
| 37 Events: | 39 Events: |
| 38 None. | 40 None. |
| 39 --> | 41 --> |
| 40 | 42 |
| 41 <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"> |
| 42 | 44 |
| 43 <link rel="import" href="bot-list-shared.html"> | 45 <link rel="import" href="bot-list-shared.html"> |
| 44 | 46 |
| 45 <dom-module id="bot-list-data"> | 47 <dom-module id="bot-list-data"> |
| 46 <template> | 48 <template> |
| 47 <iron-ajax id="request" | 49 <iron-ajax id="botlist" |
| 48 url="/_ah/api/swarming/v1/bots/list" | 50 url="/_ah/api/swarming/v1/bots/list" |
| 49 headers="[[auth_headers]]" | 51 headers="[[auth_headers]]" |
| 50 handle-as="json" | 52 handle-as="json" |
| 51 last-response="{{_data}}" | 53 last-response="{{_list}}" |
| 52 loading="{{busy}}"> | 54 loading="{{_busy1}}"> |
| 55 </iron-ajax> |
| 56 |
| 57 <iron-ajax id="fleet" |
| 58 url="/_ah/api/swarming/v1/bots/count" |
| 59 headers="[[auth_headers]]" |
| 60 handle-as="json" |
| 61 last-response="{{_count}}" |
| 62 loading="{{_busy2}}"> |
| 53 </iron-ajax> | 63 </iron-ajax> |
| 54 </template> | 64 </template> |
| 55 <script> | 65 <script> |
| 56 (function(){ | 66 (function(){ |
| 57 // TODO(kjlubick): Add more of these as well as things from state | 67 // TODO(kjlubick): Add more of these as well as things from state |
| 58 // i.e. disk space remaining. | 68 // i.e. disk space remaining. |
| 59 var DIMENSIONS = ["cores", "cpu", "id", "os", "pool"]; | 69 var DIMENSIONS = ["cores", "cpu", "id", "os", "pool"]; |
| 60 // "gpu" and "devices" are added separately because we need to | 70 // "gpu" and "devices" are added separately because we need to |
| 61 // deal with aliases. | 71 // deal with aliases. |
| 62 var BOT_PROPERTIES = ["gpu", "devices", "task", "status"]; | 72 var BOT_PROPERTIES = ["gpu", "devices", "task", "status"]; |
| 63 Polymer({ | 73 Polymer({ |
| 64 is: 'bot-list-data', | 74 is: 'bot-list-data', |
| 75 |
| 76 behaviors: [SwarmingBehaviors.BotListBehavior], |
| 77 |
| 65 properties: { | 78 properties: { |
| 66 // inputs | 79 // inputs |
| 67 auth_headers: { | 80 auth_headers: { |
| 68 type: Object, | 81 type: Object, |
| 69 observer: "signIn", | 82 observer: "signIn", |
| 70 }, | 83 }, |
| 71 | 84 |
| 72 //outputs | 85 //outputs |
| 73 bots: { | 86 bots: { |
| 74 type: Array, | 87 type: Array, |
| 75 computed: "_bots(_data)", | 88 computed: "_bots(_list)", |
| 76 notify: true, | 89 notify: true, |
| 77 }, | 90 }, |
| 78 busy: { | 91 busy: { |
| 79 type: Boolean, | 92 type: Boolean, |
| 93 computed: "_or(_busy1,_busy2)", |
| 94 notify: true, |
| 95 }, |
| 96 fleet: { |
| 97 type: Object, |
| 98 computed: "_fleet(_count)", |
| 80 notify: true, | 99 notify: true, |
| 81 }, | 100 }, |
| 82 primary_map: { | 101 primary_map: { |
| 83 type:Object, | 102 type:Object, |
| 84 computed: "_primaryMap(bots)", | 103 computed: "_primaryMap(bots)", |
| 85 notify: true, | 104 notify: true, |
| 86 }, | 105 }, |
| 87 primary_arr: { | 106 primary_arr: { |
| 88 type:Array, | 107 type:Array, |
| 89 value: function() { | 108 value: function() { |
| 90 return DIMENSIONS.concat(BOT_PROPERTIES); | 109 return DIMENSIONS.concat(BOT_PROPERTIES); |
| 91 }, | 110 }, |
| 92 notify: true, | 111 notify: true, |
| 93 }, | 112 }, |
| 94 | 113 |
| 95 // private | 114 // private |
| 96 _data: { | 115 _count: { |
| 116 type: Object, |
| 117 }, |
| 118 _list: { |
| 97 type: Object, | 119 type: Object, |
| 98 }, | 120 }, |
| 99 }, | 121 }, |
| 100 behaviors: [SwarmingBehaviors.BotListBehavior], | |
| 101 | 122 |
| 102 signIn: function(){ | 123 signIn: function(){ |
| 103 this.$.request.generateRequest(); | 124 this.$.botlist.generateRequest(); |
| 125 this.$.fleet.generateRequest(); |
| 104 }, | 126 }, |
| 105 | 127 |
| 106 _bots: function(){ | 128 _bots: function(){ |
| 107 if (!this._data || !this._data.items) { | 129 if (!this._list || !this._list.items) { |
| 108 return []; | 130 return []; |
| 109 } | 131 } |
| 110 this._data.items.forEach(function(o){ | 132 this._list.items.forEach(function(o){ |
| 111 o.state = JSON.parse(o.state); | 133 o.state = JSON.parse(o.state); |
| 112 }); | 134 }); |
| 113 return this._data.items; | 135 return this._list.items; |
| 136 }, |
| 137 |
| 138 _fleet: function() { |
| 139 if (!this._count) { |
| 140 return {}; |
| 141 } |
| 142 return { |
| 143 alive: this._count.count || -1, |
| 144 busy: this._count.busy || -1, |
| 145 idle: this._count.count && this._count.busy && |
| 146 this._count.count - this._count.busy, |
| 147 dead: this._count.dead || -1, |
| 148 quarantined: this._count.quarantined || -1, |
| 149 } |
| 114 }, | 150 }, |
| 115 | 151 |
| 116 _primaryMap: function(bots){ | 152 _primaryMap: function(bots){ |
| 117 // map will keep track of dimensions that we have seen at least once. | 153 // map will keep track of dimensions that we have seen at least once. |
| 118 // This will then basically get turned into an array to be used for | 154 // This will then basically get turned into an array to be used for |
| 119 // filtering. | 155 // filtering. |
| 120 var map = {}; | 156 var map = {}; |
| 121 DIMENSIONS.forEach(function(p){ | 157 DIMENSIONS.forEach(function(p){ |
| 122 map[p] = {}; | 158 map[p] = {}; |
| 123 }); | 159 }); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 // Create custom filter options | 201 // Create custom filter options |
| 166 pMap["task"] = ["busy", "idle"]; | 202 pMap["task"] = ["busy", "idle"]; |
| 167 pMap["status"] = ["available", "dead", "quarantined"]; | 203 pMap["status"] = ["available", "dead", "quarantined"]; |
| 168 return pMap; | 204 return pMap; |
| 169 }, | 205 }, |
| 170 | 206 |
| 171 }); | 207 }); |
| 172 })(); | 208 })(); |
| 173 </script> | 209 </script> |
| 174 </dom-module> | 210 </dom-module> |
| OLD | NEW |