Skip to content

Commit 209d9c4

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 209d9c4

File tree

2 files changed

+108
-5
lines changed

2 files changed

+108
-5
lines changed

REFERENCE.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ Supported use cases:
114114
* [`peadm::restore`](#peadm--restore): Restore puppet primary configuration
115115
* [`peadm::restore_ca`](#peadm--restore_ca)
116116
* [`peadm::status`](#peadm--status): Return status information from one or more PE clusters in a table format
117+
* [`peadm::temp_plan`](#peadm--temp_plan)
117118
* [`peadm::upgrade`](#peadm--upgrade): Upgrade a PEAdm-managed cluster
118119
* [`peadm::util::init_db_server`](#peadm--util--init_db_server)
119120

@@ -2322,6 +2323,8 @@ The following parameters are available in the `peadm::migrate` plan:
23222323

23232324
* [`old_primary_host`](#-peadm--migrate--old_primary_host)
23242325
* [`new_primary_host`](#-peadm--migrate--new_primary_host)
2326+
* [`upgrade_version`](#-peadm--migrate--upgrade_version)
2327+
* [`replica_host`](#-peadm--migrate--replica_host)
23252328

23262329
##### <a name="-peadm--migrate--old_primary_host"></a>`old_primary_host`
23272330

@@ -2335,6 +2338,22 @@ Data type: `Peadm::SingleTargetSpec`
23352338

23362339
The new server that will become the PE primary server
23372340

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

23402359
Certificates can be modified by adding extensions, removing extensions, or
@@ -2580,6 +2599,22 @@ Toggles the usage of colors, you may want to disable if the format is json
25802599

25812600
Default value: `$format ? { 'json' => false, default => true`
25822601

2602+
### <a name="peadm--temp_plan"></a>`peadm::temp_plan`
2603+
2604+
The peadm::temp_plan class.
2605+
2606+
#### Parameters
2607+
2608+
The following parameters are available in the `peadm::temp_plan` plan:
2609+
2610+
* [`old_primary_host`](#-peadm--temp_plan--old_primary_host)
2611+
2612+
##### <a name="-peadm--temp_plan--old_primary_host"></a>`old_primary_host`
2613+
2614+
Data type: `Peadm::SingleTargetSpec`
2615+
2616+
2617+
25832618
### <a name="peadm--upgrade"></a>`peadm::upgrade`
25842619

25852620
Upgrade a PEAdm-managed cluster

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)