blob: af2016ea610525ba0a92c32cbfb850201691a598 [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 Broulik1c513982017-07-04 22:19:51 +020060 sleep(30)
Jiri Broulikf2abf422017-07-03 17:04:19 +020061
62 // performs restore
Jiri Broulik6a0d3562017-07-11 10:45:01 +020063 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 Broulikf2abf422017-07-03 17:04:19 +020067
Jiri Broulik1c513982017-07-04 22:19:51 +020068 sleep(60)
Jiri Broulikf2abf422017-07-03 17:04:19 +020069 salt.runSaltProcessStep(saltMaster, 'I@opencontrail:control', 'service.restart', ['supervisor-database'], null, true)
70
Jiri Broulik1c513982017-07-04 22:19:51 +020071 sleep(50)
Jiri Broulikf2abf422017-07-03 17:04:19 +020072 salt.cmdRun(saltMaster, 'I@opencontrail:control', "nodetool status")
73 salt.cmdRun(saltMaster, 'I@opencontrail:control', "contrail-status")
74 }
75 }
76}
77
78
79