Commit 0b6b20804af389764b1216d3e0b4735304fcd06a

Authored by Elena.Budnik
1 parent 87a28122

TT download

src/InputOutput/IHMImpl/Config/IHMConfigClass.php
... ... @@ -34,6 +34,8 @@ class IHMConfigClass
34 34 private static $ttDir = "TT/";
35 35  
36 36 private static $wsDir = "WS/";
  37 +
  38 + private static $downloadTmp = "DOWNLOAD.TEMP/";
37 39  
38 40 private static $jobsDir = "JOBS/";
39 41  
... ... @@ -94,14 +96,19 @@ class IHMConfigClass
94 96 return self::getUserPath().self::$paramTemplateGenerateDir;
95 97 }
96 98  
  99 + public static function getDownloadTmpPath()
  100 + {
  101 + return self::getUserPath().self::$downloadTmp;
  102 + }
  103 +
97 104 public static function getParamTemplateListFilePath()
98 105 {
99 106 return IHM_SRC_DIR.self::$genericDataDir.self::$paramTemplateDir.self::$paramTemplateFile;
100 107 }
101 108  
102   - public static function getUserParamManagerFilePath()
103   - {
104   - return self::getUserWSPath().self::$userParamMgrFile;
  109 + public static function getUserParamManagerFilePath()
  110 + {
  111 + return self::getUserWSPath().self::$userParamMgrFile;
105 112 }
106 113  
107 114 public static function getUserDerivedParamFilePath($paramId)
... ...
src/InputOutput/IHMImpl/IHMInputOutputClass.php
... ... @@ -88,6 +88,9 @@ class IHMInputOutputClass implements InputOutputInterface
88 88 case FunctionTypeEnumClass::TTUNION :
89 89 $this->inputOutput = new IHMInputOutputUnionTTClass();
90 90 break;*/
  91 + case FunctionTypeEnumClass::TTCONVERT :
  92 + $this->inputOutput = new IHMInputOutputTTClass();
  93 + break;
91 94 case FunctionTypeEnumClass::PARAMINFO :
92 95 $this->inputOutput = new IHMInputOutputParamInfoClass();
93 96 break;
... ...
src/InputOutput/IHMImpl/TimeTables/IHMInputOutputConvertTTClass.php 0 → 100644
... ... @@ -0,0 +1,69 @@
  1 +<?php
  2 +
  3 +/**
  4 + * @class IHMInputOutputTTClass
  5 + * @brief
  6 + * @details
  7 +*/
  8 +class IHMInputOutputTTClass implements InputOutputInterface
  9 +{
  10 + /*
  11 + * @brief Constructor
  12 + */
  13 + function __construct()
  14 + {
  15 + //$this->jobsManager = new IHMJobsManagerClass();
  16 + }
  17 +
  18 + /*
  19 + * @brief translate input data from IHM client to AMDA_Integration module for a tt process request
  20 + */
  21 + public function getInputData($input, $function, $requestId="")
  22 + {
  23 + if (isset($this->processDatas))
  24 + unset($this->processDatas);
  25 +
  26 + if (!$res['success'])
  27 + throw new Exception($res['message']);
  28 +
  29 +
  30 + foreach($input->list as $tt)
  31 + {
  32 + //create a list of data to treat
  33 + $processData = new TTRequestDataClass();
  34 +
  35 + $processData->setInputTimeTable($tt);
  36 + $processData->setInputFormat($input);
  37 + $processData->setOutputDir();
  38 + $processData->setOutputTimeTable($tt);
  39 + $processData->setOutputFormat();
  40 +
  41 + $processData->setCompression();
  42 +
  43 + $this->processDatas[] = $processData;
  44 + }
  45 +
  46 + return $this->processDatas;
  47 + }
  48 +
  49 + /*
  50 + * @brief translate output data from AMDA_Integration module to IHM client request
  51 + */
  52 + public function getOutput($data)
  53 + {
  54 + $result = array();
  55 +
  56 + foreach ($data as $d)
  57 + {
  58 + if (!$d->getSuccess())
  59 + continue;
  60 +
  61 + //$res = $this->jobsManager->deleteJob($d->getId());
  62 + }
  63 +
  64 + return $result;
  65 + }
  66 +}
  67 +
  68 +}
  69 +?>
