Skip to content
This repository was archived by the owner on Sep 10, 2021. It is now read-only.

Commit e58a729

Browse files
author
Charles Ma
committed
ENH: refs #301 Fixed tests
1 parent 86f6349 commit e58a729

File tree

19 files changed

+138
-80
lines changed

19 files changed

+138
-80
lines changed

modules/remoteprocessing/controllers/ConfigController.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
11
<?php
2+
/*=========================================================================
3+
MIDAS Server
4+
Copyright (c) Kitware SAS. 20 rue de la Villette. All rights reserved.
5+
69328 Lyon, FRANCE.
26
7+
See Copyright.txt for details.
8+
This software is distributed WITHOUT ANY WARRANTY; without even
9+
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
10+
PURPOSE. See the above copyright notices for more information.
11+
=========================================================================*/
12+
13+
/** Config controller */
314
class Remoteprocessing_ConfigController extends Remoteprocessing_AppController
415
{
5-
public $_moduleForms=array('Config');
6-
public $_components=array('Utility', 'Date');
16+
public $_moduleForms = array('Config');
17+
public $_components = array('Utility', 'Date');
718

819
/** download remote script */
920
function downloadAction()
1021
{
11-
if(!$this->logged||!$this->userSession->Dao->getAdmin()==1)
22+
if(!$this->logged || !$this->userSession->Dao->getAdmin() == 1)
1223
{
1324
throw new Zend_Exception("You should be an administrator");
1425
}
@@ -39,7 +50,7 @@ function downloadAction()
3950
/** index action*/
4051
function indexAction()
4152
{
42-
if(!$this->logged||!$this->userSession->Dao->getAdmin()==1)
53+
if(!$this->logged || !$this->userSession->Dao->getAdmin() == 1)
4354
{
4455
throw new Zend_Exception("You should be an administrator");
4556
}
@@ -78,7 +89,7 @@ function indexAction()
7889
}
7990
if(file_exists(BASE_PATH."/core/configs/".$this->moduleName.".local.ini"))
8091
{
81-
rename(BASE_PATH."/core/configs/".$this->moduleName.".local.ini",BASE_PATH."/core/configs/".$this->moduleName.".local.ini.old");
92+
rename(BASE_PATH."/core/configs/".$this->moduleName.".local.ini", BASE_PATH."/core/configs/".$this->moduleName.".local.ini.old");
8293
}
8394
$applicationConfig['global']['securitykey'] = $this->_getParam('securitykey');
8495

modules/remoteprocessing/controllers/ExecutableController.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
<?php
2+
/*=========================================================================
3+
MIDAS Server
4+
Copyright (c) Kitware SAS. 20 rue de la Villette. All rights reserved.
5+
69328 Lyon, FRANCE.
26
7+
See Copyright.txt for details.
8+
This software is distributed WITHOUT ANY WARRANTY; without even
9+
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
10+
PURPOSE. See the above copyright notices for more information.
11+
=========================================================================*/
12+
/** Executable controller */
313
class Remoteprocessing_ExecutableController extends Remoteprocessing_AppController
414
{
515
public $_models = array('Item', 'Bitstream', 'ItemRevision', 'Assetstore');
@@ -41,7 +51,7 @@ function defineAction()
4151
$this->view->itemDao = $itemDao;
4252
$this->view->jsonMetadata = $jsonContents;
4353
$this->view->json['item'] = $itemDao->toArray();
44-
if($this->_request->isPost())
54+
if($this->_request->isPost())
4555
{
4656
$this->disableLayout();
4757
$this->disableView();
@@ -76,9 +86,8 @@ function defineAction()
7686
$bitstreamDao->setName('MetaIO.vxml');
7787
$bitstreamDao->setPath($pathFile);
7888
$bitstreamDao->fillPropertiesFromPath();
79-
$defaultAssetStoreId = Zend_Registry::get('configGlobal')->defaultassetstore->id;
80-
$bitstreamDao->setAssetstoreId($defaultAssetStoreId);
81-
$assetstoreDao = $this->Assetstore->load($defaultAssetStoreId);
89+
$assetstoreDao = $this->Assetstore->getDefault();
90+
$bitstreamDao->setAssetstoreId($assetstoreDao->getKey());
8291

8392
// Upload the bitstream if necessary (based on the assetstore type)
8493
$this->Component->Upload->uploadBitstream($bitstreamDao, $assetstoreDao);

modules/remoteprocessing/controllers/JobController.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
<?php
2+
/*=========================================================================
3+
MIDAS Server
4+
Copyright (c) Kitware SAS. 20 rue de la Villette. All rights reserved.
5+
69328 Lyon, FRANCE.
26
7+
See Copyright.txt for details.
8+
This software is distributed WITHOUT ANY WARRANTY; without even
9+
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
10+
PURPOSE. See the above copyright notices for more information.
11+
=========================================================================*/
12+
/** job controller*/
313
class Remoteprocessing_JobController extends Remoteprocessing_AppController
414
{
515
public $_models = array('Item', 'Bitstream', 'ItemRevision', 'Assetstore');
@@ -36,10 +46,9 @@ function manageAction()
3646
{
3747
$this->showNotificationMessage('The Job will appear in a next few minutes.');
3848
}
39-
4049
}
4150

42-
/** init a job */
51+
/** init a job */
4352
function initAction()
4453
{
4554
$this->view->header = $this->t("Job");
@@ -71,7 +80,7 @@ function initAction()
7180

7281
$this->view->itemDao = $itemDao;
7382
$this->view->json['item'] = $itemDao->toArray();
74-
if($this->_request->isPost())
83+
if($this->_request->isPost())
7584
{
7685
$this->disableLayout();
7786
$this->disableView();

modules/remoteprocessing/controllers/components/ApiComponent.php

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function registerserver($args)
4444
$securitykey = $args['securitykey'];
4545
}
4646

47-
$modulesConfig=Zend_Registry::get('configsModules');
47+
$modulesConfig = Zend_Registry::get('configsModules');
4848
$checkSecuritykey = $modulesConfig['remoteprocessing']->securitykey;
4949
if(empty($securitykey) || $securitykey != $checkSecuritykey)
5050
{
@@ -68,7 +68,12 @@ public function registerserver($args)
6868
$userModel->save($userDao);
6969
$serverGroup = $groupModel->load(MIDAS_GROUP_SERVER_KEY);
7070
$groupModel->addUser($serverGroup, $userDao);
71-
$userapiDao = $Api_UserapiModel->createKey($userDao, 'remoteprocessing', '100');
71+
72+
$userapiDao = $Api_UserapiModel->getByAppAndUser('remoteprocessing', $userDao);
73+
if($userapiDao == false)
74+
{
75+
$userapiDao = $Api_UserapiModel->createKey($userDao, 'remoteprocessing', '100');
76+
}
7277

7378
$apikey = $userapiDao->getApikey();
7479

@@ -185,7 +190,7 @@ public function keepaliveserver($args)
185190
public function resultsserver($args)
186191
{
187192
$testingmode = false;
188-
if($_GET['testingmode'] == 1)
193+
if(isset($_GET['testingmode']) && $_GET['testingmode'] == 1)
189194
{
190195
$testingmode = true;
191196
}
@@ -247,7 +252,7 @@ public function resultsserver($args)
247252
if(file_exists($destionation."/results.zip"))
248253
{
249254
mkdir($destionation.'/content');
250-
$target_directory= $destionation.'/content';
255+
$target_directory = $destionation.'/content';
251256
$filter = new Zend_Filter_Decompress(array(
252257
'adapter' => 'Zip',
253258
'options' => array(
@@ -278,13 +283,13 @@ public function resultsserver($args)
278283
{
279284
throw new Exception('Error, unable to find results.', MIDAS_INVALID_PARAMETER);
280285
}
281-
//$this->rrmdir($destionation);
286+
$this->_rrmdir($destionation);
282287
return array();
283288
}
284289

285290

286-
/** recursively delete a folder*/
287-
private function rrmdir($dir)
291+
/** recursively delete a folder*/
292+
private function _rrmdir($dir)
288293
{
289294
if(is_dir($dir))
290295
{
@@ -297,17 +302,17 @@ private function rrmdir($dir)
297302
{
298303
if(filetype($dir."/".$object) == "dir")
299304
{
300-
$this->rrmdir($dir."/".$object);
305+
$this->_rrmdir($dir."/".$object);
301306
}
302307
else
303308
{
304309
unlink($dir."/".$object);
305310
}
306311
}
307312
}
308-
reset($objects);
309-
rmdir($dir);
310-
}
313+
reset($objects);
314+
rmdir($dir);
315+
}
311316

312317
} // end class
313318

modules/remoteprocessing/controllers/components/ExecutableComponent.php

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ function initAndSchedule($itemDao, $xmlMeta, $javascriptResults)
151151
$script .= "import subprocess\n";
152152
foreach($commandMatrix as $key => $commandList)
153153
{
154-
$script .= "print 'Matrix Element ".$key."'\n";
155154
$command = $executable->getName().' '. join('', $commandList);
156155
if($key == 1)
157156
{
@@ -164,10 +163,16 @@ function initAndSchedule($itemDao, $xmlMeta, $javascriptResults)
164163

165164
$script .= "process = subprocess.Popen('".$command."', shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)\n";
166165
$script .= "process.wait()\n";
167-
$script .= "print process.stdout.readline()\n";
168-
$script .= "print process.stderr.readline()\n";
166+
$script .= "returnArray = process.communicate()\n";
167+
$script .= "print '-COMMAND'\n";
168+
$script .= "print '".$command."'\n";
169+
$script .= "print '-STDOUT'\n";
170+
$script .= "print returnArray[0]\n";
171+
$script .= "print '-STDERR'\n";
172+
$script .= "print returnArray[1]\n";
169173
}
170174

175+
171176
$tmpOutputArray = $ouputArray;
172177
foreach($tmpOutputArray as $ouput)
173178
{
@@ -178,7 +183,7 @@ function initAndSchedule($itemDao, $xmlMeta, $javascriptResults)
178183
}
179184
}
180185

181-
$parameters = $jobComponent->initJobParameters('CALLBACK_REMOTEPROCESSING_EXECUTABLE_RESULTS', $inputArray, $ouputArray , $additionalParams);
186+
$parameters = $jobComponent->initJobParameters('CALLBACK_REMOTEPROCESSING_EXECUTABLE_RESULTS', $inputArray, $ouputArray, $additionalParams);
182187

183188
$ext = end(explode('.', $executable->getName()));
184189
if($ext == 'exe')
@@ -239,7 +244,7 @@ private function _createParametersMatrix($cmdOptions)
239244
}
240245
$matrix[$i][$key] = $tmpvalue;
241246
}
242-
if(count($values) >1)
247+
if(count($values) > 1)
243248
{
244249
$multipleElement = $multipleElement * count($values);
245250
}
@@ -265,59 +270,59 @@ function createDefinitionFile($elements)
265270
{
266271
$element = explode(';', $r);
267272
$option = $xml->addChild('option');
268-
$option->addChild('number',htmlspecialchars(utf8_encode($i)));
269-
$option->addChild('name',htmlspecialchars(utf8_encode($element[0])));
270-
$option->addChild('tag',htmlspecialchars(utf8_encode($element[5])));
271-
$option->addChild('longtag',htmlspecialchars(utf8_encode('')));
272-
$option->addChild('description',htmlspecialchars(utf8_encode('')));
273+
$option->addChild('number', htmlspecialchars(utf8_encode($i)));
274+
$option->addChild('name', htmlspecialchars(utf8_encode($element[0])));
275+
$option->addChild('tag', htmlspecialchars(utf8_encode($element[5])));
276+
$option->addChild('longtag', htmlspecialchars(utf8_encode('')));
277+
$option->addChild('description', htmlspecialchars(utf8_encode('')));
273278
if($element[4] == 'True')
274279
{
275-
$option->addChild('required',htmlspecialchars(utf8_encode(1)));
280+
$option->addChild('required', htmlspecialchars(utf8_encode(1)));
276281
}
277282
else
278283
{
279-
$option->addChild('required',htmlspecialchars(utf8_encode(0)));
284+
$option->addChild('required', htmlspecialchars(utf8_encode(0)));
280285
}
281286

282287
if($element[1] == 'ouputFile')
283288
{
284-
$option->addChild('channel',htmlspecialchars(utf8_encode('ouput')));
289+
$option->addChild('channel', htmlspecialchars(utf8_encode('ouput')));
285290
}
286291
else
287292
{
288-
$option->addChild('channel',htmlspecialchars(utf8_encode('input')));
293+
$option->addChild('channel', htmlspecialchars(utf8_encode('input')));
289294
}
290295

291-
$option->addChild('nvalues',htmlspecialchars(utf8_encode(1)));
296+
$option->addChild('nvalues', htmlspecialchars(utf8_encode(1)));
292297

293298
$field = $option->addChild('field');
294-
$field->addChild('name',htmlspecialchars(utf8_encode($element[0])));
295-
$field->addChild('description',htmlspecialchars(utf8_encode('')));
299+
$field->addChild('name', htmlspecialchars(utf8_encode($element[0])));
300+
$field->addChild('description', htmlspecialchars(utf8_encode('')));
296301

297302
if($element[1] == 'inputParam')
298303
{
299-
$field->addChild('type',htmlspecialchars(utf8_encode($element[2])));
304+
$field->addChild('type', htmlspecialchars(utf8_encode($element[2])));
300305
}
301306
else
302307
{
303-
$field->addChild('type',htmlspecialchars(utf8_encode('string')));
308+
$field->addChild('type', htmlspecialchars(utf8_encode('string')));
304309
}
305-
$field->addChild('value',htmlspecialchars(utf8_encode('')));
310+
$field->addChild('value', htmlspecialchars(utf8_encode('')));
306311
if($element[4] == 'True')
307312
{
308-
$field->addChild('required',htmlspecialchars(utf8_encode(1)));
313+
$field->addChild('required', htmlspecialchars(utf8_encode(1)));
309314
}
310315
else
311316
{
312-
$field->addChild('required',htmlspecialchars(utf8_encode(0)));
317+
$field->addChild('required', htmlspecialchars(utf8_encode(0)));
313318
}
314319
if($element[1] == 'inputParam')
315320
{
316-
$field->addChild('external',htmlspecialchars(utf8_encode(0)));
321+
$field->addChild('external', htmlspecialchars(utf8_encode(0)));
317322
}
318323
else
319324
{
320-
$field->addChild('external',htmlspecialchars(utf8_encode(1)));
325+
$field->addChild('external', htmlspecialchars(utf8_encode(1)));
321326
}
322327
}
323328
$xml = $xml->asXML();

modules/remoteprocessing/controllers/components/JobComponent.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function initJobParameters($resultCallback, $inputArray = array(), $ouput
2828
{
2929
throw new Zend_Exception("Unable to find callback ".$resultCallback);
3030
}
31-
if(!is_array($inputArray) || !is_array($ouputArray) ||!is_array($additionalParams))
31+
if(!is_array($inputArray) || !is_array($ouputArray) || !is_array($additionalParams))
3232
{
3333
throw new Zend_Exception("Error params");
3434
}
@@ -76,7 +76,7 @@ public function scheduleJob($parameters, $script, $os = MIDAS_REMOTEPROCESSING_O
7676
$scheduleParams['fire_time'] = $fire_time;
7777
}
7878

79-
if(!$only_once && $time_interval !==false)
79+
if(!$only_once && $time_interval !== false)
8080
{
8181
$scheduleParams['run_only_once'] = false;
8282
$scheduleParams['time_interval'] = $time_interval;

modules/remoteprocessing/controllers/forms/ConfigForm.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
11
<?php
2+
/*=========================================================================
3+
MIDAS Server
4+
Copyright (c) Kitware SAS. 20 rue de la Villette. All rights reserved.
5+
69328 Lyon, FRANCE.
6+
7+
See Copyright.txt for details.
8+
This software is distributed WITHOUT ANY WARRANTY; without even
9+
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
10+
PURPOSE. See the above copyright notices for more information.
11+
=========================================================================*/
12+
/** form*/
213
class Remoteprocessing_ConfigForm extends AppForm
314
{
415

@@ -19,5 +30,4 @@ public function createConfigForm()
1930
return $form;
2031
}
2132

22-
} // end class
23-
?>
33+
} // end class

0 commit comments

Comments
 (0)