[Mapbender-commits] r9852 - in trunk/mapbender: lib resources/db/pgsql/UTF-8/update tools
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Tue Jan 30 11:33:31 PST 2018
Author: armin11
Date: 2018-01-30 11:33:31 -0800 (Tue, 30 Jan 2018)
New Revision: 9852
Modified:
trunk/mapbender/lib/class_Monitor.php
trunk/mapbender/resources/db/pgsql/UTF-8/update/update_2.7.4_to_2.8_pgsql_UTF-8.sql
trunk/mapbender/tools/mod_monitorCapabilities_main.php
trunk/mapbender/tools/mod_monitorCapabilities_write.php
Log:
New option to monitor wfs
Modified: trunk/mapbender/lib/class_Monitor.php
===================================================================
--- trunk/mapbender/lib/class_Monitor.php 2018-01-30 08:13:37 UTC (rev 9851)
+++ trunk/mapbender/lib/class_Monitor.php 2018-01-30 19:33:31 UTC (rev 9852)
@@ -50,25 +50,41 @@
var $remoteXML;
var $localXML;
var $capabilitiesDiff;
- var $tmpDir = null;
+ var $tmpDir = null;
+ var $serviceType; //WMS|WFS
+ var $serviceId;
- function __construct($reportFile, $autoUpdate, $tmpDir) {
+ function __construct($reportFile, $autoUpdate, $tmpDir, $serviceType="WMS") {
$this->tmpDir = $tmpDir;
-
+ $this->serviceType = $serviceType;
$this->reportFile = $tmpDir.$reportFile;
//$this->reportFile = $reportFile;
- $this->wmsId = $this->getTagOutOfXML($this->reportFile,'wms_id');
- $this->uploadId = $this->getTagOutOfXML($this->reportFile,'upload_id');
+ switch ($this->serviceType) {
+ case "WMS":
+ $this->serviceId = $this->getTagOutOfXML($this->reportFile,'wms_id',$this->serviceType);
+ break;
+ case "WFS":
+ $this->serviceId = $this->getTagOutOfXML($this->reportFile,'wfs_id',$this->serviceType);
+ break;
+ }
+ $this->uploadId = $this->getTagOutOfXML($this->reportFile,'upload_id',$this->serviceType);
$this->autoUpdate = $autoUpdate;
$e=new mb_notice("Monitor Report File: ".$this->reportFile);
- $e=new mb_notice("WMS ID: ".$this->wmsId);
- $this->capabilitiesURL = urldecode($this->getTagOutOfXML($this->reportFile,'getcapurl'));//read out from xml
+ $e=new mb_notice("Service ID: ".$this->serviceId);
+ $this->capabilitiesURL = urldecode($this->getTagOutOfXML($this->reportFile,'getcapurl',$this->serviceType));//read out from xml
$e=new mb_notice("GetCapURL: ".$this->capabilitiesURL);
set_time_limit(TIME_LIMIT);
$this->timestamp = microtime(TRUE);
//get authentication info for service
$admin = new administration();
- $auth = $admin->getAuthInfoOfWMS($this->wmsId);
+ switch ($this->serviceType) {
+ case "WMS":
+ $auth = $admin->getAuthInfoOfWMS($this->serviceId);
+ break;
+ case "WFS":
+ $auth = $admin->getAuthInfoOfWFS($this->serviceId);
+ break;
+ }
if ($auth['auth_type']==''){
unset($auth);
}
@@ -84,7 +100,7 @@
$this->remoteXML = $admin->char_encode($this->remoteXML);
$this->timestamp_cap_end=microtime(TRUE);
//read local copy out of xml
- $this->localXML = urldecode($this->getTagOutOfXML($this->reportFile,'getcapdoclocal'));
+ $this->localXML = urldecode($this->getTagOutOfXML($this->reportFile,'getcapdoclocal',$this->serviceType));
// service unreachable
if (!$this->remoteXML) {
$this->result = -1;
@@ -111,22 +127,24 @@
// capabilities files match
if ($this->localXML == $this->remoteXML) {
$this->result = 1;
- $this->comment = "WMS is stable.";
+ $this->comment = "Service is stable.";
//$e=new mb_exception("Compare ok - Docs ident");
}
// capabilities files don't match
else {
//check i a capabilities document was send, if not give an error
- $searchString = 'WMT_MS_Capabilities';
- $pos = strpos($this->remoteXML, $searchString);
- if ($pos === false) {
+ $searchStringWms = 'WMT_MS_Capabilities';
+ $searchStringWfs = 'WFS_Capabilities';
+ $posWms = strpos($this->remoteXML, $searchStringWms);
+ $posWfs = strpos($this->remoteXML, $searchStringWfs);
+ if ($posWms === false && $posWfs === false) {
$this->result = -1;
$this->comment = "Invalid getCapabilities request/document or service exception.";
}
else {
$this->result = 0;
- $this->comment = "WMS is not up to date.";
+ $this->comment = "Service is not up to date.";
$localXMLArray = explode("\n", $this->localXML);
$remoteXMLArray = explode("\n", $this->remoteXML);
$this->capabilitiesDiff = $this->outputDiffHtml($localXMLArray,$remoteXMLArray);
@@ -139,22 +157,40 @@
* 2) update the local backup of the capabilities doc if necessary
*/
if ($this->result != -1) {
- $this->mapURL = urldecode($this->getTagOutOfXML($this->reportFile,'getmapurl'));
+ switch ($this->serviceType) {
+ case "WMS":
+ $this->mapURL = urldecode($this->getTagOutOfXML($this->reportFile,'getmapurl',$this->serviceType));
+ break;
+ case "WFS":
+
+ break;
+ }
if (isset($auth)) {
- if ($this->isImage($this->mapURL,$auth)) {
- $this->returnsImage = 1;
- }
- else {
- $this->returnsImage = -1;
- }
-
+ switch ($this->serviceType) {
+ case "WMS":
+ if ($this->isImage($this->mapURL,$auth)) {
+ $this->returnsImage = 1;
+ } else {
+ $this->returnsImage = -1;
+ }
+ break;
+ case "WFS":
+
+ break;
+ }
} else {
- if ($this->isImage($this->mapURL)) {
- $this->returnsImage = 1;
+ switch ($this->serviceType) {
+ case "WMS":
+ if ($this->isImage($this->mapURL)) {
+ $this->returnsImage = 1;
+ } else {
+ $this->returnsImage = -1;
+ }
+ break;
+ case "WFS":
+
+ break;
}
- else {
- $this->returnsImage = -1;
- }
}
//Check for valid XML - validate it again wms 1.1.1 -some problems occur?
#$dtd = "../schemas/capabilities_1_1_1.dtd";
@@ -231,10 +267,20 @@
* Update database
*/
function updateInDB() {
- $sql = "UPDATE mb_monitor SET updated = $1, status = $2, image = $3, status_comment = $4, upload_url = $5, timestamp_end = $6, map_url = $7 , timestamp_begin = $10 WHERE upload_id = $8 AND fkey_wms_id=$9";
- $v = array($this->updated, $this->result, $this->returnsImage, $this->comment, $this->capabilitiesURL, $this->timestamp_cap_end, $this->mapURL, $this->uploadId, $this->wmsId, $this->timestamp_cap_begin);
- $t = array('s', 'i', 'i', 's', 's', 's', 's', 's', 'i','s');
- $res = db_prep_query($sql,$v,$t);
+ switch ($this->serviceType) {
+ case "WMS":
+ $sql = "UPDATE mb_monitor SET updated = $1, status = $2, image = $3, status_comment = $4, upload_url = $5, timestamp_end = $6, map_url = $7 , timestamp_begin = $10 WHERE upload_id = $8 AND fkey_wms_id=$9";
+ $v = array($this->updated, $this->result, $this->returnsImage, $this->comment, $this->capabilitiesURL, $this->timestamp_cap_end, $this->mapURL, $this->uploadId, $this->serviceId, $this->timestamp_cap_begin);
+ $t = array('s', 'i', 'i', 's', 's', 's', 's', 's', 'i','s');
+ $res = db_prep_query($sql,$v,$t);
+ break;
+ case "WFS":
+ $sql = "UPDATE mb_monitor SET updated = $1, status = $2, feature_content = $3, status_comment = $4, upload_url = $5, timestamp_end = $6, feature_urls = $7 , timestamp_begin = $10 WHERE upload_id = $8 AND fkey_wfs_id=$9";
+ $v = array($this->updated, $this->result, "feature_content - json", $this->comment, $this->capabilitiesURL, $this->timestamp_cap_end, "feature_urls - json", $this->uploadId, $this->serviceId, $this->timestamp_cap_begin);
+ $t = array('s', 'i', 's', 's', 's', 's', 's', 's', 'i','s');
+ $res = db_prep_query($sql,$v,$t);
+ break;
+ }
}
/**
* Update xml
@@ -264,14 +310,28 @@
$difftext .= "</body></html>";
//write to report
$xml=simplexml_load_file($this->reportFile);
- $xml->wms->image=$this->returnsImage;
- $xml->wms->status=$this->result;
- $xml->wms->getcapduration = intval(($this->timestamp_cap_end-$this->timestamp_cap_begin)*1000);
- $xml->wms->getcapdocremote = rawurlencode($this->remoteXML);
- $xml->wms->getcapdiff = rawurlencode($difftext);
- $xml->wms->comment=$this->comment;
- $xml->wms->getcapbegin=$this->timestamp_cap_begin;
- $xml->wms->getcapend=$this->timestamp_cap_end;
+ switch ($this->serviceType) {
+ case "WMS":
+ $xml->wms->image=$this->returnsImage;
+ $xml->wms->status=$this->result;
+ $xml->wms->getcapduration = intval(($this->timestamp_cap_end-$this->timestamp_cap_begin)*1000);
+ $xml->wms->getcapdocremote = rawurlencode($this->remoteXML);
+ $xml->wms->getcapdiff = rawurlencode($difftext);
+ $xml->wms->comment=$this->comment;
+ $xml->wms->getcapbegin=$this->timestamp_cap_begin;
+ $xml->wms->getcapend=$this->timestamp_cap_end;
+ break;
+ case "WFS":
+ //$xml->wfs->image=$this->returnsImage;
+ $xml->wfs->status=$this->result;
+ $xml->wfs->getcapduration = intval(($this->timestamp_cap_end-$this->timestamp_cap_begin)*1000);
+ $xml->wfs->getcapdocremote = rawurlencode($this->remoteXML);
+ $xml->wfs->getcapdiff = rawurlencode($difftext);
+ $xml->wfs->comment=$this->comment;
+ $xml->wfs->getcapbegin=$this->timestamp_cap_begin;
+ $xml->wfs->getcapend=$this->timestamp_cap_end;
+ break;
+ }
$xml->asXML($this->reportFile);
}
/*
@@ -309,9 +369,9 @@
/**
* Returns the objects out of the xml file
*/
- private function getTagOutOfXML($reportFile,$tagName) {
+ private function getTagOutOfXML($reportFile,$tagName,$serviceType) {
$xml=simplexml_load_file($reportFile);
- $result=(string)$xml->wms->$tagName;
+ $result=(string)$xml->{strtolower($serviceType)}->$tagName;
return $result;
}
/*
Modified: trunk/mapbender/resources/db/pgsql/UTF-8/update/update_2.7.4_to_2.8_pgsql_UTF-8.sql
===================================================================
--- trunk/mapbender/resources/db/pgsql/UTF-8/update/update_2.7.4_to_2.8_pgsql_UTF-8.sql 2018-01-30 08:13:37 UTC (rev 9851)
+++ trunk/mapbender/resources/db/pgsql/UTF-8/update/update_2.7.4_to_2.8_pgsql_UTF-8.sql 2018-01-30 19:33:31 UTC (rev 9852)
@@ -2079,3 +2079,138 @@
INSERT INTO gui_element(fkey_gui_id, e_id, e_pos, e_public, e_comment, e_title, e_element, e_src, e_attributes, e_left, e_top, e_width, e_height, e_z_index, e_more_styles, e_content, e_closetag, e_js_file, e_mb_mod, e_target, e_requires, e_url) VALUES('admin_metadata','mb_metadata_xml_import',1,1,'','','div','','',NULL ,NULL ,NULL ,NULL ,NULL ,'','','div','../plugins/mb_metadata_xml_import.js','','','','');
+-- add possibility to store wfs monitoring information in database
+
+-- first add new primary key
+
+ALTER TABLE mb_monitor DROP CONSTRAINT pk_mb_monitor;
+ALTER TABLE mb_monitor ADD COLUMN id SERIAL PRIMARY KEY;
+ALTER TABLE mb_monitor ALTER COLUMN fkey_wms_id DROP NOT NULL;
+ALTER TABLE mb_monitor ALTER COLUMN fkey_wms_id DROP DEFAULT;
+
+-- Column: fkey_wfs_id
+
+-- ALTER TABLE mb_monitor DROP COLUMN fkey_wfs_id;
+
+ALTER TABLE mb_monitor ADD COLUMN fkey_wfs_id integer;
+
+-- Foreign Key: fkey_monitor_wfs_id_wfs_id
+
+-- ALTER TABLE mb_monitor DROP CONSTRAINT fkey_monitor_wfs_id_wfs_id;
+
+ALTER TABLE mb_monitor
+ ADD CONSTRAINT fkey_monitor_wfs_id_wfs_id FOREIGN KEY (fkey_wfs_id)
+ REFERENCES wfs (wfs_id) MATCH SIMPLE
+ ON UPDATE CASCADE ON DELETE CASCADE;
+
+-- add new columns for json which holds the results of the getfeature requests and urls
+
+-- Column: feature_urls
+
+-- ALTER TABLE mb_monitor DROP COLUMN feature_urls;
+
+ALTER TABLE mb_monitor ADD COLUMN feature_urls character varying;
+
+-- Column: feature_content
+
+-- ALTER TABLE mb_monitor DROP COLUMN feature_content;
+
+ALTER TABLE mb_monitor ADD COLUMN feature_content character varying;
+
+-- Table: mb_wfs_availability
+
+-- DROP TABLE mb_wfs_availability;
+
+CREATE TABLE mb_wfs_availability
+(
+ fkey_wfs_id integer,
+ fkey_upload_id character varying,
+ last_status integer,
+ availability real,
+ feature_content character varying,
+ status_comment character varying,
+ average_resp_time real,
+ upload_url character varying,
+ feature_urls character varying,
+ cap_diff text DEFAULT ''::text,
+ CONSTRAINT mb_wfs_availability_fkey_wfs_id_wfs_id FOREIGN KEY (fkey_wfs_id)
+ REFERENCES wfs (wfs_id) MATCH SIMPLE
+ ON UPDATE CASCADE ON DELETE CASCADE
+)
+WITH (
+ OIDS=FALSE
+);
+ALTER TABLE mb_wfs_availability
+ OWNER TO postgres;
+
+
+-- alter trigger function for handling of wfs monitors
+-- 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
+ IF NEW.fkey_wms_id != null 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 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;
+ ELSE
+ IF NEW.fkey_wfs_id != null THEN
+ count_monitors := count(fkey_wfs_id) from mb_monitor where fkey_wfs_id=NEW.fkey_wfs_id;
+ --the following should be adopted if the duration of storing is changed!!!
+ average_res_cap := ((select average_resp_time from mb_wfs_availability where fkey_wfs_id=NEW.fkey_wfs_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_wfs_availability where fkey_wfs_id=NEW.fkey_wfs_id)*count_monitors + 100)/(count_monitors+1) as numeric),2);
+ ELSE --service has problems with caps
+ availability_new := round(cast(((select availability from mb_wfs_availability where fkey_wfs_id=NEW.fkey_wfs_id)*count_monitors)/(count_monitors+1) as numeric),2);
+ END IF;
+
+ UPDATE mb_wfs_availability SET average_resp_time=average_res_cap,last_status=NEW.status, availability=availability_new, feature_content=NEW.feature_content, status_comment=NEW.status_comment,upload_url=NEW.upload_url,feature_urls=NEW.feature_urls, cap_diff=NEW.cap_diff WHERE mb_wfs_availability.fkey_wfs_id=NEW.fkey_wfs_id;
+ RETURN NEW;
+ END IF;
+ END IF;
+ END IF;
+
+ IF TG_OP = 'INSERT' THEN
+ IF NEW.fkey_wms_id IS NOT NULL 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;
+ ELSE
+ IF NEW.fkey_wfs_id IS NOT NULL THEN
+ IF (select count(fkey_wfs_id) from mb_wfs_availability where fkey_wfs_id=NEW.fkey_wfs_id) > 0 then -- service is not new
+ UPDATE mb_wfs_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_wfs_id=NEW.fkey_wfs_id;
+ ELSE --service has not yet been monitored
+ INSERT INTO mb_wfs_availability (fkey_upload_id,fkey_wfs_id,last_status,status_comment,upload_url,feature_urls,cap_diff,average_resp_time,availability) VALUES (NEW.upload_id,NEW.fkey_wfs_id,NEW.status,NEW.status_comment,NEW.upload_url::text,NEW.feature_urls,NEW.cap_diff,0,100);
+ END IF;
+ RETURN NEW;
+ END IF;
+ END IF;
+ END IF;
+ RETURN NEW;
+ END;
+$BODY$
+ LANGUAGE plpgsql VOLATILE
+ COST 100;
+ALTER FUNCTION mb_monitor_after()
+ OWNER TO postgres;
+
Modified: trunk/mapbender/tools/mod_monitorCapabilities_main.php
===================================================================
--- trunk/mapbender/tools/mod_monitorCapabilities_main.php 2018-01-30 08:13:37 UTC (rev 9851)
+++ trunk/mapbender/tools/mod_monitorCapabilities_main.php 2018-01-30 19:33:31 UTC (rev 9852)
@@ -19,35 +19,32 @@
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
+//do db close at the most reasonable point
$admin = new administration();
-
$user = null;
$group = null;
$application = null;
-
+//commandline
$cl = false;
-// can be replaced by existing functionality
-function getConjunctionCharacter($onlineresource) {
- if(strstr($onlineresource, "?")) {
- $lastChar = substr($onlineresource,strlen($onlineresource)-1, 1);
- if ($lastChar == "?" || $lastChar == "&") {return "";}
- else{return "&";}
+function getTagsOutOfXML($reportFile,$tagsToReturn, $serviceType="wms") {
+ if (file_exists($reportFile)) {
+ $xml = simplexml_load_file($reportFile);
+ if ($xml == false) {
+ $e = new mb_exception("/tools/mod_monitorCapabilities.php: could not open file: ".$reportFile);
+ }
+ foreach($tagsToReturn as $tagName) {
+ $result[$tagName] = (string)$xml->{$serviceType}->$tagName;
+ }
+ } else {
+ $e = new mb_exception("/tools/mod_monitorCapabilities.php: could not find file: ".$reportFile);
}
- else {return "?";}
-}
-
-function getTagOutOfXML($reportFile,$tagName) {
- $xml=simplexml_load_file($reportFile);
- $result=(string)$xml->wms->$tagName;
return $result;
}
-//command line
+//commandline
if ($_SERVER["argc"] > 0) {
$cl = true;
-
if ($_SERVER["argc"] > 1 && $_SERVER["argv"][1] !== "") {
$param = $_SERVER["argv"][1];
if (substr($param, 0,5) == "user:") {
@@ -91,16 +88,13 @@
echo _mb("Parameter 'group' must be numeric.");
die;
}
-
//read out user who are subadmins - only their services are controlled - til now
- $sql = "SELECT fkey_mb_user_id FROM mb_user_mb_group WHERE " .
+ $sql = "SELECT DISTINCT fkey_mb_user_id FROM mb_user_mb_group WHERE " .
"fkey_mb_group_id = (SELECT mb_group_id FROM mb_group WHERE " .
"mb_group_id = $1)";
-
$v = array($group);
$t = array('i');
$res = db_prep_query($sql,$v,$t);
-
$userIdArray = array();
while ($row = db_fetch_array($res)) {
$userIdArray[] = $row["fkey_mb_user_id"];
@@ -131,98 +125,161 @@
die;
}
-
$user_id_all = $userIdArray;
echo $br ."Count of registrating users: " . count($user_id_all) . $br;
-$e = new mb_notice("mod_monitorCapabilities_main.php: count of group members: ".count($user_id_all));
+$e = new mb_exception("mod_monitorCapabilities_main.php: count of group members: ".count($user_id_all));
$time_array = array();
+
+//delete all temporary files (.xml and .png) from last monitoring
+array_map('unlink', glob(dirname(__FILE__)."/tmp/*.xml"));
+array_map('unlink', glob(dirname(__FILE__)."/tmp/*.png"));
+//define service types which should be monitored
+$serviceTypes = array('WMS','WFS');
+//for testing
+$serviceTypes = array('WMS');
+
for ($iz = 0; $iz < count($user_id_all); $iz++) {
+ $e = new mb_exception("/tools/mod_monitorCapabilities_main.php: - initialize monitoring for userid: ".$user_id_all[$iz]);
+ foreach ($serviceTypes as $serviceType) {
$userid = $user_id_all[$iz];
-
- //get all owned wms
- $wms_id_own = $admin->getWmsByWmsOwner($userid);
-
- // initialize monitoring processes
+ //get all owned services
+ switch ($serviceType) {
+ case "WMS":
+ $service_id_own = $admin->getWmsByWmsOwner($userid);
+ break;
+ case "WFS":
+ $service_id_own = $admin->getWfsByWfsOwner($userid);
+ break;
+ }
+ //initialize monitoring processes
echo "Starting monitoring cycle...$br";
- echo "WMS services are requested for availability.$br";
+ echo $serviceType." services are requested for availability.$br";
echo "Capabilities documents are requested and compared to the infos in the service db.$br";
$e = new mb_notice("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!
sleep(1);
-
$time = $time_array[$userid];
-
- for ($k=0; $k<count($wms_id_own); $k++) {
-
+ for ($k=0; $k<count($service_id_own); $k++) {
//get relevant data out of registry
- $sql = "SELECT wms_upload_url, wms_getcapabilities_doc, " .
- "wms_version, wms_getcapabilities, wms_getmap FROM wms " .
- "WHERE wms_id = $1";
- $v = array($wms_id_own[$k]);
+ switch ($serviceType) {
+ case "WMS":
+ $sql = "SELECT wms_upload_url as service_upload_url, wms_getcapabilities_doc as service_capabilities_doc, " .
+ "wms_version as service_version, wms_getcapabilities as service_getcapabilities, wms_getmap as service_getcontent FROM wms " .
+ "WHERE wms_id = $1";
+ break;
+ case "WFS":
+ $sql = "SELECT wfs_upload_url as service_upload_url, wfs_getcapabilities_doc as service_capabilities_doc, " .
+ "wfs_version as service_version, wfs_getcapabilities as service_getcapabilities, wfs_getfeature as service_getcontent FROM wfs " .
+ "WHERE wfs_id = $1";
+ break;
+ }
+ $v = array($service_id_own[$k]);
$t = array('i');
$res = db_prep_query($sql,$v,$t);
$someArray = db_fetch_array($res);
- $url = $someArray['wms_upload_url'];
-
- $capDoc = $someArray['wms_getcapabilities_doc'];
- $version = $someArray['wms_version'];
- $capabilities = $someArray['wms_getcapabilities'];
- $getmap = $someArray['wms_getmap'];
- $getMapUrl = getMapRequest($wms_id_own[$k], $version, $getmap);
+ $url = $someArray['service_upload_url'];
+ $capDoc = $someArray['service_capabilities_doc'];
+ $version = $someArray['service_version'];
+ $capabilities = $someArray['service_getcapabilities'];
+ $getcontent = $someArray['service_getcontent'];
+ switch ($serviceType) {
+ case "WMS":
+ $getMapUrl = getMapRequest($service_id_own[$k], $version, $getcontent);
+ break;
+ }
+ // for the case when there is no upload url - however - we need the
+ // url to the capabilities file - depends on the service type
- // for the case when there is no upload url - however - we need the
- // url to the capabilities file
if (!$url || $url == "") {
$capabilities=$admin->checkURL($capabilities);
- if ($version == "1.0.0" ) {
- $url = $capabilities . "REQUEST=capabilities&WMTVER=1.0.0";
+ switch ($serviceType) {
+ case "WMS":
+ if ($version == "1.0.0" ) {
+ $url = $capabilities . "REQUEST=capabilities&WMTVER=1.0.0";
+ } else {
+ $url = $capabilities . "REQUEST=GetCapabilities&" .
+ "SERVICE=WMS&VERSION=" . $version;
+ }
+ break;
+ case "WFS":
+ $url = $capabilities . "REQUEST=GetCapabilities&" .
+ "SERVICE=WFS&VERSION=" . $version;
+ break;
}
- else {
- $url = $capabilities . "REQUEST=GetCapabilities&" .
- "SERVICE=WMS&VERSION=" . $version;
- }
+
}
//$url is the url to the service which should be monitored in this cycle
//initialize monitoriung in db (set status=-2)
echo "initialize monitoring for user: " . $userid .
- " WMS: " . $wms_id_own[$k] . $br;
- $e = new mb_notice("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)";
+ " ".$serviceType.": " . $service_id_own[$k] . $br;
+ //$e = new mb_exception("/tools/mod_monitorCapabilities_main.php: ".$serviceType.": ".$service_id_own[$k]);
+ switch ($serviceType) {
+ case "WMS":
+ $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)";
- $v = array(
- $time,
- $wms_id_own[$k],
- "-2",
- "Monitoring is still in progress...",
- time(),
- "0",
- $url,
- "0"
- );
- $t = array('s', 'i', 's', 's', 's', 's', 's', 's');
- $res = db_prep_query($sql,$v,$t);
+ $v = array(
+ $time,
+ $service_id_own[$k],
+ "-2",
+ "Monitoring is still in progress...",
+ time(),
+ "0",
+ $url,
+ "0"
+ );
+ $t = array('s', 'i', 's', 's', 's', 's', 's', 's');
+ $res = db_prep_query($sql,$v,$t);
+ break;
+ case "WFS":
+ $sql = "INSERT INTO mb_monitor (upload_id, fkey_wfs_id, " .
+ "status, status_comment, timestamp_begin, timestamp_end, " .
+ "upload_url, updated)";
+ $sql .= "VALUES ($1, $2, $3, $4, $5, $6, $7, $8)";
+ $v = array(
+ $time,
+ $service_id_own[$k],
+ "-2",
+ "Monitoring is still in progress...",
+ time(),
+ "0",
+ $url,
+ "0"
+ );
+ $t = array('s', 'i', 's', 's', 's', 's', 's', 's');
+ $res = db_prep_query($sql,$v,$t);
+ break;
+ }
+
// Decode orig capabilities out of db cause they are converted before
// saving them while upload
//$capDoc=$admin->char_decode($capDoc);
// do the next to exchange the update before by another behavior! -
// look in class_monitor.php !
- $currentFilename = "wms_monitor_report_" . $time . "_" .
- $wms_id_own[$k] . "_" . $userid . ".xml";
+ $currentFilename = strtolower($serviceType)."_monitor_report_" . $time . "_" .
+ $service_id_own[$k] . "_" . $userid . ".xml";
$report = fopen(dirname(__FILE__)."/tmp/".$currentFilename,"a");
//$e = new mb_notice("mod_monitorCapabilities_main.php: currentFilename: ".dirname(__FILE__)."/tmp/".$currentFilename);
$lb = chr(13).chr(10);
fwrite($report,"<monitorreport>".$lb);
- fwrite($report,"<wms>".$lb);
- fwrite($report,"<wms_id>".$wms_id_own[$k]."</wms_id>".$lb);
+ switch ($serviceType) {
+ case "WMS":
+ fwrite($report,"<wms>".$lb);
+ fwrite($report,"<wms_id>".$service_id_own[$k]."</wms_id>".$lb);
+ break;
+ case "WFS":
+ fwrite($report,"<wfs>".$lb);
+ fwrite($report,"<wfs_id>".$service_id_own[$k]."</wfs_id>".$lb);
+ break;
+ }
fwrite($report,"<upload_id>".$time."</upload_id>".$lb);
fwrite($report,"<getcapbegin></getcapbegin>".$lb);
fwrite($report,"<getcapurl>".urlencode($url)."</getcapurl>".$lb);
@@ -231,29 +288,59 @@
fwrite($report,"<getcapdiff></getcapdiff>".$lb);
fwrite($report,"<getcapend></getcapend>".$lb);
fwrite($report,"<getcapduration></getcapduration>".$lb);
- fwrite($report,"<getmapurl>".urlencode($getMapUrl)."</getmapurl>".$lb);
+ switch ($serviceType) {
+ case "WMS":
+ fwrite($report,"<getmapurl>".urlencode($getMapUrl)."</getmapurl>".$lb);
+ break;
+ case "WFS":
+
+ break;
+ }
fwrite($report,"<status>-2</status>".$lb);
- fwrite($report,"<image></image>".$lb);
+ switch ($serviceType) {
+ case "WMS":
+ fwrite($report,"<image></image>".$lb);
+ break;
+ case "WFS":
+
+ break;
+ }
fwrite($report,"<comment>Monitoring in progress...</comment>".$lb);
fwrite($report,"<timeend></timeend>".$lb);
- fwrite($report,"</wms>".$lb);
+ switch ($serviceType) {
+ case "WMS":
+ fwrite($report,"</wms>".$lb);
+ break;
+ case "WFS":
+ fwrite($report,"</wfs>".$lb);
+ break;
+ }
fwrite($report,"</monitorreport>".$lb);
fclose($report);
-
// start of the monitoring processes on shell
// (maybe problematic for windows os)
//$e = new mb_notice("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));TODO what goes wrong here?
- exec($exec);
+ switch ($serviceType) {
+ case "WMS":
+ $exec = PHP_PATH . "php5 " . dirname(__FILE__) . "/mod_monitorCapabilities_write.php " .
+ $currentFilename ." ".$serviceType." 0 > /dev/null &";
+ /*
+ * @security_patch exec done
+ * Added escapeshellcmd()
+ */
+ #exec(escapeshellcmd($exec));TODO what goes wrong here?
+ exec($exec);
+ break;
+ case "WFS":
+ $exec = PHP_PATH . "php5 " . dirname(__FILE__) . "/mod_monitorCapabilities_write.php " .
+ $currentFilename ." ".$serviceType." 0 > /dev/null &";
+ exec($exec);
+ break;
+ }
}
echo "Monitoring start cycle for user: ".$userid." has ended. " .
- "(Altogether: " . count($wms_id_own) . " WMS monitorings started).$br";
+ "(Altogether: " . count($service_id_own) . " ".$serviceType." monitorings started).$br";
+ }
}
//set time limit (mapbender.conf)
set_time_limit(TIME_LIMIT);
@@ -263,6 +350,8 @@
sleep(TIME_LIMIT);
//when time limit has ended: begin to collect results for every registrating user
for ($iz = 0; $iz < count($user_id_all); $iz++) {
+ $e = new mb_exception("/tools/mod_monitorCapabilities.php - collect info from xml for user: ".$user_id_all[$iz]);
+ foreach ($serviceTypes as $serviceType) {
// when time limit has ended: begin to collect results for every
// registrating user
$problemOWS = array();//define array with id's of problematic wms
@@ -270,57 +359,111 @@
$userid = $user_id_all[$iz];
//get the old upload_id from the monitoring to identify it in the database
$time = $time_array[$userid];
- //read sequencialy all user owned xml files from tmp and update the
- // records in the database
- $wms_id_own = $admin->getWmsByWmsOwner($userid);
- for ($k = 0; $k < count($wms_id_own); $k++) {
+ //get all owned services
+ switch ($serviceType) {
+ case "WMS":
+ $service_id_own = $admin->getWmsByWmsOwner($userid);
+ $tagsToReturn = array("status", "comment", "getcapdiff", "image", "getcapbegin", "getcapend", "getmapurl");
+ break;
+ case "WFS":
+ $service_id_own = $admin->getWfsByWfsOwner($userid);
+ $tagsToReturn = array("status", "comment", "getcapdiff", "getcapbegin", "getcapend");
+ break;
+ }
+ for ($k = 0; $k < count($service_id_own); $k++) {
+ $monitorFile = dirname(__FILE__)."/tmp/".strtolower($serviceType)."_monitor_report_" . $time . "_" .
+ $service_id_own[$k] . "_".$userid.".xml";
- $monitorFile = "./tmp/wms_monitor_report_" . $time . "_" .
- $wms_id_own[$k] . "_".$userid.".xml";
- $e = new mb_notice("mod_monitorCapabilities_main.php: look for following file: ".$monitorFile);
- $status = getTagOutOfXML($monitorFile,"status");
- $status_comment = getTagOutOfXML($monitorFile,"comment");
- $cap_diff = getTagOutOfXML($monitorFile,"getcapdiff");
- $image = getTagOutOfXML($monitorFile,"image");
- $map_url = rawurldecode(getTagOutOfXML($monitorFile,"getmapurl"));
- $timestamp_begin = getTagOutOfXML($monitorFile,"getcapbegin");
- $timestamp_end = getTagOutOfXML($monitorFile,"getcapend");
+ $tags = getTagsOutOfXML($monitorFile, $tagsToReturn, strtolower($serviceType));
+ $status = $tags['status'];
+ $status_comment = $tags['comment'];
+ $cap_diff = $tags['getcapdiff'];
+ $timestamp_begin = $tags['getcapbegin'];
+ $timestamp_end = $tags['getcapend'];
+ switch ($serviceType) {
+ case "WMS":
+ $map_url = rawurldecode($tags['getmapurl']);
+ $image = rawurldecode($tags['image']);
+ break;
+ case "WFS":
+ //TODO
+ break;
+ }
+ switch ($serviceType) {
+ case "WMS":
+ $sql = "UPDATE mb_monitor SET updated = $1, status = $2, " .
+ "image = $3, status_comment = $4, timestamp_end = $5, " .
+ "map_url = $6 , timestamp_begin = $7, cap_diff = $8 " .
+ "WHERE upload_id = $9 AND fkey_wms_id=$10 ";
- $sql = "UPDATE mb_monitor SET updated = $1, status = $2, " .
- "image = $3, status_comment = $4, timestamp_end = $5, " .
- "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,
+ // push into problematic array
+ if ($status == '-1' or $status == '-2') {
+ $status_comment = "Monitoring process timed out.";
+ $status = '-1';
+ array_push($problemOWS,$service_id_own[$k]);
+ array_push($commentProblemOWS,$status_comment);
+ }
+ $v = array(
+ '0',
+ intval($status),
+ intval($image),
+ $status_comment,
+ (string)intval($timestamp_end),
+ $map_url,
+ (string)intval($timestamp_begin),
+ $cap_diff,
+ (string)$time,
+ $service_id_own[$k]
+ );
+ $t = array('s', 'i', 'i', 's', 's', 's', 's', 's','s','s');
+ $res = db_prep_query($sql,$v,$t);
+ break;
+ case "WFS":
+ $sql = "UPDATE mb_monitor SET updated = $1, status = $2, " .
+ "feature_content = $3, status_comment = $4, timestamp_end = $5, " .
+ "feature_urls = $6 , timestamp_begin = $7, cap_diff = $8 " .
+ "WHERE upload_id = $9 AND fkey_wfs_id=$10 ";
- // check if status = -2 return new comment and status -1,
- // push into problematic array
- if ($status == '-1' or $status == '-2') {
- $status_comment = "Monitoring process timed out.";
- $status = '-1';
- array_push($problemOWS,$wms_id_own[$k]);
- array_push($commentProblemOWS,$status_comment);
- }
-
- $v = array(
- '0',
- intval($status),
- intval($image),
- $status_comment,
- (string)intval($timestamp_end),
- $map_url,
- (string)intval($timestamp_begin),
- $cap_diff,
- (string)$time,
- $wms_id_own[$k]
- );
- $t = array('s', 'i', 'i', 's', 's', 's', 's', 's','s','s');
- $res = db_prep_query($sql,$v,$t);
+ // check if status = -2 return new comment and status -1,
+ // push into problematic array
+ if ($status == '-1' or $status == '-2') {
+ $status_comment = "Monitoring process timed out.";
+ $status = '-1';
+ array_push($problemOWS,$service_id_own[$k]);
+ array_push($commentProblemOWS,$status_comment);
+ }
+ $v = array(
+ '0',
+ intval($status),
+ "feature_content - json",
+ $status_comment,
+ (string)intval($timestamp_end),
+ "feature_urls - json",
+ (string)intval($timestamp_begin),
+ $cap_diff,
+ (string)$time,
+ $service_id_own[$k]
+ );
+ $t = array('s', 'i', 's', 's', 's', 's', 's', 's','s','s');
+ $res = db_prep_query($sql,$v,$t);
+ break;
+ }
}
$body = "";
echo "\nmonitoring info in db for user: ".$userid."\n";
//loop for single monitor requests that has problems
for ($i=0; $i < count($problemOWS); $i++) {
- $body .= $br . $admin->getWmsTitleByWmsId($problemOWS[$i]) .
- " (" . $problemOWS[$i] . "): " . $commentProblemOWS[$i] . $br;
+ switch ($serviceType) {
+ case "WMS":
+ $body .= $br . $admin->getWmsTitleByWmsId($problemOWS[$i]) .
+ " (" . $problemOWS[$i] . "): " . $commentProblemOWS[$i] . $br;
+ break;
+ case "WFS":
+ $body .= $br . $admin->getWfsTitleByWfsId($problemOWS[$i]) .
+ " (" . $problemOWS[$i] . "): " . $commentProblemOWS[$i] . $br;
+ break;
+ }
}
unset($problemOWS);
unset($commentProblemOWS);
@@ -348,5 +491,6 @@
echo "\n ERROR: " . $error_msg;
}
}
+ }
}
?>
Modified: trunk/mapbender/tools/mod_monitorCapabilities_write.php
===================================================================
--- trunk/mapbender/tools/mod_monitorCapabilities_write.php 2018-01-30 08:13:37 UTC (rev 9851)
+++ trunk/mapbender/tools/mod_monitorCapabilities_write.php 2018-01-30 19:33:31 UTC (rev 9852)
@@ -4,7 +4,7 @@
/*
* incoming parameters from command line
*/
-if ($_SERVER["argc"] != 3) {
+if ($_SERVER["argc"] != 4) {
echo _mb("Insufficient arguments! Monitoring aborted.");
$e = new mb_exception("Insufficient arguments! Monitoring aborted.");
die;
@@ -12,9 +12,11 @@
$reportFile = $_SERVER["argv"][1];
-$autoUpdate = intval($_SERVER["argv"][2]);
+$serviceType = $_SERVER["argv"][2];
-$monitor = new Monitor($reportFile, $autoUpdate, dirname(__FILE__)."/tmp/");
+$autoUpdate = intval($_SERVER["argv"][3]);
+$monitor = new Monitor($reportFile, $autoUpdate, dirname(__FILE__)."/tmp/", $serviceType);
+
$monitor->updateInXMLReport();
?>
More information about the Mapbender_commits
mailing list