Add deployment status cli

This commit is contained in:
Gianluca Piccolo 2020-10-07 16:53:32 +02:00 committed by Thomas Gelf
parent 8e0761176e
commit 0a54fda6b6
3 changed files with 59 additions and 38 deletions

View File

@ -4,6 +4,7 @@ namespace Icinga\Module\Director\Clicommands;
use Icinga\Application\Benchmark; use Icinga\Application\Benchmark;
use Icinga\Module\Director\Cli\Command; use Icinga\Module\Director\Cli\Command;
use Icinga\Module\Director\Deployment\DeploymentStatus;
use Icinga\Module\Director\IcingaConfig\IcingaConfig; use Icinga\Module\Director\IcingaConfig\IcingaConfig;
/** /**
@ -119,4 +120,17 @@ class ConfigCommand extends Command
); );
} }
} }
/**
* Checks the deployments status
*/
public function deploymentstatusAction()
{
$db = $this->db();
$api = $this->api();
$status = new DeploymentStatus($db, $api);
$result = $status->getDeploymentStatus($this->params->get('configs'), $this->params->get('activities'));
printf(json_encode($result));
}
} }

View File

@ -133,45 +133,8 @@ class ConfigController extends ActionController
} }
$db = $this->db(); $db = $this->db();
$api = $this->api(); $api = $this->api();
try {
if (DirectorDeploymentLog::hasUncollected($db)) {
$api->collectLogFiles($db);
}
} catch (Exception $e) {
// Ignore eventual issues while talking to Icinga
}
$activeConfiguration = null;
$lastActivityLogChecksum = null;
$configChecksum = null;
$status = new DeploymentStatus($db, $api); $status = new DeploymentStatus($db, $api);
if ($stageName = $api->getActiveStageName()) { $result = $status->getDeploymentStatus($this->params->get('configs'), $this->params->get('activities'));
$activityLogChecksum = DirectorDeploymentLog::getRelatedToActiveStage($api, $db);
$lastActivityLogChecksum = bin2hex($activityLogChecksum->last_activity_checksum);
$configChecksum = $status->getConfigChecksumForStageName($stageName);
$activeConfiguration = [
'stage_name' => $stageName,
'config' => ($configChecksum) ? : null,
'activity' => $lastActivityLogChecksum
];
}
$result = [
'active_configuration' => (object) $activeConfiguration,
];
if ($configChecksumsListToVerify = $this->params->get('configs')) {
$result['configs'] = $status->getDeploymentStatusForConfigChecksums(
explode(',', $configChecksumsListToVerify),
$configChecksum
);
}
if ($activityLogChecksumsListToVerify = $this->params->get('activities')) {
$result['activities'] = $status->getDeploymentStatusForActivityLogChecksums(
explode(',', $activityLogChecksumsListToVerify),
$lastActivityLogChecksum
);
}
$this->sendJson($this->getResponse(), (object) $result); $this->sendJson($this->getResponse(), (object) $result);
} }

View File

@ -4,6 +4,7 @@ namespace Icinga\Module\Director\Deployment;
use Icinga\Module\Director\Core\CoreApi; use Icinga\Module\Director\Core\CoreApi;
use Icinga\Module\Director\Db; use Icinga\Module\Director\Db;
use Icinga\Module\Director\Objects\DirectorDeploymentLog;
class DeploymentStatus class DeploymentStatus
{ {
@ -17,6 +18,49 @@ class DeploymentStatus
$this->api = $api; $this->api = $api;
} }
public function getDeploymentStatus($configs = null, $activities = null)
{
try {
if (DirectorDeploymentLog::hasUncollected($this->db)) {
$this->api->collectLogFiles($this->db);
}
} catch (Exception $e) {
// Ignore eventual issues while talking to Icinga
}
$activeConfiguration = null;
$lastActivityLogChecksum = null;
$configChecksum = null;
if ($stageName = $this->api->getActiveStageName()) {
$activityLogChecksum = DirectorDeploymentLog::getRelatedToActiveStage($this->api, $this->db);
$lastActivityLogChecksum = bin2hex($activityLogChecksum->last_activity_checksum);
$configChecksum = $this->getConfigChecksumForStageName($stageName);
$activeConfiguration = [
'stage_name' => $stageName,
'config' => ($configChecksum) ? : null,
'activity' => $lastActivityLogChecksum
];
}
$result = [
'active_configuration' => (object) $activeConfiguration,
];
if ($configs) {
$result['configs'] = $this->getDeploymentStatusForConfigChecksums(
explode(',', $configs),
$configChecksum
);
}
if ($activities) {
$result['activities'] = $this->getDeploymentStatusForActivityLogChecksums(
explode(',', $activities),
$lastActivityLogChecksum
);
}
return $result;
}
public function getConfigChecksumForStageName($stageName) public function getConfigChecksumForStageName($stageName)
{ {
$db = $this->db->getDbAdapter(); $db = $this->db->getDbAdapter();