|
4 | 4 | # The existing PE primary server that will be migrated from
|
5 | 5 | # @param new_primary_host
|
6 | 6 | # The new server that will become the PE primary server
|
| 7 | +# @param upgrade_version |
| 8 | +# Optional version to upgrade to after migration is complete |
7 | 9 | #
|
8 | 10 | plan peadm::migrate (
|
9 | 11 | Peadm::SingleTargetSpec $old_primary_host,
|
10 | 12 | Peadm::SingleTargetSpec $new_primary_host,
|
| 13 | + Optional[String] $upgrade_version = undef, |
| 14 | + Optional[Peadm::SingleTargetSpec] $replica_host = undef, |
11 | 15 | ) {
|
12 | 16 | peadm::assert_supported_bolt_version()
|
13 | 17 |
|
14 | 18 | $backup_file = run_plan('peadm::backup', $old_primary_host, {
|
15 | 19 | backup_type => 'migration',
|
16 | 20 | })
|
17 | 21 |
|
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'] |
19 | 24 |
|
20 | 25 | $backup_filename = basename($backup_file['path'])
|
21 | 26 | $remote_backup_path = "/tmp/${backup_filename}"
|
22 |
| - $current_dir = system::env('PWD') |
23 | 27 |
|
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) |
25 | 29 |
|
26 | 30 | $old_primary_target = get_targets($old_primary_host)[0]
|
27 | 31 | $old_primary_password = peadm::get_pe_conf($old_primary_target)['console_admin_password']
|
28 | 32 | $old_pe_conf = run_task('peadm::get_peadm_config', $old_primary_target).first.value
|
29 | 33 |
|
| 34 | + out::message("old_pe_conf:${old_pe_conf}.") |
| 35 | + |
30 | 36 | run_plan('peadm::install', {
|
31 | 37 | primary_host => $new_primary_host,
|
32 | 38 | console_password => $old_primary_password,
|
|
40 | 46 | restore_type => 'migration',
|
41 | 47 | input_file => $remote_backup_path,
|
42 | 48 | })
|
| 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 | + } |
43 | 100 | }
|
0 commit comments