DeploymentStatus: new helper

* this also adds director/config/deployment-status

refs #2187
This commit is contained in:
Thomas Gelf 2020-10-07 09:30:17 +02:00
parent e2d753bad7
commit 3f8f7bd1eb
2 changed files with 48 additions and 1 deletions

View File

@ -6,6 +6,7 @@ use Icinga\Data\Filter\Filter;
use Icinga\Exception\IcingaException;
use Icinga\Exception\NotFoundError;
use Icinga\Module\Director\ConfigDiff;
use Icinga\Module\Director\Deployment\DeploymentStatus;
use Icinga\Module\Director\Forms\DeployConfigForm;
use Icinga\Module\Director\Forms\SettingsForm;
use Icinga\Module\Director\IcingaConfig\IcingaConfig;
@ -15,7 +16,6 @@ use Icinga\Module\Director\Web\Table\ActivityLogTable;
use Icinga\Module\Director\Web\Table\ConfigFileDiffTable;
use Icinga\Module\Director\Web\Table\DeploymentLogTable;
use Icinga\Module\Director\Web\Table\GeneratedConfigFileTable;
use Icinga\Module\Director\Util;
use Icinga\Module\Director\Web\Controller\ActionController;
use Icinga\Module\Director\Web\Tabs\InfraTabs;
use Icinga\Module\Director\Web\Widget\ActivityLogInfo;
@ -126,6 +126,23 @@ class ConfigController extends ActionController
}
}
public function deploymentStatusAction()
{
if ($this->sendNotFoundUnlessRestApi()) {
return;
}
$api = $this->api();
$status = new DeploymentStatus($this->db(), $api);
$stageName = $api->getActiveStageName();
$checksum = $status->getConfigChecksumForStageName($stageName);
$this->sendJson($this->getResponse(), (object) [
'active_configuration' => (object) [
'active_stage_name' => $stageName,
'active_checksum' => $checksum
],
]);
}
/**
* @throws \Icinga\Security\SecurityException
*/

View File

@ -0,0 +1,30 @@
<?php
namespace Icinga\Module\Director\Deployment;
use Icinga\Module\Director\Core\CoreApi;
use Icinga\Module\Director\Db;
class DeploymentStatus
{
protected $db;
protected $api;
public function __construct(Db $db, CoreApi $api)
{
$this->db = $db;
$this->api = $api;
}
public function getConfigChecksumForStageName($stageName)
{
$db = $this->db->getDbAdapter();
$query = $db->select()->from(
array('l' => 'director_deployment_log'),
array('checksum' => $this->db->dbHexFunc('l.config_checksum'))
)->where('l.stage_name = ?', $stageName);
return $db->fetchOne($query);
}
}