diff options
author | Frank Bergkemper <frank.bergkemper@bareos.com> | 2017-10-16 16:56:09 +0300 |
---|---|---|
committer | Frank Bergkemper <frank.bergkemper@bareos.com> | 2017-10-16 16:56:09 +0300 |
commit | 0f1d99fc6fe04be0efb871138eb34cc31a92aae2 (patch) | |
tree | ccd59c2faaa5e077e090a40ab59358e628fab7aa | |
parent | e1118ea676b008313b1d6b8bebf2c7e5358bede1 (diff) |
Jobs: Improve run jobs sub-module
-rw-r--r-- | module/Job/src/Job/Controller/JobController.php | 25 | ||||
-rw-r--r-- | module/Job/src/Job/Form/RunJobForm.php | 329 | ||||
-rw-r--r-- | module/Job/src/Job/Model/JobModel.php | 21 | ||||
-rw-r--r-- | module/Job/view/job/job/run.phtml | 28 |
4 files changed, 308 insertions, 95 deletions
diff --git a/module/Job/src/Job/Controller/JobController.php b/module/Job/src/Job/Controller/JobController.php index 9c1a250..24c936e 100644 --- a/module/Job/src/Job/Controller/JobController.php +++ b/module/Job/src/Job/Controller/JobController.php @@ -298,15 +298,34 @@ class JobController extends AbstractActionController $this->bsock = $this->getServiceLocator()->get('director'); + // Get query parameter jobname + $jobname = $this->params()->fromQuery('jobname') ? $this->params()->fromQuery('jobname') : null; + + if ($jobname != null) { + $jobdefaults = $this->getJobModel()->getJobDefaults($this->bsock, $jobname); + } + // Get required form construction data, jobs, clients, etc. $clients = $this->getClientModel()->getClients($this->bsock); - $jobs = $this->getJobModel()->getJobsByType($this->bsock, null); - $filesets = $this->getFilesetModel()->getFilesets($this->bsock); + + // Get the different kind of jobs and merge them. Jobs of the following types + // cannot nor wanted to be run. M,V,R,U,I,C and S. + $job_type_B = $this->getJobModel()->getJobsByType($this->bsock, "B"); // Backup Job + $job_type_D = $this->getJobModel()->getJobsByType($this->bsock, 'D'); // Admin Job + $job_type_A = $this->getJobModel()->getJobsByType($this->bsock, 'A'); // Archive Job + $job_type_c = $this->getJobModel()->getJobsByType($this->bsock, 'c'); // Copy Job + $job_type_g = $this->getJobModel()->getJobsByType($this->bsock, 'g'); // Migration Job + $job_type_O = $this->getJobModel()->getJobsByType($this->bsock, 'O'); // Always Incremental Consolidate Job + $job_type_V = $this->getJobModel()->getJobsByType($this->bsock, 'V'); // Verify Job + + $jobs = array_merge($job_type_B, $job_type_D, $job_type_A, $job_type_c, $job_type_g, $job_type_O, $job_type_V); + + $filesets = $this->getFilesetModel()->getDotFilesets($this->bsock); $storages = $this->getStorageModel()->getStorages($this->bsock); $pools = $this->getPoolModel()->getDotPools($this->bsock, null); // build form - $form = new RunJobForm($clients, $jobs, $filesets, $storages, $pools); + $form = new RunJobForm($clients, $jobs, $filesets, $storages, $pools, $jobdefaults); // Set the method attribute for the form $form->setAttribute('method', 'post'); diff --git a/module/Job/src/Job/Form/RunJobForm.php b/module/Job/src/Job/Form/RunJobForm.php index 715a7f0..0ab5083 100644 --- a/module/Job/src/Job/Form/RunJobForm.php +++ b/module/Job/src/Job/Form/RunJobForm.php @@ -34,8 +34,9 @@ class RunJobForm extends Form protected $jobs; protected $storages; protected $pools; + protected $jobdefaults; - public function __construct($clients=null, $jobs=null, $filesets=null, $storages=null, $pools=null) + public function __construct($clients=null, $jobs=null, $filesets=null, $storages=null, $pools=null, $jobdefaults=null) { parent::__construct('runjob'); @@ -44,108 +45,218 @@ class RunJobForm extends Form $this->filesets = $filesets; $this->storages = $storages; $this->pools = $pools; + $this->jobdefaults = $jobdefaults; // Client - $this->add(array( - 'name' => 'client', - 'type' => 'select', - 'options' => array( - 'label' => _('Client'), - 'empty_option' => '', - 'value_options' => $this->getClientList() - ), - 'attributes' => array( - 'class' => 'form-control selectpicker show-tick', - 'data-live-search' => 'true', - 'id' => 'client', - 'value' => null - ) - )); + if(isset($jobdefaults['client'])) { + $this->add(array( + 'name' => 'client', + 'type' => 'select', + 'options' => array( + 'label' => _('Client'), + 'empty_option' => '', + 'value_options' => $this->getClientList() + ), + 'attributes' => array( + 'class' => 'form-control selectpicker show-tick', + 'data-live-search' => 'true', + 'id' => 'client', + 'value' => $jobdefaults['client'] + ) + )); + } + else { + $this->add(array( + 'name' => 'client', + 'type' => 'select', + 'options' => array( + 'label' => _('Client'), + 'empty_option' => '', + 'value_options' => $this->getClientList() + ), + 'attributes' => array( + 'class' => 'form-control selectpicker show-tick', + 'data-live-search' => 'true', + 'id' => 'client', + 'value' => null + ) + )); + } // Job - $this->add(array( - 'name' => 'job', - 'type' => 'select', - 'options' => array( - 'label' => _('Job'), - 'empty_option' => '', - 'value_options' => $this->getJobList() - ), - 'attributes' => array( - 'class' => 'form-control selectpicker show-tick', - 'data-live-search' => 'true', - 'id' => 'job', - 'value' => null - ) - )); + if(isset($jobdefaults['job'])) { + $this->add(array( + 'name' => 'job', + 'type' => 'select', + 'options' => array( + 'label' => _('Job'), + 'empty_option' => '', + 'value_options' => $this->getJobList() + ), + 'attributes' => array( + 'class' => 'form-control selectpicker show-tick', + 'data-live-search' => 'true', + 'id' => 'job', + 'value' => $jobdefaults['job'] + ) + )); + } else { + $this->add(array( + 'name' => 'job', + 'type' => 'select', + 'options' => array( + 'label' => _('Job'), + 'empty_option' => '', + 'value_options' => $this->getJobList() + ), + 'attributes' => array( + 'class' => 'form-control selectpicker show-tick', + 'data-live-search' => 'true', + 'id' => 'job', + 'value' => null + ) + )); + } // Fileset - $this->add(array( - 'name' => 'fileset', - 'type' => 'select', - 'options' => array( - 'label' => _('Fileset'), - 'empty_option' => '', - 'value_options' => $this->getFilesetList() - ), - 'attributes' => array( - 'class' => 'form-control selectpicker show-tick', - 'data-live-search' => 'true', - 'id' => 'fileset', - 'value' => null - ) - )); + if(isset($jobdefaults['fileset'])) { + $this->add(array( + 'name' => 'fileset', + 'type' => 'select', + 'options' => array( + 'label' => _('Fileset'), + 'empty_option' => '', + 'value_options' => $this->getFilesetList() + ), + 'attributes' => array( + 'class' => 'form-control selectpicker show-tick', + 'data-live-search' => 'true', + 'id' => 'fileset', + 'value' => $jobdefaults['fileset'] + ) + )); + } else { + $this->add(array( + 'name' => 'fileset', + 'type' => 'select', + 'options' => array( + 'label' => _('Fileset'), + 'empty_option' => '', + 'value_options' => $this->getFilesetList() + ), + 'attributes' => array( + 'class' => 'form-control selectpicker show-tick', + 'data-live-search' => 'true', + 'id' => 'fileset', + 'value' => null + ) + )); + } // Storage - $this->add(array( - 'name' => 'storage', - 'type' => 'select', - 'options' => array( - 'label' => _('Storage'), - 'empty_option' => '', - 'value_options' => $this->getStorageList() - ), - 'attributes' => array( - 'class' => 'form-control selectpicker show-tick', - 'data-live-search' => 'true', - 'id' => 'storage', - 'value' => null - ) - )); + if(isset($jobdefaults['storage'])) { + $this->add(array( + 'name' => 'storage', + 'type' => 'select', + 'options' => array( + 'label' => _('Storage'), + 'empty_option' => '', + 'value_options' => $this->getStorageList() + ), + 'attributes' => array( + 'class' => 'form-control selectpicker show-tick', + 'data-live-search' => 'true', + 'id' => 'storage', + 'value' => $jobdefaults['storage'] + ) + )); + } else { + $this->add(array( + 'name' => 'storage', + 'type' => 'select', + 'options' => array( + 'label' => _('Storage'), + 'empty_option' => '', + 'value_options' => $this->getStorageList() + ), + 'attributes' => array( + 'class' => 'form-control selectpicker show-tick', + 'data-live-search' => 'true', + 'id' => 'storage', + 'value' => null + ) + )); + } // Pool - $this->add(array( - 'name' => 'pool', - 'type' => 'select', - 'options' => array( - 'label' => _('Pool'), - 'empty_option' => '', - 'value_options' => $this->getPoolList() - ), - 'attributes' => array( - 'class' => 'form-control selectpicker show-tick', - 'data-live-search' => 'true', - 'id' => 'pool', - 'value' => null - ) - )); + if(isset($jobdefaults['pool'])) { + $this->add(array( + 'name' => 'pool', + 'type' => 'select', + 'options' => array( + 'label' => _('Pool'), + 'empty_option' => '', + 'value_options' => $this->getPoolList() + ), + 'attributes' => array( + 'class' => 'form-control selectpicker show-tick', + 'data-live-search' => 'true', + 'id' => 'pool', + 'value' => $jobdefaults['pool'] + ) + )); + } else { + $this->add(array( + 'name' => 'pool', + 'type' => 'select', + 'options' => array( + 'label' => _('Pool'), + 'empty_option' => '', + 'value_options' => $this->getPoolList() + ), + 'attributes' => array( + 'class' => 'form-control selectpicker show-tick', + 'data-live-search' => 'true', + 'id' => 'pool', + 'value' => null + ) + )); + } // Level - $this->add(array( - 'name' => 'level', - 'type' => 'select', - 'options' => array( - 'label' => _('Level'), - 'empty_option' => '', - 'value_options' => $this->getLevelList() - ), - 'attributes' => array( - 'class' => 'form-control selectpicker show-tick', - 'data-live-search' => 'true', - 'id' => 'level', - 'value' => null - ) - )); + if(isset($jobdefaults['level'])) { + $this->add(array( + 'name' => 'level', + 'type' => 'select', + 'options' => array( + 'label' => _('Level'), + 'empty_option' => '', + 'value_options' => $this->getLevelList() + ), + 'attributes' => array( + 'class' => 'form-control selectpicker show-tick', + 'data-live-search' => 'true', + 'id' => 'level', + 'value' => $jobdefaults['level'] + ) + )); + } else { + $this->add(array( + 'name' => 'level', + 'type' => 'select', + 'options' => array( + 'label' => _('Level'), + 'empty_option' => '', + 'value_options' => $this->getLevelList() + ), + 'attributes' => array( + 'class' => 'form-control selectpicker show-tick', + 'data-live-search' => 'true', + 'id' => 'level', + 'value' => null + ) + )); + } // Priority $this->add(array( @@ -161,6 +272,40 @@ class RunJobForm extends Form ) )); + // Type + if(isset($jobdefaults['type'])) { + $this->add(array( + 'name' => 'type', + 'type' => 'Zend\Form\Element\Text', + 'options' => array( + 'label' => _('Type'), + 'empty_option' => '', + ), + 'attributes' => array( + 'class' => 'form-control', + 'id' => 'type', + 'value' => $jobdefaults['type'], + 'readonly' => true + ) + )); + } + else { + $this->add(array( + 'name' => 'type', + 'type' => 'Zend\Form\Element\Text', + 'options' => array( + 'label' => _('Type'), + 'empty_option' => '', + ), + 'attributes' => array( + 'class' => 'form-control', + 'id' => 'type', + 'value' => null, + 'readonly' => true + ) + )); + } + /* // Backup Format $this->add(array( @@ -233,7 +378,7 @@ class RunJobForm extends Form $selectData = array(); if(!empty($this->filesets)) { foreach($this->filesets as $fileset) { - $selectData[$fileset['fileset']] = $fileset['fileset']; + $selectData[$fileset['name']] = $fileset['name']; } } ksort($selectData); diff --git a/module/Job/src/Job/Model/JobModel.php b/module/Job/src/Job/Model/JobModel.php index 04b600f..47e95d2 100644 --- a/module/Job/src/Job/Model/JobModel.php +++ b/module/Job/src/Job/Model/JobModel.php @@ -419,6 +419,27 @@ class JobModel } /** + * Get job defaults + * + * @param $bsock + * @param $name + * + * @return array + */ + public function getJobDefaults(&$bsock=null, $name=null) + { + if(isset($bsock, $name)) { + $cmd = '.defaults job="'.$name.'"'; + $result = $bsock->send_command($cmd, 2, null); + $jobdefaults = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY); + return $jobdefaults['result']['defaults']; + } + else { + throw new \Exception('Missing argument.'); + } + } + + /** * Run a custom job * * @param $bsock diff --git a/module/Job/view/job/job/run.phtml b/module/Job/view/job/job/run.phtml index 96bd29d..78ef915 100644 --- a/module/Job/view/job/job/run.phtml +++ b/module/Job/view/job/job/run.phtml @@ -98,6 +98,13 @@ $this->headTitle($title); </div> <div class="form-group"> + <label class="control-label col-md-2"><?php echo $this->formLabel($form->get('type')); ?></label> + <div class="control-input col-md-6"> + <?php echo $this->formInput($form->get('type')); ?> + </div> + </div> + + <div class="form-group"> <label class="control-label col-md-2"><?php echo $this->formLabel($form->get('priority')); ?></label> <div class="control-input col-md-6"> <?php echo $this->formInput($form->get('priority')); ?> @@ -154,10 +161,31 @@ $this->headTitle($title); <?php endif; ?> <script type="text/javascript"> + + function updateQueryParams(k, v) { + var p = []; + var params = []; + + p['jobname'] = '<?php echo $this->jobname; ?>'; + + p[k] = v; + + for(key in p) { + params.push(key + "=" + p[key]); + } + + return params.join('&'); + } + + $('#job').change(function(event) { + window.location.href = window.location.pathname + '?' + updateQueryParams('jobname', this.value); + }); + $(function() { $('#when-datepicker').datetimepicker({ format: 'YYYY-MM-DD HH:mm:ss', sideBySide: true }); }); + </script> |