forked from kgyrtkirk/hive-toolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtoolbox.user.js
326 lines (284 loc) · 10.5 KB
/
toolbox.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
// ==UserScript==
// @name hu.rxd.hive.toolbox
// @namespace http://tampermonkey.net/
// @version 0.7
// @description adds some things...
// @author kirk
// @match https://issues.apache.org/jira/browse/**
// @match https://builds.apache.org/job/PreCommit-HIVE-Build/*/testReport/
// @match http://sustaining-jenkins.eng.hortonworks.com:8080/**/*hive*/*/testReport/**
// @grant GM_getValue
// @grant GM_setValue
// @run-at document-idle
// @require http://code.jquery.com/jquery-latest.js
// @require https://bowercdn.net/c/urijs-1.19.1/src/URI.min.js
// ==/UserScript==
(function() {
'use strict';
// credit: https://stackoverflow.com/a/4673436/1525291
if (!String.prototype.format) {
String.prototype.format = function() {
var args = arguments;
return this.replace(/{(\d+)}/g, function(match, number) {
return typeof args[number] != 'undefined'
? args[number]
: match
;
});
};
}
function addCustomStyle() {
var style = $(`<style>
.toolbox_button {
color: blue;
xbackground-color: lightblue;
border: 1px solid lightblue;
margin:-1px;
margin-left:1px;
margin-right: 5px;
min-width:1em;
text-align: center;
text-decoration: none !IMPORTANT;
display: inline-block;
}
.toolbox_button:hover {
background-color: lightblue;
}
.ptest-status {
display:block;
float:right;
background-color1:orange;
border: 1px solid orange;
font-size:2em;
}
</style>
`);
$('html > head').append(style);
}
//$("a[title='Show details']").css( "border", "3px double red" );
function createLink(label,link){
var newLink=$("<a>", {
title: label,
href: link,
class: "toolbox_button"
}).append( label );
return newLink;
}
function jiraSearch(jql){
var args = {
jql:jql
};
var uri=URI('https://issues.apache.org/jira/issues/').search(args);
return uri;
}
function relatedTicketsSearch(testInfo) {
var kwPart=testInfo.keywords.map(function(kw) {
return ' ( summary ~ "{0}" or description ~ "{0}" or description ~ "{0}.q" )'.format(kw);
}).join("\n and ");
return jiraSearch(kwPart + "\nand project = hive order by updated desc");
}
function getTestOpts(testInfo) {
// FIXME: possibly remove mavenPattern from testInfo
// ultimate: https://api.github.com/search/code?q=filename:TestCliDriver.java+repo:apache/hive
var testOpts='-Dtest={0}'.format(testInfo.mavenPattern);
if(testInfo.testClassFull.toLowerCase().indexOf("spark") == -1) {
testOpts+="\n-DskipSparkTests";
}
switch(testInfo.testClass){
case "TestCliDriver":
case "TestNegativeCliDriver":
case "TestMiniLlapCliDriver":
case "TestMiniLlapLocalCliDriver":
testOpts+="\n-pl itests/qtest";
break;
default:
}
return testOpts;
}
function buildJobInvocationUri(jobName,testInfo) {
var testOpts=getTestOpts(testInfo);
var args={
KEYWORD: 'R[{0}]'.format(testInfo.mavenPattern),
M_TEST_OPTS: testOpts
};
var u=URI('http://sustaining-jenkins.eng.hortonworks.com:8080/view/hive/job/{0}/parambuild/'.format(jobName)).search(args);
return u;
}
function createTestInfo(txt){
var ret={};
var tparts=txt.split(".");
ret.keywords=[];
ret.testMethod=tparts.pop();
ret.testClassFull=tparts.join(".");
ret.testClass=tparts.pop();
ret.mavenPattern='{0}#{1}'.format(ret.testClass,ret.testMethod);
ret.keywords.push(ret.testClass);
var p = ret.testMethod.replace("]","").split(/\[/);
if(p.size() == 2 ){
ret.testParam=p.last();
ret.keywords.push(ret.testParam);
}
return ret;
}
// $("tr:has( > td > a[title='Show details'])").css( "border", "3px double green" );
function processFailureRow(row){
// $(row).css( "border", "3px double brown" );
var testLink=$(row).find("td:first-child a[href]");
var testInfo=createTestInfo(testLink.text());
var newLinks=[
createLink("L",relatedTicketsSearch(testInfo)),
createLink("R",buildJobInvocationUri('hive-check',testInfo)),
createLink("B",buildJobInvocationUri('hive-bisect',testInfo)),
];
newLinks.each(function (item) {
item.insertBefore(testLink);
});
// testLink.css( "border", "3px double blue" );
}
function decorateJenkinsResults() {
$("tr:has( > td > a[title='Show details'])").each( function() {
processFailureRow(this);
});
}
function collapseQAComments(){
$(".activity-comment:has(a[rel=hiveqa]):not(:last)")
.removeClass("extended")
.addClass("collapsed");
}
function fixAttachmentSortOrder() {
var p=$('ol:has(>li.attachment-content)');
$('li.attachment-content').sort(function (a, b) {
var contentA =parseInt($(a).attr('data-attachment-id'));
var contentB =parseInt($(b).attr('data-attachment-id'));
console.log(contentA);
return (contentA-contentB);
}).appendTo(p);
}
function getAttachments() {
return $('li.attachment-content').map( function() {
return {
name:$(this).find("a").text(),
time:$(this).find('time').attr('datetime'),
attachmentId:parseInt($(this).attr('data-attachment-id')),
url:$(this).find("a").attr('href'),
}; } ).sort(function(a,b) { return + a.attachmentId - b.attachmentId; });
}
function extractTicketId(str){
var cand=str.replace(/.*\//,'');
if(cand.match(/^[A-Z]+-[0-9]+$/) != null)
return cand;
return null;
}
function buildReExecJobInvocationUri(branch,qaInfo,patchUrl) {
var jobName="hive-ptest-rerun";
var args={
KEYWORD: 'R[{2}@{0}@{1}]'.format(patchUrl.match(/[^\/]+$/),branch,ticketId),
PTEST_JOB_URL: qaInfo.buildUrl,
PATCH_URL: patchUrl,
};
// alert(args.KEYWORD);
var u=URI('http://sustaining-jenkins.eng.hortonworks.com:8080/view/hive/job/{0}/parambuild/'.format(jobName)).search(args);
return u;
}
function decorateLastQA() {
var c=$(".activity-comment:has(a[rel=hiveqa]):last");
var qaInfo={
patchUrl: c.find("a.external-link:contains('/attachment/')").text(),
buildUrl: c.find("a.external-link:contains('/job/')").last().text().match(/.*\/[0-9]+/)+"/"
};
if(c.size() == 0 )
return;
var c2=c.find(".preformatted");
// c2.css( "border", "3px double red" );
createLink("re-run with patch",buildReExecJobInvocationUri("apache/master",qaInfo,qaInfo.patchUrl)).insertAfter(c2);
createLink("re-run at master",buildReExecJobInvocationUri("apache/master",qaInfo,"")).insertAfter(c2);
}
function cachedGet(cacheTime, cacheLabel, url, fnOk, fnFail) {
var ttlKey='cache.ttl.'+cacheLabel;
var dataKey='cache.data.'+cacheLabel;
var ttl=Number(GM_getValue(ttlKey));
var data=GM_getValue(dataKey);
var now=Date.now();
if(Number.isNaN(ttl) || now > ttl) {
$.get( url, function (data) {
GM_setValue(ttlKey, now+cacheTime);
GM_setValue(dataKey, data);
fnOk(data);
}, null, "text").fail(fnFail);
} else {
console.log("serving "+url+" from cache");
console.log(data);
fnOk(data);
}
}
function showQueueStatus(ticketId){
var id=ticketId.replace(/^[^0-9]+/,"");
var url="https://builds.apache.org/queue/api/xml?tree=items[actions[parameters[name,value]],task[name]]";
cachedGet(600*1000, "apache.queue",url,
function(data) {
document.apacheQueueData=data;
var hiveQueue=$(document.apacheQueueData)
.find("item")
.filter(
function (idx,e) {
return $(e).find("name").text().match(/HIVE/);
});
var hiveInfos=hiveQueue.map( function (idx,queueItem) {
return $(queueItem).find("parameter")
.map(function (idx,u) {
return [[$(u).find("name").text(),$(u).find("value").text()]];
}).toArray().reduce(function(map, obj) {
map[obj[0]] = obj[1];
return map;
}, {});
});
document.hiveInfos=hiveInfos;
var qStatus=$('<div id=qStatus>').addClass("ptest-status");
qStatus.insertAfter($('#summary-val'));
hiveInfos.each( function (idx,info) {
var match=info["ISSUE_NUM"]==id;
$("<a>")
.append(match?"■":"□")
.attr("title","HIVE-"+info["ISSUE_NUM"])
.attr("href","https://issues.apache.org/jira/browse/HIVE-"+info["ISSUE_NUM"])
.appendTo(qStatus);
});
qStatus.append($("<br>"));
var issueIdx=document.hiveInfos.toArray().findIndex( function (a) { return a["ISSUE_NUM"] == id;});
var statusStr;
if(issueIdx>=0) {
statusStr="Q: "+(issueIdx+1)+" / " +hiveInfos.size();
}else{
statusStr="[N/A] / "+ +hiveInfos.size();
}
$('<span>')
.append(statusStr)
.appendTo(qStatus);
},function() {
$('<span>')
.addClass("ptest-status")
.append("xxx")
.insertAfter($('#summary-val'));
});
}
var ticketId;
function go(){
ticketId = extractTicketId(window.location.pathname);
addCustomStyle();
decorateJenkinsResults();
collapseQAComments();
fixAttachmentSortOrder();
decorateLastQA();
console.log("ticketId:"+ticketId);
if(ticketId != null && ticketId.startsWith("HIVE")) {
showQueueStatus(ticketId);
}
}
/*
window.addEventListener("load", init, false);
function init() {
setTimeout(go, 500, document.body);
}
*/
go();
})();