Jiri Broulik | f2abf42 | 2017-07-03 17:04:19 +0200 | [diff] [blame] | 1 | /** |
| 2 | * Update packages on given nodes |
| 3 | * |
| 4 | * Expected parameters: |
| 5 | * SALT_MASTER_CREDENTIALS Credentials to the Salt API. |
| 6 | * SALT_MASTER_URL Full Salt API address [http://10.10.10.1:8000]. |
| 7 | * |
| 8 | **/ |
| 9 | |
| 10 | def common = new com.mirantis.mk.Common() |
| 11 | def salt = new com.mirantis.mk.Salt() |
| 12 | |
| 13 | |
| 14 | def saltMaster |
| 15 | |
| 16 | timestamps { |
| 17 | node() { |
| 18 | |
| 19 | stage('Connect to Salt API') { |
| 20 | saltMaster = salt.connection(SALT_MASTER_URL, SALT_MASTER_CREDENTIALS) |
| 21 | } |
| 22 | |
| 23 | stage('Start restore') { |
| 24 | // # actual upgrade |
| 25 | |
| 26 | stage('Ask for manual confirmation') { |
| 27 | input message: "Are you sure you have the correct backups ready? Do you really want to continue to restore Cassandra?" |
| 28 | } |
| 29 | // Cassandra restore section |
| 30 | try { |
| 31 | salt.runSaltProcessStep(saltMaster, 'I@opencontrail:control', 'service.stop', ['supervisor-database'], null, true) |
| 32 | } catch (Exception er) { |
| 33 | common.warningMsg('Supervisor-database service already stopped') |
| 34 | } |
| 35 | try { |
Jiri Broulik | 1c51398 | 2017-07-04 22:19:51 +0200 | [diff] [blame] | 36 | salt.cmdRun(saltMaster, 'I@opencontrail:control', "mkdir -p /root/cassandra/cassandra.bak") |
Jiri Broulik | f2abf42 | 2017-07-03 17:04:19 +0200 | [diff] [blame] | 37 | } catch (Exception er) { |
| 38 | common.warningMsg('Directory already exists') |
| 39 | } |
| 40 | |
Jiri Broulik | f2abf42 | 2017-07-03 17:04:19 +0200 | [diff] [blame] | 41 | try { |
| 42 | salt.cmdRun(saltMaster, 'I@opencontrail:control', "mv /var/lib/cassandra/* /root/cassandra/cassandra.bak") |
| 43 | } catch (Exception er) { |
| 44 | common.warningMsg('Files were already moved') |
| 45 | } |
Jiri Broulik | 1c51398 | 2017-07-04 22:19:51 +0200 | [diff] [blame] | 46 | try { |
| 47 | salt.cmdRun(saltMaster, 'I@opencontrail:control', "rm -rf /var/lib/cassandra/*") |
| 48 | } catch (Exception er) { |
| 49 | common.warningMsg('Directory already empty') |
| 50 | } |
Jiri Broulik | f2abf42 | 2017-07-03 17:04:19 +0200 | [diff] [blame] | 51 | |
Jiri Broulik | 6a0d356 | 2017-07-11 10:45:01 +0200 | [diff] [blame] | 52 | _pillar = salt.getPillar(saltMaster, "I@cassandra:backup:client", 'cassandra:backup:backup_dir') |
Jiri Broulik | f2abf42 | 2017-07-03 17:04:19 +0200 | [diff] [blame] | 53 | backup_dir = _pillar['return'][0].values()[0] |
| 54 | if(backup_dir == null || backup_dir.isEmpty()) { backup_dir='/var/backups/cassandra' } |
| 55 | print(backup_dir) |
Jiri Broulik | 6a0d356 | 2017-07-11 10:45:01 +0200 | [diff] [blame] | 56 | salt.runSaltProcessStep(saltMaster, 'I@cassandra:backup:client', 'file.remove', ["${backup_dir}/dbrestored"], null, true) |
Jiri Broulik | f2abf42 | 2017-07-03 17:04:19 +0200 | [diff] [blame] | 57 | |
Jiri Broulik | 6a0d356 | 2017-07-11 10:45:01 +0200 | [diff] [blame] | 58 | salt.runSaltProcessStep(saltMaster, 'I@cassandra:backup:client', 'service.start', ['supervisor-database'], null, true) |
Jiri Broulik | f2abf42 | 2017-07-03 17:04:19 +0200 | [diff] [blame] | 59 | |
Jiri Broulik | 1c51398 | 2017-07-04 22:19:51 +0200 | [diff] [blame] | 60 | sleep(30) |
Jiri Broulik | f2abf42 | 2017-07-03 17:04:19 +0200 | [diff] [blame] | 61 | |
| 62 | // performs restore |
Jiri Broulik | 6a0d356 | 2017-07-11 10:45:01 +0200 | [diff] [blame] | 63 | salt.cmdRun(saltMaster, 'I@cassandra:backup:client', "su root -c 'salt-call state.sls cassandra'") |
| 64 | salt.runSaltProcessStep(saltMaster, 'I@cassandra:backup:client', 'system.reboot', null, null, true, 5) |
| 65 | salt.runSaltProcessStep(saltMaster, 'I@opencontrail:control and not I@cassandra:backup:client', 'system.reboot', null, null, true, 5) |
| 66 | salt.runSaltProcessStep(saltMaster, 'I@opencontrail:control and not I@cassandra:backup:client', 'system.reboot', null, null, true, 5) |
Jiri Broulik | f2abf42 | 2017-07-03 17:04:19 +0200 | [diff] [blame] | 67 | |
Jiri Broulik | 1c51398 | 2017-07-04 22:19:51 +0200 | [diff] [blame] | 68 | sleep(60) |
Jiri Broulik | f2abf42 | 2017-07-03 17:04:19 +0200 | [diff] [blame] | 69 | salt.runSaltProcessStep(saltMaster, 'I@opencontrail:control', 'service.restart', ['supervisor-database'], null, true) |
| 70 | |
Jiri Broulik | 1c51398 | 2017-07-04 22:19:51 +0200 | [diff] [blame] | 71 | sleep(50) |
Jiri Broulik | f2abf42 | 2017-07-03 17:04:19 +0200 | [diff] [blame] | 72 | salt.cmdRun(saltMaster, 'I@opencontrail:control', "nodetool status") |
| 73 | salt.cmdRun(saltMaster, 'I@opencontrail:control', "contrail-status") |
| 74 | } |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | |
| 79 | |