blob: 4a9c89ead493e0393e6856963592da637357fb37 [file] [log] [blame]
Jiri Broulikf2abf422017-07-03 17:04:19 +02001/**
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
10def common = new com.mirantis.mk.Common()
11def salt = new com.mirantis.mk.Salt()
12
13
14def saltMaster
15
16timestamps {
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 Broulik1c513982017-07-04 22:19:51 +020036 salt.cmdRun(saltMaster, 'I@opencontrail:control', "mkdir -p /root/cassandra/cassandra.bak")
Jiri Broulikf2abf422017-07-03 17:04:19 +020037 } catch (Exception er) {
38 common.warningMsg('Directory already exists')
39 }
40
Jiri Broulikf2abf422017-07-03 17:04:19 +020041 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 Broulik1c513982017-07-04 22:19:51 +020046 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 Broulikf2abf422017-07-03 17:04:19 +020051
Jiri Broulik6a0d3562017-07-11 10:45:01 +020052 _pillar = salt.getPillar(saltMaster, "I@cassandra:backup:client", 'cassandra:backup:backup_dir')
Jiri Broulikf2abf422017-07-03 17:04:19 +020053 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 Broulik6a0d3562017-07-11 10:45:01 +020056 salt.runSaltProcessStep(saltMaster, 'I@cassandra:backup:client', 'file.remove', ["${backup_dir}/dbrestored"], null, true)
Jiri Broulikf2abf422017-07-03 17:04:19 +020057
Jiri Broulik6a0d3562017-07-11 10:45:01 +020058 salt.runSaltProcessStep(saltMaster, 'I@cassandra:backup:client', 'service.start', ['supervisor-database'], null, true)
Jiri Broulikf2abf422017-07-03 17:04:19 +020059
Jiri Broulik8dabbfd2017-07-25 10:49:45 +020060 // wait until supervisor-database service is up
61 salt.commandStatus(saltMaster, 'I@cassandra:backup:client', 'service supervisor-database status', 'running')
Jiri Broulikf2abf422017-07-03 17:04:19 +020062
63 // performs restore
Jiri Broulik6a0d3562017-07-11 10:45:01 +020064 salt.cmdRun(saltMaster, 'I@cassandra:backup:client', "su root -c 'salt-call state.sls cassandra'")
65 salt.runSaltProcessStep(saltMaster, '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 Broulikf2abf422017-07-03 17:04:19 +020067
Jiri Broulik8dabbfd2017-07-25 10:49:45 +020068 // wait until supervisor-database service is up
69 salt.commandStatus(saltMaster, 'I@cassandra:backup:client', 'service supervisor-database status', 'running')
70 salt.commandStatus(saltMaster, 'I@opencontrail:control and not I@cassandra:backup:client', 'service supervisor-database status', 'running')
71 sleep(5)
72
Jiri Broulikf2abf422017-07-03 17:04:19 +020073 salt.runSaltProcessStep(saltMaster, 'I@opencontrail:control', 'service.restart', ['supervisor-database'], null, true)
74
Jiri Broulik8dabbfd2017-07-25 10:49:45 +020075 // wait until contrail-status is up
76 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)
77
Jiri Broulikf2abf422017-07-03 17:04:19 +020078 salt.cmdRun(saltMaster, 'I@opencontrail:control', "nodetool status")
79 salt.cmdRun(saltMaster, 'I@opencontrail:control', "contrail-status")
80 }
81 }
82}