... ...
src/InputOutput/IHMImpl/TimeTables/IHMInputOutputTTClass.php 0 → 100644
... ... @@ -0,0 +1,122 @@
  1 +<?php
  2 +
  3 +/**
  4 + * @class IHMInputOutputTTClass
  5 + * @brief
  6 + * @details
  7 +*/
  8 +class IHMInputOutputTTClass implements InputOutputInterface
  9 +{
  10 +
  11 +/*
  12 + * @brief Constructor
  13 +*/
  14 + function __construct()
  15 + {
  16 +
  17 + }
  18 +
  19 +/*
  20 + * @brief translate input data from IHM client to AMDA_Integration module for a tt process request
  21 +*/
  22 + public function getInputData($input, $function, $requestId="")
  23 + {
  24 + if (isset($this->processDatas))
  25 + unset($this->processDatas);
  26 +
  27 + $final = "";
  28 +
  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 $tt)
  35 + {
  36 + //create a list of data to treat
  37 + $processData = new TTRequestDataClass();
  38 + $ttName = IHMConfigClass::getUserTTPath().$tt->id.'.xml';
  39 + if (!file_exists($ttName))
  40 + throw new Exception('TimeTable '.$tt->name.' not found');
  41 + $processData->setInputFileName($ttName);
  42 + $processData->setInputFileFormat(TTRequestFileFormatEnum::INTERNAL);
  43 + $processData->setOutputDir(IHMConfigClass::getDownloadTmpPath());
  44 +
  45 + switch ($input->fileformat) {
  46 + case 'vot' :
  47 + $processData->setOutputFileFormat(TTRequestFileFormatEnum::VOTABLE);
  48 + $outputName = $tt->name.'.xml';
  49 + break;
  50 + default :
  51 + $processData->setOutputFileFormat(TTRequestFileFormatEnum::ASCII);
  52 + $outputName = $tt->name;
  53 + }
  54 +
  55 + // $processData->setOutputTimeFormat($input->timeformat);
  56 + $processData->setOutputFileName($outputName);
  57 + $final .= " ".$outputName;
  58 + $processData->setType($function);
  59 + $processData->setCmd("ttConversion");
  60 +
  61 + $this->processDatas[] = $processData;
  62 + }
  63 +
  64 + $this->postProcessTT = new PostProcessTTClass();
  65 + $this->postProcessTT->setOutputDirAlias($this->processDatas[0]->getOutputDir());
  66 +
  67 + if ($input->compression !== 'none') {
  68 + $this->postProcessTT->compression = true;
  69 + $archive = "Timetable_archive_".date('Ymd_Hi');
  70 + switch ($input->compression) {
  71 + case 'zip' :
  72 + $postCmd = "zip -Dj ".$archive.".zip ".$final." 1> /dev/null 2> /dev/null";
  73 + $outputFileName = $archive.".zip";
  74 + break;
  75 + case 'tar+gzip':
  76 + default :
  77 + $postCmd="tar cfz ".$archive.".tar.gz --directory=".$this->processDatas[0]->getOutputDir()." ".$final;
  78 + $outputFileName = $archive.".tar.gz";
  79 + break;
  80 + }
  81 + $this->postProcessTT->setPostCmd($postCmd);
  82 + $this->postProcessTT->setOutputFileName($outputFileName);
  83 + $this->postProcessTT->setOutputDir($this->processDatas[0]->getOutputDir());
  84 + }
  85 +
  86 + return $this->processDatas;
  87 + }
  88 +
  89 +/*
  90 + * @brief translate output data from AMDA_Integration module to IHM client request
  91 +*/
  92 + public function getOutput($data)
  93 + {
  94 + if ( $this->postProcessTT->compression ) {
  95 +
  96 + $cmd = $this->postProcessTT->getPostCmd();
  97 + system($cmd);
  98 + sleep(1); // if immediately - raw files are not deleted (?)
  99 +
  100 + foreach ($data as $d)
  101 + {
  102 + $rawFileName = $d->getOutputDir().$d->getOutputFileName();
  103 + if (file_exists($rawFileName))
  104 + unlink($rawFileName);
  105 + }
  106 +
  107 + $result = array('success'=>true,
  108 + 'download'=>$this->postProcessTT->getOutputDirAlias().$this->postProcessTT->getOutputFileName(),
  109 + 'compression' => $this->postProcessTT->compression);
  110 +
  111 +
  112 + }
  113 + else {
  114 + $result = array('success'=>$data[0]->getSuccess(),
  115 + 'download' => $this->postProcessTT->getOutputDirAlias().$data[0]->getOutputFileName());
  116 + }
  117 +
  118 + return $result;
  119 + }
  120 +}
  121 +
  122 +?>
