From 3f8f7bd1eb3a128e6c659eecf221665ee102bcb7 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Wed, 7 Oct 2020 09:30:17 +0200 Subject: [PATCH] DeploymentStatus: new helper * this also adds director/config/deployment-status refs #2187 --- application/controllers/ConfigController.php | 19 +++++++++++- .../Director/Deployment/DeploymentStatus.php | 30 +++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 library/Director/Deployment/DeploymentStatus.php diff --git a/application/controllers/ConfigController.php b/application/controllers/ConfigController.php index d0459f48..b193bc80 100644 --- a/application/controllers/ConfigController.php +++ b/application/controllers/ConfigController.php @@ -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 */ diff --git a/library/Director/Deployment/DeploymentStatus.php b/library/Director/Deployment/DeploymentStatus.php new file mode 100644 index 00000000..ec7be55d --- /dev/null +++ b/library/Director/Deployment/DeploymentStatus.php @@ -0,0 +1,30 @@ +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); + } +}