Commit 9b69cb352b7e273adf20c608e5fee40b02f229fd
1 parent
e5ab198f
Exists in
master
and in
110 other branches
Implement batch mode for getParameter REST api
Showing
6 changed files
with
102 additions
and
64 deletions
Show diff stats
php/classes/AmdaAction.php
@@ -844,7 +844,7 @@ class AmdaAction | @@ -844,7 +844,7 @@ class AmdaAction | ||
844 | /* | 844 | /* |
845 | * Get Jobs en cours | 845 | * Get Jobs en cours |
846 | */ | 846 | */ |
847 | - public function getJobs($obj) | 847 | + public function getJobs($obj = null) |
848 | { | 848 | { |
849 | require_once(INTEGRATION_SRC_DIR."RequestManager.php"); | 849 | require_once(INTEGRATION_SRC_DIR."RequestManager.php"); |
850 | return $this->executeRequest($obj, FunctionTypeEnumClass::PROCESSRUNNINGINFO); | 850 | return $this->executeRequest($obj, FunctionTypeEnumClass::PROCESSRUNNINGINFO); |
@@ -909,8 +909,7 @@ class AmdaAction | @@ -909,8 +909,7 @@ class AmdaAction | ||
909 | try | 909 | try |
910 | { | 910 | { |
911 | $res = $requestManager->runIHMRequest($this->user, $res['userHost'], $function, $obj); | 911 | $res = $requestManager->runIHMRequest($this->user, $res['userHost'], $function, $obj); |
912 | - } catch (Exception $e) | ||
913 | - { | 912 | + } catch (Exception $e) { |
914 | return array('success' => false, 'message' => 'Exception detected : '.$e->getMessage()); | 913 | return array('success' => false, 'message' => 'Exception detected : '.$e->getMessage()); |
915 | } | 914 | } |
916 | return $res; | 915 | return $res; |
php/classes/RequestMgr.php
@@ -247,7 +247,8 @@ class RequestMgr extends AmdaObjectMgr | @@ -247,7 +247,8 @@ class RequestMgr extends AmdaObjectMgr | ||
247 | if ($obj->timesrc != 'Interval') break; | 247 | if ($obj->timesrc != 'Interval') break; |
248 | 248 | ||
249 | foreach ($obj->list as $param) | 249 | foreach ($obj->list as $param) |
250 | - { | 250 | + { |
251 | + | ||
251 | //TODO not in code spase___IMPEX_ !!! | 252 | //TODO not in code spase___IMPEX_ !!! |
252 | //TODO other models (tsyganenko etc) | 253 | //TODO other models (tsyganenko etc) |
253 | if (preg_match("#^spase___IMPEX_#", $param->paramid)) | 254 | if (preg_match("#^spase___IMPEX_#", $param->paramid)) |
@@ -255,14 +256,15 @@ class RequestMgr extends AmdaObjectMgr | @@ -255,14 +256,15 @@ class RequestMgr extends AmdaObjectMgr | ||
255 | if ($param->template_args->url_XYZ) $params[] = $param->template_args->url_XYZ; | 256 | if ($param->template_args->url_XYZ) $params[] = $param->template_args->url_XYZ; |
256 | } | 257 | } |
257 | } | 258 | } |
258 | - if (count($params) > 0) | 259 | + if (isset($params) && count($params) > 0) |
259 | { | 260 | { |
261 | + // tab is not defined, iterate over $obj->tabs? | ||
260 | $argsTab['param'] = array_unique($params); | 262 | $argsTab['param'] = array_unique($params); |
261 | $argsTab['startTime'] = $tab->{'multi-plot-linked'} ? $obj->startDate : $tab->startDate; | 263 | $argsTab['startTime'] = $tab->{'multi-plot-linked'} ? $obj->startDate : $tab->startDate; |
262 | $argsTab['stopTime'] = $tab->{'multi-plot-linked'} ? $obj->startDate : $tab->stopDate; | 264 | $argsTab['stopTime'] = $tab->{'multi-plot-linked'} ? $obj->startDate : $tab->stopDate; |
263 | } | 265 | } |
264 | if (count($argsTab) > 0) $args[] = $argsTab; | 266 | if (count($argsTab) > 0) $args[] = $argsTab; |
265 | - | 267 | + |
266 | break; | 268 | break; |
267 | case 'statistics' : | 269 | case 'statistics' : |
268 | return array('success' => true); | 270 | return array('success' => true); |
@@ -270,23 +272,23 @@ class RequestMgr extends AmdaObjectMgr | @@ -270,23 +272,23 @@ class RequestMgr extends AmdaObjectMgr | ||
270 | default : | 272 | default : |
271 | return array('success' => false, 'message' => "unknown action ".$obj->nodeType); | 273 | return array('success' => false, 'message' => "unknown action ".$obj->nodeType); |
272 | } | 274 | } |
273 | - | ||
274 | - if (count($args) === 0) return array('success' => true); | ||
275 | - | 275 | + |
276 | + if (count($args) === 0) return array('success' => true); | ||
277 | + | ||
276 | try | 278 | try |
277 | { | 279 | { |
278 | $client = new SoapClient(DD_WSDL); | 280 | $client = new SoapClient(DD_WSDL); |
279 | } | 281 | } |
280 | catch (SoapFault $exception) | 282 | catch (SoapFault $exception) |
281 | - { | 283 | + { |
282 | return array('success' => false, 'message' => $exception->faultstring); | 284 | return array('success' => false, 'message' => $exception->faultstring); |
283 | } | 285 | } |
284 | - | 286 | + |
285 | $orbitsXml = new DomDocument("1.0"); | 287 | $orbitsXml = new DomDocument("1.0"); |
286 | $orbitsXml->load(orbitsAllXml); | 288 | $orbitsXml->load(orbitsAllXml); |
287 | $tr = array('_' => ':'); | 289 | $tr = array('_' => ':'); |
288 | - | ||
289 | - foreach ($args as $tab) | 290 | + |
291 | + foreach ($args as $tab) | ||
290 | { | 292 | { |
291 | $startTime = $tab['startTime']; | 293 | $startTime = $tab['startTime']; |
292 | $stopTime = $tab['stopTime']; | 294 | $stopTime = $tab['stopTime']; |
@@ -315,8 +317,8 @@ class RequestMgr extends AmdaObjectMgr | @@ -315,8 +317,8 @@ class RequestMgr extends AmdaObjectMgr | ||
315 | return array('success' => false, 'message' => "Too big interval for IMPEX request : ".IMPEX_INTERVAL_LIMIT/86400.." day limit!"); | 317 | return array('success' => false, 'message' => "Too big interval for IMPEX request : ".IMPEX_INTERVAL_LIMIT/86400.." day limit!"); |
316 | } | 318 | } |
317 | } | 319 | } |
318 | - | ||
319 | - return array('success' => true); | 320 | + |
321 | + return array('success' => true); | ||
320 | } | 322 | } |
321 | } | 323 | } |
322 | ?> | 324 | ?> |
php/classes/UserMgr.php
@@ -491,13 +491,8 @@ class UserMgr | @@ -491,13 +491,8 @@ class UserMgr | ||
491 | 491 | ||
492 | public function ddCheckUser() | 492 | public function ddCheckUser() |
493 | { | 493 | { |
494 | - error_log("Checking user..."); | ||
495 | $this->IP = $this->getIPclient(); | 494 | $this->IP = $this->getIPclient(); |
496 | - error_log("User: " . $this->user); | ||
497 | - error_log("IP: " . $this->IP); | ||
498 | - | ||
499 | $cmdCheckUser = DDBIN."DDCheckUser ".$this->IP." ".$this->user." 1> /dev/null 2> /dev/null"; | 495 | $cmdCheckUser = DDBIN."DDCheckUser ".$this->IP." ".$this->user." 1> /dev/null 2> /dev/null"; |
500 | - error_log("cmdCheckUser: " . $cmdCheckUser); | ||
501 | system($cmdCheckUser, $res); | 496 | system($cmdCheckUser, $res); |
502 | return $res; | 497 | return $res; |
503 | } | 498 | } |
@@ -612,6 +607,7 @@ class UserMgr | @@ -612,6 +607,7 @@ class UserMgr | ||
612 | public function dirSize($dir) | 607 | public function dirSize($dir) |
613 | { | 608 | { |
614 | $handle = opendir($dir); | 609 | $handle = opendir($dir); |
610 | + $mas = 1024 * 1024 * 200; // fixme | ||
615 | 611 | ||
616 | while ($file = readdir($handle)) | 612 | while ($file = readdir($handle)) |
617 | { | 613 | { |
php/classes/WebServer.php
@@ -113,7 +113,7 @@ class WebServer | @@ -113,7 +113,7 @@ class WebServer | ||
113 | else | 113 | else |
114 | $this->userPWD = 'impexfp7'; | 114 | $this->userPWD = 'impexfp7'; |
115 | 115 | ||
116 | - | 116 | +// |
117 | 117 | ||
118 | return array('success' => true, 'vars' => $vars); | 118 | return array('success' => true, 'vars' => $vars); |
119 | } | 119 | } |
@@ -503,7 +503,37 @@ class WebServer | @@ -503,7 +503,37 @@ class WebServer | ||
503 | ); | 503 | ); |
504 | 504 | ||
505 | $aa = new AmdaAction(); | 505 | $aa = new AmdaAction(); |
506 | - return $aa->getJobs($obj); | 506 | + $jobs = $aa->getJobs($obj); |
507 | + | ||
508 | +// job = | ||
509 | +// { | ||
510 | +// "success":true, | ||
511 | +// "id":"process_aiaoh7_1517403874_1372", | ||
512 | +// "name":"download_data_1517403886", | ||
513 | +// "status":"in_progress", | ||
514 | +// "jobType":"download", | ||
515 | +// "info":" ", | ||
516 | +// "start":"31-01-2018 13:04:34", | ||
517 | +// "stop":"unknown", | ||
518 | +// "folder":"DDpTDRrk_", | ||
519 | +// "result":"result_pTDRrk", | ||
520 | +// "format":"unknown", | ||
521 | +// "compression":"", | ||
522 | +// "sendToSamp":false | ||
523 | +// } | ||
524 | + | ||
525 | + foreach ($jobs['jobsInProgress'] as $job) { | ||
526 | + if ($job['id'] == $data['id']) { | ||
527 | + return ['success' => true, 'status' => 'in_progress']; | ||
528 | + } | ||
529 | + } | ||
530 | + foreach ($jobs['jobsFinished'] as $job) { | ||
531 | + if ($job['id'] == $data['id']) { | ||
532 | + return $this->finishDownloadRequest($job); | ||
533 | + } | ||
534 | + } | ||
535 | + | ||
536 | + return ['success' => false, 'message' => 'No job found for this id.']; | ||
507 | } | 537 | } |
508 | 538 | ||
509 | public function getParameterList($data) | 539 | public function getParameterList($data) |
@@ -576,7 +606,6 @@ class WebServer | @@ -576,7 +606,6 @@ class WebServer | ||
576 | ///////////////////////////////////////START GET DATASET /////////////////////////////// | 606 | ///////////////////////////////////////START GET DATASET /////////////////////////////// |
577 | public function getParameter($data) | 607 | public function getParameter($data) |
578 | { | 608 | { |
579 | - | ||
580 | $multiParam = false; | 609 | $multiParam = false; |
581 | 610 | ||
582 | $res = $this->init($data); | 611 | $res = $this->init($data); |
@@ -940,6 +969,7 @@ class WebServer | @@ -940,6 +969,7 @@ class WebServer | ||
940 | "fileformat" => $fileformat, | 969 | "fileformat" => $fileformat, |
941 | "timeformat" => $timeformat, | 970 | "timeformat" => $timeformat, |
942 | "compression" => $compression, | 971 | "compression" => $compression, |
972 | + "extension" => $wsExtension, | ||
943 | "disablebatch" => false | 973 | "disablebatch" => false |
944 | ); | 974 | ); |
945 | 975 | ||
@@ -958,31 +988,49 @@ class WebServer | @@ -958,31 +988,49 @@ class WebServer | ||
958 | else return array('success' => false, 'message' => $downloadResult['message']); | 988 | else return array('success' => false, 'message' => $downloadResult['message']); |
959 | } | 989 | } |
960 | 990 | ||
961 | - $resultFile = USERPATH . $this->userID . '/RES/' . $downloadResult['folder'] . '/' . $downloadResult['result']; | ||
962 | - $resultFile .= $kernelExtension; | ||
963 | - | ||
964 | - if (!file_exists($resultFile)) { | ||
965 | - if ($this->isSoap) throw new SoapFault("server04", 'Cannot retrieve result file ' . $resultFile); | ||
966 | - else return array('success' => false, 'message' => 'Cannot retrieve result file'); | ||
967 | - } | ||
968 | - | ||
969 | - rename($resultFile, WSRESULT . $this->dataFileName . $wsExtension); | ||
970 | - $outputFile = WSRESULT . $this->dataFileName . $wsExtension; | ||
971 | - chmod($outputFile, 0664); | ||
972 | - $outputFile = 'http://' . str_replace(BASE_PATH, $_SERVER['SERVER_NAME'] . APACHE_ALIAS, $outputFile); | ||
973 | - | ||
974 | - $obj = (object)array( | ||
975 | - 'id' => $downloadResult['id'] | ||
976 | - ); | ||
977 | - | ||
978 | - try { | ||
979 | - $downloadResult = $this->requestManager->runIHMRequest($this->userID, $this->getIPclient(), FunctionTypeEnumClass::PROCESSDELETE, $obj); | ||
980 | - } catch (Exception $e) { | ||
981 | - //Nothing to do | 991 | + if($downloadResult['status'] == 'in_progress') { |
992 | + return ['success' => true, 'status' => 'in_progress', 'id' => $downloadResult['id']]; | ||
993 | + } elseif ($downloadResult['status'] == 'done') { | ||
994 | + return $this->finishDownloadRequest($downloadResult); | ||
995 | + } else { | ||
996 | + return ['success' => false, 'message' => 'Unknown status ' . $downloadResult['status'] . '.']; | ||
982 | } | 997 | } |
998 | + } | ||
983 | 999 | ||
984 | - return array('success' => true, 'dataFileURLs' => $outputFile); | ||
985 | - | 1000 | + private function finishDownloadRequest($downloadResult) |
1001 | + { | ||
1002 | + require_once(INTEGRATION_SRC_DIR . "RequestManager.php"); | ||
1003 | + IHMConfigClass::setUserName($this->userID); | ||
1004 | + if (!isset($this->paramLoader)) | ||
1005 | + $this->paramLoader = new IHMUserParamLoaderClass(); | ||
1006 | + if (!isset($this->requestManager)) | ||
1007 | + $this->requestManager = new RequestManagerClass(); | ||
1008 | + | ||
1009 | + $kernelExtension = '.txt'; // TODO: handle other formats | ||
1010 | + $wsExtension = '.txt'; | ||
1011 | + $resultFile = USERPATH . $this->userID . '/RES/' . $downloadResult['folder'] . '/' . $downloadResult['result'] . $kernelExtension; | ||
1012 | + $outputFile = WSRESULT . $this->dataFileName . $wsExtension; | ||
1013 | + | ||
1014 | + if (!file_exists($resultFile)) { | ||
1015 | + if ($this->isSoap) throw new SoapFault("server04", 'Cannot retrieve result file ' . $resultFile); | ||
1016 | + else return ['success' => false, 'message' => 'Cannot retrieve result file']; | ||
1017 | + } | ||
1018 | + | ||
1019 | + rename($resultFile, $outputFile); | ||
1020 | + chmod($outputFile, 0664); | ||
1021 | + $outputURL = 'http://' . str_replace(BASE_PATH, $_SERVER['SERVER_NAME'] . APACHE_ALIAS, $outputFile); | ||
1022 | + | ||
1023 | + $obj = (object)array( | ||
1024 | + 'id' => $downloadResult['id'] | ||
1025 | + ); | ||
1026 | + | ||
1027 | + try { | ||
1028 | + $downloadResult = $this->requestManager->runIHMRequest($this->userID, $this->getIPclient(), FunctionTypeEnumClass::PROCESSDELETE, $obj); | ||
1029 | + } catch (Exception $e) { | ||
1030 | + //Nothing to do | ||
1031 | + } | ||
1032 | + | ||
1033 | + return array('success' => true, 'status' => 'done', 'dataFileURLs' => $outputURL); | ||
986 | } | 1034 | } |
987 | 1035 | ||
988 | protected function timeIntervalToDuration($startTime, $stopTime) | 1036 | protected function timeIntervalToDuration($startTime, $stopTime) |
php/rest/getParameter.php
@@ -13,17 +13,11 @@ require_once '../config.php'; | @@ -13,17 +13,11 @@ require_once '../config.php'; | ||
13 | $amda_ws = new WebServer(); | 13 | $amda_ws = new WebServer(); |
14 | 14 | ||
15 | if (!key_exists("token", $_GET)) { | 15 | if (!key_exists("token", $_GET)) { |
16 | - $result = array('success' => false, 'message' => "E01: Authentication is required for this webservice."); | 16 | + $result = array('success' => false, 'message' => "Authentication is required for this webservice."); |
17 | } else if ($amda_ws->getNewToken()['token'] != $_GET["token"]) { | 17 | } else if ($amda_ws->getNewToken()['token'] != $_GET["token"]) { |
18 | - $result = array('success' => false, 'message' => "E02: Token expired. Please authenticate again."); | 18 | + $result = array('success' => false, 'status' => 'expired', 'message' => "Token expired. Please authenticate again."); |
19 | } else { | 19 | } else { |
20 | $result = $amda_ws->getParameter($_GET); | 20 | $result = $amda_ws->getParameter($_GET); |
21 | } | 21 | } |
22 | - | ||
23 | -if ($result['success']) { | ||
24 | - echo $result['dataFileURLs']; | ||
25 | -} else { | ||
26 | - echo $result['message']; | ||
27 | -} | ||
28 | - | 22 | +echo json_encode($result); |
29 | ?> | 23 | ?> |
30 | \ No newline at end of file | 24 | \ No newline at end of file |
php/rest/getStatus.php
@@ -6,14 +6,13 @@ | @@ -6,14 +6,13 @@ | ||
6 | * | 6 | * |
7 | * @version $Id: $ | 7 | * @version $Id: $ |
8 | */ | 8 | */ |
9 | -// | ||
10 | -// | ||
11 | -// 3€/m <50Go | ||
12 | -// | ||
13 | -require_once '../config.php'; | ||
14 | 9 | ||
15 | -$amda_ws = new WebServer(); | ||
16 | -$result = $amda_ws->getStatus($_GET); | 10 | +require_once '../config.php'; |
17 | 11 | ||
18 | -echo '<pre>' . var_export($result, true) . '</pre>'; | ||
19 | -?> | ||
20 | \ No newline at end of file | 12 | \ No newline at end of file |
13 | +if (!key_exists("id", $_GET)) { | ||
14 | + $result = array('success' => false, 'message' => "You must provide a job id."); | ||
15 | +} else { | ||
16 | + $amda_ws = new WebServer(); | ||
17 | + $result = $amda_ws->getStatus($_GET); | ||
18 | +} | ||
19 | +echo json_encode($result); | ||
21 | \ No newline at end of file | 20 | \ No newline at end of file |