Modification: move modification handling to...

...a dedicated namespace
This commit is contained in:
Thomas Gelf 2016-11-23 12:27:55 +01:00
parent 9acdba0dc4
commit 2b98629f3e
8 changed files with 53 additions and 27 deletions

View file

@ -2,25 +2,30 @@
namespace Icinga\Module\Businessprocess\Forms;
use Icinga\Web\Notification;
use Icinga\Web\Request;
use Icinga\Module\Businessprocess\Node;
use Icinga\Module\Businessprocess\BpNode;
use Icinga\Module\Businessprocess\Form;
use Icinga\Module\Businessprocess\ProcessChanges;
use Icinga\Module\Businessprocess\BusinessProcess;
use Icinga\Module\Businessprocess\Modification\ProcessChanges;
use Icinga\Module\Businessprocess\Web\Form\QuickForm;
use Icinga\Module\Monitoring\Backend\MonitoringBackend;
use Icinga\Web\Notification;
use Icinga\Web\Session\SessionNamespace;
class ProcessForm extends Form
class ProcessForm extends QuickForm
{
/** @var MonitoringBackend */
protected $backend;
protected $process;
/** @var BusinessProcess */
protected $bp;
/** @var BpNode */
protected $node;
protected $objectList = array();
protected $processList = array();
/** @var SessionNamespace */
protected $session;
public function setup()
@ -37,7 +42,7 @@ class ProcessForm extends Form
'label' => $this->translate('Title'),
'description' => $this->translate(
'Usually this title will be shown for this node. Equals name'
. ' if not given'
. ' if not given'
),
));

View file

@ -3,6 +3,8 @@
namespace Icinga\Module\Businessprocess;
use Icinga\Application\Benchmark;
use Icinga\Exception\ProgrammingError;
use Icinga\Module\Businessprocess\Modification\ProcessChanges;
use Icinga\Module\Monitoring\Backend\MonitoringBackend;
use Icinga\Data\Filter\Filter;
use Exception;
@ -360,7 +362,7 @@ class BusinessProcess
$hostStatus = $backend->select()->from('hostStatus', array(
'hostname' => 'host_name',
'last_state_change' => $hostStateChangeColumn,
'last_state_change' => $hostStateChangeColumn,
'in_downtime' => 'host_in_downtime',
'ack' => 'host_acknowledged',
'state' => $hostStateColumn
@ -369,7 +371,7 @@ class BusinessProcess
$serviceStatus = $backend->select()->from('serviceStatus', array(
'hostname' => 'host_name',
'service' => 'service_description',
'last_state_change' => $serviceStateChangeColumn,
'last_state_change' => $serviceStateChangeColumn,
'in_downtime' => 'service_in_downtime',
'ack' => 'service_acknowledged',
'state' => $serviceStateColumn
@ -381,7 +383,7 @@ class BusinessProcess
foreach ($hostStatus as $row) {
$this->handleDbRow($row);
}
}
ksort($this->root_nodes);
Benchmark::measure('Got states for business process ' . $this->getName());
@ -398,7 +400,10 @@ class BusinessProcess
$key .= ';Hoststatus';
}
// We fetch more states than we need, so skip unknown ones
if (! $this->hasNode($key)) return;
if (! $this->hasNode($key)) {
return;
}
$node = $this->getNode($key);
if ($row->state !== null) {
@ -527,6 +532,11 @@ class BusinessProcess
return $this;
}
public function removeNode($name)
{
throw new ProgrammingError('Not implemented yet');
}
public function listBpNodes()
{
$nodes = array();

View file

@ -3,13 +3,12 @@
namespace Icinga\Module\Businessprocess;
use Icinga\Application\Icinga;
use Icinga\Module\Businessprocess\BusinessProcess;
use Icinga\Module\Businessprocess\Modification\ProcessChanges;
use Icinga\Module\Businessprocess\Storage\LegacyStorage;
use Icinga\Module\Businessprocess\Web\Component\ActionBar;
use Icinga\Module\Monitoring\Backend;
use Icinga\Module\Businessprocess\Web\Form\FormLoader;
use Icinga\Web\Controller as ModuleController;
use Icinga\Web\Notification;
use Icinga\Module\Businessprocess\Web\Form\FormLoader;
use Icinga\Web\Widget;
class Controller extends ModuleController

View file

@ -1,7 +1,9 @@
<?php
namespace Icinga\Module\Businessprocess;
namespace Icinga\Module\Businessprocess\Modification;
use Icinga\Module\Businessprocess\BusinessProcess;
use Icinga\Module\Businessprocess\Node;
use Icinga\Exception\ProgrammingError;
/**
@ -22,7 +24,7 @@ abstract class NodeAction
/** @var string Name of the node this action applies to */
protected $nodeName;
/** @var array Properties which should be preeserved when serializing this action */
/** @var array Properties which should be preserved when serializing this action */
protected $preserveProperties = array();
/**
@ -82,8 +84,8 @@ abstract class NodeAction
*/
public static function create($actionName, $nodeName)
{
$classname = __NAMESPACE__ . '\\Node' . ucfirst($actionName) . 'Action';
$object = new $classname($nodeName);
$className = __NAMESPACE__ . '\\Node' . ucfirst($actionName) . 'Action';
$object = new $className($nodeName);
return $object;
}
@ -114,7 +116,7 @@ abstract class NodeAction
* @param $string
* @return NodeAction
*/
public static function unserialize($string)
public static function unSerialize($string)
{
$object = json_decode($string);
$action = self::create($object->actionName, $object->nodeName);

View file

@ -1,7 +1,10 @@
<?php
namespace Icinga\Module\Businessprocess;
namespace Icinga\Module\Businessprocess\Modification;
use Icinga\Module\Businessprocess\BusinessProcess;
use Icinga\Module\Businessprocess\BpNode;
use Icinga\Module\Businessprocess\Node;
use stdClass;
class NodeCreateAction extends NodeAction

View file

@ -1,6 +1,9 @@
<?php
namespace Icinga\Module\Businessprocess;
namespace Icinga\Module\Businessprocess\Modification;
use Icinga\Module\Businessprocess\BusinessProcess;
use Icinga\Module\Businessprocess\Node;
class NodeModifyAction extends NodeAction
{

View file

@ -1,6 +1,8 @@
<?php
namespace Icinga\Module\Businessprocess;
namespace Icinga\Module\Businessprocess\Modification;
use Icinga\Module\Businessprocess\BusinessProcess;
/**
* NodeRemoveAction

View file

@ -1,7 +1,9 @@
<?php
namespace Icinga\Module\Businessprocess;
namespace Icinga\Module\Businessprocess\Modification;
use Icinga\Module\Businessprocess\BusinessProcess;
use Icinga\Module\Businessprocess\Node;
use Icinga\Web\Session\SessionNamespace as Session;
class ProcessChanges
@ -41,7 +43,7 @@ class ProcessChanges
if ($actions = $session->get($key)) {
foreach ($actions as $string) {
$changes->push(NodeAction::unserialize($string));
$changes->push(NodeAction::unSerialize($string));
}
}
$changes->session = $session;
@ -64,7 +66,7 @@ class ProcessChanges
/**
* @param Node|string $nodeName
* @param array $properties
* @param object $properties
* @param Node $parent
*
* @return $this
@ -86,7 +88,7 @@ class ProcessChanges
*/
public function deleteNode(Node $node)
{
return $this->push(new NodeDeleteAction($node));
return $this->push(new NodeRemoveAction($node));
}
/**