2015-02-12 19:54:47 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Icinga\Module\Businessprocess;
|
|
|
|
|
|
2015-10-16 16:48:57 -04:00
|
|
|
use Exception;
|
2015-02-12 19:54:47 -05:00
|
|
|
|
2019-01-28 02:50:42 -05:00
|
|
|
class ImportedNode extends BpNode
|
2015-02-12 19:54:47 -05:00
|
|
|
{
|
2019-01-28 02:50:42 -05:00
|
|
|
/** @var BpConfig */
|
|
|
|
|
protected $parentBp;
|
|
|
|
|
|
2016-11-28 18:34:28 -05:00
|
|
|
/** @var string */
|
2015-02-12 19:54:47 -05:00
|
|
|
protected $configName;
|
|
|
|
|
|
2017-01-03 05:17:17 -05:00
|
|
|
/** @var string */
|
|
|
|
|
protected $nodeName;
|
|
|
|
|
|
2016-11-28 18:34:28 -05:00
|
|
|
/** @var BpNode */
|
2019-01-28 02:50:42 -05:00
|
|
|
protected $importedNode;
|
2015-02-12 19:54:47 -05:00
|
|
|
|
2019-01-28 02:50:42 -05:00
|
|
|
/** @var string */
|
|
|
|
|
protected $className = 'process subtree';
|
2015-10-05 06:34:47 -04:00
|
|
|
|
2019-01-28 02:50:42 -05:00
|
|
|
/** @var string */
|
2019-01-22 05:21:40 -05:00
|
|
|
protected $icon = 'download';
|
|
|
|
|
|
2019-02-04 02:37:36 -05:00
|
|
|
public function __construct(BpConfig $parentBp, $object)
|
2015-02-12 19:54:47 -05:00
|
|
|
{
|
2019-02-04 02:37:36 -05:00
|
|
|
$this->parentBp = $parentBp;
|
2015-02-12 19:54:47 -05:00
|
|
|
$this->configName = $object->configName;
|
2019-01-28 02:50:42 -05:00
|
|
|
$this->nodeName = $object->node;
|
|
|
|
|
|
2019-02-04 02:37:36 -05:00
|
|
|
parent::__construct((object) [
|
2019-02-14 09:32:51 -05:00
|
|
|
'name' => '@' . $this->configName . ':' . $this->nodeName,
|
|
|
|
|
'operator' => null,
|
|
|
|
|
'child_names' => null
|
|
|
|
|
]);
|
2017-01-03 05:17:17 -05:00
|
|
|
}
|
|
|
|
|
|
2016-11-28 18:34:28 -05:00
|
|
|
/**
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2015-02-12 19:54:47 -05:00
|
|
|
public function getConfigName()
|
|
|
|
|
{
|
|
|
|
|
return $this->configName;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-28 18:34:28 -05:00
|
|
|
/**
|
2019-01-28 02:50:42 -05:00
|
|
|
* @return string
|
2016-11-28 18:34:28 -05:00
|
|
|
*/
|
2019-01-28 02:50:42 -05:00
|
|
|
public function getNodeName()
|
2015-02-12 19:54:47 -05:00
|
|
|
{
|
2019-01-28 02:50:42 -05:00
|
|
|
return $this->nodeName;
|
2015-02-12 19:54:47 -05:00
|
|
|
}
|
|
|
|
|
|
2019-02-21 05:45:45 -05:00
|
|
|
public function getIdentifier()
|
|
|
|
|
{
|
|
|
|
|
return $this->getName();
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-04 02:37:36 -05:00
|
|
|
public function getBpConfig()
|
|
|
|
|
{
|
|
|
|
|
if ($this->bp === null) {
|
|
|
|
|
$this->bp = $this->parentBp->getImportedConfig($this->configName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this->bp;
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-12 19:54:47 -05:00
|
|
|
public function getAlias()
|
|
|
|
|
{
|
2019-01-28 02:50:42 -05:00
|
|
|
if ($this->alias === null) {
|
|
|
|
|
$this->alias = $this->importedNode()->getAlias();
|
2015-02-12 19:54:47 -05:00
|
|
|
}
|
2017-01-03 05:17:17 -05:00
|
|
|
|
2019-01-28 02:50:42 -05:00
|
|
|
return $this->alias;
|
2015-02-12 19:54:47 -05:00
|
|
|
}
|
|
|
|
|
|
2019-01-28 02:50:42 -05:00
|
|
|
public function getOperator()
|
2015-02-12 19:54:47 -05:00
|
|
|
{
|
2019-01-28 02:50:42 -05:00
|
|
|
if ($this->operator === null) {
|
|
|
|
|
$this->operator = $this->importedNode()->getOperator();
|
2015-02-12 19:54:47 -05:00
|
|
|
}
|
2017-01-03 05:17:17 -05:00
|
|
|
|
2019-01-28 02:50:42 -05:00
|
|
|
return $this->operator;
|
2015-02-12 19:54:47 -05:00
|
|
|
}
|
|
|
|
|
|
2019-01-28 02:50:42 -05:00
|
|
|
public function getChildNames()
|
2015-02-12 19:54:47 -05:00
|
|
|
{
|
2019-01-28 02:50:42 -05:00
|
|
|
if ($this->childNames === null) {
|
|
|
|
|
$this->childNames = $this->importedNode()->getChildNames();
|
2015-02-12 19:54:47 -05:00
|
|
|
}
|
2016-11-28 18:34:28 -05:00
|
|
|
|
2019-01-28 02:50:42 -05:00
|
|
|
return $this->childNames;
|
2015-02-12 19:54:47 -05:00
|
|
|
}
|
2016-11-28 18:34:28 -05:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return BpNode
|
|
|
|
|
*/
|
2019-01-28 02:50:42 -05:00
|
|
|
protected function importedNode()
|
2017-01-03 05:17:17 -05:00
|
|
|
{
|
2019-01-28 02:50:42 -05:00
|
|
|
if ($this->importedNode === null) {
|
|
|
|
|
try {
|
2019-02-04 02:37:36 -05:00
|
|
|
$this->importedNode = $this->getBpConfig()->getBpNode($this->nodeName);
|
2019-01-28 02:50:42 -05:00
|
|
|
} catch (Exception $e) {
|
|
|
|
|
return $this->createFailedNode($e);
|
2016-11-28 18:34:28 -05:00
|
|
|
}
|
2015-02-12 19:54:47 -05:00
|
|
|
}
|
2017-01-03 05:17:17 -05:00
|
|
|
|
2019-01-28 02:50:42 -05:00
|
|
|
return $this->importedNode;
|
2015-03-16 04:08:00 -04:00
|
|
|
}
|
|
|
|
|
|
2016-11-28 18:34:28 -05:00
|
|
|
/**
|
|
|
|
|
* @param Exception $e
|
|
|
|
|
*
|
|
|
|
|
* @return BpNode
|
|
|
|
|
*/
|
|
|
|
|
protected function createFailedNode(Exception $e)
|
2015-03-16 04:08:00 -04:00
|
|
|
{
|
2019-01-28 02:50:42 -05:00
|
|
|
$this->parentBp->addError($e->getMessage());
|
2019-02-04 02:37:36 -05:00
|
|
|
$node = new BpNode((object) array(
|
2017-01-03 05:17:17 -05:00
|
|
|
'name' => $this->getName(),
|
2016-11-28 18:34:28 -05:00
|
|
|
'operator' => '&',
|
2019-01-28 02:50:42 -05:00
|
|
|
'child_names' => []
|
2015-03-16 04:08:00 -04:00
|
|
|
));
|
2019-02-04 02:37:36 -05:00
|
|
|
$node->setBpConfig($this->getBpConfig());
|
2016-11-28 18:34:28 -05:00
|
|
|
$node->setState(2);
|
|
|
|
|
$node->setMissing(false)
|
|
|
|
|
->setDowntime(false)
|
|
|
|
|
->setAck(false)
|
|
|
|
|
->setAlias($e->getMessage());
|
|
|
|
|
|
|
|
|
|
return $node;
|
|
|
|
|
}
|
2015-02-12 19:54:47 -05:00
|
|
|
}
|