Split restoreGaleraDb function and add restoreType param support
- restoreGaleraDb now restores database
- original function renamed to restoreGaleraCluster
- kept restoreGaleraDb(env) method for backwards compatibility
- added support to set the restoreType
- fixed broken db connection
Depends-On: https://gerrit.mcp.mirantis.com/#/c/41885/
Related: PROD-26657 (PROD:26657)
Change-Id: I9790c444ea3d929054a644e1dc6a363aa802b92f
(cherry picked from commit 9044fe45f7aef67bb7ceb992a529a9b50d50e3c9)
diff --git a/src/com/mirantis/mk/Galera.groovy b/src/com/mirantis/mk/Galera.groovy
index 7627077..acf5e9e 100644
--- a/src/com/mirantis/mk/Galera.groovy
+++ b/src/com/mirantis/mk/Galera.groovy
@@ -267,11 +267,12 @@
}
/**
- * Restores Galera database
- * @param env Salt Connection object or pepperEnv
+ * Restores Galera cluster
+ * @param env Salt Connection object or pepperEnv
+ * @param runRestoreDb Boolean to determine if the restoration of DB should be run as well
* @return output of salt commands
*/
-def restoreGaleraDb(env) {
+def restoreGaleraCluster(env, runRestoreDb=true) {
def salt = new com.mirantis.mk.Salt()
def common = new com.mirantis.mk.Common()
try {
@@ -315,11 +316,16 @@
} catch (Exception er) {
common.warningMsg('File is not present')
}
+
+ // make sure that gcom parameter is empty
salt.cmdRun(env, lastNodeTarget, "sed -i '/gcomm/c\\wsrep_cluster_address=\"gcomm://\"' /etc/mysql/my.cnf")
- def backup_dir = salt.getReturnValues(salt.getPillar(env, lastNodeTarget, 'xtrabackup:client:backup_dir'))
- if(backup_dir == null || backup_dir.isEmpty()) { backup_dir='/var/backups/mysql/xtrabackup' }
- salt.runSaltProcessStep(env, lastNodeTarget, 'file.remove', ["${backup_dir}/dbrestored"])
- salt.cmdRun(env, 'I@xtrabackup:client', "su root -c 'salt-call state.sls xtrabackup'")
+
+ // run restore of DB
+ if (runRestoreDb) {
+ restoreGaleraDb(env, lastNodeTarget)
+ }
+
+ // start mysql service on the last node
salt.runSaltProcessStep(env, lastNodeTarget, 'service.start', ['mysql'])
// wait until mysql service on galera master is up
@@ -329,6 +335,34 @@
input message: "Database is not running please fix it first and only then click on PROCEED."
}
+ // start mysql services on the rest of the nodes
salt.runSaltProcessStep(env, "I@galera:master and not ${lastNodeTarget}", 'service.start', ['mysql'])
salt.runSaltProcessStep(env, "I@galera:slave and not ${lastNodeTarget}", 'service.start', ['mysql'])
+
+ // wait until mysql service on the rest of the nodes is up
+ try {
+ salt.commandStatus(env, "( I@galera:master or I@galera:slave ) and not ${lastNodeTarget}", 'service mysql status', 'running')
+ } catch (Exception er) {
+ input message: "Database is not running please fix it first and only then click on PROCEED."
+ }
+
+ // apply any changes in configuration
+ salt.enforceState(env, lastNodeTarget, 'galera')
}
+
+/**
+ * Restores Galera database
+ * @param env Salt Connection object or pepperEnv
+ * @param targetNode Node to be targeted
+ */
+def restoreGaleraDb(env, targetNode) {
+ def backup_dir = salt.getReturnValues(salt.getPillar(env, targetNode, 'xtrabackup:client:backup_dir'))
+ if(backup_dir == null || backup_dir.isEmpty()) { backup_dir='/var/backups/mysql/xtrabackup' }
+ salt.runSaltProcessStep(env, targetNode, 'file.remove', ["${backup_dir}/dbrestored"])
+ salt.cmdRun(env, 'I@xtrabackup:client', "su root -c 'salt-call state.sls xtrabackup'")
+}
+
+def restoreGaleraDb(env) {
+ common.warningMsg("This method was renamed to 'restoreGaleraCluster'. Please change your pipeline to use this call instead! If you think that you really wanted to call 'restoreGaleraDb' you may be missing 'targetNode' parameter in you call.")
+ return restoreGaleraCluster(env)
+}
\ No newline at end of file