mirror of
https://github.com/Icinga/icingaweb2-module-businessprocess.git
synced 2025-12-20 14:50:11 -05:00
BpConfig: Delay processing of imported configurations
Solves the issue that two processes cannot import each other
This commit is contained in:
parent
0194f9afe9
commit
00b88055f7
12 changed files with 85 additions and 66 deletions
|
|
@ -32,6 +32,11 @@ class BpConfig
|
|||
*/
|
||||
protected $backend;
|
||||
|
||||
/**
|
||||
* @var LegacyStorage
|
||||
*/
|
||||
protected $storage;
|
||||
|
||||
/** @var Metadata */
|
||||
protected $metadata;
|
||||
|
||||
|
|
@ -455,12 +460,12 @@ class BpConfig
|
|||
public function createService($host, $service)
|
||||
{
|
||||
$node = new ServiceNode(
|
||||
$this,
|
||||
(object) array(
|
||||
'hostname' => $host,
|
||||
'service' => $service
|
||||
)
|
||||
);
|
||||
$node->setBpConfig($this);
|
||||
$this->nodes[$host . ';' . $service] = $node;
|
||||
$this->hosts[$host] = true;
|
||||
return $node;
|
||||
|
|
@ -468,7 +473,8 @@ class BpConfig
|
|||
|
||||
public function createHost($host)
|
||||
{
|
||||
$node = new HostNode($this, (object) array('hostname' => $host));
|
||||
$node = new HostNode((object) array('hostname' => $host));
|
||||
$node->setBpConfig($this);
|
||||
$this->nodes[$host . ';Hoststatus'] = $node;
|
||||
$this->hosts[$host] = true;
|
||||
return $node;
|
||||
|
|
@ -514,11 +520,12 @@ class BpConfig
|
|||
*/
|
||||
public function createBp($name, $operator = '&')
|
||||
{
|
||||
$node = new BpNode($this, (object) array(
|
||||
$node = new BpNode((object) array(
|
||||
'name' => $name,
|
||||
'operator' => $operator,
|
||||
'child_names' => array(),
|
||||
));
|
||||
$node->setBpConfig($this);
|
||||
|
||||
$this->addNode($name, $node);
|
||||
return $node;
|
||||
|
|
@ -541,18 +548,6 @@ class BpConfig
|
|||
|
||||
public function createImportedNode($config, $name = null)
|
||||
{
|
||||
if (! isset($this->importedConfigs[$config])) {
|
||||
$import = $this->storage()->loadProcess($config);
|
||||
|
||||
if ($this->usesSoftStates()) {
|
||||
$import->useSoftStates();
|
||||
} else {
|
||||
$import->useHardStates();
|
||||
}
|
||||
|
||||
$this->importedConfigs[$config] = $import;
|
||||
}
|
||||
|
||||
$params = (object) array('configName' => $config);
|
||||
if ($name !== null) {
|
||||
$params->node = $name;
|
||||
|
|
@ -566,7 +561,15 @@ class BpConfig
|
|||
public function getImportedConfig($name)
|
||||
{
|
||||
if (! isset($this->importedConfigs[$name])) {
|
||||
throw new LogicException("Config $name not imported yet");
|
||||
$import = $this->storage()->loadProcess($name);
|
||||
|
||||
if ($this->usesSoftStates()) {
|
||||
$import->useSoftStates();
|
||||
} else {
|
||||
$import->useHardStates();
|
||||
}
|
||||
|
||||
$this->importedConfigs[$name] = $import;
|
||||
}
|
||||
|
||||
return $this->importedConfigs[$name];
|
||||
|
|
@ -577,9 +580,13 @@ class BpConfig
|
|||
*/
|
||||
protected function storage()
|
||||
{
|
||||
return new LegacyStorage(
|
||||
Config::module('businessprocess')->getSection('global')
|
||||
);
|
||||
if ($this->storage === null) {
|
||||
$this->storage = new LegacyStorage(
|
||||
Config::module('businessprocess')->getSection('global')
|
||||
);
|
||||
}
|
||||
|
||||
return $this->storage;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -632,11 +639,12 @@ class BpConfig
|
|||
$this->calculateAllStates();
|
||||
|
||||
$names = array_keys($this->getUnboundNodes());
|
||||
$bp = new BpNode($this, (object) array(
|
||||
$bp = new BpNode((object) array(
|
||||
'name' => '__unbound__',
|
||||
'operator' => '&',
|
||||
'child_names' => $names
|
||||
));
|
||||
$bp->setBpConfig($this);
|
||||
$bp->setAlias($this->translate('Unbound nodes'));
|
||||
return $bp;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,9 +48,8 @@ class BpNode extends Node
|
|||
|
||||
protected $className = 'process';
|
||||
|
||||
public function __construct(BpConfig $bp, $object)
|
||||
public function __construct($object)
|
||||
{
|
||||
$this->bp = $bp;
|
||||
$this->name = $object->name;
|
||||
$this->operator = $object->operator;
|
||||
$this->childNames = $object->child_names;
|
||||
|
|
@ -178,7 +177,7 @@ class BpNode extends Node
|
|||
{
|
||||
if ($this->missing === null) {
|
||||
$exists = false;
|
||||
$bp = $this->bp;
|
||||
$bp = $this->getBpConfig();
|
||||
$bp->beginLoopDetection($this->name);
|
||||
foreach ($this->getChildren() as $child) {
|
||||
if (! $child->isMissing()) {
|
||||
|
|
@ -299,8 +298,8 @@ class BpNode extends Node
|
|||
try {
|
||||
$this->reCalculateState();
|
||||
} catch (NestingError $e) {
|
||||
$this->bp->addError(
|
||||
$this->bp->translate('Nesting error detected: %s'),
|
||||
$this->getBpConfig()->addError(
|
||||
$this->getBpConfig()->translate('Nesting error detected: %s'),
|
||||
$e->getMessage()
|
||||
);
|
||||
|
||||
|
|
@ -327,7 +326,7 @@ class BpNode extends Node
|
|||
*/
|
||||
public function reCalculateState()
|
||||
{
|
||||
$bp = $this->bp;
|
||||
$bp = $this->getBpConfig();
|
||||
|
||||
$sort_states = array();
|
||||
$lastStateChange = 0;
|
||||
|
|
@ -401,7 +400,7 @@ class BpNode extends Node
|
|||
|
||||
public function checkForLoops()
|
||||
{
|
||||
$bp = $this->bp;
|
||||
$bp = $this->getBpConfig();
|
||||
foreach ($this->getChildren() as $child) {
|
||||
$bp->beginLoopDetection($this->name);
|
||||
if ($child instanceof BpNode) {
|
||||
|
|
@ -426,7 +425,7 @@ class BpNode extends Node
|
|||
|
||||
public function setChildNames($names)
|
||||
{
|
||||
if (! $this->bp->getMetadata()->isManuallyOrdered()) {
|
||||
if (! $this->getBpConfig()->getMetadata()->isManuallyOrdered()) {
|
||||
natcasesort($names);
|
||||
$names = array_values($names);
|
||||
}
|
||||
|
|
@ -451,13 +450,13 @@ class BpNode extends Node
|
|||
{
|
||||
if ($this->children === null) {
|
||||
$this->children = array();
|
||||
if (! $this->bp->getMetadata()->isManuallyOrdered()) {
|
||||
if (! $this->getBpConfig()->getMetadata()->isManuallyOrdered()) {
|
||||
$childNames = $this->getChildNames();
|
||||
natcasesort($childNames);
|
||||
$this->childNames = array_values($childNames);
|
||||
}
|
||||
foreach ($this->getChildNames() as $name) {
|
||||
$this->children[$name] = $this->bp->getNode($name);
|
||||
$this->children[$name] = $this->getBpConfig()->getNode($name);
|
||||
$this->children[$name]->addParent($this);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,11 +34,10 @@ class HostNode extends MonitoredNode
|
|||
|
||||
protected $icon = 'host';
|
||||
|
||||
public function __construct(BpConfig $bp, $object)
|
||||
public function __construct($object)
|
||||
{
|
||||
$this->name = $object->hostname . ';Hoststatus';
|
||||
$this->hostname = $object->hostname;
|
||||
$this->bp = $bp;
|
||||
if (isset($object->state)) {
|
||||
$this->setState($object->state);
|
||||
} else {
|
||||
|
|
@ -62,8 +61,8 @@ class HostNode extends MonitoredNode
|
|||
'host' => $this->getHostname(),
|
||||
);
|
||||
|
||||
if ($this->bp->hasBackendName()) {
|
||||
$params['backend'] = $this->bp->getBackendName();
|
||||
if ($this->getBpConfig()->hasBackendName()) {
|
||||
$params['backend'] = $this->getBpConfig()->getBackendName();
|
||||
}
|
||||
|
||||
return Url::fromPath('businessprocess/host/show', $params);
|
||||
|
|
|
|||
|
|
@ -24,14 +24,13 @@ class ImportedNode extends BpNode
|
|||
/** @var string */
|
||||
protected $icon = 'download';
|
||||
|
||||
public function __construct(BpConfig $bp, $object)
|
||||
public function __construct(BpConfig $parentBp, $object)
|
||||
{
|
||||
$this->parentBp = $bp;
|
||||
$this->parentBp = $parentBp;
|
||||
$this->configName = $object->configName;
|
||||
$this->nodeName = $object->node;
|
||||
|
||||
$importedConfig = $bp->getImportedConfig($this->configName);
|
||||
parent::__construct($importedConfig, (object) [
|
||||
parent::__construct((object) [
|
||||
'name' => '@' . $this->configName . ':' . $this->nodeName,
|
||||
'operator' => null,
|
||||
'child_names' => null
|
||||
|
|
@ -55,6 +54,15 @@ class ImportedNode extends BpNode
|
|||
return $this->nodeName;
|
||||
}
|
||||
|
||||
public function getBpConfig()
|
||||
{
|
||||
if ($this->bp === null) {
|
||||
$this->bp = $this->parentBp->getImportedConfig($this->configName);
|
||||
}
|
||||
|
||||
return $this->bp;
|
||||
}
|
||||
|
||||
public function getAlias()
|
||||
{
|
||||
if ($this->alias === null) {
|
||||
|
|
@ -89,7 +97,7 @@ class ImportedNode extends BpNode
|
|||
{
|
||||
if ($this->importedNode === null) {
|
||||
try {
|
||||
$this->importedNode = $this->bp->getBpNode($this->nodeName);
|
||||
$this->importedNode = $this->getBpConfig()->getBpNode($this->nodeName);
|
||||
} catch (Exception $e) {
|
||||
return $this->createFailedNode($e);
|
||||
}
|
||||
|
|
@ -106,11 +114,12 @@ class ImportedNode extends BpNode
|
|||
protected function createFailedNode(Exception $e)
|
||||
{
|
||||
$this->parentBp->addError($e->getMessage());
|
||||
$node = new BpNode($this->bp, (object) array(
|
||||
$node = new BpNode((object) array(
|
||||
'name' => $this->getName(),
|
||||
'operator' => '&',
|
||||
'child_names' => []
|
||||
));
|
||||
$node->setBpConfig($this->getBpConfig());
|
||||
$node->setState(2);
|
||||
$node->setMissing(false)
|
||||
->setDowntime(false)
|
||||
|
|
|
|||
|
|
@ -101,7 +101,8 @@ class NodeCreateAction extends NodeAction
|
|||
} else {
|
||||
$properties['child_names'] = array();
|
||||
}
|
||||
$node = new BpNode($config, (object) $properties);
|
||||
$node = new BpNode((object) $properties);
|
||||
$node->setBpConfig($config);
|
||||
|
||||
foreach ($this->getProperties() as $key => $val) {
|
||||
if ($key === 'parentName') {
|
||||
|
|
|
|||
|
|
@ -109,7 +109,18 @@ abstract class Node
|
|||
99 => 'PENDING'
|
||||
);
|
||||
|
||||
abstract public function __construct(BpConfig $bp, $object);
|
||||
abstract public function __construct($object);
|
||||
|
||||
public function setBpConfig(BpConfig $bp)
|
||||
{
|
||||
$this->bp = $bp;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getBpConfig()
|
||||
{
|
||||
return $this->bp;
|
||||
}
|
||||
|
||||
public function setMissing($missing = true)
|
||||
{
|
||||
|
|
@ -341,7 +352,7 @@ abstract class Node
|
|||
*/
|
||||
public function getPaths()
|
||||
{
|
||||
if ($this->bp->hasRootNode($this->getName())) {
|
||||
if ($this->getBpConfig()->hasRootNode($this->getName())) {
|
||||
return array(array($this->getName()));
|
||||
}
|
||||
|
||||
|
|
@ -356,14 +367,6 @@ abstract class Node
|
|||
return $paths;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BpConfig
|
||||
*/
|
||||
public function getBusinessProcess()
|
||||
{
|
||||
return $this->bp;
|
||||
}
|
||||
|
||||
protected function stateToSortState($state)
|
||||
{
|
||||
if (array_key_exists($state, $this->stateToSortStateMap)) {
|
||||
|
|
|
|||
|
|
@ -122,7 +122,7 @@ class NodeTile extends BaseHtmlElement
|
|||
$renderer = $this->renderer;
|
||||
|
||||
$params = [
|
||||
'config' => $node->getBusinessProcess()->getName(),
|
||||
'config' => $node->getBpConfig()->getName(),
|
||||
'node' => $node instanceof ImportedNode
|
||||
? $node->getNodeName()
|
||||
: $this->name
|
||||
|
|
@ -181,7 +181,7 @@ class NodeTile extends BaseHtmlElement
|
|||
$link = Html::tag('a', ['href' => $url, 'data-base-target' => '_next'], $node->getHostname());
|
||||
} else {
|
||||
$link = Html::tag('a', ['href' => $url], $node->getAlias());
|
||||
if ($node->getBusinessProcess()->getName() !== $this->renderer->getBusinessProcess()->getName()) {
|
||||
if ($node->getBpConfig()->getName() !== $this->renderer->getBusinessProcess()->getName()) {
|
||||
$link->getAttributes()->add('data-base-target', '_next');
|
||||
} else {
|
||||
$link->getAttributes()->add('data-base-target', '_self');
|
||||
|
|
|
|||
|
|
@ -169,13 +169,13 @@ class TreeRenderer extends Renderer
|
|||
$div->add(Html::tag('span', ['class' => 'op'], $node->operatorHtml()));
|
||||
}
|
||||
|
||||
if (! $this->isLocked() && $node->getBusinessProcess()->getName() === $this->getBusinessProcess()->getName()) {
|
||||
if (! $this->isLocked() && $node->getBpConfig()->getName() === $this->getBusinessProcess()->getName()) {
|
||||
$div->add($this->getActionIcons($bp, $node));
|
||||
}
|
||||
|
||||
$ul = Html::tag('ul', [
|
||||
'class' => ['bp', 'sortable'],
|
||||
'data-sortable-disabled' => $this->isLocked() || $node->getBusinessProcess()->getName() !== $this->getBusinessProcess()->getName() ? 'true' : 'false',
|
||||
'data-sortable-disabled' => $this->isLocked() || $node->getBpConfig()->getName() !== $this->getBusinessProcess()->getName() ? 'true' : 'false',
|
||||
'data-sortable-invert-swap' => 'true',
|
||||
'data-sortable-data-id-attr' => 'id',
|
||||
'data-sortable-draggable' => '.movable',
|
||||
|
|
@ -187,7 +187,7 @@ class TreeRenderer extends Renderer
|
|||
'data-csrf-token' => CsrfToken::generate(),
|
||||
'data-action-url' => $this->getUrl()
|
||||
->overwriteParams([
|
||||
'config' => $node->getBusinessProcess()->getName(),
|
||||
'config' => $node->getBpConfig()->getName(),
|
||||
'node' => $node instanceof ImportedNode
|
||||
? $node->getNodeName()
|
||||
: (string) $node
|
||||
|
|
@ -222,7 +222,7 @@ class TreeRenderer extends Renderer
|
|||
$link->getAttributes()->set('data-base-target', '_next');
|
||||
$li->add($link);
|
||||
|
||||
if (! $this->isLocked() && $node->getBusinessProcess()->getName() === $this->getBusinessProcess()->getName()) {
|
||||
if (! $this->isLocked() && $node->getBpConfig()->getName() === $this->getBusinessProcess()->getName()) {
|
||||
$li->add($this->getActionIcons($bp, $node));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,12 +14,11 @@ class ServiceNode extends MonitoredNode
|
|||
|
||||
protected $icon = 'service';
|
||||
|
||||
public function __construct(BpConfig $bp, $object)
|
||||
public function __construct($object)
|
||||
{
|
||||
$this->name = $object->hostname . ';' . $object->service;
|
||||
$this->hostname = $object->hostname;
|
||||
$this->service = $object->service;
|
||||
$this->bp = $bp;
|
||||
if (isset($object->state)) {
|
||||
$this->setState($object->state);
|
||||
} else {
|
||||
|
|
@ -49,8 +48,8 @@ class ServiceNode extends MonitoredNode
|
|||
'service' => $this->getServiceDescription()
|
||||
);
|
||||
|
||||
if ($this->bp->hasBackendName()) {
|
||||
$params['backend'] = $this->bp->getBackendName();
|
||||
if ($this->getBpConfig()->hasBackendName()) {
|
||||
$params['backend'] = $this->getBpConfig()->getBackendName();
|
||||
}
|
||||
|
||||
return Url::fromPath('businessprocess/service/show', $params);
|
||||
|
|
|
|||
|
|
@ -333,11 +333,12 @@ class LegacyConfigParser
|
|||
$childNames[] = $val;
|
||||
}
|
||||
|
||||
$node = new BpNode($bp, (object) array(
|
||||
$node = new BpNode((object) array(
|
||||
'name' => $name,
|
||||
'operator' => $op_name,
|
||||
'child_names' => $childNames
|
||||
));
|
||||
$node->setBpConfig($bp);
|
||||
|
||||
$bp->addNode($name, $node);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,9 +57,9 @@ class HostNodeTest extends BaseTestCase
|
|||
protected function localhost()
|
||||
{
|
||||
$bp = new BpConfig();
|
||||
return new HostNode($bp, (object) array(
|
||||
return (new HostNode((object) array(
|
||||
'hostname' => 'localhost',
|
||||
'state' => 0,
|
||||
));
|
||||
)))->setBpConfig($bp);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,10 +47,10 @@ class ServiceNodeTest extends BaseTestCase
|
|||
protected function pingOnLocalhost()
|
||||
{
|
||||
$bp = new BpConfig();
|
||||
return new ServiceNode($bp, (object) array(
|
||||
return (new ServiceNode((object) array(
|
||||
'hostname' => 'localhost',
|
||||
'service' => 'ping <> pong',
|
||||
'state' => 0,
|
||||
));
|
||||
)))->setBpConfig($bp);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue