 Chromium Code Reviews
 Chromium Code Reviews Issue 2182693002:
  Add new botlist for swarming  (Closed) 
  Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-py@app-wrapper
    
  
    Issue 2182693002:
  Add new botlist for swarming  (Closed) 
  Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-py@app-wrapper| Index: appengine/swarming/elements/res/imp/botlist/bot-list-shared.html | 
| diff --git a/appengine/swarming/elements/res/imp/botlist/bot-list-shared.html b/appengine/swarming/elements/res/imp/botlist/bot-list-shared.html | 
| new file mode 100644 | 
| index 0000000000000000000000000000000000000000..a1bf385156337c505d8e2222f77b598e1986cb9f | 
| --- /dev/null | 
| +++ b/appengine/swarming/elements/res/imp/botlist/bot-list-shared.html | 
| @@ -0,0 +1,152 @@ | 
| +<!-- | 
| + Copyright 2016 The LUCI Authors. All rights reserved. | 
| + Use of this source code is governed under the Apache License, Version 2.0 | 
| + that can be found in the LICENSE file. | 
| + | 
| + window.SwarmingBehaviors.BotListBehavior contains any shared functions and | 
| + constants used by the bot-list and its sub-elements. | 
| + | 
| + To use it, include | 
| + behaviors: [SwarmingBehaviors.BotListBehavior] | 
| + in the creation of your Polymer element. | 
| +--> | 
| +<script> | 
| + | 
| + window.SwarmingBehaviors = window.SwarmingBehaviors || {}; | 
| 
stephana
2016/07/29 14:09:31
IMO this should go into a pure JS file. Behaviors
 
kjlubick
2016/07/29 19:13:25
From the docs:
"Polymer supports extending custom
 | 
| + (function(){ | 
| + var ANDROID_ALIASES = { | 
| + "bullhead": "Nexus 5X", | 
| + "flo": "Nexus 7", | 
| + "hammerhead": "Nexus 5", | 
| + "mako": "Nexus 4", | 
| + "shamu": "Nexus 6", | 
| + }; | 
| + // Taken from http://developer.android.com/reference/android/os/BatteryManager.html | 
| + var BATTERY_HEALTH_UNKNOWN = 1; | 
| + var BATTERY_HEALTH_GOOD = 2; | 
| + var BATTERY_STATUS_CHARGING = 2; | 
| + | 
| + var UNAUTHENTICATED = "unauthenticated"; | 
| + var AVAILABLE = "available"; | 
| + | 
| + var GPU_ALIASES = { | 
| + "1002": "AMD", | 
| + "1002:6779": "AMD Radeon HD 6450/7450/8450", | 
| + "1002:6821": "AMD Radeon HD 8870M", | 
| + "102b": "Matrox", | 
| + "102b:0522": "Matrox MGA G200e", | 
| + "102b:0532": "Matrox MGA G200eW", | 
| + "102b:0534": "Matrox G200eR2", | 
| + "10de": "NVIDIA", | 
| + "10de:08aa": "NVIDIA GeForce 320M", | 
| + "10de:0fe9": "NVIDIA GeForce GT 750M Mac Edition", | 
| + "10de:104a": "NVIDIA GeForce GT 610", | 
| + "10de:11c0": "NVIDIA GeForce GTX 660", | 
| + "10de:1244": "NVIDIA GeForce GTX 550 Ti", | 
| + "10de:1401": "NVIDIA GeForce GTX 960", | 
| + "8086": "Intel", | 
| + "8086:041a": "Intel Xeon Integrated", | 
| + "8086:0a2e": "Intel Haswell Integrated", | 
| + "8086:0d26": "Intel Crystal Well Integrated", | 
| + } | 
| + | 
| + // For consistency, all aliases are displayed like: | 
| + // Nexus 5X (bullhead) | 
| + // This regex matches a string like "ALIAS (ORIG)", with ORIG as group 1. | 
| + var ALIAS_REGEXP = /.+ \((.*)\)/; | 
| + | 
| + // This behavior wraps up all the shared bot-list functionality. | 
| + SwarmingBehaviors.BotListBehavior = { | 
| + | 
| + _androidAlias: function(device) { | 
| + if (device.notReady) { | 
| + return UNAUTHENTICATED.toUpperCase(); | 
| + } | 
| + var t = this._deviceType(device); | 
| + var a = ANDROID_ALIASES[t]; | 
| + if (!a) { | 
| + return "UNKNOWN"; | 
| + } | 
| + return a; | 
| + }, | 
| + | 
| + // _applyAlias is the consistent way to modify a string to show its alias. | 
| + _applyAlias: function(orig, alias) { | 
| + return alias +" ("+orig+")"; | 
| + }, | 
| + | 
| + _cores: function(bot) { | 
| + // For whatever reason, sometimes cores are in dimensions and sometimes | 
| + // they are in state, but never both. | 
| + var c = (bot && bot.state && bot.state.cores); | 
| + if (c && c.length > 0) { | 
| + return c; | 
| + } | 
| + c = this._dimension(bot, "cores") || ["Unknown"]; | 
| + return c; | 
| + }, | 
| + | 
| + _devices: function(bot) { | 
| + var devices = []; | 
| + var d = (bot && bot.state && bot.state.devices) || {}; | 
| + // state.devices is like {Serial:Object}, so we need to keep the serial | 
| + for (key in d) { | 
| + var o = d[key]; | 
| + o.serial = key; | 
| + o.okay = (o.state === AVAILABLE); | 
| + devices.push(o); | 
| + } | 
| + return devices; | 
| + }, | 
| + | 
| + // _deviceType returns the codename of a given Android device. | 
| + _deviceType: function(device) { | 
| + if (!device || !device.build) { | 
| + return "unknown"; | 
| + } | 
| + var t = device.build["build.product"] || device.build["product.board"] || | 
| + device.build["product.device"] || "unknown"; | 
| + return t.toLowerCase(); | 
| + }, | 
| + | 
| + // _dimension returns the given dimension of a bot. If it is defined, it | 
| + // is typically an array of strings. | 
| + _dimension: function(bot, dim) { | 
| + if (!bot || !bot.dimensions || !dim) { | 
| + return undefined; | 
| + } | 
| + for (var i = 0; i < bot.dimensions.length; i++) { | 
| + if (bot.dimensions[i].key === dim) { | 
| + return bot.dimensions[i].value; | 
| + } | 
| + } | 
| + return undefined; | 
| + }, | 
| + | 
| + _gpuAlias: function(gpu) { | 
| + var a = GPU_ALIASES[gpu]; | 
| + if (!a) { | 
| + return "UNKNOWN"; | 
| + } | 
| + return a; | 
| + }, | 
| + | 
| + _taskId: function(bot) { | 
| + if (bot && bot.task_id) { | 
| + return bot.task_id; | 
| + } | 
| + return "idle"; | 
| + }, | 
| + | 
| + // _unalias will return the base dimension/state with its alias removed | 
| + // if it had one. This is handy for sorting and filtering. | 
| + _unalias: function(str) { | 
| + var match = ALIAS_REGEXP.exec(str); | 
| + if (match) { | 
| + return match[1]; | 
| + } | 
| + return str; | 
| + }, | 
| + } | 
| + })() | 
| +</script> |