mirror of
https://github.com/Icinga/icingaweb2-module-businessprocess.git
synced 2026-05-28 04:34:08 -04:00
BpConfig: Add method applyDbStates() to clean-up redundant code
This commit is contained in:
parent
be8119f964
commit
e99bb0d26c
9 changed files with 26 additions and 101 deletions
|
|
@ -7,12 +7,8 @@ namespace Icinga\Module\Businessprocess\Clicommands;
|
|||
|
||||
use Exception;
|
||||
use Icinga\Application\Logger;
|
||||
use Icinga\Application\Modules\Module;
|
||||
use Icinga\Cli\Command;
|
||||
use Icinga\Module\Businessprocess\Modification\NodeRemoveAction;
|
||||
use Icinga\Module\Businessprocess\ProvidedHook\Icingadb\IcingadbSupport;
|
||||
use Icinga\Module\Businessprocess\State\IcingaDbState;
|
||||
use Icinga\Module\Businessprocess\State\MonitoringState;
|
||||
use Icinga\Module\Businessprocess\Storage\LegacyStorage;
|
||||
|
||||
class CleanupCommand extends Command
|
||||
|
|
@ -62,14 +58,7 @@ class CleanupCommand extends Command
|
|||
continue;
|
||||
}
|
||||
|
||||
if (
|
||||
Module::exists('icingadb')
|
||||
&& (! $bp->hasBackendName() && IcingadbSupport::useIcingaDbAsBackend())
|
||||
) {
|
||||
IcingaDbState::apply($bp);
|
||||
} else {
|
||||
MonitoringState::apply($bp);
|
||||
}
|
||||
$bp->applyDbStates();
|
||||
|
||||
$removedNodes = [];
|
||||
foreach (array_keys($bp->getMissingChildren()) as $missingNode) {
|
||||
|
|
|
|||
|
|
@ -7,16 +7,12 @@ namespace Icinga\Module\Businessprocess\Clicommands;
|
|||
|
||||
use Exception;
|
||||
use Icinga\Application\Logger;
|
||||
use Icinga\Application\Modules\Module;
|
||||
use Icinga\Cli\Command;
|
||||
use Icinga\Module\Businessprocess\BpConfig;
|
||||
use Icinga\Module\Businessprocess\BpNode;
|
||||
use Icinga\Module\Businessprocess\HostNode;
|
||||
use Icinga\Module\Businessprocess\Node;
|
||||
use Icinga\Module\Businessprocess\ProvidedHook\Icingadb\IcingadbSupport;
|
||||
use Icinga\Module\Businessprocess\ServiceNode;
|
||||
use Icinga\Module\Businessprocess\State\IcingaDbState;
|
||||
use Icinga\Module\Businessprocess\State\MonitoringState;
|
||||
use Icinga\Module\Businessprocess\Storage\LegacyStorage;
|
||||
|
||||
class ProcessCommand extends Command
|
||||
|
|
@ -139,14 +135,7 @@ class ProcessCommand extends Command
|
|||
try {
|
||||
/** @var BpNode $node */
|
||||
$node = $bp->getNode($nodeName);
|
||||
if (
|
||||
Module::exists('icingadb')
|
||||
&& (! $bp->hasBackendName() && IcingadbSupport::useIcingaDbAsBackend())
|
||||
) {
|
||||
IcingaDbState::apply($bp);
|
||||
} else {
|
||||
MonitoringState::apply($bp);
|
||||
}
|
||||
$bp->applyDbStates();
|
||||
|
||||
if ($bp->hasErrors()) {
|
||||
Logger::error("Checking Business Process '%s' failed: %s\n", $name, $bp->getErrors());
|
||||
|
|
|
|||
|
|
@ -6,13 +6,9 @@
|
|||
namespace Icinga\Module\Businessprocess\Controllers;
|
||||
|
||||
use Exception;
|
||||
use Icinga\Application\Modules\Module;
|
||||
use Icinga\Module\Businessprocess\ProvidedHook\Icingadb\IcingadbSupport;
|
||||
use Icinga\Module\Businessprocess\Renderer\Breadcrumb;
|
||||
use Icinga\Module\Businessprocess\Renderer\TileRenderer;
|
||||
use Icinga\Module\Businessprocess\Simulation;
|
||||
use Icinga\Module\Businessprocess\State\IcingaDbState;
|
||||
use Icinga\Module\Businessprocess\State\MonitoringState;
|
||||
use Icinga\Module\Businessprocess\Web\Controller;
|
||||
use Icinga\Module\Businessprocess\Web\Url;
|
||||
use ipl\Html\Html;
|
||||
|
|
@ -98,14 +94,7 @@ class NodeController extends Controller
|
|||
continue;
|
||||
}
|
||||
|
||||
if (
|
||||
Module::exists('icingadb') &&
|
||||
(! $config->getBackendName() && IcingadbSupport::useIcingaDbAsBackend())
|
||||
) {
|
||||
IcingaDbState::apply($config);
|
||||
} else {
|
||||
MonitoringState::apply($config);
|
||||
}
|
||||
$config->applyDbStates();
|
||||
$config->applySimulation($simulation);
|
||||
|
||||
foreach ($parents as $parentAndPath) {
|
||||
|
|
|
|||
|
|
@ -5,21 +5,17 @@
|
|||
|
||||
namespace Icinga\Module\Businessprocess\Controllers;
|
||||
|
||||
use Icinga\Application\Modules\Module;
|
||||
use Icinga\Date\DateFormatter;
|
||||
use Icinga\Module\Businessprocess\BpConfig;
|
||||
use Icinga\Module\Businessprocess\BpNode;
|
||||
use Icinga\Module\Businessprocess\Forms\AddNodeForm;
|
||||
use Icinga\Module\Businessprocess\Forms\EditNodeForm;
|
||||
use Icinga\Module\Businessprocess\Node;
|
||||
use Icinga\Module\Businessprocess\ProvidedHook\Icingadb\IcingadbSupport;
|
||||
use Icinga\Module\Businessprocess\Renderer\Breadcrumb;
|
||||
use Icinga\Module\Businessprocess\Renderer\Renderer;
|
||||
use Icinga\Module\Businessprocess\Renderer\TileRenderer;
|
||||
use Icinga\Module\Businessprocess\Renderer\TreeRenderer;
|
||||
use Icinga\Module\Businessprocess\Simulation;
|
||||
use Icinga\Module\Businessprocess\State\IcingaDbState;
|
||||
use Icinga\Module\Businessprocess\State\MonitoringState;
|
||||
use Icinga\Module\Businessprocess\Storage\ConfigDiff;
|
||||
use Icinga\Module\Businessprocess\Storage\LegacyConfigRenderer;
|
||||
use Icinga\Module\Businessprocess\Web\Component\ActionBar;
|
||||
|
|
@ -97,14 +93,7 @@ class ProcessController extends Controller
|
|||
$bp = $this->loadModifiedBpConfig();
|
||||
$node = $this->getNode($bp);
|
||||
|
||||
if (
|
||||
Module::exists('icingadb') &&
|
||||
(! $bp->hasBackendName() && IcingadbSupport::useIcingaDbAsBackend())
|
||||
) {
|
||||
IcingaDbState::apply($bp);
|
||||
} else {
|
||||
MonitoringState::apply($bp);
|
||||
}
|
||||
$bp->applyDbStates();
|
||||
|
||||
$this->handleSimulations($bp);
|
||||
|
||||
|
|
|
|||
|
|
@ -157,6 +157,23 @@ class BpConfig
|
|||
return $this->metadata;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply database states
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function applyDbStates(): void
|
||||
{
|
||||
if (
|
||||
Module::exists('icingadb')
|
||||
&& (! $this->hasBackendName() && IcingadbSupport::useIcingaDbAsBackend())
|
||||
) {
|
||||
IcingaDbState::apply($this);
|
||||
} else {
|
||||
MonitoringState::apply($this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set metadata
|
||||
*
|
||||
|
|
@ -179,14 +196,7 @@ class BpConfig
|
|||
*/
|
||||
public function applyChanges(ProcessChanges $changes)
|
||||
{
|
||||
if (
|
||||
Module::exists('icingadb')
|
||||
&& (! $this->hasBackendName() && IcingadbSupport::useIcingaDbAsBackend())
|
||||
) {
|
||||
IcingaDbState::apply($this);
|
||||
} else {
|
||||
MonitoringState::apply($this);
|
||||
}
|
||||
$this->applyDbStates();
|
||||
|
||||
$cnt = 0;
|
||||
foreach ($changes->getChanges() as $change) {
|
||||
|
|
|
|||
|
|
@ -6,12 +6,8 @@
|
|||
namespace Icinga\Module\Businessprocess\Web\Component;
|
||||
|
||||
use Exception;
|
||||
use Icinga\Application\Modules\Module;
|
||||
use Icinga\Authentication\Auth;
|
||||
use Icinga\Module\Businessprocess\BpConfig;
|
||||
use Icinga\Module\Businessprocess\ProvidedHook\Icingadb\IcingadbSupport;
|
||||
use Icinga\Module\Businessprocess\State\IcingaDbState;
|
||||
use Icinga\Module\Businessprocess\State\MonitoringState;
|
||||
use Icinga\Module\Businessprocess\Storage\Storage;
|
||||
use ipl\Html\BaseHtmlElement;
|
||||
use ipl\Html\Html;
|
||||
|
|
@ -112,14 +108,7 @@ class Dashboard extends BaseHtmlElement
|
|||
continue;
|
||||
}
|
||||
|
||||
if (
|
||||
Module::exists('icingadb') &&
|
||||
(! $bp->hasBackendName() && IcingadbSupport::useIcingaDbAsBackend())
|
||||
) {
|
||||
IcingaDbState::apply($bp);
|
||||
} else {
|
||||
MonitoringState::apply($bp);
|
||||
}
|
||||
$bp->applyDbStates();
|
||||
|
||||
$this->add(new BpDashboardTile(
|
||||
$bp,
|
||||
|
|
|
|||
|
|
@ -6,12 +6,7 @@
|
|||
namespace Icinga\Module\Businessprocess\Web\Component;
|
||||
|
||||
use Exception;
|
||||
use Icinga\Application\Modules\Module;
|
||||
use Icinga\Authentication\Auth;
|
||||
use Icinga\Module\Businessprocess\BpConfig;
|
||||
use Icinga\Module\Businessprocess\ProvidedHook\Icingadb\IcingadbSupport;
|
||||
use Icinga\Module\Businessprocess\State\IcingaDbState;
|
||||
use Icinga\Module\Businessprocess\State\MonitoringState;
|
||||
use Icinga\Module\Businessprocess\Storage\Storage;
|
||||
use ipl\Html\BaseHtmlElement;
|
||||
use ipl\Html\Html;
|
||||
|
|
@ -69,14 +64,7 @@ class DashboardFullscreen extends BaseHtmlElement
|
|||
continue;
|
||||
}
|
||||
|
||||
if (
|
||||
Module::exists('icingadb') &&
|
||||
(! $bp->hasBackendName() && IcingadbSupport::useIcingaDbAsBackend())
|
||||
) {
|
||||
IcingaDbState::apply($bp);
|
||||
} else {
|
||||
MonitoringState::apply($bp);
|
||||
}
|
||||
$bp->applyDbStates();
|
||||
|
||||
$this->add(new BpDashboardFullscreenTile(
|
||||
$bp,
|
||||
|
|
|
|||
|
|
@ -8,9 +8,6 @@ namespace Icinga\Module\Businessprocess\Web\Form\Validator;
|
|||
use Icinga\Module\Businessprocess\BpConfig;
|
||||
use Icinga\Module\Businessprocess\BpNode;
|
||||
use Icinga\Module\Businessprocess\ServiceNode;
|
||||
use Icinga\Module\Businessprocess\State\IcingaDbState;
|
||||
use Icinga\Module\Businessprocess\State\MonitoringState;
|
||||
use Icinga\Module\Monitoring\Backend\MonitoringBackend;
|
||||
use ipl\I18n\Translation;
|
||||
use ipl\Validator\BaseValidator;
|
||||
use ipl\Web\FormElement\TermInput\Term;
|
||||
|
|
@ -72,11 +69,7 @@ class HostServiceTermValidator extends BaseValidator
|
|||
}
|
||||
}
|
||||
|
||||
if ($testConfig->getBackend() instanceof MonitoringBackend) {
|
||||
MonitoringState::apply($testConfig);
|
||||
} else {
|
||||
IcingaDbState::apply($testConfig);
|
||||
}
|
||||
$testConfig->applyDbStates();
|
||||
|
||||
foreach ($terms as $term) {
|
||||
/** @var Term $term */
|
||||
|
|
|
|||
|
|
@ -6,11 +6,7 @@
|
|||
namespace Icinga\Module\Businessprocess\Web\Navigation\Renderer;
|
||||
|
||||
use Icinga\Application\Logger;
|
||||
use Icinga\Application\Modules\Module;
|
||||
use Icinga\Module\Businessprocess\Node;
|
||||
use Icinga\Module\Businessprocess\ProvidedHook\Icingadb\IcingadbSupport;
|
||||
use Icinga\Module\Businessprocess\State\IcingaDbState;
|
||||
use Icinga\Module\Businessprocess\State\MonitoringState;
|
||||
use Icinga\Module\Businessprocess\Storage\LegacyStorage;
|
||||
use Icinga\Web\Navigation\Renderer\BadgeNavigationItemRenderer;
|
||||
use Throwable;
|
||||
|
|
@ -35,14 +31,7 @@ class ProcessesProblemsBadge extends BadgeNavigationItemRenderer
|
|||
|
||||
foreach ($storage->listProcessNames() as $processName) {
|
||||
$bp = $storage->loadProcess($processName);
|
||||
if (
|
||||
Module::exists('icingadb') &&
|
||||
(! $bp->hasBackendName() && IcingadbSupport::useIcingaDbAsBackend())
|
||||
) {
|
||||
IcingaDbState::apply($bp);
|
||||
} else {
|
||||
MonitoringState::apply($bp);
|
||||
}
|
||||
$bp->applyDbStates();
|
||||
|
||||
foreach ($bp->getRootNodes() as $rootNode) {
|
||||
$nodeState = $rootNode->getState();
|
||||
|
|
|
|||
Loading…
Reference in a new issue