Commit 574d7ed3a42588ee78d64d9b9a0933303ae2e0f7
1 parent
22253da3
Exists in
master
and in
55 other branches
First step to automatically split user plot requests
Showing
6 changed files
with
198 additions
and
4 deletions
Show diff stats
src/FunctionTypeEnumClass.php
@@ -19,6 +19,7 @@ abstract class FunctionTypeEnumClass | @@ -19,6 +19,7 @@ abstract class FunctionTypeEnumClass | ||
19 | const TTUNION = "tt_union"; | 19 | const TTUNION = "tt_union"; |
20 | const TTCONVERT = "tt_convert"; | 20 | const TTCONVERT = "tt_convert"; |
21 | const PARAMINFO = "param_info"; | 21 | const PARAMINFO = "param_info"; |
22 | + const USERWSINIT = "user_init"; | ||
22 | } | 23 | } |
23 | ?> | 24 | ?> |
24 | 25 |
src/InputOutput/IHMImpl/Config/IHMConfigClass.php
@@ -25,6 +25,8 @@ class IHMConfigClass | @@ -25,6 +25,8 @@ class IHMConfigClass | ||
25 | 25 | ||
26 | private static $compilationDir = "compilation/"; | 26 | private static $compilationDir = "compilation/"; |
27 | 27 | ||
28 | + private static $storedRequestDir = "REQ/"; | ||
29 | + | ||
28 | private static $requestDir = "RES/"; | 30 | private static $requestDir = "RES/"; |
29 | 31 | ||
30 | private static $sharedDir = "shared_data/"; | 32 | private static $sharedDir = "shared_data/"; |
@@ -43,12 +45,16 @@ class IHMConfigClass | @@ -43,12 +45,16 @@ class IHMConfigClass | ||
43 | 45 | ||
44 | private static $aliasesFile = "Alias.xml"; | 46 | private static $aliasesFile = "Alias.xml"; |
45 | 47 | ||
48 | + private static $wsInfoFile = "WS_info.json"; | ||
49 | + | ||
46 | private static $processMgrFile = "processManager.xml"; | 50 | private static $processMgrFile = "processManager.xml"; |
47 | 51 | ||
48 | private static $jobsMgrFile = "jobs.xml"; | 52 | private static $jobsMgrFile = "jobs.xml"; |
49 | 53 | ||
50 | private static $userParamMgrFile = "WsParams.xml"; | 54 | private static $userParamMgrFile = "WsParams.xml"; |
51 | 55 | ||
56 | + private static $userRequestMgrFile = "Request.xml"; | ||
57 | + | ||
52 | private static $userName; | 58 | private static $userName; |
53 | 59 | ||
54 | private static $userHost; | 60 | private static $userHost; |
@@ -97,6 +103,11 @@ class IHMConfigClass | @@ -97,6 +103,11 @@ class IHMConfigClass | ||
97 | return $userPath; | 103 | return $userPath; |
98 | } | 104 | } |
99 | 105 | ||
106 | + public static function getUserWSInfoFilePath() | ||
107 | + { | ||
108 | + return self::getUserPath().self::$wsInfoFile; | ||
109 | + } | ||
110 | + | ||
100 | public static function getProcessManagerFilePath() | 111 | public static function getProcessManagerFilePath() |
101 | { | 112 | { |
102 | return self::getDataDir().self::$processMgrFile; | 113 | return self::getDataDir().self::$processMgrFile; |
@@ -141,6 +152,11 @@ class IHMConfigClass | @@ -141,6 +152,11 @@ class IHMConfigClass | ||
141 | { | 152 | { |
142 | return self::getUserWSPath().self::$userParamMgrFile; | 153 | return self::getUserWSPath().self::$userParamMgrFile; |
143 | } | 154 | } |
155 | + | ||
156 | + public static function getUserRequestManagerFilePath() | ||
157 | + { | ||
158 | + return self::getUserWSPath().self::$userRequestMgrFile; | ||
159 | + } | ||
144 | 160 | ||
145 | public static function getUserDerivedParamFilePath($paramId) | 161 | public static function getUserDerivedParamFilePath($paramId) |
146 | { | 162 | { |
@@ -245,6 +261,16 @@ class IHMConfigClass | @@ -245,6 +261,16 @@ class IHMConfigClass | ||
245 | 261 | ||
246 | return $requestPath; | 262 | return $requestPath; |
247 | } | 263 | } |
264 | + | ||
265 | + public static function getStoredRequestPath() | ||
266 | + { | ||
267 | + $storedRequestPath = self::getUserPath().self::$storedRequestDir; | ||
268 | + | ||
269 | + if (!is_dir($storedRequestPath)) | ||
270 | + mkdir($storedRequestPath); | ||
271 | + | ||
272 | + return $storedRequestPath; | ||
273 | + } | ||
248 | 274 | ||
249 | public static function getRemoteDataPath() | 275 | public static function getRemoteDataPath() |
250 | { | 276 | { |
src/InputOutput/IHMImpl/IHMInputOutputClass.php
@@ -8,6 +8,7 @@ | @@ -8,6 +8,7 @@ | ||
8 | class IHMInputOutputClass implements InputOutputInterface | 8 | class IHMInputOutputClass implements InputOutputInterface |
9 | { | 9 | { |
10 | protected $inputOutput = null; | 10 | protected $inputOutput = null; |
11 | + protected $userWSMgr = null; | ||
11 | 12 | ||
12 | /* | 13 | /* |
13 | * @brief Constructor | 14 | * @brief Constructor |
@@ -16,6 +17,7 @@ class IHMInputOutputClass implements InputOutputInterface | @@ -16,6 +17,7 @@ class IHMInputOutputClass implements InputOutputInterface | ||
16 | { | 17 | { |
17 | IHMConfigClass::setUserName($userName); | 18 | IHMConfigClass::setUserName($userName); |
18 | IHMConfigClass::setUserHost($userHost); | 19 | IHMConfigClass::setUserHost($userHost); |
20 | + $this->userWSMgr = new IHMUserWSManagerClass(); | ||
19 | } | 21 | } |
20 | 22 | ||
21 | /* | 23 | /* |
@@ -23,10 +25,6 @@ class IHMInputOutputClass implements InputOutputInterface | @@ -23,10 +25,6 @@ class IHMInputOutputClass implements InputOutputInterface | ||
23 | */ | 25 | */ |
24 | public function getInputData($input,$function,$requestId = "") | 26 | public function getInputData($input,$function,$requestId = "") |
25 | { | 27 | { |
26 | - //check user workspace | ||
27 | - if (IHMConfigClass::getUserName() == "" || !is_dir(IHMConfigClass::getUserPath())) | ||
28 | - throw new Exception('Cannot find user workspace.'); | ||
29 | - | ||
30 | switch ($function) | 28 | switch ($function) |
31 | { | 29 | { |
32 | case FunctionTypeEnumClass::PARAMS : | 30 | case FunctionTypeEnumClass::PARAMS : |
@@ -102,6 +100,8 @@ class IHMInputOutputClass implements InputOutputInterface | @@ -102,6 +100,8 @@ class IHMInputOutputClass implements InputOutputInterface | ||
102 | case FunctionTypeEnumClass::PARAMINFO : | 100 | case FunctionTypeEnumClass::PARAMINFO : |
103 | $this->inputOutput = new IHMInputOutputParamInfoClass(); | 101 | $this->inputOutput = new IHMInputOutputParamInfoClass(); |
104 | break; | 102 | break; |
103 | + case FunctionTypeEnumClass::USERWSINIT : | ||
104 | + return $this->userWSMgr->init(); | ||
105 | default : | 105 | default : |
106 | throw new Exception('Request type '.$function.' not implemented for this client.'); | 106 | throw new Exception('Request type '.$function.' not implemented for this client.'); |
107 | } | 107 | } |
@@ -0,0 +1,138 @@ | @@ -0,0 +1,138 @@ | ||
1 | +<?php | ||
2 | + | ||
3 | +/** | ||
4 | + * @class IHMUserWSManagerClass | ||
5 | + * @brief Manager for IHM user workspace | ||
6 | + * @details | ||
7 | + */ | ||
8 | +class IHMUserWSManagerClass | ||
9 | +{ | ||
10 | + private static $WS_VERSION = 1; | ||
11 | + | ||
12 | + protected $wsInfo = null; | ||
13 | + | ||
14 | + public function init() | ||
15 | + { | ||
16 | + //check user workspace | ||
17 | + if (IHMConfigClass::getUserName() == "" || !is_dir(IHMConfigClass::getUserPath())) | ||
18 | + throw new Exception('Cannot find user workspace.'); | ||
19 | + | ||
20 | + //Load info about WS | ||
21 | + if (!$this->loadWSInfoFile()) | ||
22 | + throw new Exception('Error to load workspace info file.'); | ||
23 | + | ||
24 | + //Update WS if need | ||
25 | + if (!$this->update()) | ||
26 | + throw new Exception('Error during user workspace conversion.'); | ||
27 | + | ||
28 | + return TRUE; | ||
29 | + } | ||
30 | + | ||
31 | + public function update() | ||
32 | + { | ||
33 | + while (IHMUserWSManagerClass::$WS_VERSION > $this->wsInfo['version']) { | ||
34 | + $updateMethod = "updateFromVersion".$this->wsInfo['version']; | ||
35 | + if (method_exists($this,$updateMethod)) { | ||
36 | + if (!$this->{$updateMethod}()) { | ||
37 | + return FALSE; | ||
38 | + } | ||
39 | + } | ||
40 | + $this->wsInfo['version'] += 1; | ||
41 | + if (!$this->saveWSInfoFile()) { | ||
42 | + return FALSE; | ||
43 | + } | ||
44 | + } | ||
45 | + return TRUE; | ||
46 | + } | ||
47 | + | ||
48 | + private function loadWSInfoFile() | ||
49 | + { | ||
50 | + if (file_exists(IHMConfigClass::getUserWSInfoFilePath())) { | ||
51 | + $infoContent = file_get_contents(IHMConfigClass::getUserWSInfoFilePath()); | ||
52 | + if (empty($infoContent)) { | ||
53 | + return FALSE; | ||
54 | + } | ||
55 | + $this->wsInfo = json_decode($infoContent, TRUE); | ||
56 | + if (empty($this->wsInfo)) { | ||
57 | + return FALSE; | ||
58 | + } | ||
59 | + return TRUE; | ||
60 | + } | ||
61 | + | ||
62 | + //Init info file | ||
63 | + $this->wsInfo = array( | ||
64 | + "version" => 0, | ||
65 | + ); | ||
66 | + | ||
67 | + return $this->saveWSInfoFile(); | ||
68 | + } | ||
69 | + | ||
70 | + private function saveWSInfoFile() | ||
71 | + { | ||
72 | + if (empty($this->wsInfo)) { | ||
73 | + return FALSE; | ||
74 | + } | ||
75 | + | ||
76 | + $json_data = json_encode($this->wsInfo); | ||
77 | + | ||
78 | + if ($json_data === FALSE) { | ||
79 | + return FALSE; | ||
80 | + } | ||
81 | + | ||
82 | + | ||
83 | + return file_put_contents(IHMConfigClass::getUserWSInfoFilePath(),$json_data); | ||
84 | + } | ||
85 | + | ||
86 | + private function updateFromVersion0() { | ||
87 | + // This update split plot requests | ||
88 | + | ||
89 | + // Load user requests file | ||
90 | + $req_mgr_file_path = IHMConfigClass::getUserRequestManagerFilePath(); | ||
91 | + if (!file_exists($req_mgr_file_path)) { | ||
92 | + return TRUE; | ||
93 | + } | ||
94 | + | ||
95 | + $dom = new DOMDocument(); | ||
96 | + if (!$dom->load($req_mgr_file_path)) { | ||
97 | + return FALSE; | ||
98 | + } | ||
99 | + | ||
100 | + // Retrieve all plot requests and last request id | ||
101 | + $plot_requests = array(); | ||
102 | + $last_id = 0; | ||
103 | + foreach ($dom->getElementsByTagName('request') as $requestNode) { | ||
104 | + $request_id = $requestNode->getAttribute("xml:id"); | ||
105 | + $plot_requests[$request_id] = $requestNode; | ||
106 | + sscanf($request_id, "req_%d", $crt_id); | ||
107 | + if ($crt_id > $last_id) { | ||
108 | + $last_id = $crt_id; | ||
109 | + } | ||
110 | + } | ||
111 | + | ||
112 | + if (empty($plot_requests)) { | ||
113 | + //No plot requests | ||
114 | + return TRUE; | ||
115 | + } | ||
116 | + | ||
117 | + // Split requests | ||
118 | + foreach ($plot_requests as $id => $node) { | ||
119 | + $req_data_path = IHMConfigClass::getStoredRequestPath() . $id; | ||
120 | + if (!file_exists($req_data_path)) { | ||
121 | + continue; | ||
122 | + } | ||
123 | + $req_data_content = file_get_contents($req_data_path); | ||
124 | + if (!$req_data_content) { | ||
125 | + continue; | ||
126 | + } | ||
127 | + $req_data_json = json_decode($req_data_content); | ||
128 | + if (!$req_data_json) { | ||
129 | + continue; | ||
130 | + } | ||
131 | + // ToDo | ||
132 | + } | ||
133 | + | ||
134 | + | ||
135 | + return TRUE; | ||
136 | + } | ||
137 | +} | ||
138 | + |
@@ -0,0 +1,27 @@ | @@ -0,0 +1,27 @@ | ||
1 | +<?php | ||
2 | +/** | ||
3 | + * @class UserRequestClass | ||
4 | + * @brief Implementation of a RequestAbstractClass for a user request | ||
5 | + * @details | ||
6 | + */ | ||
7 | +class UserRequestClass extends RequestAbstractClass | ||
8 | +{ | ||
9 | + /* | ||
10 | + * @brief Init a user request | ||
11 | + */ | ||
12 | + public function init() | ||
13 | + { | ||
14 | + //For the moment, nothing to do | ||
15 | + return TRUE; | ||
16 | + } | ||
17 | + | ||
18 | + /* | ||
19 | + * @brief Run a user request | ||
20 | + */ | ||
21 | + public function run() | ||
22 | + { | ||
23 | + //For the moment, nothing to do | ||
24 | + return TRUE; | ||
25 | + } | ||
26 | +} | ||
27 | +?> |
src/RequestManagerClass.php
@@ -82,6 +82,8 @@ Class RequestManagerClass | @@ -82,6 +82,8 @@ Class RequestManagerClass | ||
82 | return new TTRequestClass($user, $userHost); | 82 | return new TTRequestClass($user, $userHost); |
83 | case FunctionTypeEnumClass::PARAMINFO : | 83 | case FunctionTypeEnumClass::PARAMINFO : |
84 | return new ParamInfoRequestClass($user, $userHost); | 84 | return new ParamInfoRequestClass($user, $userHost); |
85 | + case FunctionTypeEnumClass::USERWSINIT : | ||
86 | + return new UserRequestClass($user, $userHost); | ||
85 | default : | 87 | default : |
86 | throw new Exception('Request '.$function.' not implemented.'); | 88 | throw new Exception('Request '.$function.' not implemented.'); |
87 | } | 89 | } |