From a55dc57ad141127f71c0f8779d325898a1815c85 Mon Sep 17 00:00:00 2001 From: Elena.Budnik <ebudnik@irap.omp.eu> Date: Tue, 6 Mar 2018 17:00:12 +0100 Subject: [PATCH] interim commit --- php/classes/WebServer.php | 134 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------------------------------------------------------- 1 file changed, 57 insertions(+), 77 deletions(-) diff --git a/php/classes/WebServer.php b/php/classes/WebServer.php index 7d51baf..f134f96 100644 --- a/php/classes/WebServer.php +++ b/php/classes/WebServer.php @@ -82,7 +82,7 @@ class WebServer function __construct() { - + if (!is_dir(WSConfigClass::getWsResultDir())) mkdir(WSConfigClass::getWsResultDir(), 0775); // $this->resultMgr = new WebResultMgr(); } @@ -158,33 +158,6 @@ class WebServer return $realIP; } -// private function timeInterval2Days($TimeInterval) -// { -// $divDays = 60*60*24; -// $nbDays = floor($TimeInterval / $divDays); -// $divHours = 60*60; -// $nbHours = floor(($TimeInterval - $divDays*$nbDays)/$divHours); -// $nbMin = floor(($TimeInterval - $divDays*$nbDays - $divHours*$nbHours)/60); -// $nbSec = $TimeInterval - $divDays*$nbDays - $divHours*$nbHours - $nbMin*60; -// -// $DD = sprintf("%03d", $nbDays); // format ex. 005 not 5 -// $HH = sprintf("%02d", $nbHours); // format ex. 25 -// $MM = sprintf("%02d", $nbMin); // format ex. 03 not 3 -// $SS = sprintf("%02d", $nbSec); // format ex. 02 not 2 -// -// return $DD.':'.$HH.':'.$MM.':'.$SS; -// } - - /* Start Time into AMDA format YYYY:DOY-1:HH:MM:SS */ -// private function startTime2Days($startTime) -// { -// $ddStart = getdate($startTime); -// $date_start = sprintf("%04d",$ddStart["year"]).":".sprintf("%03d", $ddStart["yday"]).":" -// .sprintf("%02d",$ddStart["hours"]).":".sprintf("%02d",$ddStart["minutes"]).":" -// .sprintf("%02d",$ddStart["seconds"]); -// return $date_start; -// } - private function rrmdir($dir) { if (is_dir($dir)) { @@ -457,61 +430,68 @@ class WebServer public function getStatus($id) { - $processManager = new ProcessManagerClass(IHMConfigClass::getProcessManagerFilePath()); + $this->userID = 'impex'; + + if (!isset($this->requestManager)) + $this->requestManager = new RequestManagerClass(); try { - $res = $processManager->getProcessInfo($id, true); + $res = $this->requestManager->runWSRequest($this->userID, $this->getIPclient(), FunctionTypeEnumClass::PROCESSGETINFO, null, $id); } catch (Exception $e) { - $this->throwError("serverError","Exception detected : ".$e->getMessage()); - } -// [success] => 1 -// [result] => Array -// ( -// [id] => process_ADBCw1_1519836455_19505 -// [cmd] => /home/budnik/AMDA/AMDA_Kernel/build/Debug/bin/amdaXMLRequestorTool /home/budnik/AMDA/AMDA_IHM/data/budnik/RES/DDnT8PLR_/request_0.xml -// [outputfile] => cmd_output -// [exitcodefile] => cmd_exitcode -// [processfile] => cmd_process -// [exitcode] => 0 -// [PID] => 19505 -// [runningpath] => /home/budnik/AMDA/AMDA_IHM/data/budnik/RES/DDnT8PLR_/ -// [runningstart] => 1519836455 -// [isrunning] => -// [iskilled] => -// [lastupdate] => 1519837450 -// ) + return array("error" => $e->getMessage()); + // $this->throwError("serverError", "Exeption detected : ".$e->getMessage()); + } +// [success] => 1 +// [id] => process_t7ovpn_1520344095_13119 +// [name] => download_1520344108 +// [status] => done +// [jobType] => download +// [info] => imf +// [start] => 06-03-2018 13:48:15 +// [stop] => 06-03-2018 15:40:20 +// [folder] => DDEUQzrM_ +// [result] => result_EUQzrM +// [format] => unknown +// [compression] => 0 + +// [success] => 1 +// [id] => process_t7ovpn_1520344095_13119 +// [name] => download_1520344108 +// [status] => in_progress +// [jobType] => download +// [info] => imf +// [start] => 06-03-2018 13:48:15 +// [stop] => unknown +// [folder] => DDEUQzrM_ +// [result] => result_EUQzrM +// [format] => unknown +// [compression] => 0 if (!$res['success']) { $this->throwError("processError","Cannot retrieve process $id info"); } - - $result = $res['result']; - - if ($result['isrunning']) { - return array('success' => true, 'status' => 'in_progress'); - } - - if ($result['iskilled']) { - $this->throwError("processError","Process $id was killed"); - } - - if ($result['exitcode'] !== 0) { - $this->throwError("processError","Process $id error code: ".$result['exitcode']); + + if ($res['status'] == 'in_progress') { + return array('success' => true, 'status' => 'in progress'); } - $vars = $this->getVarsFromRunningPath($result['runningpath']); - - if (!$vars['success']) { - $this->throwError("processError","Process $id : cannot generate file name for result : ".$vars['message']); + if ($res['error']) { + $this->throwError("processError","Process $id error code"); } - $resultFile = glob($result['runningpath']."result_*"); + // $vars = $this->getVarsFromRunningPath($result['runningpath']); - $tempFilePath = $result['runningpath'].$resultFile.$vars['kernelExtension']; - - $outputFilePath = WSRESULT.$vars['dataFileName'].$vars['wsExtension']; +// if (!$vars['success']) { +// $this->throwError("processError","Process $id : cannot generate file name for result : ".$vars['message']); +// } +// +// $resultFile = glob($result['runningpath']."result_*"); +// +// $tempFilePath = $result['runningpath'].$resultFile.$vars['kernelExtension']; +// +// $outputFilePath = WSRESULT.$vars['dataFileName'].$vars['wsExtension']; - return $this->finishDownloadRequest($id, $tempFilePath, $outputFilePath); + return array('success' => true,'status' => $res['status']); //$this->finishDownloadRequest($id, $tempFilePath, $outputFilePath); } @@ -911,7 +891,7 @@ class WebServer $this->requestManager = new RequestManagerClass(); try { - $downloadResult = $this->requestManager->runWSRequest($this->userID, $this->getIPclient(), WSConfigClass::DOWNLOAD, $obj); + $downloadResult = $this->requestManager->runWSRequest($this->userID, $this->getIPclient(), FunctionTypeEnumClass::PARAMS, WSConfigClass::DOWNLOAD, $obj); } catch (Exception $e) { $this->throwError("executionError", "Exception detected : ".$e->getMessage()); } @@ -939,7 +919,7 @@ class WebServer } rename($resTempFilePath, $resOutputFilePath); - chmod($resOutputFilePath, 0664); + // chmod($resOutputFilePath, 0664); $outputURL = 'http://' . str_replace(BASE_PATH, $_SERVER['SERVER_NAME'] . APACHE_ALIAS, $resOutputFilePath); @@ -950,11 +930,11 @@ class WebServer if (!isset($this->requestManager)) $this->requestManager = new RequestManagerClass(); - try { - $downloadResult = $this->requestManager->runIHMRequest($this->userID, $this->getIPclient(), FunctionTypeEnumClass::PROCESSDELETE, $obj); - } catch (Exception $e) { - error_log("Can not delete file $resOutputFilePath: $e"); - } +// try { +// $downloadResult = $this->requestManager->runIHMRequest($this->userID, $this->getIPclient(), FunctionTypeEnumClass::PROCESSDELETE, $obj); +// } catch (Exception $e) { +// error_log("Can not delete file $resOutputFilePath: $e"); +// } return array('success' => true, 'status' => 'done', 'dataFileURLs' => $outputURL); } -- libgit2 0.21.2