From 31520a7d21bd99b86635716b57edf0639e9814d0 Mon Sep 17 00:00:00 2001 From: Markus Frosch Date: Mon, 7 Nov 2016 16:04:37 +0100 Subject: [PATCH 1/3] IcingaService: Don't even try to render service_set related services refs #12891 --- library/Director/Objects/IcingaService.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/library/Director/Objects/IcingaService.php b/library/Director/Objects/IcingaService.php index a5f56624..ac39bddc 100644 --- a/library/Director/Objects/IcingaService.php +++ b/library/Director/Objects/IcingaService.php @@ -177,7 +177,10 @@ class IcingaService extends IcingaObject public function renderToLegacyConfig(IcingaConfig $config) { - if ($this->isApplyRule()) { + if ($this->get('service_set_id') !== null) { + return; + } + else if ($this->isApplyRule()) { $this->renderLegacyApplyToConfig($config); } else { parent::renderToLegacyConfig($config); @@ -214,7 +217,7 @@ class IcingaService extends IcingaObject public function toLegacyConfigString() { - if ($this->get('service_set_id')) { + if ($this->get('service_set_id') !== null) { return ''; } From a8a9278806392d337b31c8192c00c597784feb69 Mon Sep 17 00:00:00 2001 From: Markus Frosch Date: Mon, 7 Nov 2016 16:41:00 +0100 Subject: [PATCH 2/3] IcingaHostGroup(legacy): Render assign to a hostgroup_member list Supporting active-passive and masterless, by writing multiple versions of the object. refs #13049 --- library/Director/Objects/IcingaHostGroup.php | 99 ++++++++++++++++++++ 1 file changed, 99 insertions(+) diff --git a/library/Director/Objects/IcingaHostGroup.php b/library/Director/Objects/IcingaHostGroup.php index 4570c319..5c7959c6 100644 --- a/library/Director/Objects/IcingaHostGroup.php +++ b/library/Director/Objects/IcingaHostGroup.php @@ -2,6 +2,11 @@ namespace Icinga\Module\Director\Objects; +use Icinga\Data\Filter\Filter; +use Icinga\Exception\ProgrammingError; +use Icinga\Module\Director\IcingaConfig\IcingaConfig; +use Icinga\Module\Director\IcingaConfig\IcingaLegacyConfigHelper as c1; + class IcingaHostGroup extends IcingaObjectGroup { protected $table = 'icinga_hostgroup'; @@ -10,4 +15,98 @@ class IcingaHostGroup extends IcingaObjectGroup { return true; } + + public function renderToLegacyConfig(IcingaConfig $config) + { + if ($this->get('assign_filter') !== null) { + $this->renderLegacyApplyToConfig($config); + } else { + parent::renderToLegacyConfig($config); + } + } + + /** + * @param IcingaConfig $config + * + * @throws ProgrammingError When IcingaConfig deployment mode is not supported + */ + protected function renderLegacyApplyToConfig(IcingaConfig $config) + { + $conn = $this->getConnection(); + + $filter = Filter::fromQueryString($this->get('assign_filter')); + $hosts = HostApplyMatches::forFilter($filter, $conn); + $this->set('object_type', 'object'); + + $zoneMap = array(); + + foreach ($hosts as $hostname) { + $host = IcingaHost::load($hostname, $this->connection); + + if (($zoneId = $host->getResolvedProperty('zone_id')) !== null) { + $zoneMap[$zoneId][] = $hostname; + } else { + $zoneMap[0][] = $hostname; + } + } + + if (empty($zoneMap)) { + // no hosts matched + $file = $this->legacyZoneHostgroupFile($config); + $this->properties['hostgroup_members'] = array(); + $file->addLegacyObject($this); + + } else { + $allMembers = array(); + + foreach ($zoneMap as $zoneId => $members) { + $file = $this->legacyZoneHostgroupFile($config, $zoneId); + $this->properties['hostgroup_members'] = $members; + $file->addLegacyObject($this); + + $allMembers = array_merge($allMembers, $members); + } + + $deploymentMode = $config->getDeploymentMode(); + if ($deploymentMode === 'active-passive') { + $this->properties['hostgroup_members'] = $allMembers; + $this->legacyZoneHostgroupFile($config, 0) + ->addLegacyObject($this); + } else if ($deploymentMode == 'masterless') { + // nothing to add + } else { + throw new ProgrammingError('Unsupported deployment mode: %s' . $deploymentMode); + } + } + } + + protected function legacyZoneHostgroupFile(IcingaConfig $config, $zoneId = null) + { + if ($zoneId !== null) { + $zone = IcingaZone::load($zoneId, $this->getConnection())->getObjectName(); + } else { + $zone = $this->connection->getDefaultGlobalZoneName(); + } + return $config->configFile( + 'director/' . $zone . '/hostgroups' + ); + } + + protected function renderLegacyHostgroup_members() + { + if (empty($this->properties['hostgroup_members'])) { + return ''; + } + return c1::renderKeyValue('hostgroup_members', join(',', $this->properties['hostgroup_members'])); + } + + /** + * Note: rendered with renderLegacyHostgroup_members() + * + * @return string + */ + protected function renderLegacyAssign_filter() + { + return ''; + } } From 116016bbfcc9e0ad592127270bc54a2183be7f9a Mon Sep 17 00:00:00 2001 From: Markus Frosch Date: Fri, 11 Nov 2016 10:40:55 +0100 Subject: [PATCH 3/3] HostApplyMatches: Raise memory_limit for bigger caches refs #13049 --- library/Director/Objects/HostApplyMatches.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/library/Director/Objects/HostApplyMatches.php b/library/Director/Objects/HostApplyMatches.php index a6e68773..e3e860a0 100644 --- a/library/Director/Objects/HostApplyMatches.php +++ b/library/Director/Objects/HostApplyMatches.php @@ -48,8 +48,19 @@ class HostApplyMatches return self::$flatObjects; } + protected static function raiseLimits() + { + // Raise limits. TODO: do this in a failsafe way, and only if necessary + // Note: IcingaConfig also raises the limit for generation, **but** we need the higher limit for preview. + if ((string) ini_get('memory_limit') !== '-1') { + ini_set('memory_limit', '1024M'); + } + } + protected static function fetchFlatObjects(Db $db) { + self::raiseLimits(); + Benchmark::measure('HostApplyMatches: prefetching'); PrefetchCache::initialize($db); $all = IcingaHost::prefetchAll($db);