Commit 68de0b397e6ec2d3b696ccb69313c3cd495a9a4f

Authored by Benjamin Renard
2 parents f1252b32 9e741d41

Merge branch master into install-rework

src/ClientTypeEnumClass.php
... ... @@ -8,6 +8,6 @@ abstract class ClientTypeEnumClass
8 8 {
9 9 const IHM = "ihm";
10 10 const TEST = "test";
11   - const WEBSERVICE = "webservice";
  11 + const WS = "webservice";
12 12 }
13 13 ?>
... ...
src/InputOutput/IHMImpl/Config/IHMConfigClass.php
... ... @@ -75,16 +75,21 @@ class IHMConfigClass
75 75 return self::$userHost;
76 76 }
77 77  
  78 + public static function getDataDir()
  79 + {
  80 + return IHM_SRC_DIR."/".self::$dataDir.'/';
  81 + }
  82 +
78 83 public static function getRelativeResultPath()
79 84 {
80   - $userPath = self::$dataDir.self::$userName.'/'.self::$requestDir;
  85 + $userPath = self::$dataDir."/".self::$userName.'/'.self::$requestDir;
81 86  
82 87 return $userPath;
83 88 }
84 89  
85 90 public static function getUserPath()
86 91 {
87   - $userPath = IHM_SRC_DIR.'/'.self::$dataDir.self::$userName.'/';
  92 + $userPath = self::getDataDir().self::$userName.'/';
88 93  
89 94 if (!is_dir($userPath))
90 95 mkdir($userPath);
... ... @@ -94,22 +99,27 @@ class IHMConfigClass
94 99  
95 100 public static function getProcessManagerFilePath()
96 101 {
97   - return IHM_SRC_DIR.'/'.self::$dataDir.self::$processMgrFile;
  102 + return self::getDataDir().self::$processMgrFile;
98 103 }
99   -
  104 +
  105 + public static function getGenericDataPath()
  106 + {
  107 + return IHM_SRC_DIR."/".self::$genericDataDir."/";
  108 + }
  109 +
100 110 public static function getConstantsFilePath()
101 111 {
102   - return IHM_SRC_DIR.'/'.self::$genericDataDir.self::$functionsDir.self::$constantsFile;
  112 + return self::getGenericDataPath().self::$functionsDir.self::$constantsFile;
103 113 }
104 114  
105 115 public static function getFunctionsFilePath()
106 116 {
107   - return IHM_SRC_DIR.'/'.self::$genericDataDir.self::$functionsDir.self::$functionsFile;
  117 + return self::getGenericDataPath().self::$functionsDir.self::$functionsFile;
108 118 }
109 119  
110 120 public static function getParamTemplateFilePath($fileName)
111 121 {
112   - return IHM_SRC_DIR.'/'.self::$genericDataDir.self::$paramTemplateDir.$fileName.".xml";
  122 + return self::getGenericDataPath().self::$paramTemplateDir.$fileName.".xml";
113 123 }
114 124  
115 125 public static function getTemplateParamGeneratePath()
... ... @@ -124,7 +134,7 @@ class IHMConfigClass
124 134  
125 135 public static function getParamTemplateListFilePath()
126 136 {
127   - return IHM_SRC_DIR.'/'.self::$genericDataDir.self::$paramTemplateDir.self::$paramTemplateFile;
  137 + return self::getGenericDataPath().self::$paramTemplateDir.self::$paramTemplateFile;
128 138 }
129 139  
130 140 public static function getUserParamManagerFilePath()
... ... @@ -238,7 +248,7 @@ class IHMConfigClass
238 248  
239 249 public static function getRemoteDataPath()
240 250 {
241   - $remoteDataPath = IHM_SRC_DIR.'/'.self::$genericDataDir.self::$remoteDataDir;
  251 + $remoteDataPath = self::getGenericDataPath().self::$remoteDataDir;
242 252  
243 253 return $remoteDataPath;
244 254 }
... ...
src/InputOutput/IHMImpl/IHMInputOutputClass.php
1   -<?php
2   -
3   -/**
4   - * @class IHMInputOutputClass
5   - * @brief Class that's implement an InputOutputInterface for AMDA IHM client.
6   - * @details
7   - */
8   -class IHMInputOutputClass implements InputOutputInterface
9   -{
10   - private $inputOutput = null;
11   -
12   - /*
13   - * @brief Constructor
14   - */
15   - function __construct($userName, $userHost)
16   - {
17   - IHMConfigClass::setUserName($userName);
18   - IHMConfigClass::setUserHost($userHost);
19   - }
20   -
21   - /*
22   - * @brief translate input data from AMDA IHM to AMDA_Integration module
23   - */
24   - public function getInputData($input,$function,$requestId = "")
25   - {
26   - //check user workspace
27   - if (IHMConfigClass::getUserName() == "" || !is_dir(IHMConfigClass::getUserPath()))
28   - throw new Exception('Cannot find user workspace.');
29   -
30   - switch ($function)
31   - {
32   - case FunctionTypeEnumClass::PARAMS :
33   - switch ($input->nodeType)
34   - {
35   - case 'download' :
36   - //download data
37   - if ($input->downloadSrc != "0")
38   - throw new Exception('Download source '.$input->downloadSrc.' not implemented for this client.');
39   - $this->inputOutput = new IHMInputOutputParamsDownloadClass();
40   - break;
41   - case 'condition' :
42   - //data mining
43   - $this->inputOutput = new IHMInputOutputParamsDataMiningClass();
44   - break;
45   - case 'request' :
46   - //plot
47   - if (($input->{"file-format"} == "PNG") && ($input->{"file-output"} == "INTERACTIVE"))
48   - {
49   - //set working dir for interactive plot
50   - $requestId = "Plot";
51   - }
52   - $this->inputOutput = new IHMInputOutputParamsPlotClass();
53   - break;
54   - case 'statistics' :
55   - //catalog generation
56   - $this->inputOutput = new IHMInputOutputParamsStatisticsClass();
57   - break;
58   - case 'killplot' :
59   - $requestId = "Plot";
60   - $this->inputOutput = new IHMInputOutputParamsKillPlotClass();
61   - break;
62   - default :
63   - throw new Exception('Params request type '.$input_request->nodeType.' not implemented for this client.');
64   - }
65   - break;
66   - case FunctionTypeEnumClass::PARAMSGEN :
67   - $this->inputOutput = new IHMInputOutputParamsGeneratorClass();
68   - $requestId = "ParamGen";
69   - break;
70   - case FunctionTypeEnumClass::ACTION :
71   - $this->inputOutput = new IHMInputOutputParamsPlotClass();
72   - $requestId = "Plot";
73   - break;
74   - case FunctionTypeEnumClass::PROCESSDELETE :
75   - $this->inputOutput = new IHMInputOutputDeleteProcessClass();
76   - break;
77   - case FunctionTypeEnumClass::PROCESSRUNNINGINFO :
78   - $this->inputOutput = new IHMInputOutputRunningInfoProcessClass();
79   - break;
80   - case FunctionTypeEnumClass::PROCESSGETINFO :
81   - $this->inputOutput = new IHMInputOutputGetInfoProcessClass();
82   - break;
83   - case FunctionTypeEnumClass::PROCESSCLEAN :
84   - $this->inputOutput = new IHMInputOutputCleanProcessClass();
85   - break;
86   - case FunctionTypeEnumClass::PROCESSGETREQUEST :
87   - $this->inputOutput = new IHMInputOutputGetProcessRequestClass();
88   - break;
89   - /*case FunctionTypeEnumClass::TTMERGE :
90   - $this->inputOutput = new IHMInputOutputMergeTTClass();
91   - break;
92   - case FunctionTypeEnumClass::TTUNION :
93   - $this->inputOutput = new IHMInputOutputUnionTTClass();
94   - break;*/
95   - case FunctionTypeEnumClass::TTCONVERT :
96   - $this->inputOutput = new IHMInputOutputTTClass();
97   - break;
98   - case FunctionTypeEnumClass::PARAMINFO :
99   - $this->inputOutput = new IHMInputOutputParamInfoClass();
100   - break;
101   - default :
102   - throw new Exception('Request type '.$function.' not implemented for this client.');
103   - }
104   -
105   - return $this->inputOutput->getInputData($input,$function,$requestId);
106   - }
107   -
108   - /*
109   - * @brief translate output data from AMDA_Integration module to AMDA IHM
110   - */
111   - public function getOutput($data)
112   - {
113   - if (!isset($this->inputOutput))
114   - return array("success" => false, "message" => "Input Output Interface not initialized for this request");
115   -
116   - return $this->inputOutput->getOutput($data);
117   - }
118   -}
119   -
120   -?>
  1 +<?php
  2 +
  3 +/**
  4 + * @class IHMInputOutputClass
  5 + * @brief Class that's implement an InputOutputInterface for AMDA IHM client.
  6 + * @details
  7 + */
  8 +class IHMInputOutputClass implements InputOutputInterface
  9 +{
  10 + protected $inputOutput = null;
  11 +
  12 + /*
  13 + * @brief Constructor
  14 + */
  15 + function __construct($userName, $userHost)
  16 + {
  17 + IHMConfigClass::setUserName($userName);
  18 + IHMConfigClass::setUserHost($userHost);
  19 + }
  20 +
  21 + /*
  22 + * @brief translate input data from AMDA IHM to AMDA_Integration module
  23 + */
  24 + public function getInputData($input,$function,$requestId = "")
  25 + {
  26 + //check user workspace
  27 + if (IHMConfigClass::getUserName() == "" || !is_dir(IHMConfigClass::getUserPath()))
  28 + throw new Exception('Cannot find user workspace.');
  29 +
  30 + switch ($function)
  31 + {
  32 + case FunctionTypeEnumClass::PARAMS :
  33 + switch ($input->nodeType)
  34 + {
  35 + case 'download' :
  36 + //download data
  37 + if ($input->downloadSrc != "0")
  38 + throw new Exception('Download source '.$input->downloadSrc.' not implemented for this client.');
  39 + $this->inputOutput = new IHMInputOutputParamsDownloadClass();
  40 + break;
  41 + case 'condition' :
  42 + //data mining
  43 + $this->inputOutput = new IHMInputOutputParamsDataMiningClass();
  44 + break;
  45 + case 'request' :
  46 + //plot
  47 + if (($input->{"file-format"} == "PNG") && ($input->{"file-output"} == "INTERACTIVE"))
  48 + {
  49 + //set working dir for interactive plot
  50 + $requestId = "Plot";
  51 + }
  52 + $this->inputOutput = new IHMInputOutputParamsPlotClass();
  53 + break;
  54 + case 'statistics' :
  55 + //catalog generation
  56 + $this->inputOutput = new IHMInputOutputParamsStatisticsClass();
  57 + break;
  58 + case 'killplot' :
  59 + $requestId = "Plot";
  60 + $this->inputOutput = new IHMInputOutputParamsKillPlotClass();
  61 + break;
  62 + default :
  63 + throw new Exception('Params request type '.$input_request->nodeType.' not implemented for this client.');
  64 + }
  65 + break;
  66 + case FunctionTypeEnumClass::PARAMSGEN :
  67 + $this->inputOutput = new IHMInputOutputParamsGeneratorClass();
  68 + $requestId = "ParamGen";
  69 + break;
  70 + case FunctionTypeEnumClass::ACTION :
  71 + $this->inputOutput = new IHMInputOutputParamsPlotClass();
  72 + $requestId = "Plot";
  73 + break;
  74 + case FunctionTypeEnumClass::PROCESSDELETE :
  75 + $this->inputOutput = new IHMInputOutputDeleteProcessClass();
  76 + break;
  77 + case FunctionTypeEnumClass::PROCESSRUNNINGINFO :
  78 + $this->inputOutput = new IHMInputOutputRunningInfoProcessClass();
  79 + break;
  80 + case FunctionTypeEnumClass::PROCESSGETINFO :
  81 + $this->inputOutput = new IHMInputOutputGetInfoProcessClass();
  82 + break;
  83 + case FunctionTypeEnumClass::PROCESSCLEAN :
  84 + $this->inputOutput = new IHMInputOutputCleanProcessClass();
  85 + break;
  86 + case FunctionTypeEnumClass::PROCESSGETREQUEST :
  87 + $this->inputOutput = new IHMInputOutputGetProcessRequestClass();
  88 + break;
  89 + /*case FunctionTypeEnumClass::TTMERGE :
  90 + $this->inputOutput = new IHMInputOutputMergeTTClass();
  91 + break;
  92 + case FunctionTypeEnumClass::TTUNION :
  93 + $this->inputOutput = new IHMInputOutputUnionTTClass();
  94 + break;*/
  95 + case FunctionTypeEnumClass::TTCONVERT :
  96 + $this->inputOutput = new IHMInputOutputTTClass();
  97 + break;
  98 + case FunctionTypeEnumClass::PARAMINFO :
  99 + $this->inputOutput = new IHMInputOutputParamInfoClass();
  100 + break;
  101 + default :
  102 + throw new Exception('Request type '.$function.' not implemented for this client.');
  103 + }
  104 +
  105 + return $this->inputOutput->getInputData($input,$function,$requestId);
  106 + }
  107 +
  108 + /*
  109 + * @brief translate output data from AMDA_Integration module to AMDA IHM
  110 + */
  111 + public function getOutput($data)
  112 + {
  113 + if (!isset($this->inputOutput))
  114 + return array("success" => false, "message" => "Input Output Interface not initialized for this request");
  115 +
  116 + return $this->inputOutput->getOutput($data);
  117 + }
  118 +}
  119 +
  120 +?>
... ...
src/InputOutput/IHMImpl/Params/IHMInputOutputParamsAbstractClass.php
... ... @@ -14,8 +14,8 @@ abstract class IHMInputOutputParamsAbstractClass implements InputOutputInterface
14 14 protected $paramsData = null;
15 15 protected $requestID = "";
16 16 protected $requestDirPrefix = "";
17   - private $input = null;
18   - protected $sendToSamp = FALSE;
  17 + protected $input = null;
  18 + protected $sendToSamp = FALSE;
19 19  
20 20 /*
21 21 * @brief Constructor
... ... @@ -117,13 +117,13 @@ abstract class IHMInputOutputParamsAbstractClass implements InputOutputInterface
117 117 */
118 118 protected function addToJobsFile($data,$resultKey)
119 119 {
120   - $waitingResult = $data->getWaitingResult($resultKey);
121   - if ($this->sendToSamp && ($data->getStatus() == ProcessStatusEnumClass::DONE)) {
122   - $waitingResult = explode("\n", file_get_contents(IHMConfigClass::getRequestPath()."/".$this->getWorkingDirName()."/".$waitingResult));
123   - $waitingResult = implode(',', $waitingResult);
124   - $waitingResult = rtrim($waitingResult, ',');
125   - }
126   -
  120 + $waitingResult = $data->getWaitingResult($resultKey);
  121 + if ($this->sendToSamp && ($data->getStatus() == ProcessStatusEnumClass::DONE)) {
  122 + $waitingResult = explode("\n", file_get_contents(IHMConfigClass::getRequestPath()."/".$this->getWorkingDirName()."/".$waitingResult));
  123 + $waitingResult = implode(',', $waitingResult);
  124 + $waitingResult = rtrim($waitingResult, ',');
  125 + }
  126 +
127 127 return $this->jobsManager->addJob(
128 128 $this->input,
129 129 $data->getId(),
... ... @@ -147,42 +147,42 @@ abstract class IHMInputOutputParamsAbstractClass implements InputOutputInterface
147 147 foreach ($res['jobs'] as $jobId)
148 148 {
149 149 //delete process
150   - $deleteData = new ProcessRequestDataClass();
151   - $deleteData->setManagerFilePath(IHMConfigClass::getProcessManagerFilePath());
152   - $deleteData->setType(ProcessTypeEnumClass::DELETE);
153   - $deleteData->setId($jobId);
154   -
155   - $processRequest = new ProcessRequestClass();
156   - $processRequest->setData($deleteData);
157   -
158   - if ($processRequest->init())
  150 + $deleteData = new ProcessRequestDataClass();
  151 + $deleteData->setManagerFilePath(IHMConfigClass::getProcessManagerFilePath());
  152 + $deleteData->setType(ProcessTypeEnumClass::DELETE);
  153 + $deleteData->setId($jobId);
  154 +
  155 + $processRequest = new ProcessRequestClass();
  156 + $processRequest->setData($deleteData);
  157 +
  158 + if ($processRequest->init())
159 159 $processRequest->run();
160 160  
161   - //delete job and working dir
  161 + //delete job and working dir
162 162 $this->jobsManager->deleteJob($jobId);
163 163 }
164 164 }
165 165 /*
166 166 * @brief Marshall request result for the IHM client
167 167 */
168   - protected function commonMarshallResult($data,$resultKey)
169   - {
170   - if (!$data->getSuccess())
171   - return array(
172   - 'success' => false,
173   - 'message' => $data->getLastErrorMessage());
174   -
175   - switch ($data->getStatus())
176   - {
  168 + protected function commonMarshallResult($data,$resultKey)
  169 + {
  170 + if (!$data->getSuccess())
  171 + return array(
  172 + 'success' => false,
  173 + 'message' => $data->getLastErrorMessage());
  174 +
  175 + switch ($data->getStatus())
  176 + {
177 177 case ProcessStatusEnumClass::ERROR :
178   - case ProcessStatusEnumClass::RUNNING :
  178 + case ProcessStatusEnumClass::RUNNING :
179 179 case ProcessStatusEnumClass::DONE :
180   - return $this->addToJobsFile($data,$resultKey);
181   - default :
182   - return array(
183   - 'success' => false,
184   - 'message' => 'Unknown Process Status');
185   - }
  180 + return $this->addToJobsFile($data,$resultKey);
  181 + default :
  182 + return array(
  183 + 'success' => false,
  184 + 'message' => 'Unknown Process Status');
  185 + }
186 186 }
187 187  
188 188 /*
... ... @@ -201,7 +201,7 @@ abstract class IHMInputOutputParamsAbstractClass implements InputOutputInterface
201 201 }
202 202 else
203 203 {
204   - $this->requestDirPrefix = "";
  204 + $this->requestDirPrefix = "";
205 205 $this->requestID = $requestId;
206 206  
207 207 }
... ... @@ -233,4 +233,4 @@ abstract class IHMInputOutputParamsAbstractClass implements InputOutputInterface
233 233 abstract protected function marshallResult($data);
234 234 }
235 235  
236   -?>
  236 +?>
... ...
src/InputOutput/IHMImpl/Process/IHMInputOutputDeleteProcessClass.php
... ... @@ -7,7 +7,7 @@
7 7 */
8 8 class IHMInputOutputDeleteProcessClass implements InputOutputInterface
9 9 {
10   - private $jobsManager = null;
  10 + protected $jobsManager = null;
11 11 private $paramsData = null;
12 12  
13 13 /*
... ...
src/InputOutput/IHMImpl/Tools/IHMJobsManagerClass.php
... ... @@ -28,7 +28,7 @@ class IHMJobsManagerClass {
28 28 /*
29 29 * @brief Load jobs file and create it if needed
30 30 */
31   - private function init()
  31 + protected function init()
32 32 {
33 33 $this->jobXmlName = IHMConfigClass::getUserJobsFile();
34 34 $this->jobXml = new DomDocument("1.0");
... ... @@ -52,7 +52,7 @@ class IHMJobsManagerClass {
52 52 /*
53 53 * @brief Create a new jobs file
54 54 */
55   - private function createJobsFile()
  55 + protected function createJobsFile()
56 56 {
57 57 $rootElement = $this->jobXml->createElement('jobs');
58 58 $jobsInProgress = $this->jobXml->createElement('jobsInProgress');
... ...
src/InputOutput/IHMImpl/Tools/IHMParamTemplateClass.php
... ... @@ -173,7 +173,7 @@ class IHMParamTemplateClass
173 173 if (!$templateHandle || !$dstHandle)
174 174 return "";
175 175 while (($line = fgets($templateHandle)) !== false) {
176   - fwrite($dstHandle, $this->replaceArgs($line, $template_args));
  176 + fwrite($dstHandle, $this->replaceArgs($line, $template_args, $this->getArguments($param_id)));
177 177 }
178 178 fclose($templateHandle);
179 179 fclose($dstHandle);
... ... @@ -218,13 +218,17 @@ class IHMParamTemplateClass
218 218 /*
219 219 * @brief Replace args in string
220 220 */
221   - public function replaceArgs($string, $template_args) {
  221 + public function replaceArgs($string, $template_args, $arguments = array()) {
222 222 $result = $string;
223 223 if (empty($template_args)) {
224 224 return $result;
225 225 }
226 226 foreach ($template_args as $template_arg_key => $template_arg_value) {
227 227 $result = str_replace("##".$template_arg_key."##", $template_arg_value, $result);
  228 + if (array_key_exists($template_arg_key, $arguments) && ($arguments[$template_arg_key]['type'] == 'list')) {
  229 + $item_name = array_key_exists($template_arg_value, $arguments[$template_arg_key]['items']) ? $arguments[$template_arg_key]['items'][$template_arg_value] : 'Unknown';
  230 + $result = str_replace("@@".$template_arg_key."@@", $item_name, $result);
  231 + }
228 232 }
229 233 return $result;
230 234 }
... ... @@ -233,17 +237,25 @@ class IHMParamTemplateClass
233 237 * @brief Enrich Template args with default values
234 238 */
235 239 private function addDefaultValues($param_id, &$template_args) {
236   - $list = $this->getParamTemplates();
237   -
238   - if (!array_key_exists($param_id, $list) || !isset($list[$param_id]->arguments))
  240 + $arguments = $this->getArguments($param_id);
  241 + if (empty($arguments))
239 242 return;
240   -
241   - $arguments = $list[$param_id]->arguments;
242 243 foreach ($arguments as $arg_key => $arg_def) {
243 244 if (!array_key_exists($arg_key, $template_args))
244 245 $template_args[$arg_key] = $arg_def->default;
245 246 }
246 247 }
  248 +
  249 + /*
  250 + * @brief Get list of arguments for a given parameter
  251 + */
  252 + protected function getArguments($param_id) {
  253 + $list = $this->getParamTemplates();
  254 +
  255 + if (!array_key_exists($param_id, $list) || !isset($list[$param_id]['arguments']))
  256 + return array();
  257 + return $list[$param_id]['arguments'];
  258 + }
247 259  
248 260 /*
249 261 * @brief Load list of templated parameters
... ...
src/InputOutput/WSImpl/Config/WSConfigClass.php 0 โ†’ 100644
... ... @@ -0,0 +1,60 @@
  1 +<?php
  2 +/**
  3 + * @class WSConfigClass
  4 + * @brief Class that's contain all specific configuration of the WebServices client
  5 + * @details
  6 + */
  7 +class WSConfigClass
  8 +{
  9 + const PARAMETER = "getparameter";
  10 + const PLOT = "getplot";
  11 + const ORBIT = "getorbites";
  12 + const DATASET = "getdataset";
  13 +
  14 + public static $timeToBatchMode = 10;
  15 + public static $enableBatch = true;
  16 + public static $file_prefix = "result_";
  17 + public static $timeLimitQuery = 600; // secs
  18 +
  19 + //TODO define during installation
  20 + private static $xslDir = "xml/";
  21 +
  22 + private static $wsResultDir = "WSRESULT";
  23 + private static $jobsFile = "WSjobs.xml";
  24 +
  25 + // TODO define during installation
  26 + private static $WebUrl = "http://apus.irap.omp.eu/NEWAMDA/data/";
  27 +
  28 + private static $dataSetInfoDir = "DataSetInfo";
  29 +
  30 + public static function getUrl()
  31 + {
  32 + return self::$WebUrl.self::$wsResultDir.'/';
  33 + }
  34 +
  35 + public static function getWsResultDir()
  36 + {
  37 + return IHMConfigClass::getDataDir().self::$wsResultDir.'/';
  38 + }
  39 +
  40 + public static function getWsJobsFile()
  41 + {
  42 + return IHMConfigClass::getDataDir().self::$wsResultDir.'/'.self::$jobsFile;
  43 + }
  44 +
  45 + public static function getDataSetInfoDir()
  46 + {
  47 + return IHMConfigClass::getGenericDataPath().self::$dataSetInfoDir.'/';
  48 + }
  49 +
  50 + public static function getXslDir()
  51 + {
  52 + return IHM_SRC_DIR."php/WebServices/".self::$xslDir;
  53 + }
  54 +
  55 + public static function getOrbitsXml()
  56 + {
  57 + return IHMConfigClass::getGenericDataPath()."LocalData/OrbitsAll.xml";
  58 + }
  59 +}
  60 +?>
... ...
src/InputOutput/WSImpl/Params/DownloadImpl/WSInputOutputParamsDownloadClass.php 0 โ†’ 100644
... ... @@ -0,0 +1,248 @@
  1 +<?php
  2 +
  3 +/**
  4 + * @class WSInputOutputParamsDownloadClass
  5 + * @brief Implementation of IHMInputOutputParamsAbstractClass to treat download request
  6 + * @details
  7 +*/
  8 +class WSInputOutputParamsDownloadClass extends IHMInputOutputParamsAbstractClass
  9 +{
  10 + /*
  11 + * @brief Constructor
  12 + */
  13 + function __construct()
  14 + {
  15 + $this->paramManager = new IHMParamManagerClass();
  16 + $this->jobsManager = new WSJobsManagerClass();
  17 + }
  18 + /*
  19 + * @brief method to unmarshall a download request
  20 + */
  21 + protected function unmarshallRequest($input)
  22 + {
  23 + $requestNode = $this->paramsData->addRequestNode();
  24 +
  25 + $paramsNode = $requestNode->getParamsNode();
  26 +
  27 + //unmarshall time definition
  28 + $this->unmarshallTimeDefinition($input, 0);
  29 +
  30 + //unmarshall download output definition
  31 + $outputsNode = $requestNode->getOutputsNode();
  32 + $downloadNode = $outputsNode->addNewOutput(RequestOutputTypeEnum::DOWNLOAD);
  33 +
  34 + switch ($input->timeformat)
  35 + {
  36 + case 'ISO08601' :
  37 + $downloadNode->setTimeFormat(RequestOutputDownloadTimeFormatEnum::ISO);
  38 + break;
  39 + case 'unixtime' :
  40 + $downloadNode->setTimeFormat(RequestOutputDownloadTimeFormatEnum::TIMESTAMP);
  41 + break;
  42 + default :
  43 + $downloadNode->setTimeFormat(RequestOutputDownloadTimeFormatEnum::ISO);
  44 + }
  45 +
  46 + switch ($input->fileformat)
  47 + {
  48 + case "CDF" :
  49 + $downloadNode->setFileFormat(RequestOutputDownloadFileFormatEnum::CDF);
  50 + $formatExtension = ".cdf";
  51 + break;
  52 + case "ASCII" :
  53 + $downloadNode->setFileFormat(RequestOutputDownloadFileFormatEnum::ASCII);
  54 + $formatExtension = ".txt";
  55 + break;
  56 + case "VOTable" :
  57 + $downloadNode->setFileFormat(RequestOutputDownloadFileFormatEnum::VOTABLE);
  58 + $formatExtension = ".vot";
  59 + break;
  60 + case "netCDF" :
  61 + throw new Exception('File format '.$input->fileformat.' not implemented yet');
  62 + break;
  63 + default :
  64 + $downloadNode->setFileFormat(RequestOutputDownloadFileFormatEnum::ASCII);
  65 + $formatExtension = ".txt";
  66 + }
  67 +
  68 + //add params to output
  69 + $resultFile = WSInputOutputClass::getService();
  70 + $isFirst = true;
  71 +
  72 + foreach ($input->list as $param)
  73 + {
  74 + $paramInfo = $this->paramManager->addExistingParam($param->paramid, $this->paramsData, $param->template_args);
  75 +
  76 + switch ($param->type) {
  77 + case 0:
  78 + //scalar - nothing to do
  79 + break;
  80 + case 1:
  81 + //Tab1D
  82 + if ($param->{'dim1-is-range'}) {
  83 + $template_args = array(
  84 + 'paramid' => $paramInfo['id'],
  85 + 'min' => $param->{'dim1-min-range'},
  86 + 'max' => $param->{'dim1-max-range'},
  87 + 'relateddim' => 0
  88 + );
  89 + $paramInfo = $this->paramManager->addExistingParam('sum_into_table_range', $this->paramsData, $template_args);
  90 + }
  91 + else {
  92 + if (($param->{'dim1-index'} != '*') && ($param->{'dim1-index'} != '')) {
  93 + $paramInfo['indexes'] = array();
  94 + $paramInfo['indexes'][] = $param->{'dim1-index'};
  95 + }
  96 + }
  97 +
  98 + if ($param->{'dim2-is-range'}) {
  99 + $template_args = array(
  100 + 'paramid' => $paramInfo['id'],
  101 + 'min' => $param->{'dim2-min-range'},
  102 + 'max' => $param->{'dim2-max-range'},
  103 + 'relateddim' => 1
  104 + );
  105 + $paramInfo = $this->paramManager->addExistingParam('sum_into_table_range', $this->paramsData, $template_args);
  106 + }
  107 + else {
  108 + if (($param->{'dim2-index'} != '*') && ($param->{'dim2-index'} != '')) {
  109 + $paramInfo['indexes'] = array();
  110 + $paramInfo['indexes'][] = $param->{'dim2-index'};
  111 + }
  112 + }
  113 + break;
  114 + case 2:
  115 + if (($param->{'dim1-index'} != '*') || ($param->{'dim2-index'} != '*')) {
  116 + $paramInfo['indexes'] = array();
  117 + $paramInfo['indexes'][] = "[".$param->{'dim1-index'}.",".$param->{'dim2-index'}."]";
  118 + }
  119 + break;
  120 + }
  121 +
  122 + $downloadNode->addParam($paramInfo['id'],$paramInfo['indexes'],$paramInfo['calib_infos']);
  123 + $paramsNode->addParam($paramInfo['id']);
  124 +
  125 + if ( WSInputOutputClass::getService() == WSConfigClass::DATASET && $isFirst)
  126 + {
  127 + $resultFile .= "_".$this->getDatasetIdFromParamInfo($param->paramid);
  128 + $isFirst = false;
  129 + }
  130 + elseif ( WSInputOutputClass::getService() != WSConfigClass::DATASET )
  131 + {
  132 + $resultFile .= "_".$paramInfo['id'];
  133 + if (!empty($paramInfo['indexes']))
  134 + foreach ($paramInfo['indexes'] as $index)
  135 + $resultFile .= "_".$index;
  136 + }
  137 +
  138 + }
  139 +
  140 + if ($input->sampling)
  141 + {
  142 + $downloadNode->setSamplingTime($input->sampling);
  143 + $downloadNode->setStructure(RequestOutputDownloadStructureEnum::ONE_FILE);
  144 + }
  145 + else {
  146 + $downloadNode->setStructure(RequestOutputDownloadStructureEnum::ONE_FILE_PER_PARAMETER_PER_INTERVAL);
  147 + }
  148 +
  149 + switch ($input->compression)
  150 + {
  151 + case "1" :
  152 + $extension = $formatExtension.".gz";
  153 + $downloadNode->addPostProcessing(RequestOutputPostProcessingEnumClass::GZIP);
  154 + $resultFilePrefix = "output-";
  155 + break;
  156 + case "0" :
  157 + default :
  158 + $extension = $formatExtension;
  159 + $resultFilePrefix = "output-";
  160 + }
  161 +
  162 + $resultFile .= "_".date("Ymd\THis", strtotime($input->startDate))."_".date("Ymd\THis",strtotime($input->stopDate));
  163 +
  164 + $this->paramsData->addWaitingResult(WSInputOutputClass::getService(), $resultFile.$extension);
  165 +
  166 + // internal kernel output
  167 + $postProcessCmd = "mv ".$resultFilePrefix."*";
  168 +
  169 + $postProcessCmd .= $extension;
  170 + $postProcessCmd .= " ".WSConfigClass::getWsResultDir().$resultFile.$extension;
  171 +
  172 + $this->paramsData->setPostCmd($postProcessCmd);
  173 +
  174 +
  175 + $this->paramsData->setBatchEnable(WSConfigClass::$enableBatch);
  176 +
  177 + return $this->paramsData;
  178 + }
  179 +
  180 + /*
  181 + * @brief Unmarshall the time definition from the WS request
  182 + */
  183 + protected function unmarshallTimeDefinition($input, $requestIndex)
  184 + {
  185 + $requestNodes = $this->paramsData->getRequestNodes();
  186 + $timesNode = $requestNodes[$requestIndex]->getTimesNode();
  187 +
  188 + date_default_timezone_set('UTC');
  189 + $timeStamp = strtotime($input->startDate);
  190 + $start = CommonClass::timeStampToDDTime($timeStamp);
  191 + $timeStamp = strtotime($input->stopDate) - strtotime($input->startDate);
  192 + $duration = CommonClass::timeStampToDDTime($timeStamp);
  193 + $timesNode->addInterval($start, $duration);
  194 + }
  195 +
  196 + /*
  197 + * @brief Add a job to the job manager
  198 + */
  199 + protected function addToJobsFile($data,$resultKey)
  200 + {
  201 + $waitingResult = $data->getWaitingResult($resultKey);
  202 +
  203 + return $this->jobsManager->addJob(
  204 + $this->input,
  205 + $data->getId(),
  206 + $this->getWorkingDirName(),
  207 + $data->getStatus() == ProcessStatusEnumClass::RUNNING,
  208 + $data->getStart(),
  209 + $waitingResult,
  210 + $data->getErrorCode());
  211 + }
  212 +
  213 + protected function getDatasetIdFromParamInfo($paramId)
  214 + {
  215 + $paramInfoFilePath = IHMConfigClass::getLocalParamDBPath().$paramId.".xml";
  216 + $dom = new DomDocument("1.0");
  217 +
  218 + $dom->load($paramInfoFilePath);
  219 +
  220 + return $dom->getElementsByTagName("dataset_id")->item(0)->nodeValue;
  221 +
  222 +
  223 + }
  224 +
  225 + /*
  226 + * @brief method to marshall the result of a download request
  227 + */
  228 + protected function marshallResult($data)
  229 + {
  230 + if (!$data->getSuccess())
  231 + return array(
  232 + 'success' => false,
  233 + 'message' => $data->getLastErrorMessage());
  234 +
  235 + switch ($data->getStatus())
  236 + {
  237 + case ProcessStatusEnumClass::ERROR :
  238 + case ProcessStatusEnumClass::RUNNING :
  239 + case ProcessStatusEnumClass::DONE :
  240 + return $this->addToJobsFile($data, WSInputOutputClass::getService());
  241 + default :
  242 + return array(
  243 + 'success' => false,
  244 + 'message' => 'Unknown Process Status');
  245 + }
  246 + }
  247 +}
  248 +?>
... ...
src/InputOutput/WSImpl/Params/PlotImpl/WSInputOutputParamsPlotClass.php 0 โ†’ 100644
... ... @@ -0,0 +1,199 @@
  1 +<?php
  2 +/**
  3 + * @class WSInputOutputParamsPlotClass
  4 + * @brief Implementation of IHMInputOutputParamsAbstractClass to treat plot request
  5 + * @details
  6 +*/
  7 +class WSInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass
  8 +{
  9 + /*
  10 + * @brief Constructor
  11 + */
  12 + function __construct()
  13 + {
  14 + $this->paramManager = new IHMParamManagerClass();
  15 + $this->jobsManager = new WSJobsManagerClass();
  16 + }
  17 +
  18 + /*
  19 + * @brief method to unmarshall a plot request
  20 + */
  21 + protected function unmarshallRequest($input)
  22 + {
  23 + //Request
  24 + $requestIndexInParamData = 0;
  25 + $tabRequestIndex = 1;
  26 +
  27 + $postProcessCmd = "";
  28 +
  29 + $requestNode = $this->paramsData->addRequestNode();
  30 + $requestNode->setRealIndex($tabRequestIndex);
  31 + $outputsNode = $requestNode->getOutputsNode();
  32 + $paramsNode = $requestNode->getParamsNode();
  33 +
  34 + //unmarshall time definition
  35 + $this->unmarshallTimeDefinition($input, $tabRequestIndex-1, $requestIndexInParamData);
  36 +
  37 + $plotOutputNode = $outputsNode->addNewOutput(RequestOutputTypeEnum::PLOT);
  38 + $plotOutputNode->setWriteContextFile("false");
  39 +
  40 + $plotOutputNode->setStructure(RequestOutputPlotStructureEnum::ONE_FILE);
  41 +
  42 + //prefix
  43 +
  44 + $filePrefix = "plot";
  45 +
  46 + $plotOutputNode->setFilePrefix($filePrefix);
  47 +
  48 + //page
  49 + $pageNode = $plotOutputNode->getPage();
  50 +
  51 + switch ($input->{'file-format'})
  52 + {
  53 + case 'PNG' :
  54 + $fileFormat = RequestOutputPlotPageFormatEnum::PNG;
  55 + $extension = ".png";
  56 + break;
  57 + case 'PDF' :
  58 + $fileFormat = RequestOutputPlotPageFormatEnum::PDF;
  59 + $extension = ".pdf";
  60 + break;
  61 + case 'PS' :
  62 + $fileFormat = RequestOutputPlotPageFormatEnum::PS;
  63 + $extension = ".ps";
  64 + break;
  65 + case 'SVG' :
  66 + $fileFormat = RequestOutputPlotPageFormatEnum::SVG;
  67 + $extension = ".svg";
  68 + break;
  69 + default:
  70 + throw new Exception('File format not implemented.');
  71 + }
  72 +
  73 + $pageNode->setFormat($fileFormat);
  74 + $pageNode->setOrientation(RequestOutputPlotPageOrientationEnum::LANDSCAPE);
  75 + $pageNode->setDimension(RequestOutputPlotPageDimensionEnum::ISO_A4);
  76 + $pageNode->setMode(RequestOutputPlotPageModeEnum::COLOR);
  77 +
  78 + // Layout
  79 + $pageNode->getLayout()->setType(RequestOutputPlotLayoutTypeEnum::VERTICAL);
  80 + $pageNode->getLayout()->setPanelHeight("0.5");
  81 + $pageNode->getLayout()->setPanelSpacing("0");
  82 + $pageNode->getLayout()->setExpand("false"); // true ?
  83 + $pageNode->getLayout()->setOnlyLowerTimeAxesLegend("true");
  84 +
  85 + $parametersToPlot = $input->{'parameters'}; // one parameter on panel
  86 +
  87 + $panelN = 1;
  88 + foreach ($parametersToPlot as $param)
  89 + {
  90 + $panelNode = $pageNode->addPanel();
  91 + $panelNode->setId($panelN);
  92 + $panelNode->setIndex($panelN -1);
  93 + $plotNode = $panelNode->addPlotElement(RequestOutputPlotElementTypeEnum::TIMEPLOT);
  94 +
  95 + //Axes
  96 + $timeAxisNode = $plotNode->getTimeAxis();
  97 + $yAxisNode = $plotNode->addYAxis('y-left');
  98 +
  99 + //Params
  100 + $this->unmarshallParams($param, $paramsNode, $plotNode, $panelNode);
  101 + $panelN++;
  102 + }
  103 +
  104 + $resultFile = $filePrefix."_*".$extension;
  105 + $waitingResultFile = $input->{'result-file'}.$extension;
  106 +
  107 + $this->paramsData->addWaitingResult(WSInputOutputClass::getService(), $waitingResultFile);
  108 +
  109 + //Post process command to apply to the result file
  110 + $postProcessCmd .= "mv ".$resultFile." ".WSConfigClass::getWsResultDir().$waitingResultFile;
  111 +
  112 +
  113 + $this->paramsData->setBatchEnable(true);
  114 + $this->paramsData->setPostCmd($postProcessCmd);
  115 +
  116 + return $this->paramsData;
  117 + }
  118 +
  119 +
  120 + protected function unmarshallParams($paramData, $requestParamsNode, $plotNode, $panelNode)
  121 + {
  122 + //Main drawing element parameter
  123 + $paramInfo = $this->paramManager->addExistingParam($paramData->{'paramid'}, $this->paramsData, NULL);
  124 +
  125 + $requestParamsNode->addParam($paramInfo['id']);
  126 + $paramNode = $plotNode->getParams()->getParamById($paramInfo['id']);
  127 +
  128 + $serieNode = $paramNode->addYSerie('y-left', -1);
  129 + $serieNode->setId('1');
  130 +
  131 + $lineNode = $serieNode->getLine();
  132 + $lineNode->setType(RequestOutputPlotLineTypeEnum::LINE);
  133 +
  134 + if ($this->isVector($paramInfo['id'])) { // vector - activate legend
  135 + $paramLegendNode = $plotNode->getLegends()->getParamsLegend();
  136 + $paramLegendNode->setType(RequestOutputPlotParamsLegendTypeEnum::TEXTONLY);
  137 + $paramLegendNode->setShowParamInfo("true");
  138 + $paramLegendNode->setShowIntervalInfo("false");
  139 + $paramLegendNode->setPosition("outside");
  140 + }
  141 + }
  142 +
  143 +
  144 + protected function isVector($paramId)
  145 + {
  146 + $paramPath = IHMConfigClass::getLocalParamDBPath().$paramId.".xml";
  147 +
  148 + $dom = new DomDocument("1.0");
  149 + if (!@$dom->load($paramPath))
  150 + return false;
  151 +
  152 + // TODO use tensor_order
  153 + $components = $dom->getElementsByTagName("components")->item(0)->nodeValue;
  154 + $arr = explode(",",$components);
  155 +
  156 + return (count($arr) == 3);
  157 + }
  158 +
  159 + /*
  160 + * @brief Add a job to the job manager
  161 + */
  162 + protected function addToJobsFile($data,$resultKey)
  163 + {
  164 + $waitingResult = $data->getWaitingResult($resultKey);
  165 +
  166 + return $this->jobsManager->addJob(
  167 + $this->input,
  168 + $data->getId(),
  169 + $this->getWorkingDirName(),
  170 + $data->getStatus() == ProcessStatusEnumClass::RUNNING,
  171 + $data->getStart(),
  172 + $waitingResult,
  173 + $data->getErrorCode());
  174 + }
  175 +
  176 + /*
  177 + * @brief method to marshall the result of a download request
  178 + */
  179 + protected function marshallResult($data)
  180 + {
  181 + if (!$data->getSuccess())
  182 + return array(
  183 + 'success' => false,
  184 + 'message' => $data->getLastErrorMessage());
  185 +
  186 + switch ($data->getStatus())
  187 + {
  188 + case ProcessStatusEnumClass::ERROR :
  189 + case ProcessStatusEnumClass::RUNNING :
  190 + case ProcessStatusEnumClass::DONE :
  191 + return $this->addToJobsFile($data, WSInputOutputClass::getService());
  192 + default :
  193 + return array(
  194 + 'success' => false,
  195 + 'message' => 'Unknown Process Status');
  196 + }
  197 + }
  198 +}
  199 +?>
... ...
src/InputOutput/WSImpl/Process/WSInputOutputDeleteProcessClass.php 0 โ†’ 100644
... ... @@ -0,0 +1,66 @@
  1 +<?php
  2 +
  3 +/**
  4 + * @class WSInputOutputDeleteProcessClass
  5 + * @brief Class that's implement an InputOutputInterface used to treat a delete process request
  6 + * @details
  7 + */
  8 +class WSInputOutputDeleteProcessClass extends IHMInputOutputDeleteProcessClass implements InputOutputInterface
  9 +{
  10 + protected $jobsManager = null;
  11 + // private $paramsData = null;
  12 +
  13 + /*
  14 + * @brief Constructor
  15 + */
  16 + function __construct()
  17 + {
  18 + $this->jobsManager = new WSJobsManagerClass();
  19 + }
  20 +
  21 + /*
  22 + * @brief translate input data from WS client to AMDA_Integration module for a delete process request
  23 + */
  24 +// public function getInputData($input,$function,$requestId="")
  25 +// {
  26 +// if (isset($this->paramsData))
  27 +// unset($this->paramsData);
  28 +//
  29 +// $this->paramsData = new ProcessRequestDataClass();
  30 +//
  31 +// $this->paramsData->setManagerFilePath(IHMConfigClass::getProcessManagerFilePath());
  32 +// $this->paramsData->setType(ProcessTypeEnumClass::DELETE);
  33 +//
  34 +// $this->paramsData->setId($input->id);
  35 +//
  36 +// return $this->paramsData;
  37 +// }
  38 +
  39 + /*
  40 + * @brief translate output data from AMDA_Integration module to IHM client for a delete process request
  41 + */
  42 +// public function getOutput($data)
  43 +// {
  44 +// if (!$data->getSuccess())
  45 +// {
  46 +// return array(
  47 +// 'success' => false,
  48 +// 'message' => $data->getLastErrorMessage());
  49 +// }
  50 +//
  51 +// $res = $this->jobsManager->deleteJob($this->paramsData->getId());
  52 +//
  53 +// /*if (!$res['success'])
  54 +// {
  55 +// return array(
  56 +// 'success' => false,
  57 +// 'message' => $res['message']);
  58 +// }*/
  59 +//
  60 +// return array(
  61 +// 'success' => true,
  62 +// 'id' => $this->paramsData->getId());
  63 +// }
  64 +}
  65 +
  66 +?>
0 67 \ No newline at end of file
... ...
src/InputOutput/WSImpl/Process/WSInputOutputGetInfoProcessClass.php 0 โ†’ 100644
... ... @@ -0,0 +1,43 @@
  1 +<?php
  2 +
  3 +/**
  4 + * @class WSInputOutputGetInfoProcessClass
  5 + * @brief Class that's implement an InputOutputInterface used to treat a get info process request
  6 + * @details
  7 + */
  8 +class WSInputOutputGetInfoProcessClass extends IHMInputOutputGetInfoProcessClass
  9 +{
  10 + protected $jobsManager = null;
  11 +
  12 + /*
  13 + * @brief Constructor
  14 + */
  15 + function __construct()
  16 + {
  17 + $this->jobsManager = new WSJobsManagerClass();
  18 + }
  19 +
  20 + public function getOutput($data)
  21 + {
  22 + if (!$data->getSuccess())
  23 + {
  24 + return array(
  25 + 'success' => false,
  26 + 'message' => $data->getLastErrorMessage());
  27 + }
  28 +
  29 + $jobInfo = $this->jobsManager->updateJobStatus(
  30 + $data->getId(),
  31 + $data->getStatus() == ProcessStatusEnumClass::RUNNING,
  32 + $data->getErrorCode());
  33 +
  34 + if (!$jobInfo['success'])
  35 + {
  36 + return array(
  37 + 'success' => false,
  38 + 'message' => $data->getLastErrorMessage());
  39 + }
  40 + return $jobInfo;
  41 + }
  42 +}
  43 +?>
... ...
src/InputOutput/WSImpl/TimeTables/WSInputOutputTTClass.php 0 โ†’ 100644
... ... @@ -0,0 +1,89 @@
  1 +<?php
  2 +
  3 +/**
  4 + * @class WSInputOutputTTClass
  5 + * @brief
  6 + * @details
  7 +*/
  8 +//TODO not finished and not used for the moment
  9 +class WSInputOutputTTClass extends IHMInputOutputTTClass
  10 +{
  11 +
  12 +/*
  13 + * @brief Constructor
  14 +*/
  15 + function __construct()
  16 + {
  17 +
  18 + }
  19 +
  20 +/*
  21 + * @brief translate input data from IHM client to AMDA_Integration module for a tt process request
  22 +*/
  23 + public function getInputData($input, $function, $requestId="")
  24 + {
  25 + if (isset($this->processDatas))
  26 + unset($this->processDatas);
  27 +
  28 + $final = "";
  29 +// if (is_dir(IHMConfigClass::getDownloadTmpPath())) {
  30 +// foreach (glob(IHMConfigClass::getDownloadTmpPath().'*.zip') as $filename) unlink($filename);
  31 +// foreach (glob(IHMConfigClass::getDownloadTmpPath().'*.tar.gz') as $filename) unlink($filename);
  32 +// }
  33 +
  34 + foreach($input->list as $ttId)
  35 + {
  36 + //create a list of data to treat
  37 + $processData = new TTRequestDataClass();
  38 + if (strpos($id,"sharedtimeTable_") === 0) {
  39 + //Shared TimeTable
  40 + $result = IHMSharedObjectsClass::getPath("timeTable", $ttId);
  41 + if (!$result['success'])
  42 + throw new Exception('Shared TimeTable '.$ttId.' not found');
  43 + $ttName = $result['path'];
  44 + }
  45 + else {
  46 + //User TimeTable
  47 + $ttName = IHMConfigClass::getUserTTPath().$ttId.'.xml';
  48 + }
  49 + if (!file_exists($ttName))
  50 + throw new Exception('TimeTable '.$ttId.' not found');
  51 +
  52 + $processData->setInputFileName($ttName);
  53 + $processData->setInputFileFormat(TTRequestFileFormatEnum::INTERNAL);
  54 + $processData->setOutputDir(WSConfigClass::getWSResultDir());
  55 +
  56 + $processData->setOutputFileFormat(TTRequestFileFormatEnum::VOTABLE);
  57 + $outputName = $ttId.'.xml';
  58 +
  59 + $processData->setOutputFileName($outputName);
  60 +
  61 + $processData->setType($function);
  62 + $processData->setCmd("ttConversion");
  63 +
  64 + $this->processDatas[] = $processData;
  65 + }
  66 +
  67 + $this->postProcessTT = new PostProcessTTClass();
  68 + $this->postProcessTT->setOutputDirAlias($this->processDatas[0]->getOutputDir());
  69 +
  70 + $this->postProcessTT->setOutputFileName($outputFileName);
  71 + $this->postProcessTT->setOutputDir($this->processDatas[0]->getOutputDir());
  72 +
  73 + return $this->processDatas;
  74 + }
  75 +
  76 +/*
  77 + * @brief translate output data from AMDA_Integration module to IHM client request
  78 +*/
  79 + public function getOutput($data)
  80 + {
  81 +
  82 + $result = array('success'=>$data[0]->getSuccess(),
  83 + 'download' => $this->postProcessTT->getOutputDirAlias().$data[0]->getOutputFileName());
  84 +
  85 + return $result;
  86 + }
  87 +}
  88 +
  89 +?>
... ...
src/InputOutput/WSImpl/Tools/WSJobsManagerClass.php 0 โ†’ 100644
... ... @@ -0,0 +1,291 @@
  1 +<?php
  2 +/**
  3 + * @class WSJobsManagerClass
  4 + * @brief Jobs manager
  5 + * @details
  6 + */
  7 +class WSJobsManagerClass extends IHMJobsManagerClass {
  8 +
  9 + protected $jobXml, $jobXmlName;
  10 +
  11 + protected $bkgRootNode = array(WSConfigClass::PLOT => 'bkgPlotRootNode',
  12 + WSConfigClass::PARAMETER => 'bkgParamRootNode',
  13 + WSConfigClass::ORBIT => 'bkgOrbRootNode',
  14 + WSConfigClass::DATASET => 'bkgDatasetRootNode');
  15 +
  16 + protected $resRootNode = array(WSConfigClass::PLOT => 'resPlotRootNode',
  17 + WSConfigClass::PARAMETER => 'resParamRootNode',
  18 + WSConfigClass::ORBIT => 'resOrbRootNode',
  19 + WSConfigClass::DATASET => 'bkgDatasetRootNode');
  20 +
  21 + /*
  22 + * @brief Constructor
  23 + */
  24 + function __construct()
  25 + {
  26 + }
  27 +
  28 + /*
  29 + * @brief Load jobs file and create it if needed
  30 + */
  31 + protected function init()
  32 + {
  33 + $this->jobXmlName = WSConfigClass::getWsJobsFile();
  34 + $this->jobXml = new DomDocument("1.0");
  35 +
  36 + if (!file_exists($this->jobXmlName))
  37 + {
  38 + $res = $this->createJobsFile();
  39 + if (!$res['success'])
  40 + return $res;
  41 + }
  42 +
  43 + $res = $this->jobXml->load($this->jobXmlName);
  44 + if (!$res)
  45 + return array(
  46 + "success" => false,
  47 + "message" => "Cannot load jobs file");
  48 +
  49 + return array("success" => true);
  50 + }
  51 +
  52 + /*
  53 + * @brief get job info about a job
  54 + */
  55 + public function getJobInfo($id)
  56 + {
  57 + $res = $this->init();
  58 + if (!$res['success'])
  59 + return $res;
  60 +
  61 + $job = $this->jobXml->getElementById($id);
  62 + $format = 'unknown';
  63 + $compression = 'unknown';
  64 + if($job)
  65 + {
  66 + // $name = $job->getAttribute('name');
  67 + $status = $job->getAttribute('status');
  68 + $jobType = $job->getAttribute('jobType');
  69 + // $info = $job->getAttribute('info');
  70 + $start = $job->getAttribute('start');
  71 + $stop = $job->getAttribute('stop');
  72 + $result = $job->getAttribute('result');
  73 + $folder = $job->getAttribute('folder');
  74 + $request_obj = $this->getRequestObjectFile($id);
  75 + if (isset($request_obj))
  76 + {
  77 + if (isset($request_obj->fileformat))
  78 + {
  79 + $format = strtolower($request_obj->format);
  80 + if (($format == "pdf") || ($format == "ps"))
  81 + //auto compression for plot request
  82 + $compression = ".tar.gz";
  83 +
  84 + // if ($format == "ascii") $format = 'txt';
  85 + }
  86 + if (isset($request_obj->compression))
  87 + $compression = strtolower($request_obj->compression);
  88 + }
  89 + }
  90 + return array(
  91 + 'success' => true,
  92 + 'id' => $id,
  93 + // 'name' => $name,
  94 + 'status' => $status,
  95 + 'jobType' => $jobType,
  96 + // 'info' => $info,
  97 + 'start' => $start,
  98 + 'stop' => $stop,
  99 + 'folder' => $folder,
  100 + 'result' => $result,
  101 + 'format' => $format,
  102 + 'compression' => $compression
  103 + );
  104 + }
  105 +
  106 + /*
  107 + * @brief Add a new job
  108 + */
  109 + public function addJob($obj, $id, $folder,
  110 + $running, $start, $result, $exitcode)
  111 + {
  112 + $res = $this->init();
  113 +
  114 + if (!$res['success'])
  115 + return $res;
  116 +
  117 + $key = WSInputOutputClass::getService();
  118 +
  119 + $newJob = $this->jobXml->createElement('job');
  120 +
  121 + $newJob->setAttribute('xml:id', $id);
  122 + $newJob->setAttribute('jobType', $key);
  123 +
  124 +// switch ($key)
  125 +// {
  126 +// case 'parameter' :
  127 +// $name = "download_".time();
  128 +// $info = '';
  129 +// foreach ($obj->list as $param)
  130 +// {
  131 +// $info .= ' '.$param->paramid; //data
  132 +// }
  133 +// break;
  134 +// case 'plot' :
  135 +// $name = "request_".time();
  136 +// $info = '';
  137 +// for ($i=0; $i < count($obj->children); $i++) {
  138 +// for ($j=0; $j < count($obj->children[$i]->children); $j++) {
  139 +// $info = $info.' '.$obj->children[$i]->children[$j]->paramid;
  140 +// }
  141 +// }
  142 +// break;
  143 +// default:
  144 +// $name = "unknown_".time();
  145 +// $info = '';
  146 +// }
  147 +
  148 +// $newJob->setAttribute('name', $name);
  149 +// $newJob->setAttribute('info', $info);
  150 + $newJob->setAttribute('result', $result);
  151 + $newJob->setAttribute('folder', $folder);
  152 + $newJob->setAttribute('start', date('d-m-Y H:i:s', $start));
  153 + $newJob->setAttribute('user', IHMConfigClass::getUserName());
  154 + $newJob->setAttribute('host', IHMConfigClass::getUserHost());
  155 + //to know if know if it's an immediate job or not
  156 +// $newJob->setAttribute('immediate', !$running);
  157 +
  158 + if ($running)
  159 + {
  160 + $rootJobNode = $this->jobXml->getElementById($this->bkgRootNode[$key]);
  161 + if (!$rootJobNode)
  162 + {
  163 + $rootJobNode = $this->jobXml->createElement("$key");
  164 + $rootJobNode->setAttribute('xml:id', $this->bkgRootNode[$key]);
  165 + $jobsInProgress = $this->jobXml->getElementsByTagName('jobsInProgress')->item(0);
  166 + $jobsInProgress->appendChild($rootJobNode);
  167 + }
  168 + }
  169 + else
  170 + {
  171 + $rootJobNode = $this->jobXml->getElementById($this->resRootNode[$key]);
  172 + if (!$rootJobNode)
  173 + {
  174 + $rootJobNode = $this->jobXml->createElement("$key");
  175 + $rootJobNode->setAttribute('xml:id', $this->resRootNode[$key]);
  176 + $jobsFinished = $this->jobXml->getElementsByTagName('jobsFinished')->item(0);
  177 + $jobsFinished->appendChild($rootJobNode);
  178 + }
  179 + }
  180 +
  181 + $rootJobNode->appendChild($newJob);
  182 +
  183 + if (!$this->jobXml->save($this->jobXmlName))
  184 + return array("success" => false, "message" => "Cannot save job manager file");
  185 +
  186 + $this->saveRequestObjectFile($obj, $id);
  187 +
  188 + return $this->updateJobStatus($id, $running, $exitcode);
  189 + }
  190 +
  191 + /*
  192 + * @brief Update the status of a job
  193 + */
  194 +// public function updateJobStatus($id, $running, $exitcode)
  195 +// {
  196 +// $res = $this->init();
  197 +// if (!$res['success'])
  198 +// return $res;
  199 +//
  200 +// $job = $this->jobXml->getElementById($id);
  201 +//
  202 +// if (!isset($job))
  203 +// return array("success" => false, "message" => "Cannot found job");
  204 +//
  205 +// $jobstatus = $this->getJobStatus($running,$exitcode);
  206 +// $job->setAttribute('status', $jobstatus);
  207 +//
  208 +// if ($running)
  209 +// $job->setAttribute('stop', 'unknown');
  210 +// else if ($job->getAttribute('stop') == '' || $job->getAttribute('stop') == 'unknown')
  211 +// {
  212 +// $job->setAttribute('stop', date('d-m-Y H:i:s', time()));
  213 +// $this->jobXml->getElementById($this->resRootNode[$job->getAttribute('jobType')])->appendChild($job);
  214 +// }
  215 +//
  216 +// $res = $this->jobXml->save($this->jobXmlName);
  217 +//
  218 +// if (!$res)
  219 +// return array(
  220 +// 'success' => false,
  221 +// 'message' => "Cannot save jobs status file");
  222 +//
  223 +// return $this->getJobInfo($id);
  224 +// }
  225 +
  226 + /*
  227 + * @brief delete a job
  228 + */
  229 + public function deleteJob($id)
  230 + {
  231 + $res = $this->init();
  232 + if (!$res['success'])
  233 + return $res;
  234 +
  235 + $job = $this->jobXml->getElementById($id);
  236 +
  237 + //delete job
  238 + if (!$job)
  239 + return array('success' => false, 'message' => "Job not reachable");
  240 +
  241 + $folder = $job->getAttribute('folder');
  242 +
  243 + //be sure that it's an AMDA working dir before deletion...
  244 + $fullFolderPath = IHMConfigClass::getRequestPath().$folder.'/';
  245 +
  246 + if ((isset($folder)) &&
  247 + ($folder != "") &&
  248 + is_dir($fullFolderPath) &&
  249 + (preg_match("/DD[0-9A-Za-z]*_/",$folder) ||
  250 + preg_match("/Plot[0-9]*_/",$folder)))
  251 + {
  252 + foreach (glob($fullFolderPath.'*') as $filename)
  253 + {
  254 + if (is_dir($filename) && (basename($filename) == 'params'))
  255 + {
  256 + //recursive deletion only for "params" dir (a full recursive deletion is probably too dangerous...)
  257 + foreach (glob($filename.'/*') as $paramname)
  258 + unlink($paramname);
  259 + rmdir($filename);
  260 + }
  261 + else
  262 + unlink($filename);
  263 + }
  264 + rmdir($fullFolderPath);
  265 + }
  266 +
  267 + $this->deleteRequestObjectFile($id);
  268 +
  269 +// $job->parentNode->removeChild($job);
  270 +// $res = $this->jobXml->save($this->jobXmlName);
  271 +
  272 + if (!$res)
  273 + return array(
  274 + 'success' => false,
  275 + 'message' => "Cannot save jobs file");
  276 +
  277 + return array('success' => true, 'id' => $id);
  278 + }
  279 +
  280 + public function getResultFromProcessId($id)
  281 + {
  282 + $res = $this->init();
  283 + $job = $this->jobXml->getElementById($id);
  284 +
  285 + if (!$job)
  286 + return array('success' => false, 'message' => "Job not reachable");
  287 +
  288 + return array('success' => true, 'result' => $job->getAttribute('result'));
  289 + }
  290 +}
  291 +?>
... ...
src/InputOutput/WSImpl/WSInputOutputClass.php 0 โ†’ 100644
... ... @@ -0,0 +1,72 @@
  1 +<?php
  2 +
  3 +/**
  4 + * @class WSInputOutputClass
  5 + * @brief Class that's implement an InputOutputInterface for WebServices client. This class inherits from IHMInputOutputClass.
  6 + * @details
  7 + */
  8 +class WSInputOutputClass extends IHMInputOutputClass
  9 +{
  10 + /*
  11 + * @brief translate input data from WebServices request to AMDA_Integration module
  12 + */
  13 + public static $service;
  14 +
  15 + public static function setService($service)
  16 + {
  17 + self::$service = $service;
  18 + }
  19 +
  20 + public static function getService()
  21 + {
  22 + return self::$service;
  23 + }
  24 +
  25 + public function getInputData($input,$function,$requestId = "")
  26 + {
  27 + switch ($function)
  28 + {
  29 + case FunctionTypeEnumClass::PARAMS :
  30 + switch (self::$service)
  31 + {
  32 + case WSConfigClass::PARAMETER :
  33 + case WSConfigClass::DATASET :
  34 + case WSConfigClass::ORBIT :
  35 + $this->inputOutput = new WSInputOutputParamsDownloadClass();
  36 + break;
  37 + case WSConfigClass::PLOT :
  38 + $this->inputOutput = new WSInputOutputParamsPlotClass();
  39 + break;
  40 + default :
  41 + throw new Exception('Service'.self::$service.' not implemented yet');
  42 + }
  43 + break;
  44 + case FunctionTypeEnumClass::PROCESSDELETE :
  45 + $this->inputOutput = new WSInputOutputDeleteProcessClass();
  46 + break;
  47 + case FunctionTypeEnumClass::PROCESSRUNNINGINFO :
  48 + $this->inputOutput = new IHMInputOutputRunningInfoProcessClass();
  49 + break;
  50 + case FunctionTypeEnumClass::PROCESSGETINFO :
  51 + $this->inputOutput = new WSInputOutputGetInfoProcessClass();
  52 + break;
  53 + case FunctionTypeEnumClass::PROCESSCLEAN :
  54 + $this->inputOutput = new IHMInputOutputCleanProcessClass();
  55 + break;
  56 + case FunctionTypeEnumClass::PROCESSGETREQUEST :
  57 + $this->inputOutput = new IHMInputOutputGetProcessRequestClass();
  58 + break;
  59 + //TODO actually this is done by WebServer xslt transformation
  60 + case FunctionTypeEnumClass::TTCONVERT :
  61 + $this->inputOutput = new WSInputOutputTTClass();
  62 + break;
  63 + default :
  64 + throw new Exception('Request type '.$function.' not implemented for this client.');
  65 + }
  66 +
  67 + return $this->inputOutput->getInputData($input,$function,$requestId);
  68 + }
  69 +
  70 +}
  71 +
  72 +?>
0 73 \ No newline at end of file
... ...
src/Request/ProcessRequestImpl/Process/ProcessManagerClass.php
... ... @@ -261,6 +261,8 @@ class ProcessManagerClass
261 261 return array('success' => false, 'message' => 'Error to retrieve process info');
262 262  
263 263 $this->updateProcessInProcessNode($dom, $processNode, $process);
  264 +
  265 + $dom->save($this->processManagerFilePath);
264 266 }
265 267  
266 268 $processInfo = $this->getProcessInfoFromNode($processNode);
... ...
src/RequestManagerClass.php
... ... @@ -15,6 +15,20 @@ Class RequestManagerClass
15 15 {
16 16  
17 17 }
  18 +
  19 +/*
  20 + * @brief Treat a request that's come from the WebServices
  21 +*/
  22 + public function runWSRequest($user, $userHost, $function, $service = "", $input)
  23 + {
  24 + if (isset($service))
  25 + WSInputOutputClass::setService($service);
  26 + //TODO time table conversions can be made by AMDA_Kernel
  27 + if ($function == FunctionTypeEnumClass::PARAMS ) // || $function == FunctionTypeEnumClass::TTCONVERT)
  28 + KernelConfigClass::setTimeToBatchMode(WSConfigClass::$timeToBatchMode);
  29 +
  30 + return $this->runGenericRequest(ClientTypeEnumClass::WS, $user, $userHost, $function, $input);
  31 + }
18 32  
19 33 /*
20 34 * @brief Treat a request that's come from the IHM
... ... @@ -70,8 +84,10 @@ Class RequestManagerClass
70 84 {
71 85 case ClientTypeEnumClass::IHM :
72 86 return new IHMInputOutputClass($user, $userHost);
  87 + case ClientTypeEnumClass::WS :
  88 + return new WSInputOutputClass($user, $userHost);
73 89 case ClientTypeEnumClass::TEST :
74   - return new TestInputOutputClass($user);
  90 + return new TestInputOutputClass($user);
75 91 default :
76 92 throw new Exception('Client '.$client.' not implemented.');
77 93 }
... ... @@ -90,7 +106,7 @@ Class RequestManagerClass
90 106  
91 107 //create an instance of the RequestClass to run the request
92 108 $request = $this->createRequest($user, $userHost, $function);
93   -
  109 +
94 110 if (is_array($inputdata))
95 111 {
96 112 $outputdata = array();
... ... @@ -100,7 +116,7 @@ Class RequestManagerClass
100 116 }
101 117 else
102 118 $outputdata = $this->runSingleRequest($request,$inputdata);
103   -
  119 +
104 120 //get the request output data from the output data by using the InputOutput interface
105 121 return $inputOutput->getOutput($outputdata);
106 122 }
... ... @@ -112,7 +128,7 @@ Class RequestManagerClass
112 128 {
113 129 //link the request to the input data
114 130 $request->setData($data);
115   -
  131 +
116 132 //init the request
117 133 if (!$request->init())
118 134 {
... ...
src/amdaintegration_autoload.php
... ... @@ -17,6 +17,13 @@ function amdaintegration_autoload($class_name)
17 17 'InputOutput/IHMImpl/Tools',
18 18 'InputOutput/IHMImpl/TimeTables',
19 19 'InputOutput/TestImpl',
  20 + 'InputOutput/WSImpl',
  21 + 'InputOutput/WSImpl/Config',
  22 + 'InputOutput/WSImpl/Process',
  23 + 'InputOutput/WSImpl/Params/DownloadImpl',
  24 + 'InputOutput/WSImpl/Params/PlotImpl',
  25 + 'InputOutput/WSImpl/Tools',
  26 + 'InputOutput/WSImpl/TimeTables',
20 27 'Request',
21 28 'Request/Config',
22 29 'Request/ParamsRequestImpl',
... ... @@ -31,7 +38,9 @@ function amdaintegration_autoload($class_name)
31 38  
32 39 $ihm_dirs = array(
33 40 IHM_SRC_DIR.'/php/classes',
34   - IHM_SRC_DIR.'/php/RemoteDataCenter'
  41 + IHM_SRC_DIR.'/php/RemoteDataCenter',
  42 + IHM_SRC_DIR.'/php/WebServices',
  43 + IHM_SRC_DIR.'/php/WebServices/Client'
35 44 );
36 45  
37 46 $find = false;
... ...