Commit d4071e275c5fc8d4c58454556ef4fd31f461541d
1 parent
0ec21281
Exists in
master
and in
9 other branches
makeProxy with env set
Showing
3 changed files
with
62 additions
and
55 deletions
Show diff stats
src/REMOTEDATA/CDAWEB.php
... | ... | @@ -24,9 +24,8 @@ class CDAWEB extends RemoteDataCenterClass |
24 | 24 | // FOR INFO : Excluded automatically |
25 | 25 | private $excludeDatasets = ["DMSP_R0_SSJ4", "DMSP_R0_SSIES", "I7_R0_LEPEDEA", "I8_R0_LEPEDEA" ]; |
26 | 26 | |
27 | - private $DDserverXml, $DDserverXmlName, $DDserverDir; | |
27 | + protected $DDserverXml, $DDserverXmlName; | |
28 | 28 | |
29 | - public $dir; | |
30 | 29 | |
31 | 30 | public function html_encode($param) |
32 | 31 | { |
... | ... | @@ -44,7 +43,7 @@ class CDAWEB extends RemoteDataCenterClass |
44 | 43 | { |
45 | 44 | $this->ch = curl_init(); |
46 | 45 | curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, 1); |
47 | - curl_setopt($this->ch, CURLOPT_TIMEOUT, 60); | |
46 | + curl_setopt($this->ch, CURLOPT_TIMEOUT, 60); | |
48 | 47 | } |
49 | 48 | |
50 | 49 | private function closeConnection() |
... | ... | @@ -52,33 +51,16 @@ class CDAWEB extends RemoteDataCenterClass |
52 | 51 | curl_close($this->ch); |
53 | 52 | } |
54 | 53 | |
55 | - public function initProxy() | |
56 | - { | |
57 | - $this->dir = getenv("DDBASE")."/../INFO"; | |
58 | - define('RemoteData', $this->dir."/bases/"); | |
59 | - | |
60 | - // if (!is_dir(RemoteData)) mkdir(RemoteData, 0755, true); | |
61 | - if (!is_dir($this->dir."/bases/".$this->baseID)) | |
62 | - mkdir($this->dir."/bases/".$this->baseID, 0755, true); | |
63 | - | |
64 | - $this->DDserverDir = $this->dir."/DDServer/".$this->baseID; | |
65 | - | |
66 | - if (!is_dir($this->DDserverDir)) | |
67 | - mkdir($this->DDserverDir, 0755, true); | |
68 | - | |
69 | - $this->init(); | |
70 | - | |
71 | - $this->getRemoteTree(); | |
72 | - } | |
73 | - | |
74 | 54 | protected function setDataViewURL() |
75 | 55 | { |
76 | 56 | curl_setopt($this->ch, CURLOPT_URL, CDAWebConfigClass::$restUrl."/dataviews"); |
57 | + | |
77 | 58 | $this->res = new DomDocument(); |
78 | 59 | $this->res->loadXML(curl_exec($this->ch)); |
79 | 60 | $this->dataViewURL = $this->res->getElementsByTagName('EndpointAddress')->item(0)->nodeValue; |
80 | 61 | } |
81 | - | |
62 | + | |
63 | + // Using CDAS REST APIs get all CDAWEB dataset descriptions | |
82 | 64 | protected function getRemoteTree() |
83 | 65 | { |
84 | 66 | $this->openConnection(); |
... | ... | @@ -380,7 +362,7 @@ class CDAWEB extends RemoteDataCenterClass |
380 | 362 | |
381 | 363 | $obj = json_decode(curl_exec($this->ch)); |
382 | 364 | $parameters = $obj->VariableDescription; |
383 | - | |
365 | + | |
384 | 366 | $paramNodes = array(); |
385 | 367 | |
386 | 368 | foreach ($parameters as $param) |
... | ... | @@ -442,15 +424,18 @@ class CDAWEB extends RemoteDataCenterClass |
442 | 424 | return $sampling; |
443 | 425 | } |
444 | 426 | |
427 | + // Get IDs and SPASE URLs of all CDAWEB SPASE-defined datasets | |
445 | 428 | protected function getAllSpaseDatasets() |
446 | 429 | { |
447 | 430 | require_once "simple_html_dom.php"; |
448 | 431 | |
449 | - if (file_exists("NumericalData.html")) rename("NumericalData.html","NumericalData.html.bak"); | |
450 | - // exec("wget -O NumericalData.html ".CDAWebConfigClass::$spaseRegistry); | |
451 | - //TODO errors | |
452 | - copy(CDAWebConfigClass::$spaseRegistry, "NumericalData.html"); | |
432 | + if (file_exists("NumericalData.html")) | |
433 | + rename("NumericalData.html","NumericalData.html.bak"); | |
453 | 434 | |
435 | + // if cannot reach CDAWEB Spase Registry use an old file | |
436 | + if (!copy(CDAWebConfigClass::$spaseRegistry, "NumericalData.html")) | |
437 | + copy("NumericalData.html.bak", "NumericalData.html"); | |
438 | + | |
454 | 439 | $html = file_get_html('NumericalData.html'); |
455 | 440 | $ids = $html->find('td[class="Spase.URL.ProductID"]'); |
456 | 441 | |
... | ... | @@ -461,7 +446,7 @@ class CDAWEB extends RemoteDataCenterClass |
461 | 446 | $this->CDAWEB[$key[0]->innertext] = $ref[0]->innertext; |
462 | 447 | } |
463 | 448 | |
464 | - echo count($this->CDAWEB).PHP_EOL; | |
449 | + echo "SPASE-defined CDAWEB datasets : ".count($this->CDAWEB).PHP_EOL; | |
465 | 450 | } |
466 | 451 | |
467 | 452 | protected function initDDServerXml($ds, $ins, $obs) | ... | ... |
src/REMOTEDATA/RemoteDataCenterClass.php
... | ... | @@ -14,10 +14,10 @@ abstract class RemoteDataCenterClass |
14 | 14 | public $domAmda = null, $dataCenter = null; |
15 | 15 | public $domAmdaName = "base.xml"; |
16 | 16 | public $additionalArgs = null; |
17 | - public $templateFile, $plotSettings; | |
18 | 17 | public $baseID = null; |
19 | 18 | |
20 | 19 | public $tree = null; |
20 | + protected $DDserverDir; | |
21 | 21 | |
22 | 22 | public static $MAX_NAME_LENGTH = 31; |
23 | 23 | public static $MAX_VI_NAME_LENGTH = 16; |
... | ... | @@ -27,20 +27,20 @@ abstract class RemoteDataCenterClass |
27 | 27 | */ |
28 | 28 | function __construct() |
29 | 29 | { |
30 | - $this->baseID = get_class($this); | |
31 | - $this->templateFile = $this->baseID."_Templates.xml"; | |
32 | - $this->plotSettings = $this->baseID."_PlotSettings.xml"; | |
30 | + $this->baseID = get_class($this); | |
33 | 31 | } |
34 | 32 | |
35 | 33 | public function param2dd($paramID) |
36 | 34 | { |
37 | - $pairs = array(" " => "_","-" => "_","/" => "_","%" => "_","\\" => "_","$" => "_",":" => "_","+" =>"_","#" => "_","@" => "_","." => "_", ">" => "_", "<" => "_", "," => "_", ")" => "", "(" => "_"); | |
35 | + $pairs = array(" " => "_","-" => "_","/" => "_","%" => "_","\\" => "_","$" => "_",":" => "_","+" =>"_","#" => "_", | |
36 | + "@" => "_","." => "_", ">" => "_", "<" => "_", "," => "_", ")" => "", "(" => "_"); | |
37 | + | |
38 | 38 | return strtr($paramID,$pairs); |
39 | 39 | } |
40 | 40 | |
41 | 41 | public function saveProxy() |
42 | 42 | { |
43 | - $this->domAmda->save(RemoteData.$this->baseID."/".$this->domAmdaName); | |
43 | + $this->domAmda->save(RemoteData."/bases/".$this->baseID."/".$this->domAmdaName); | |
44 | 44 | } |
45 | 45 | |
46 | 46 | abstract public function init(); |
... | ... | @@ -51,18 +51,23 @@ abstract class RemoteDataCenterClass |
51 | 51 | // abstract public function getDatasetInfo($ds); |
52 | 52 | // abstract public function getData($ds, $start, $stop); |
53 | 53 | // abstract protected function convert2nc(); |
54 | -// abstract protected function createDatasetNodes(); | |
55 | -// abstract protected function createParameterNodes(); | |
56 | -// abstract protected function createDatasetGroupNodes($data); | |
54 | +// abstract protected function createDatasetNodes(); | |
55 | +// abstract protected function createParameterNodes(); | |
56 | +// abstract protected function createDatasetGroupNodes($data); | |
57 | 57 | |
58 | 58 | public function initProxy() |
59 | 59 | { |
60 | - if (!is_dir(RemoteData.$this->baseID)) | |
61 | - mkdir(RemoteData.$this->baseID); | |
62 | - | |
63 | - chmod(RemoteData.$this->baseID,0775); | |
60 | + if (!is_dir(RemoteData."/bases/".$this->baseID)) | |
61 | + mkdir(RemoteData."/bases/".$this->baseID, 0755, true); | |
62 | + | |
63 | + $this->DDserverDir = RemoteData."/DDServer/".$this->baseID; | |
64 | + | |
65 | + if (!is_dir($this->DDserverDir)) | |
66 | + mkdir($this->DDserverDir, 0755, true); | |
67 | + | |
68 | + $this->init(); | |
64 | 69 | |
65 | - $this->getRemoteTree(); | |
70 | + $this->getRemoteTree(); | |
66 | 71 | } |
67 | 72 | |
68 | 73 | public function makeProxy() | ... | ... |
src/REMOTEDATA/makeProxy.php
... | ... | @@ -12,24 +12,41 @@ |
12 | 12 | putenv("LD_LIBRARY_PATH=".getenv("LD_LIBRARY_PATH")); |
13 | 13 | putenv("PATH=./:".getenv("DDBASEBIN").":/bin:/usr/bin"); |
14 | 14 | set_include_path("./:".getenv("DATAMANAGER").":".getenv("REMOTEDATA").":".getenv("CALLEXT")); |
15 | + | |
16 | + $LOGDIR = getenv("DDBASE")."/../LOG"; | |
17 | + if (!is_dir($LOGDIR)) | |
18 | + mkdir($LOGDIR, 0755, true); | |
19 | + | |
20 | + define("log",$LOGDIR."/ProxyCreate.log"); | |
21 | + define("err",$LOGDIR."/ProxyCreate.err"); | |
22 | + | |
23 | + if (file_exists(log)) unlink(log); | |
24 | + if (file_exists(err)) unlink(err); | |
15 | 25 | |
16 | -// if (! file_exists(DATAPATH."/RemoteData/Bases.xml")) | |
17 | -// exit('No Bases.xml file'.PHP_EOL); | |
18 | -// | |
19 | -// $basesDom->load(DATAPATH."/RemoteData/Bases.xml"); | |
20 | -// | |
21 | -// $bases = $basesDom->getElementsByTagName("dataCenter"); | |
26 | + define('RemoteData', getenv("DDBASE")."/../INFO"); | |
22 | 27 | |
28 | + if (!file_exists(RemoteData."/Bases.xml")) | |
29 | + exit('No Bases.xml'.PHP_EOL); | |
30 | + | |
31 | + $basesDom = new DomDocument("1.0"); | |
32 | + if (!$basesDom->load(RemoteData."/Bases.xml")) | |
33 | + exit('Cannot load Bases.xml'.PHP_EOL); | |
34 | + | |
35 | + $bases = $basesDom->getElementsByTagName("dataCenter"); | |
36 | + if ($bases->length == 0) | |
37 | + exit('No Bases'.PHP_EOL); | |
23 | 38 | |
24 | - $bases = array("CDAWEB"); | |
39 | +// $bases = array("CDAWEB"); | |
25 | 40 | $useSpase = true; |
26 | 41 | |
27 | 42 | foreach ($bases as $base) |
28 | - { | |
29 | - | |
30 | - // $class = $base->getAttribute('xml:id'); | |
31 | - echo PHP_EOL.$base.PHP_EOL; | |
32 | - $center = new $base(); | |
43 | + { | |
44 | + // isSimulation -> proxy is being made at AMDA | |
45 | + if ($base->hasAttribute("isSimulation")) | |
46 | + continue; | |
47 | + $class = $base->getAttribute('xml:id'); | |
48 | + echo PHP_EOL.$class.PHP_EOL; | |
49 | + $center = new $class(); | |
33 | 50 | // if ($center->monitor()) |
34 | 51 | // { |
35 | 52 | $center->initProxy(); | ... | ... |