ConfigController: do not show an exception...

...when a deployment fails
This commit is contained in:
Thomas Gelf 2016-12-14 14:56:22 +01:00
parent f614d75edc
commit ade7b1415e
1 changed files with 35 additions and 20 deletions

View File

@ -59,7 +59,6 @@ class ConfigController extends ActionController
$this->assertPermission('director/deploy');
// TODO: require POST
$isApiRequest = $this->getRequest()->isApiRequest();
$checksum = $this->params->get('checksum');
if ($checksum) {
$config = IcingaConfig::load(Util::hex2binary($checksum), $this->db());
@ -68,10 +67,22 @@ class ConfigController extends ActionController
$checksum = $config->getHexChecksum();
}
try {
$this->api()->wipeInactiveStages($this->db());
} catch (Exception $e) {
$this->deploymentFailed($checksum, $e->getMessage());
}
if ($this->api()->dumpConfig($config, $this->db())) {
if ($isApiRequest) {
$this->deploymentSucceeded($checksum);
} else {
$this->deploymentFailed($checksum);
}
}
protected function deploymentSucceeded($checksum)
{
if ($this->getRequest()->isApiRequest()) {
return $this->sendJson((object) array('checksum' => $checksum));
} else {
$url = Url::fromPath('director/config/deployments');
@ -80,18 +91,22 @@ class ConfigController extends ActionController
);
$this->redirectNow($url);
}
}
protected function deploymentFailed($checksum, $error = null)
{
$extra = $error ? ': ' . $error: '';
if ($this->getRequest()->isApiRequest()) {
return $this->sendJsonError('Config deployment failed' . $extra);
} else {
if ($isApiRequest) {
return $this->sendJsonError('Config deployment failed');
} else {
$url = Url::fromPath('director/config/show', array('checksum' => $checksum));
Notification::success(
$this->translate('Config deployment failed')
$url = Url::fromPath('director/config/files', array('checksum' => $checksum));
Notification::error(
$this->translate('Config deployment failed') . $extra
);
$this->redirectNow($url);
}
}
}
public function activitiesAction()
{