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

Commit

Permalink
Update - Rerun or Cancel Jobs
Browse files Browse the repository at this point in the history
Rerun or cancel jobs from dashboard and job module, but there are still some
things which needs to be done to cancel waiting jobs.
  • Loading branch information
fbergkemper committed Feb 11, 2014
1 parent 941c163 commit 56110a1
Show file tree
Hide file tree
Showing 10 changed files with 173 additions and 12 deletions.
12 changes: 6 additions & 6 deletions module/Dashboard/view/dashboard/dashboard/index.phtml
Expand Up @@ -107,9 +107,9 @@ $flash->setMessageOpenFormat('
<span class="sr-only">Toggle Dropdown</span>
</button>
<ul class="dropdown-menu" role="menu">
<li><a href="<?php echo $this->url('log', array('action' => 'job', 'id' => $item->jobid)); ?>" title="<?php echo $this->translate("View logs"); ?>"><span class="glyphicon glyphicon-file"> View messages</a></li>
<li><a href="<?php echo $this->url('log', array('action' => 'job', 'id' => $item->jobid)); ?>" title="<?php echo $this->translate("View logs"); ?>"><span class="glyphicon glyphicon-file"></span> View messages</a></li>
<li class="divider"></li>
<li><a href="<?php ?>" title="<?php echo $this->translate("Cancel"); ?>"><span class="glyphicon glyphicon-trash"></span> Cancel job</a></li>
<li><a href="<?php echo $this->url('job', array('action' => 'cancel', 'id' => $item->jobid)); ?>" title="<?php echo $this->translate("Cancel"); ?>"><span class="glyphicon glyphicon-trash"></span> Cancel job</a></li>
</ul>
</div>

Expand Down Expand Up @@ -186,9 +186,9 @@ $flash->setMessageOpenFormat('
<span class="sr-only">Toggle Dropdown</span>
</button>
<ul class="dropdown-menu" role="menu">
<li><a href="<?php echo $this->url('log', array('action' => 'job', 'id' => $item->jobid)); ?>" title="<?php echo $this->translate("View logs"); ?>"><span class="glyphicon glyphicon-file"> View messages</a></li>
<li><a href="<?php echo $this->url('log', array('action' => 'job', 'id' => $item->jobid)); ?>" title="<?php echo $this->translate("View logs"); ?>"><span class="glyphicon glyphicon-file"></span> View messages</a></li>
<li class="divider"></li>
<li><a href="<?php ?>" title="<?php echo $this->translate("Cancel"); ?>"><span class="glyphicon glyphicon-trash"></span> Cancel job</a></li>
<li><a href="<?php echo $this->url('job', array('action' => 'cancel', 'id' => $item->jobid)); ?>" title="<?php echo $this->translate("Cancel"); ?>"><span class="glyphicon glyphicon-trash"></span> Cancel job</a></li>
<ul>
</div>

Expand Down Expand Up @@ -273,7 +273,7 @@ $flash->setMessageOpenFormat('
<ul class="dropdown-menu" role="menu">
<li><a href="<?php echo $this->url('log', array('action' => 'job', 'id' => $jobUnsuccess->jobid)); ?>" title="<?php echo $this->translate("View logs"); ?>"><span class="glyphicon glyphicon-file"></span> View messages</a></li>
<li class="divider"></li>
<li><a href="<?php ?>" title="<?php echo $this->translate("Rerun"); ?>"><span class="glyphicon glyphicon-repeat"></span> Re-run job</a></li>
<li><a href="<?php echo $this->url('job', array('action' => 'rerun', 'id' => $jobUnsuccess->jobid)); ?>" title="<?php echo $this->translate("Rerun"); ?>"><span class="glyphicon glyphicon-repeat"></span> Re-run job</a></li>
</ul>
</div>
<?php endif; ?>
Expand Down Expand Up @@ -362,7 +362,7 @@ $flash->setMessageOpenFormat('
<ul class="dropdown-menu" role="menu">
<li><a href="<?php echo $this->url('log', array('action' => 'job', 'id' => $jobSuccess->jobid));?>" title="<?php echo $this->translate("View messages"); ?>"><span class="glyphicon glyphicon-file"></span> View messages</a></li>
<li class="divider"></li>
<li><a href="<?php ?>" title="<?php echo $this->translate("Rerun"); ?>"><span class="glyphicon glyphicon-repeat"></span> Re-run job</a></li>
<li><a href="<?php echo $this->url('job', array('action' => 'rerun', 'id' => $jobSuccess->jobid)); ?>" title="<?php echo $this->translate("Rerun"); ?>"><span class="glyphicon glyphicon-repeat"></span> Re-run job</a></li>
<li><a href="<?php ?>" title="<?php echo $this->translate("Restore"); ?>"><span class="glyphicon glyphicon-import"></span> Restore job</a></li>
</ul>
</div>
Expand Down
1 change: 1 addition & 0 deletions module/Director/view/director/director/index.phtml
Expand Up @@ -7,6 +7,7 @@
* @link http://github.com/fbergkemper/barbossa for the canonical source repository
* @copyright Copyright (c) 2013-2014 dass-IT GmbH (http://www.dass-it.de/)
* @license GNU Affero General Public License (http://www.gnu.org/licenses/)
* @author Frank Bergkemper
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
Expand Down
60 changes: 60 additions & 0 deletions module/Job/src/Job/Controller/JobController.php
Expand Up @@ -33,6 +33,7 @@ class JobController extends AbstractActionController
{

protected $jobTable;
protected $bconsoleOutput = array();

public function indexAction()
{
Expand Down Expand Up @@ -119,6 +120,32 @@ public function timelineAction()
return new ViewModel();
}

public function rerunAction()
{
$jobid = (int) $this->params()->fromRoute('id', 0);
$cmd = "rerun jobid=" . $jobid . " yes";
return new ViewModel(
array(
'bconsoleOutput' => $this->getBConsoleOutput($cmd),
'jobid' => $jobid,
)
);
}

public function cancelAction()
{
$jobid = (int) $this->params()->fromRoute('id', 0);

//TODO
//$this->getJobTable()->getJobNameById($jobid);

$cmd = "cancel jobid=" . $jobid; //. " jobname=" . $jobname;

return new ViewModel(
array('bconsoleOutput' => $this->getBConsoleOutput($cmd))
);
}

public function getJobTable()
{
if(!$this->jobTable) {
Expand All @@ -128,5 +155,38 @@ public function getJobTable()
return $this->jobTable;
}

public function getBConsoleOutput($cmd)
{
$descriptorspec = array(
0 => array("pipe", "r"),
1 => array("pipe", "w"),
2 => array("pipe", "r")
);

$cwd = '/usr/sbin';
$env = array('/usr/sbin');

$process = proc_open('sudo /usr/sbin/bconsole', $descriptorspec, $pipes, $cwd, $env);

if(!is_resource($process))
throw new \Exception("proc_open error");

if(is_resource($process))
{
fwrite($pipes[0], $cmd);
fclose($pipes[0]);
while(!feof($pipes[1])) {
array_push($this->bconsoleOutput, fread($pipes[1],8192));
}
fclose($pipes[1]);

}

$return_value = proc_close($process);

return $this->bconsoleOutput;

}

}

10 changes: 10 additions & 0 deletions module/Job/src/Job/Model/JobTable.php
Expand Up @@ -334,6 +334,16 @@ public function getLastSuccessfulClientJob($id)
return $row;
}

public function getJobNameById($jobid)
{
$select = new Select();
$select->columns(array('name'));
$select->from('job');
$select->where("jobid=".$jobid);
$resultSet = $this->tableGateway->selectWith($select);
return $resultSet;
}

public function getStoredBytes7Days()
{
$end = date("Y-m-d H:i:s",time());
Expand Down
45 changes: 45 additions & 0 deletions module/Job/view/job/job/cancel.phtml
@@ -0,0 +1,45 @@
<?php

/**
*
* Barbossa - A Web-Frontend to manage Bareos
*
* @link http://github.com/fbergkemper/barbossa for the canonical source repository
* @copyright Copyright (c) 2013-2014 dass-IT GmbH (http://www.dass-it.de/)
* @license GNU Affero General Public License (http://www.gnu.org/licenses/)
* @author Frank Bergkemper
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

$title = 'Job Cancel';
$this->headTitle($title);

?>

<h3 class="text-muted"><?php echo $title; ?></h3>
<hr />

<p>Cancel job <?php echo $this->jobid; ?></p>

<pre style="font-size: 8pt;">
<code>
<?php
foreach($this->bconsoleOutput as $row) {
echo $row ."<br />";
}
?>
</code>
</pre>
6 changes: 3 additions & 3 deletions module/Job/view/job/job/index.phtml
Expand Up @@ -96,12 +96,12 @@ $this->headTitle($title);
<li><a href="<?php echo $this->url('log', array('action' => 'job', 'id' => $job->jobid)); ?>" title="<?php echo $this->translate("View logs"); ?>"><span class="glyphicon glyphicon-file"></span> View messages</a></li>
<li class="divider"></li>
<?php if($job->jobstatus == "T") : ?>
<li><a href="<?php ?>" title="<?php echo $this->translate("Rerun"); ?>"><span class="glyphicon glyphicon-repeat"></span> Re-run job</a></li>
<li><a href="<?php echo $this->url('job', array('action' => 'rerun', 'id' => $job->jobid)); ?>" title="<?php echo $this->translate("Rerun"); ?>"><span class="glyphicon glyphicon-repeat"></span> Re-run job</a></li>
<li><a href="<?php ?>" title="<?php echo $this->translate("Restore"); ?>"><span class="glyphicon glyphicon-import"></span> Restore job</a></li>
<?php elseif($job->jobstatus == "E" || $job->jobstatus == "e" || $job->jobstatus == "f" || $job->jobstatus == "A") : ?>
<li><a href="<?php ?>" title="<?php echo $this->translate("Rerun"); ?>"><span class="glyphicon glyphicon-repeat"></span> Re-run job</a></li>
<li><a href="<?php echo $this->url('job', array('action' => 'rerun', 'id' => $job->jobid)); ?>" title="<?php echo $this->translate("Rerun"); ?>"><span class="glyphicon glyphicon-repeat"></span> Re-run job</a></li>
<?php else : ?>
<li><a href="<?php ?>" title="<?php echo $this->translate("Cancel"); ?>"><span class="glyphicon glyphicon-trash"></span> Cancel job</a></li>
<li><a href="<?php echo $this->url('job', array('action' => 'cancel', 'id' => $job->jobid)); ?>" title="<?php echo $this->translate("Cancel"); ?>"><span class="glyphicon glyphicon-trash"></span> Cancel job</a></li>
<?php endif; ?>
</ul>
</div>
Expand Down
45 changes: 45 additions & 0 deletions module/Job/view/job/job/rerun.phtml
@@ -0,0 +1,45 @@
<?php

/**
*
* Barbossa - A Web-Frontend to manage Bareos
*
* @link http://github.com/fbergkemper/barbossa for the canonical source repository
* @copyright Copyright (c) 2013-2014 dass-IT GmbH (http://www.dass-it.de/)
* @license GNU Affero General Public License (http://www.gnu.org/licenses/)
* @author Frank Bergkemper
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

$title = 'Job Rerun';
$this->headTitle($title);

?>

<h3 class="text-muted"><?php echo $title; ?></h3>
<hr />

<p>Re-running job <?php echo $this->jobid; ?></p>

<pre style="font-size: 8pt;">
<code>
<?php
foreach($this->bconsoleOutput as $row) {
echo $row ."<br />";
}
?>
</code>
</pre>
2 changes: 1 addition & 1 deletion module/Job/view/job/job/running.phtml
Expand Up @@ -107,7 +107,7 @@ $flash->setMessageOpenFormat('
<ul class="dropdown-menu" role="menu">
<li><a href="<?php echo $this->url('log', array('action' => 'job', 'id' => $job->jobid)); ?>" title="<?php echo $this->translate("View messages"); ?>"><span class="glyphicon glyphicon-file"></span> View messages</a></li>
<li class="divider"></li>
<li><a href="<?php ?>" title="<?php echo $this->translate("Cancel"); ?>"><span class="glyphicon glyphicon-trash"></span> Cancel job</a></li>
<li><a href="<?php echo $this->url('job', array('action' => 'cancel', 'id' => $job->jobid)); ?>" title="<?php echo $this->translate("Cancel"); ?>"><span class="glyphicon glyphicon-trash"></span> Cancel job</a></li>
</ul>
</div>

Expand Down
2 changes: 1 addition & 1 deletion module/Job/view/job/job/successful.phtml
Expand Up @@ -111,7 +111,7 @@ $flash->setMessageOpenFormat('
<ul class="dropdown-menu" role="menu">
<li><a href="<?php echo $this->url('log', array('action' => 'job', 'id' => $job->jobid)); ?>" title="<?php echo $this->translate("View messages"); ?>"><span class="glyphicon glyphicon-file"></span> View messages</a></li>
<li class="divider"></li>
<li><a href="<?php ?>" title="<?php echo $this->translate("Rerun"); ?>"><span class="glyphicon glyphicon-repeat"></span> Re-run job</a></li>
<li><a href="<?php echo $this->url('job', array('action' => 'rerun', 'id' => $job->jobid)); ?>" title="<?php echo $this->translate("Rerun"); ?>"><span class="glyphicon glyphicon-repeat"></span> Re-run job</a></li>
<li><a href="<?php ?>" title="<?php echo $this->translate("Restore"); ?>"><span class="glyphicon glyphicon-import"></span> Restore job</a></li>
</ul>
</div>
Expand Down
2 changes: 1 addition & 1 deletion module/Job/view/job/job/unsuccessful.phtml
Expand Up @@ -111,7 +111,7 @@ $flash->setMessageOpenFormat('
<ul class="dropdown-menu" role="menu">
<li><a href="<?php echo $this->url('log', array('action' => 'job', 'id' => $job->jobid)); ?>" title="<?php echo $this->translate("View messages"); ?>"><span class="glyphicon glyphicon-file"></span> View messages</a></li>
<li class="divider"></li>
<li><a href="<?php ?>" title="<?php echo $this->translate("Rerun"); ?>"><span class="glyphicon glyphicon-repeat"></span> Re-run job</a></li>
<li><a href="<?php echo $this->url('job', array('action' => 'rerun', 'id' => $job->jobid)); ?>" title="<?php echo $this->translate("Rerun"); ?>"><span class="glyphicon glyphicon-repeat"></span> Re-run job</a></li>
</ul>
</div>

Expand Down

0 comments on commit 56110a1

Please sign in to comment.