Skip to content

Commit 96ddfcb

Browse files
committed
WIP add defined type
1 parent 14a1bfb commit 96ddfcb

File tree

3 files changed

+73
-91
lines changed

3 files changed

+73
-91
lines changed

manifests/collect.pp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Create systemd units for repacking a given database type
2+
define pe_databases::collect (
3+
String $database_type = $title,
4+
String $command = undef,
5+
Boolean $disable_maintenance = false,
6+
String $on_cal = undef,
7+
) {
8+
9+
Service {
10+
notify => Exec['pe_databases_daemon_reload'],
11+
}
12+
File {
13+
notify => Exec['pe_databases_daemon_reload'],
14+
}
15+
16+
$ensure_service = $disable_maintenance ? {
17+
true => stopped,
18+
default => running,
19+
}
20+
21+
$ensure_file = $disable_maintenance ? {
22+
true => absent,
23+
default => present
24+
}
25+
26+
file {"/etc/systemd/system/pe_databases-${database_type}.service":
27+
ensure => $ensure_file,
28+
content => epp('pe_databases/service.epp', { 'tables' => $database_type, 'command' => $command }),
29+
}
30+
file {"/etc/systemd/system/pe_databases-${database_type}.timer":
31+
ensure => $ensure_file,
32+
content => epp('pe_databases/timer.epp', { 'tables' => $database_type, 'on_cal' => $on_cal }),
33+
}
34+
35+
service { "pe_databases-${database_type}.service": }
36+
service { "pe_databases-${database_type}.timer":
37+
ensure => $ensure_service,
38+
enable => ! $disable_maintenance,
39+
subscribe => File["/etc/systemd/system/pe_databases-${database_type}.timer"],
40+
}
41+
}

manifests/pg_repack.pp