... ...
src/Request/ProcessRequestImpl/Process/ProcessManagerClass.php
... ... @@ -24,7 +24,7 @@ class ProcessManagerClass
24 24 $process = new ProcessClass($cmd, $postProcessCmd);
25 25  
26 26 if (!$process->run($runningPath, $envArray))
27   - return array("success" => false, "message" => "Cannot run the process");;
  27 + return array("success" => false, "message" => "Cannot run the process");
28 28  
29 29 $res = $this->concurrentAccessProcessManagerFile(array($this,'addProcessInProcessManagerFile'),$process);
30 30  
... ...
src/Request/TTRequestImpl/PostProcessTTClass.php 0 → 100644
... ... @@ -0,0 +1,63 @@
  1 +<?php
  2 +
  3 +/**
  4 + * @class PostProcessTTClass
  5 + * @brief Data for a TT post process request
  6 + * @details
  7 + */
  8 +class PostProcessTTClass
  9 +{
  10 +
  11 + private $outputFileName = "";
  12 + private $postCmd = "";
  13 + private $outputDirAlias = "";
  14 + private $outputDir = "";
  15 +
  16 + public $compression = false;
  17 +
  18 + public function getOutputFileName()
  19 + {
  20 + return $this->outputFileName;
  21 + }
  22 +
  23 + public function setOutputFileName($outputFileName)
  24 + {
  25 + $this->outputFileName = $outputFileName;
  26 + }
  27 +
  28 + public function getPostCmd()
  29 + {
  30 + return $this->postCmd;
  31 + }
  32 +
  33 + public function setPostCmd($postCmd)
  34 + {
  35 + $this->postCmd = $postCmd;
  36 + }
  37 +
  38 + public function getOutputDir()
  39 + {
  40 + return $this->outputDir."/";
  41 + }
  42 +
  43 + public function setOutputDir($outputDir)
  44 + {
  45 + $this->outputDir = $outputDir;
  46 + }
  47 +
  48 + public function getOutputDirAlias()
  49 + {
  50 + return $this->outputDirAlias;
  51 + }
  52 +
  53 + public function setOutputDirAlias($outputDir)
  54 + {
  55 + $pos = strpos($outputDir, '/data/');
  56 +
  57 + if ($pos > 0)
  58 + $this->outputDirAlias = substr($outputDir,$pos + 1);
  59 + }
  60 +
  61 +}
  62 +
  63 +?>
