PageRenderTime 32ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

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

#
PHP | 177 lines | 117 code | 32 blank | 28 comment | 18 complexity | 72c11378895f8f8ae0276236da210855 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. set_include_path(get_include_path().":".getcwd()."/includes".":".getcwd()."/lang");
  19. require_once('headfoot.inc');
  20. require_once('lmtable.inc');
  21. require_once('comfun.inc');
  22. require_once('cnvtime.inc');
  23. require_once('cnvname.inc');
  24. require_once('toreload.inc');
  25. require_once('ldap_nice_dump.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. $debug = ( $_GET["debug"] ) ? $_GET["debug"] : 0;
  31. $lang = @$_GET["lang"];
  32. if ( !$lang ) $lang = "default"; // browser language
  33. define("FORCE_LANG",$lang);
  34. // Setting up the page itself
  35. $toppage = new LmDoc("quelist",$qname." (".$host.")");
  36. $toptitle = $toppage->title;
  37. $module = &$toppage->module;
  38. $strings = &$toppage->strings;
  39. $errors = &$toppage->errors;
  40. $clstring = popup("clusdes.php?host=$host&port=$port",700,620,1,$lang,$debug);
  41. // Header table
  42. $toppage->tabletop("","<b><i>".$toptitle." ".$qname." (<a href=\"$clstring\">".$host."</a>)</i></b>");
  43. $lim = array( "dn", JOB_NAME, JOB_GOWN, JOB_SUBM, JOB_STAT, JOB_COMP, JOB_USET, JOB_USEM, JOB_ERRS, JOB_CPUS, JOB_EQUE );
  44. if ( $debug ) {
  45. ob_end_flush();
  46. ob_implicit_flush();
  47. }
  48. $tlim = 15;
  49. $tout = 20;
  50. if( $debug ) dbgmsg("<div align=\"left\"><i>:::&gt; ".$errors["101"].$tlim.$errors["102"].$tout.$errors["103"]." &lt;:::</div><br>");
  51. // ldapsearch filter strings for cluster and queues
  52. $filstr = "(objectclass=".OBJ_AJOB.")";
  53. $dn = DN_LOCAL;
  54. $topdn = DN_GLOBL;
  55. // Establish connection to the requested LDAP server
  56. $ds = ldap_connect($host,$port);
  57. if ($ds) {
  58. // If contact OK, search for NorduGrid clusters
  59. $basedn = QUE_NAME."=".$qname.",".CLU_NAME."=".$host.",";
  60. $locdn = $basedn.$dn;
  61. $aaa = ldap_nice_dump($strings,$ds,$locdn);
  62. echo "<br>";
  63. $ts1 = time();
  64. $sr = ldap_search($ds,$dn,$filstr,$lim,0,0,$tlim,LDAP_DEREF_NEVER);
  65. $ts2 = time(); if($debug) dbgmsg("<br><b>".$errors["110"]." (".($ts2-$ts1).$errors["104"].")</b><br>");
  66. // Fall back to conventional LDAP
  67. // if (!$sr) $sr = ldap_search($ds,$dn,$filstr,$lim,0,0,$tlim,LDAP_DEREF_NEVER);
  68. if ($sr) {
  69. $nmatch = ldap_count_entries($ds,$sr);
  70. if ($nmatch > 0) {
  71. $entries = ldap_get_entries($ds,$sr);
  72. $njobs = $entries["count"];
  73. define("CMPKEY",JOB_SUBM);
  74. usort($entries,"ldap_entry_comp");
  75. // HTML table initialisation
  76. $ltable = new LmTable($module,$toppage->$module);
  77. // loop on jobs
  78. $nj = 0;
  79. for ($i=1; $i<$njobs+1; $i++) {
  80. $equeue = $entries[$i][JOB_EQUE][0];
  81. if ( $equeue !== $qname ) {
  82. if ( $debug == 2 ) dbgmsg($equeue." != ".$qname);
  83. continue;
  84. }
  85. $jobdn = rawurlencode($entries[$i]["dn"]);
  86. $curstat = $entries[$i][JOB_STAT][0];
  87. $stahead = substr($curstat,0,12);
  88. $ftime = "";
  89. if ($stahead=="FINISHED at:") {
  90. $ftime = substr(strrchr($curstat, " "), 1);
  91. } elseif ($curstat=="FINISHED") {
  92. $ftime = $entries[$i][JOB_COMP][0];
  93. }
  94. if ( $ftime ) {
  95. $ftime = cnvtime($ftime);
  96. $curstat = "FINISHED at: ".$ftime;
  97. }
  98. $uname = $entries[$i][JOB_GOWN][0];
  99. $encuname = rawurlencode($uname);
  100. $family = cnvname($uname, 2);
  101. $jname = htmlentities($entries[$i][JOB_NAME][0]);
  102. $jobname = ($entries[$i][JOB_NAME][0]) ? $jname : "<font color=\"red\">N/A</font>";
  103. $time = ($entries[$i][JOB_USET][0]) ? $entries[$i][JOB_USET][0] : "";
  104. $memory = ($entries[$i][JOB_USEM][0]) ? $entries[$i][JOB_USEM][0] : "";
  105. $ncpus = ($entries[$i][JOB_CPUS][0]) ? $entries[$i][JOB_CPUS][0] : "";
  106. $error = ($entries[$i][JOB_ERRS][0]);
  107. if ( $error ) $error = ( preg_match("/user/i",$error) ) ? "X" : "!";
  108. $status = "All";
  109. $newwin = popup("jobstat.php?host=$host&port=$port&status=$status&jobdn=$jobdn",750,430,4,$lang,$debug);
  110. $usrwin = popup("userlist.php?bdn=$topdn&owner=$encuname",700,500,5,$lang,$debug);
  111. // filling the table
  112. $nj++;
  113. $lrowcont[] = "$nj&nbsp;<b><font color=\"red\">$error</font></b>";
  114. $lrowcont[] = "<a href=\"$newwin\">$jobname</a>";
  115. $lrowcont[] = "<a href=\"$usrwin\">$family</a>";
  116. $lrowcont[] = "$curstat";
  117. $lrowcont[] = "$time";
  118. $lrowcont[] = "$memory";
  119. $lrowcont[] = "$ncpus";
  120. $ltable->addrow($lrowcont);
  121. $lrowcont = array ();
  122. }
  123. $ltable->close();
  124. } else {
  125. $errno = "4";
  126. echo "<br><font color=\"red\"><b>".$errors[$errno]."</b></font>\n";
  127. return $errno;
  128. }
  129. } else {
  130. $errno = "5";
  131. echo "<br><font color=\"red\"><b>".$errors[$errno]."</b></font>\n";
  132. return $errno;
  133. }
  134. ldap_free_result($sr);
  135. ldap_close($ds);
  136. return 0;
  137. }
  138. else {
  139. $errno = "6";
  140. echo "<br><font color=\"red\"><b>".$errors[$errno]."</b></font>\n";
  141. return $errno;
  142. }
  143. // Done
  144. $toppage->close();
  145. ?>