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 { |
| 36 | salt.cmdRun(saltMaster, 'I@opencontrail:control', "mkdir /root/cassandra/cassandra.bak") |
| 37 | } catch (Exception er) { |
| 38 | common.warningMsg('Directory already exists') |
| 39 | } |
| 40 | |
| 41 | // add check if empty dir ? |
| 42 | try { |
| 43 | salt.cmdRun(saltMaster, 'I@opencontrail:control', "mv /var/lib/cassandra/* /root/cassandra/cassandra.bak") |
| 44 | } catch (Exception er) { |
| 45 | common.warningMsg('Files were already moved') |
| 46 | } |
| 47 | |
| 48 | _pillar = salt.getPillar(saltMaster, "ntw01*", 'cassandra:backup:backup_dir') |
| 49 | backup_dir = _pillar['return'][0].values()[0] |
| 50 | if(backup_dir == null || backup_dir.isEmpty()) { backup_dir='/var/backups/cassandra' } |
| 51 | print(backup_dir) |
| 52 | salt.runSaltProcessStep(saltMaster, 'I@galera:master', 'file.remove', ["${backup_dir}/dbrestored"], null, true) |
| 53 | |
| 54 | salt.runSaltProcessStep(saltMaster, 'ntw01*', 'service.start', ['supervisor-database'], null, true) |
| 55 | |
| 56 | sleep(10) |
| 57 | |
| 58 | // performs restore |
| 59 | salt.cmdRun(saltMaster, 'ntw01*', "su root -c 'salt-call state.sls cassandra'") |
| 60 | salt.runSaltProcessStep(saltMaster, 'ntw01*', 'system.reboot', null, null, true, 5) |
| 61 | salt.runSaltProcessStep(saltMaster, 'ntw02*', 'system.reboot', null, null, true, 5) |
| 62 | salt.runSaltProcessStep(saltMaster, 'ntw03*', 'system.reboot', null, null, true, 5) |
| 63 | |
| 64 | sleep(15) |
| 65 | salt.runSaltProcessStep(saltMaster, 'I@opencontrail:control', 'service.restart', ['supervisor-database'], null, true) |
| 66 | |
| 67 | sleep(10) |
| 68 | salt.cmdRun(saltMaster, 'I@opencontrail:control', "nodetool status") |
| 69 | salt.cmdRun(saltMaster, 'I@opencontrail:control', "contrail-status") |
| 70 | } |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | |
| 75 | |