Update getGaleraLastShutdownNode and getWsrepParameters

  - Add ability to pass list of nodes to find the last
    shutdown node from
  - Update imports for getWsrepParameters method and
    fix return key class type

Related: PROD-27547 (PROD:27547)

Change-Id: Ib8f102759284c34d4e9c83b486279c9bae9bdc45
diff --git a/src/com/mirantis/mk/Galera.groovy b/src/com/mirantis/mk/Galera.groovy
index 5178ce2..3cbaafd 100644
--- a/src/com/mirantis/mk/Galera.groovy
+++ b/src/com/mirantis/mk/Galera.groovy
@@ -17,7 +17,9 @@
  */
 
 def getWsrepParameters(env, target, parameters=[], print=false) {
-    result = []
+    def salt = new com.mirantis.mk.Salt()
+    def common = new com.mirantis.mk.Common()
+    result = [:]
     out = salt.runSaltProcessStep(env, "${target}", "mysql.status", [], null, false)
     outlist = out['return'][0]
     resultYaml = outlist.get(outlist.keySet()[0]).sort()
@@ -30,12 +32,12 @@
     if (parameters == [] || parameters == ['']) {
         result = resultYaml
     } else {
-        for (key in parameters) {
-            value = resultYaml[key]
+        for (String param in parameters) {
+            value = resultYaml[param]
             if (value instanceof String && value.isBigDecimal()) {
                 value = value.toBigDecimal()
             }
-            result = ["${key}": value] + result
+            result[param] = value
         }
     }
     return result
@@ -217,13 +219,27 @@
     }
 }
 
-def getGaleraLastShutdownNode(env) {
+/** Returns last shutdown node of Galera cluster
+@param env      Salt Connection object or pepperEnv
+@param nodes    List of nodes to check only (defaults to []). If not provided, it will check all nodes.
+                Use this parameter if the cluster splits to several components and you only want to check one fo them.
+@return status  ip address or hostname of last shutdown node
+*/
+
+def getGaleraLastShutdownNode(env, nodes = []) {
     def salt = new com.mirantis.mk.Salt()
     def common = new com.mirantis.mk.Common()
-    members = ''
+    members = []
     lastNode = [ip: '', seqno: -2]
     try {
-        members = salt.getReturnValues(salt.getPillar(env, "I@galera:master", "galera:master:members"))
+        if (nodes) {
+            nodes = salt.getIPAddressesForNodenames(env, nodes)
+            for (node in nodes) {
+                members = [host: "${node.get(node.keySet()[0])}"] + members
+            }
+        } else {
+            members = salt.getReturnValues(salt.getPillar(env, "I@galera:master", "galera:master:members"))
+        }
     } catch (Exception er) {
         common.errorMsg('Could not retrieve members list')
         return 'I@galera:master'