Storage, Process: shift backend responsability

We do not want to take care about backends manually, they should just work
This commit is contained in:
Thomas Gelf 2015-02-07 00:49:32 +01:00
parent 2712b63dd6
commit 99edc846e5
3 changed files with 15 additions and 17 deletions

View file

@ -115,6 +115,12 @@ class BusinessProcess
return $this->title ?: $this->getName();
}
public function loadBackendByName($name)
{
$this->backend = MonitoringBackend::createBackend($name);
return $this;
}
public function setBackend(MonitoringBackend $backend)
{
$this->backend = $backend;
@ -123,6 +129,9 @@ class BusinessProcess
public function getBackend()
{
if ($this->backend === null) {
$this->backend = MonitoringBackend::createBackend();
}
return $this->backend;
}
@ -176,9 +185,9 @@ class BusinessProcess
return $this;
}
public function retrieveStatesFromBackend(MonitoringBackend $backend)
public function retrieveStatesFromBackend()
{
$this->backend = $backend;
$backend = $this->getBackend();
// TODO: Split apart, create a dedicated function.
// Separate "parse-logic" from "retrieve-state-logic"
// Allow DB-based backend

View file

@ -31,7 +31,6 @@ class Controller extends ModuleActionController
}
$this->config = $this->Config();
$this->prepareBackend();
}
protected function tabs()
@ -72,7 +71,7 @@ class Controller extends ModuleActionController
}
}
$bp->retrieveStatesFromBackend($this->backend);
$bp->retrieveStatesFromBackend();
return $bp;
}
@ -101,17 +100,4 @@ class Controller extends ModuleActionController
->module('BpAddon')
->getBpSlaValues($sla_hosts, $start, $end);
}
protected function prepareBackend()
{
if ($this->backend === null) {
$name = $this->config->get('global', 'default_backend');
if (isset($this->bpconf->backend)) {
$name = $this->bpconf->backend;
}
$this->backend = Backend::createBackend($name);
}
return $this->backend;
}
}

View file

@ -210,6 +210,9 @@ class LegacyStorage extends Storage
// TODO: do not open twice, this is quick and dirty based on existing code
$header = $this->readHeader($file, $name);
$bp->setTitle($header['Title']);
if ($header['Backend']) {
$bp->loadBackendByName($header['Backend']);
}
return $bp;
}