Blame view

src/CALLEXT/createVI.php 3.96 KB
bd9dfce2   Benjamin Renard   Add CALLEXT and D...
1
<?php
dcb59fdf   Elena.Budnik   new CALLEXT
2
3
4
/**----------------------------------------------------------------------
*                   DD SERVER TOOLS
*                   data update collection 
bd9dfce2   Benjamin Renard   Add CALLEXT and D...
5
6
*  @file  createVI.php
*  @brief DD_Server tool <br> Creates New Virtual Instrument
dcb59fdf   Elena.Budnik   new CALLEXT
7
*  @version  
bd9dfce2   Benjamin Renard   Add CALLEXT and D...
8
9
10
11
*   Creates New VI at DD_Server Side \n
*   Args: dataBaseID  ddDataSetID  remoteDataSetID \n
*   Env Vars:  $DDBASE $DDBASEBIN $DDLIB \n
*   Executables: makeDDsys info2nc TimesUpdate \n
bd9dfce2   Benjamin Renard   Add CALLEXT and D...
12
*
dcb59fdf   Elena.Budnik   new CALLEXT
13
* @arg Checks if VI already exists in dataBase desctiptor DDsys.xml
bd9dfce2   Benjamin Renard   Add CALLEXT and D...
14
* @arg Adds non-existing VI to DDres.xml 
dcb59fdf   Elena.Budnik   new CALLEXT
15
* @arg makeDDsys creats refer.nc file from DDsys.xml
bd9dfce2   Benjamin Renard   Add CALLEXT and D...
16
* @arg Gets dataSet Info from INFO/DDServer dir
dcb59fdf   Elena.Budnik   new CALLEXT
17
* @arg Creates dir, *_cache.nc, *_info.nc and empty *_times.nc
bd9dfce2   Benjamin Renard   Add CALLEXT and D...
18
19
20
*
*/
  
dcb59fdf   Elena.Budnik   new CALLEXT
21
22
23
24
25
26
27
28
29
30
31
32
	if (!function_exists('__autoload')) 
	{
		function __autoload($class_name) {
				require_once $class_name . '.php';
		}
	}
	
   date_default_timezone_set('UTC');
   putenv("LD_LIBRARY_PATH=".getenv("LD_LIBRARY_PATH"));
	putenv("PATH=./:".getenv("DDBASEBIN").":/bin:/usr/bin");
	set_include_path("./:".getenv("DATAMANAGER").":".getenv("REMOTEDATA").":".getenv("CALLEXT")); 

155b6b3c   Elena.Budnik   other approach to...
33
	$verbose = true;
cf197d4f   Benjamin Renard   Fix bug when DDBA...
34
35
36
37
38
39
40
41

	$DDBASE=getenv("DDBASE");
	if (is_link($DDBASE)) {
		$DDBASE=readlink($DDBASE);
		if ($DDBASE === FALSE) {
			exit(0);
		}
	}
e3e17497   Benjamin Renard   Some fix around r...
42
	define('RemoteData',  $DDBASE."/../INFO");
dcb59fdf   Elena.Budnik   new CALLEXT
43
	
cf197d4f   Benjamin Renard   Fix bug when DDBA...
44
	$LOGDIR = $DDBASE."/../LOG/";
155b6b3c   Elena.Budnik   other approach to...
45
46
47
48
49
	if (!is_dir($LOGDIR))
				mkdir($LOGDIR, 0755, true);
				
	define("log",$LOGDIR."/addVI.log");
	define("err",$LOGDIR."/addVI.err");
35322ea6   Elena.Budnik   case of absence o...
50
			
dcb59fdf   Elena.Budnik   new CALLEXT
51
52
	if ($argc != 4) 
	{
35322ea6   Elena.Budnik   case of absence o...
53
		error_log("Usage: php createVI.php <BaseID> <RemSetID> <NewVIName>".PHP_EOL, 3, err);
dcb59fdf   Elena.Budnik   new CALLEXT
54
55
		exit("Usage: php createVI.php <BaseID> <RemSetID> <NewVIName>".PHP_EOL);
	}
bd9dfce2   Benjamin Renard   Add CALLEXT and D...
56
 
dcb59fdf   Elena.Budnik   new CALLEXT
57
58
59
60
	$base = strtoupper($argv[1]);
	$remSetID = $argv[2];
	$ViId = strtolower($argv[3]); 
	
35322ea6   Elena.Budnik   case of absence o...
61
62
63
64
	if ($verbose)
			error_log(date("Y-m-d\TH:i:s")." Request to add Data Set ".$base.":".$remSetID." as ".$ViId.PHP_EOL, 3, log);      
	error_log(date("Y-m-d\TH:i:s")." Request to add Data Set ".$base.":".$remSetID." as ".$ViId.PHP_EOL, 3, err);
	
