[Mapbender-commits] r7439 - in trunk/mapbender: http/php lib resources/db/pgsql/UTF-8/update tools

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Wed Jan 12 11:53:53 EST 2011


Author: armin11
Date: 2011-01-12 08:53:53 -0800 (Wed, 12 Jan 2011)
New Revision: 7439

Added:
   trunk/mapbender/tools/monitorCapabilities.sh
Modified:
   trunk/mapbender/http/php/mod_monitorCapabilities_read.php
   trunk/mapbender/lib/class_Monitor.php
   trunk/mapbender/resources/db/pgsql/UTF-8/update/update_2.7rc1_to_2.7rc2_pgsql_UTF-8.sql
   trunk/mapbender/tools/mod_monitorCapabilities_main.php
   trunk/mapbender/tools/mod_monitorCapabilities_write.php
Log:
Some changes from geoportal.rlp

Modified: trunk/mapbender/http/php/mod_monitorCapabilities_read.php
===================================================================
--- trunk/mapbender/http/php/mod_monitorCapabilities_read.php	2011-01-12 13:52:15 UTC (rev 7438)
+++ trunk/mapbender/http/php/mod_monitorCapabilities_read.php	2011-01-12 16:53:53 UTC (rev 7439)
@@ -22,6 +22,7 @@
 require_once(dirname(__FILE__)."/../classes/class_administration.php");
 require_once(dirname(__FILE__)."/../classes/class_user.php");
 require_once(dirname(__FILE__)."/../classes/class_wms.php");
+require_once(dirname(__FILE__)."/../classes/class_mb_exception.php");
 ?>
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 <html>
@@ -94,15 +95,18 @@
 	}
 	echo "<br>Please note: The updated services need to be monitored again in order to update the database.<br><br>";
 }
-
+$e = new mb_exception("mod_monitorCapabilities_read.php: userId: ".$_SESSION["mb_user_id"]);
 $sql = "SELECT DISTINCT mb_monitor.fkey_wms_id FROM mb_monitor, wms " . 
 	"WHERE mb_monitor.fkey_wms_id = wms.wms_id AND wms.wms_owner = $1";
+
 $res = db_prep_query($sql, array($_SESSION["mb_user_id"]), array("i"));
+
 $wms = array();
+
 while($row = db_fetch_array($res)){
 	$wms[] = $row["fkey_wms_id"];
+	$e = new mb_exception("mod_monitorCapabilities_read.php: wmsId: ".$row["fkey_wms_id"]);
 }
-
 $wms_id = array();
 $status = array();
 $upload_id = array();
@@ -137,7 +141,7 @@
 	}
 	
 	$sql = "SELECT status, status_comment, timestamp_begin, timestamp_end, " . 
-		"upload_url, updated, image, map_url, caps_diff FROM mb_monitor, wms " . 
+		"upload_url, updated, image, map_url, cap_diff FROM mb_monitor, wms " . 
 		"WHERE upload_id = $1 AND fkey_wms_id = $2 AND wms_owner = $3 ORDER BY status, " . 
 		"status_comment, timestamp_end, fkey_wms_id";
 	$v = array($upload_id[$wms[$i]], $wms_id[$wms[$i]], $user->id);
@@ -152,7 +156,7 @@
 	$updated[$wms[$i]] = db_result($res,0,"updated");
 	$mapurl[$wms[$i]] = db_result($res,0,"map_url");
 	$image[$wms[$i]] = db_result($res,0,"image");
-	$caps_diff[$wms[$i]] = db_result($res,0,"caps_diff");
+	$cap_diff[$wms[$i]] = db_result($res,0,"cap_diff");
 	
  	if ($status[$wms[$i]] == -2 && 
 		intval(time())-intval($timestamp_begin[$wms[$i]]) > intval(TIME_LIMIT)) 
@@ -293,7 +297,7 @@
 
 	$str .= "\n\t\t<td><input type=button value='details' onclick=\"var newWindow = window.open('../php/mod_monitorCapabilities_read_single.php?wmsid=".$wms_id[$k]."','wms','width=500,height=700,scrollbars');newWindow.href.location='test.php'\"></td>";
 	$str .= "\n\t\t\t<td>";	
