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 Zookeeper?" |
| 28 | } |
| 29 | // Zookeeper restore section |
| 30 | try { |
| 31 | salt.runSaltProcessStep(saltMaster, 'I@opencontrail:control', 'service.stop', ['supervisor-config'], null, true) |
| 32 | } catch (Exception er) { |
| 33 | common.warningMsg('Supervisor-config service already stopped') |
| 34 | } |
| 35 | try { |
| 36 | salt.runSaltProcessStep(saltMaster, 'I@opencontrail:control', 'service.stop', ['supervisor-control'], null, true) |
| 37 | } catch (Exception er) { |
| 38 | common.warningMsg('Supervisor-control service already stopped') |
| 39 | } |
| 40 | try { |
| 41 | salt.runSaltProcessStep(saltMaster, 'I@opencontrail:control', 'service.stop', ['zookeeper'], null, true) |
| 42 | } catch (Exception er) { |
| 43 | common.warningMsg('Zookeeper service already stopped') |
| 44 | } |
Jiri Broulik | 8dabbfd | 2017-07-25 10:49:45 +0200 | [diff] [blame] | 45 | //sleep(5) |
| 46 | // wait until zookeeper service is down |
| 47 | salt.commandStatus(saltMaster, 'I@opencontrail:control', 'service zookeeper status', 'stop') |
| 48 | |
Jiri Broulik | f2abf42 | 2017-07-03 17:04:19 +0200 | [diff] [blame] | 49 | try { |
Jiri Broulik | 1c51398 | 2017-07-04 22:19:51 +0200 | [diff] [blame] | 50 | salt.cmdRun(saltMaster, 'I@opencontrail:control', "mkdir -p /root/zookeeper/zookeeper.bak") |
Jiri Broulik | f2abf42 | 2017-07-03 17:04:19 +0200 | [diff] [blame] | 51 | } catch (Exception er) { |
| 52 | common.warningMsg('Directory already exists') |
| 53 | } |
| 54 | |
Jiri Broulik | f2abf42 | 2017-07-03 17:04:19 +0200 | [diff] [blame] | 55 | try { |
| 56 | salt.cmdRun(saltMaster, 'I@opencontrail:control', "mv /var/lib/zookeeper/version-2/* /root/zookeeper/zookeeper.bak") |
| 57 | } catch (Exception er) { |
| 58 | common.warningMsg('Files were already moved') |
| 59 | } |
Jiri Broulik | 1c51398 | 2017-07-04 22:19:51 +0200 | [diff] [blame] | 60 | try { |
| 61 | salt.cmdRun(saltMaster, 'I@opencontrail:control', "rm -rf /var/lib/zookeeper/version-2/*") |
| 62 | } catch (Exception er) { |
| 63 | common.warningMsg('Directory already empty') |
| 64 | } |
Jiri Broulik | f2abf42 | 2017-07-03 17:04:19 +0200 | [diff] [blame] | 65 | |
| 66 | _pillar = salt.getPillar(saltMaster, "I@opencontrail:control", 'zookeeper:backup:backup_dir') |
| 67 | backup_dir = _pillar['return'][0].values()[0] |
| 68 | if(backup_dir == null || backup_dir.isEmpty()) { backup_dir='/var/backups/zookeeper' } |
| 69 | print(backup_dir) |
Jiri Broulik | 1c51398 | 2017-07-04 22:19:51 +0200 | [diff] [blame] | 70 | salt.runSaltProcessStep(saltMaster, 'I@opencontrail:control', 'file.remove', ["${backup_dir}/dbrestored"], null, true) |
Jiri Broulik | f2abf42 | 2017-07-03 17:04:19 +0200 | [diff] [blame] | 71 | |
| 72 | // performs restore |
| 73 | salt.cmdRun(saltMaster, 'I@opencontrail:control', "su root -c 'salt-call state.sls zookeeper'") |
| 74 | |
| 75 | salt.runSaltProcessStep(saltMaster, 'I@opencontrail:control', 'service.start', ['zookeeper'], null, true) |
| 76 | salt.runSaltProcessStep(saltMaster, 'I@opencontrail:control', 'service.start', ['supervisor-config'], null, true) |
| 77 | salt.runSaltProcessStep(saltMaster, 'I@opencontrail:control', 'service.start', ['supervisor-control'], null, true) |
| 78 | |
Jiri Broulik | 8dabbfd | 2017-07-25 10:49:45 +0200 | [diff] [blame] | 79 | // wait until contrail-status is up |
| 80 | salt.commandStatus(saltMaster, 'I@opencontrail:control', "contrail-status | grep -v == | grep -v \'disabled on boot\' | grep -v nodemgr | grep -v active | grep -v backup", null, false) |
| 81 | |
Jiri Broulik | f2abf42 | 2017-07-03 17:04:19 +0200 | [diff] [blame] | 82 | salt.cmdRun(saltMaster, 'I@opencontrail:control', "ls /var/lib/zookeeper/version-2") |
Jiri Broulik | 1c51398 | 2017-07-04 22:19:51 +0200 | [diff] [blame] | 83 | try { |
| 84 | salt.cmdRun(saltMaster, 'I@opencontrail:control', "echo stat | nc localhost 2181") |
| 85 | } catch (Exception er) { |
| 86 | common.warningMsg('Check which node is zookeeper leader') |
| 87 | } |
Jiri Broulik | f2abf42 | 2017-07-03 17:04:19 +0200 | [diff] [blame] | 88 | salt.cmdRun(saltMaster, 'I@opencontrail:control', "contrail-status") |
| 89 | } |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | |
| 94 | |