jobqueue.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  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 max_queue_length = 0;
  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_queue_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. max_queue_length = 0;
  73. var svgdoc=svg.getSVGDocument();
  74. if(svgdoc.rootElement.firstChild)
  75. svgdoc.rootElement.removeChild(svgdoc.rootElement.firstChild);
  76. document.getElementById('loader').src=src;
  77. displayProgress('Querying dali ...');
  78. }
  79. function show_q_popup(x,y,wuid,dt)
  80. {
  81. var svg=document.getElementById('SVG');
  82. if(!svg) return;
  83. var src='<table id="tab" style="font:menu"><colgroup><col align="left" valign="top"/></colgroup>'+
  84. '<tr><th>Wuid</th><td>'+wuid+'</td></tr>'+
  85. '<tr><th>Time</th><td>'+dt+'</td></tr></table>';
  86. if (!isFF)
  87. {
  88. labelPopup=window.createPopup();
  89. var popupBody=labelPopup.document.body;
  90. popupBody.style.backgroundColor = "yellow";
  91. popupBody.style.border = "outset black 2px";
  92. popupBody.innerHTML=src;
  93. var xp=x+svg.offsetLeft-document.body.scrollLeft+window.screenLeft-50,
  94. yp=y+svg.offsetTop-document.body.scrollTop+window.screenTop+250;
  95. labelPopup.show(xp,yp,400,100,null);
  96. var w=labelPopup.document.getElementById('tab').clientWidth+5,
  97. h=labelPopup.document.getElementById('tab').clientHeight+5;
  98. labelPopup.show(xp,yp,w,h,null);
  99. }
  100. else
  101. {
  102. if(labelPanel)
  103. {
  104. labelPanel.hide();
  105. labelPanel=null;
  106. }
  107. var l = x-1550;
  108. var t = y-350;
  109. labelPanel = new YAHOO.widget.Panel("labelPanel", { width:"160px", height:"60px",
  110. visible:true, constraintoviewport:true, close:false,
  111. xy: [l, t]
  112. } );
  113. //labelPanel.setHeader("WUInfo");
  114. labelPanel.setBody(src);
  115. labelPanel.render(document.body);
  116. labelPanel.show();
  117. }
  118. }
  119. function show_q_popup1(evt,wuid,dt)
  120. {
  121. show_q_popup(evt.screenX,evt.screenY,wuid,dt);
  122. }
  123. /*
  124. function hide_popup()
  125. {
  126. if(window.labelPopup)
  127. {
  128. labelPopup.hide();
  129. labelPopup=null;
  130. }
  131. }
  132. function open_workunit(wuid)
  133. {
  134. //document.location.href='/WsWorkunits/WUInfo?Wuid='+wuid;
  135. var wu_window = window.open('/WsWorkunits/WUInfo?Wuid=' + wuid,
  136. 'Workunit', 'location=0,status=1,scrollbars=1,resizable=1,width=500,height=600');
  137. wu_window.opener = window;
  138. wu_window.focus();
  139. }
  140. */
  141. var fromDate=null, toDate=null;
  142. var usageArray=null;
  143. var busagAarray = null;
  144. var nbusageArray = null;
  145. var totalWorkunits=0;
  146. var itemWidth=0.4;
  147. function displayQLegend()
  148. {
  149. var count = 3;
  150. var clrArray=new Array('green', 'blue', 'red');
  151. var clrDiscArray=new Array('Connected', 'Running', 'Queued');
  152. var svg=document.getElementById('SVG0');
  153. var svgdoc=svg.getSVGDocument();
  154. var g1=svgdoc.createElementNS("http://www.w3.org/2000/svg", "g");
  155. g1.setAttribute("transform","translate(20,20) scale(25,20)");
  156. var g=svgdoc.createElementNS("http://www.w3.org/2000/svg", "g");
  157. g.setAttribute("stroke-width","0.01");
  158. g.setAttribute("stroke","black");
  159. g.setAttribute("font-size","0.5");
  160. g.setAttribute("stroke-width","0.01");
  161. g.setAttribute("alignment-baseline","middle");
  162. for(var i=0;i<count;i++)
  163. {
  164. var line=svgdoc.createElementNS("http://www.w3.org/2000/svg", "line");
  165. line.setAttribute("x1",0);
  166. line.setAttribute("y1",i*0.5);
  167. line.setAttribute("x2",1);
  168. line.setAttribute("y2",i*0.5);
  169. line.setAttribute("stroke",clrArray[i]);
  170. line.setAttribute("stroke-width",0.5);
  171. g.appendChild(line);
  172. var text=svgdoc.createElementNS("http://www.w3.org/2000/svg", "text");
  173. text.setAttribute("x",1.5);
  174. text.setAttribute("y",i*0.5 + 0.2);
  175. text.setAttribute("text-anchor","clrDiscArray");
  176. text.appendChild(svgdoc.createTextNode(clrDiscArray[i]));
  177. g.appendChild(text);
  178. }
  179. g1.appendChild(g);
  180. svgdoc.rootElement.appendChild(g1);
  181. svg.style.width=400;
  182. svg.style.height=10+count*10+10;
  183. svgdoc.rootElement.setAttribute("width",396);
  184. svgdoc.rootElement.setAttribute("height",8+count*10+8);
  185. }
  186. var max_queues = 0;
  187. var records = 0;
  188. function displayQBegin(queues, connected, count)
  189. {
  190. max_queues=queues;
  191. records = count;
  192. var svg=document.getElementById('SVG');
  193. var svgdoc=svg.getSVGDocument();
  194. var g1=svgdoc.createElementNS("http://www.w3.org/2000/svg", "g");
  195. g1.setAttribute("transform","translate(60,20) scale(25,20)");
  196. g1.setAttribute("id","top");
  197. var g=svgdoc.createElementNS("http://www.w3.org/2000/svg", "g");
  198. g.setAttribute("stroke-width","0.01");
  199. g.setAttribute("stroke","black");
  200. g.setAttribute("font-size","0.5");
  201. g.setAttribute("stroke-width","0.01");
  202. g.setAttribute("alignment-baseline","middle");
  203. var lines = queues + connected + 1;
  204. for(var i=0;i<lines;i++)
  205. {
  206. var text1=svgdoc.createElementNS("http://www.w3.org/2000/svg", "text");
  207. text1.setAttribute("x",-0.5);
  208. text1.setAttribute("y",i);
  209. text1.setAttribute("text-anchor","end");
  210. text1.appendChild(svgdoc.createTextNode(lines - i - 1));
  211. g.appendChild(text1);
  212. var line=svgdoc.createElementNS("http://www.w3.org/2000/svg", "line");
  213. line.setAttribute("x1",0);
  214. line.setAttribute("y1",i);
  215. line.setAttribute("x2",count*itemWidth+0.3);
  216. line.setAttribute("y2",i);
  217. if(i==0 || i==(lines-1))
  218. {
  219. line.setAttribute("stroke-width",0.05);
  220. }
  221. g.appendChild(line);
  222. }
  223. var line1=svgdoc.createElementNS("http://www.w3.org/2000/svg", "line");
  224. line1.setAttribute("x1",0);
  225. line1.setAttribute("y1",0);
  226. line1.setAttribute("x2",0);
  227. line1.setAttribute("y2", lines - 1);
  228. line1.setAttribute("stroke-width",0.05);
  229. g.appendChild(line1);
  230. g1.appendChild(g);
  231. svgdoc.rootElement.appendChild(g1);
  232. svg.style.width=1150;
  233. svg.style.height=150+20+count*20+40;
  234. svgdoc.rootElement.setAttribute("width",1148);
  235. svgdoc.rootElement.setAttribute("height",20+count*20+40);
  236. }
  237. var lastjob = '';
  238. var seq = 0;
  239. function displayQueue(count,dt,running,queued,waiting,connected,idle,wuid1, wuid2)
  240. {
  241. var svg=document.getElementById('SVG');
  242. var svgdoc=svg.getSVGDocument();
  243. var g=svgdoc.createElementNS("http://www.w3.org/2000/svg", "g");
  244. g.setAttribute("stroke","black");
  245. g.setAttribute("font-size","0.4");
  246. g.setAttribute("stroke-width","0.02");
  247. g.setAttribute("alignment-baseline","middle");
  248. var xpos = itemWidth*count - 0.1;
  249. var ybase = max_queues + 2;
  250. var ypos = ybase+0.2;
  251. if (dt != '')
  252. {
  253. var gskew = svgdoc.createElementNS("http://www.w3.org/2000/svg", "g");
  254. var trans = "translate(" + xpos + "," + ypos + ") rotate(-90)";
  255. gskew.setAttribute("transform", trans);
  256. var text3=svgdoc.createElementNS("http://www.w3.org/2000/svg", "text");
  257. text3.setAttribute("x",0);
  258. text3.setAttribute("y",0);
  259. text3.setAttribute("text-anchor","end");
  260. text3.appendChild(svgdoc.createTextNode(dt));
  261. gskew.appendChild(text3);
  262. g.appendChild(gskew);
  263. }
  264. if (connected > 0)
  265. {
  266. var line1=svgdoc.createElementNS("http://www.w3.org/2000/svg", "line");
  267. line1.setAttribute("stroke",'green');
  268. line1.setAttribute("x1",xpos-0.15);
  269. line1.setAttribute("y1",ybase);
  270. line1.setAttribute("x2",xpos-0.15);
  271. line1.setAttribute("y2",ybase - connected);
  272. line1.setAttribute("stroke-width",0.15);
  273. g.appendChild(line1);
  274. }
  275. if (running > 0)
  276. {
  277. var g1=svgdoc.createElementNS("http://www.w3.org/2000/svg", "g");
  278. g1.setAttribute("stroke","blue");
  279. g1.setAttribute("stroke-width",1);
  280. g1.addEventListener("mouseover",function(evt) { show_q_popup1(evt,wuid1,dt); }, false);
  281. g1.addEventListener("mouseout",function(evt) { hide_popup(); }, false);
  282. g1.addEventListener("click",function(evt) { open_workunit(wuid1); }, false);
  283. var line2=svgdoc.createElementNS("http://www.w3.org/2000/svg", "line");
  284. line2.setAttribute("x1",+xpos);
  285. line2.setAttribute("y1",ybase);
  286. line2.setAttribute("x2",xpos);
  287. line2.setAttribute("y2",ybase - 1);
  288. line2.setAttribute("stroke-width",0.15);
  289. g1.appendChild(line2);
  290. g.appendChild(g1);
  291. }
  292. if (running > 1)
  293. {
  294. var g1=svgdoc.createElementNS("http://www.w3.org/2000/svg", "g");
  295. g1.setAttribute("stroke","blue");
  296. g1.setAttribute("stroke-width",1);
  297. g1.addEventListener("mouseover",function(evt) { show_q_popup1(evt,wuid2,dt); }, false);
  298. g1.addEventListener("mouseout",function(evt) { hide_popup(); }, false);
  299. g1.addEventListener("click",function(evt) { open_workunit(wuid2); }, false);
  300. var line2=svgdoc.createElementNS("http://www.w3.org/2000/svg", "line");
  301. line2.setAttribute("x1",+xpos);
  302. line2.setAttribute("y1",ybase - 1);
  303. line2.setAttribute("x2",xpos);
  304. line2.setAttribute("y2",ybase - 2);
  305. line2.setAttribute("stroke-width",0.15);
  306. g1.appendChild(line2);
  307. g.appendChild(g1);
  308. }
  309. if (queued > 0)
  310. {
  311. var line1=svgdoc.createElementNS("http://www.w3.org/2000/svg", "line");
  312. line1.setAttribute("stroke",'red');
  313. line1.setAttribute("x1",xpos);
  314. line1.setAttribute("y1",ybase - running);
  315. line1.setAttribute("x2",xpos);
  316. line1.setAttribute("y2",ybase - running - queued);
  317. line1.setAttribute("stroke-width",0.15);
  318. g.appendChild(line1);
  319. }
  320. if (queued > max_queue_length)
  321. max_queue_length = queued;
  322. svgdoc.getElementById("top").appendChild(g);
  323. }
  324. function displayQEnd(msg)
  325. {
  326. //displayProgress('<table><tr><td>Total: '+(max_queues)+' graphs (<a href=\"/WsWorkunits/WUClusterJobXLS?' + xls +'\">xls</a>...<a href=\"/WsWorkunits/WUClusterJobSummaryXLS?' + xls +'\">summary</a>)</td></tr></table>');
  327. displayProgress(msg);
  328. var svg=document.getElementById('SVG');
  329. var svgdoc=svg.getSVGDocument();
  330. svg.style.width=1150;
  331. svg.style.height=210+max_queue_length*20;
  332. svgdoc.rootElement.setAttribute("width",1148);
  333. svgdoc.rootElement.setAttribute("height",210+max_queue_length*20);
  334. }