forked from HPCNow/PHPQstat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
qstat_user.php
265 lines (210 loc) · 7.69 KB
/
qstat_user.php
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
<html>
<head>
<title>PHPQstat</title>
<meta name="AUTHOR" content="Jordi Blasco Pallares ">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="KEYWORDS" content="gridengine sge sun hpc supercomputing batch queue linux xml qstat qhost jordi blasco solnu">
<link rel="stylesheet" href="phpqstat.css" type="text/css" />
</head>
<?php
$owner = isset($_GET['owner']) ? $_GET['owner'] : 'all';
$jobstat = isset($_GET['jobstat']) ? $_GET['jobstat'] : null ;
$queue = isset($_GET['queue']) ? $_GET['queue'] : null ;
$job = isset($_GET['job']) ? $_GET['job'] : null ;
include("header.php");
include_once('qzbix.php');
$token = uniqid('phpqstat_');
$tokenfile="/tmp/$token.xml";
function clean_owner($owner) {
switch ($owner) {
case 'all':
case '*':
case '':
case !isset($owner):
$cleaned = '*';
break;
default:
$cleaned = $owner;
break;
}
return $cleaned;
}
function cont_job($str) {
return "contains(JB_name, '$str')";
}
function build_xpath_query($type, $owner, $queue, $job) {
$query = array( "@state='$type'" ) ;
$query[] = (empty($owner) or $owner == '*') ? '' : "JB_owner='$owner'" ;
$query[] = (empty($queue) or $queue == '*') ? '' : "starts-with(queue_name, '$queue@')";
# PHP is a horrible language.
if (!empty($job)) {
$job=trim($job);
$query[] = '(' . join(' or ', array_map( 'cont_job', preg_split('/\s+/', $job))) . ')';
}
return join(' and ', preg_grep('/^\s*$/', $query, $flags=PREG_GREP_INVERT));
}
function show_run($qstat,$owner,$queue, $job) {
echo "<table align=center width=95%xml border=\"1\" cellpadding=\"0\" cellspacing=\"0\">
<tbody>
<tr>
<td CLASS=\"header\" width=120 colspan=10><b>Running Jobs</b></td></tr>
<tr>
<td>JobID</td>
<td>Owner</td>
<td>Priority</td>
<td>Name</td>
<td>State</td>
<td>Project </td>
<td>Queue </td>
<td>Start Time</td>
<td>PE</td>
<td>Slots</td>
</tr>";
$owner = clean_owner(trim($owner));
$queue = clean_owner(trim($queue)); //Works for both
$xpath_query = build_xpath_query('running', $owner, $queue, $job);
$xpath = "/job_info/queue_info/job_list[$xpath_query]";
#print "\n\n$xpath\n\n<br>queue=$queue owner=$owner job=$job";
foreach ($qstat->xpath($xpath) as $job_list) {
$pe=$job_list->granted_pe['name'];
$slots = $pe ? $job_list->granted_pe : 1;
$queue = $job_list->queue_name;
$queue_display = preg_replace('/\.be-md.*$/', '', $queue);
list($qname, $sgehost) = split("@", $job_list->queue_name);
// Add Zabbix Link
$zabbix_link = zabbix_link($sgehost);
// END of Zabbix Link
$qstat_user_link = '<a href="' . "qstat_user.php?queue=$queue&owner=$owner" . '">' . $queue_display . '</a>';
$job_number = $job_list->JB_job_number;
echo " <tr>
<td><a href=qstat_job.php?jobid=$job_list->JB_job_number&owner=$owner>$job_list->JB_job_number</a></td>
<td><a href=qstat_user.php?owner=$job_list->JB_owner>$job_list->JB_owner</a></td>
<td>$job_list->JAT_prio</td>
<td>$job_list->JB_name</td>
<td>$job_list->state</td>
<td>$job_list->JB_project</td>
<td>$qstat_user_link$zabbix_link</td>
<td>$job_list->JAT_start_time</td>
<td>$pe</td>
<td>$slots</td>
</tr>";
}
echo "</tbody></table><br><br>\n";
}
function show_pend($qstat,$owner,$queue, $job) {
echo "<table align=center width=95%xml border=\"1\" cellpadding=\"0\" cellspacing=\"0\">
<tbody>
<tr>
<td CLASS=\"header\" width=120 colspan=10><b>Pending Jobs</b></td></tr>
<tr>
<td>JobID</td>
<td>Owner</td>
<td>Priority</td>
<td>Name</td>
<td>State</td>
<td>Project </td>
<td>Submission Time</th>
<td>PE</th>
<td>Tasks</th>
</tr>";
$owner = clean_owner($owner);
$queue = $queue ? "'$queue'" : '*';
# Note this is '/job_info/job_info' (repeated)!
#$xpath_query = "/job_info/job_info/job_list[@state='pending' and JB_owner=$owner]";
$xpath_query = build_xpath_query('pending', $owner, $queue, $job);
$xpath = "/job_info/job_info/job_list[$xpath_query]";
#print "\n\n$xpath\n\n";
foreach ($qstat->xpath($xpath) as $job_list) {
$pe = $job_list->requested_pe['name'];
if ($pe) { $pe .= ':' . $job_list->requested_pe; }
$tasks = $job_list->tasks ? $job_list->tasks : 1;
echo " <tr>
<td><a href=qstat_job.php?jobid=$job_list->JB_job_number&owner=$owner>$job_list->JB_job_number</a></td>
<td><a href=qstat_user.php?owner=$job_list->JB_owner>$job_list->JB_owner</a></td>
<td>$job_list->JAT_prio</td>
<td>$job_list->JB_name</td>
<td>$job_list->state</td>
<td>$job_list->JB_project</td>
<td>$job_list->JB_submission_time</td>
<td>$pe</td>
<td align='right'>$tasks</td>
</tr>";
}
echo "</tbody></table><br>";
}
############################################################################################################
echo "<body><table align=center width=95% border=\"1\" cellpadding=\"0\" cellspacing=\"0\"><tbody>";
echo "<tr><td><h1>PHPQstat</h1></td></tr>
<tr><td CLASS=\"header\" align=center>
<a href=\"qstat.php?owner=$owner\">Queue status</a> •
<a href=\"qhost.php?owner=$owner\">Hosts status</a> •
<a href=\"qstat_user.php?owner=$owner\">Jobs status ($owner)</a> •
<a href=\"about.php?owner=$owner\">About PHPQstat</a>
</td></tr>";
echo '<tr><td align="center">';
print "<form action=qstat_user.php method=get>\n
User: <input size=10 name=owner type=text value=\"$owner\"><input type=submit value='Enter'> •
Queue: <input size=10 name=queue type=text value=\"$queue\"><input type=submit value='Enter'> •
Job: <input size=20 name=job type=text value=\"$job\"><input type=submit value='Enter'></form> ";
echo "</td></tr>";
echo "<tr><td><br>";
if($queue){$queueflag="-q $queue";}else{$queueflag="";}
if($jobstat){$jobstatflag="-s $jobstat";}else{$jobstatflag="";}
if ($qstat_reduce == "yes" ) {
$qstat = simplexml_load_file("/tmp/qstat_all.xml");
if (!$qstat) {
print "</trd</tr>\n<h2>There was an error loading the XML output from SGE. Please try again in about 30 seconds.</h2>";
include('bottom.php');
print("</tbody></table></body></html");
}
}
switch ($jobstat) {
case "r":
$jobstatflag="-s r";
if ($qstat_reduce != "yes" ) {
$out = exec("./gexml -u $owner $jobstatflag $queueflag -o $tokenfile");
show_run("",$owner,$queue,$job);
unlink($tokenfile);
} else {
show_run($qstat,$owner,$queue,$job);
}
break;
case "p":
$jobstatflag="-s p";
if ($qstat_reduce != "yes" ) {
$out = exec("./gexml -u $owner $jobstatflag $queueflag -o /tmp/$token.xml");
show_pend("",$owner,$queue,$job);
unlink($tokenfile);
} else {
show_pend($qstat,$owner,$queue,$job);
}
break;
default:
$jobstatflag="-s r";
if ($qstat_reduce != "yes" ) {
$out = exec("./gexml -u $owner $jobstatflag $queueflag -o /tmp/$token.xml");
show_run("",$owner,$queue,$job);
unlink($tokenfile);
} else {
show_run($qstat,$owner,$queue,$job);
}
$jobstatflag="-s p";
if ($qstat_reduce != "yes" ) {
$out = exec("./gexml -u $owner $jobstatflag $queueflag -o /tmp/$token.xml");
show_pend("",$owner,$queue,$job);
unlink($tokenfile);
} else {
show_pend($qstat,$owner,$queue,$job);
}
break;
}
?>
</td>
</tr>
<?php
include("bottom.php");
?>
</tbody>
</table>
</body>
</html>