-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathjob.output.inc
118 lines (102 loc) · 3.18 KB
/
job.output.inc
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
<?php
function boa_job_output($jobId) {
global $user;
if (!isValidJob($jobId))
invalidJob($jobId);
drupal_set_title(t('Output for Job ') . $jobId);
$query = db_select('boa_jobs', 'r');
$query->join('boa_output', 'o', 'r.id = o.id');
$query->fields('r', array('hadoop_status'));
$query->fields('o', array('web_result'));
$query->addExpression('COALESCE(o.length, 0)', 'length');
$query->addExpression('COALESCE(LENGTH(o.web_result), 0)', 'weblen');
$query->condition('r.id', $jobId);
$record = $query->execute()->fetchObject();
if ($record->hadoop_status == 2) {
if ($record->length > 0) {
$trimmed = $record->length > $record->weblen;
$content = "";
if ($trimmed)
$content .= "\nNote: Output is <b>" . formatBytes($record->length) . "</b>, only showing first " . formatBytes($record->weblen) . "\n";
$content .= _print_table($record->web_result);
if ($trimmed)
$content .= "... remaining output not shown, please <a href=\"?q=boa/job/$jobId/download\">download output</a>.\n";
return $content;
}
drupal_set_message(t('The job finished successfully, but has no output.'), 'warning');
drupal_goto("boa/job/$jobId");
drupal_exit();
}
drupal_set_message(t('The job has not successfully finished running.'), 'warning');
drupal_goto("boa/job/$jobId");
drupal_exit();
}
function _print_table($table) {
$rows = explode("\n", substr($table, 0, strrpos($table, "\n")));
$content = '';
$last = '';
$prevTable = false;
foreach ($rows as $row) {
$eqPos = strpos($row, '=');
$bracketPos = strpos($row, '[');
if ($bracketPos != -1 && $bracketPos < $eqPos)
$cur = substr($row, 0, strpos($row, '['));
else
$cur = substr($row, 0, strpos($row, '='));
if (strpos($row, '[] = ') !== false) {
if ($last != $cur) {
if ($prevTable)
$content .= "</table>\n";
if ($content != '')
$content .= "</pre>\n";
$content .= "<pre style=\"overflow-x: auto;\">";
}
$content .= '<b>' . str_replace('[] = ', '</b> = ', htmlspecialchars($row)) . "\n";
$prevTable = false;
$last = $cur;
continue;
}
if ($last != $cur) {
if ($prevTable)
$content .= "</table>\n";
if ($content != '')
$content .= "</pre>\n";
$content .= "<pre><table style=\"display: block; overflow-x: auto; white-space: nowrap;\">\n";
}
$content .= _print_row($row);
$prevTable = true;
$last = $cur;
}
if ($prevTable)
$content .= "</table></pre>\n";
return linkify($content, array('target' => '_blank'));
}
function _print_row($row) {
$splitpos = strpos($row, '] = ');
$cols = explode('[', substr($row, 0, $splitpos + 1));
$keycount = count($cols) - 1;
$cols[] = substr($row, $splitpos + 4);
$content = '<tr>';
for ($i = 0; $i < count($cols); $i++) {
$col = $cols[$i];
if ($i > 0 && $i <= $keycount)
$col = trim(substr($col, 0, -1));
if ($i == count($cols) - 1)
$content .= '<td style="width: 100%;">';
else
$content .= '<td style="min-width: 100px;">';
if ($i == 0)
$content .= '<b>';
else if ($i <= $keycount)
$content .= '<i>';
$content .= htmlspecialchars($col);
if ($i == 0)
$content .= '</b>';
else if ($i < $keycount)
$content .= '</i>';
$content .= '</td>';
}
$content .= '</tr>';
return $content;
}
?>