Optimalize salt results printing
Change-Id: I75dfb480c956a0626117d9c290eb1e4368d701ff
diff --git a/src/com/mirantis/mk/Salt.groovy b/src/com/mirantis/mk/Salt.groovy
index 52e77e8..be7dbb4 100644
--- a/src/com/mirantis/mk/Salt.groovy
+++ b/src/com/mirantis/mk/Salt.groovy
@@ -1,5 +1,6 @@
package com.mirantis.mk
+import java.util.stream.Collectors
/**
* Salt functions
*
@@ -334,6 +335,7 @@
def node=entry[nodeKey]
common.infoMsg("Node ${nodeKey} changes:")
if(node instanceof Map || node instanceof List){
+ def outputResources = []
for (int k=0;k<node.size();k++) {
def resource;
def resKey;
@@ -354,22 +356,24 @@
if(resource.keySet().contains("pchanges")){
resource.remove("pchanges")
}
-
if(!resource["result"] || (resource["result"] instanceof String && resource["result"] != "true")){
if(resource["result"] != null){
- common.errorMsg(String.format("Resource: %s\n%s", resKey, common.prettyPrint(resource)))
+ outputResources.add(String.format("Resource: %s\n\\u001B[31m%s\\u001B[0m", resKey, common.prettyPrint(resource)))
}else{
- common.warningMsg(String.format("Resource: %s\n%s", resKey, common.prettyPrint(resource)))
+ outputResources.add(String.format("Resource: %s\n\\u001B[33m%s\\u001B[0m", resKey, common.prettyPrint(resource)))
}
}else{
if(!onlyChanges || resource.changes.size() > 0){
- common.successMsg(String.format("Resource: %s\n%s", resKey, common.prettyPrint(resource)))
+ outputResources.add(String.format("Resource: %s\n\\u001B[32m%s\\u001B[0m", resKey, common.prettyPrint(resource)))
}
}
}else{
- common.infoMsg(String.format("Resource: %s\n%s", resKey, common.prettyPrint(resource)))
+ outputResources.add(String.format("Resource: %s\n\\u001B[36m%s\\u001B[0m", resKey, common.prettyPrint(resource)))
}
}
+ wrap([$class: 'AnsiColorBuildWrapper']) {
+ print outputResources.stream().collect(Collectors.joining("\n"))
+ }
}else{
common.infoMsg(common.prettyPrint(node))
}