Skip to content

Commit 8d174a7

Browse files
petergmurphypetergmurphy
and
petergmurphy
authored
(PE-40372/3) Add optional upgrade and replica support to migration plan (#552)
* (PE-40373) Add optional upgrade to migration plan This commit extends the existing migration plan by adding an optional upgrade step after the migration is complete. If an upgrade version is specified, the plan will automatically perform an upgrade to the new version using the peadm::upgrade plan. * (PE-40372) Add optional replica host to migration plan This commit extends the migration plan to support and utilise an optional new replica host parameter. Code has also been added to purge old nodes from the newly restored infrastructure. --------- Co-authored-by: petergmurphy <[email protected]>
1 parent be0fb06 commit 8d174a7

File tree

2 files changed

+78
-3
lines changed

2 files changed

+78
-3
lines changed

REFERENCE.md

+18
Original file line numberDiff line numberDiff line change
@@ -2322,6 +2322,8 @@ The following parameters are available in the `peadm::migrate` plan:
23222322

23232323
* [`old_primary_host`](#-peadm--migrate--old_primary_host)
23242324
* [`new_primary_host`](#-peadm--migrate--new_primary_host)
2325+
* [`upgrade_version`](#-peadm--migrate--upgrade_version)
2326+
* [`replica_host`](#-peadm--migrate--replica_host)
23252327

23262328
##### <a name="-peadm--migrate--old_primary_host"></a>`old_primary_host`
23272329

@@ -2335,6 +2337,22 @@ Data type: `Peadm::SingleTargetSpec`
23352337

23362338
The new server that will become the PE primary server
23372339

2340+
##### <a name="-peadm--migrate--upgrade_version"></a>`upgrade_version`
2341+
2342+
Data type: `Optional[String]`
2343+
2344+
Optional version to upgrade to after migration is complete
2345+
2346+
Default value: `undef`
2347+
2348+
##### <a name="-peadm--migrate--replica_host"></a>`replica_host`
2349+
2350+
Data type: `Optional[Peadm::SingleTargetSpec]`
2351+
2352+
2353+
2354+
Default value: `undef`
2355+
23382356
### <a name="peadm--modify_certificate"></a>`peadm::modify_certificate`
23392357

23402358
Certificates can be modified by adding extensions, removing extensions, or

plans/migrate.pp

+60-3
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,35 @@
44
# The existing PE primary server that will be migrated from
55
# @param new_primary_host
66
# The new server that will become the PE primary server
7+
# @param upgrade_version
8+
# Optional version to upgrade to after migration is complete
79
#
810
plan peadm::migrate (
911
Peadm::SingleTargetSpec $old_primary_host,
1012
Peadm::SingleTargetSpec $new_primary_host,
13+
Optional[String] $upgrade_version = undef,
14+
Optional[Peadm::SingleTargetSpec] $replica_host = undef,
1115
) {
1216
peadm::assert_supported_bolt_version()
1317

1418
$backup_file = run_plan('peadm::backup', $old_primary_host, {
1519
backup_type => 'migration',
1620
})
1721

18-
download_file($backup_file['path'], 'backup', $old_primary_host)
22+
$download_results = download_file($backup_file['path'], 'backup', $old_primary_host)
23+
$download_path = $download_results[0]['path']
1924

2025
$backup_filename = basename($backup_file['path'])
2126
$remote_backup_path = "/tmp/${backup_filename}"
22-
$current_dir = system::env('PWD')
2327

24-
upload_file("${current_dir}/downloads/backup/${old_primary_host}/${backup_filename}", $remote_backup_path, $new_primary_host)
28+
upload_file($download_path, $remote_backup_path, $new_primary_host)
2529

2630
$old_primary_target = get_targets($old_primary_host)[0]
2731
$old_primary_password = peadm::get_pe_conf($old_primary_target)['console_admin_password']
2832
$old_pe_conf = run_task('peadm::get_peadm_config', $old_primary_target).first.value
2933

34+
out::message("old_pe_conf:${old_pe_conf}.")
35+
3036
run_plan('peadm::install', {
3137
primary_host => $new_primary_host,
3238
console_password => $old_primary_password,
@@ -40,4 +46,55 @@
4046
restore_type => 'migration',
4147
input_file => $remote_backup_path,
4248
})
49+
50+
$node_types = {
51+
'primary_host' => $old_pe_conf['params']['primary_host'],
52+
'replica_host' => $old_pe_conf['params']['replica_host'],
53+
'primary_postgresql_host' => $old_pe_conf['params']['primary_postgresql_host'],
54+
'replica_postgresql_host' => $old_pe_conf['params']['replica_postgresql_host'],
55+
'compilers' => $old_pe_conf['params']['compilers'],
56+
'legacy_compilers' => $old_pe_conf['params']['legacy_compilers'],
57+
}
58+
59+
$nodes_to_purge = $node_types.reduce([]) |$memo, $entry| {
60+
$value = $entry[1]
61+
62+
if empty($value) {
63+
$memo
64+
}
65+
elsif $value =~ Array {
66+
$memo + $value.filter |$node| { !empty($node) }
67+
}
68+
else {
69+
$memo + [$value]
70+
}
71+
}
72+
73+
out::message("Nodes to purge: ${nodes_to_purge}")
74+
75+
if !empty($nodes_to_purge) {
76+
out::message('Purging nodes from old configuration individually')
77+
$nodes_to_purge.each |$node| {
78+
out::message("Purging node: ${node}")
79+
run_command("/opt/puppetlabs/bin/puppet node purge ${node}", $new_primary_host)
80+
}
81+
} else {
82+
out::message('No nodes to purge from old configuration')
83+
}
84+
85+
if $replica_host {
86+
run_plan('peadm::add_replica', {
87+
primary_host => $new_primary_host,
88+
replica_host => $replica_host,
89+
})
90+
}
91+
92+
if $upgrade_version and $upgrade_version != '' and !empty($upgrade_version) {
93+
run_plan('peadm::upgrade', {
94+
primary_host => $new_primary_host,
95+
version => $upgrade_version,
96+
download_mode => 'direct',
97+
replica_host => $replica_host,
98+
})
99+
}
43100
}

0 commit comments

Comments
 (0)