From d4071e275c5fc8d4c58454556ef4fd31f461541d Mon Sep 17 00:00:00 2001 From: Elena.Budnik Date: Fri, 17 Nov 2017 17:19:55 +0100 Subject: [PATCH] makeProxy with env set --- src/REMOTEDATA/CDAWEB.php | 43 ++++++++++++++----------------------------- src/REMOTEDATA/RemoteDataCenterClass.php | 33 +++++++++++++++++++-------------- src/REMOTEDATA/makeProxy.php | 41 +++++++++++++++++++++++++++++------------ 3 files changed, 62 insertions(+), 55 deletions(-) diff --git a/src/REMOTEDATA/CDAWEB.php b/src/REMOTEDATA/CDAWEB.php index 397605d..73ffbc8 100644 --- a/src/REMOTEDATA/CDAWEB.php +++ b/src/REMOTEDATA/CDAWEB.php @@ -24,9 +24,8 @@ class CDAWEB extends RemoteDataCenterClass // FOR INFO : Excluded automatically private $excludeDatasets = ["DMSP_R0_SSJ4", "DMSP_R0_SSIES", "I7_R0_LEPEDEA", "I8_R0_LEPEDEA" ]; - private $DDserverXml, $DDserverXmlName, $DDserverDir; + protected $DDserverXml, $DDserverXmlName; - public $dir; public function html_encode($param) { @@ -44,7 +43,7 @@ class CDAWEB extends RemoteDataCenterClass { $this->ch = curl_init(); curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($this->ch, CURLOPT_TIMEOUT, 60); + curl_setopt($this->ch, CURLOPT_TIMEOUT, 60); } private function closeConnection() @@ -52,33 +51,16 @@ class CDAWEB extends RemoteDataCenterClass curl_close($this->ch); } - public function initProxy() - { - $this->dir = getenv("DDBASE")."/../INFO"; - define('RemoteData', $this->dir."/bases/"); - - // if (!is_dir(RemoteData)) mkdir(RemoteData, 0755, true); - if (!is_dir($this->dir."/bases/".$this->baseID)) - mkdir($this->dir."/bases/".$this->baseID, 0755, true); - - $this->DDserverDir = $this->dir."/DDServer/".$this->baseID; - - if (!is_dir($this->DDserverDir)) - mkdir($this->DDserverDir, 0755, true); - - $this->init(); - - $this->getRemoteTree(); - } - protected function setDataViewURL() { curl_setopt($this->ch, CURLOPT_URL, CDAWebConfigClass::$restUrl."/dataviews"); + $this->res = new DomDocument(); $this->res->loadXML(curl_exec($this->ch)); $this->dataViewURL = $this->res->getElementsByTagName('EndpointAddress')->item(0)->nodeValue; } - + + // Using CDAS REST APIs get all CDAWEB dataset descriptions protected function getRemoteTree() { $this->openConnection(); @@ -380,7 +362,7 @@ class CDAWEB extends RemoteDataCenterClass $obj = json_decode(curl_exec($this->ch)); $parameters = $obj->VariableDescription; - + $paramNodes = array(); foreach ($parameters as $param) @@ -442,15 +424,18 @@ class CDAWEB extends RemoteDataCenterClass return $sampling; } + // Get IDs and SPASE URLs of all CDAWEB SPASE-defined datasets protected function getAllSpaseDatasets() { require_once "simple_html_dom.php"; - if (file_exists("NumericalData.html")) rename("NumericalData.html","NumericalData.html.bak"); - // exec("wget -O NumericalData.html ".CDAWebConfigClass::$spaseRegistry); - //TODO errors - copy(CDAWebConfigClass::$spaseRegistry, "NumericalData.html"); + if (file_exists("NumericalData.html")) + rename("NumericalData.html","NumericalData.html.bak"); + // if cannot reach CDAWEB Spase Registry use an old file + if (!copy(CDAWebConfigClass::$spaseRegistry, "NumericalData.html")) + copy("NumericalData.html.bak", "NumericalData.html"); + $html = file_get_html('NumericalData.html'); $ids = $html->find('td[class="Spase.URL.ProductID"]'); @@ -461,7 +446,7 @@ class CDAWEB extends RemoteDataCenterClass $this->CDAWEB[$key[0]->innertext] = $ref[0]->innertext; } - echo count($this->CDAWEB).PHP_EOL; + echo "SPASE-defined CDAWEB datasets : ".count($this->CDAWEB).PHP_EOL; } protected function initDDServerXml($ds, $ins, $obs) diff --git a/src/REMOTEDATA/RemoteDataCenterClass.php b/src/REMOTEDATA/RemoteDataCenterClass.php index 7584e52..874a81b 100644 --- a/src/REMOTEDATA/RemoteDataCenterClass.php +++ b/src/REMOTEDATA/RemoteDataCenterClass.php @@ -14,10 +14,10 @@ abstract class RemoteDataCenterClass public $domAmda = null, $dataCenter = null; public $domAmdaName = "base.xml"; public $additionalArgs = null; - public $templateFile, $plotSettings; public $baseID = null; public $tree = null; + protected $DDserverDir; public static $MAX_NAME_LENGTH = 31; public static $MAX_VI_NAME_LENGTH = 16; @@ -27,20 +27,20 @@ abstract class RemoteDataCenterClass */ function __construct() { - $this->baseID = get_class($this); - $this->templateFile = $this->baseID."_Templates.xml"; - $this->plotSettings = $this->baseID."_PlotSettings.xml"; + $this->baseID = get_class($this); } public function param2dd($paramID) { - $pairs = array(" " => "_","-" => "_","/" => "_","%" => "_","\\" => "_","$" => "_",":" => "_","+" =>"_","#" => "_","@" => "_","." => "_", ">" => "_", "<" => "_", "," => "_", ")" => "", "(" => "_"); + $pairs = array(" " => "_","-" => "_","/" => "_","%" => "_","\\" => "_","$" => "_",":" => "_","+" =>"_","#" => "_", + "@" => "_","." => "_", ">" => "_", "<" => "_", "," => "_", ")" => "", "(" => "_"); + return strtr($paramID,$pairs); } public function saveProxy() { - $this->domAmda->save(RemoteData.$this->baseID."/".$this->domAmdaName); + $this->domAmda->save(RemoteData."/bases/".$this->baseID."/".$this->domAmdaName); } abstract public function init(); @@ -51,18 +51,23 @@ abstract class RemoteDataCenterClass // abstract public function getDatasetInfo($ds); // abstract public function getData($ds, $start, $stop); // abstract protected function convert2nc(); -// abstract protected function createDatasetNodes(); -// abstract protected function createParameterNodes(); -// abstract protected function createDatasetGroupNodes($data); +// abstract protected function createDatasetNodes(); +// abstract protected function createParameterNodes(); +// abstract protected function createDatasetGroupNodes($data); public function initProxy() { - if (!is_dir(RemoteData.$this->baseID)) - mkdir(RemoteData.$this->baseID); - - chmod(RemoteData.$this->baseID,0775); + if (!is_dir(RemoteData."/bases/".$this->baseID)) + mkdir(RemoteData."/bases/".$this->baseID, 0755, true); + + $this->DDserverDir = RemoteData."/DDServer/".$this->baseID; + + if (!is_dir($this->DDserverDir)) + mkdir($this->DDserverDir, 0755, true); + + $this->init(); - $this->getRemoteTree(); + $this->getRemoteTree(); } public function makeProxy() diff --git a/src/REMOTEDATA/makeProxy.php b/src/REMOTEDATA/makeProxy.php index 0cf6e16..1a7c68e 100644 --- a/src/REMOTEDATA/makeProxy.php +++ b/src/REMOTEDATA/makeProxy.php @@ -12,24 +12,41 @@ putenv("LD_LIBRARY_PATH=".getenv("LD_LIBRARY_PATH")); putenv("PATH=./:".getenv("DDBASEBIN").":/bin:/usr/bin"); set_include_path("./:".getenv("DATAMANAGER").":".getenv("REMOTEDATA").":".getenv("CALLEXT")); + + $LOGDIR = getenv("DDBASE")."/../LOG"; + if (!is_dir($LOGDIR)) + mkdir($LOGDIR, 0755, true); + + define("log",$LOGDIR."/ProxyCreate.log"); + define("err",$LOGDIR."/ProxyCreate.err"); + + if (file_exists(log)) unlink(log); + if (file_exists(err)) unlink(err); -// if (! file_exists(DATAPATH."/RemoteData/Bases.xml")) -// exit('No Bases.xml file'.PHP_EOL); -// -// $basesDom->load(DATAPATH."/RemoteData/Bases.xml"); -// -// $bases = $basesDom->getElementsByTagName("dataCenter"); + define('RemoteData', getenv("DDBASE")."/../INFO"); + if (!file_exists(RemoteData."/Bases.xml")) + exit('No Bases.xml'.PHP_EOL); + + $basesDom = new DomDocument("1.0"); + if (!$basesDom->load(RemoteData."/Bases.xml")) + exit('Cannot load Bases.xml'.PHP_EOL); + + $bases = $basesDom->getElementsByTagName("dataCenter"); + if ($bases->length == 0) + exit('No Bases'.PHP_EOL); - $bases = array("CDAWEB"); +// $bases = array("CDAWEB"); $useSpase = true; foreach ($bases as $base) - { - - // $class = $base->getAttribute('xml:id'); - echo PHP_EOL.$base.PHP_EOL; - $center = new $base(); + { + // isSimulation -> proxy is being made at AMDA + if ($base->hasAttribute("isSimulation")) + continue; + $class = $base->getAttribute('xml:id'); + echo PHP_EOL.$class.PHP_EOL; + $center = new $class(); // if ($center->monitor()) // { $center->initProxy(); -- libgit2 0.21.2