Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/buildmaster/build-slaves.php
blob: 36a1522f2a7718c79447a414f1b0186083f7a097 (plain)
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
<?php
require_once "../init.php";
require_once BASE . "/lib/style.php";
require_once BASE . "/lib/mysql.php";

$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" => "`ba_q`.`cb`",
    "mysql_ba_q_name" => "cb",
    "mysql_ba_q_query" => "CONCAT(`architectures`.`name`,\"/\",`package_sources`.`pkgbase`)",
    "sort" => "currently_building",
    "title" => "pkgbase of currently building package"
  ),
  "last_connection" => array(
    "label" => "last connection",
    "mysql_name" => "lc",
    "mysql_query" => "`sl_q`.`lc`",
    "mysql_sl_q_name" => "lc",
    "mysql_sl_q_query" => "MAX(`ssh_log`.`date`)",
    "sort" => "last_connection",
    "title" => "time of last connection"
  ),
  "building_since" => array(
    "label" => "building since",
    "mysql_name" => "bs",
    "mysql_query" => "`sl_q`.`bs`",
    "mysql_sl_q_name" => "bs",
    "mysql_sl_q_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"] . "`";
}

function combine_ba_q_fields($cln) {
  if (isset($cln["mysql_ba_q_query"]) && isset($cln["mysql_ba_q_name"]))
    return $cln["mysql_ba_q_query"] . " AS `" . $cln["mysql_ba_q_name"] . "`";
}

function combine_sl_q_fields($cln) {
  if (isset($cln["mysql_sl_q_query"]) && isset($cln["mysql_sl_q_name"]))
    return $cln["mysql_sl_q_query"] . " AS `" . $cln["mysql_sl_q_name"] . "`";
}

function non_empty($val) {
  return ! empty($val);
}

$result = mysql_run_query(
  "SELECT `sub_query`.* FROM (" .
    "SELECT " .
    implode(",",array_map("combine_fields",$columns)) .
    " FROM `build_slaves`" .
    mysql_join_build_slaves_ssh_keys() .
    mysql_join_ssh_keys_persons().

    " LEFT JOIN (" .
      "SELECT " .
      "`build_assignments`.`id` AS `id`," .
      implode(",",array_filter(array_map("combine_ba_q_fields",$columns),"non_empty")) .
      " FROM `build_assignments`" .
      mysql_join_build_assignments_package_sources() .
      mysql_join_build_assignments_architectures() .
    ") AS `ba_q`" .
    " ON `ba_q`.`id`=`build_slaves`.`currently_building`" .

    " LEFT JOIN (" .
      "SELECT " .
      "`ssh_log`.`build_slave` AS `build_slave`," .
      implode(",",array_filter(array_map("combine_sl_q_fields",$columns),"non_empty")) .
      " FROM `ssh_log`" .
      " WHERE `ssh_log`.`date`>=ADDDATE(NOW(),\"-5 00:00:00\")" .
      " GROUP BY `ssh_log`.`build_slave`" .
    ") AS `sl_q`" .
    " ON `sl_q`.`build_slave`=`build_slaves`.`id`" .
  ") 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] = "&nbsp;";
    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";

}

?>
            </tr>
          </thead>
          <tbody>
<?php

$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 "            </tr>\n";

  if ($oddity == "odd" )
    $oddity = "even";
  else
    $oddity = "odd";

}

?>
          </tbody>
        </table>
      </div>
<?php
}

print_footer();