|
11 | 11 | Peadm::SingleTargetSpec $old_primary_host, |
12 | 12 | Peadm::SingleTargetSpec $new_primary_host, |
13 | 13 | Optional[String] $upgrade_version = undef, |
| 14 | + Optional[Peadm::SingleTargetSpec] $replica_host = undef, |
14 | 15 | ) { |
15 | 16 | peadm::assert_supported_bolt_version() |
16 | 17 |
|
17 | 18 | $backup_file = run_plan('peadm::backup', $old_primary_host, { |
18 | 19 | backup_type => 'migration', |
19 | 20 | }) |
20 | 21 |
|
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'] |
22 | 24 |
|
23 | 25 | $backup_filename = basename($backup_file['path']) |
24 | 26 | $remote_backup_path = "/tmp/${backup_filename}" |
25 | | - $current_dir = system::env('PWD') |
26 | 27 |
|
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) |
28 | 29 |
|
29 | 30 | $old_primary_target = get_targets($old_primary_host)[0] |
30 | 31 | $old_primary_password = peadm::get_pe_conf($old_primary_target)['console_admin_password'] |
31 | 32 | $old_pe_conf = run_task('peadm::get_peadm_config', $old_primary_target).first.value |
32 | 33 |
|
| 34 | + out::message("old_pe_conf:${old_pe_conf}.") |
| 35 | + |
33 | 36 | run_plan('peadm::install', { |
34 | 37 | primary_host => $new_primary_host, |
35 | 38 | console_password => $old_primary_password, |
|
44 | 47 | input_file => $remote_backup_path, |
45 | 48 | }) |
46 | 49 |
|
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) { |
48 | 115 | run_plan('peadm::upgrade', { |
49 | 116 | primary_host => $new_primary_host, |
50 | 117 | version => $upgrade_version, |
51 | | - download_mode => 'direct', |
| 118 | + download_mode => 'direct', |
| 119 | + replica_host => $replica_host, |
52 | 120 | }) |
53 | 121 | } |
54 | 122 | } |
0 commit comments