Lines changed: 25 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,6 @@
77
Integer $jobs = $facts['processors']['count'] / 4
88
) {
99

10-
$ensure_service = $disable_maintenance ? {
11-
true => stopped,
12-
default => running,
13-
}
14-
15-
$ensure_file = $disable_maintenance ? {
16-
true => absent,
17-
default => present
18-
}
19-
2010
# PE 2019.1 starting shipping versioned pe-postgres packages where all paths are versioned.
2111
# So, prior to 2019.1 use a non-versioned path, and after use a versioned path.
2212
# TODO: Use $pe_databases::psql_version after identifying why it is cast to ${psql_version}00000 in spec tests.
@@ -37,101 +27,46 @@
3727
$reports_table = '-t reports'
3828
$resource_events_table = '-t resource_events'
3929

40-
Service {
41-
notify => Exec['pe_databases_daemon_reload'],
42-
}
43-
File {
44-
notify => Exec['pe_databases_daemon_reload'],
45-
}
46-
47-
file { '/etc/systemd/system/pe_databases-facts.service':
48-
ensure => $ensure_file,
49-
content => epp('pe_databases/service.epp', { 'tables' => 'facts', 'command' => "${repack} ${repack_jobs} ${facts_tables}" }),
50-
}
51-
file {'/etc/systemd/system/pe_databases-facts.timer':
52-
ensure => $ensure_file,
53-
content => epp('pe_databases/timer.epp', { 'tables' => 'facts', 'on_cal' => 'Tue,Sat *-*-* 04:30:00' },),
54-
}
55-
56-
service { 'pe_databases-facts': }
57-
service { 'pe_databases-facts.timer':
58-
ensure => $ensure_service,
59-
enable => ! $disable_maintenance,
60-
subscribe => File['/etc/systemd/system/pe_databases-facts.timer'],
61-
}
62-
63-
file { '/etc/systemd/system/pe_databases-catalogs.service':
64-
ensure => $ensure_file,
65-
content => epp('pe_databases/service.epp', { 'tables' => 'catalogs', 'command' => "${repack} ${repack_jobs} ${facts_tables}" }),
66-
}
67-
file {'/etc/systemd/system/pe_databases-catalogs.timer':
68-
ensure => $ensure_file,
69-
content => epp('pe_databases/timer.epp', { 'tables' => 'catalogs', 'on_cal' => 'Sun,Thu *-*-* 04:30:00' },),
70-
}
71-
72-
service { 'pe_databases-catalogs': }
73-
service { 'pe_databases-catalogs.timer':
74-
ensure => $ensure_service,
75-
enable => ! $disable_maintenance,
76-
subscribe => File['/etc/systemd/system/pe_databases-catalogs.timer'],
30+
pe_databases::collect {'facts':
31+
disable_maintenance => $disable_maintenance,
32+
command => "${repack} ${repack_jobs} ${facts_tables}",
33+
on_cal => 'Tue,Sat *-*-* 04:30:00',
7734
}
7835

79-
file { '/etc/systemd/system/pe_databases-other.service':
80-
ensure => $ensure_file,
81-
content => epp('pe_databases/service.epp', { 'tables' => 'other', 'command' => "${repack} ${repack_jobs} ${facts_tables}" }),
82-
}
83-
file {'/etc/systemd/system/pe_databases-other.timer':
84-
ensure => $ensure_file,
85-
content => epp('pe_databases/timer.epp', { 'tables' => 'other', 'on_cal' => '*-*-20 05:30:00' },),
36+
pe_databases::collect {'catalogs':
37+
disable_maintenance => $disable_maintenance,
38+
command => "${repack} ${repack_jobs} ${catalogs_tables}",
39+
on_cal => 'Sun,Thu *-*-* 04:30:00',
8640
}
8741

88-
service { 'pe_databases-other': }
89-
service { 'pe_databases-other.timer':
90-
ensure => $ensure_service,
91-
enable => ! $disable_maintenance,
92-
subscribe => File['/etc/systemd/system/pe_databases-other.timer'],
42+
pe_databases::collect {'other':
43+
disable_maintenance => $disable_maintenance,
44+
command => "${repack} ${repack_jobs} ${other_tables}",
45+
on_cal => '*-*-20 05:30:00',
9346
}
9447

9548
if versioncmp($facts['pe_server_version'], '2019.7.0') < 0 {
96-
file { '/etc/systemd/system/pe_databases-reports.service':
97-
ensure => $ensure_file,
98-
content => epp('pe_databases/service.epp', { 'tables' => 'reports', 'command' => "${repack} ${repack_jobs} ${facts_tables}" }),
99-
}
100-
file {'/etc/systemd/system/pe_databases-reports.timer':
101-
ensure => $ensure_file,
102-
content => epp('pe_databases/timer.epp', { 'tables' => 'reports', 'on_cal' => '*-*-10 05:30:00' },),
103-
}
104-
105-
service { 'pe_databases-reports': }
106-
service { 'pe_databases-reports.timer':
107-
ensure => $ensure_service,
108-
enable => ! $disable_maintenance,
109-
subscribe => File['/etc/systemd/system/pe_databases-reports.timer'],
49+
pe_databases::collect {'reports':
50+
disable_maintenance => $disable_maintenance,
51+
command => "${repack} ${repack_jobs} ${reports_table}",
52+
on_cal => '*-*-10 05:30:00',
11053
}
11154
}
11255

11356
if versioncmp($facts['pe_server_version'], '2019.3.0') < 0 {
114-
file { '/etc/systemd/system/pe_databases-resource_events.service':
115-
ensure => $ensure_file,
116-
content => epp(
117-
'pe_databases/service.epp', { 'tables' => 'resource_events', 'command' => "${repack} ${repack_jobs} ${resource_events_table}"}
118-
),
119-
}
120-
file {'/etc/systemd/system/pe_databases-resource_events.timer':
121-
ensure => $ensure_file,
122-
content => epp('pe_databases/timer.epp', { 'tables' => 'resource_events', 'on_cal' => '*-*-15 05:30:00' },),
123-
}
124-
125-
service { 'pe_databases-resource_events': }
126-
service { 'pe_databases-resource_events.timer':
127-
ensure => $ensure_service,
128-
enable => ! $disable_maintenance,
129-
subscribe => File['/etc/systemd/system/pe_databases-resource_events.timer'],
57+
pe_databases::collect {'resource_events':
58+
disable_maintenance => $disable_maintenance,
59+
command => "${repack} ${repack_jobs} ${resource_events_table}",
60+
on_cal => '*-*-15 05:30:00',
13061
}
13162
}
13263

13364
# Legacy cleanup
134-
cron { ['pg_repack facts tables', 'pg_repack catalogs tables', 'pg_repack other tables', 'pg_repack reports tables', 'pg_repack resource_events tables']: # lint:ignore:140chars
65+
$legacy_crons = [
66+
'pg_repack facts tables', 'pg_repack catalogs tables', 'pg_repack other tables',
67+
'pg_repack reports tables', 'pg_repack resource_events tables'
68+
]
69+
cron { $legacy_crons:
13570
ensure => absent,
13671
}
13772
}

spec/classes/pg_repack_spec.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@
33
describe 'pe_databases::pg_repack' do
44
on_supported_os.each do |os, os_facts|
55
context "on #{os}" do
6-
let(:pre_condition) { "class { 'pe_databases': manage_database_backups => false, manage_postgresql_settings => false, manage_table_settings => false, }" }
6+
let(:pre_condition) do
7+
"class { 'pe_databases':
8+
manage_database_backups => false,
9+
manage_postgresql_settings => false,
10+
manage_table_settings => false,
11+
}"
12+
end
713
let(:facts) { os_facts }
814

915
it { is_expected.to compile }

0 commit comments

Comments
 (0)