0 64 \ No newline at end of file
... ...
src/Request/TTRequestImpl/TTRequestClass.php 0 → 100644
... ... @@ -0,0 +1,96 @@
  1 +<?php
  2 +/**
  3 + * @class TTRequestClass
  4 + * @brief Implementation of a
  5 +
  6 + */
  7 +class TTRequestClass extends RequestAbstractClass
  8 +{
  9 + /*
  10 + * @brief Init a process request of type "run"
  11 + */
  12 + public function init()
  13 + {
  14 + if (!isset($this->requestData))
  15 + return false;
  16 +
  17 + if ($this->requestData->getCmd() == '')
  18 + {
  19 + $this->requestData->setLastErrorMessage('No process command defined');
  20 + return false;
  21 + }
  22 +
  23 + if ($this->requestData->getOutputDir() == '')
  24 + {
  25 + $this->requestData->setLastErrorMessage('No output dir defined');
  26 + return false;
  27 + }
  28 +
  29 + if (!is_dir($this->requestData->getOutputDir()))
  30 + {
  31 + if (!mkdir($this->requestData->getOutputDir(),0777) || !is_dir($this->requestData->getOutputDir()))
  32 + {
  33 + $this->requestData->setLastErrorMessage('Cannot create output dir');
  34 + return false;
  35 + }
  36 + }
  37 +
  38 + if (!file_exists($this->requestData->getOutputDir()."app.properties"))
  39 + KernelConfigClass::write($this->requestData->getOutputDir(), "", "");
  40 +
  41 + $this->requestData->setEnvVars(KernelConfigClass::getExecEnvVarArray());
  42 +
  43 + return true;
  44 + }
  45 +
  46 + /*
  47 + * @brief Run a process request
  48 + */
  49 +
  50 + public function run()
  51 + {
  52 + if (!isset($this->requestData))
  53 + return false;
  54 +
  55 + $this->requestData->setSuccess(false);
  56 + $this->requestData->setLastErrorMessage('Cannot run process request');
  57 +
  58 + switch ($this->requestData->getType())
  59 + {
  60 + case FunctionTypeEnumClass::TTCONVERT :
  61 + //run process
  62 +
  63 + $args = $this->requestData->getInputFileName()." ".$this->requestData->getInputFileFormat()
  64 + ." ".$this->requestData->getOutputDir()." ".$this->requestData->getOutputFileName()
  65 + ." ".$this->requestData->getOutputFileFormat();
  66 +
  67 + $cmd = $this->requestData->getCmd()." ".$args;
  68 +
  69 + $process = new ProcessClass($cmd); //, $postProcessCmd);
  70 +
  71 + if (!$process->run($this->requestData->getOutputDir(), $this->requestData->getEnvVars()))
  72 + return array("success" => false, "message" => "Cannot run the TT process");
  73 +
  74 + //TBD
  75 + while ($process->isRunning() && time() - $process->getRunningStart() > KernelConfigClass::getTimeToBatchMode()) {
  76 + sleep(1);
  77 + }
  78 +
  79 + $result = array('success' => true);
  80 +
  81 + break;
  82 + default :
  83 + $this->requestData->setLastErrorMessage("TT process method not implemented");
  84 + return false;
  85 + }
  86 +
  87 + $this->requestData->setSuccess($result['success']);
  88 +
  89 + if (!$result['success'])
  90 + $this->requestData->setLastErrorMessage($result['message']);
  91 +
  92 + return ($result['success']);
  93 + }
  94 +
  95 +}
  96 +?>
