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

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

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

Powered by Google App Engine
This is Rietveld 408576698