Commit 34cd00b5d744fa34143675e98e81529db62bf9f4

Authored by Elena.Budnik
1 parent 24edfa77

new DATAMANAGER

src/DATA/MANAGER/AddLocalVI.php
... ... @@ -2,99 +2,47 @@
2 2  
3 3 /**
4 4 * @file AddLocalVI.php
5   -* @version $Id: AddLocalVI.php,v 1.3 2010/10/29 14:03:53 budnik Exp $
  5 +* @version
6 6 * @brief DD Server Tools:
7 7 * @arg
8 8 */
9 9  
10   - function makeInfoXml() {
11   -
12   - $xml_dom = new DomDocument("1.0");
13   - $rootElement = $xml_dom -> createElement("VI");
14   - $rootElement -> appendChild($xml_dom -> createElement("Mission",mission));
15   - $rootElement -> appendChild($xml_dom -> createElement("Instrument",instrument));
16   - $rootElement -> appendChild($xml_dom -> createElement("GlobalStart"));
17   - $rootElement -> appendChild($xml_dom -> createElement("GlobalStop"));
18   - $rootElement -> appendChild($xml_dom -> createElement("MinSampling", MinSampling));
19   - if (MaxSampling > MinSampling) $rootElement -> appendChild($xml_dom -> createElement("MaxSampling", MaxSampling));
20   - $rootElement -> appendChild($xml_dom -> createElement("LocalStart"));
21   - $rootElement -> appendChild($xml_dom -> createElement("LocalStop"));
22   - $xml_dom -> appendChild($rootElement);
23   - $xml_dom -> save(brief."_info.xml");
24   -
25   -}
26   -
27   - require_once 'mgr_ini.php';
28   - define("CURRDIR",dirname(__FILE__));
  10 + if (!function_exists('__autoload'))
  11 + {
  12 + function __autoload($class_name) {
  13 + require_once $class_name . '.php';
  14 + }
  15 + }
  16 +
  17 + putenv("LD_LIBRARY_PATH=".getenv("LD_LIBRARY_PATH"));
  18 + putenv("PATH=./:".getenv("DDBASEBIN").":/bin:/usr/bin");
  19 + set_include_path("./:".getenv("DATAMANAGER").":".getenv("REMOTEDATA").":".getenv("CALLEXT"));
29 20  
30 21 /*
31 22 * DEFINITIONS TO FILL
32 23 */
33   - define("brief", "jedi"); // prefix
34   - define("ViId", "juno_jedi_i180");
35   - define("mission", "JUNO");
36   - define("instrument", "JEDI");
37   - define("MISSION_DIR", DDBASE."JUNO/");
38   - define("location", MISSION_DIR."JEDI/I_180");
39   - define("MinSampling", 2);
40   - define("MaxSampling", 3); // 0 if constant sampling
  24 + $brief = "jedi"; // prefix $argv[1]
  25 + $ViId = "juno_jedi_i180"; // $argv[2]
  26 + $mission = "JUNO"; // $argv[3]
  27 + $instrument= "JEDI"; // $argv[4]
  28 + $mission_dir = "JUNO/"; // $argv[5]
  29 + $location = "JEDI/I_180"; // $argv[6]
  30 + $min_sampling = 2;// $argv[7]
  31 + $max_sampling = 3;// $argv[8] // 0 if constant sampling
41 32 /*
42 33 * DO NOT TOUCH
43 34 */
44   -
45   - $times = brief."_times.nc";
46   - $info = brief."_info.nc";
47   - $info_xml = brief."_info.xml";
48   - $cache = brief."_cache.nc";
  35 + $base = "LOCAL";
  36 + $baseMgr = new DDBaseMgr();
49 37  
50   - $DDsysDoc = new DomDocument();
51   - $DDsysDoc->preserveWhiteSpace = false;
52   - $DDsysDoc->formatOutput = true;
53   - $DDsysDoc->load(DDBASE.DDsys);
54   - $dataSet = $DDsysDoc->getElementsByTagName("VI");
55   -/*
56   -* Check if there is already such VI
57   -*/
58   - foreach ($dataSet as $theDataSet)
59   - if (strcmp($theDataSet->getElementsByTagName("NAME")->item(0)->nodeValue, ViId) == 0)
60   - die(ViId." Already Exists!!!\n");
61   -
62   - $refNode = $dataSet->item(0);
63   - $newNode = $DDsysDoc->createElement("VI");
64   - $name = $newNode->appendChild($DDsysDoc->createElement("NAME",ViId));
65   - $name->setAttributeNode(new DOMAttr('base', 'LOCAL'));
66   - $name->setAttributeNode(new DOMAttr('mission', mission));
67   - $name->setAttributeNode(new DOMAttr('instrument', instrument));
  38 + if ($baseMgr->viExists($ViId, $base)) die("$ViId Already Exists!!!".PHP_EOL);
