From 2c71cf835a85cdd2c22cc49c605a4c1726e1fee2 Mon Sep 17 00:00:00 2001 From: Elena.Budnik <ebudnik@irap.omp.eu> Date: Mon, 7 Oct 2019 14:44:51 +0200 Subject: [PATCH] THEMIS update start stop --- src/CALLEXT/getData.php | 12 +++++++----- src/DATA/MANAGER/DDBaseMgr.php | 20 ++++++++++++++++++-- src/REMOTEDATA/RemoteDataCenterClass.php | 50 ++++++++++++++++++++++++++++++++++++++++++++++++-- src/REMOTEDATA/THEMIS.php | 11 +++++++---- src/REMOTEDATA/makeProxy.php | 7 +++++-- 5 files changed, 85 insertions(+), 15 deletions(-) diff --git a/src/CALLEXT/getData.php b/src/CALLEXT/getData.php index 9613ad5..0639342 100644 --- a/src/CALLEXT/getData.php +++ b/src/CALLEXT/getData.php @@ -68,12 +68,14 @@ $ncFiles = $center->getData($id, $start, $stop); // Add nc to Vi - $nc_prefix = strlen($id) > RemoteDataCenterClass::$MAX_VI_NAME_LENGTH ? + if ( strpos($id, ":") !== false ) { + $nc_prefix = substr($id,strpos($id, ":")+1); + } else { + $nc_prefix = strlen($id) > RemoteDataCenterClass::$MAX_VI_NAME_LENGTH ? substr($id, 0, RemoteDataCenterClass::$MAX_VI_NAME_LENGTH - 1): $id; - -// $nc_prefix = strpos($id, ":") !== false ? -// substr($id,strpos($id, ":")+1) : $id; - + } + + $baseMgr = new DDBaseMgr(); // $baseMgr->setViId($id); $baseMgr->setViInfo(strtolower($nc_prefix)); diff --git a/src/DATA/MANAGER/DDBaseMgr.php b/src/DATA/MANAGER/DDBaseMgr.php index 4b459a5..8065867 100644 --- a/src/DATA/MANAGER/DDBaseMgr.php +++ b/src/DATA/MANAGER/DDBaseMgr.php @@ -18,7 +18,7 @@ class DDBaseMgr function __construct() { - $this->DDsys = getenv("DDBASE")."/DDsys.xml"; + $this->DDsys = getenv("DDBASE")."/DDsys.xml"; $this->DDsysDoc = new DomDocument(); $this->DDsysDoc->preserveWhiteSpace = false; $this->DDsysDoc->formatOutput = true; @@ -243,7 +243,7 @@ class DDBaseMgr $WORKING_DIR = getcwd(); chdir($this->ViDir); system("./clean"); - + foreach ($ncFiles as $ncFile) { //TODO errors @@ -291,6 +291,22 @@ class DDBaseMgr chdir($currDir); } + public function updateViStop($globaStop) + { + $xml_dom = new DomDocument("1.0"); + $xml_dom->load($this->location."/".$this->info_xml); + $stopNode = $xml_dom->getElementsByTagName("GlobalStop")->item(0); + $startNode->nodeValue = $globalStop; + + $xml_dom->save($this->location."/".$this->info_xml); + + $currDir = getcwd(); + chdir($this->location); + system("infoLocal2nc ".$this->info_xml." ".$this->info); + chdir($currDir); + } + + public function cleanRemote($opt = NULL) { $res_before = disk_free_space(getenv("DDBASE")); diff --git a/src/REMOTEDATA/RemoteDataCenterClass.php b/src/REMOTEDATA/RemoteDataCenterClass.php index da08880..9f84da9 100644 --- a/src/REMOTEDATA/RemoteDataCenterClass.php +++ b/src/REMOTEDATA/RemoteDataCenterClass.php @@ -31,6 +31,7 @@ abstract class RemoteDataCenterClass $this->baseID = get_class($this); $this->location = RemoteData."/bases/".$this->baseID; date_default_timezone_set('UTC'); + $this->DDserverDir = RemoteData."/DDServer/".$this->baseID; } /* Function to change External Bases stuff in case of existing AMDA aliases. @@ -77,8 +78,6 @@ abstract class RemoteDataCenterClass { if (!is_dir($this->location)) mkdir($this->location, 0775, true); - - $this->DDserverDir = RemoteData."/DDServer/".$this->baseID; if (!is_dir($this->DDserverDir)) mkdir($this->DDserverDir, 0775, true); @@ -137,5 +136,52 @@ abstract class RemoteDataCenterClass return false; } } + public function updateBufferDataBase() + { + $DDsys = new DomDocument("1.0"); + + if (file_exists(DDBASE."DDsys.xml") && $DDsys->load(DDBASE."DDsys.xml")) { + + $currDir = getcwd(); + $xpath = new domxpath($DDsys); + $datasets = $xpath->query("//NAME[@base='".$this->baseID."']"); + + foreach ($datasets as $ds) { + $vi = $ds->parentNode; + $id = $ds->nodeValue; + + foreach ($vi->childNodes as $pp) { + if ($pp->nodeName == "LOCATION") + $loc = $pp->nodeValue; + if ($pp->nodeName == "INFO") + $info = $pp->nodeValue; + } + if (file_exists($loc.$info)) { + $infoXml = str_replace(".nc",".xml", $info); + if (is_dir($this->DDserverDir)) { + $ddInfoXml = $this->DDserverDir."/".strtoupper($id).".xml"; + if (file_exists($ddInfoXml)) { + chdir($loc); + copy($ddInfoXml,$infoXml); + system("infoLocal2nc ".$infoXml." ".$info); + chdir($currDir); + } + else { + echo 'Cannot update '.$id.' in DDBASE : No '.$ddInfoXml.PHP_EOL; + } + } + else { + echo 'Cannot update '.$tid.' in DDBASE : No '.$loc.$info.PHP_EOL; + } + } + else { + echo 'Cannot update '.$this->baseID.' in DDBASE : No DDServer INFO Dir'.PHP_EOL; + } + } + } + else { + echo 'Cannot update '.$this->baseID.' in DDBASE : Cannot load DDsys.xml'.PHP_EOL; + } + } } ?> diff --git a/src/REMOTEDATA/THEMIS.php b/src/REMOTEDATA/THEMIS.php index ff3319b..bab2d0b 100644 --- a/src/REMOTEDATA/THEMIS.php +++ b/src/REMOTEDATA/THEMIS.php @@ -62,7 +62,7 @@ class THEMIS extends RemoteDataCenterClass $this->updateGlobalStartStop($dataset); $this->createVi($dataset); - $ncFiles = $this->getData($remSetID, $start, $stop); + //$ncFiles = $this->getData($remSetID, $start, $stop); $params = $dataset->getElementsByTagName("parameter"); foreach ($params as $param) { $template = $param->getAttribute("xml:id"); @@ -122,8 +122,7 @@ class THEMIS extends RemoteDataCenterClass echo $globalStart." ".$globalStop.PHP_EOL; if ($this->baseMgr->viExists($ViId, $this->baseID)) { // error_log - // updateStartStop - + $this->baseMgr->updateViStop($globalStop); return; } $info = explode("_", $ViId); @@ -160,12 +159,16 @@ class THEMIS extends RemoteDataCenterClass $this->baseMgr->updateRemoteStart(); } - + protected function setDataCenterAttributes(){ $this->dataCenter->setAttribute('xml:id', $this->baseID); $this->dataCenter->setAttribute('name', $this->baseID."_iRAP"); } + public function updateBufferDataBase() { + echo "THEMIS : UPDATE automatic".PHP_EOL; + } + protected function makeArgumentsList(){} public function getData($remId, $start, $stop) diff --git a/src/REMOTEDATA/makeProxy.php b/src/REMOTEDATA/makeProxy.php index 81b2e7c..8241c00 100644 --- a/src/REMOTEDATA/makeProxy.php +++ b/src/REMOTEDATA/makeProxy.php @@ -1,6 +1,7 @@ <?php /* * Executable to make 'base.xml' proxies for Remote Centers (DD Server) +* Updates Global Start/Stop in remote temporary data sets */ error_reporting(E_ERROR); @@ -10,7 +11,7 @@ } } - putenv("LD_LIBRARY_PATH=".getenv("LD_LIBRARY_PATH")); + putenv("LD_LIBRARY_PATH=".getenv("LD_LIBRARY_PATH")); putenv("PATH=./:".getenv("DDBASEBIN").":/bin:/usr/bin"); set_include_path("./:".getenv("DATAMANAGER").":".getenv("REMOTEDATA").":".getenv("CALLEXT")); @@ -33,7 +34,8 @@ if (file_exists(err)) unlink(err); define('RemoteData', $DDBASE."/../INFO"); - + define('DDBASE', $DDBASE."/"); + // check permissions $perms = fileperms(RemoteData); if (! ($perms & 0x0010)) @@ -65,6 +67,7 @@ $center->initProxy(); $center->makeProxy(); $center->saveProxy(); + $center->updateBufferDataBase(); // } // else // { -- libgit2 0.21.2