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

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: Add documentation 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">
stephana 2016/07/29 14:09:31 What is the benefit of creating a declarative ajax
kjlubick 2016/07/29 19:13:25 Using iron-ajax, to me, seems easier to read and h
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 var DIMENSIONS = ["cores", "cpu", "id", "os", "pool"];
58 // "gpu" and "devices" are added separately because we need to
59 // deal with aliases.
60 var BOT_PROPERTIES = ["gpu", "devices", "task", "status"];
61 Polymer({
62 is: 'bot-list-data',
63 properties: {
64 // inputs
65 auth_headers: {
66 type: Object,
67 observer: "signIn",
68 },
69
70 //outputs
71 bots: {
72 type: Array,
73 computed: "_bots(_data)",
74 notify: true,
75 },
76 busy: {
77 type: Boolean,
78 notify: true,
79 },
80 primary_map: {
81 type:Object,
82 computed: "_primaryMap(bots)",
83 notify: true,
84 },
85 primary_arr: {
86 type:Array,
87 value: function() {
88 return DIMENSIONS.concat(BOT_PROPERTIES);
89 },
90 notify: true,
91 },
92
93 // private
94 _data: {
95 type: Object,
96 },
97 },
98 behaviors: [SwarmingBehaviors.BotListBehavior],
99
100 signIn: function(){
101 this.$.request.generateRequest();
102 },
103
104 _bots: function(){
105 if (!this._data || !this._data.items) {
106 return [];
107 }
108 this._data.items.forEach(function(o){
109 o.state = JSON.parse(o.state);
110 });
111 return this._data.items;
112 },
113
114 _primaryMap: function(bots){
115 // map will keep track of dimensions that we have seen at least once.
116 // This will then basically get turned into an array to be used for
117 // filtering.
118 var map = {};
119 DIMENSIONS.forEach(function(p){
120 map[p] = {};
121 });
122 map["devices"] = {};
123 map["gpu"] = {};
124 bots.forEach(function(b){
125 DIMENSIONS.forEach(function(d){
126 var dims = this._dimension(b, d) || [];
127 dims.forEach(function(e){
128 map[d][e] = true;
129 });
130 }.bind(this));
131
132 // Add Android devices and their aliases
133 this._devices(b).forEach(function(d){
134 var dt = this._deviceType(d);
135 var alias = this._androidAlias(d);
136 if (dt !== "unknown") {
137 dt = this._applyAlias(dt,alias);
138 }
139 map["devices"][dt] = true;
140 }.bind(this));
141 map["devices"]["none"] = true;
142
143 // Add GPUs and their aliases
144 var gpus = this._dimension(b, "gpu") || [];
145 gpus.forEach(function(g){
146 var alias = this._gpuAlias(g);
147 if (alias !== "UNKNOWN") {
148 map["gpu"][this._applyAlias(g, alias)] = true;
149 } else {
150 map["gpu"][g] = true;
151 }
152
153 }.bind(this));
154 }.bind(this));
155
156 // Turn the Map<Object,Map<Boolean>> into a Map<Object,Array<String>>
157 // with all of the secondary elements sorted appropriately.
158 var pMap = {};
159 for (key in map){
160 pMap[key] = Object.keys(map[key]).sort(function(a,b){
161 // Try numeric, aka "natural" sort first.
162 var ns = a - b;
163 if (ns) {
164 return ns;
165 }
166 return a.localeCompare(b);
167 });
168 }
169
170 // Create custom filter options
171 pMap["task"] = ["busy", "idle"];
172 pMap["status"] = ["available", "dead", "quarantined"];
173 return pMap;
174 },
175
176 });
177 })();
178 </script>
179 </dom-module>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698