dcb59fdf   Elena.Budnik   new CALLEXT
65
66
67
68
	$baseMgr = new DDBaseMgr();	
   
	$nc_prefix = strlen($ViId) > RemoteDataCenterClass::$MAX_VI_NAME_LENGTH ? 
					substr($ViId, 0, RemoteDataCenterClass::$MAX_VI_NAME_LENGTH - 1): $ViId;
bd9dfce2   Benjamin Renard   Add CALLEXT and D...
69
 
35322ea6   Elena.Budnik   case of absence o...
70
71
72
73
74
75
	if ($baseMgr->viExists($ViId, $base)) {
		if ($verbose)
				error_log($base." : ".$ViId." already Exists!!!".PHP_EOL, 3, log);
				
		die("$ViId Already Exists!!!".PHP_EOL);
	}
dcb59fdf   Elena.Budnik   new CALLEXT
76
77
78
79
80
81
82
83

	$baseMgr->setViId($ViId);
	$baseMgr->setViInfo($nc_prefix);
	$status = $baseMgr->setViInfoFromFile($base, $remSetID);

	if ($status === 0) 
	{
		$baseMgr->createVi();
dcb59fdf   Elena.Budnik   new CALLEXT
84
85
86
87
88
		$center = new $base();

		$startStamp = strtotime($baseMgr->globalStart);
		$stopStamp = strtotime($baseMgr->globalStart."+1 day");
		$start = date( "Ymd\THis\Z", $startStamp);
0ec21281   Elena.Budnik   reorganization + ...
89
		$stop = date( "Ymd\THis\Z", $stopStamp-60.0);
dcb59fdf   Elena.Budnik   new CALLEXT
90
91
92
		
		$startIso = date( "Y-m-d\TH:i:s\.000\Z", $startStamp);
		$stopIso = date( "Y-m-d\TH:i:s\.000\Z", $stopStamp);
0ec21281   Elena.Budnik   reorganization + ...
93
94
95
96
		// Get Full Dataset Info file from distant database
		$infoFile = $center->getDatasetInfo($remSetID);
		 
		if ($infoFile) 
c8f4ea1d   Elena.Budnik   new cdf2nc, updat...
97
		{			
0ec21281   Elena.Budnik   reorganization + ...
98
99
100
			$baseMgr->setInfo($infoFile);
		}
		 
dcb59fdf   Elena.Budnik   new CALLEXT
101
102
		$ncFiles = $center->getData($remSetID, $start, $stop);
		
0ec21281   Elena.Budnik   reorganization + ...
103
104
		if (!$infoFile && $ncFiles)
		{
35322ea6   Elena.Budnik   case of absence o...
105
			 if ($verbose) 
e3e17497   Benjamin Renard   Some fix around r...
106
					error_log("No dataset info file for ".$remSetID." from ".$ViId." uses regular file".PHP_EOL, 3, log);
35322ea6   Elena.Budnik   case of absence o...
107
108
109
110
					
			$infoFileName = strtolower($remSetID).".nc";		
			copy($ncFiles[0], $infoFileName);		
			$baseMgr->setInfo($infoFileName);
0ec21281   Elena.Budnik   reorganization + ...
111
112
		}
		
c8f4ea1d   Elena.Budnik   new cdf2nc, updat...
113
114
115
116
		$baseMgr->addRemoteData($remSetID, $ncFiles, $startIso, $stopIso); 
		// put real Global Start from file - IMPORTANT for new AMDA Kernel
		$baseMgr->updateRemoteStart();
		
155b6b3c   Elena.Budnik   other approach to...
117
//     if ($verbose) error_log("Get dataset info for ".$remSetID." from ".$dataBaseID." returns ".$res.PHP_EOL, 3, log);
dcb59fdf   Elena.Budnik   new CALLEXT
118
119
120
121
122
123
124
125
126
127
128
129
130
	 
				 

// 			if ($AddInfo) 
// 			{
// 				$function_name = "createHeader".$dataBaseID;
// 				require_once(DDLIB.$function_name.".php");
// 				$function_name($remSetID); 
// 			}
//			if (verbose) error_log("Added ".$VIID.PHP_EOL, 3, log); 
	}
	else 
	{
155b6b3c   Elena.Budnik   other approach to...
131
		if ($verbose) error_log("No DDServer Info File for $base  $ViId".PHP_EOL, 3, log); 
dcb59fdf   Elena.Budnik   new CALLEXT
132
133
	}
		 
cf197d4f   Benjamin Renard   Fix bug when DDBA...
134
?>