Ensure that backend states are applied when applying ProcessChanges

This commit is contained in:
Sukhwinder Dhillon 2025-08-18 12:33:18 +02:00
parent 2111103957
commit ec14bdff0d
5 changed files with 57 additions and 7 deletions

View file

@ -94,12 +94,14 @@ 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);
if (! $bp->statesApplied()) {
if (Module::exists('icingadb') &&
(! $bp->hasBackendName() && IcingadbSupport::useIcingaDbAsBackend())
) {
IcingaDbState::apply($bp);
} else {
MonitoringState::apply($bp);
}
}
$this->handleSimulations($bp);

View file

@ -133,6 +133,9 @@ class BpConfig
/** @var bool Whether the config is faulty */
protected $isFaulty = false;
/** @var bool Whether the backend states are applied */
protected bool $statesApplied = false;
public function __construct()
{
}
@ -151,6 +154,30 @@ class BpConfig
return $this->metadata;
}
/**
* Get whether the backend states are applied
*
* @return bool
*/
public function statesApplied(): bool
{
return $this->statesApplied;
}
/**
* Set whether the backend states are applied
*
* @param bool $statesApplied
*
* @return $this
*/
public function setStatesApplied(bool $statesApplied = true): static
{
$this->statesApplied = $statesApplied;
return $this;
}
/**
* Set metadata
*

View file

@ -146,6 +146,8 @@ class IcingaDbState
Benchmark::measure('Retrieved states for ' . count($hostIds) . ' hosts in ' . $config->getName());
}
$config->setStatesApplied();
Benchmark::measure('Got states for business process ' . $config->getName());
return $this;

View file

@ -107,6 +107,7 @@ class MonitoringState
}
}
$config->setStatesApplied();
// TODO: Union, single query?
Benchmark::measure('Got states for business process ' . $config->getName());

View file

@ -3,8 +3,12 @@
namespace Icinga\Module\Businessprocess\Web;
use Icinga\Application\Icinga;
use Icinga\Application\Modules\Module;
use Icinga\Module\Businessprocess\BpConfig;
use Icinga\Module\Businessprocess\Modification\ProcessChanges;
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\Module\Businessprocess\Storage\Storage;
use Icinga\Module\Businessprocess\Web\Component\ActionBar;
@ -196,7 +200,21 @@ class Controller extends CompatController
$changes->clear();
$this->redirectNow($this->url()->without('dismissChanges')->without('unlocked'));
}
$bp->applyChanges($changes);
if (! $changes->isEmpty()) {
if (! $bp->statesApplied()) {
if (Module::exists('icingadb') &&
(! $bp->hasBackendName() && IcingadbSupport::useIcingaDbAsBackend())
) {
IcingaDbState::apply($bp);
} else {
MonitoringState::apply($bp);
}
}
$bp->applyChanges($changes);
}
return $bp;
}