-	if ($caps_diff[$k] != "")
+	if ($cap_diff[$k] != "")
 		$str .= "<a href='mod_monitorCapabilities_read_single_diff.php?wmsid=".$wms_id[$k]."&upload_id=".$upload_id[$k]."' target=_blank>view</a>";
 	$str .= "</td></tr>";
 

Modified: trunk/mapbender/lib/class_Monitor.php
===================================================================
--- trunk/mapbender/lib/class_Monitor.php	2011-01-12 13:52:15 UTC (rev 7438)
+++ trunk/mapbender/lib/class_Monitor.php	2011-01-12 16:53:53 UTC (rev 7439)
@@ -64,8 +64,8 @@
 		$this->wmsId = $this->getTagOutOfXML($this->reportFile,'wms_id');
 		$this->uploadId = $this->getTagOutOfXML($this->reportFile,'upload_id');
 		$this->autoUpdate = $autoUpdate;
-		$e=new mb_notice("Monitor Report File: ".$this->reportFile);
-		$e=new mb_notice("WMS ID: ".$this->wmsId);
+		$e=new mb_exception("Monitor Report File: ".$this->reportFile);
+		$e=new mb_exception("WMS ID: ".$this->wmsId);
 		$this->capabilitiesURL = urldecode($this->getTagOutOfXML($this->reportFile,'getcapurl'));//read out from xml
 		$e=new mb_notice("GetCapURL: ".$this->capabilitiesURL);
 

Modified: trunk/mapbender/resources/db/pgsql/UTF-8/update/update_2.7rc1_to_2.7rc2_pgsql_UTF-8.sql
===================================================================
--- trunk/mapbender/resources/db/pgsql/UTF-8/update/update_2.7rc1_to_2.7rc2_pgsql_UTF-8.sql	2011-01-12 13:52:15 UTC (rev 7438)
+++ trunk/mapbender/resources/db/pgsql/UTF-8/update/update_2.7rc1_to_2.7rc2_pgsql_UTF-8.sql	2011-01-12 16:53:53 UTC (rev 7439)
@@ -77,3 +77,46 @@
   COST 100;
 ALTER FUNCTION f_collect_searchtext_wmc(integer) OWNER TO postgres;
 
+--Bugfix in integral monitoring table
+
+-- Function: mb_monitor_after()
+
+-- DROP FUNCTION mb_monitor_after();
+
+CREATE OR REPLACE FUNCTION mb_monitor_after()
+  RETURNS "trigger" AS
+$BODY$DECLARE
+   availability_new REAL;
+   average_res_cap REAL;
+   count_monitors REAL;
+    BEGIN
+     IF TG_OP = 'UPDATE' THEN
+     
+     count_monitors := count(fkey_wms_id) from mb_monitor where fkey_wms_id=NEW.fkey_wms_id;
+      --the following should be adopted if the duration of storing is changed!!!
+      average_res_cap := ((select average_resp_time from mb_wms_availability where fkey_wms_id=NEW.fkey_wms_id)*count_monitors+(NEW.timestamp_end-NEW.timestamp_begin))/(count_monitors+1);
+
+     IF NEW.status > -1 THEN --service gives caps
+      availability_new := round(cast(((select availability from mb_wms_availability where fkey_wms_id=NEW.fkey_wms_id)*count_monitors + 100)/(count_monitors+1) as numeric),2);
+     ELSE --service has problems with caps
+      availability_new := round(cast(((select availability from mb_wms_availability where fkey_wms_id=NEW.fkey_wms_id)*count_monitors)/(count_monitors+1) as numeric),2);
+     END IF;
+
+      UPDATE mapbender.mb_wms_availability SET average_resp_time=average_res_cap,last_status=NEW.status, availability=availability_new, image=NEW.image, status_comment=NEW.status_comment,upload_url=NEW.upload_url,map_url=NEW.map_url, cap_diff=NEW.cap_diff WHERE mb_wms_availability.fkey_wms_id=NEW.fkey_wms_id;
+      RETURN NEW;
+     END IF;
+     IF TG_OP = 'INSERT' THEN
+
+	IF (select count(fkey_wms_id) from mb_wms_availability where fkey_wms_id=NEW.fkey_wms_id) > 0  then -- service is not new
+			UPDATE mb_wms_availability set fkey_upload_id=NEW.upload_id,last_status=NEW.status,status_comment=NEW.status_comment,upload_url=NEW.upload_url, cap_diff=NEW.cap_diff where fkey_wms_id=NEW.fkey_wms_id;
+		else --service has not yet been monitored
+			INSERT INTO mb_wms_availability (fkey_upload_id,fkey_wms_id,last_status,status_comment,upload_url,map_url,cap_diff,average_resp_time,availability) VALUES (NEW.upload_id,NEW.fkey_wms_id,NEW.status,NEW.status_comment,NEW.upload_url::text,NEW.map_url,NEW.cap_diff,0,100);
+		end if;
+
+      RETURN NEW;
+     END IF;
+    END;
+$BODY$
+  LANGUAGE 'plpgsql' VOLATILE;
+ALTER FUNCTION mb_monitor_after() OWNER TO postgres;
+