68 39  
69   - if (substr(location, -1) !== "/") $newNode->appendChild($DDsysDoc->createElement("LOCATION",location."/"));
70   - else $newNode->appendChild($DDsysDoc->createElement("LOCATION",location));
71   -
72   - $newNode->appendChild($DDsysDoc->createElement("TIMES",$times));
73   - $newNode->appendChild($DDsysDoc->createElement("INFO",$info));
74   - $newNode->appendChild($DDsysDoc->createElement("CACHE",$cache));
75   -
76   - $newNode = $refNode->parentNode->insertBefore($newNode, $refNode);
77   -
78   - $DDsysDoc->save(DDBASE.DDsys);
79   - system(DDBASEBIN."/makeDDsys");
80   -
81   -/*
82   -* Create Real Stuff
83   -*
84   -*/
  40 + $baseMgr->setViId($ViId);
  41 + $baseMgr->setViInfo($brief);
  42 + $baseMgr->setViParentsInfo($base, $mission, $instrument);
  43 + $baseMgr->setViLocation($mission_dir, $location);
  44 + $baseMgr->setViSampling($min_sampling, $max_sampling);
85 45  
86   - if (!is_dir(MISSION_DIR)) mkdir(MISSION_DIR);
87   - if (!is_dir(location)) mkdir(location, 0775, true);
88   - echo location."\n";
89   - chdir(location);
90   - if (!file_exists($times)) system(DDBASEBIN."/TimesUpdate -r ".$times." ".brief."_[0-9]*.nc");
91   - if (!file_exists($info_xml)) makeInfoXml();
92   - if (!file_exists($info)) system(DDBASEBIN."/infoLocal2nc ".$info_xml." ".$info);
93   - if (!file_exists("clean")) {
94   - copy (DDLIB."/Cash.template", $cache);
95   - $SED = "sed 's/NAME/".brief."/g' ".DDLIB."/Clean.template > clean";
96   - exec($SED);
97   - exec('chmod ugo+x clean');
98   - }
99   - chdir(CURRDIR);
  46 + $baseMgr->createVi();
  47 +
