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

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

Issue 2211163003: Update new botlist to use dimensions endpoint (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-py@limiting
Patch Set: put demo data in luci-py wiki 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 window.SwarmingBehaviors.BotListBehavior contains any shared functions and 6 window.SwarmingBehaviors.BotListBehavior contains any shared functions and
7 constants used by the bot-list and its sub-elements. 7 constants used by the bot-list and its sub-elements.
8 8
9 To use it, include 9 To use it, include
10 behaviors: [SwarmingBehaviors.BotListBehavior] 10 behaviors: [SwarmingBehaviors.BotListBehavior]
11 in the creation of your Polymer element. 11 in the creation of your Polymer element.
12 --> 12 -->
13 <script> 13 <script>
14 14
15 window.SwarmingBehaviors = window.SwarmingBehaviors || {}; 15 window.SwarmingBehaviors = window.SwarmingBehaviors || {};
16 (function(){ 16 (function(){
17 var ANDROID_ALIASES = { 17 var ANDROID_ALIASES = {
18 "bullhead": "Nexus 5X", 18 "bullhead": "Nexus 5X",
19 "flo": "Nexus 7", 19 "flo": "Nexus 7",
20 "flounder": "Nexus 9",
20 "hammerhead": "Nexus 5", 21 "hammerhead": "Nexus 5",
21 "mako": "Nexus 4", 22 "mako": "Nexus 4",
22 "shamu": "Nexus 6", 23 "shamu": "Nexus 6",
23 }; 24 };
24 // Taken from http://developer.android.com/reference/android/os/BatteryManag er.html 25 // Taken from http://developer.android.com/reference/android/os/BatteryManag er.html
25 var BATTERY_HEALTH_UNKNOWN = 1; 26 var BATTERY_HEALTH_UNKNOWN = 1;
26 var BATTERY_HEALTH_GOOD = 2; 27 var BATTERY_HEALTH_GOOD = 2;
27 var BATTERY_STATUS_CHARGING = 2; 28 var BATTERY_STATUS_CHARGING = 2;
28 29
29 var UNAUTHENTICATED = "unauthenticated"; 30 var UNAUTHENTICATED = "unauthenticated";
30 var AVAILABLE = "available"; 31 var AVAILABLE = "available";
32 var UNKNOWN = "unknown";
31 33
32 var GPU_ALIASES = { 34 var GPU_ALIASES = {
33 "1002": "AMD", 35 "1002": "AMD",
34 "1002:6779": "AMD Radeon HD 6450/7450/8450", 36 "1002:6779": "AMD Radeon HD 6450/7450/8450",
35 "1002:6821": "AMD Radeon HD 8870M", 37 "1002:6821": "AMD Radeon HD 8870M",
38 "1002:9830": "AMD Radeon HD 8400",
36 "102b": "Matrox", 39 "102b": "Matrox",
37 "102b:0522": "Matrox MGA G200e", 40 "102b:0522": "Matrox MGA G200e",
38 "102b:0532": "Matrox MGA G200eW", 41 "102b:0532": "Matrox MGA G200eW",
39 "102b:0534": "Matrox G200eR2", 42 "102b:0534": "Matrox G200eR2",
40 "10de": "NVIDIA", 43 "10de": "NVIDIA",
41 "10de:08aa": "NVIDIA GeForce 320M", 44 "10de:08aa": "NVIDIA GeForce 320M",
42 "10de:0fe9": "NVIDIA GeForce GT 750M Mac Edition", 45 "10de:0fe9": "NVIDIA GeForce GT 750M Mac Edition",
43 "10de:104a": "NVIDIA GeForce GT 610", 46 "10de:104a": "NVIDIA GeForce GT 610",
44 "10de:11c0": "NVIDIA GeForce GTX 660", 47 "10de:11c0": "NVIDIA GeForce GTX 660",
45 "10de:1244": "NVIDIA GeForce GTX 550 Ti", 48 "10de:1244": "NVIDIA GeForce GTX 550 Ti",
46 "10de:1401": "NVIDIA GeForce GTX 960", 49 "10de:1401": "NVIDIA GeForce GTX 960",
47 "8086": "Intel", 50 "8086": "Intel",
48 "8086:041a": "Intel Xeon Integrated", 51 "8086:041a": "Intel Xeon Integrated",
49 "8086:0a2e": "Intel Haswell Integrated", 52 "8086:0a2e": "Intel Haswell Integrated",
50 "8086:0d26": "Intel Crystal Well Integrated", 53 "8086:0d26": "Intel Crystal Well Integrated",
51 } 54 }
52 55
53 // For consistency, all aliases are displayed like: 56 // For consistency, all aliases are displayed like:
54 // Nexus 5X (bullhead) 57 // Nexus 5X (bullhead)
55 // This regex matches a string like "ALIAS (ORIG)", with ORIG as group 1. 58 // This regex matches a string like "ALIAS (ORIG)", with ORIG as group 1.
56 var ALIAS_REGEXP = /.+ \((.*)\)/; 59 var ALIAS_REGEXP = /.+ \((.*)\)/;
57 60
58 // This behavior wraps up all the shared bot-list functionality. 61 // This behavior wraps up all the shared bot-list functionality.
59 SwarmingBehaviors.BotListBehavior = { 62 SwarmingBehaviors.BotListBehavior = {
60 63
61 _androidAlias: function(device) { 64 properties: {
62 if (device.notReady) { 65 // TODO(kjlubick): Add more of these things from state, as they
63 return UNAUTHENTICATED.toUpperCase(); 66 // needed/useful/requested.
64 } 67 DIMENSIONS: {
65 var t = this._deviceType(device); 68 type: Array,
66 var a = ANDROID_ALIASES[t]; 69 value: function(){
67 if (!a) { 70 return ["android_devices", "cores", "cpu", "device_type",
68 return "UNKNOWN"; 71 "device_os", "gpu", "id", "os", "pool"];
69 } 72 },
70 return a; 73 },
74 DIMENSIONS_WITH_ALIASES: {
75 type: Array,
76 value: function(){
77 return ["device_type", "gpu"];
78 },
79 },
80 BOT_PROPERTIES: {
81 type: Array,
82 value: function() {
83 return ["disk_space", "task", "status"];
84 }
85 },
86 },
87
88 _androidAlias: function(dt) {
89 return ANDROID_ALIASES[dt] || UNKNOWN;
71 }, 90 },
72 91
73 // _applyAlias is the consistent way to modify a string to show its alias. 92 // _applyAlias is the consistent way to modify a string to show its alias.
74 _applyAlias: function(orig, alias) { 93 _applyAlias: function(orig, alias) {
75 return alias +" ("+orig+")"; 94 return alias +" ("+orig+")";
76 }, 95 },
77 96
78 _cores: function(bot) { 97 // _attribute looks first in dimension and then in state for the
79 // For whatever reason, sometimes cores are in dimensions and sometimes 98 // specified attribute. This will always return an array. If there is
80 // they are in state, but never both. 99 // no matching attribute, ["unknown"] will be returned.
81 var c = (bot && bot.state && bot.state.cores); 100 _attribute: function(bot, attr, none) {
82 if (c && c.length > 0) { 101 none = none || UNKNOWN;
83 return c; 102 return this._dimension(bot, attr) || this._state(bot, attr) || [none];
84 }
85 c = this._dimension(bot, "cores") || ["Unknown"];
86 return c;
87 }, 103 },
88 104
89 _devices: function(bot) { 105 _devices: function(bot) {
90 var devices = []; 106 var devices = [];
91 var d = (bot && bot.state && bot.state.devices) || {}; 107 var d = (bot && bot.state && bot.state.devices) || {};
92 // state.devices is like {Serial:Object}, so we need to keep the serial 108 // state.devices is like {Serial:Object}, so we need to keep the serial
93 for (key in d) { 109 for (key in d) {
94 var o = d[key]; 110 var o = d[key];
95 o.serial = key; 111 o.serial = key;
96 o.okay = (o.state === AVAILABLE); 112 o.okay = (o.state === AVAILABLE);
97 devices.push(o); 113 devices.push(o);
98 } 114 }
99 return devices; 115 return devices;
100 }, 116 },
101 117
102 // _deviceType returns the codename of a given Android device. 118 // _deviceType returns the codename of a given Android device.
103 _deviceType: function(device) { 119 _deviceType: function(device) {
104 if (!device || !device.build) { 120 if (!device || !device.build) {
105 return "unknown"; 121 return UNKNOWN;
106 } 122 }
107 var t = device.build["build.product"] || device.build["product.board"] | | 123 var t = device.build["build.product"] || device.build["product.board"] | |
108 device.build["product.device"] || "unknown"; 124 device.build["product.device"] || UNKNOWN;
109 return t.toLowerCase(); 125 return t.toLowerCase();
110 }, 126 },
111 127
112 // _dimension returns the given dimension of a bot. If it is defined, it 128 // _dimension returns the given dimension of a bot. If it is defined, it
113 // is typically an array of strings. 129 // is an array of strings.
114 _dimension: function(bot, dim) { 130 _dimension: function(bot, dim) {
115 if (!bot || !bot.dimensions || !dim) { 131 if (!bot || !bot.dimensions || !dim) {
116 return undefined; 132 return undefined;
117 } 133 }
118 for (var i = 0; i < bot.dimensions.length; i++) { 134 for (var i = 0; i < bot.dimensions.length; i++) {
119 if (bot.dimensions[i].key === dim) { 135 if (bot.dimensions[i].key === dim) {
120 return bot.dimensions[i].value; 136 return bot.dimensions[i].value;
121 } 137 }
122 } 138 }
123 return undefined; 139 return undefined;
124 }, 140 },
125 141
126 _gpuAlias: function(gpu) { 142 _gpuAlias: function(gpu) {
127 var a = GPU_ALIASES[gpu]; 143 return GPU_ALIASES[gpu] || UNKNOWN;
128 if (!a) {
129 return "UNKNOWN";
130 }
131 return a;
132 }, 144 },
133 145
134 _not: function(a) { 146 _not: function(a) {
135 return !a; 147 return !a;
136 }, 148 },
137 149
138 _or: function() { 150 _or: function() {
139 var result = false; 151 var result = false;
140 // can't use .foreach, as arguments isn't really a function. 152 // can't use .foreach, as arguments isn't really a function.
141 for (var i = 0; i < arguments.length; i++) { 153 for (var i = 0; i < arguments.length; i++) {
142 result = result || arguments[i]; 154 result = result || arguments[i];
143 } 155 }
144 return result; 156 return result;
145 }, 157 },
146 158
159 // _state returns the requested attribute from a bot's state.
160 // For consistency with _dimension, if the attribute is not an array,
161 // it is put as the only element in an array.
162 _state: function(bot, attr) {
163 if (!bot || !bot.state || !bot.state[attr]) {
164 return undefined
165 }
166 var state = bot.state[attr];
167 if (Array.isArray(state)) {
168 return state;
169 }
170 return [state];
171 },
172
147 _taskId: function(bot) { 173 _taskId: function(bot) {
148 if (bot && bot.task_id) { 174 if (bot && bot.task_id) {
149 return bot.task_id; 175 return bot.task_id;
150 } 176 }
151 return "idle"; 177 return "idle";
152 }, 178 },
153 179
154 // _unalias will return the base dimension/state with its alias removed 180 // _unalias will return the base dimension/state with its alias removed
155 // if it had one. This is handy for sorting and filtering. 181 // if it had one. This is handy for sorting and filtering.
156 _unalias: function(str) { 182 _unalias: function(str) {
157 var match = ALIAS_REGEXP.exec(str); 183 var match = ALIAS_REGEXP.exec(str);
158 if (match) { 184 if (match) {
159 return match[1]; 185 return match[1];
160 } 186 }
161 return str; 187 return str;
162 }, 188 },
163 } 189 }
164 })() 190 })()
165 </script> 191 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698