blob: 3ead8aa06bc08f7075bf481a0f1bbabf4ba5dcf1 [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
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040016node() {
Jiri Broulikf2abf422017-07-03 17:04:19 +020017
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040018 stage('Connect to Salt API') {
19 saltMaster = salt.connection(SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
20 }
21
22 stage('Start restore') {
23 // # actual upgrade
24
25 stage('Ask for manual confirmation') {
26 input message: "Are you sure you have the correct backups ready? Do you really want to continue to restore Zookeeper?"
27 }
28 // Zookeeper restore section
29 try {
30 salt.runSaltProcessStep(saltMaster, 'I@opencontrail:control', 'service.stop', ['supervisor-config'], null, true)
31 } catch (Exception er) {
32 common.warningMsg('Supervisor-config service already stopped')
33 }
34 try {
35 salt.runSaltProcessStep(saltMaster, 'I@opencontrail:control', 'service.stop', ['supervisor-control'], null, true)
36 } catch (Exception er) {
37 common.warningMsg('Supervisor-control service already stopped')
38 }
39 try {
40 salt.runSaltProcessStep(saltMaster, 'I@opencontrail:control', 'service.stop', ['zookeeper'], null, true)
41 } catch (Exception er) {
42 common.warningMsg('Zookeeper service already stopped')
43 }
44 //sleep(5)
45 // wait until zookeeper service is down
46 salt.commandStatus(saltMaster, 'I@opencontrail:control', 'service zookeeper status', 'stop')
47
48 try {
49 salt.cmdRun(saltMaster, 'I@opencontrail:control', "mkdir -p /root/zookeeper/zookeeper.bak")
50 } catch (Exception er) {
51 common.warningMsg('Directory already exists')
Jiri Broulikf2abf422017-07-03 17:04:19 +020052 }
53
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040054 try {
55 salt.cmdRun(saltMaster, 'I@opencontrail:control', "mv /var/lib/zookeeper/version-2/* /root/zookeeper/zookeeper.bak")
56 } catch (Exception er) {
57 common.warningMsg('Files were already moved')
Jiri Broulikf2abf422017-07-03 17:04:19 +020058 }
Ruslan Kamaldinov6feef402017-08-02 16:55:58 +040059 try {
60 salt.cmdRun(saltMaster, 'I@opencontrail:control', "rm -rf /var/lib/zookeeper/version-2/*")
61 } catch (Exception er) {
62 common.warningMsg('Directory already empty')
63 }
64
65 _pillar = salt.getPillar(saltMaster, "I@opencontrail:control", 'zookeeper:backup:backup_dir')
66 backup_dir = _pillar['return'][0].values()[0]
67 if(backup_dir == null || backup_dir.isEmpty()) { backup_dir='/var/backups/zookeeper' }
68 print(backup_dir)
69 salt.runSaltProcessStep(saltMaster, 'I@opencontrail:control', 'file.remove', ["${backup_dir}/dbrestored"], null, true)
70
71 // performs restore
72 salt.cmdRun(saltMaster, 'I@opencontrail:control', "su root -c 'salt-call state.sls zookeeper'")
73
74 salt.runSaltProcessStep(saltMaster, 'I@opencontrail:control', 'service.start', ['zookeeper'], null, true)
75 salt.runSaltProcessStep(saltMaster, 'I@opencontrail:control', 'service.start', ['supervisor-config'], null, true)
76 salt.runSaltProcessStep(saltMaster, 'I@opencontrail:control', 'service.start', ['supervisor-control'], null, true)
77
78 // wait until contrail-status is up
79 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)
80
81 salt.cmdRun(saltMaster, 'I@opencontrail:control', "ls /var/lib/zookeeper/version-2")
82 try {
83 salt.cmdRun(saltMaster, 'I@opencontrail:control', "echo stat | nc localhost 2181")
84 } catch (Exception er) {
85 common.warningMsg('Check which node is zookeeper leader')
86 }
87 salt.cmdRun(saltMaster, 'I@opencontrail:control', "contrail-status")
Jiri Broulikf2abf422017-07-03 17:04:19 +020088 }
89}