Skip to content

Commit

Permalink
webui: remove getData action from job controller
Browse files Browse the repository at this point in the history
  • Loading branch information
fbergkemper committed Apr 17, 2023
1 parent fdd7de3 commit 9ae5f05
Showing 1 changed file with 0 additions and 237 deletions.
237 changes: 0 additions & 237 deletions webui/module/Job/src/Job/Controller/JobController.php
Expand Up @@ -588,243 +588,6 @@ public function timelineAction()
return new ViewModel();
}

public function getDataAction()
{
$this->RequestURIPlugin()->setRequestURI();

if (!$this->SessionTimeoutPlugin()->isValid()) {
return $this->redirect()->toRoute(
'auth',
array(
'action' => 'login'
),
array(
'query' => array(
'req' => $this->RequestURIPlugin()->getRequestURI(),
'dird' => $_SESSION['bareos']['director']
)
)
);
}

$result = null;

$data = $this->params()->fromQuery('data');
$jobid = $this->params()->fromQuery('jobid');
$jobname = $this->params()->fromQuery('jobname');
$jobs = $this->params()->fromQuery('jobs');
$status = $this->params()->fromQuery('status');
$period = $this->params()->fromQuery('period');
$client = $this->params()->fromQuery('client');
$clients = $this->params()->fromQUery('clients');

try {
$this->bsock = $this->getServiceLocator()->get('director');
} catch (Exception $e) {
echo $e->getMessage();
}

if ($data == "jobs") {
try {
$result = $this->getJobModel()->getJobs($this->bsock, null, $period);
} catch (Exception $e) {
echo $e->getMessage();
}
} elseif ($data == "runjobs") {
try {
// 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.
$jobs_B = $this->getJobModel()->getJobsByType($this->bsock, 'B'); // Backup Job
$jobs_D = $this->getJobModel()->getJobsByType($this->bsock, 'D'); // Admin Job
$jobs_A = $this->getJobModel()->getJobsByType($this->bsock, 'A'); // Archive Job
$jobs_c = $this->getJobModel()->getJobsByType($this->bsock, 'c'); // Copy Job
$jobs_g = $this->getJobModel()->getJobsByType($this->bsock, 'g'); // Migration Job
$jobs_O = $this->getJobModel()->getJobsByType($this->bsock, 'O'); // Always Incremental Consolidate Job
$jobs_V = $this->getJobModel()->getJobsByType($this->bsock, 'V'); // Verify Job
$result = array_merge(
$jobs_B,
$jobs_D,
$jobs_A,
$jobs_c,
$jobs_g,
$jobs_O,
$jobs_V
);
} catch (Exception $e) {
echo $e->getMessage();
}
} elseif ($data == "all-job-resources") {
try {
$jobs_B = $this->getJobModel()->getJobsByType($this->bsock, 'B'); // Backup Job
$jobs_D = $this->getJobModel()->getJobsByType($this->bsock, 'D'); // Admin Job
$jobs_A = $this->getJobModel()->getJobsByType($this->bsock, 'A'); // Archive Job
$jobs_c = $this->getJobModel()->getJobsByType($this->bsock, 'c'); // Copy Job
$jobs_g = $this->getJobModel()->getJobsByType($this->bsock, 'g'); // Migration Job
$jobs_O = $this->getJobModel()->getJobsByType($this->bsock, 'O'); // Always Incremental Consolidate Job
$jobs_V = $this->getJobModel()->getJobsByType($this->bsock, 'V'); // Verify Job
$jobs_R = $this->getJobModel()->getJobsByType($this->bsock, 'R'); // Restore Job
$result = array_merge(
$jobs_B,
$jobs_D,
$jobs_A,
$jobs_c,
$jobs_g,
$jobs_O,
$jobs_V,
$jobs_R
);
} catch (Exception $e) {
echo $e->getMessage();
}
} elseif ($data == "details") {
try {
$result = $this->getJobModel()->getJob($this->bsock, $jobid);
} catch (Exception $e) {
echo $e->getMessage();
}
} elseif ($data == "logs" && isset($jobid)) {
try {
$result = $this->getJobModel()->getJobLog($this->bsock, $jobid);
} catch (Exception $e) {
echo $e->getMessage();
}
} elseif ($data == "jobmedia" && isset($jobid)) {
try {
$result = $this->getJobModel()->getJobMedia($this->bsock, $jobid);
} catch (Exception $e) {
echo $e->getMessage();
}
} elseif ($data == "jobs-to-rerun") {
try {
$result = $this->getJobModel()->getJobsToRerun($this->bsock, $period, null);
} catch (Exception $e) {
echo $e->getMessage();
}
} elseif ($data == "job-rerun") {
try {
$result = [];
$j = explode(",", $jobs);
foreach ($j as $job) {
array_push($result, $this->getJobModel()->rerunJob($this->bsock, $job));
}
} catch (Exception $e) {
echo $e->getMessage();
}

$response = $this->getResponse();
$response->getHeaders()->addHeaderLine('Content-Type', 'application/json');

if (isset($result)) {
$response->setContent(JSON::encode($result));
}

return $response;
} elseif ($data == "job-timeline") {
try {
$result = [];
$j = explode(",", $jobs);

foreach ($j as $jobname) {
$result = array_merge($result, $this->getJobModel()->getJobsForPeriodByJobname($this->bsock, $jobname, $period));
}

$jobs = array();

foreach ($result as $job) {
$starttime = new \DateTime($job['starttime'], new \DateTimeZone('UTC'));
$endtime = new \DateTime($job['endtime'], new \DateTimeZone('UTC'));
$schedtime = new \DateTime($job['schedtime'], new \DateTimeZone('UTC'));

$starttime = $starttime->format('U') * 1000;
$endtime = $endtime->format('U') * 1000;
$schedtime = $schedtime->format('U') * 1000;

switch ($job['jobstatus']) {
// SUCESS
case 'T':
$fillcolor = "#5cb85c";
break;
// WARNING
case 'A':
case 'W':
$fillcolor = "#f0ad4e";
break;
// RUNNING
case 'R':
case 'l':
$fillcolor = "#5bc0de";
$endtime = new \DateTime("now", new \DateTimeZone('UTC'));
$endtime = $endtime->format('U') * 1000;
break;
// FAILED
case 'E':
case 'e':
case 'f':
$fillcolor = "#d9534f";
break;
// WAITING
case 'F':
case 'S':
case 's':
case 'M':
case 'm':
case 'j':
case 'C':
case 'c':
case 'd':
case 't':
case 'p':
case 'q':
$fillcolor = "#555555";
$endtime = new \DateTime("now", new \DateTimeZone('UTC'));
$endtime = $endtime->format('U') * 1000;
break;
default:
$fillcolor = "#555555";
break;
}

// workaround to display short job runs <= 1 sec.
if ($starttime === $endtime) {
$endtime += 1000;
}

$item = new \stdClass();
$item->x = $job["client"];
$item->y = array($starttime, $endtime);
$item->fillColor = $fillcolor;
$item->name = $job["name"];
$item->jobid = $job["jobid"];
$item->starttime = $job["starttime"];
$item->endtime = $job["endtime"];
$item->schedtime = $job["schedtime"];
$item->client = $job["client"];

array_push($jobs, $item);
}

$result = $jobs;
} catch (Exception $e) {
echo $e->getMessage();
}
}

try {
$this->bsock->disconnect();
} catch (Exception $e) {
echo $e->getMessage();
}

$response = $this->getResponse();
$response->getHeaders()->addHeaderLine('Content-Type', 'application/json');

if (isset($result)) {
$response->setContent(JSON::encode($result));
}

return $response;
}

public function getJobModel()
{
if (!$this->jobModel) {
Expand Down

0 comments on commit 9ae5f05

Please sign in to comment.