PageRenderTime 25ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/nordugrid-arc-2.0.0/src/services/ws-monitor/quelist.php

#
PHP | 182 lines | 123 code | 33 blank | 26 comment | 19 complexity | 952d0aa2b28bca5b13091172865f9d98 MD5 | raw file
Possible License(s): Apache-2.0
  1. <?php
  2. // Author: oxana.smirnova@hep.lu.se
  3. /**
  4. * Retrieves the queue job list information from a given NorduGrid domain
  5. * Uses LDAP functions of PHP
  6. *
  7. * Author: O.Smirnova (June 2002)
  8. * inspired by the LDAPExplorer by T.Miao
  9. *
  10. * input:
  11. * host (default: grid.quark.lu.se)
  12. * port (default: 2135)
  13. * qname (default: "default")
  14. *
  15. * output:
  16. * an HTML table, containing the list of the jobs in the queue
  17. */
  18. include_once 'db.php';
  19. set_include_path(get_include_path().":".getcwd()."/includes".":".getcwd()."/lang");
  20. require_once('headfoot.inc');
  21. require_once('lmtable.inc');
  22. require_once('comfun.inc');
  23. require_once('cnvtime.inc');
  24. require_once('cnvname.inc');
  25. require_once('toreload.inc');
  26. // getting parameters
  27. $host = ( $_GET["host"] ) ? $_GET["host"] : "quark.hep.lu.se";
  28. $port = ( $_GET["port"] ) ? $_GET["port"] : 2135;
  29. $qname = $_GET["qname"];
  30. $qid = $_GET["qid"];
  31. $debug = ( $_GET["debug"] ) ? $_GET["debug"] : 0;
  32. // Setting up the page itself
  33. $toppage = new LmDoc("quelist",$qname." (".$host.")");
  34. $toptitle = $toppage->title;
  35. $module = &$toppage->module;
  36. $strings = &$toppage->strings;
  37. $errors = &$toppage->errors;
  38. $cert = &$toppage->cert;
  39. $clstring = popup("clusdes.php?host=$host&port=$port",700,620,1);
  40. // Header table
  41. $toppage->tabletop("","<b><i>".$toptitle." ".$qname." (<a href=\"$clstring\">".$host."</a>)</i></b>");
  42. $lim = array( "dn", JOB_NAME, JOB_GOWN, JOB_SUBM, JOB_STAT, JOB_COMP, JOB_USET, JOB_USEM, JOB_ERRS, JOB_CPUS, JOB_EQUE );
  43. if ( $debug ) {
  44. ob_end_flush();
  45. ob_implicit_flush();
  46. }
  47. $tlim = 15;
  48. $tout = 20;
  49. if( $debug ) dbgmsg("<div align=\"left\"><i>:::&gt; ".$errors["101"].$tlim.$errors["102"].$tout.$errors["103"]." &lt;:::</div><br>");
  50. // ldapsearch filter strings for cluster and queues
  51. $filstr = "(objectclass=".OBJ_AJOB.")";
  52. $dn = DN_LOCAL;
  53. $topdn = DN_GLOBL;
  54. // Establish connection to the requested information server
  55. $type = 'DB';
  56. $isis = new $type($cert,array());
  57. if ($isis) {
  58. // If contact OK, search for NorduGrid clusters
  59. if ($host) {
  60. $ts1 = time();
  61. $entries = $isis->cluster_info($host);
  62. $ts2 = time(); if($debug) dbgmsg("<br><b>".$errors["110"]." (".($ts2-$ts1).$errors["104"].")</b><br>");
  63. if ($entries) {
  64. $queues = $entries->Domains->AdminDomain->Services->ComputingService->ComputingShares->ComputingShare;
  65. $queues_new = $entries->Domains->AdminDomain->Services->ComputingService->ComputingShare;
  66. $queues = @($queues) ? $queues : $queues_new ;
  67. $actual_queue = NULL;
  68. foreach ($queues as $queue) {
  69. if ($queue->ID == $qid) $actual_queue = $queue;
  70. }
  71. $isis->xml_nice_dump($actual_queue, "queue", $debug);
  72. echo "<br>";
  73. $jobs = $entries->Domains->AdminDomain->Services->ComputingService->ComputingEndpoint->ComputingActivities->ComputingActivity;
  74. $njobs = count($jobs);
  75. define("CMPKEY",JOB_SUBM);
  76. usort($entries,"ldap_entry_comp");
  77. // HTML table initialisation
  78. $ltable = new LmTable($module,$toppage->$module);
  79. // loop on jobs
  80. $nj = 0;
  81. for ($i=0; $i<$njobs; $i++) {
  82. $equeue = (string)$jobs[$i]->{JOB_EQUE};
  83. if ( $equeue !== $qname ) {
  84. if ( $debug == 2 ) dbgmsg(",".$equeue." != ".$qname.",");
  85. continue;
  86. }
  87. $jobdn = rawurlencode($jobs[$i]->ID);
  88. $curstat = $jobs[$i]->{JOB_STAT};
  89. $stahead = substr($curstat,0,12);
  90. $ftime = "";
  91. if ($stahead=="FINISHED at:") {
  92. $ftime = substr(strrchr($curstat, " "), 1);
  93. } elseif ($curstat=="FINISHED") {
  94. $ftime = $jobs[$i]->{JOB_COMP};
  95. }
  96. if ( $ftime ) {
  97. $ftime = cnvtime($ftime);
  98. $curstat = "FINISHED at: ".$ftime;
  99. }
  100. $uname = $jobs[$i]->{JOB_GOWN};
  101. $encuname = rawurlencode($uname);
  102. $family = cnvname($uname, 2);
  103. $jname = htmlentities($jobs[$i]->{JOB_NAME});
  104. $jobname = ($jobs[$i]->{JOB_NAME}) ? $jname : "<font color=\"red\">N/A</font>";
  105. $time = ($jobs[$i]->{JOB_USET}) ? $jobs[$i]->{JOB_USET} : "";
  106. $memory = ($jobs[$i]->{JOB_USEM}) ? $jobs[$i]->{JOB_USEM} : "";
  107. $ncpus = ($jobs[$i]->{JOB_CPUS}) ? $jobs[$i]->{JOB_CPUS} : "";
  108. $error = ($jobs[$i]->{JOB_ERRS});
  109. if ( $error ) $error = ( preg_match("/user/i",$error) ) ? "X" : "!";
  110. $status = "All";
  111. $newwin = popup("jobstat.php?host=$host&port=$port&status=$status&jobdn=$jobdn",750,430,4);
  112. $usrwin = popup("userlist.php?bdn=$topdn&owner=$encuname",700,500,5);
  113. // filling the table
  114. $nj++;
  115. $lrowcont[] = "$nj&nbsp;<b><font color=\"red\">$error</font></b>";
  116. $lrowcont[] = "<a href=\"$newwin\">$jobname</a>";
  117. $lrowcont[] = "<a href=\"$usrwin\">$family</a>";
  118. $lrowcont[] = "$curstat";
  119. $lrowcont[] = "$time";
  120. $lrowcont[] = "$memory";
  121. $lrowcont[] = "$ncpus";
  122. $ltable->addrow($lrowcont);
  123. $lrowcont = array ();
  124. }
  125. $ltable->close();
  126. } else {
  127. $errno = "4";
  128. echo "<br><font color=\"red\"><b>".$errors[$errno]."</b></font>\n";
  129. $toppage->close();
  130. return $errno;
  131. }
  132. } else {
  133. $errno = "5";
  134. echo "<br><font color=\"red\"><b>".$errors[$errno]."</b></font>\n";
  135. $toppage->close();
  136. return $errno;
  137. }
  138. $toppage->close();
  139. return 0;
  140. }
  141. else {
  142. $errno = "6";
  143. echo "<br><font color=\"red\"><b>".$errors[$errno]."</b></font>\n";
  144. $toppage->close();
  145. return $errno;
  146. }
  147. // Done
  148. $toppage->close();
  149. ?>