0 97 \ No newline at end of file
... ...
src/Request/TTRequestImpl/TTRequestDataClass.php 0 → 100644
... ... @@ -0,0 +1,129 @@
  1 +<?php
  2 +
  3 +abstract class TTRequestTimeFormatEnum
  4 +{
  5 + const UNKNOWN = "";
  6 + const ISO = "ISO";
  7 + const DDTIME = "DD";
  8 + const TIMESTAMP = "DOUBLE";
  9 +}
  10 +
  11 +abstract class TTRequestFileFormatEnum
  12 +{
  13 + const UNKNOWN = "";
  14 + const ASCII = "ASCII";
  15 + const VOTABLE = "VO";
  16 + const INTERNAL = "Internal";
  17 +}
  18 +
  19 +/**
  20 + * @class TTRequestDataClass
  21 + * @brief Data for a TT process request
  22 + * @details
  23 + */
  24 +class TTRequestDataClass extends RequestDataClass
  25 +{
  26 + private $inputTimeTable = "";
  27 + private $outputTimeTable = "";
  28 + private $inputFileFormat = "";
  29 + private $outputFileFormat = "";
  30 + private $inputTimeFormat = "";
  31 + private $outputTimeFormat = "";
  32 + private $outputDir = "";
  33 + private $cmd = "";
  34 + private $envVars = array();
  35 + private $exitCode = 0;
  36 +
  37 + public function getInputFileName()
  38 + {
  39 + return $this->inputTimeTable;
  40 + }
  41 +
  42 + public function setInputFileName($inputTimeTable)
  43 + {
  44 + $this->inputTimeTable = $inputTimeTable;
  45 + }
  46 +
  47 + public function getOutputFileName()
  48 + {
  49 + return $this->outputTimeTable;
  50 + }
  51 +
  52 + public function setOutputFileName($outputTimeTable)
  53 + {
  54 + $this->outputTimeTable = $outputTimeTable;
  55 + }
  56 +
  57 + public function getOutputFileFormat()
  58 + {
  59 + return $this->outputFileFormat;
  60 + }
  61 +
  62 + public function setOutputFileFormat($outputFileFormat)
  63 + {
  64 + $this->outputFileFormat = $outputFileFormat;
  65 + }
  66 +
  67 + public function getInputFileFormat()
  68 + {
  69 + return $this->inputFileFormat;
  70 + }
  71 +
  72 + public function setInputFileFormat($inputFileFormat)
  73 + {
  74 + $this->inputFileFormat = $inputFileFormat;
  75 + }
  76 +
  77 + public function getOutputDir()
  78 + {
  79 + return $this->outputDir."/";
  80 + }
  81 +
  82 + public function setOutputDir($outputDir)
  83 + {
  84 + $this->outputDir = $outputDir;
  85 + }
  86 +
  87 + public function getCmd()
  88 + {
  89 + return $this->cmd;
  90 + }
  91 +
  92 + public function setCmd($cmd)
  93 + {
  94 + $this->cmd = $cmd;
  95 + }
  96 +
  97 + public function getEnvVars()
  98 + {
  99 + return $this->envVars;
  100 + }
  101 +
  102 + public function setEnvVars($envVars)
  103 + {
  104 + $this->envVars = $envVars;
  105 + }
  106 +
  107 + public function getType()
  108 + {
  109 + return $this->type;
  110 + }
  111 +
  112 + public function setType($type)
  113 + {
  114 + $this->type = $type;
  115 + }
  116 +
  117 +
  118 + public function getErrorCode()
  119 + {
  120 + return $this->exitCode;
  121 + }
  122 +
  123 + public function setErrorCode($errorCode)
  124 + {
  125 + $this->exitCode = $errorCode;
  126 + }
  127 +}
  128 +
  129 +?>
0 130 \ No newline at end of file
... ...
src/RequestManager.php
... ... @@ -16,6 +16,7 @@ function amdaintegration_autoload($class_name)
16 16 'InputOutput/IHMImpl/Process',
17 17 'InputOutput/IHMImpl/ParamInfo',
18 18 'InputOutput/IHMImpl/Tools',
  19 + 'InputOutput/IHMImpl/TimeTables',
19 20 'InputOutput/TestImpl',
20 21 'Request',
21 22 'Request/Config',
... ... @@ -25,7 +26,8 @@ function amdaintegration_autoload($class_name)
25 26 'Request/ParamsRequestImpl/Nodes/Params',
26 27 'Request/ParamsRequestImpl/Nodes/Requests',
27 28 'Request/ProcessRequestImpl',
28   - 'Request/ProcessRequestImpl/Process'
  29 + 'Request/ProcessRequestImpl/Process',
  30 + 'Request/TTRequestImpl'
