Commit 155b6b3c2244e58c41451b55104272dd4e46614e
1 parent
2908eda1
Exists in
master
and in
9 other branches
other approach to makeproxy
Showing
4 changed files
with
207 additions
and
62 deletions
Show diff stats
src/CALLEXT/createVI.php
... | ... | @@ -30,12 +30,15 @@ |
30 | 30 | putenv("PATH=./:".getenv("DDBASEBIN").":/bin:/usr/bin"); |
31 | 31 | set_include_path("./:".getenv("DATAMANAGER").":".getenv("REMOTEDATA").":".getenv("CALLEXT")); |
32 | 32 | |
33 | - define("verbose", true); | |
33 | + $verbose = true; | |
34 | 34 | |
35 | - define("INFODIR",getenv("DDBASE")."../INFO/"); | |
36 | - define ("log",INFODIR."addVI.log"); | |
37 | - define ("err",INFODIR."addVI.err"); | |
38 | - | |
35 | + $LOGDIR = getenv("DDBASE")."../LOG/"); | |
36 | + if (!is_dir($LOGDIR)) | |
37 | + mkdir($LOGDIR, 0755, true); | |
38 | + | |
39 | + define("log",$LOGDIR."/addVI.log"); | |
40 | + define("err",$LOGDIR."/addVI.err"); | |
41 | + | |
39 | 42 | if ($argc != 4) |
40 | 43 | { |
41 | 44 | // error_log("Usage: php createVI.php <BaseID> <RemSetID> <NewVIName>".PHP_EOL, 3, err); |
... | ... | @@ -60,9 +63,10 @@ |
60 | 63 | if ($status === 0) |
61 | 64 | { |
62 | 65 | $baseMgr->createVi(); |
63 | -// if (verbose) | |
64 | -// error_log("request to add Data Set ".$base.":".$remSetID." as ".$ViId.PHP_EOL, 3, log); | |
65 | -// | |
66 | + | |
67 | + if ($verbose) | |
68 | + error_log("Request to add Data Set ".$base.":".$remSetID." as ".$ViId.PHP_EOL, 3, log); | |
69 | + | |
66 | 70 | $center = new $base(); |
67 | 71 | |
68 | 72 | $startStamp = strtotime($baseMgr->globalStart); |
... | ... | @@ -90,9 +94,8 @@ |
90 | 94 | } |
91 | 95 | |
92 | 96 | $baseMgr->addRemoteData($remSetID, $ncFiles, $startIso, $stopIso); |
93 | - // echo "START-STOP ".$start." ".$stop.PHP_EOL; | |
94 | 97 | |
95 | -// if (verbose) error_log("Get dataset info for ".$remSetID." from ".$dataBaseID." returns ".$res.PHP_EOL, 3, log); | |
98 | +// if ($verbose) error_log("Get dataset info for ".$remSetID." from ".$dataBaseID." returns ".$res.PHP_EOL, 3, log); | |
96 | 99 | |
97 | 100 | |
98 | 101 | |
... | ... | @@ -106,7 +109,7 @@ |
106 | 109 | } |
107 | 110 | else |
108 | 111 | { |
109 | - if (verbose) error_log("No DDServer Info File for $base $ViId".PHP_EOL, 3, log); | |
112 | + if ($verbose) error_log("No DDServer Info File for $base $ViId".PHP_EOL, 3, log); | |
110 | 113 | } |
111 | 114 | |
112 | 115 | ?> |
113 | 116 | \ No newline at end of file | ... | ... |
src/DATA/MANAGER/DDBaseMgr.php
src/REMOTEDATA/CDAWEB.php
... | ... | @@ -8,14 +8,17 @@ class CDAWEB extends RemoteDataCenterClass |
8 | 8 | { |
9 | 9 | private $ch, $res, $dataViewUR; |
10 | 10 | private $obsGroupsIds; |
11 | + private $spase_res; | |
11 | 12 | |
12 | 13 | private $observatoryGroups, $instrumentTypes; |
13 | 14 | private $CDAWEB = array(), $masterCDF = array(); |
14 | 15 | |
15 | 16 | // https://cdaweb.gsfc.nasa.gov/WS/cdasr/1/dataviews/sp_phys/instrumentTypes |
16 | - private $validInstrumentTypes = [ "Activity%20Indices", "Electric%20Fields%20(space)","Gamma%20and%20X-Rays", | |
17 | +/* private $validInstrumentTypes = [ "Activity%20Indices", "Electric%20Fields%20(space)","Gamma%20and%20X-Rays", | |
17 | 18 | "Magnetic%20Fields%20(space)", "Particles%20(space)", "Plasma%20and%20Solar%20Wind", |
18 | - "Radio%20and%20Plasma%20Waves%20(space)" ]; | |
19 | + "Radio%20and%20Plasma%20Waves%20(space)" ]; */ | |
20 | + private $validInstrumentTypes = [ "Magnetic%20Fields%20(space)" ]; | |
21 | + | |
19 | 22 | // not used : $validInstrumentTypes = ["Ephemeris"]; |
20 | 23 | |
21 | 24 | private $excludeIns = ["GIFWALK", "Unknown"], $excludeGroup = ["THEMIS", "ARTEMIS", "NOAA"]; |
... | ... | @@ -183,84 +186,80 @@ class CDAWEB extends RemoteDataCenterClass |
183 | 186 | $newNode = false; |
184 | 187 | } |
185 | 188 | |
186 | - foreach ($insTypes as $insType => $obss) | |
187 | - { | |
189 | + foreach ($insTypes as $insType => $obss){ | |
188 | 190 | // echo $insType.PHP_EOL; |
189 | 191 | |
190 | - foreach ( $obss as $obs => $inss) | |
191 | - { | |
192 | + foreach ( $obss as $obs => $inss){ | |
192 | 193 | // echo $obs.PHP_EOL; |
193 | 194 | // OMNI ONLY ONCE |
194 | - if (substr($obs,0,4) == "OMNI" && substr($missionId,0,4) != "OMNI") | |
195 | - { | |
195 | + if (substr($obs,0,4) == "OMNI" && substr($missionId,0,4) != "OMNI"){ | |
196 | 196 | //echo ' '.$obs.' '.$missionId.PHP_EOL; |
197 | 197 | continue; |
198 | 198 | } |
199 | 199 | |
200 | - $obsId = $this->baseID.":".$this->param2dd($groupId).":".$this->param2dd($obs); | |
200 | + if (file_exists(RemoteData."/".CDAWebConfigClass::$mapXML)) { | |
201 | + $obsAMDA = $this->alias(RemoteData."/".CDAWebConfigClass::$mapXML, $obs); | |
202 | + } | |
203 | + else { | |
204 | + $obsAMDA = $obs; | |
205 | + } | |
206 | + | |
207 | + $obsId = $this->baseID.":".$this->param2dd($groupId).":".$this->param2dd($obsAMDA); | |
201 | 208 | $obsNodes = $missionNode->getElementsByTagName('observatory'); |
202 | 209 | $newObsNode = true; |
203 | 210 | |
204 | - foreach ($obsNodes as $node) | |
205 | - { | |
211 | + foreach ($obsNodes as $node){ | |
206 | 212 | $id = $node->getAttribute("xml:id"); |
207 | 213 | |
208 | - if ($id == $obsId) | |
209 | - { | |
214 | + if ($id == $obsId) { | |
210 | 215 | $obsNode = $node; |
211 | 216 | $newObsNode = false; |
212 | 217 | break; |
213 | 218 | } |
214 | 219 | } |
215 | - if ( $newObsNode ) | |
216 | - { | |
220 | + | |
221 | + if ( $newObsNode ){ | |
217 | 222 | $obsNode = $this->createObservatoryNode($obs, $groupId); |
218 | 223 | } |
219 | - foreach ( $inss as $ins => $dss) | |
220 | - { | |
224 | + | |
225 | + foreach ($inss as $ins => $dss){ | |
221 | 226 | $insId = $this->baseID.":".$this->param2dd($groupId).":".$this->param2dd($obs).":".$this->param2dd($ins); |
222 | 227 | $insNodes = $obsNode->getElementsByTagName('instrument'); |
223 | 228 | $newInsNode = true; |
224 | 229 | |
225 | - foreach ($insNodes as $node) | |
226 | - { | |
230 | + foreach ($insNodes as $node){ | |
227 | 231 | $id = $node->getAttribute("xml:id"); |
228 | 232 | |
229 | - if ($id == $insId) | |
230 | - { | |
233 | + if ($id == $insId) { | |
231 | 234 | $insNode = $node; |
232 | 235 | $newInsNode = false; |
233 | 236 | break; |
234 | 237 | } |
235 | 238 | } |
239 | + | |
236 | 240 | if ( $newInsNode ) |
237 | 241 | $insNode = $this->createInstrumentNode($ins, $obs, $groupId); |
238 | 242 | |
239 | - foreach ($dss as $ds) | |
240 | - { | |
243 | + foreach ($dss as $ds){ | |
241 | 244 | $dsId = $this->baseID.":".$ds; |
242 | 245 | $dsNodes = $insNode->getElementsByTagName('dataset'); |
243 | 246 | $newDsNode = true; |
244 | 247 | |
245 | - foreach ($dsNodes as $node) | |
246 | - { | |
248 | + foreach ($dsNodes as $node){ | |
247 | 249 | $id = $node->getAttribute("xml:id"); |
248 | 250 | |
249 | - if ($id == $dsId) | |
250 | - { | |
251 | + if ($id == $dsId){ | |
251 | 252 | $dsNode = $node; |
252 | 253 | $newDsNode = false; |
253 | 254 | break; |
254 | 255 | } |
255 | 256 | } |
256 | 257 | |
257 | - if ($newDsNode) | |
258 | - { | |
258 | + if ($newDsNode) { | |
259 | 259 | $this->initDDServerXml($ds,$ins,$obs); |
260 | 260 | |
261 | 261 | $dsNode = $this->createDatasetNode($ds); |
262 | - if ($dsNode) | |
263 | - { | |
262 | + if ($dsNode){ | |
264 | 263 | $insNode->appendChild($dsNode); |
265 | 264 | $this->saveDDServerXml(); |
266 | 265 | } |
... | ... | @@ -271,8 +270,7 @@ class CDAWEB extends RemoteDataCenterClass |
271 | 270 | $obsNode->appendChild($insNode); |
272 | 271 | } |
273 | 272 | |
274 | - if ($newObsNode && $obsNode->hasChildNodes()) | |
275 | - { | |
273 | + if ($newObsNode && $obsNode->hasChildNodes()){ | |
276 | 274 | $missionNode->appendChild($obsNode); |
277 | 275 | } |
278 | 276 | } |
... | ... | @@ -290,13 +288,12 @@ class CDAWEB extends RemoteDataCenterClass |
290 | 288 | protected function createObservatoryNode($id, $grpId) |
291 | 289 | { |
292 | 290 | |
293 | - $insNode = $this->domAmda->createElement('observatory'); | |
291 | + $obsNode = $this->domAmda->createElement('observatory'); | |
294 | 292 | |
295 | - $insNode->setAttribute("xml:id",$this->baseID.":".$this->param2dd($grpId).":".$this->param2dd($id)); | |
296 | - $insNode->setAttribute("name",$id); | |
297 | - // $insNode->setAttribute("description",$ins[1]); | |
293 | + $obsNode->setAttribute("xml:id",$this->baseID.":".$this->param2dd($grpId).":".$this->param2dd($id)); | |
294 | + $obsNode->setAttribute("name",$id); | |
298 | 295 | |
299 | - return $insNode; | |
296 | + return $obsNode; | |
300 | 297 | } |
301 | 298 | |
302 | 299 | protected function createInstrumentNode($id, $obsId, $groupId) |
... | ... | @@ -343,8 +340,11 @@ class CDAWEB extends RemoteDataCenterClass |
343 | 340 | else |
344 | 341 | $this->updateDDServerXml("MinSampling",$sampling); |
345 | 342 | |
346 | - $dsNode->setAttribute('spaseUrl',$this->CDAWEB[$dsId]); | |
343 | + $dsNode->setAttribute('spaseUrl',$this->CDAWEB[$dsId]); | |
347 | 344 | // $dsNode->setAttribute('masterCdf',$this->existsMasterCdf($dsId)); |
345 | + $dsNode->setAttribute("desc", "$label; $startTime - $endTime"); | |
346 | + $dsNode->setAttribute("start", $startTime); | |
347 | + $dsNode->setAttribute("stop", $stopTime); | |
348 | 348 | |
349 | 349 | $parameterNodes = $this->createParameterNodes($dsId); |
350 | 350 | foreach ( $parameterNodes as $parameterNode) |
... | ... | @@ -386,10 +386,11 @@ class CDAWEB extends RemoteDataCenterClass |
386 | 386 | return -1; // no description in SpaseRegistry |
387 | 387 | |
388 | 388 | curl_setopt($this->ch, CURLOPT_URL, CDAWebConfigClass::$spaseResolver."id=".$this->CDAWEB[$dsID]); |
389 | - | |
390 | - $this->res->loadXML(curl_exec($this->ch)); | |
391 | - //TODO errors | |
392 | - $messages = $this->res->getElementsByTagName('Message'); | |
389 | + | |
390 | + if (!$this->spase_res->loadXML(curl_exec($this->ch))) | |
391 | + return -100; | |
392 | + | |
393 | + $messages = $this->spase_res->getElementsByTagName('Message'); | |
393 | 394 | |
394 | 395 | if ($messages->length > 0) |
395 | 396 | { |
... | ... | @@ -398,12 +399,12 @@ class CDAWEB extends RemoteDataCenterClass |
398 | 399 | return -2; // no description in www-spase |
399 | 400 | } |
400 | 401 | |
401 | - $instrument = $this->res->getElementsByTagName('InstrumentID'); | |
402 | - echo " instrument ".$instrument->item(0)->nodeValue.PHP_EOL; | |
402 | +// $instrument = $this->spase_res->getElementsByTagName('InstrumentID'); | |
403 | +// echo " instrument ".$instrument->item(0)->nodeValue.PHP_EOL; | |
403 | 404 | |
404 | - $cadence = $this->res->getElementsByTagName('Cadence'); | |
405 | + $cadence = $this->spase_res->getElementsByTagName('Cadence'); | |
405 | 406 | |
406 | - if ( $cadence->length == 0) | |
407 | + if ($cadence->length == 0) | |
407 | 408 | return -3; // no cadence in spase xml |
408 | 409 | |
409 | 410 | $sampling = $this->cadence2sampling($cadence->item(0)->nodeValue); |
... | ... | @@ -585,6 +586,126 @@ class CDAWEB extends RemoteDataCenterClass |
585 | 586 | |
586 | 587 | return $infoFile; |
587 | 588 | } |
589 | + | |
590 | + public function makeProxy() | |
591 | + { | |
592 | + $this->spase_res = new DomDocument("1.0"); | |
593 | + $this->domAmda = new DOMDocument('1.0', 'utf-8'); | |
594 | + $this->domAmda->formatOutput = TRUE; | |
595 | + $this->domAmda->preserveWhiteSpace = FALSE; | |
596 | + | |
597 | + $dataRoot = $this->domAmda->createElement('dataRoot'); | |
598 | + $dataRoot->setAttribute('xml:id', 'myRemoteData-treeRootNode'); | |
599 | + $this->domAmda->appendChild($dataRoot); | |
600 | + | |
601 | + $this->dataCenter=$this->domAmda->createElement('dataCenter'); | |
602 | + | |
603 | + $this->dataCenter->setAttribute('xml:id', $this->baseID); | |
604 | + // $this->dataCenter->setIdAttribute('xml:id', true); | |
605 | + $this->dataCenter->setAttribute('name', $this->baseID); | |
606 | + | |
607 | + $dataRoot->appendChild($this->dataCenter); | |
608 | + | |
609 | + $this->setDataCenterAttributes(); | |
610 | + | |
611 | + foreach ($this->obsGroupsIds as $groupId => $insTypes){ | |
612 | + foreach ($insTypes as $insType => $obss){ | |
613 | + $obsNodes = array(); | |
614 | + foreach ($obss as $obs => $inss){ | |
615 | + $insNodes = array(); | |
616 | + // Create instrument nodes | |
617 | + foreach ($inss as $ins => $dss){ | |
618 | + $dsNodes = array(); | |
619 | + // Create datasets nodes | |
620 | + foreach ($dss as $ds){ | |
621 | + $dsId = $this->baseID.":".$ds; | |
622 | +// $this->domAmda->save('temp.xml'); | |
623 | +// $this->domAmda->load('temp.xml'); | |
624 | + if (!$this->domAmda->getElementById($dsId)){ | |
625 | + $this->initDDServerXml($ds,$ins,$obs); | |
626 | + $dsNode = $this->createDatasetNode($ds); | |
627 | + if ($dsNode){ | |
628 | + $this->saveDDServerXml(); | |
629 | + $dsNodes[] = $dsNode; | |
630 | + } | |
631 | + } | |
632 | + } // foreach ($dss as $ds) | |
633 | + if ($dsNodes){ | |
634 | + // last $spase_res : instrument should be the same | |
635 | + $insSpaseId = $this->getInstrumentSpase(); | |
636 | + if (!$insSpaseId ) | |
637 | + $insSpaseId = $ins; | |
638 | + | |
639 | + $insId = $this->baseID.":".$this->param2dd($groupId).":".$this->param2dd($obs).":".$this->param2dd($insSpaseId); | |
640 | + | |
641 | + if (!($insNode = $this->domAmda->getElementById($insId))){ | |
642 | + $insNode = $this->createInstrumentNode($insSpaseId, $obs, $groupId); | |
643 | + $insNodes[] = $insNode; | |
644 | + } | |
645 | + foreach ($dsNodes as $dsNode){ | |
646 | + $insNode->appendChild($dsNode); | |
647 | + } | |
648 | + } | |
649 | + } // foreach ($inss as $ins => $dss) | |
650 | + if ($insNodes){ | |
651 | + $obsId = $this->baseID.":".$this->param2dd($groupId).":".$this->param2dd($obs); | |
652 | + | |
653 | + if (!($obsNode = $this->domAmda->getElementById($obsId))){ | |
654 | + $obsNode = $this->createObservatoryNode($obs, $groupId); | |
655 | + $obsNodes[] = $obsNode; | |
656 | + } | |
657 | + | |
658 | + foreach ($insNodes as $insNode){ | |
659 | + $obsNode->appendChild($insNode); | |
660 | + } | |
661 | + } | |
662 | + } // foreach ($obss as $obs => $inss) | |
663 | + } | |
664 | + if ($obsNodes){ | |
665 | + $missionId = $this->baseID.":".$this->param2dd($groupId); | |
666 | + | |
667 | + if (!($missionNode = $this->domAmda->getElementById($missionId))){ | |
668 | + $missionNode = $this->createMissionNode($groupId); | |
669 | + $this->dataCenter->appendChild($missionNode); | |
670 | + } | |
671 | + | |
672 | + foreach ($obsNodes as $obsNode){ | |
673 | + $missionNode->appendChild($obsNode); | |
674 | + } | |
675 | + } | |
676 | + } | |
677 | + } | |
678 | + | |
679 | + protected function createMissionNode($groupId){ | |
680 | + $missionId = $this->baseID.":".$this->param2dd($groupId); | |
681 | + $missionNode = $this->domAmda->createElement('mission'); | |
682 | + $missionNode->setAttribute("xml:id",$missionId); | |
683 | + $missionNode->setAttribute("name",$groupId); | |
684 | + | |
685 | + return $missionNode; | |
686 | + } | |
687 | + | |
688 | + protected function getInstrumentSpase(){ | |
689 | + $insXML = new DomDocument("1.0"); | |
690 | + | |
691 | + if ($this->spase_res){ | |
692 | + $instrument = $this->spase_res->getElementsByTagName('InstrumentID'); | |
693 | + | |
694 | + if ($instrument->length > 0) { | |
695 | + return $this->getIdFromSpase($instrument->item(0)->nodeValue); | |
696 | +// curl_setopt($this->ch, CURLOPT_URL, CDAWebConfigClass::$spaseResolver."id=".$instrument->item(0)->nodeValue); | |
697 | +// | |
698 | +// if (!$insXML->loadXML(curl_exec($this->ch))){ | |
699 | +// return null; | |
700 | +// } | |
701 | + //InstrumentType | |
702 | + //spase://SMWG/Observatory/ACE | |
703 | + } | |
704 | + } | |
705 | + | |
706 | + return null; | |
707 | + } | |
708 | + | |
588 | 709 | protected function setDataCenterAttributes(){} |
589 | 710 | protected function makeArgumentsList(){} |
590 | 711 | } | ... | ... |
src/REMOTEDATA/RemoteDataCenterClass.php
... | ... | @@ -28,7 +28,23 @@ abstract class RemoteDataCenterClass |
28 | 28 | function __construct() |
29 | 29 | { |
30 | 30 | $this->baseID = get_class($this); |
31 | - } | |
31 | + } | |
32 | + | |
33 | + /* Function to change External Bases stuff in case of existing AMDA aliases. | |
34 | + Uses file DICTIONARY_DIR.mapBaseID.xml */ | |
35 | + | |
36 | + protected function alias($Dictionary, $name) { | |
37 | + | |
38 | + $xmldoc = new DomDocument("1.0"); | |
39 | + $xmldoc->load($DictionaryFile); | |
40 | + $item = $xmldoc->getElementById(strtoupper($name)); | |
41 | + | |
42 | + if (!$item) return $name; | |
43 | + $alias = $item->nodeValue; | |
44 | + | |
45 | + return $alias; | |
46 | + } | |
47 | + | |
32 | 48 | |
33 | 49 | public function param2dd($paramID) |
34 | 50 | { |
... | ... | @@ -94,7 +110,13 @@ abstract class RemoteDataCenterClass |
94 | 110 | foreach ($missionNodes as $missionNode) |
95 | 111 | $this->dataCenter->appendChild($missionNode); |
96 | 112 | } |
97 | - | |
113 | + | |
114 | + protected function getIdFromSpase($spaseId) | |
115 | + { | |
116 | + $temp = explode('/',$spaseId); | |
117 | + return $temp[count($temp)-1]; | |
118 | + } | |
119 | + | |
98 | 120 | public function monitor() |
99 | 121 | { |
100 | 122 | $ch = curl_init($this->url."/".$this->WSDL); | ... | ... |