summaryrefslogtreecommitdiffstats
path: root/modules-available/dnbd3
diff options
context:
space:
mode:
authorSimon Rettberg2017-10-26 16:58:14 +0200
committerSimon Rettberg2017-10-26 16:58:14 +0200
commit017fb7924f3551004607aa74dbc0b3431d6c01a1 (patch)
treecb6b1e90f5a13b7b2f9b1567a1bc472ae5a0aa10 /modules-available/dnbd3
parent[dnbd3] Implement settings dialog for automatic proxies (diff)
downloadslx-admin-017fb7924f3551004607aa74dbc0b3431d6c01a1.tar.gz
slx-admin-017fb7924f3551004607aa74dbc0b3431d6c01a1.tar.xz
slx-admin-017fb7924f3551004607aa74dbc0b3431d6c01a1.zip
[dnbd3] Improve server sorting, main-warning, errormsg, Taskmanager intergration
Diffstat (limited to 'modules-available/dnbd3')
-rw-r--r--modules-available/dnbd3/api.inc.php7
-rw-r--r--modules-available/dnbd3/baseconfig/getconfig.inc.php5
-rw-r--r--modules-available/dnbd3/hooks/main-warning.inc.php25
-rw-r--r--modules-available/dnbd3/inc/dnbd3.inc.php10
-rw-r--r--modules-available/dnbd3/inc/dnbd3rpc.inc.php17
-rw-r--r--modules-available/dnbd3/inc/dnbd3util.inc.php41
-rw-r--r--modules-available/dnbd3/lang/de/messages.json2
-rw-r--r--modules-available/dnbd3/page.inc.php27
-rw-r--r--modules-available/dnbd3/templates/page-serverlist.html10
9 files changed, 117 insertions, 27 deletions
diff --git a/modules-available/dnbd3/api.inc.php b/modules-available/dnbd3/api.inc.php
new file mode 100644
index 00000000..68f8007c
--- /dev/null
+++ b/modules-available/dnbd3/api.inc.php
@@ -0,0 +1,7 @@
+<?php
+
+if (Dnbd3::isEnabled()) {
+ die('YES');
+} else {
+ die('NO');
+}
diff --git a/modules-available/dnbd3/baseconfig/getconfig.inc.php b/modules-available/dnbd3/baseconfig/getconfig.inc.php
index ae4d2924..d614dc6f 100644
--- a/modules-available/dnbd3/baseconfig/getconfig.inc.php
+++ b/modules-available/dnbd3/baseconfig/getconfig.inc.php
@@ -36,11 +36,12 @@ while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
}
$old = isset($servers[$ip]) ? $servers[$ip] : $defPrio;
if (is_null($row['locationid']) || !isset($locationsAssoc[$row['locationid']])) {
- $servers[$ip] = min($defPrio, $old);
+ $servers[$ip] = min($defPrio, $old) . '.' . mt_rand();
} else {
- $servers[$ip] = min($locationsAssoc[$row['locationid']], $old);
+ $servers[$ip] = min($locationsAssoc[$row['locationid']], $old) . '.' . mt_rand();
}
}
asort($servers, SORT_NUMERIC | SORT_ASC);
ConfigHolder::add('SLX_DNBD3_SERVERS', implode(' ', array_keys($servers)));
+ConfigHolder::add('SLX_VM_DNBD3', 'yes');
diff --git a/modules-available/dnbd3/hooks/main-warning.inc.php b/modules-available/dnbd3/hooks/main-warning.inc.php
new file mode 100644
index 00000000..258d03d0
--- /dev/null
+++ b/modules-available/dnbd3/hooks/main-warning.inc.php
@@ -0,0 +1,25 @@
+<?php
+
+if (Dnbd3::isEnabled()) {
+ $res = Database::simpleQuery('SELECT s.fixedip, s.lastseen AS dnbd3lastseen, s.errormsg, m.clientip, m.hostname
+ FROM dnbd3_server s
+ LEFT JOIN machine m USING (machineuuid)
+ WHERE errormsg IS NOT NULL');
+
+ while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+ $error = $row['errormsg'] ? $row['errormsg'] : '<unknown error>';
+ $lastSeen = date('d.m.Y H:i', $row['dnbd3lastseen']);
+ if ($row['fixedip'] === '<self>') {
+ Message::addError('dnbd3.main-dnbd3-unreachable', true, $error, $lastSeen);
+ continue;
+ }
+ if (!is_null($row['fixedip'])) {
+ $ip = $row['fixedip'];
+ } else {
+ $ip = $row['clientip'] . '/' . $row['hostname'];
+ }
+ Message::addWarning('dnbd3.dnbd3-proxy-unreachable', true, $ip, $error, $lastSeen);
+ }
+
+ unset($res);
+}
diff --git a/modules-available/dnbd3/inc/dnbd3.inc.php b/modules-available/dnbd3/inc/dnbd3.inc.php
index 905bdc68..eb41c000 100644
--- a/modules-available/dnbd3/inc/dnbd3.inc.php
+++ b/modules-available/dnbd3/inc/dnbd3.inc.php
@@ -12,6 +12,16 @@ class Dnbd3 {
public static function setEnabled($bool)
{
Property::set(self::PROP_ENABLED, $bool ? 1 : 0);
+ $task = Taskmanager::submit('Systemctl', array(
+ 'operation' => ($bool ? 'start' : 'stop'),
+ 'service' => 'dnbd3-server'
+ ));
+ return $task;
+ }
+
+ public static function getLocalStatus()
+ {
+
}
} \ No newline at end of file
diff --git a/modules-available/dnbd3/inc/dnbd3rpc.inc.php b/modules-available/dnbd3/inc/dnbd3rpc.inc.php
index 27713bfb..35d79a31 100644
--- a/modules-available/dnbd3/inc/dnbd3rpc.inc.php
+++ b/modules-available/dnbd3/inc/dnbd3rpc.inc.php
@@ -2,6 +2,10 @@
class Dnbd3Rpc {
+ const QUERY_UNREACHABLE = 1;
+ const QUERY_NOT_200 = 2;
+ const QUERY_NOT_JSON = 3;
+
/**
* Query given DNBD3 server for status information.
*
@@ -11,7 +15,7 @@ class Dnbd3Rpc {
* @param bool $clients include client list
* @param bool $images include image list
* @param bool $diskSpace include disk space stats
- * @return false|array the queried data as an array, or false on error
+ * @return int|array the queried data as an array, or false on error
*/
public static function query($server, $port, $stats, $clients, $images, $diskSpace)
{
@@ -33,9 +37,14 @@ class Dnbd3Rpc {
$url .= 'q=space&';
}
$str = Download::asString($url, 3, $code);
- if ($str === false || $code !== 200)
- return false;
- return json_decode($str, true);
+ if ($str === false)
+ return self::QUERY_UNREACHABLE;
+ if ($code !== 200)
+ return self::QUERY_NOT_200;
+ $ret = json_decode($str, true);
+ if (!is_array($ret))
+ return self::QUERY_NOT_JSON;
+ return $ret;
}
}
diff --git a/modules-available/dnbd3/inc/dnbd3util.inc.php b/modules-available/dnbd3/inc/dnbd3util.inc.php
index 03499413..a9b9241e 100644
--- a/modules-available/dnbd3/inc/dnbd3util.inc.php
+++ b/modules-available/dnbd3/inc/dnbd3util.inc.php
@@ -49,10 +49,26 @@ class Dnbd3Util {
// Now query them all
$NOW = time();
foreach ($servers as $server) {
- $data = Dnbd3Rpc::query($server['addr'], 5003, true, false, false, true);
- if (!is_array($data) || !isset($data['runId'])) {
- Database::exec('UPDATE dnbd3_server SET uptime = 0, clientcount = 0 WHERE serverid = :serverid',
- array('serverid' => $server['serverid']));
+ $port = 5003;
+ $data = Dnbd3Rpc::query($server['addr'], $port, true, false, false, true);
+ if ($data === Dnbd3Rpc::QUERY_UNREACHABLE) {
+ $error = 'No (HTTP) reply on port ' . $port;
+ } elseif ($data === Dnbd3Rpc::QUERY_NOT_200) {
+ $error = 'No HTTP 200 OK on port ' . $port;
+ } elseif ($data === Dnbd3Rpc::QUERY_NOT_JSON) {
+ $error = 'Reply to status query is not JSON';
+ } elseif (!is_array($data) || !isset($data['runId'])) {
+ if (is_array($data) && isset($data['errorMsg'])) {
+ $error = 'DNBD3: ' . $data['errorMsg'];
+ } else {
+ $error = 'Reply to status query has unexpected format';
+ }
+ } else {
+ $error = false;
+ }
+ if ($error !== false) {
+ Database::exec('UPDATE dnbd3_server SET uptime = 0, clientcount = 0, errormsg = :errormsg WHERE serverid = :serverid',
+ array('serverid' => $server['serverid'], 'errormsg' => $error));
continue;
}
// Seems up - since we only get absolute rx/tx values from the server, we have to prevent update race conditions
@@ -60,7 +76,7 @@ class Dnbd3Util {
Database::exec('UPDATE dnbd3_server SET runid = :runid, lastseen = :now, uptime = :uptime,
totalup = totalup + If(runid = :runid AND uptime <= :uptime, If(lastup < :up, :up - lastup, 0), If(:uptime < 1800, :up, 0)),
totaldown = totaldown + If(runid = :runid AND uptime <= :uptime, If(lastdown < :down, :down - lastdown, 0), If(:uptime < 1800, :up, 0)),
- lastup = :up, lastdown = :down, clientcount = :clientcount, disktotal = :disktotal, diskfree = :diskfree
+ lastup = :up, lastdown = :down, clientcount = :clientcount, disktotal = :disktotal, diskfree = :diskfree, errormsg = NULL
WHERE serverid = :serverid', array(
'runid' => $data['runId'],
'now' => $NOW,
@@ -93,7 +109,7 @@ class Dnbd3Util {
while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
$assignedLocs[] = $row['locationid'];
}
- $modeData = (array)json_decode($modeData, true);
+ $modeData = (array)json_decode($modeData, true) + self::defaultRunmodeConfig();
if (!empty($assignedLocs) && isset($modeData['firewall']) && $modeData['firewall']) {
// Get all sub-locations too
$recursiveLocs = $assignedLocs;
@@ -122,6 +138,8 @@ class Dnbd3Util {
WHERE s.machineuuid <> :uuid OR s.machineuuid IS NULL', array('uuid' => $machineUuid));
$public = array();
$private = array();
+ $self = Property::getServerIp();
+ $public[$self] = $self;
while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
$ip = $row['clientip'] ? $row['clientip'] : $row['fixedip'];
if ($ip === '<self>') {
@@ -132,13 +150,16 @@ class Dnbd3Util {
$public[$ip] = $ip;
}
} else {
+ unset($public[$ip]);
$private[$ip] = $ip;
}
}
if (!empty($public)) {
+ shuffle($public);
ConfigHolder::add('SLX_DNBD3_PUBLIC', implode(' ', $public));
}
if (!empty($private)) {
+ shuffle($private);
ConfigHolder::add('SLX_DNBD3_PRIVATE', implode(' ', $private));
}
if (isset($modeData['bgr']) && $modeData['bgr']) {
@@ -170,4 +191,12 @@ class Dnbd3Util {
return long2ip($start) . '/' . $mask;
}
+ public static function defaultRunmodeConfig()
+ {
+ return array(
+ 'bgr' => true,
+ 'firewall' => false
+ );
+ }
+
}
diff --git a/modules-available/dnbd3/lang/de/messages.json b/modules-available/dnbd3/lang/de/messages.json
index 630ebe31..05b8f968 100644
--- a/modules-available/dnbd3/lang/de/messages.json
+++ b/modules-available/dnbd3/lang/de/messages.json
@@ -1,5 +1,7 @@
{
+ "dnbd3-proxy-unreachable": "DNBD3-Proxy {{0}} ist offline seit {{2}}. ({{1}})",
"invalid-ipv4": "{{0}} ist keine g\u00fcltige IPv4-Adresse",
+ "main-dnbd3-unreachable": "Zentraler DNBD3-Server des Satelliten ist offline seit {{1}}. ({{0}})",
"not-automatic-server": "{{0}} wird nicht \u00fcber den Satelliten verwaltet",
"server-added": "Server {{0}} hinzugef\u00fcgt",
"server-already-exists": "Server {{0}} existiert bereits",
diff --git a/modules-available/dnbd3/page.inc.php b/modules-available/dnbd3/page.inc.php
index cfe86e48..feefc75d 100644
--- a/modules-available/dnbd3/page.inc.php
+++ b/modules-available/dnbd3/page.inc.php
@@ -40,13 +40,14 @@ class Page_Dnbd3 extends Page
$bgr = Request::post('bgr', false, 'bool');
$firewall = Request::post('firewall', false, 'bool');
RunMode::setRunMode($server['machineuuid'], 'dnbd3', 'proxy',
- json_encode(compact('bgr', 'firewall')));
+ json_encode(compact('bgr', 'firewall')), false);
}
private function toggleUsage()
{
$enabled = Request::post('enabled', false, 'bool');
- Dnbd3::setEnabled($enabled);
+ $task = Dnbd3::setEnabled($enabled);
+ Taskmanager::waitComplete($task, 5000);
}
private function saveServerLocations()
@@ -127,7 +128,8 @@ class Page_Dnbd3 extends Page
{
$dynClients = RunMode::getForMode(Page::getModule(), 'proxy', true, true);
$res = Database::simpleQuery('SELECT s.serverid, s.machineuuid, s.fixedip, s.lastseen AS dnbd3lastseen,
- s.uptime, s.totalup, s.totaldown, s.clientcount, s.disktotal, s.diskfree, Count(sxl.locationid) AS locations
+ s.uptime, s.totalup, s.totaldown, s.clientcount, s.disktotal, s.diskfree, Count(sxl.locationid) AS locations,
+ s.errormsg
FROM dnbd3_server s
LEFT JOIN dnbd3_server_x_location sxl USING (serverid)
GROUP BY s.serverid');
@@ -188,7 +190,7 @@ class Page_Dnbd3 extends Page
$server = $this->getServerById();
Render::addTemplate('page-header-servername', $server);
$data = Dnbd3Rpc::query($server['ip'], 5003,false, true, false, false);
- if ($data === false || !isset($data['clients'])) {
+ if (!is_array($data) || !isset($data['clients'])) {
Message::addError('server-unreachable');
return;
}
@@ -297,6 +299,9 @@ class Page_Dnbd3 extends Page
protected function doAjax()
{
+ User::load();
+ if (!User::isLoggedIn())
+ die('No');
$action = Request::any('action', false, 'string');
if ($action === 'servertest') {
$this->ajaxServerTest();
@@ -327,11 +332,13 @@ class Page_Dnbd3 extends Page
die('{"error": "Server with this IP already exists", "fatal": true}');
// Query
$reply = Dnbd3Rpc::query($ip, 5003,true, false, false, true);
- if ($reply === false)
+ if ($reply === Dnbd3Rpc::QUERY_UNREACHABLE)
die('{"error": "Could not reach server"}');
- if (!is_array($reply))
+ if ($reply === Dnbd3Rpc::QUERY_NOT_200)
+ die('{"error": "Server did not reply with 200 OK"}');
+ if ($reply === Dnbd3Rpc::QUERY_NOT_JSON)
die('{"error": "No JSON received from server"}');
- if (!isset($reply['uptime']) || !isset($reply['clientCount']))
+ if (!is_array($reply) || !isset($reply['uptime']) || !isset($reply['clientCount']))
die('{"error": "Reply does not suggest this is a dnbd3 server"}');
echo json_encode($reply);
}
@@ -348,10 +355,8 @@ class Page_Dnbd3 extends Page
echo 'Error: RunMode entry missing.';
return;
}
- $modeData = json_decode($rm[$server['machineuuid']]['modedata'], true);
- if (is_array($modeData)) {
- $server += $modeData;
- }
+ $modeData = (array)json_decode($rm[$server['machineuuid']]['modedata'], true);
+ $server += $modeData + Dnbd3Util::defaultRunmodeConfig();
echo Render::parse('fragment-server-settings', $server);
}
diff --git a/modules-available/dnbd3/templates/page-serverlist.html b/modules-available/dnbd3/templates/page-serverlist.html
index 2280511b..2d2ef803 100644
--- a/modules-available/dnbd3/templates/page-serverlist.html
+++ b/modules-available/dnbd3/templates/page-serverlist.html
@@ -43,7 +43,6 @@
<thead>
<tr>
<th></th>
- <th></th>
<th>{{lang_proxyServerTHead}}</th>
<th class="text-right">{{lang_storageSize}}</th>
<th class="text-right">{{lang_clientCount}}</th>
@@ -59,15 +58,13 @@
<tbody>
{{#list}}
<tr>
- <td>
+ <td class="text-right">
{{#slxOk}}
<span class="glyphicon glyphicon-ok text-success"></span>
{{/slxOk}}
{{#slxDown}}
<span class="glyphicon glyphicon-off"></span>
{{/slxDown}}
- </td>
- <td>
{{#uptime}}
<span class="glyphicon glyphicon-ok text-success"></span>
{{/uptime}}
@@ -88,6 +85,11 @@
title="{{lang_diskFree}}: {{diskfree_s}}">
{{disktotal_s}}
</div>
+ {{#errormsg}}
+ <div class="small text-nowrap text-danger" style="margin-right:-500px">
+ {{errormsg}}
+ </div>
+ {{/errormsg}}
</td>
<td data-sort="int" data-sort-default="desc" class="text-right">
{{#uptime}}