zookeeper and cassandra restore pipelines
Change-Id: I4e1986dd0f38d8756865e588bffa306f1722ab90
diff --git a/restore-zookeeper.groovy b/restore-zookeeper.groovy
new file mode 100644
index 0000000..711601e
--- /dev/null
+++ b/restore-zookeeper.groovy
@@ -0,0 +1,80 @@
+/**
+ * Update packages on given nodes
+ *
+ * Expected parameters:
+ * SALT_MASTER_CREDENTIALS Credentials to the Salt API.
+ * SALT_MASTER_URL Full Salt API address [http://10.10.10.1:8000].
+ *
+**/
+
+def common = new com.mirantis.mk.Common()
+def salt = new com.mirantis.mk.Salt()
+
+
+def saltMaster
+
+timestamps {
+ node() {
+
+ stage('Connect to Salt API') {
+ saltMaster = salt.connection(SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
+ }
+
+ stage('Start restore') {
+ // # actual upgrade
+
+ stage('Ask for manual confirmation') {
+ input message: "Are you sure you have the correct backups ready? Do you really want to continue to restore Zookeeper?"
+ }
+ // Zookeeper restore section
+ try {
+ salt.runSaltProcessStep(saltMaster, 'I@opencontrail:control', 'service.stop', ['supervisor-config'], null, true)
+ } catch (Exception er) {
+ common.warningMsg('Supervisor-config service already stopped')
+ }
+ try {
+ salt.runSaltProcessStep(saltMaster, 'I@opencontrail:control', 'service.stop', ['supervisor-control'], null, true)
+ } catch (Exception er) {
+ common.warningMsg('Supervisor-control service already stopped')
+ }
+ try {
+ salt.runSaltProcessStep(saltMaster, 'I@opencontrail:control', 'service.stop', ['zookeeper'], null, true)
+ } catch (Exception er) {
+ common.warningMsg('Zookeeper service already stopped')
+ }
+ try {
+ salt.cmdRun(saltMaster, 'I@opencontrail:control', "mkdir /root/zookeeper/zookeeper.bak")
+ } catch (Exception er) {
+ common.warningMsg('Directory already exists')
+ }
+
+ // add check if empty dir ?
+ try {
+ salt.cmdRun(saltMaster, 'I@opencontrail:control', "mv /var/lib/zookeeper/version-2/* /root/zookeeper/zookeeper.bak")
+ } catch (Exception er) {
+ common.warningMsg('Files were already moved')
+ }
+
+ _pillar = salt.getPillar(saltMaster, "I@opencontrail:control", 'zookeeper:backup:backup_dir')
+ backup_dir = _pillar['return'][0].values()[0]
+ if(backup_dir == null || backup_dir.isEmpty()) { backup_dir='/var/backups/zookeeper' }
+ print(backup_dir)
+ salt.runSaltProcessStep(saltMaster, 'I@galera:master', 'file.remove', ["${backup_dir}/dbrestored"], null, true)
+
+ // performs restore
+ salt.cmdRun(saltMaster, 'I@opencontrail:control', "su root -c 'salt-call state.sls zookeeper'")
+
+ salt.runSaltProcessStep(saltMaster, 'I@opencontrail:control', 'service.start', ['zookeeper'], null, true)
+ salt.runSaltProcessStep(saltMaster, 'I@opencontrail:control', 'service.start', ['supervisor-config'], null, true)
+ salt.runSaltProcessStep(saltMaster, 'I@opencontrail:control', 'service.start', ['supervisor-control'], null, true)
+
+ sleep(15)
+ salt.cmdRun(saltMaster, 'I@opencontrail:control', "ls /var/lib/zookeeper/version-2")
+ salt.cmdRun(saltMaster, 'I@opencontrail:control', "echo stat | nc localhost 2181 | grep leader")
+ salt.cmdRun(saltMaster, 'I@opencontrail:control', "contrail-status")
+ }
+ }
+}
+
+
+