29 31 );
30 32  
31 33 foreach($dirs as $dir)
... ... @@ -57,6 +59,7 @@ abstract class FunctionTypeEnumClass
57 59 const PROCESSCLEAN = "process_clean";
58 60 const TTMERGE = "tt_merge";
59 61 const TTUNION = "tt_union";
  62 + const TTCONVERT = "tt_convert";
60 63 const PARAMINFO = "param_info";
61 64 }
62 65  
... ... @@ -80,33 +83,33 @@ Class RequestManagerClass
80 83 {
81 84 public static $version = "1.5.0";
82 85  
83   - /*
84   - * @brief Constructor
85   - */
  86 +/*
  87 + * @brief Constructor
  88 +*/
86 89 function __construct()
87 90 {
88 91 }
89 92  
90   - /*
91   - * @brief Treat a request that's come from the IHM
92   - */
  93 +/*
  94 + * @brief Treat a request that's come from the IHM
  95 +*/
93 96 public function runIHMRequest($user, $userHost, $function, $input)
94 97 {
95 98 return $this->runGenericRequest(ClientTypeEnumClass::IHM,$user,$userHost,$function,$input);
96 99 }
97 100  
98   - /*
99   - * @brief Treat a request that's come from a test script
100   - */
  101 +/*
  102 + * @brief Treat a request that's come from a test script
  103 +*/
101 104 public function runTestRequest($user, $function, $input)
102 105 {
103 106 $userHost = "";
104 107 return $this->runGenericRequest(ClientTypeEnumClass::TEST,$user,$userHost,$function,$input);
105 108 }
106 109  
107   - /*
108   - * @brief Create the request instance in relation with the function type
109   - */
  110 +/*
  111 + * @brief Create the request instance in relation with the function type
  112 +*/
110 113 private function createRequest($user, $userHost, $function)
111 114 {
112 115 switch ($function)
... ... @@ -122,6 +125,7 @@ Class RequestManagerClass
122 125 return new ProcessRequestClass($user, $userHost);
123 126 case FunctionTypeEnumClass::TTMERGE :
124 127 case FunctionTypeEnumClass::TTUNION :
  128 + case FunctionTypeEnumClass::TTCONVERT :
125 129 return new TTRequestClass($user, $userHost);
126 130 case FunctionTypeEnumClass::PARAMINFO :
127 131 return new ParamInfoRequestClass($user, $userHost);
... ... @@ -130,9 +134,9 @@ Class RequestManagerClass
130 134 }
131 135 }
132 136  
133   - /*
134   - * @brief Create an instance of the InputOutput interface in relation with the client
135   - */
  137 +/*
  138 + * @brief Create an instance of the InputOutput interface in relation with the client
  139 +*/
136 140 private function createInputOutput($user,$client)
137 141 {
138 142 switch ($client)
... ... @@ -146,9 +150,9 @@ Class RequestManagerClass
146 150 }
147 151 }
148 152  
149   - /*
150   - * @brief Sequence used to run a request
151   - */
  153 +/*
  154 + * @brief Sequence used to run a request
  155 +*/
152 156 private function runGenericRequest($client,$user,$userHost,$function,$input)
153 157 {
154 158 //create an instance of the InputOutput interface
... ... @@ -169,14 +173,14 @@ Class RequestManagerClass
169 173 }
170 174 else
171 175 $outputdata = $this->runSingleRequest($request,$inputdata);
172   -
  176 +
173 177 //get the request output data from the output data by using the InputOutput interface
174 178 return $inputOutput->getOutput($outputdata);
175 179 }
176 180  
177   - /*
178   - * @brief Run a single request
179   - */
  181 +/*
  182 + * @brief Run a single request
  183 +*/
180 184 private function runSingleRequest($request,$data)
181 185 {
182 186 //link the request to the input data
... ...