1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
<?php
namespace Icinga\Module\Director\Job;
use Icinga\Module\Director\Deployment\ConditionalConfigRenderer;
use Icinga\Module\Director\Deployment\ConditionalDeployment;
use Icinga\Module\Director\Deployment\DeploymentGracePeriod;
use Icinga\Module\Director\Hook\JobHook;
use Icinga\Module\Director\Web\Form\QuickForm;
class ConfigJob extends JobHook
{
public function run()
{
$db = $this->db();
$deployer = new ConditionalDeployment($db);
$renderer = new ConditionalConfigRenderer($db);
if ($grace = $this->getSetting('grace_period')) {
$deployer->setGracePeriod(new DeploymentGracePeriod((int) $grace, $db));
}
if ($this->getSetting('force_generate') === 'y') {
$renderer->forceRendering();
}
$deployer->deploy($renderer->getConfig());
}
public static function addSettingsFormFields(QuickForm $form)
{
$form->addElement('select', 'force_generate', [
'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',
'multiOptions' => [
'y' => $form->translate('Yes'),
'n' => $form->translate('No'),
]
]);
$form->addElement('select', 'deploy_when_changed', [
'label' => $form->translate('Deploy modified config'),
'description' => $form->translate(
'This allows you to immediately deploy a modified configuration'
),
'value' => 'n',
'multiOptions' => [
'y' => $form->translate('Yes'),
'n' => $form->translate('No'),
]
]);
$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,
));
return $form;
}
public static function getDescription(QuickForm $form)
{
return $form->translate(
'The Config job allows you to generate and eventually deploy your'
. ' Icinga 2 configuration'
);
}
}
|