Add deployment status cli
This commit is contained in:
parent
8e0761176e
commit
0a54fda6b6
|
@ -4,6 +4,7 @@ namespace Icinga\Module\Director\Clicommands;
|
|||
|
||||
use Icinga\Application\Benchmark;
|
||||
use Icinga\Module\Director\Cli\Command;
|
||||
use Icinga\Module\Director\Deployment\DeploymentStatus;
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -133,45 +133,8 @@ class ConfigController extends ActionController
|
|||
}
|
||||
$db = $this->db();
|
||||
$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);
|
||||
if ($stageName = $api->getActiveStageName()) {
|
||||
$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
|
||||
);
|
||||
}
|
||||
$result = $status->getDeploymentStatus($this->params->get('configs'), $this->params->get('activities'));
|
||||
|
||||
$this->sendJson($this->getResponse(), (object) $result);
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ namespace Icinga\Module\Director\Deployment;
|
|||
|
||||
use Icinga\Module\Director\Core\CoreApi;
|
||||
use Icinga\Module\Director\Db;
|
||||
use Icinga\Module\Director\Objects\DirectorDeploymentLog;
|
||||
|
||||
class DeploymentStatus
|
||||
{
|
||||
|
@ -17,6 +18,49 @@ class DeploymentStatus
|
|||
$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)
|
||||
{
|
||||
$db = $this->db->getDbAdapter();
|
||||
|
|
Loading…
Reference in New Issue