Skip to content

Commit

Permalink
(PE-40372) Add optional replica host to migration plan
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
petergmurphy committed Mar 3, 2025
1 parent b5c3cfb commit b1f86e5
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 5 deletions.
18 changes: 18 additions & 0 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2322,6 +2322,8 @@ The following parameters are available in the `peadm::migrate` plan:

* [`old_primary_host`](#-peadm--migrate--old_primary_host)
* [`new_primary_host`](#-peadm--migrate--new_primary_host)
* [`upgrade_version`](#-peadm--migrate--upgrade_version)
* [`replica_host`](#-peadm--migrate--replica_host)

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

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

The new server that will become the PE primary server

##### <a name="-peadm--migrate--upgrade_version"></a>`upgrade_version`

Data type: `Optional[String]`

Optional version to upgrade to after migration is complete

Default value: `undef`

##### <a name="-peadm--migrate--replica_host"></a>`replica_host`

Data type: `Optional[Peadm::SingleTargetSpec]`



Default value: `undef`

### <a name="peadm--modify_certificate"></a>`peadm::modify_certificate`

Certificates can be modified by adding extensions, removing extensions, or
Expand Down
56 changes: 51 additions & 5 deletions plans/migrate.pp
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,28 @@
Peadm::SingleTargetSpec $old_primary_host,
Peadm::SingleTargetSpec $new_primary_host,
Optional[String] $upgrade_version = undef,
Optional[Peadm::SingleTargetSpec] $replica_host = undef,
) {
peadm::assert_supported_bolt_version()

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

download_file($backup_file['path'], 'backup', $old_primary_host)
$download_results = download_file($backup_file['path'], 'backup', $old_primary_host)
$download_path = $download_results[0]['path']

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

upload_file("${current_dir}/downloads/backup/${old_primary_host}/${backup_filename}", $remote_backup_path, $new_primary_host)
upload_file($download_path, $remote_backup_path, $new_primary_host)

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

out::message("old_pe_conf:${old_pe_conf}.")

run_plan('peadm::install', {
primary_host => $new_primary_host,
console_password => $old_primary_password,
Expand All @@ -44,11 +47,54 @@
input_file => $remote_backup_path,
})

if $upgrade_version {
$node_types = {
'primary_host' => $old_pe_conf['params']['primary_host'],
'replica_host' => $old_pe_conf['params']['replica_host'],
'primary_postgresql_host' => $old_pe_conf['params']['primary_postgresql_host'],
'replica_postgresql_host' => $old_pe_conf['params']['replica_postgresql_host'],
'compilers' => $old_pe_conf['params']['compilers'],
'legacy_compilers' => $old_pe_conf['params']['legacy_compilers'],
}

$nodes_to_purge = $node_types.reduce([]) |$memo, $entry| {
$value = $entry[1]

if empty($value) {
$memo
}
elsif $value =~ Array {
$memo + $value.filter |$node| { !empty($node) }
}
else {
$memo + [$value]
}
}

out::message("Nodes to purge: ${nodes_to_purge}")

if !empty($nodes_to_purge) {
out::message('Purging nodes from old configuration individually')
$nodes_to_purge.each |$node| {
out::message("Purging node: ${node}")
run_command("/opt/puppetlabs/bin/puppet node purge ${node}", $new_primary_host)
}
} else {
out::message('No nodes to purge from old configuration')
}

if $replica_host {
run_plan('peadm::add_replica', {
primary_host => $new_primary_host,
replica_host => $replica_host,
})
}

if $upgrade_version and $upgrade_version != '' and !empty($upgrade_version) {
run_plan('peadm::upgrade', {
primary_host => $new_primary_host,
version => $upgrade_version,
download_mode => 'direct',
download_mode => 'direct',
replica_host => $replica_host,
})
}
}

0 comments on commit b1f86e5

Please # to comment.