100 48 ?>
... ...
src/DATA/MANAGER/DDBaseMgr.php 0 โ†’ 100644
... ... @@ -0,0 +1,235 @@
  1 +<?php
  2 +
  3 +/**
  4 +* @class DDBaseMgr
  5 +* @brief
  6 +* @arg
  7 +*/
  8 +class DDBaseMgr
  9 +{
  10 +
  11 + private $brief, $times, $info, $info_xml, $cache;
  12 + private $ViId, $remoteViId;
  13 + private $DDsysDoc, $DDsys;
  14 + private $base, $mission, $instrument;
  15 + private $min_sampling, $max_sampling;
  16 + private $location, $ViDir;
  17 + public $globalStart = null, $globalStop = null;
  18 +
  19 + function __construct()
  20 + {
  21 + $this->DDsys = getenv("DDBASE")."/DDsys.xml";
  22 + $this->DDsysDoc = new DomDocument();
  23 + $this->DDsysDoc->preserveWhiteSpace = false;
  24 + $this->DDsysDoc->formatOutput = true;
  25 + $this->DDsysDoc->load($this->DDsys);
  26 + }
  27 +
  28 + public function setViInfo($brief)
  29 + {
  30 + $this->brief = $brief;
  31 + $this->times = $brief."_times.nc";
  32 + $this->info = $brief."_info.nc";
  33 + $this->info_xml = $brief."_info.xml";
  34 + $this->cache = $brief."_cache.nc";
  35 + }
  36 +
  37 + public function setViDir($ViDir)
  38 + {
  39 + $this->ViDir = $ViDir;
  40 + }
  41 +
  42 + public function setViId($ViId)
  43 + {
  44 + $this->ViId = $ViId;
  45 + }
  46 +
  47 + public function setViParentsInfo($base, $mission, $instrument)
  48 + {
  49 + $this->base = $base;
  50 + $this->mission = $mission;
  51 + $this->instrument = $instrument;
  52 + }
  53 +
  54 + public function setViSampling($min_sampling, $max_sampling)
  55 + {
  56 + $this->min_sampling = $min_sampling;
  57 + $this->max_sampling = $max_sampling;
  58 + }
  59 +
  60 + public function setViLocation($mission_dir, $location)
  61 + {
  62 + $this->location = getenv("DDBASE")."/".$mission_dir."/".$location;
  63 + $this->ViDir = $this->location;
  64 + }
  65 +
  66 + // For Remote Data Centers
  67 + public function setViInfoFromFile($base, $ds)
  68 + {
  69 + $infoXml = new DomDocument("1.0");
  70 + $infoXmlFile = getenv("DDBASE")."/../INFO/DDServer/$base/$ds.xml";
  71 +
  72 + if (!file_exists($infoXmlFile))
  73 + return -100;
  74 +
  75 + if (!$infoXml->load($infoXmlFile))
  76 + return -10;
  77 + $this->base = $base;
  78 + $this->mission = $infoXml->getElementsByTagName("Mission")->item(0)->nodeValue;
  79 + $this->instrument = $infoXml->getElementsByTagName("Instrument")->item(0)->nodeValue;
  80 + $this->min_sampling = $infoXml->getElementsByTagName("MinSampling")->item(0)->nodeValue;
  81 + $this->remoteViId = $ds;
  82 + $this->globalStart = $infoXml->getElementsByTagName("GlobalStart")->item(0)->nodeValue;
  83 + $this->globalStop = $infoXml->getElementsByTagName("GlobalStop")->item(0)->nodeValue;
  84 +
  85 + $this->location = getenv("DDBASE")."/".$this->base."/".strtoupper($this->ViId)."/";
  86 + $this->ViDir = $this->location;
  87 + //--------- Check if additional Info should be added to VI
  88 +// $theFormat = $infoXml->getElementsByTagName("Format")->item(0);
  89 +// if ($theFormat != NULL)
  90 +// $AddInfo = ($theFormat->nodeValue == "Text");
  91 +// if (!$AddInfo)
  92 +// $AddInfo = ($infoXml->getElementsByTagName("AdditionalInfoNeed")->item(0) != NULL);
  93 +
  94 + return 0;
  95 + }
  96 +
  97 + public function viExists($ViId, $baseId)
  98 + {
  99 + $XPath = new DOMXpath($this->DDsysDoc);
  100 +
  101 + $dataSet = $XPath->query("//NAME[.='$ViId']");
  102 +
  103 + if ($dataSet->item(0) != NULL)
  104 + {
  105 + if ($dataSet->item(0)->getAttribute("base") != $baseId) return false;
  106 + else return true;
  107 + }
  108 +
  109 + return false;
  110 + }
  111 +
  112 + public function createVi()
  113 + {
  114 + $this->makeDDsys();
  115 + $this->makeAllInLocation();
  116 + }
  117 +
  118 + private function makeAllInLocation()
  119 + {
  120 + if (!is_dir($this->location))
  121 + mkdir($this->location, 0775, true);
  122 + $currDir = getcwd();
  123 +
  124 + chdir($this->location);
  125 + if (!file_exists($this->times)) system("TimesUpdate -r ".$this->times." ".$this->brief."_[0-9]*.nc");
  126 + if (!file_exists($this->info_xml)) $this->makeInfoXml();
  127 + if (!file_exists($this->info)) system("infoLocal2nc ".$this->info_xml." ".$this->info);
  128 + if (!file_exists("clean"))
  129 + {
  130 + copy(getenv("DDBASE")."/Cache.template", $this->cache);
  131 + $SED = "sed 's/NAME/".$this->brief."/g' ".getenv("DDBASE")."/Clean.template > clean";
  132 + exec($SED);
  133 + chmod("clean", 0755);
  134 + }
  135 +
  136 + chdir($currDir);
  137 + }
  138 +
  139 + private function makeInfoXml()
  140 + {
  141 + $xml_dom = new DomDocument("1.0");
  142 + $rootElement = $xml_dom->createElement("VI");
  143 + if ($this->base != "LOCAL")
  144 + $rootElement->appendChild($xml_dom->createElement("DataBaseID",$this->base));
  145 + $rootElement->appendChild($xml_dom->createElement("Mission",$this->mission));
  146 + $rootElement->appendChild($xml_dom->createElement("Instrument",$this->instrument));
  147 + if ($this->base != "LOCAL")
  148 + $rootElement->appendChild($xml_dom->createElement("DataSetID",$this->remoteViId));
  149 + $rootElement->appendChild($xml_dom->createElement("GlobalStart", $this->globalStart));
  150 + $rootElement->appendChild($xml_dom->createElement("GlobalStop", $this->globalStop));
  151 + $rootElement->appendChild($xml_dom->createElement("MinSampling", $this->min_sampling));
  152 + if ($this->max_sampling > $this->min_sampling)
  153 + $rootElement->appendChild($xml_dom->createElement("MaxSampling", $this->max_sampling));
  154 + $rootElement->appendChild($xml_dom->createElement("LocalStart"));
  155 + $rootElement->appendChild($xml_dom->createElement("LocalStop"));
  156 + $xml_dom->appendChild($rootElement);
  157 + $xml_dom->save($this->location."/".$this->info_xml);
  158 + }
  159 +
  160 + private function makeDDsys()
  161 + {
  162 + $newNode = $this->DDsysDoc->createElement("VI");
  163 + $name = $newNode->appendChild($this->DDsysDoc->createElement("NAME",$this->ViId));
  164 + $name->setAttribute('base', $this->base);
  165 + $name->setAttribute('mission', $this->mission);
  166 + $name->setAttribute('instrument', $this->instrument);
  167 +
  168 + if (substr($this->location, -1) !== "/")
  169 + $newNode->appendChild($this->DDsysDoc->createElement("LOCATION",$this->location."/"));
  170 + else
  171 + $newNode->appendChild($this->DDsysDoc->createElement("LOCATION",$this->location));
  172 +
  173 + $newNode->appendChild($this->DDsysDoc->createElement("TIMES", $this->times));
  174 + $newNode->appendChild($this->DDsysDoc->createElement("INFO", $this->info));
  175 + $newNode->appendChild($this->DDsysDoc->createElement("CACHE", $this->cache));
  176 +
  177 + $this->DDsysDoc->documentElement->appendChild($newNode);
  178 +
  179 + $this->DDsysDoc->save($this->DDsys);
  180 + system("makeDDsys");
  181 + }
  182 +
  183 + public function deleteVi($ViId, $baseId)
  184 + {
  185 +
  186 + }
  187 +
  188 +// public function getRemoteLocation($base, $remoteVi)
  189 +// {
  190 +// $XPath = new DOMXpath($this->DDsysDoc);
  191 +//
  192 +// $dataSet = $XPath->query("//NAME[.='$ViId']");
  193 +// $allVis = $this->DDsysDoc-
  194 +//
  195 +// }
  196 +
  197 + protected function lockVi()
  198 + {
  199 + // Stamp -> this directory is being updated
  200 +
  201 + touch($this->ViDir."/LOCK");
  202 +
  203 + // fprintf($STDERR,$ViDir." is LOCKED\n");
  204 + }
  205 +
  206 + protected function unlockVi()
  207 + {
  208 + if (file_exists($this->ViDir."/LOCK")) unlink($this->ViDir."/LOCK");
  209 + // fprintf($STDERR,$ViDir." is UNLOCKED\n");
  210 + }
  211 +
  212 + public function addRemoteData($id, $ncFiles, $start, $stop)
  213 + {
  214 + $this->lockVi();
  215 +
  216 + $WORKING_DIR = getcwd();
  217 + chdir($this->ViDir);
  218 + system("./clean");
  219 +
  220 + foreach ($ncFiles as $ncFile)
  221 + {
  222 + //TODO errors
  223 + //if (!file_exists($ncFile))
  224 + rename($WORKING_DIR."/".$ncFile,$this->ViDir."/".$ncFile);
  225 + system("TimesUpdate -u ".strtolower($id)."_times.nc ".$ncFile);
  226 + }
  227 +
  228 + system("TimesUpdateNoData ".strtolower($id)."_times.nc ".$start." ".$stop);
  229 +
  230 + chdir($WORKING_DIR);
  231 + $this->unlockVi();
  232 + }
  233 +}
  234 +?>
  235 +
0 236 \ No newline at end of file
... ...