Modified: trunk/mapbender/tools/mod_monitorCapabilities_main.php
===================================================================
--- trunk/mapbender/tools/mod_monitorCapabilities_main.php	2011-01-12 13:52:15 UTC (rev 7438)
+++ trunk/mapbender/tools/mod_monitorCapabilities_main.php	2011-01-12 16:53:53 UTC (rev 7439)
@@ -17,6 +17,7 @@
 require_once dirname(__FILE__) ."/../http/classes/class_administration.php";
 require_once dirname(__FILE__) ."/../tools/mod_monitorCapabilities_defineGetMapBbox.php";
 require_once dirname(__FILE__) ."/../http/classes/class_bbox.php";
+require_once(dirname(__FILE__)."/../http/classes/class_mb_exception.php");
 
 #do db close at the most reasonable point 
 $admin = new administration();
@@ -79,11 +80,13 @@
 	$br = "\n\n";
 }
 
+$e = new mb_exception("mod_monitorCapabilities_main.php: group: ".$group);
+
 $userIdArray = array();
 
 //loop for doing the monitor for all registrating institutions ****************
 if (!is_null($group)) {
-	echo "monitoriing " . $group;
+	echo "monitoring " . $group;
 	if (!is_numeric($group)) {
 		echo _mb("Parameter 'group' must be numeric.");
 		die;
@@ -125,12 +128,13 @@
 
 if (count($userIdArray) === 0) {
 	echo _mb("No user found for the given parameters.");
+
 	die;
 }
 
 $user_id_all = $userIdArray;
 echo $br ."Count of registrating users: " . count($user_id_all) . $br;
-
+$e = new mb_exception("mod_monitorCapabilities_main.php: count of group members: ".count($user_id_all));
 $time_array = array();
 
 for ($iz = 0; $iz < count($user_id_all); $iz++) {
@@ -143,7 +147,7 @@
 	echo "Starting monitoring cycle...$br";
 	echo "WMS services are requested for availability.$br"; 
 	echo "Capabilities documents are requested and compared to the infos in the service db.$br";
-
+	$e = new mb_exception("mod_monitorCapabilities_main.php: monitoring for user: ".$userid);
 	//new: time user-monitoring cycle must stored in array
 	$time_array[$userid] = strval(time());
 	//wait 2 seconds to give enough time between to different users the time can differ also for one user!
@@ -185,7 +189,8 @@
 		//initialize monitoriung in db (set status=-2)
 		echo "initialize monitoring for user: " . $userid . 
 			" WMS: " . $wms_id_own[$k] . $br;
-			$sql = "INSERT INTO mb_monitor (upload_id, fkey_wms_id, " . 
+		$e = new mb_exception("mod_monitorCapabilities_main.php: wms: ".$wms_id_own[$k]);
+		$sql = "INSERT INTO mb_monitor (upload_id, fkey_wms_id, " . 
 				"status, status_comment, timestamp_begin, timestamp_end, " . 
 				"upload_url, updated)";
 		$sql .= "VALUES ($1, $2, $3, $4, $5, $6, $7, $8)";
@@ -236,13 +241,15 @@
 
 		// start of the monitoring processes on shell 
 		// (maybe problematic for windows os)
+		$e = new mb_exception("mod_monitorCapabilities_main.php: php call: ".$exec);
    		$exec = PHP_PATH . "php5 " . dirname(__FILE__) . "/mod_monitorCapabilities_write.php " . 
 			$currentFilename . " 0 > /dev/null &";
 		/*
 		 * @security_patch exec done
 		 * Added escapeshellcmd()
 		 */
-   		exec(escapeshellcmd($exec));
+   		#exec(escapeshellcmd($exec));TODO what goes wrong here?
+		exec($exec);
 	}
 	echo "Monitoring start cycle for user: ".$userid." has ended. " . 
 		"(Altogether: " . count($wms_id_own) . " WMS monitorings started).$br";
@@ -266,8 +273,10 @@
 	// records in the database 
 	$wms_id_own = $admin->getWmsByWmsOwner($userid);
 	for ($k = 0; $k < count($wms_id_own); $k++) {
+		
 		$monitorFile = "./tmp/wms_monitor_report_" . $time . "_" . 
 			$wms_id_own[$k] . "_".$userid.".xml";
+		$e = new mb_exception("mod_monitorCapabilities_main.php: look for following file: ".$monitorFile);
 		$status = getTagOutOfXML($monitorFile,"status");
 		$status_comment = getTagOutOfXML($monitorFile,"comment");
 		$cap_diff = getTagOutOfXML($monitorFile,"getcapdiff");
@@ -278,7 +287,7 @@
 
 		$sql = "UPDATE mb_monitor SET updated = $1, status = $2, " . 
 			"image = $3, status_comment = $4, timestamp_end = $5, " . 
-			"map_url = $6 , timestamp_begin = $7, caps_diff = $8 " . 
+			"map_url = $6 , timestamp_begin = $7, cap_diff = $8 " . 
 			"WHERE upload_id = $9 AND fkey_wms_id=$10 ";
 
 		// check if status = -2 return new comment and status -1, 
@@ -339,4 +348,4 @@
 		}
 	}
 }
