Skip to content

Commit 534d04a

Browse files
author
petergmurphy
committed
(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.
1 parent b5c3cfb commit 534d04a

File tree

2 files changed

+91
-5
lines changed

2 files changed

+91
-5
lines changed

REFERENCE.md

Lines changed: 18 additions & 0 deletions
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[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

Lines changed: 73 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,28 @@
1111
Peadm::SingleTargetSpec $old_primary_host,
1212
Peadm::SingleTargetSpec $new_primary_host,
1313
Optional[String] $upgrade_version = undef,
14+
Optional[Peadm::SingleTargetSpec] $replica_host = undef,
1415
) {
1516
peadm::assert_supported_bolt_version()
1617

1718
$backup_file = run_plan('peadm::backup', $old_primary_host, {
1819
backup_type => 'migration',
1920
})
2021

21-
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']
2224

2325
$backup_filename = basename($backup_file['path'])
2426
$remote_backup_path = "/tmp/${backup_filename}"
25-
$current_dir = system::env('PWD')
2627

27-
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)
2829

2930
$old_primary_target = get_targets($old_primary_host)[0]
3031
$old_primary_password = peadm::get_pe_conf($old_primary_target)['console_admin_password']
3132
$old_pe_conf = run_task('peadm::get_peadm_config', $old_primary_target).first.value
3233

34+
out::message("old_pe_conf:${old_pe_conf}.")
35+
3336
run_plan('peadm::install', {
3437
primary_host => $new_primary_host,
3538
console_password => $old_primary_password,
@@ -44,11 +47,76 @@
4447
input_file => $remote_backup_path,
4548
})
4649

47-
if $upgrade_version {
50+
# Use the old PE configuration to determine which nodes to purge
51+
$old_primary_host_value = $old_pe_conf['params']['primary_host']
52+
$replica_host_value = $old_pe_conf['params']['replica_host']
53+
$primary_postgresql_host_value = $old_pe_conf['params']['primary_postgresql_host']
54+
$replica_postgresql_host_value = $old_pe_conf['params']['replica_postgresql_host']
55+
$compilers_value = $old_pe_conf['params']['compilers']
56+
$legacy_compilers_value = $old_pe_conf['params']['legacy_compilers']
57+
58+
$old_primary_host_string = !empty($old_primary_host_value) ? {
59+
true => $old_primary_host_value,
60+
default => ''
61+
}
62+
63+
$replica_host_string = !empty($replica_host_value) ? {
64+
true => $replica_host_value,
65+
default => ''
66+
}
67+
68+
$primary_postgresql_host_string = !empty($primary_postgresql_host_value) ? {
69+
true => $primary_postgresql_host_value,
70+
default => ''
71+
}
72+
73+
$replica_postgresql_host_string = !empty($replica_postgresql_host_value) ? {
74+
true => $replica_postgresql_host_value,
75+
default => ''
76+
}
77+
78+
$compilers_string = !empty($compilers_value) ? {
79+
true => $compilers_value.filter |$node| { !empty($node) }.join(','),
80+
default => ''
81+
}
82+
83+
$legacy_compilers_string = !empty($legacy_compilers_value) ? {
84+
true => $legacy_compilers_value.filter |$node| { !empty($node) }.join(','),
85+
default => ''
86+
}
87+
88+
$purge_components = [
89+
$replica_host_string,
90+
$primary_postgresql_host_string,
91+
$replica_postgresql_host_string,
92+
$compilers_string,
93+
$legacy_compilers_string,
94+
$old_primary_host_string,
95+
].filter |$component| { !empty($component) }
96+
97+
if !empty($purge_components) {
98+
out::message('Purging nodes from old configuration individually')
99+
$purge_components.each |$component| {
100+
out::message("Purging component: ${component}")
101+
run_command("/opt/puppetlabs/bin/puppet node purge ${component}", $new_primary_host)
102+
}
103+
} else {
104+
out::message('No nodes to purge from old configuration')
105+
}
106+
107+
if $replica_host {
108+
run_plan('peadm::add_replica', {
109+
primary_host => $new_primary_host,
110+
replica_host => $replica_host,
111+
})
112+
}
113+
114+
if $upgrade_version and $upgrade_version != '' and !empty($upgrade_version) {
48115
run_plan('peadm::upgrade', {
49116
primary_host => $new_primary_host,
50117
version => $upgrade_version,
51-
download_mode => 'direct',
118+
download_mode => 'direct',
119+
replica_host => $replica_host,
52120
})
53121
}
54122
}

0 commit comments

Comments
 (0)