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

Commit

Permalink
ENH: refs #301 Added autogenerated name
Browse files Browse the repository at this point in the history
Fixed wizard style
Added my jobs page
Added jobs name
  • Loading branch information
Charles Ma committed Nov 11, 2011
1 parent c668b0c commit 3974ef3
Show file tree
Hide file tree
Showing 23 changed files with 310 additions and 121 deletions.
4 changes: 2 additions & 2 deletions core/public/css/jquery/jquery.smartWizard-2.0.css
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
border: 0px solid #CCC;
overflow:hidden;
clear:right;
height:400px;
height:500px;
}

.swMain .stepContainer div.content {
Expand All @@ -39,7 +39,7 @@
font: normal 12px Verdana, Arial, Helvetica, sans-serif;
color:#5A5655;
background-color:#F8F8F8;
height:450px;
height:500px;
text-align:left;
overflow:auto;
z-index:88;
Expand Down
2 changes: 1 addition & 1 deletion core/views/item/view.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ if($this->preview) // module visualize
</li>
<li>
<a href='javascript:;' type='item' element='{$this->itemDao->getKey()}' class='sharingLink' ><img alt='' src='{$this->coreWebroot}/public/images/icons/share.png'/> {$this->t('Permissions')}</a>
</li>
</li>
<li>
<a href='javascript:;' type='item' element='{$this->itemDao->getKey()}' class='uploadRevisionLink' ><img alt='' src='{$this->coreWebroot}/public/images/icons/upload.png'/> {$this->t('Upload new revision')}</a>
</li>
Expand Down
17 changes: 14 additions & 3 deletions modules/remoteprocessing/Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function getActionMenu($params)
<a href='".Zend_Registry::get('webroot')."/remoteprocessing/executable/define/?itemId=".$params['item']->getKey()."'><img alt='' src='".Zend_Registry::get('coreWebroot')."/public/images/icons/xml.png'/> ".$this->t('Define Executable')."</a>
</li>
<li>
<a href='".Zend_Registry::get('webroot')."/remoteprocessing/job/manage/?itemId=".$params['item']->getKey()."'><img alt='' src='".Zend_Registry::get('coreWebroot')."/public/images/icons/job.png'/> ".$this->t('Manage Processing Jobs')."</a>
<a href='".Zend_Registry::get('webroot')."/remoteprocessing/job/init/?itemId=".$params['item']->getKey()."'><img alt='' src='".Zend_Registry::get('coreWebroot')."/public/images/icons/job.png'/> ".$this->t('Create a Job')."</a>
</li> ";
return $html;
}
Expand Down Expand Up @@ -143,8 +143,13 @@ public function getItemInfo($params)
$i = 0;
foreach($jobs as $job)
{
$name = $job->getName();
if(empty($name))
{
$name = $job->getCreationDate();
}
$html .= "<li>";
$html .= "<a element='".$job->getKey()."' href='".Zend_Registry::get('webroot')."/remoteprocessing/job/view/?jobId=".$job->getKey()."'>".$job->getCreationDate()."</a>";
$html .= "<a element='".$job->getKey()."' href='".Zend_Registry::get('webroot')."/remoteprocessing/job/view/?jobId=".$job->getKey()."'>".$name."</a>";
$html .= "</li>";
if($i > 3)
{
Expand Down Expand Up @@ -187,9 +192,11 @@ public function processProcessingResults($params)
if(file_exists($filepath))
{
$tmpArray = array_reverse(explode('.', basename($filepath)));
$oldfilepath = $filepath;
$filepath = str_replace(".".$tmpArray[1].".", ".", $filepath);
rename($oldfilepath, $filepath);
$item = $uploadComponent->createUploadedItem($userDao, basename($filepath), $filepath, $folder);
$jobModel->addItemRelation($job, $item, MIDAS_REMOTEPROCESSING_RELATION_TYPE_OUPUT);

// add parameter metadata
if(is_numeric($tmpArray[1]) && isset($params['parametersList']) && isset($params['optionMatrix']))
{
Expand Down Expand Up @@ -269,6 +276,10 @@ public function addJob($params)
{
$job->setCreatorId($params['params']['creator_id']);
}
if(isset($params['params']['job_name']))
{
$job->setName($params['params']['job_name']);
}

$job->setParams(JsonComponent::encode($params['params']));
$this->Remoteprocessing_Job->save($job);
Expand Down
40 changes: 13 additions & 27 deletions modules/remoteprocessing/controllers/JobController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,17 @@ class Remoteprocessing_JobController extends Remoteprocessing_AppController
/** manage jobs */
function manageAction()
{
$itemId = $this->_getParam("itemId");
if(!isset($itemId) || !is_numeric($itemId))
{
throw new Zend_Exception("itemId should be a number");
}

$itemDao = $this->Item->load($itemId);
if($itemDao === false)
{
throw new Zend_Exception("This item doesn't exist.");
}
if(!$this->Item->policyCheck($itemDao, $this->userSession->Dao, MIDAS_POLICY_WRITE))
if(!$this->logged)
{
throw new Zend_Exception("Problem policies.");
$this->haveToBeLogged();
return false;
}
$this->view->header = $this->t("Manage Jobs: ".$itemDao->getName());
$metaFile = $this->ModuleComponent->Executable->getMetaIoFile($itemDao);
$this->view->metaFile = $metaFile;
$this->view->itemDao = $itemDao;

$this->view->relatedJobs = $this->Remoteprocessing_Job->getRelatedJob($itemDao);
$this->view->header = $this->t("Manage Your Jobs");

if(isset($_GET['inprogress']))
{
$this->showNotificationMessage('The Job will appear in a next few minutes.');
}
$modelLoad = new MIDAS_ModelLoader();
$schedulerJobModel = $modelLoad->loadModel('Job', 'scheduler');
$this->view->scheduledJobs = $schedulerJobModel->getJobsByTaskAndCreator('TASK_REMOTEPROCESSING_ADD_JOB', $this->userSession->Dao);
$this->view->relatedJobs = $this->Remoteprocessing_Job->getByUser($this->userSession->Dao, 10);
}

/** init a job*/
Expand Down Expand Up @@ -128,7 +113,7 @@ function initAction()
}
else if($option->field->external == 1)
{
$parametersList[$i] = $option->name;
$parametersList[$i] = (string)$option->name;
if(strpos($result, 'folder') !== false)
{
$folder = $this->Folder->load(str_replace('folder', '', $result));
Expand All @@ -151,7 +136,7 @@ function initAction()
}
else
{
$parametersList[$i] = $option->name;
$parametersList[$i] = (string)$option->name;
$cmdOptions[$i] = array('type' => 'param', 'values' => array());
if(strpos($result, ';') !== false)
{
Expand Down Expand Up @@ -184,7 +169,7 @@ function initAction()

if(!empty($option->tag))
{
$cmdOptions[$i]['tag'] = $option->tag;
$cmdOptions[$i]['tag'] = (string)$option->tag;
}
}
$i++;
Expand All @@ -204,7 +189,7 @@ function initAction()
}
}

$this->ModuleComponent->Executable->initAndSchedule($this->userSession->Dao, $itemDao, $cmdOptions, $parametersList, $fire_time, $time_interval, $only_once);
$this->ModuleComponent->Executable->initAndSchedule($this->userSession->Dao, $itemDao, $_POST['name'], $cmdOptions, $parametersList, $fire_time, $time_interval, $only_once);
}
}

Expand Down Expand Up @@ -264,6 +249,7 @@ function viewAction()
}

