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

Side by Side Diff: appengine/swarming/elements/res/imp/botpage/bot-page-data.html

Issue 2291323002: Introduce new bot-page UI (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-py@bot-page
Patch Set: Fix some query glitches Created 4 years, 3 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-page-data> 9 <bot-page-data>
10 10
(...skipping 14 matching lines...) Expand all
25 25
26 Methods: 26 Methods:
27 request(): Force a fetch of the data. This happens automatically when 27 request(): Force a fetch of the data. This happens automatically when
28 auth_headers is set or bot_id is changed. 28 auth_headers is set or bot_id is changed.
29 29
30 Events: 30 Events:
31 None. 31 None.
32 --> 32 -->
33 33
34 34
35 <link rel="import" href="/res/imp/common/common-behavior.html"> 35 <link rel="import" href="bot-page-shared-behavior.html">
36 36
37 <dom-module id="bot-page-data"> 37 <dom-module id="bot-page-data">
38 <script> 38 <script>
39 (function(){ 39 (function(){
40 // Time to wait before requesting a new bot. This is to allow a user to
41 // type in a name and not have it make one set of requests for each
42 // keystroke.
43 var BOT_ID_DEBOUNCE_MS = 400;
44 var lastRequest;
45
46 var BOT_TIMES = ["first_seen_ts", "last_seen_ts"];
47 var TASK_TIMES = ["started_ts", "completed_ts", "abandoned_ts", "modified_ts "];
40 48
41 Polymer({ 49 Polymer({
42 is: 'bot-page-data', 50 is: 'bot-page-data',
43 51
44 behaviors: [ 52 behaviors: [
45 SwarmingBehaviors.CommonBehavior, 53 SwarmingBehaviors.BotPageBehavior,
46 ], 54 ],
47 55
48 properties: { 56 properties: {
49 // inputs 57 // inputs
50 auth_headers: { 58 auth_headers: {
51 type: Object, 59 type: Object,
52 }, 60 },
53 bot_id: { 61 bot_id: {
54 type: String, 62 type: String,
55 }, 63 },
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 type: Object, 107 type: Object,
100 }, 108 },
101 }, 109 },
102 110
103 observers: [ 111 observers: [
104 "request(auth_headers,bot_id)", 112 "request(auth_headers,bot_id)",
105 ], 113 ],
106 114
107 request: function(){ 115 request: function(){
108 if (!this.bot_id || !this.auth_headers) { 116 if (!this.bot_id || !this.auth_headers) {
109 console.log("bot_id and auth_headers can't be empty");
110 return; 117 return;
111 } 118 }
112 var baseUrl = "/_ah/api/swarming/v1/bot/"+this.bot_id; 119 if (lastRequest) {
113 this._getJsonAsync("_bot", baseUrl + "/get", 120 clearTimeout(lastRequest);
114 "_busy1", this.auth_headers); 121 }
115 // We limit the fields on these two queries to make them faster. 122
116 this._getJsonAsync("_events", 123 lastRequest = setTimeout(function(){
stephana 2016/09/01 15:16:18 IMO the Polymer async method is preferrable, i.e.
kjlubick 2016/09/01 17:24:08 I did not know about Polymer's async. Thanks!
117 baseUrl + "/events?fields=items(event_type%2Cmessage%2Cquarantined%2Ct ask_id%2Cts%2Cversion)", 124 lastRequest = undefined;
118 "_busy2", this.auth_headers); 125 var baseUrl = "/_ah/api/swarming/v1/bot/"+this.bot_id;
119 this._getJsonAsync("_tasks", 126 this._getJsonAsync("_bot", baseUrl + "/get",
120 baseUrl + "/tasks?fields=items(abandoned_ts%2Cbot_version%2Ccompleted_ ts%2Cduration%2Cexit_code%2Cfailure%2Cinternal_failure%2Cmodified_ts%2Cname%2Cst arted_ts%2Cstate%2Ctask_id%2Ctry_number)", 127 "_busy1", this.auth_headers);
121 "_busy3", this.auth_headers); 128 // We limit the fields on these two queries to make them faster.
129 this._getJsonAsync("_events",
130 baseUrl + "/events?fields=items(event_type%2Cmessage%2Cquarantined%2 Ctask_id%2Cts%2Cversion)",
131 "_busy2", this.auth_headers);
132 this._getJsonAsync("_tasks",
133 baseUrl + "/tasks?fields=items(abandoned_ts%2Cbot_version%2Ccomplete d_ts%2Cduration%2Cexit_code%2Cfailure%2Cinternal_failure%2Cmodified_ts%2Cname%2C started_ts%2Cstate%2Ctask_id%2Ctry_number)",
134 "_busy3", this.auth_headers);
135 }.bind(this), BOT_ID_DEBOUNCE_MS);
136
122 }, 137 },
123 138
124 _parseBot: function(bot) { 139 _parseBot: function(bot) {
125 if (!bot) { 140 if (!bot) {
126 return {}; 141 return {};
127 } 142 }
143 // Do any preprocessing here
144 bot.state = bot.state || "{}";
145 bot.state = JSON.parse(bot.state);
146
147 // get the disks in an easier to deal with format, sorted by size.
148 var disks = bot.state.disks || {};
149 var keys = Object.keys(disks);
150 if (!keys.length) {
151 bot.disks = [{"id": "unknown", "mb": 0}];
152 } else {
153 bot.disks = [];
154 for (var i = 0; i < keys.length; i++) {
155 bot.disks.push({"id":keys[i], "mb":disks[keys[i]].free_mb});
156 }
157 // Sort these so the biggest disk comes first.
158 bot.disks.sort(function(a, b) {
159 return b.mb - a.mb;
160 });
161 }
162
163 // Date.toString() looks like "Mon Aug 29 2016 09:03:41 GMT-0400 (EDT)"
164 // we want to extract the time zone part and append it to the
165 // locale time.
stephana 2016/09/01 15:16:18 This seems something that the Date object should p
kjlubick 2016/09/01 17:24:08 The Date Object will only give me the TimeZoneOffs
166 var str = (new Date()).toString();
167 var timeZone = str.substring(str.indexOf("("))
168
169 BOT_TIMES.forEach(function(time) {
170 if (bot[time]) {
171 bot[time] = new Date(bot[time]);
172 var locale = bot[time].toLocaleString();
173 bot["human_"+time] = locale + " " + timeZone;
174 }
175 });
128 return bot; 176 return bot;
129 }, 177 },
130 178
131 _parseEvents: function(events) { 179 _parseEvents: function(events) {
132 if (!events || !events.items) { 180 if (!events || !events.items) {
133 return []; 181 return [];
134 } 182 }
135 return events.items; 183 var events = events.items;
184 var str = (new Date()).toString();
185 var timeZone = str.substring(str.indexOf("("))
186 events.forEach(function(event){
187 // Do any preprocessing here
188 if (event.ts) {
189 event.ts = new Date(event.ts);
190 var locale = event.ts.toLocaleString();
191 event.human_ts = locale + " " + timeZone;
192 }
193 });
194
195 // Sort the most recent events first.
196 events.sort(function(a,b) {
197 return b.ts - a.ts;
198 });
199
200 return events;
136 }, 201 },
137 202
138 _parseTasks: function(tasks) { 203 _parseTasks: function(tasks) {
139 if (!tasks || !tasks.items) { 204 if (!tasks || !tasks.items) {
140 return []; 205 return [];
141 } 206 }
142 return tasks.items; 207 var tasks = tasks.items;
208
209 // Date.toString() looks like "Mon Aug 29 2016 09:03:41 GMT-0400 (EDT)"
210 // we want to extract the time zone part and append it to the
211 // locale time.
212 var str = (new Date()).toString();
213 var timeZone = str.substring(str.indexOf("("))
stephana 2016/09/01 15:16:18 Same as above. Instead of copying the code there s
kjlubick 2016/09/01 17:24:08 Done. Created formatDate();
214 tasks.forEach(function(task){
215 // Do any preprocessing here
216 TASK_TIMES.forEach(function(time) {
217 if (task[time]) {
218 task[time] = new Date(task[time]);
219 var locale = task[time].toLocaleString();
220 task["human_"+time] = locale + " " + timeZone;
221 }
222 });
223
224
225 if (task.duration) {
226 task.human_duration = sk.human.strDuration(task.duration) || "0s";
227 } else {
228 var end = task.completed_ts || task.abandoned_ts || task.modified_ts || new Date();
229 task.human_duration = this._timeDiffExact(task.started_ts, end);
230 }
231
232 task.state = task.state || "UNKNOWN";
233 if (task.state === "COMPLETED") {
234 if (task.failure) {
235 task.state = "FAILURE";
236 } else {
237 task.state = "SUCCESS";
238 }
239 }
240
241 }.bind(this));
242
243 // Sort the most recent tasks first.
244 tasks.sort(function(a,b) {
245 return b.started_ts - a.started_ts;
246 });
247
248 return tasks;
143 } 249 }
144 250
145 }); 251 });
146 })(); 252 })();
147 </script> 253 </script>
148 </dom-module> 254 </dom-module>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698