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

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

Issue 2182693002: Add new botlist for swarming (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-py@app-wrapper
Patch Set: Adjust font and layout a bit more 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
(Empty)
1 <!--
2 Copyright 2016 The LUCI Authors. All rights reserved.
3 Use of this source code is governed under the Apache License, Version 2.0
4 that can be found in the LICENSE file.
5
6 This in an HTML Import-able file that contains the definition
7 of the following elements:
8
9 <bot-list-data>
10
11 This makes calls authenticated with Oauth 2 to the swarming apis. It parses
12 that data into usable data structures.
13
14 Usage:
15
16 <bot-list-data></bot-list-data>
17
18 Properties:
19 // inputs
20 auth_headers: Object, the OAuth2 header to include in the request. This
21 should come from swarming-app.
22 // outputs
23 bots: Array<Object>, all bots returned by the botlist.
24 busy: Boolean, if the ajax request is in flight.
25 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
27 primary values (aka the secondary items) are things that can be filtered
28 on. Primary consists of dimensions and state. Secondary contains the
29 values primary things can be.
30 primary_arr: Array<String>, the display order of the primary keys.
31 This is dimensions, then bot properties, then elements from bot.state.
32
33 Methods:
34 signIn(): Force a signin of the user using OAuth. This happens
35 automatically when auth_headers is set.
36
37 Events:
38 None.
39 -->
40
41 <link rel="import" href="/res/imp/bower_components/iron-ajax/iron-ajax.html">
42
43 <link rel="import" href="bot-list-shared.html">
44
45 <dom-module id="bot-list-data">
46 <template>
47 <iron-ajax id="request"
48 url="/_ah/api/swarming/v1/bots/list"
49 headers="[[auth_headers]]"
50 handle-as="json"
51 last-response="{{_data}}"
52 loading="{{busy}}">
53 </iron-ajax>
54 </template>
55 <script>
56 (function(){
57 // TODO(kjlubick): Add more of these as well as things from state
58 // i.e. disk space remaining.
59 var DIMENSIONS = ["cores", "cpu", "id", "os", "pool"];
60 // "gpu" and "devices" are added separately because we need to
61 // deal with aliases.
62 var BOT_PROPERTIES = ["gpu", "devices", "task", "status"];
63 Polymer({
64 is: 'bot-list-data',
65 properties: {
66 // inputs
67 auth_headers: {
68 type: Object,
69 observer: "signIn",
70 },
71
72 //outputs
73 bots: {
74 type: Array,
75 computed: "_bots(_data)",
76 notify: true,
77 },
78 busy: {
79 type: Boolean,
80 notify: true,
81 },
82 primary_map: {
83 type:Object,
84 computed: "_primaryMap(bots)",
85 notify: true,
86 },
87 primary_arr: {
88 type:Array,
89 value: function() {
90 return DIMENSIONS.concat(BOT_PROPERTIES);
91 },
92 notify: true,
93 },
94
95 // private
96 _data: {
97 type: Object,
98 },
99 },
100 behaviors: [SwarmingBehaviors.BotListBehavior],
101
102 signIn: function(){
103 this.$.request.generateRequest();
104 },
105
106 _bots: function(){
107 if (!this._data || !this._data.items) {
108 return [];
109 }
110 this._data.items.forEach(function(o){
111 o.state = JSON.parse(o.state);
112 });
113 return this._data.items;
114 },
115
116 _primaryMap: function(bots){
117 // 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
119 // filtering.
120 var map = {};
121 DIMENSIONS.forEach(function(p){
122 map[p] = {};
123 });
124 map["devices"] = {};
125 map["gpu"] = {};
126 bots.forEach(function(b){
127 DIMENSIONS.forEach(function(d){
128 var dims = this._dimension(b, d) || [];
129 dims.forEach(function(e){
130 map[d][e] = true;
131 });
132 }.bind(this));
133
134 // Add Android devices and their aliases
135 this._devices(b).forEach(function(d){
136 var dt = this._deviceType(d);
137 var alias = this._androidAlias(d);
138 if (dt !== "unknown") {
139 dt = this._applyAlias(dt,alias);
140 }
141 map["devices"][dt] = true;
142 }.bind(this));
143 map["devices"]["none"] = true;
144
145 // Add GPUs and their aliases
146 var gpus = this._dimension(b, "gpu") || [];
147 gpus.forEach(function(g){
148 var alias = this._gpuAlias(g);
149 if (alias !== "UNKNOWN") {
150 map["gpu"][this._applyAlias(g, alias)] = true;
151 } else {
152 map["gpu"][g] = true;
153 }
154
155 }.bind(this));
156 }.bind(this));
157
158 // Turn the Map<Object,Map<Boolean>> into a Map<Object,Array<String>>
159 // with all of the secondary elements sorted appropriately.
160 var pMap = {};
161 for (key in map){
162 pMap[key] = Object.keys(map[key]).sort(swarming.naturalCompare);
163 }
164
165 // Create custom filter options
166 pMap["task"] = ["busy", "idle"];
167 pMap["status"] = ["available", "dead", "quarantined"];
168 return pMap;
169 },
170
171 });
172 })();
173 </script>
174 </dom-module>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698