$this->view->job = $jobDao;
$this->view->header = $this->t("Job: ".$jobDao->getName());
$items = $jobDao->getItems();
$inputs = array();
$outputs = array();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function getExecutable($itemDao)
}

/** schedule Job (create script and set parameters).*/
function initAndSchedule($userDao, $executableItemDao, $cmdOptions, $parametersList, $fire_time = false, $time_interval = false, $only_once = true)
function initAndSchedule($userDao, $executableItemDao, $jobName, $cmdOptions, $parametersList, $fire_time = false, $time_interval = false, $only_once = true)
{
$componentLoader = new MIDAS_ComponentLoader();
$modelLoader = new MIDAS_ModelLoader();
Expand All @@ -73,6 +73,7 @@ function initAndSchedule($userDao, $executableItemDao, $cmdOptions, $parametersL

$parameters['cmdOptions'] = $cmdOptions;
$parameters['creator_id'] = $userDao->getKey();
$parameters['job_name'] = $jobName;
$parameters['parametersList'] = $parametersList;
$parameters['executable'] = $executableItemDao->getKey();

Expand Down Expand Up @@ -130,7 +131,7 @@ public function processScheduledJobParameters($params)
}

$commandMatrix = $this->_createParametersMatrix($cmdOptions);
$tmp = $this->_createScript($commandMatrix, $executable, $ouputArray);
$tmp = $this->_createScript($params['params']['parametersList'], $commandMatrix, $executable, $ouputArray);

$ouputArray = $tmp['outputArray'];
$script = $tmp['script'];
Expand All @@ -142,20 +143,25 @@ public function processScheduledJobParameters($params)
}

