mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-30 17:24:18 +02:00
Various: stick with default exceptions...
...IDE hints are annoying
This commit is contained in:
parent
183ea4a949
commit
8c432285e7
@ -2,11 +2,12 @@
|
|||||||
|
|
||||||
namespace Icinga\Module\Director\CustomVariable;
|
namespace Icinga\Module\Director\CustomVariable;
|
||||||
|
|
||||||
use Icinga\Exception\ProgrammingError;
|
use Exception;
|
||||||
use Icinga\Module\Director\Db\Cache\PrefetchCache;
|
use Icinga\Module\Director\Db\Cache\PrefetchCache;
|
||||||
use Icinga\Module\Director\IcingaConfig\IcingaConfigHelper as c;
|
use Icinga\Module\Director\IcingaConfig\IcingaConfigHelper as c;
|
||||||
use Icinga\Module\Director\IcingaConfig\IcingaConfigRenderer;
|
use Icinga\Module\Director\IcingaConfig\IcingaConfigRenderer;
|
||||||
use Exception;
|
use InvalidArgumentException;
|
||||||
|
use LogicException;
|
||||||
|
|
||||||
abstract class CustomVariable implements IcingaConfigRenderer
|
abstract class CustomVariable implements IcingaConfigRenderer
|
||||||
{
|
{
|
||||||
@ -97,16 +98,15 @@ abstract class CustomVariable implements IcingaConfigRenderer
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param bool $renderExpressions
|
* @param bool $renderExpressions
|
||||||
* @throws ProgrammingError
|
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function toConfigString($renderExpressions = false)
|
public function toConfigString($renderExpressions = false)
|
||||||
{
|
{
|
||||||
// TODO: this should be an abstract method once we deprecate PHP < 5.3.9
|
// TODO: this should be an abstract method once we deprecate PHP < 5.3.9
|
||||||
throw new ProgrammingError(
|
throw new LogicException(sprintf(
|
||||||
'%s has no toConfigString() implementation',
|
'%s has no toConfigString() implementation',
|
||||||
get_class($this)
|
get_class($this)
|
||||||
);
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function flatten(array & $flat, $prefix)
|
public function flatten(array & $flat, $prefix)
|
||||||
@ -236,7 +236,7 @@ abstract class CustomVariable implements IcingaConfigRenderer
|
|||||||
// TODO: check for specific class/stdClass/interface?
|
// TODO: check for specific class/stdClass/interface?
|
||||||
return new CustomVariableDictionary($key, $value);
|
return new CustomVariableDictionary($key, $value);
|
||||||
} else {
|
} else {
|
||||||
throw new ProgrammingError('WTF (%s): %s', $key, var_export($value, 1));
|
throw new LogicException(sprintf('WTF (%s): %s', $key, var_export($value, 1)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -250,14 +250,14 @@ abstract class CustomVariable implements IcingaConfigRenderer
|
|||||||
$var = self::create($row->varname, json_decode($row->varvalue));
|
$var = self::create($row->varname, json_decode($row->varvalue));
|
||||||
break;
|
break;
|
||||||
case 'expression':
|
case 'expression':
|
||||||
throw new ProgrammingError(
|
throw new InvalidArgumentException(
|
||||||
'Icinga code expressions are not yet supported'
|
'Icinga code expressions are not yet supported'
|
||||||
);
|
);
|
||||||
default:
|
default:
|
||||||
throw new ProgrammingError(
|
throw new InvalidArgumentException(sprintf(
|
||||||
'%s is not a supported custom variable format',
|
'%s is not a supported custom variable format',
|
||||||
$row->format
|
$row->format
|
||||||
);
|
));
|
||||||
}
|
}
|
||||||
if (property_exists($row, 'checksum')) {
|
if (property_exists($row, 'checksum')) {
|
||||||
$var->setChecksum($row->checksum);
|
$var->setChecksum($row->checksum);
|
||||||
|
@ -2,13 +2,15 @@
|
|||||||
|
|
||||||
namespace Icinga\Module\Director\Data\Db;
|
namespace Icinga\Module\Director\Data\Db;
|
||||||
|
|
||||||
use Icinga\Exception\IcingaException as IE;
|
|
||||||
use Icinga\Exception\NotFoundError;
|
use Icinga\Exception\NotFoundError;
|
||||||
use Icinga\Module\Director\Db;
|
use Icinga\Module\Director\Db;
|
||||||
use Icinga\Module\Director\Exception\DuplicateKeyException;
|
use Icinga\Module\Director\Exception\DuplicateKeyException;
|
||||||
use Icinga\Module\Director\Util;
|
use Icinga\Module\Director\Util;
|
||||||
use Exception;
|
use InvalidArgumentException;
|
||||||
|
use LogicException;
|
||||||
|
use RuntimeException;
|
||||||
use Zend_Db_Adapter_Abstract;
|
use Zend_Db_Adapter_Abstract;
|
||||||
|
use Zend_Db_Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for ...
|
* Base class for ...
|
||||||
@ -88,7 +90,7 @@ abstract class DbObject
|
|||||||
|| $this->keyName === null
|
|| $this->keyName === null
|
||||||
|| $this->defaultProperties === null
|
|| $this->defaultProperties === null
|
||||||
) {
|
) {
|
||||||
throw new IE("Someone extending this class didn't RTFM");
|
throw new LogicException("Someone extending this class didn't RTFM");
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->properties = $this->defaultProperties;
|
$this->properties = $this->defaultProperties;
|
||||||
@ -227,8 +229,6 @@ abstract class DbObject
|
|||||||
*
|
*
|
||||||
* @param string $property Property
|
* @param string $property Property
|
||||||
*
|
*
|
||||||
* @throws IE
|
|
||||||
*
|
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function get($property)
|
public function get($property)
|
||||||
@ -255,7 +255,10 @@ abstract class DbObject
|
|||||||
protected function assertPropertyExists($key)
|
protected function assertPropertyExists($key)
|
||||||
{
|
{
|
||||||
if (! array_key_exists($key, $this->properties)) {
|
if (! array_key_exists($key, $this->properties)) {
|
||||||
throw new IE('Trying to get invalid property "%s"', $key);
|
throw new InvalidArgumentException(sprintf(
|
||||||
|
'Trying to get invalid property "%s"',
|
||||||
|
$key
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
@ -285,8 +288,6 @@ abstract class DbObject
|
|||||||
* @param string $key
|
* @param string $key
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
*
|
*
|
||||||
* @throws IE
|
|
||||||
*
|
|
||||||
* @return self
|
* @return self
|
||||||
*/
|
*/
|
||||||
public function set($key, $value)
|
public function set($key, $value)
|
||||||
@ -298,7 +299,11 @@ abstract class DbObject
|
|||||||
|
|
||||||
$func = 'validate' . ucfirst($key);
|
$func = 'validate' . ucfirst($key);
|
||||||
if (method_exists($this, $func) && $this->$func($value) !== true) {
|
if (method_exists($this, $func) && $this->$func($value) !== true) {
|
||||||
throw new IE('Got invalid value "%s" for "%s"', $value, $key);
|
throw new InvalidArgumentException(sprintf(
|
||||||
|
'Got invalid value "%s" for "%s"',
|
||||||
|
$value,
|
||||||
|
$key
|
||||||
|
));
|
||||||
}
|
}
|
||||||
$func = 'munge' . ucfirst($key);
|
$func = 'munge' . ucfirst($key);
|
||||||
if (method_exists($this, $func)) {
|
if (method_exists($this, $func)) {
|
||||||
@ -315,7 +320,10 @@ abstract class DbObject
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (! $this->hasProperty($key)) {
|
if (! $this->hasProperty($key)) {
|
||||||
throw new IE('Trying to set invalid key %s', $key);
|
throw new InvalidArgumentException(sprintf(
|
||||||
|
'Trying to set invalid key %s',
|
||||||
|
$key
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((is_numeric($value) || is_string($value))
|
if ((is_numeric($value) || is_string($value))
|
||||||
@ -325,7 +333,7 @@ abstract class DbObject
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($key === $this->getAutoincKeyName() && $this->hasBeenLoadedFromDb()) {
|
if ($key === $this->getAutoincKeyName() && $this->hasBeenLoadedFromDb()) {
|
||||||
throw new IE('Changing autoincremental key is not allowed');
|
throw new InvalidArgumentException('Changing autoincremental key is not allowed');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->reallySet($key, $value);
|
return $this->reallySet($key, $value);
|
||||||
@ -383,13 +391,12 @@ abstract class DbObject
|
|||||||
* Magic unsetter
|
* Magic unsetter
|
||||||
*
|
*
|
||||||
* @param string $key
|
* @param string $key
|
||||||
* @throws IE
|
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function __unset($key)
|
public function __unset($key)
|
||||||
{
|
{
|
||||||
if (! array_key_exists($key, $this->properties)) {
|
if (! array_key_exists($key, $this->properties)) {
|
||||||
throw new IE('Trying to unset invalid key');
|
throw new InvalidArgumentException('Trying to unset invalid key');
|
||||||
}
|
}
|
||||||
$this->properties[$key] = $this->defaultProperties[$key];
|
$this->properties[$key] = $this->defaultProperties[$key];
|
||||||
}
|
}
|
||||||
@ -398,13 +405,15 @@ abstract class DbObject
|
|||||||
* Runs set() for every key/value pair of the given Array
|
* Runs set() for every key/value pair of the given Array
|
||||||
*
|
*
|
||||||
* @param array $props Array of properties
|
* @param array $props Array of properties
|
||||||
* @throws IE
|
|
||||||
* @return self
|
* @return self
|
||||||
*/
|
*/
|
||||||
public function setProperties($props)
|
public function setProperties($props)
|
||||||
{
|
{
|
||||||
if (! is_array($props)) {
|
if (! is_array($props)) {
|
||||||
throw new IE('Array required, got %s', gettype($props));
|
throw new InvalidArgumentException(sprintf(
|
||||||
|
'Array required, got %s',
|
||||||
|
gettype($props)
|
||||||
|
));
|
||||||
}
|
}
|
||||||
foreach ($props as $key => $value) {
|
foreach ($props as $key => $value) {
|
||||||
$this->set($key, $value);
|
$this->set($key, $value);
|
||||||
@ -638,11 +647,11 @@ abstract class DbObject
|
|||||||
{
|
{
|
||||||
foreach ($properties as $key => $val) {
|
foreach ($properties as $key => $val) {
|
||||||
if (! array_key_exists($key, $this->properties)) {
|
if (! array_key_exists($key, $this->properties)) {
|
||||||
throw new IE(
|
throw new LogicException(sprintf(
|
||||||
'Trying to set invalid %s key "%s". DB schema change?',
|
'Trying to set invalid %s key "%s". DB schema change?',
|
||||||
$this->table,
|
$this->table,
|
||||||
$key
|
$key
|
||||||
);
|
));
|
||||||
}
|
}
|
||||||
if ($val === null) {
|
if ($val === null) {
|
||||||
$this->properties[$key] = null;
|
$this->properties[$key] = null;
|
||||||
@ -695,6 +704,7 @@ abstract class DbObject
|
|||||||
* Ändert den entsprechenden Datensatz in der Datenbank
|
* Ändert den entsprechenden Datensatz in der Datenbank
|
||||||
*
|
*
|
||||||
* @return int Anzahl der geänderten Zeilen
|
* @return int Anzahl der geänderten Zeilen
|
||||||
|
* @throws \Zend_Db_Adapter_Exception
|
||||||
*/
|
*/
|
||||||
protected function updateDb()
|
protected function updateDb()
|
||||||
{
|
{
|
||||||
@ -716,6 +726,7 @@ abstract class DbObject
|
|||||||
* Fügt der Datenbank-Tabelle einen entsprechenden Datensatz hinzu
|
* Fügt der Datenbank-Tabelle einen entsprechenden Datensatz hinzu
|
||||||
*
|
*
|
||||||
* @return int Anzahl der betroffenen Zeilen
|
* @return int Anzahl der betroffenen Zeilen
|
||||||
|
* @throws \Zend_Db_Adapter_Exception
|
||||||
*/
|
*/
|
||||||
protected function insertIntoDb()
|
protected function insertIntoDb()
|
||||||
{
|
{
|
||||||
@ -740,7 +751,7 @@ abstract class DbObject
|
|||||||
*
|
*
|
||||||
* @param DbConnection $db
|
* @param DbConnection $db
|
||||||
* @return bool Whether storing succeeded
|
* @return bool Whether storing succeeded
|
||||||
* @throws IE
|
* @throws DuplicateKeyException
|
||||||
*/
|
*/
|
||||||
public function store(DbConnection $db = null)
|
public function store(DbConnection $db = null)
|
||||||
{
|
{
|
||||||
@ -749,7 +760,11 @@ abstract class DbObject
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($this->validate() !== true) {
|
if ($this->validate() !== true) {
|
||||||
throw new IE('%s[%s] validation failed', $this->table, $this->getLogId());
|
throw new InvalidArgumentException(sprintf(
|
||||||
|
'%s[%s] validation failed',
|
||||||
|
$this->table,
|
||||||
|
$this->getLogId()
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->hasBeenLoadedFromDb() && ! $this->hasBeenModified()) {
|
if ($this->hasBeenLoadedFromDb() && ! $this->hasBeenModified()) {
|
||||||
@ -767,11 +782,11 @@ abstract class DbObject
|
|||||||
$result = true;
|
$result = true;
|
||||||
$this->onUpdate();
|
$this->onUpdate();
|
||||||
} else {
|
} else {
|
||||||
throw new IE(
|
throw new RuntimeException(sprintf(
|
||||||
'FAILED storing %s "%s"',
|
'FAILED storing %s "%s"',
|
||||||
$table,
|
$table,
|
||||||
$this->getLogId()
|
$this->getLogId()
|
||||||
);
|
));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if ($id && $this->existsInDb()) {
|
if ($id && $this->existsInDb()) {
|
||||||
@ -797,25 +812,21 @@ abstract class DbObject
|
|||||||
$this->onInsert();
|
$this->onInsert();
|
||||||
$result = true;
|
$result = true;
|
||||||
} else {
|
} else {
|
||||||
throw new IE(
|
throw new RuntimeException(sprintf(
|
||||||
'FAILED to store new %s "%s"',
|
'FAILED to store new %s "%s"',
|
||||||
$table,
|
$table,
|
||||||
$this->getLogId()
|
$this->getLogId()
|
||||||
);
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception $e) {
|
} catch (Zend_Db_Exception $e) {
|
||||||
if ($e instanceof IE) {
|
throw new RuntimeException(sprintf(
|
||||||
throw $e;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new IE(
|
|
||||||
'Storing %s[%s] failed: %s {%s}',
|
'Storing %s[%s] failed: %s {%s}',
|
||||||
$this->table,
|
$this->table,
|
||||||
$this->getLogId(),
|
$this->getLogId(),
|
||||||
$e->getMessage(),
|
$e->getMessage(),
|
||||||
var_export($this->getProperties(), 1) // TODO: Remove properties
|
var_export($this->getProperties(), 1) // TODO: Remove properties
|
||||||
);
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->modifiedProperties = array();
|
$this->modifiedProperties = array();
|
||||||
@ -823,6 +834,7 @@ abstract class DbObject
|
|||||||
$this->loadedProperties = $this->properties;
|
$this->loadedProperties = $this->properties;
|
||||||
$this->onStore();
|
$this->onStore();
|
||||||
$this->loadedFromDb = true;
|
$this->loadedFromDb = true;
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -842,17 +854,17 @@ abstract class DbObject
|
|||||||
/**
|
/**
|
||||||
* @param string $key
|
* @param string $key
|
||||||
* @return self
|
* @return self
|
||||||
* @throws IE
|
* @throws InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
protected function setKey($key)
|
protected function setKey($key)
|
||||||
{
|
{
|
||||||
$keyname = $this->getKeyName();
|
$keyname = $this->getKeyName();
|
||||||
if (is_array($keyname)) {
|
if (is_array($keyname)) {
|
||||||
if (! is_array($key)) {
|
if (! is_array($key)) {
|
||||||
throw new IE(
|
throw new InvalidArgumentException(sprintf(
|
||||||
'%s has a multicolumn key, array required',
|
'%s has a multicolumn key, array required',
|
||||||
$this->table
|
$this->table
|
||||||
);
|
));
|
||||||
}
|
}
|
||||||
foreach ($keyname as $k) {
|
foreach ($keyname as $k) {
|
||||||
if (! array_key_exists($k, $key)) {
|
if (! array_key_exists($k, $key)) {
|
||||||
@ -943,27 +955,27 @@ abstract class DbObject
|
|||||||
$table = $this->table;
|
$table = $this->table;
|
||||||
|
|
||||||
if (! $this->hasBeenLoadedFromDb()) {
|
if (! $this->hasBeenLoadedFromDb()) {
|
||||||
throw new IE(
|
throw new LogicException(sprintf(
|
||||||
'Cannot delete %s "%s", it has not been loaded from Db',
|
'Cannot delete %s "%s", it has not been loaded from Db',
|
||||||
$table,
|
$table,
|
||||||
$this->getLogId()
|
$this->getLogId()
|
||||||
);
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! $this->existsInDb()) {
|
if (! $this->existsInDb()) {
|
||||||
throw new IE(
|
throw new InvalidArgumentException(sprintf(
|
||||||
'Cannot delete %s "%s", it does not exist',
|
'Cannot delete %s "%s", it does not exist',
|
||||||
$table,
|
$table,
|
||||||
$this->getLogId()
|
$this->getLogId()
|
||||||
);
|
));
|
||||||
}
|
}
|
||||||
$this->beforeDelete();
|
$this->beforeDelete();
|
||||||
if (! $this->deleteFromDb()) {
|
if (! $this->deleteFromDb()) {
|
||||||
throw new IE(
|
throw new RuntimeException(sprintf(
|
||||||
'Deleting %s (%s) FAILED',
|
'Deleting %s (%s) FAILED',
|
||||||
$table,
|
$table,
|
||||||
$this->getLogId()
|
$this->getLogId()
|
||||||
);
|
));
|
||||||
}
|
}
|
||||||
// $this->log(sprintf('%s "%s" has been DELETED', $table, this->getLogId()));
|
// $this->log(sprintf('%s "%s" has been DELETED', $table, this->getLogId()));
|
||||||
$this->onDelete();
|
$this->onDelete();
|
||||||
@ -988,7 +1000,6 @@ abstract class DbObject
|
|||||||
* @param DbConnection|null $connection
|
* @param DbConnection|null $connection
|
||||||
*
|
*
|
||||||
* @return static
|
* @return static
|
||||||
* @throws IE
|
|
||||||
*/
|
*/
|
||||||
public static function create($properties = array(), DbConnection $connection = null)
|
public static function create($properties = array(), DbConnection $connection = null)
|
||||||
{
|
{
|
||||||
@ -1075,7 +1086,6 @@ abstract class DbObject
|
|||||||
* @param $id
|
* @param $id
|
||||||
* @param DbConnection $connection
|
* @param DbConnection $connection
|
||||||
* @return static
|
* @return static
|
||||||
* @throws IE
|
|
||||||
* @throws NotFoundError
|
* @throws NotFoundError
|
||||||
*/
|
*/
|
||||||
public static function loadWithAutoIncId($id, DbConnection $connection)
|
public static function loadWithAutoIncId($id, DbConnection $connection)
|
||||||
@ -1105,7 +1115,6 @@ abstract class DbObject
|
|||||||
* @param $id
|
* @param $id
|
||||||
* @param DbConnection $connection
|
* @param DbConnection $connection
|
||||||
* @return static
|
* @return static
|
||||||
* @throws IE
|
|
||||||
* @throws NotFoundError
|
* @throws NotFoundError
|
||||||
*/
|
*/
|
||||||
public static function load($id, DbConnection $connection)
|
public static function load($id, DbConnection $connection)
|
||||||
@ -1127,7 +1136,6 @@ abstract class DbObject
|
|||||||
* @param string|null $keyColumn
|
* @param string|null $keyColumn
|
||||||
*
|
*
|
||||||
* @return static[]
|
* @return static[]
|
||||||
* @throws IE
|
|
||||||
*/
|
*/
|
||||||
public static function loadAll(DbConnection $connection, $query = null, $keyColumn = null)
|
public static function loadAll(DbConnection $connection, $query = null, $keyColumn = null)
|
||||||
{
|
{
|
||||||
@ -1161,7 +1169,6 @@ abstract class DbObject
|
|||||||
* @param bool $force
|
* @param bool $force
|
||||||
*
|
*
|
||||||
* @return static[]
|
* @return static[]
|
||||||
* @throws IE
|
|
||||||
*/
|
*/
|
||||||
public static function prefetchAll(DbConnection $connection, $force = false)
|
public static function prefetchAll(DbConnection $connection, $force = false)
|
||||||
{
|
{
|
||||||
|
@ -2,12 +2,12 @@
|
|||||||
|
|
||||||
namespace Icinga\Module\Director\Db\Cache;
|
namespace Icinga\Module\Director\Db\Cache;
|
||||||
|
|
||||||
use Icinga\Exception\ProgrammingError;
|
|
||||||
use Icinga\Module\Director\CustomVariable\CustomVariable;
|
use Icinga\Module\Director\CustomVariable\CustomVariable;
|
||||||
use Icinga\Module\Director\Db;
|
use Icinga\Module\Director\Db;
|
||||||
use Icinga\Module\Director\Objects\IcingaObject;
|
use Icinga\Module\Director\Objects\IcingaObject;
|
||||||
use Icinga\Module\Director\Resolver\HostServiceBlacklist;
|
use Icinga\Module\Director\Resolver\HostServiceBlacklist;
|
||||||
use Icinga\Module\Director\Resolver\TemplateTree;
|
use Icinga\Module\Director\Resolver\TemplateTree;
|
||||||
|
use LogicException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Central prefetch cache
|
* Central prefetch cache
|
||||||
@ -45,14 +45,14 @@ class PrefetchCache
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws ProgrammingError
|
* @throws LogicException
|
||||||
*
|
*
|
||||||
* @return self
|
* @return self
|
||||||
*/
|
*/
|
||||||
public static function instance()
|
public static function instance()
|
||||||
{
|
{
|
||||||
if (static::$instance === null) {
|
if (static::$instance === null) {
|
||||||
throw new ProgrammingError('Prefetch cache has not been loaded');
|
throw new LogicException('Prefetch cache has not been loaded');
|
||||||
}
|
}
|
||||||
|
|
||||||
return static::$instance;
|
return static::$instance;
|
||||||
|
@ -5,10 +5,7 @@ namespace Icinga\Module\Director\IcingaConfig;
|
|||||||
use Icinga\Application\Benchmark;
|
use Icinga\Application\Benchmark;
|
||||||
use Icinga\Application\Hook;
|
use Icinga\Application\Hook;
|
||||||
use Icinga\Application\Icinga;
|
use Icinga\Application\Icinga;
|
||||||
use Icinga\Exception\ConfigurationError;
|
|
||||||
use Icinga\Exception\IcingaException;
|
|
||||||
use Icinga\Exception\NotFoundError;
|
use Icinga\Exception\NotFoundError;
|
||||||
use Icinga\Exception\ProgrammingError;
|
|
||||||
use Icinga\Module\Director\Application\MemoryLimit;
|
use Icinga\Module\Director\Application\MemoryLimit;
|
||||||
use Icinga\Module\Director\Db\Cache\PrefetchCache;
|
use Icinga\Module\Director\Db\Cache\PrefetchCache;
|
||||||
use Icinga\Module\Director\Db;
|
use Icinga\Module\Director\Db;
|
||||||
@ -17,6 +14,9 @@ use Icinga\Module\Director\Objects\IcingaObject;
|
|||||||
use Icinga\Module\Director\Util;
|
use Icinga\Module\Director\Util;
|
||||||
use Icinga\Module\Director\Objects\IcingaHost;
|
use Icinga\Module\Director\Objects\IcingaHost;
|
||||||
use Icinga\Module\Director\Objects\IcingaZone;
|
use Icinga\Module\Director\Objects\IcingaZone;
|
||||||
|
use InvalidArgumentException;
|
||||||
|
use LogicException;
|
||||||
|
use RuntimeException;
|
||||||
|
|
||||||
class IcingaConfig
|
class IcingaConfig
|
||||||
{
|
{
|
||||||
@ -28,9 +28,7 @@ class IcingaConfig
|
|||||||
|
|
||||||
protected $lastActivityChecksum;
|
protected $lastActivityChecksum;
|
||||||
|
|
||||||
/**
|
/** @var \Zend_Db_Adapter_Abstract */
|
||||||
* @var \Zend_Db_Adapter_Abstract
|
|
||||||
*/
|
|
||||||
protected $db;
|
protected $db;
|
||||||
|
|
||||||
protected $connection;
|
protected $connection;
|
||||||
@ -83,17 +81,17 @@ class IcingaConfig
|
|||||||
if ($this->isLegacy()) {
|
if ($this->isLegacy()) {
|
||||||
return $this->deploymentModeV1;
|
return $this->deploymentModeV1;
|
||||||
} else {
|
} else {
|
||||||
throw new ProgrammingError('There is no deployment mode for Icinga 2 config format!');
|
throw new LogicException('There is no deployment mode for Icinga 2 config format!');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setConfigFormat($format)
|
public function setConfigFormat($format)
|
||||||
{
|
{
|
||||||
if (! in_array($format, array('v1', 'v2'))) {
|
if (! in_array($format, array('v1', 'v2'))) {
|
||||||
throw new ConfigurationError(
|
throw new InvalidArgumentException(sprintf(
|
||||||
'Only Icinga v1 and v2 config format is supported, got "%s"',
|
'Only Icinga v1 and v2 config format is supported, got "%s"',
|
||||||
$format
|
$format
|
||||||
);
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->configFormat = $format;
|
$this->configFormat = $format;
|
||||||
@ -438,8 +436,6 @@ class IcingaConfig
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws IcingaException
|
|
||||||
*
|
|
||||||
* @return self
|
* @return self
|
||||||
*/
|
*/
|
||||||
protected function generateFromDb()
|
protected function generateFromDb()
|
||||||
@ -453,7 +449,7 @@ class IcingaConfig
|
|||||||
ini_set('zend.enable_gc', 0);
|
ini_set('zend.enable_gc', 0);
|
||||||
|
|
||||||
if (! $this->connection->isPgsql() && $this->db->quote("1\0") !== '\'1\\0\'') {
|
if (! $this->connection->isPgsql() && $this->db->quote("1\0") !== '\'1\\0\'') {
|
||||||
throw new IcingaException(
|
throw new RuntimeException(
|
||||||
'Refusing to render the configuration, your DB layer corrupts binary data.'
|
'Refusing to render the configuration, your DB layer corrupts binary data.'
|
||||||
. ' You might be affected by Zend Framework bug #655'
|
. ' You might be affected by Zend Framework bug #655'
|
||||||
);
|
);
|
||||||
@ -754,10 +750,10 @@ apply Service for (title => params in host.vars["%s"]) {
|
|||||||
foreach (Hook::all('Director\\ShipConfigFiles') as $hook) {
|
foreach (Hook::all('Director\\ShipConfigFiles') as $hook) {
|
||||||
foreach ($hook->fetchFiles() as $filename => $file) {
|
foreach ($hook->fetchFiles() as $filename => $file) {
|
||||||
if (array_key_exists($filename, $this->files)) {
|
if (array_key_exists($filename, $this->files)) {
|
||||||
throw new ProgrammingError(
|
throw new LogicException(sprintf(
|
||||||
'Cannot ship one file twice: %s',
|
'Cannot ship one file twice: %s',
|
||||||
$filename
|
$filename
|
||||||
);
|
));
|
||||||
}
|
}
|
||||||
if ($file instanceof IcingaConfigFile) {
|
if ($file instanceof IcingaConfigFile) {
|
||||||
$this->files[$filename] = $file;
|
$this->files[$filename] = $file;
|
||||||
|
@ -19,6 +19,8 @@ use Icinga\Module\Director\IcingaConfig\IcingaConfigRenderer;
|
|||||||
use Icinga\Module\Director\IcingaConfig\IcingaConfigHelper as c;
|
use Icinga\Module\Director\IcingaConfig\IcingaConfigHelper as c;
|
||||||
use Icinga\Module\Director\IcingaConfig\IcingaLegacyConfigHelper as c1;
|
use Icinga\Module\Director\IcingaConfig\IcingaLegacyConfigHelper as c1;
|
||||||
use Icinga\Module\Director\Repository\IcingaTemplateRepository;
|
use Icinga\Module\Director\Repository\IcingaTemplateRepository;
|
||||||
|
use InvalidArgumentException;
|
||||||
|
use LogicException;
|
||||||
|
|
||||||
abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
|
abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
|
||||||
{
|
{
|
||||||
@ -448,7 +450,7 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
|
|||||||
*
|
*
|
||||||
* @param Filter|string $filter
|
* @param Filter|string $filter
|
||||||
*
|
*
|
||||||
* @throws ProgrammingError
|
* @throws LogicException
|
||||||
*
|
*
|
||||||
* @return self
|
* @return self
|
||||||
*/
|
*/
|
||||||
@ -461,11 +463,11 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
|
|||||||
$type = get_class($this);
|
$type = get_class($this);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new ProgrammingError(
|
throw new LogicException(sprintf(
|
||||||
'I can only assign for applied objects or objects with native'
|
'I can only assign for applied objects or objects with native'
|
||||||
. ' support for assigments, got %s',
|
. ' support for assigments, got %s',
|
||||||
$type
|
$type
|
||||||
);
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
// @codingStandardsIgnoreEnd
|
// @codingStandardsIgnoreEnd
|
||||||
@ -739,10 +741,10 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
|
|||||||
} elseif ($value === '' || $value === null) {
|
} elseif ($value === '' || $value === null) {
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
throw new ProgrammingError(
|
throw new InvalidArgumentException(sprintf(
|
||||||
'Got invalid boolean: %s',
|
'Got invalid boolean: %s',
|
||||||
var_export($value, 1)
|
var_export($value, 1)
|
||||||
);
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1231,10 +1233,10 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
|
|||||||
protected function assertCustomVarsSupport()
|
protected function assertCustomVarsSupport()
|
||||||
{
|
{
|
||||||
if (! $this->supportsCustomVars()) {
|
if (! $this->supportsCustomVars()) {
|
||||||
throw new ProgrammingError(
|
throw new LogicException(sprintf(
|
||||||
'Objects of type "%s" have no custom vars',
|
'Objects of type "%s" have no custom vars',
|
||||||
$this->getType()
|
$this->getType()
|
||||||
);
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
@ -1243,10 +1245,10 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
|
|||||||
protected function assertGroupsSupport()
|
protected function assertGroupsSupport()
|
||||||
{
|
{
|
||||||
if (! $this->supportsGroups()) {
|
if (! $this->supportsGroups()) {
|
||||||
throw new ProgrammingError(
|
throw new LogicException(sprintf(
|
||||||
'Objects of type "%s" have no groups',
|
'Objects of type "%s" have no groups',
|
||||||
$this->getType()
|
$this->getType()
|
||||||
);
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
@ -1255,10 +1257,10 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
|
|||||||
protected function assertRangesSupport()
|
protected function assertRangesSupport()
|
||||||
{
|
{
|
||||||
if (! $this->supportsRanges()) {
|
if (! $this->supportsRanges()) {
|
||||||
throw new ProgrammingError(
|
throw new LogicException(sprintf(
|
||||||
'Objects of type "%s" have no ranges',
|
'Objects of type "%s" have no ranges',
|
||||||
$this->getType()
|
$this->getType()
|
||||||
);
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
@ -1267,10 +1269,10 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
|
|||||||
protected function assertImportsSupport()
|
protected function assertImportsSupport()
|
||||||
{
|
{
|
||||||
if (! $this->supportsImports()) {
|
if (! $this->supportsImports()) {
|
||||||
throw new ProgrammingError(
|
throw new LogicException(sprintf(
|
||||||
'Objects of type "%s" have no imports',
|
'Objects of type "%s" have no imports',
|
||||||
$this->getType()
|
$this->getType()
|
||||||
);
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
@ -1305,7 +1307,6 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @return bool
|
* @return bool
|
||||||
* @throws ProgrammingError
|
|
||||||
*/
|
*/
|
||||||
public function hasInitializedVars()
|
public function hasInitializedVars()
|
||||||
{
|
{
|
||||||
@ -1580,7 +1581,10 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
|
|||||||
} elseif ($deploymentMode === 'masterless') {
|
} elseif ($deploymentMode === 'masterless') {
|
||||||
// no additional config
|
// no additional config
|
||||||
} else {
|
} else {
|
||||||
throw new ProgrammingError('Unsupported deployment mode: %s' .$deploymentMode);
|
throw new LogicException(sprintf(
|
||||||
|
'Unsupported deployment mode: %s',
|
||||||
|
$deploymentMode
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
$config->configFile(
|
$config->configFile(
|
||||||
@ -2336,10 +2340,10 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
|
|||||||
return $this->get('object_name');
|
return $this->get('object_name');
|
||||||
} else {
|
} else {
|
||||||
// TODO: replace with an exception once finished
|
// TODO: replace with an exception once finished
|
||||||
throw new ProgrammingError(
|
throw new LogicException(sprintf(
|
||||||
'Trying to access "object_name" for an instance of "%s"',
|
'Trying to access "object_name" for an instance of "%s"',
|
||||||
get_class($this)
|
get_class($this)
|
||||||
);
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2443,7 +2447,6 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
|
|||||||
* @param $type
|
* @param $type
|
||||||
* @param Db $db
|
* @param Db $db
|
||||||
* @return IcingaObject[]
|
* @return IcingaObject[]
|
||||||
* @throws ProgrammingError
|
|
||||||
*/
|
*/
|
||||||
public static function loadAllExternalObjectsByType($type, Db $db)
|
public static function loadAllExternalObjectsByType($type, Db $db)
|
||||||
{
|
{
|
||||||
@ -2452,10 +2455,10 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
|
|||||||
$dummy = $class::create();
|
$dummy = $class::create();
|
||||||
|
|
||||||
if (is_array($dummy->getKeyName())) {
|
if (is_array($dummy->getKeyName())) {
|
||||||
throw new ProgrammingError(
|
throw new LogicException(sprintf(
|
||||||
'There is no support for loading external objects of type "%s"',
|
'There is no support for loading external objects of type "%s"',
|
||||||
$type
|
$type
|
||||||
);
|
));
|
||||||
} else {
|
} else {
|
||||||
$query = $db->getDbAdapter()
|
$query = $db->getDbAdapter()
|
||||||
->select()
|
->select()
|
||||||
@ -2593,7 +2596,10 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
|
|||||||
|
|
||||||
$k = $relKey;
|
$k = $relKey;
|
||||||
} else {
|
} else {
|
||||||
throw new ProgrammingError('No such relation: %s', $relKey);
|
throw new LogicException(sprintf(
|
||||||
|
'No such relation: %s',
|
||||||
|
$relKey
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace Icinga\Module\Director\Objects;
|
namespace Icinga\Module\Director\Objects;
|
||||||
|
|
||||||
use Icinga\Exception\ProgrammingError;
|
use LogicException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class is required for historical reasons
|
* This class is required for historical reasons
|
||||||
@ -15,10 +15,10 @@ class IcingaObjectLegacyAssignments
|
|||||||
public static function applyToObject(IcingaObject $object, $values)
|
public static function applyToObject(IcingaObject $object, $values)
|
||||||
{
|
{
|
||||||
if (! $object->supportsAssignments()) {
|
if (! $object->supportsAssignments()) {
|
||||||
throw new ProgrammingError(
|
throw new LogicException(sprintf(
|
||||||
'I can only assign for applied objects, got %s',
|
'I can only assign for applied objects, got %s',
|
||||||
$object->object_type
|
$object->object_type
|
||||||
);
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($values === null) {
|
if ($values === null) {
|
||||||
@ -70,7 +70,7 @@ class IcingaObjectLegacyAssignments
|
|||||||
|
|
||||||
protected static function throwCompatError()
|
protected static function throwCompatError()
|
||||||
{
|
{
|
||||||
throw new ProgrammingError(
|
throw new LogicException(
|
||||||
'You ran into an unexpected compatibility issue. Please report'
|
'You ran into an unexpected compatibility issue. Please report'
|
||||||
. ' this with details helping us to reproduce this to the'
|
. ' this with details helping us to reproduce this to the'
|
||||||
. ' Icinga project'
|
. ' Icinga project'
|
||||||
|
@ -3,10 +3,9 @@
|
|||||||
namespace Icinga\Module\Director\Objects;
|
namespace Icinga\Module\Director\Objects;
|
||||||
|
|
||||||
use Icinga\Data\Filter\Filter;
|
use Icinga\Data\Filter\Filter;
|
||||||
use Icinga\Exception\IcingaException;
|
|
||||||
use Icinga\Exception\ProgrammingError;
|
|
||||||
use Icinga\Module\Director\Exception\DuplicateKeyException;
|
use Icinga\Module\Director\Exception\DuplicateKeyException;
|
||||||
use Icinga\Module\Director\IcingaConfig\IcingaConfig;
|
use Icinga\Module\Director\IcingaConfig\IcingaConfig;
|
||||||
|
use InvalidArgumentException;
|
||||||
|
|
||||||
class IcingaServiceSet extends IcingaObject
|
class IcingaServiceSet extends IcingaObject
|
||||||
{
|
{
|
||||||
@ -55,7 +54,10 @@ class IcingaServiceSet extends IcingaObject
|
|||||||
$this->set('object_name', $keyComponents[0]);
|
$this->set('object_name', $keyComponents[0]);
|
||||||
$this->set('object_type', 'template');
|
$this->set('object_type', 'template');
|
||||||
} else {
|
} else {
|
||||||
throw new IcingaException('Can not parse key: %s', $key);
|
throw new InvalidArgumentException(sprintf(
|
||||||
|
'Can not parse key: %s',
|
||||||
|
$key
|
||||||
|
));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return parent::setKey($key);
|
return parent::setKey($key);
|
||||||
@ -287,7 +289,7 @@ class IcingaServiceSet extends IcingaObject
|
|||||||
$name = $this->getObjectName();
|
$name = $this->getObjectName();
|
||||||
|
|
||||||
if ($this->isObject() && $this->get('host_id') === null) {
|
if ($this->isObject() && $this->get('host_id') === null) {
|
||||||
throw new ProgrammingError(
|
throw new InvalidArgumentException(
|
||||||
'A Service Set cannot be an object with no related host'
|
'A Service Set cannot be an object with no related host'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -425,7 +425,7 @@ class IcingaHostTest extends BaseTestCase
|
|||||||
$a->store();
|
$a->store();
|
||||||
try {
|
try {
|
||||||
$b->store();
|
$b->store();
|
||||||
} catch (IcingaException $e) {
|
} catch (\RuntimeException $e) {
|
||||||
$msg = $e->getMessage();
|
$msg = $e->getMessage();
|
||||||
$matchMysql = strpos(
|
$matchMysql = strpos(
|
||||||
$msg,
|
$msg,
|
||||||
|
@ -107,7 +107,7 @@ class IcingaServiceSetTest extends IcingaObjectTestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \Icinga\Exception\IcingaException
|
* @expectedException \RuntimeException
|
||||||
*/
|
*/
|
||||||
public function testCreatingSetWithoutType()
|
public function testCreatingSetWithoutType()
|
||||||
{
|
{
|
||||||
@ -118,9 +118,9 @@ class IcingaServiceSetTest extends IcingaObjectTestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \Icinga\Exception\ProgrammingError
|
* @expectedException \InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
public function testCreatingHostSetWithoutHost()
|
public function testCreatingServiceSetWithoutHost()
|
||||||
{
|
{
|
||||||
$set = IcingaServiceSet::create(array(
|
$set = IcingaServiceSet::create(array(
|
||||||
'object_name' => '___TEST__set_BAD2',
|
'object_name' => '___TEST__set_BAD2',
|
||||||
|
@ -51,7 +51,7 @@ class IcingaServiceTest extends BaseTestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException Icinga\Exception\ProgrammingError
|
* @expectedException \LogicException
|
||||||
*/
|
*/
|
||||||
public function testRefusesAssignRulesWhenNotBeingAnApply()
|
public function testRefusesAssignRulesWhenNotBeingAnApply()
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user