index : archweb32 | |
Archlinux32 website | gitolite user |
summaryrefslogtreecommitdiff |
author | Erich Eckner <git@eckner.net> | 2018-07-20 09:55:44 +0200 |
---|---|---|
committer | Erich Eckner <git@eckner.net> | 2018-07-20 09:55:44 +0200 |
commit | 4a411afe3b5e6c742b7a6dc3e8a7e45d5d075091 (patch) | |
tree | 754f2832373c6e4572a986418462d9d26b2d205a | |
parent | e42c6ee95fcef13374b744b392f3b27507683c2f (diff) |
-rw-r--r-- | buildmaster/build-slaves.php | 230 |
diff --git a/buildmaster/build-slaves.php b/buildmaster/build-slaves.php index 978e99c..c5a3ddc 100644 --- a/buildmaster/build-slaves.php +++ b/buildmaster/build-slaves.php @@ -1,65 +1,187 @@ <?php require_once "../init.php"; +require_once BASE . "/lib/style.php"; require_once BASE . "/lib/mysql.php"; - $result = mysql_run_query( - "SELECT" . - " `build_slaves`.`name`," . - "`persons`.`name` AS `operator`," . - "`package_sources`.`pkgbase`," . - "MAX(`ssh_log`.`date`" . - ") AS `lc`," . - "MAX(IF(`ssh_log`.`action`=\"get-assignment\",`ssh_log`.`date`,NULL)" . - ") AS `bs`," . - "`build_slaves`.`logged_lines`," . - "`build_slaves`.`trials`," . - "`build_slaves`.`last_action`" . - " FROM `build_slaves`" . - " LEFT JOIN `ssh_log` ON" . - " `ssh_log`.`build_slave`=`build_slaves`.`id`" . - " JOIN `ssh_keys` ON" . - " `build_slaves`.`ssh_key`=`ssh_keys`.`id`" . - " JOIN `persons` ON" . - " `ssh_keys`.`owner`=`persons`.`id`" . - " LEFT JOIN `build_assignments` ON" . - " `build_slaves`.`currently_building`=`build_assignments`.`id`" . - " LEFT JOIN `package_sources` ON" . - " `build_assignments`.`package_source`=`package_sources`.`id`" . +$columns = array( + "name" => array( + "label" => "name", + "mysql_name" => "name", + "mysql_query" => "`build_slaves`.`name`", + "sort" => "name", + "title" => "name" + ), + "operator" => array( + "label" => "operator", + "mysql_name" => "operator", + "mysql_query" => "`persons`.`name`", + "sort" => "operator", + "title" => "operator" + ), + "currently_building" => array( + "label" => "currently building", + "mysql_name" => "cb", + "mysql_query" => "`package_sources`.`pkgbase`", + "sort" => "currently_building", + "title" => "pkgbase of currently building package" + ), + "last_connection" => array( + "label" => "last connection", + "mysql_name" => "lc", + "mysql_query" => "MAX(`ssh_log`.`date`)", + "sort" => "last_connection", + "title" => "time of last connection" + ), + "building_since" => array( + "label" => "building since", + "mysql_name" => "bs", + "mysql_query" => "MAX(IF(`ssh_log`.`action`=\"get-assignment\",`ssh_log`.`date`,NULL))", + "sort" => "building_since", + "title" => "start of build" + ), + "trials" => array( + "label" => "trials", + "mysql_name" => "trials", + "mysql_query" => "`build_slaves`.`trials`", + "sort" => "trials", + "title" => "number of trials" + ), + "logged_lines" => array( + "label" => "logged lines", + "mysql_name" => "ll", + "mysql_query" => "`build_slaves`.`logged_lines`", + "sort" => "logged_lines", + "title" => "number of logged lines so far" + ), + "last_action" => array( + "label" => "last action", + "mysql_name" => "la", + "mysql_query" => "`build_slaves`.`last_action`", + "sort" => "last_action", + "title" => "last action" + ) +); + +if (!isset($_GET["sort"])) + $_GET["sort"]="-last_connection"; + +if (substr($_GET["sort"],0,1) == "-") { + $direction = " DESC"; + $sort = substr($_GET["sort"],1); +} else { + $direction = " ASC"; + $sort = $_GET["sort"]; +} + +if (isset($columns[$sort])) + $order = "IFNULL(`sub_query`.`" . $columns[$sort]["mysql_name"] . "`,0) " . $direction . ","; +else + $order = ""; + +function combine_fields($cln) { + return $cln["mysql_query"] . " AS `" . $cln["mysql_name"] . "`"; +} + +$result = mysql_run_query( + "SELECT `sub_query`.* FROM (" . + "SELECT " . + implode(",",array_map("combine_fields",$columns)) . + " FROM `build_assignments`" . + " JOIN `package_sources`" . + " ON `build_assignments`.`package_source`=`package_sources`.`id`" . + + " RIGHT JOIN `build_slaves`" . + " ON `build_slaves`.`currently_building`=`build_assignments`.`id`" . + " JOIN `ssh_keys`" . + " ON `build_slaves`.`ssh_key`=`ssh_keys`.`id`" . + " JOIN `persons`" . + " ON `ssh_keys`.`owner`=`persons`.`id`" . + + " LEFT JOIN `ssh_log`" . + " ON `ssh_log`.`build_slave`=`build_slaves`.`id`" . " GROUP BY `build_slaves`.`id`" . - " ORDER BY `lc`" - ); + ") AS `sub_query`" . + " ORDER BY " . $order . "`sub_query`.`name`" +); + +$count = 0; + +while($row = $result->fetch_assoc()) { + + foreach ($row as $name => $value) { + if (!isset($row[$name])) + $rows[$count][$name] = " "; + else + $rows[$count][$name] = $value; + } + $rows[$count]["name"] = + "<a href=\"/buildmaster/log.php?show=ssh&slave=" . + $row["name"] . + "\">" . + $row["name"] . + "</a>"; + + $count++; +} + +print_header("List of Build Slaves"); + +if ($count > 0) { + +?> + <div id="buildslaveslist-results" class="box"> + <table class="results"> + <thead> + <tr> +<?php + +foreach ($columns as $column) { + + print " <th>\n"; + print " <a href=\"?sort="; + if ($column["sort"] == $_GET["sort"]) + print "-"; + print $column["sort"] . "\" "; + print "title=\"Sort build assignments by " . $column["title"] . "\">\n"; + print " " . $column["label"] . "\n"; + print " </a>\n"; + print " </th>\n"; + +} ?> -<html> - <head> - <title>list of build slaves</title> - </head> - <body> + </tr> + </thead> + <tbody> <?php -show_warning_on_offline_slave(); - - print "<table border=1>\n"; - if ($result->num_rows > 0) { - print "<tr><th>name</th><th>operator</th><th>currently building</th><th>last connection</th><th>building since</th><th>trials</th><th>logged lines</th><th>last action</th></tr>\n"; - while ($row = $result -> fetch_assoc()) { - foreach ($row as $key => $value) { - if ($value=="") { - $row[$key]=" "; - } - } - print "<tr>"; - print "<td><a href=\"/buildmaster/log.php?show=ssh&slave=".$row["name"]."\">".$row["name"]."</a></td>"; - print "<td>".$row["operator"]."</td>"; - print "<td>".$row["pkgbase"]."</td>"; - print "<td>".$row["lc"]."</td>"; - print "<td>".$row["bs"]."</td>"; - print "<td>".$row["trials"]."</td>"; - print "<td>".$row["logged_lines"]."</td>"; - print "<td>".$row["last_action"]."</td>"; - print "</tr>\n"; - } + +$oddity = "odd"; + +foreach($rows as $row) { + + print " <tr class=\"" . $oddity . "\">\n"; + + foreach ($columns as $column) { + + print " <td>\n"; + print " " . $row[$column["mysql_name"]] . "\n"; + print " </td>\n"; + } - print "</table>\n"; + print " </tr>\n"; + + if ($oddity == "odd" ) + $oddity = "even"; + else + $oddity = "odd"; + +} ?> -</body></html> + </tbody> + </table> + </div> +<?php +} + +print_footer(); |