/** create Script */
private function _createScript($commandMatrix, $executable, $ouputArray)
private function _createScript($parametersList, $commandMatrix, $executable, $ouputArray)
{
$script = "#! /usr/bin/python\n";
$script .= "import subprocess\n";
$script .= "import time\n";
foreach($commandMatrix as $key => $commandList)
{
$command = $executable->getName().' '. join('', $commandList);
$command = str_replace('{{key}}', '.'.$key, $command);
$command = str_replace('{{key}}', '.'.$this->_generateSuffixOutputName($commandList, $parametersList).'.'.$key, $command);

$script .= "start = time.clock()\n";
$script .= "process = subprocess.Popen('".$command."', shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)\n";
$script .= "process.wait()\n";
$script .= "returnArray = process.communicate()\n";
$script .= "end = time.clock()\n";
$script .= "print '-COMMAND'\n";
$script .= "print '".$command."'\n";
$script .= "print '-EXECUTION TIME'\n";
$script .= "print '%.2gs' % (end-start)\n";
$script .= "print '-STDOUT'\n";
$script .= "print returnArray[0]\n";
$script .= "print '-STDERR'\n";
Expand All @@ -169,11 +175,28 @@ private function _createScript($commandMatrix, $executable, $ouputArray)
$ext = end(explode('.', $ouput));
foreach($commandMatrix as $key => $commandList)
{
$ouputArray[] = str_replace('.'.$ext, '.'.$key.'.'.$ext, $ouput);
$ouputArray[] = str_replace('.'.$ext, '.'.$this->_generateSuffixOutputName($commandList, $parametersList).'.'.$key.'.'.$ext, $ouput);
}
}
return array('script' => $script, 'outputArray' => $ouputArray);
}

/** generate suffix output name */
private function _generateSuffixOutputName($commandList, $parametersList)
{
$return = "";
foreach($commandList as $key => $command)
{
if(isset($parametersList[$key]) && !empty($parametersList[$key]))
{
$return = $return.substr($parametersList[$key], 0, 6)."-";
$command = str_replace('"', '', $command);
$command = (string)str_replace(' ', '', $command);
$return = $return.$command."_";
}
}
return substr($return,0,-1);
}
/** create cmd option matrix*/
private function _createParametersMatrix($cmdOptions)
{
Expand Down
35 changes: 35 additions & 0 deletions modules/remoteprocessing/database/upgrade/1.0.2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
/*=========================================================================
MIDAS Server
Copyright (c) Kitware SAS. 20 rue de la Villette. All rights reserved.
69328 Lyon, FRANCE.
See Copyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/

class Remoteprocessing_Upgrade_1_0_2 extends MIDASUpgrade
{
public function preUpgrade()
{

}

public function mysql()
{
$sql = "ALTER TABLE remoteprocessing_job ADD name varchar(512)";
$this->db->query($sql);
}

public function pgsql()
{

}

public function postUpgrade()
{
}
}
?>
1 change: 1 addition & 0 deletions modules/remoteprocessing/models/base/JobModelBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public function __construct()
'condition' => array('type' => MIDAS_DATA),
'script' => array('type' => MIDAS_DATA),
'params' => array('type' => MIDAS_DATA),
'name' => array('type' => MIDAS_DATA),
'status' => array('type' => MIDAS_DATA),
'creator_id' => array('type' => MIDAS_DATA),
'expiration_date' => array('type' => MIDAS_DATA),
Expand Down
29 changes: 29 additions & 0 deletions modules/remoteprocessing/models/pdo/JobModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,33 @@ function getRelatedJob($item)
}
return $return;
}

/** get job by user */
function getByUser($user, $limit = 10)
{
if(!$user instanceof UserDao)
{
throw new Zend_Exception("Should be an user.");
}

$sql = $this->database->select()
->from('remoteprocessing_job')
->setIntegrityCheck(false)
->where('creator_id = ?', $user->getKey())
->limit($limit)
->order('job_id DESC');

$rowset = $this->database->fetchAll($sql);
$return = array();
foreach($rowset as $row)
{
$tmpDao = $this->load($row['job_id']);
if($tmpDao != false)
{
$return[] = $tmpDao;
unset($tmpDao);
}
}
return $return;
}
} // end class
22 changes: 20 additions & 2 deletions modules/remoteprocessing/public/css/job/job.init.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.optionWrapper{
.optionWrapper, .nameWrapper{
border: 1px solid grey;
margin-bottom: 2px;

Expand All @@ -12,7 +12,7 @@
-moz-box-shadow: 0px 0px 5px #666;
padding: 0px 5px 6px 5px;
}
.optionWrapper h4{
.optionWrapper h4, .nameWrapper h4{
margin-bottom: 0px;
margin-top: 2px;
font-size: 14px;
Expand Down Expand Up @@ -43,4 +43,22 @@ background: #F8F8F8!important;

#wizard{
display:none;
}

#uploadTabs{
width: 571px!important;
}

#browseExecutableFile a img{
position:relative;
top:2px;
margin-right: 2px;
}

#metaWrapper{
display:none;
}

#metaWrapper .viewMain{
width: 95%!important;
}
8 changes: 2 additions & 6 deletions modules/remoteprocessing/public/css/job/job.manage.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
#tableJobsList{
width: 80%;
}

#tableJobsList td{
border-bottom: 1px solid grey;
.midasTree td{
cursor: pointer!important;
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
else
{
$( "div.MainDialog" ).dialog("close");
$('#metaWrapper').hide();
$('#metaPageBlock').html('');
isExecutableMeta = true;
}
}
Expand Down
Loading

0 comments on commit 3974ef3

Please sign in to comment.