Merge "Split restoreGaleraDb function and add restoreType param support" into release/proposed/2019.2.0
diff --git a/src/com/mirantis/mk/Galera.groovy b/src/com/mirantis/mk/Galera.groovy
index a49d9f8..384caaa 100644
--- a/src/com/mirantis/mk/Galera.groovy
+++ b/src/com/mirantis/mk/Galera.groovy
@@ -286,11 +286,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 {
@@ -334,11 +335,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
@@ -348,6 +354,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