-?>
\ No newline at end of file
+?>

Modified: trunk/mapbender/tools/mod_monitorCapabilities_write.php
===================================================================
--- trunk/mapbender/tools/mod_monitorCapabilities_write.php	2011-01-12 13:52:15 UTC (rev 7438)
+++ trunk/mapbender/tools/mod_monitorCapabilities_write.php	2011-01-12 16:53:53 UTC (rev 7439)
@@ -1,11 +1,12 @@
 <?php
 require_once(dirname(__FILE__)."/../lib/class_Monitor.php");
-
+require_once(dirname(__FILE__)."/../http/classes/class_mb_exception.php");
 /*
  * incoming parameters from command line
  */
 if ($_SERVER["argc"] != 3) {
 	echo _mb("Insufficient arguments! Monitoring aborted.");
+	$e = new mb_exception("Insufficient arguments! Monitoring aborted.");
 	die;
 }
 
@@ -15,5 +16,6 @@
 
 $monitor = new Monitor($reportFile, $autoUpdate, dirname(__FILE__)."/tmp/");
 
+
 $monitor->updateInXMLReport();
 ?>

Added: trunk/mapbender/tools/monitorCapabilities.sh
===================================================================
--- trunk/mapbender/tools/monitorCapabilities.sh	                        (rev 0)
+++ trunk/mapbender/tools/monitorCapabilities.sh	2011-01-12 16:53:53 UTC (rev 7439)
@@ -0,0 +1,3 @@
+. /etc/profile
+cd /data/mapbender/tools/
+php5 /data/mapbender/tools/mod_monitorCapabilities_main.php group:36 > /dev/null



More information about the Mapbender_commits mailing list