joblist.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  1. /*##############################################################################
  2. # HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems®.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. ############################################################################## */
  16. var labelPopup = null;
  17. function format2(n)
  18. {
  19. return new String(Math.floor(n/10))+ new String(n%10);
  20. }
  21. // magic function from http://www.merlyn.demon.co.uk/zeller-c.htm
  22. function ZCMJD(y, m, d)
  23. {
  24. if (m<3) { m += 12 ; y-- }
  25. return -678973 + d + (((153*m-2)/5)|0) + 365*y + ((y/4)|0) - ((y/100)|0) + ((y/400)|0);
  26. }
  27. function formatUTC(d)
  28. {
  29. var dt=new Date(d);
  30. if(isNaN(dt)) return null;
  31. return (dt.getUTCFullYear()>1950 ? dt.getUTCFullYear() : dt.getUTCFullYear()+100)+'-'+
  32. format2(dt.getUTCMonth()+1)+'-'+
  33. format2(dt.getUTCDate())+'T'+
  34. format2(dt.getUTCHours())+':'+
  35. format2(dt.getUTCMinutes())+':'+
  36. format2(dt.getUTCSeconds())+'Z';
  37. }
  38. function formatShortDate(dt)
  39. {
  40. var re=dt.toString().match(/(\S+)\s+(\S+)\s+(\d+)/i);
  41. if(!re) return '';
  42. return re[1]+', '+re[2]+' '+re[3];
  43. }
  44. function parseUTC(d)
  45. {
  46. var re=new String(d).match(/(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})Z?/);
  47. if (!re) return null;
  48. return Date.UTC(re[1],re[2]-1,re[3],re[4],re[5],re[6]);
  49. }
  50. function reload_graph(src)
  51. {
  52. var svg0=document.getElementById('SVG0');
  53. //var svgdoc0=svg0.getSVGDocument();
  54. if (svg0 == null)
  55. return;
  56. var svgdoc0 = null;
  57. if (svg0.contentDocument != null) {
  58. svgdoc0 = svg0.contentDocument;
  59. }
  60. else if (typeof svg0.getSVGDocument != 'undefined') {
  61. svgdoc0 = svg0.getSVGDocument();
  62. }
  63. if (svgdoc0 == null) {
  64. return;
  65. }
  66. if(svgdoc0.rootElement && svgdoc0.rootElement.firstChild) {
  67. svgdoc0.rootElement.removeChild(svgdoc0.rootElement.firstChild);
  68. }
  69. var svg=document.getElementById('SVG');
  70. svg.style.width=1;
  71. svg.style.height=1;
  72. var svgdoc=svg.getSVGDocument();
  73. if(svgdoc.rootElement.firstChild)
  74. svgdoc.rootElement.removeChild(svgdoc.rootElement.firstChild);
  75. document.getElementById('loader').src=src;
  76. displayProgress('Querying dali ...');
  77. }
  78. function show_popup(evt,wuid,graph,started,finished,finishTime,cluster)
  79. {
  80. var svg=document.getElementById('SVG');
  81. if(!svg) return;
  82. var x = evt.screenX, y = evt.screenY;
  83. var d=Math.floor(parseUTC(finished)-parseUTC(started))/1000,
  84. h=Math.floor(d/3600),
  85. m1=d-h*3600,
  86. m=Math.floor(m1/60),
  87. s=m1-m*60;
  88. var src='<table id="tab" style="font:menu"><colgroup><col align="left" valign="top"/></colgroup>'+
  89. '<tr><th>Wuid</th><td>'+wuid+'</td></tr>'+
  90. '<tr><th>Graph</th><td>'+graph+'</td></tr>'+
  91. '<tr><th>Cluster</th><td>'+cluster+'</td></tr>'+
  92. '<tr><th>Started</th><td>'+started+'</td></tr>'+
  93. '<tr><th>Finished</th><td>'+finishTime+'</td></tr>'+
  94. '<tr><th>Time</th><td>'+(h ? h+'h ':'')+(m ? m+'m ' : '')+(s +'s')+'</td></tr></table>';
  95. if (typeof window.createPopup != 'undefined')
  96. {
  97. var xp=x+svg.offsetLeft-document.body.scrollLeft+window.screenLeft-50,
  98. yp=y+svg.offsetTop-document.body.scrollTop+window.screenTop+200;
  99. labelPopup=window.createPopup();
  100. var popupBody=labelPopup.document.body;
  101. popupBody.style.backgroundColor = "yellow";
  102. popupBody.style.border = "outset black 2px";
  103. popupBody.innerHTML=src;
  104. labelPopup.show(xp,yp,400,100,null);
  105. var w=labelPopup.document.getElementById('tab').clientWidth+5,
  106. h=labelPopup.document.getElementById('tab').clientHeight+5;
  107. labelPopup.show(xp,yp,w,h,null);
  108. }
  109. else
  110. {
  111. var xp=x+svg.offsetLeft+document.body.scrollLeft-window.screenX-280, //- 180 - 100
  112. yp=y+svg.offsetTop+document.body.scrollTop-window.screenY-370; //- 250 - 120
  113. labelPopup = new YAHOO.widget.Panel("labelPanel", { width:"200px", height:"120px",
  114. visible:true, constraintoviewport:true, close:false,
  115. xy: [xp, yp]
  116. } );
  117. labelPopup.setBody(src);
  118. labelPopup.render(document.body);
  119. labelPopup.show();
  120. }
  121. }
  122. function close_popup()
  123. {
  124. if(labelPopup)
  125. {
  126. if (typeof labelPopup.destroy != 'undefined')
  127. {
  128. labelPopup.destroy();
  129. }
  130. else if (typeof labelPopup.close != 'undefined')
  131. {
  132. labelPopup.close();
  133. }
  134. else
  135. labelPopup.hide();
  136. labelPopup=null;
  137. }
  138. }
  139. function open_workunit(wuid)
  140. {
  141. var wu_window = window.open('/WsWorkunits/WUInfo?Wuid=' + wuid,
  142. 'Workunit', 'location=0,status=1,scrollbars=1,resizable=1,width=500,height=600');
  143. wu_window.opener = window;
  144. wu_window.focus();
  145. }
  146. var fromDate=null, toDate=null;
  147. var usageArray=null;
  148. var busagAarray = null;
  149. var nbusageArray = null;
  150. var totalWorkunits=0;
  151. var showAllStat = true;
  152. var numberOfDays = 0;
  153. function displayProgress(status)
  154. {
  155. document.getElementById('progress').innerHTML=status;
  156. }
  157. function initStat()
  158. {
  159. usageArray=new Array(numberOfDays);
  160. busageArray=new Array(numberOfDays);
  161. nbusageArray=new Array(numberOfDays);
  162. for(var i=0;i<numberOfDays;i++)
  163. {
  164. usageArray[i] = 0;
  165. busageArray[i] = 0;
  166. nbusageArray[i] = 0;
  167. }
  168. }
  169. function displayBegin(from,to,showall)
  170. {
  171. fromDate=new Date(parseUTC(from)),
  172. toDate=new Date(parseUTC(to));
  173. var first=ZCMJD(fromDate.getFullYear(),fromDate.getMonth() + 1,fromDate.getDate());
  174. var last=ZCMJD(toDate.getFullYear(),toDate.getMonth() + 1,toDate.getDate());
  175. var count=last-first+1;
  176. numberOfDays = count;
  177. showAllStat = showall;
  178. initStat();
  179. totalWorkunits=0;
  180. var svg=document.getElementById('SVG');
  181. var svgdoc=svg.getSVGDocument();
  182. var g1=svgdoc.createElementNS("http://www.w3.org/2000/svg", "g");
  183. g1.setAttribute("transform","translate(120,20) scale(25,20)");
  184. g1.setAttribute("id","top");
  185. var g=svgdoc.createElementNS("http://www.w3.org/2000/svg", "g");
  186. g.setAttribute("stroke-width","0.01");
  187. g.setAttribute("stroke","black");
  188. g.setAttribute("font-size","0.5");
  189. g.setAttribute("stroke-width","0.01");
  190. g.setAttribute("alignment-baseline","middle");
  191. g.setAttribute("id","toplines");
  192. for(var i=0;i<=count;i++)
  193. {
  194. var today=new Date(fromDate.getFullYear(),fromDate.getMonth(),fromDate.getDate()+i);
  195. if(i<count)
  196. {
  197. var text1=svgdoc.createElementNS("http://www.w3.org/2000/svg", "text");
  198. text1.setAttribute("x",-0.5);
  199. text1.setAttribute("y",i+2.5);
  200. text1.setAttribute("text-anchor","end");
  201. text1.appendChild(svgdoc.createTextNode(formatShortDate(today)));
  202. g.appendChild(text1);
  203. if(today.getDay()==0 || today.getDay()==6)
  204. {
  205. var grey=svgdoc.createElementNS("http://www.w3.org/2000/svg", "line");
  206. grey.setAttribute("x1",0);
  207. grey.setAttribute("y1",i+2.5);
  208. grey.setAttribute("x2",24);
  209. grey.setAttribute("y2",i+2.5);
  210. grey.setAttribute("stroke","#ccc");
  211. grey.setAttribute("stroke-width",1);
  212. g.appendChild(grey);
  213. }
  214. }
  215. var line=svgdoc.createElementNS("http://www.w3.org/2000/svg", "line");
  216. line.setAttribute("x1",0);
  217. line.setAttribute("y1",i+2);
  218. line.setAttribute("x2",24);
  219. line.setAttribute("y2",i+2);
  220. if(i==0 || i==count)
  221. {
  222. line.setAttribute("stroke-width",0.05);
  223. }
  224. g.appendChild(line);
  225. }
  226. for(var i=0;i<=24;i++)
  227. {
  228. var text1=svgdoc.createElementNS("http://www.w3.org/2000/svg", "text");
  229. text1.setAttribute("x",i);
  230. text1.setAttribute("y",1.5);
  231. text1.setAttribute("text-anchor","middle");
  232. text1.appendChild(svgdoc.createTextNode(i));
  233. g.appendChild(text1);
  234. var text2=svgdoc.createElementNS("http://www.w3.org/2000/svg", "text");
  235. text2.setAttribute("x",i);
  236. text2.setAttribute("y",count+2.5);
  237. text2.setAttribute("text-anchor","middle");
  238. text2.appendChild(svgdoc.createTextNode(i));
  239. g.appendChild(text2);
  240. var line=svgdoc.createElementNS("http://www.w3.org/2000/svg", "line");
  241. line.setAttribute("x1",i);
  242. line.setAttribute("y1",2);
  243. line.setAttribute("x2",i);
  244. line.setAttribute("y2",count+2);
  245. if(i==0 || i==24)
  246. {
  247. line.setAttribute("stroke-width",0.05);
  248. }
  249. g.appendChild(line);
  250. }
  251. var gskew = svgdoc.createElementNS("http://www.w3.org/2000/svg", "g");
  252. gskew.setAttribute("transform", "translate(24.5,2) rotate(-45)");
  253. gskew.setAttribute("font-size","0.45");
  254. var text3=svgdoc.createElementNS("http://www.w3.org/2000/svg", "text");
  255. text3.setAttribute("x",0);
  256. text3.setAttribute("y",0);
  257. text3.setAttribute("text-anchor","start");
  258. text3.appendChild(svgdoc.createTextNode("OVERALL"));
  259. gskew.appendChild(text3);
  260. g.appendChild(gskew);
  261. var gskew2 = svgdoc.createElementNS("http://www.w3.org/2000/svg", "g");
  262. gskew2.setAttribute("transform", "translate(25.5,2) rotate(-45)");
  263. gskew2.setAttribute("font-size","0.45");
  264. var text4=svgdoc.createElementNS("http://www.w3.org/2000/svg", "text");
  265. text4.setAttribute("x",0);
  266. text4.setAttribute("y",0);
  267. text4.setAttribute("text-anchor","start");
  268. text4.appendChild(svgdoc.createTextNode("BUSINESS"));
  269. gskew2.appendChild(text4);
  270. g.appendChild(gskew2);
  271. var gskew3 = svgdoc.createElementNS("http://www.w3.org/2000/svg", "g");
  272. gskew3.setAttribute("transform", "translate(26.5,2) rotate(-45)");
  273. gskew3.setAttribute("font-size","0.45");
  274. var text5=svgdoc.createElementNS("http://www.w3.org/2000/svg", "text");
  275. text5.setAttribute("x",0);
  276. text5.setAttribute("y",0);
  277. text5.setAttribute("text-anchor","start");
  278. text5.appendChild(svgdoc.createTextNode("NON-BUSINESS"));
  279. gskew3.appendChild(text5);
  280. g.appendChild(gskew3);
  281. g1.appendChild(g);
  282. svgdoc.rootElement.appendChild(g1);
  283. svgdoc.rootElement.setAttribute("width",896);
  284. svgdoc.rootElement.setAttribute("height",150+20+count*20+40);
  285. svg.style.width=900;
  286. svg.style.height=150+20+count*20+40;
  287. }
  288. var lastjob = '';
  289. var seq = 0;
  290. function displayJob(wuid,graph,started,finished,cluster,state,source,showall,bbtime,betime)
  291. {
  292. var first=ZCMJD(fromDate.getFullYear(),fromDate.getMonth() + 1,fromDate.getDate());
  293. displayProgress('Total: '+(++totalWorkunits)+' graphs');
  294. var from=new Date(Math.max(parseUTC(started),fromDate.getTime())),
  295. to=new Date(Math.min(parseUTC(finished),toDate.getTime()));
  296. if(from>=to) return;
  297. var svg=document.getElementById('SVG');
  298. var svgdoc=svg.getSVGDocument();
  299. var clr;
  300. if(state == 'failed')
  301. clr = 'red';
  302. else if(state == 'not finished')
  303. clr = 'tan';
  304. else if(state == 'archived')
  305. clr = 'black';
  306. else
  307. {
  308. if(wuid != lastjob)
  309. {
  310. lastjob = wuid;
  311. seq = !seq;
  312. }
  313. if(seq)
  314. clr = 'blue';
  315. else
  316. clr = 'darkblue';
  317. }
  318. var finishTime = finished;
  319. if(state == 'not finished')
  320. finishTime = '';
  321. var g=svgdoc.createElementNS("http://www.w3.org/2000/svg", "g");
  322. g.setAttribute("stroke",clr);
  323. g.setAttribute("stroke-width",1);
  324. g.addEventListener("mouseover",function(evt) { show_popup(evt,wuid,graph,started,finished,finishTime,cluster); }, false);
  325. g.addEventListener("mouseout",function(evt) { close_popup(); }, false);
  326. if (source!='sasha')
  327. g.addEventListener("click",function(evt) { open_workunit(wuid); }, false);
  328. var x1=from.getHours()+from.getMinutes()/60+from.getSeconds()/3600,
  329. y1=ZCMJD(from.getFullYear(),from.getMonth() + 1,from.getDate())-first,
  330. x2=to.getHours()+to.getMinutes()/60+to.getSeconds()/3600,
  331. y2=ZCMJD(to.getFullYear(),to.getMonth()+1,to.getDate())-first;
  332. for(var y=y1;y<=y2;y++)
  333. {
  334. var xx1= (y==y1 ? x1 : 0), xx2= (y==y2 ? x2 : 24);
  335. var line=svgdoc.createElementNS("http://www.w3.org/2000/svg", "line");
  336. line.setAttribute("x1",xx1);
  337. line.setAttribute("y1",y+2.5);
  338. line.setAttribute("x2",xx2);
  339. line.setAttribute("y2",y+2.5);
  340. g.appendChild(line);
  341. usageArray[y]+=100*(xx2-xx1)/24;
  342. var bhours = ((betime < xx2)?betime:xx2) - ((bbtime > xx1)?bbtime:xx1);
  343. if(bhours < 0)
  344. bhours = 0;
  345. var nbhours = (xx2 - xx1 - bhours);
  346. if(bbtime + (24 - betime) > 0.001)
  347. nbusageArray[y] += 100*nbhours/(bbtime + (24 - betime));
  348. if(betime - bbtime > 0.001)
  349. busageArray[y] += 100*bhours/(betime - bbtime);
  350. }
  351. svgdoc.getElementById("top").appendChild(g);
  352. }
  353. function displayStat()
  354. {
  355. var svg=document.getElementById('SVG');
  356. var svgDoc=svg.getSVGDocument();
  357. var topLines=svgDoc.getElementById('toplines');
  358. for(var i=0;i<numberOfDays;i++)
  359. {
  360. var usageStr = '';
  361. if(usageArray[i] < 10)
  362. usageStr += ' ';
  363. usageStr += Math.round(usageArray[i])+'%';
  364. if(showAllStat)
  365. usageStr += ' ' + Math.round(busageArray[i])+'% ' + Math.round(nbusageArray[i])+'%';
  366. var text=svgDoc.createElementNS("http://www.w3.org/2000/svg", "text");
  367. text.setAttribute("x",24.2);
  368. text.setAttribute("y",i+2.5);
  369. text.setAttribute("text-anchor","begin");
  370. text.appendChild(svgDoc.createTextNode(usageStr));
  371. topLines.appendChild(text);
  372. }
  373. }
  374. function displayEnd(xls)
  375. {
  376. displayStat();
  377. if (totalWorkunits > 0)
  378. displayProgress('<table><tr><td>Total: '+(totalWorkunits)+' graphs (<a href=\"/WsWorkunits/WUClusterJobSummaryXLS?' + xls +'\">summary</a>...<a href=\"/WsWorkunits/WUClusterJobXLS?' + xls +'\">cluster_jobs.html</a>)</td></tr></table>');
  379. else
  380. displayProgress('<table><tr><td>Total: '+(totalWorkunits)+' graphs</td></tr></table>');
  381. }
  382. function displaySasha()
  383. {
  384. displayProgress('Querying sasha ...');
  385. }
  386. function displayLegend()
  387. {
  388. var count = 5;
  389. var clrArray=new Array('red', 'tan', 'black', 'blue', 'darkblue');
  390. var clrDiscArray=new Array('failed', 'not finished', 'archived', 'Normal', 'Normal (diffrent workunit)');
  391. var svg=document.getElementById('SVG0');
  392. var svgdoc=svg.getSVGDocument();
  393. var g1=svgdoc.createElementNS("http://www.w3.org/2000/svg", "g");
  394. g1.setAttribute("transform","translate(20,20) scale(25,20)");
  395. g1.setAttribute("id","LegendBaseT");
  396. var g=svgdoc.createElementNS("http://www.w3.org/2000/svg", "g");
  397. g.setAttribute("stroke-width","0.01");
  398. g.setAttribute("stroke","black");
  399. g.setAttribute("font-size","0.5");
  400. g.setAttribute("stroke-width","0.01");
  401. g.setAttribute("alignment-baseline","middle");
  402. g.setAttribute("id","LegendBase");
  403. for(var i=0;i<count;i++)
  404. {
  405. var line=svgdoc.createElementNS("http://www.w3.org/2000/svg", "line");
  406. line.setAttribute("x1",0);
  407. line.setAttribute("y1",i*0.5);
  408. line.setAttribute("x2",2);
  409. line.setAttribute("y2",i*0.5);
  410. line.setAttribute("stroke",clrArray[i]);
  411. line.setAttribute("stroke-width",0.5);
  412. g.appendChild(line);
  413. var text=svgdoc.createElementNS("http://www.w3.org/2000/svg", "text");
  414. text.setAttribute("x",2);
  415. text.setAttribute("y",i*0.5 + 0.2);
  416. text.setAttribute("text-anchor","clrDiscArray");
  417. text.appendChild(svgdoc.createTextNode(clrDiscArray[i]));
  418. g.appendChild(text);
  419. }
  420. g1.appendChild(g);
  421. svgdoc.rootElement.appendChild(g1);
  422. svgdoc.rootElement.setAttribute("width",396);
  423. svgdoc.rootElement.setAttribute("height",8+count*10+8);
  424. svg.style.width=400;
  425. svg.style.height=10+count*10+10;
  426. }