- Timestamp:
- 06/10/10 15:45:20 (11 years ago)
- Location:
- trunk/server/www/app
- Files:
-
- 1 added
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/server/www/app/app_controller.php
r367 r372 72 72 if ($this->AuthCert->user()) { 73 73 $bottomControllers[__('Requests', true)] = '/requests'; 74 75 if ($this->__permitted('jobs', 'search')) { 76 $bottomControllers[__('Jobs', true)] = '/jobs/search'; 77 } 78 74 79 $bottomControllers[__('Your account', true)] = '/users/view'; 75 80 } -
trunk/server/www/app/config/sql/default-data.sql
r362 r372 242 242 ('49b108a9-404c-4f19-80ac-1c6ac0a80105', 'workers:edit', '2009-03-06 12:27:37', '2009-03-06 12:27:37', '49b10879-6cf8-410e-bbe6-1c6ac0a80105'), 243 243 ('49b108af-acdc-4365-892e-1c6ac0a80105', 'workers:delete', '2009-03-06 12:27:43', '2009-03-06 12:27:43', '49b10879-6cf8-410e-bbe6-1c6ac0a80105'), 244 ('49b108b5-9294-4acf-9a89-1c6ac0a80105', 'xmlrpc:api', '2009-03-06 12:27:49', '2009-03-06 12:27:49', '49b10879-6cf8-410e-bbe6-1c6ac0a80105'); 244 ('49b108b5-9294-4acf-9a89-1c6ac0a80105', 'xmlrpc:api', '2009-03-06 12:27:49', '2009-03-06 12:27:49', '49b10879-6cf8-410e-bbe6-1c6ac0a80105') 245 ('4c10ed1d-3bf8-4d9e-aca8-33abc0a80105', 'jobs:view', '2010-06-10 12:27:49', '2010-06-10 12:27:49', '49b10879-6cf8-410e-bbe6-1c6ac0a80105'), 246 ('4c10ecfb-5044-46a9-b5a6-33abc0a80105', 'jobs:search', '2010-06-10 12:27:49', '2010-06-10 12:27:49', '49b10879-6cf8-410e-bbe6-1c6ac0a80105'), 247 ('4c10ed07-4110-4ae5-9840-33abc0a80105', 'jobs:fail', '2010-06-10 12:27:49', '2010-06-10 12:27:49', '49b10879-6cf8-410e-bbe6-1c6ac0a80105'), 248 ('4c10ed15-6404-49bc-ae5c-33abc0a80105', 'jobs:requeue', '2010-06-10 12:27:49', '2010-06-10 12:27:49', '49b10879-6cf8-410e-bbe6-1c6ac0a80105'); 245 249 246 250 -- -
trunk/server/www/app/config/sql/schema.php
r330 r372 1 1 <?php 2 2 /* SVN FILE: $Id$ */ 3 /* App schema generated on: 2010-0 3-24 14:03:22 : 1269436882*/3 /* App schema generated on: 2010-06-08 12:06:45 : 1275992085*/ 4 4 class AppSchema extends CakeSchema { 5 5 var $name = 'App'; … … 110 110 'result_id' => array('type' => 'string', 'null' => false, 'default' => NULL, 'length' => 36), 111 111 'factory_id' => array('type' => 'string', 'null' => false, 'default' => NULL, 'length' => 36), 112 'state' => array('type' => 'integer', 'null' => false, 'default' => '1'), 112 113 'locked' => array('type' => 'datetime', 'null' => false, 'default' => '0000-00-00 00:00:00'), 113 114 'created' => array('type' => 'datetime', 'null' => true, 'default' => NULL), -
trunk/server/www/app/controllers/jobs_controller.php
r367 r372 172 172 } 173 173 174 $this->set('job', $job); 174 $inTestsuite = $this->Job->Request->inTestsuite($job['Request']['id']); 175 $this->set(compact('job', 'inTestsuite')); 176 } 177 178 /** 179 * Manually change a job's state 180 */ 181 private function _setState($state, $id = null) 182 { 183 if (!$id) { 184 $this->Session->setFlash(__('Invalid Job.', true)); 185 $this->redirect(array('controller' => 'requests', 'action'=>'index')); 186 } 187 188 $this->Job->contain(array('Request')); 189 $job = $this->Job->read(null, $id); 190 191 if (!$this->Job->Request->inTestsuite($job['Request']['id'])) { 192 $this->Session->setFlash(__('Invalid Job.', true)); 193 $this->redirect(array('controller' => 'requests', 'action'=>'index')); 194 } 195 196 $this->Job->id = $id; 197 $this->Job->saveField('state', $state); 198 $this->redirect(array('action' => 'view', $id)); 199 } 200 201 /** 202 * Manually mark job as failed 203 */ 204 public function fail($id = null) 205 { 206 $this->_setState(Job::STATE_FAILED, $id); 207 } 208 209 /** 210 * Manually mark job as failed 211 */ 212 public function requeue($id = null) 213 { 214 $this->_setState(Job::STATE_QUEUED, $id); 175 215 } 176 216 … … 240 280 $this->Job->delete(); 241 281 $this->redirect(array('controller' => 'requests', 'action'=>'view', $job['Request']['id'])); 282 } 283 284 /** 285 * Search for a given Job ID 286 * This allows factory owners to mark problematic jobs in a test suite as invalid 287 */ 288 public function search() 289 { 290 if (!empty($this->data)) { 291 $job = $this->Job->find('first', array( 292 'conditions' => array('Job.id' => $this->data['Job']['id']), 293 'recursive' => -1, 294 )); 295 296 if ($job) { 297 $this->redirect(array('action' => 'view', $job['Job']['id'])); 298 } 299 300 $this->Session->setFlash(__('That Job ID does not exist.', true)); 301 } 242 302 } 243 303 … … 425 485 LEFT JOIN `doctypes` AS `Doctype` on (`Mimetype`.`doctype_id` = `Doctype`.`id`) 426 486 WHERE `Job`.`result_id` = '' 487 AND `Job`.`state` = " . Job::STATE_QUEUED . " 427 488 AND `Job`.`locked` < '" . date('Y-m-d H:i:s') . "' 428 489 AND `Job`.`platform_id` = '" . $factory['Operatingsystem']['platform_id'] . "' … … 431 492 AND `Job`.`format_id` IN (" . implode(', ', $formats) . ") 432 493 AND `Request`.`state` = " . Request::STATE_QUEUED . " 433 AND (`Request`.`expire` > '" . date('Y-m-d H:i:s') . "' OR `Request`.`expire` IS NULL)434 494 AND `Mimetype`.`doctype_id` IN (" . implode(', ', $doctypes) . ") 435 495 AND (`Request`.`own_factory` = 0 … … 456 516 // Something went wrong. Expire the entire request 457 517 $this->Request->saveField('expire', date('Y-m-d H:i:s', time() -1)); 518 $this->Request->expire(); 519 458 520 return array('faultCode' => 2, 'faultString' => 'Job document could not be read. Please poll again.'); 459 521 } -
trunk/server/www/app/models/job.php
r295 r372 27 27 class Job extends AppModel 28 28 { 29 /**#@+ 30 * Job model states 31 */ 32 const STATE_QUEUED = 1; 33 const STATE_FINISHED = 2; 34 const STATE_FAILED = 4; 35 /**#@-*/ 36 29 37 /** 30 38 * @var array All jobs belong to a request and factory and are associated with a certain application and platform -
trunk/server/www/app/models/request.php
r367 r372 124 124 125 125 /** 126 * Check if the request belongs to a test suite 127 * @param The request ID, or NULL for $this->id 128 * @return Boolean 129 */ 130 public function inTestsuite($id = null) 131 { 132 if (!$id) { 133 $id = $this->id; 134 } 135 136 if (!$id) { 137 return false; 138 } 139 140 $request = $this->find('first', array( 141 'contain' => array('Gallery'), 142 'conditions' => array('Request.id' => $id), 143 )); 144 145 if (isset($request['Gallery']) && !empty($request['Gallery'])) { 146 foreach ($request['Gallery'] as $gallery) { 147 if ($this->Gallery->isTestsuite($gallery['id'])) { 148 return true; 149 } 150 } 151 } 152 153 return false; 154 } 155 156 /** 126 157 * Add an upload to the request 127 158 * … … 272 303 'expire' => date('Y-m-d H:i:s', time() - 1) 273 304 ))); 305 306 $this->failJobs(); 274 307 } 275 308 … … 281 314 public function expireAll() 282 315 { 283 return $this->updateAll( 284 array('Request.state' => self::STATE_EXPIRED), 285 array( 316 // Mark all old requests as expired 317 318 $requests = $this->find('all', array( 319 'conditions' => array( 286 320 'Request.expire <=' => date('Y-m-d H:i:s'), 287 'Request.state' => array(self::STATE_UPLOADING, self::STATE_PREPROCESSOR_QUEUED, self::STATE_QUEUED) 288 ) 289 ); 321 'Request.state' => array(self::STATE_UPLOADING, self::STATE_PREPROCESSOR_QUEUED, self::STATE_QUEUED), 322 'NOT' => array('Request.expire' => null), 323 ), 324 'recursive' => -1, 325 )); 326 327 foreach ($requests as $request) { 328 $this->id = $request['Request']['id']; 329 $this->expire(); 330 } 331 332 return true; 333 } 334 335 /** 336 * Expire a single request 337 */ 338 public function expire() 339 { 340 $this->saveField('state', self::STATE_EXPIRED); 341 $this->failJobs(); 290 342 } 291 343 … … 314 366 foreach ($request['Job'] as $job) { 315 367 $this->Job->delete($job['id']); // Results are deleted in Job::beforeDelete 368 } 369 } 370 371 /** 372 * Mark all unfinished jobs for this request as failed 373 */ 374 public function failJobs($id = null) 375 { 376 if (!$id) { 377 $id = $this->id; 378 } 379 380 if (!$id) { 381 return; 382 } 383 384 $request = $this->find('first', array( 385 'contain' => array('Job'), 386 'conditions' => array('Request.id' => $id), 387 )); 388 389 if (!$request || !isset($request['Job']) || empty($request['Job'])) { 390 return; 391 } 392 393 foreach ($request['Job'] as $job) { 394 if ($job['state'] == Job::STATE_QUEUED) { 395 $this->Job->id = $job['id']; 396 $this->Job->saveField('state', Job::STATE_FAILED); 397 } 316 398 } 317 399 } -
trunk/server/www/app/vendors/shells/upgrade.php
r329 r372 27 27 { 28 28 /** @var array The models to use */ 29 public $uses = array('Request', 'Result', 'User', 'Group', 'Worker' );29 public $uses = array('Request', 'Result', 'User', 'Group', 'Worker', 'Job'); 30 30 31 31 /** … … 227 227 'worker_id' => $worker['Worker']['id'], 228 228 ))); 229 } 230 } 231 } 232 233 /** 234 * Upgrade the state of jobs 235 */ 236 public function jobState() 237 { 238 $jobs = $this->Job->find('all', array( 239 'contain' => array('Request', 'Result'), 240 )); 241 242 foreach ($jobs as $job) { 243 $this->Job->id = $job['Job']['id']; 244 245 if (isset($job['Result']) && isset($job['Result']['id']) && !empty($job['Result']['id'])) { 246 $this->Job->saveField('state', Job::STATE_FINISHED); 247 } else { 248 $failed = ( 249 isset($job['Request']) && isset($job['Request']['state']) 250 && $job['Request']['state'] != Request::STATE_UPLOADING 251 && $job['Request']['state'] != Request::STATE_PREPROCESSOR_QUEUED 252 && $job['Request']['state'] != Request::STATE_QUEUED 253 ); 254 255 if ($failed) { 256 $this->Job->saveField('state', Job::STATE_FAILED); 257 } 229 258 } 230 259 } … … 248 277 $this->out("\n\tfilesystemLayout\n\t\tUpdate the layour of requests on the filesystem."); 249 278 $this->out("\n\tworkerDoctypes\n\t\tAssign the correct doctypes to all workers."); 279 $this->out("\n\tjobState\n\t\tSet the correct state flag on all jobs."); 250 280 $this->out("\n\thelp\n\t\tShow this help"); 251 281 $this->out(''); -
trunk/server/www/app/views/elements/gallery.ctp
r298 r372 56 56 </td> 57 57 <td><?php echo isset($job['Result']['created']) ? $job['Result']['created'] : $job['created']; ?></td> 58 <td><?php echo $jobModel->getState($job , $request['state']); ?></td>58 <td><?php echo $jobModel->getState($job); ?></td> 59 59 <?php if ($access):?> 60 60 <td class="actions"> </td> -
trunk/server/www/app/views/helpers/job_model.php
r297 r372 19 19 */ 20 20 21 App::import('Model', 'Job'); 22 21 23 /** 22 24 * A helper to assist in outputting Jobs … … 30 32 * Return the description of a Job 31 33 */ 32 public function getDescription($job , $request_state)34 public function getDescription($job) 33 35 { 34 36 if (!isset($job['Job'])) { … … 40 42 } 41 43 42 return $this->getState($job , $request_state);44 return $this->getState($job); 43 45 } 44 46 … … 46 48 * Return the state of a job 47 49 */ 48 public function getState($job , $request_state)50 public function getState($job) 49 51 { 50 52 if (!isset($job['Job'])) { … … 52 54 } 53 55 54 if ( !empty($job['Job']['Result']) && !empty($job['Job']['Result']['id'])) {56 if ($job['Job']['state'] == Job::STATE_FINISHED) { 55 57 return $this->output(__('Finished', true)); 56 58 } 57 59 58 if ($ request_state & (Request::STATE_UPLOADING | Request::STATE_PREPROCESSOR_QUEUED | Request::STATE_QUEUED)) {60 if ($job['Job']['state'] == Job::STATE_QUEUED) { 59 61 if ($job['Job']['locked'] == '0000-00-00 00:00:00') { 60 62 return $this->output(__('Queued')); 61 63 } 62 64 63 if (empty($job['Job']['Result'])) { 64 return $this->output(__('Processing')); 65 } 65 return $this->output(__('Processing')); 66 66 } 67 67 … … 72 72 * Return the icon of a Job 73 73 */ 74 public function getIcon($job , $request_state)74 public function getIcon($job) 75 75 { 76 76 if (!isset($job['Job'])) { … … 78 78 } 79 79 80 if ( !empty($job['Job']['Result'])) {80 if ($job['Job']['state'] == Job::STATE_FINISHED) { 81 81 if ($job['Job']['Result']['state'] == Result::STATE_SCAN_FOUND) { 82 82 $icon = 'virus.png'; … … 91 91 } 92 92 93 if ($ request_state & (Request::STATE_UPLOADING | Request::STATE_PREPROCESSOR_QUEUED | Request::STATE_QUEUED)) {93 if ($job['Job']['state'] == Job::STATE_QUEUED) { 94 94 if ($job['Job']['locked'] == '0000-00-00 00:00:00') { 95 95 return $this->output($this->Html->image('icons/queued.png', array('alt' => __('Queued', true)))); 96 96 } 97 97 98 if (empty($job['Job']['Result'])) { 99 return $this->output($this->Html->image('icons/busy.png', array('alt' => __('Processing', true)))); 100 } 98 return $this->output($this->Html->image('icons/busy.png', array('alt' => __('Processing', true)))); 101 99 } 102 100 -
trunk/server/www/app/views/jobs/admin_index.ctp
r369 r372 40 40 </td> 41 41 <td> 42 <?php echo $jobModel->getState($job , $job['Request']['state']); ?><br />42 <?php echo $jobModel->getState($job); ?><br /> 43 43 </td> 44 44 <td class="actions"> -
trunk/server/www/app/views/jobs/view.ctp
r128 r372 1 1 <div class="jobs view"> 2 <h2><?php __('Job');?></h2> 3 <dl><?php $i = 0; $class = ' class="altrow"';?> 4 <dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Id'); ?></dt> 5 <dd<?php if ($i++ % 2 == 0) echo $class;?>> 2 <h2><?php echo $job['Application']['name'];?> <?php echo $job['Job']['version'];?> (<?php echo $job['Platform']['name'];?>)</h2> 3 <span><?php printf(__('For %s', true), $html->link( 4 $job['Request']['filename'], 5 array( 6 'controller' => 'requests', 7 'action' => 'view', 8 $job['Request']['id'] 9 ) 10 ));?></span><br /><br /> 11 <dl> 12 <dt><?php __('Id'); ?></dt> 13 <dd> 6 14 <?php echo $job['Job']['id']; ?> 7 15 8 16 </dd> 9 <dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Request'); ?></dt> 10 <dd<?php if ($i++ % 2 == 0) echo $class;?>> 11 <?php echo $html->link($job['Request']['filename'], array('controller'=> 'requests', 'action'=>'view', $job['Request']['id'])); ?> 12 13 </dd> 14 <dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Platform'); ?></dt> 15 <dd<?php if ($i++ % 2 == 0) echo $class;?>> 16 <?php echo $html->link($job['Platform']['name'], array('controller'=> 'platforms', 'action'=>'view', $job['Platform']['id'])); ?> 17 18 </dd> 19 <dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Application'); ?></dt> 20 <dd<?php if ($i++ % 2 == 0) echo $class;?>> 21 <?php echo $html->link($job['Application']['name'], array('controller'=> 'applications', 'action'=>'view', $job['Application']['id'])); ?> 22 23 </dd> 24 <dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Version'); ?></dt> 25 <dd<?php if ($i++ % 2 == 0) echo $class;?>> 26 <?php echo $job['Job']['version']; ?> 27 28 </dd> 29 <dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Result'); ?></dt> 30 <dd<?php if ($i++ % 2 == 0) echo $class;?>> 31 <?php echo $html->link($job['Result']['filename'], array('controller'=> 'results', 'action'=>'view', $job['Result']['id'])); ?> 32 33 </dd> 34 <dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Factory'); ?></dt> 35 <dd<?php if ($i++ % 2 == 0) echo $class;?>> 36 <?php echo $html->link($job['Factory']['name'], array('controller'=> 'factories', 'action'=>'view', $job['Factory']['id'])); ?> 37 38 </dd> 39 <dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Locked'); ?></dt> 40 <dd<?php if ($i++ % 2 == 0) echo $class;?>> 41 <?php echo $job['Job']['locked']; ?> 42 43 </dd> 44 <dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Created'); ?></dt> 45 <dd<?php if ($i++ % 2 == 0) echo $class;?>> 17 <?php if ($job['Factory']['id']):?> 18 <dt><?php __('Factory'); ?></dt> 19 <dd> 20 <?php echo $html->link($job['Factory']['name'], array('controller'=> 'factories', 'action'=>'view', $job['Factory']['id'])); ?> 21 22 </dd> 23 <dt><?php __('Locked'); ?></dt> 24 <dd> 25 <?php echo $job['Job']['locked']; ?> 26 27 </dd> 28 <?php endif;?> 29 <dt><?php __('Created'); ?></dt> 30 <dd> 46 31 <?php echo $job['Job']['created']; ?> 47 32 48 33 </dd> 49 <dt <?php if ($i % 2 == 0) echo $class;?>><?php __('Updated'); ?></dt>50 <dd <?php if ($i++ % 2 == 0) echo $class;?>>51 <?php echo $job ['Job']['updated']; ?>34 <dt><?php __('State'); ?></dt> 35 <dd> 36 <?php echo $jobModel->getState($job); ?> 52 37 38 </dd> 39 <dt><?php __('Actions'); ?></dt> 40 <dd> 41 <?php 42 if ($inTestsuite && $job['Job']['state'] == Job::STATE_QUEUED) { 43 echo $html->link(__('Set as failed', true), array('action' => 'fail', $job['Job']['id'])); 44 } 45 if ($inTestsuite && $job['Job']['state'] == Job::STATE_FAILED) { 46 echo $html->link(__('Re-queue', true), array('action' => 'requeue', $job['Job']['id'])); 47 } 48 ?> 53 49 </dd> 54 50 </dl> 55 51 </div> 56 57 <div class="related">58 <h3><?php __('Related Results');?></h3>59 <?php if (!empty($job['Result'])):?>60 <table cellpadding = "0" cellspacing = "0">61 <tr>62 <th><?php __('Id'); ?></th>63 <th><?php __('Factory Id'); ?></th>64 <th><?php __('Filename'); ?></th>65 <th><?php __('Path'); ?></th>66 <th><?php __('Mimetype'); ?></th>67 <th><?php __('Created'); ?></th>68 <th><?php __('Updated'); ?></th>69 <th class="actions"><?php __('Actions');?></th>70 </tr>71 <tr>72 <td><?php echo $job['Result']['id'];?></td>73 <td><?php echo $job['Result']['factory_id'];?></td>74 <td><?php echo $job['Result']['filename'];?></td>75 <td><?php echo $job['Result']['path'];?></td>76 <td><?php echo $job['Result']['mimetype'];?></td>77 <td><?php echo $job['Result']['created'];?></td>78 <td><?php echo $job['Result']['updated'];?></td>79 <td class="actions">80 <?php echo $html->link(__('View', true), array('controller'=> 'results', 'action'=>'view', $job['Result']['id'])); ?>81 <?php echo $html->link(__('Edit', true), array('controller'=> 'results', 'action'=>'edit', $job['Result']['id'])); ?>82 <?php echo $html->link(__('Delete', true), array('controller'=> 'results', 'action'=>'delete', $job['Result']['id']), null, sprintf(__('Are you sure you want to delete # %s?', true), $job['Result']['id'])); ?>83 </td>84 </tr>85 </table>86 <?php endif; ?> -
trunk/server/www/app/views/requests/admin_view.ctp
r367 r372 98 98 </td> 99 99 <td> 100 <?php echo $jobModel->getState($job , $request['Request']['state']); ?><br />100 <?php echo $jobModel->getState($job); ?><br /> 101 101 </td> 102 102 <td> -
trunk/server/www/app/views/requests/view.ctp
r334 r372 105 105 </td> 106 106 <td> 107 <?php echo $jobModel->getState($job , $request['Request']['state']); ?><br />107 <?php echo $jobModel->getState($job); ?><br /> 108 108 </td> 109 109 <td>
Note: See TracChangeset
for help on using the changeset viewer.