2016-04-22 09:53:59 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Icinga\Module\Director\Job;
|
|
|
|
|
2022-03-21 21:09:33 +01:00
|
|
|
use Icinga\Module\Director\Deployment\ConditionalConfigRenderer;
|
|
|
|
use Icinga\Module\Director\Deployment\ConditionalDeployment;
|
|
|
|
use Icinga\Module\Director\Deployment\DeploymentGracePeriod;
|
2016-04-22 09:53:59 +02:00
|
|
|
use Icinga\Module\Director\Hook\JobHook;
|
2016-05-25 11:37:38 +02:00
|
|
|
use Icinga\Module\Director\Web\Form\QuickForm;
|
2016-04-22 09:53:59 +02:00
|
|
|
|
|
|
|
class ConfigJob extends JobHook
|
|
|
|
{
|
|
|
|
public function run()
|
|
|
|
{
|
2016-05-25 11:37:38 +02:00
|
|
|
$db = $this->db();
|
2022-03-21 21:09:33 +01:00
|
|
|
$deployer = new ConditionalDeployment($db);
|
|
|
|
$renderer = new ConditionalConfigRenderer($db);
|
|
|
|
if ($grace = $this->getSetting('grace_period')) {
|
|
|
|
$deployer->setGracePeriod(new DeploymentGracePeriod((int) $grace, $db));
|
2016-06-16 14:22:54 +02:00
|
|
|
}
|
2022-03-21 21:09:33 +01:00
|
|
|
if ($this->getSetting('force_generate') === 'y') {
|
|
|
|
$renderer->forceRendering();
|
2016-05-25 11:37:38 +02:00
|
|
|
}
|
|
|
|
|
2022-03-21 21:09:33 +01:00
|
|
|
$deployer->deploy($renderer->getConfig());
|
2016-06-16 14:22:54 +02:00
|
|
|
}
|
|
|
|
|
2016-05-17 16:05:00 +02:00
|
|
|
public static function addSettingsFormFields(QuickForm $form)
|
|
|
|
{
|
2022-03-21 21:09:33 +01:00
|
|
|
$form->addElement('select', 'force_generate', [
|
2016-05-25 11:37:38 +02:00
|
|
|
'label' => $form->translate('Force rendering'),
|
|
|
|
'description' => $form->translate(
|
|
|
|
'Whether rendering should be forced. If not enforced, this'
|
|
|
|
. ' job re-renders the configuration only when there have been'
|
|
|
|
. ' activities since the last rendered config'
|
|
|
|
),
|
|
|
|
'value' => 'n',
|
2022-03-21 21:09:33 +01:00
|
|
|
'multiOptions' => [
|
2016-05-25 11:37:38 +02:00
|
|
|
'y' => $form->translate('Yes'),
|
|
|
|
'n' => $form->translate('No'),
|
2022-03-21 21:09:33 +01:00
|
|
|
]
|
|
|
|
]);
|
2016-05-25 11:37:38 +02:00
|
|
|
|
2022-03-21 21:09:33 +01:00
|
|
|
$form->addElement('select', 'deploy_when_changed', [
|
2016-05-17 16:05:00 +02:00
|
|
|
'label' => $form->translate('Deploy modified config'),
|
|
|
|
'description' => $form->translate(
|
|
|
|
'This allows you to immediately deploy a modified configuration'
|
|
|
|
),
|
|
|
|
'value' => 'n',
|
2022-03-21 21:09:33 +01:00
|
|
|
'multiOptions' => [
|
2016-05-17 16:05:00 +02:00
|
|
|
'y' => $form->translate('Yes'),
|
|
|
|
'n' => $form->translate('No'),
|
2022-03-21 21:09:33 +01:00
|
|
|
]
|
|
|
|
]);
|
2016-05-17 16:05:00 +02:00
|
|
|
|
2016-05-25 11:37:38 +02:00
|
|
|
$form->addElement('text', 'grace_period', array(
|
|
|
|
'label' => $form->translate('Grace period'),
|
|
|
|
'description' => $form->translate(
|
|
|
|
'When deploying configuration, wait at least this amount of'
|
|
|
|
. ' seconds unless the next deployment should take place'
|
|
|
|
),
|
|
|
|
'value' => 600,
|
|
|
|
));
|
2016-05-17 16:05:00 +02:00
|
|
|
|
2016-05-25 11:37:38 +02:00
|
|
|
return $form;
|
2016-04-22 09:53:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function getDescription(QuickForm $form)
|
|
|
|
{
|
|
|
|
return $form->translate(
|
2016-05-17 16:05:00 +02:00
|
|
|
'The Config job allows you to generate and eventually deploy your'
|
2016-06-28 12:27:33 +02:00
|
|
|
. ' Icinga 2 configuration'
|
2016-04-22 09:53:59 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|