Skip to content

Commit

Permalink
Merge pull request #518 from tikoflano/run-job-virtualfull-improvements
Browse files Browse the repository at this point in the history
Improve the VirtualFull run job
  • Loading branch information
fbergkemper committed Jun 15, 2020
2 parents e487084 + 0a65641 commit a59af84
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 2 deletions.
8 changes: 7 additions & 1 deletion webui/module/Job/src/Job/Controller/JobController.php
Expand Up @@ -451,6 +451,11 @@ public function runAction()
$storages = $this->getStorageModel()->getStorages($this->bsock);
$pools = $this->getPoolModel()->getDotPools($this->bsock, null);

foreach($pools as &$pool) {
$nextpool = $this->getPoolModel()->getPoolNextPool($this->bsock, $pool["name"]);
$pool["nextpool"] = $nextpool;
}

// build form
$form = new RunJobForm($clients, $jobs, $filesets, $storages, $pools, $jobdefaults);

Expand All @@ -477,6 +482,7 @@ public function runAction()
$storage = $form->getInputFilter()->getValue('storage');
$pool = $form->getInputFilter()->getValue('pool');
$level = $form->getInputFilter()->getValue('level');
$nextpool = $form->getInputFilter()->getValue('nextpool');
$priority = $form->getInputFilter()->getValue('priority');
$backupformat = null; // $form->getInputFilter()->getValue('backupformat');
$when = $form->getInputFilter()->getValue('when');
Expand All @@ -495,7 +501,7 @@ public function runAction()
)
);
} else {
$result = $this->getJobModel()->runCustomJob($this->bsock, $jobname, $client, $fileset, $storage, $pool, $level, $priority, $backupformat, $when);
$result = $this->getJobModel()->runCustomJob($this->bsock, $jobname, $client, $fileset, $storage, $pool, $level, $nextpool, $priority, $backupformat, $when);
$this->bsock->disconnect();
$s = strrpos($result, "=") + 1;
$jobid = rtrim( substr( $result, $s ) );
Expand Down
55 changes: 55 additions & 0 deletions webui/module/Job/src/Job/Form/RunJobForm.php
Expand Up @@ -306,6 +306,41 @@ public function __construct($clients=null, $jobs=null, $filesets=null, $storages
));
}

// NextPool
if(isset($jobdefaults['pool'])) {
$this->add(array(
'name' => 'nextpool',
'type' => 'select',
'options' => array(
'label' => _('Next Pool'),
'empty_option' => '',
'value_options' => $this->getPoolList()
),
'attributes' => array(
'class' => 'form-control selectpicker show-tick',
'data-live-search' => 'true',
'id' => 'nextpool',
'value' => $this->getNextPool($jobdefaults['pool'])
)
));
} else {
$this->add(array(
'name' => 'nextpool',
'type' => 'select',
'options' => array(
'label' => _('Next Pool'),
'empty_option' => '',
'value_options' => $this->getPoolList()
),
'attributes' => array(
'class' => 'form-control selectpicker show-tick',
'data-live-search' => 'true',
'id' => 'nextpool',
'value' => null
)
));
}

