svn commit: r748 - trunk/mapbender/http/php
christoph at osgeo.org
christoph at osgeo.org
Fri Aug 4 09:21:06 EDT 2006
Author: christoph
Date: 2006-08-04 13:21:05+0000
New Revision: 748
Modified:
trunk/mapbender/http/php/mod_monitorCapabilities_main.php
trunk/mapbender/http/php/mod_monitorCapabilities_read.php
Log:
update database for wms:
if timeout occured, change status from "monitoring in progress" to "monitoring timed out"
Modified: trunk/mapbender/http/php/mod_monitorCapabilities_main.php
Url: https://mapbender.osgeo.org/source/browse/mapbender/trunk/mapbender/http/php/mod_monitorCapabilities_main.php?view=diff&rev=748&p1=trunk/mapbender/http/php/mod_monitorCapabilities_main.php&p2=trunk/mapbender/http/php/mod_monitorCapabilities_main.php&r1=747&r2=748
==============================================================================
--- trunk/mapbender/http/php/mod_monitorCapabilities_main.php (original)
+++ trunk/mapbender/http/php/mod_monitorCapabilities_main.php 2006-08-04 13:21:05+0000
@@ -25,37 +25,56 @@
db_select_db(DB,$con);
$admin = new administration();
+$filename_array = explode("/", $PHP_SELF);
+$filename = $filename_array[count($filename_array)-1];
-//
-//
-//
-// Falls nicht alle GUIs des Root-Benutzers gewünscht sind, folgende Zeile auskommentieren...
-//
-$ownguis = $admin->getGuisByOwner(1);
-
-//
-//
-//
-//... und in diesen Array die GUI IDs eintragen, z.B.:
-//
-#$ownguis = array("gui", "gui1");
-// ACHTUNG: Mailbenachrichtigung muß ggf. angepaßt werden, s.u.!
-
-
-//
-//
-//
-// ... falls das monitoring von einem cronjob ausgelöst werden sollte, könnte die php-Datei
-// um einen Parameter erweitert werden, der die GUI ID enthält, z.B.
-// php mod_monitorCapabilities_main.php gui1
-//
-// dann wäre folgende Zeile einzukommentieren
-#$ownguis = array($_SERVER["argv"][1]);
-// ACHTUNG: Mailbenachrichtigung muß ggf. angepaßt werden, s.u.!
+$user = "root";
+$gui = "";
+/*
+ * Still have to work on this...
+ *
+// retrieve username and gui_id
+if ($_SERVER["argv"][0] != $filename) {
+ //browser
+ $user = $_REQUEST['user'];
+ $gui = $_REQUEST['gui'];
+}
+else {
+ //command line
+ $p1 = $_SERVER["argv"][1];
+ $p2 = $_SERVER["argv"][2];
+ if (substr($p1, 0,5) == "user:") {
+ $user = substr($p1);
+ if (substr($p2, 0,4) == "gui:") {
+ $gui = substr($p2);
+ }
+ }
+}
+*/
+$userid = $admin->getUserIdByUserName($user);
+
+if ($userid) {
+ $ownguis = $admin->getGuisByOwner($userid);
+ if ($gui) {
+ if (!$admin->guiExists($gui)) {
+ echo "GUI " . $gui . " doesn't exist.\n"; die();
+ }
+ elseif (in_array($gui, $ownguis)) {
+ $ownguis = array($gui);
+ }
+ else {
+ echo "User " . $user . " is not owner of GUI " . $gui . ".\n"; die();
+ }
+ }
+}
+else {
+ echo $user . " is not a valid username.\n"; die();
+}
$wms_id_own = $admin->getWmsByOwnGuis($ownguis);
+// initialise monitoring processes
echo "Starting monitoring cycle...\n<br/>\n<br/>";
echo "WMS services are requested for availabiltiy.\n<br/> ";
echo "Capabilities documents are requested and all changes synchronized with the database cache.\n<br>\n<br>";
@@ -63,7 +82,6 @@
$time = strval(time()-2);
for ($k=0; $k<count($wms_id_own); $k++) {
- //get upload url
$sql = "SELECT wms_upload_url FROM wms WHERE wms_id = $1";
$v = array($wms_id_own[$k]);
$t = array('i');
@@ -72,17 +90,14 @@
$url = $someArray[0];
if (!$upload_url || $upload_url == "") {
- // get the wms version, capabilities, capabilities_doc
$sql = "SELECT wms_version, wms_getcapabilities FROM wms WHERE wms_id = $1";
$v = array($wms_id_own[$k]);
$t = array('i');
$res = db_prep_query($sql,$v,$t);
$someArray = db_fetch_row($res);
-
+
$version = $someArray[0];
$capabilities = $someArray[1];
-
- // construct capabilities URL
if ($version == "1.0.0" ) {
$url = $capabilities . "REQUEST=capabilities&WMTVER=1.0.0";
}
@@ -104,16 +119,17 @@
$exec = PHP_PATH . "php mod_monitorCapabilities_write.php ".$wms_id_own[$k]." ".$time." 1 > ../tmp/output.txt &";
}
else {
-# $exec = PHP_PATH . "php mod_monitorCapabilities_write.php ".$wms_id_own[$k]." ".$time." 0 > output_" . $time . "_" . $wms_id_own[$k] . ".txt &";
$exec = PHP_PATH . "php mod_monitorCapabilities_write.php ".$wms_id_own[$k]." ".$time." 0 > ../tmp/output.txt &";
}
exec($exec);
}
echo "Monitoring Cycle completed (total: " . count($wms_id_own) . " wms).\n\n";
set_time_limit(2*TIME_LIMIT);
+
+// wait until all monitoring processes are finished
sleep(TIME_LIMIT);
-$sql = "SELECT fkey_wms_id, status, status_comment, upload_url FROM mb_monitor WHERE upload_id = $1";
+$sql = "SELECT fkey_wms_id, status, status_comment, timestamp_begin, timestamp_end, upload_url FROM mb_monitor WHERE upload_id = $1";
$v = array($time);
$t = array('i');
$res = db_prep_query($sql,$v,$t);
@@ -124,27 +140,39 @@
$wms_id[$cnt] = db_result($res,$cnt,"fkey_wms_id");
$comment[$cnt] = db_result($res,$cnt,"status_comment");
$upload_url[$cnt] = db_result($res,$cnt,"upload_url");
+ $timestamp_begin[$cnt] = db_result($res,0,"timestamp_begin");
+ $timestamp_end[$cnt] = db_result($res,0,"timestamp_end");
$cnt++;
}
+
$body = "";
for ($i=0; $i<$cnt; $i++) {
+ // if monitoring is still in progress and time limit has expired, update database
+ if ($status[$i] == -2 && intval(time())-intval($timestamp_begin[$i]) > intval(TIME_LIMIT)) {
+ $comment[$i] = "Monitoring process timed out.";
+ $status[$i] = -1;
+ $new_sql = "UPDATE mb_monitor SET status = '-1', status_comment = 'Monitoring process timed out.', timestamp_end = $1 WHERE fkey_wms_id = $2 AND upload_id = $3";
+ $new_v = array((intval($upload_id[$i])+intval(TIME_LIMIT)), $wms_id[$i], $time);
+ $new_t = array('s', 'i', 's');
+ $new_res = db_prep_query($new_sql,$new_v,$new_t);
+ }
+ // compose mail message
if ($status[$i] == -1) {
$body .= $admin->getWmsTitleByWmsId($wms_id[$i]) . " (" . $wms_id[$i] . "): " . $comment[$i] . "\n\n";
}
}
+
+// Send an email to the user
if ($body) {
$error_msg = "";
- if ($admin->getEmailByUserId(1)) {
- $admin->sendEmail(MAILADMIN, MAILADMINNAME, $admin->getEmailByUserId(1), $admin->getUserNameByUserId(1), "WMS monitor report " . date("F j, Y, G:i:s", $time), utf8_decode($body), &$error_msg);
+ if ($admin->getEmailByUserId($userid)) {
+ $admin->sendEmail(MAILADMIN, MAILADMINNAME, $admin->getEmailByUserId($userid), $user, "WMS monitor report " . date("F j, Y, G:i:s", $time), utf8_decode($body), &$error_msg);
}
else {
- $error_msg = "Email address of user '" . $admin->getUserNameByUserId(1) . "' unknown!\n";
+ $error_msg = "Email address of user '" . $admin->getUserNameByUserId($userid) . "' unknown!\n";
}
if ($error_msg) {
echo "\n ERROR: " . $error_msg;
}
}
-
-
-
?>
Modified: trunk/mapbender/http/php/mod_monitorCapabilities_read.php
Url: https://mapbender.osgeo.org/source/browse/mapbender/trunk/mapbender/http/php/mod_monitorCapabilities_read.php?view=diff&rev=748&p1=trunk/mapbender/http/php/mod_monitorCapabilities_read.php&p2=trunk/mapbender/http/php/mod_monitorCapabilities_read.php&r1=747&r2=748
==============================================================================
--- trunk/mapbender/http/php/mod_monitorCapabilities_read.php (original)
+++ trunk/mapbender/http/php/mod_monitorCapabilities_read.php 2006-08-04 13:21:05+0000
@@ -100,7 +100,7 @@
$upload_url[$wms[$i]] = db_result($res,0,"upload_url");
$updated[$wms[$i]] = db_result($res,0,"updated");
- if ($comment[$wms[$i]] == "Monitoring is still in progress..." && intval(time())-intval($timestamp_begin[$wms[$i]]) > intval(TIME_LIMIT)) {
+ if ($status[$wms[$i]] == -2 && intval(time())-intval($timestamp_begin[$wms[$i]]) > intval(TIME_LIMIT)) {
$comment[$wms[$i]] = "Monitoring process timed out.";
$new_sql = "UPDATE mb_monitor SET status = '-1', status_comment = 'Monitoring process timed out.', timestamp_end = $1 WHERE fkey_wms_id = $2 AND upload_id = $3";
More information about the Mapbender_commits
mailing list