IcingaConfig: accept legacy config objects/files

This commit is contained in:
Thomas Gelf 2016-07-22 18:15:22 +02:00
parent 634d9e07b6
commit 398312a0e4
2 changed files with 47 additions and 0 deletions

View File

@ -5,6 +5,7 @@ namespace Icinga\Module\Director\IcingaConfig;
use Icinga\Application\Benchmark;
use Icinga\Application\Hook;
use Icinga\Application\Icinga;
use Icinga\Exception\ConfigurationError;
use Icinga\Exception\IcingaException;
use Icinga\Exception\ProgrammingError;
use Icinga\Module\Director\Db\Cache\PrefetchCache;
@ -34,6 +35,8 @@ class IcingaConfig
protected $generationTime;
protected $configFormat = 'v2';
public static $table = 'director_generated_config';
public function __construct(Db $connection)
@ -64,6 +67,30 @@ class IcingaConfig
return count($this->files);
}
public function getConfigFormat()
{
return $this->configFormat;
}
public function setConfigFormat($format)
{
if (! in_array($format, array('v1', 'v2'))) {
throw new ConfigurationError(
'Only Icinga v1 and v2 config format is supported, got "%s"',
$format
);
}
$this->configFormat = $format;
return $this;
}
public function isLegacy()
{
return $this->configFormat === 'v1';
}
public function getObjectCount()
{
$cnt = 0;

View File

@ -81,6 +81,15 @@ class IcingaConfigFile
return $this->checksum;
}
public function addLegacyObjects($objects)
{
foreach ($objects as $object) {
$this->addLegacyObject($object);
}
return $this;
}
public function addObjects($objects)
{
foreach ($objects as $object) {
@ -94,7 +103,18 @@ class IcingaConfigFile
{
$this->content .= $object->toConfigString();
$this->checksum = null;
return $this->addObjectStats($object);
}
public function addLegacyObject(IcingaObject $object)
{
$this->content .= $object->toLegacyConfigString();
$this->checksum = null;
return $this->addObjectStats($object);
}
protected function addObjectStats(IcingaObject $object)
{
if ($object->hasProperty('object_type')) {
$type = $object->object_type;