/*
// Backup Format
$this->add(array(
Expand Down Expand Up @@ -418,4 +453,24 @@ private function getLevelList()
$selectData['VirtualFull'] = 'VirtualFull';
return $selectData;
}

private function getNextPool($pool_name)
{
foreach($this->pools as $pool) {
if($pool["name"] === $pool_name) {
return $pool["nextpool"];
}
}
}

public function getPoolNextPoolMapping()
{
$mapping = [];

foreach($this->pools as $pool) {
$mapping[$pool["name"]] = $pool["nextpool"];
}

return json_encode($mapping);
}
}
11 changes: 11 additions & 0 deletions webui/module/Job/src/Job/Model/Job.php
Expand Up @@ -143,6 +143,17 @@ public function getInputFilter()
)
));

$inputFilter->add(array(
'name' => 'nextpool',
'required' => false,
'filters' => array(
array('name' => 'StripTags'),
array('name' => 'StringTrim'),
),
'validators' => array(
)
));

$inputFilter->add(array(
'name' => 'priority',
'required' => false,
Expand Down
6 changes: 5 additions & 1 deletion webui/module/Job/src/Job/Model/JobModel.php
Expand Up @@ -466,13 +466,14 @@ public function getJobDefaults(&$bsock=null, $name=null)
* @param $storage
* @param $pool
* @param $level
* @param $nextpool
* @param $priority
* @param $backupformat
* @param $when
*
* @return string
*/
public function runCustomJob(&$bsock=null, $jobname=null, $client=null, $fileset=null, $storage=null, $pool=null, $level=null, $priority=null, $backupformat=null, $when=null)
public function runCustomJob(&$bsock=null, $jobname=null, $client=null, $fileset=null, $storage=null, $pool=null, $level=null, $nextpool=null, $priority=null, $backupformat=null, $when=null)
{
if(isset($bsock, $jobname)) {
$cmd = 'run job="' . $jobname . '"';
Expand All @@ -491,6 +492,9 @@ public function runCustomJob(&$bsock=null, $jobname=null, $client=null, $fileset
if(!empty($level)) {
$cmd .= ' level="' . $level . '"';
}
if(!empty($nextpool)) {
$cmd .= ' nextpool="' . $nextpool . '"';
}
if(!empty($priority)) {
$cmd .= ' priority="' . $priority . '"';
}
Expand Down
38 changes: 38 additions & 0 deletions webui/module/Job/view/job/job/run.phtml
Expand Up @@ -104,6 +104,13 @@ $this->headTitle($title);
</div>
</div>

<div class="form-group">
<label class="control-label col-md-2"><?php echo $this->formLabel($form->get('nextpool')); ?></label>
<div class="control-input col-md-6">
<?php echo $this->formSelect($form->get('nextpool')); ?>
</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">
Expand Down Expand Up @@ -162,6 +169,8 @@ $this->headTitle($title);

<script type="text/javascript">

let pool_nextpool_mapping = JSON.parse('<?php echo $form->getPoolNextPoolMapping(); ?>');

function updateQueryParams(k, v) {
var p = [];
var params = [];
Expand All @@ -177,15 +186,44 @@ $this->headTitle($title);
return params.join('&');
}

function hasNextPoolOption() {
return $('#level').selectpicker('val') == "VirtualFull" ||
$('#type').val() == "Copy" ||
$('#type').val() == "Migrate"
}

$('#job').change(function(event) {
window.location.href = window.location.pathname + '?' + updateQueryParams('jobname', this.value);
});

$('#pool').change(function(event) {
if(hasNextPoolOption()) {
let nextpool = pool_nextpool_mapping[$('#pool').selectpicker('val')];

if(nextpool) {
$('#nextpool').selectpicker('val', nextpool);
}
}
});

$('#level').change(function() {
if(hasNextPoolOption()) {
$("#nextpool").parents(".form-group").fadeIn();
$('#pool').change();
} else {
$("#nextpool").parents(".form-group").hide();
$('#nextpool').selectpicker('val', '');
}
});

$(function() {
$('#when-datepicker').datetimepicker({
format: 'YYYY-MM-DD HH:mm:ss',
sideBySide: true
});

// This will enable/disable the Next Pool select based on the Level value on load
$('#level').change();
});

</script>
23 changes: 23 additions & 0 deletions webui/module/Pool/src/Pool/Model/PoolModel.php
Expand Up @@ -132,4 +132,27 @@ public function getPoolMedia(&$bsock=null, $pool=null)
throw new \Exception('Missing argument.');
}
}

/**
* Get the NextPool value from a Pool model definition
*
* @param $bsock
* @param $pool
*
* @return array
*/
public function getPoolNextPool(&$bsock=null, $pool=null)
{
if(isset($bsock, $pool)) {
$cmd = 'show pool="'.$pool.'"';
$result = $bsock->send_command($cmd, 0);

$matches = [];
preg_match('/\s*Next\s*Pool\s*=\s*("|\')?(?<value>.*)(?(1)\1|)/i', $result, $matches);
return $matches["value"];
}
else {
throw new \Exception('Missing argument.');
}
}
}

0 comments on commit a59af84

Please sign in to comment.