in web_ui/src/applications/bistro/controllers/BistroHTTPTaskLogViewController.php [131:194]
private function getLogLines($hp_source) {
list($query_line_id, $query_timestamp) = $this->getLineIDOrTimestamp();
$query = $this->makeQuery($query_line_id, $query_timestamp);
$next_line_id = self::NOT_A_LINE_ID;
$stream_to_lines_lists = array();
$is_ascending = $this->prefs->get(BistroTaskLogPrefs::PREF_ASCENDING);
// Use MultiCurl to fetch logs from all Bistro instances in parallel.
$multi_curl_fetcher = new BistroMonitor2HTTPMultiCurlClient();
foreach ($multi_curl_fetcher->getSuccessfulHostportResponses(
$this->prefs, $this->getHostports($hp_source), json_encode($query))
as $hp => $response_str) {
list($response, $_is_complete) =
parse_monitor2_response($query, $hp, $response_str);
// Even if some streams had errors, there's a chance the others did not.
foreach ($response as $stream => $subresponse) {
if (!$subresponse) {
continue; // In the absence of lines, Bistro returns {}
}
$stream_to_lines_lists[$stream][] = $subresponse['lines'];
$cur_next_line_id = intval($subresponse['next_line_id']);
// Pick the most restrictive next_line_id of all the Bistro hosts.
if (
// Bistro returns NOT_A_LINE_ID to mark "no more lines", so we
// must not use it to restrict the "next line ID".
($cur_next_line_id !== self::NOT_A_LINE_ID) && (
// Only matches initially, due to the previous test.
($next_line_id === self::NOT_A_LINE_ID) ||
($is_ascending && $next_line_id > $cur_next_line_id) ||
(!$is_ascending && $next_line_id < $cur_next_line_id)
)
) {
$next_line_id = $cur_next_line_id;
}
}
}
// Filter out log lines that are beyond the most restrictive "next line ID"
$out_lines = array();
foreach ($stream_to_lines_lists as $stream => $lines_lists) {
foreach ($lines_lists as $lines) {
foreach ($lines as $line) {
$line[4] = intval($line[4]);
if (
($next_line_id === self::NOT_A_LINE_ID) ||
($line[4] === self::NOT_A_LINE_ID) ||
($is_ascending && $line[4] < $next_line_id) ||
(!$is_ascending && $line[4] > $next_line_id)
) {
array_unshift($line, $stream);
$out_lines[] = $line;
}
}
}
}
// Always display lines from oldest to newest
return array(
$query_line_id === null && $query_timestamp === null,
$next_line_id,
isort($out_lines, 5));
}