Created
May 29, 2018 13:02
-
-
Save malys/844a7a29a6775867d4565cec7e4e7d43 to your computer and use it in GitHub Desktop.
[Wildfly] Compare context #wildlfy #cli
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package scripts | |
| import org.jboss.as.cli.scriptsupport.CLI | |
| import org.jboss.dmr.ModelNode | |
| import org.jboss.dmr.Property | |
| import java.security.KeyManagementException | |
| import java.security.NoSuchAlgorithmException | |
| import static groovy.json.JsonOutput.prettyPrint | |
| import static groovy.json.JsonOutput.toJson | |
| /*** | |
| * Script launcher | |
| * | |
| * -Djavax.net.ssl.trustStore="C:/Program Files/Java/jre1.8.0_151/lib/security/cacerts" -Djavax.net.ssl.trustStorePassword=xxxx -DDEBUG=true -DSECURITY=OFF | |
| * user pw server1 server2 | |
| */ | |
| public class CompareConfiguration { | |
| static List<String> envVariable=['CERTIFICATE_DIR','DATA_DIR','SECURITY_DIR','DOMAIN', | |
| 'LDAP_LOGIN','LDAP_CONTEXT','LDAP_HOST','LDAP_USERNAME_ATTRIBUTE}', | |
| 'VAULT_PASSWORD','VAULT_SALT', | |
| 'JBOSS_NODE_ID','JBOSS_NODE_IP','INITIAL_HOSTS','TRAP_HOST','TRAP_OID_ERROR','TRAP_OID_FATAL'] | |
| static Map<String, List<String>> compare(oldMap, newMap) { | |
| def newKeys = newMap*.key | |
| def oldKeys = oldMap*.key | |
| def removedKeys = oldKeys - newKeys | |
| def addedKeys = newKeys - oldKeys | |
| def commonKeys = newKeys - removedKeys - addedKeys | |
| def changedKeys = commonKeys.findAll { oldMap[it] != newMap[it] } | |
| def unchangedKeys = commonKeys - changedKeys | |
| def changes = [ | |
| removed : oldMap.findAll { it.key in removedKeys }, | |
| added : newMap.findAll { it.key in addedKeys }, | |
| changed : oldMap.findAll { it.key in changedKeys }, | |
| diff : changedKeys.collectEntries { k -> [k, oldMap[k] + "<--->" + newMap[k]] }, | |
| unchanged: newMap.findAll { it.key in unchangedKeys }, | |
| ] | |
| return changes | |
| } | |
| static void checkUndefined(String currentEndpoint,String key, String value){ | |
| if("undefined" == value || ""== value || null == value){ | |
| println "UNDEFINED -> $currentEndpoint $key=$value" | |
| } | |
| } | |
| static Map<String, String> process(String currentEndpoint,String currentUser,String currentPw){ | |
| CLI cli = CLI.newInstance() | |
| cli.connect("https-remoting", new URI(currentEndpoint).getHost(), 9993, currentUser, currentPw.toCharArray()) | |
| CLI.Result resp = cli.cmd("/core-service=platform-mbean/type=runtime:read-attribute(name=system-properties)") | |
| ModelNode node = resp.getResponse().get("result") | |
| Map<String, String> map1 = new HashMap<>() | |
| for (Property i : node.asPropertyList()) { | |
| map1.put(i.getName(), i.getValue().toString().replaceAll("^\"|\"\$", "")) | |
| checkUndefined(currentEndpoint,i.getName(), i.getValue().toString()) | |
| } | |
| envVariable.each { | |
| it -> resp = cli.cmd(":resolve-expression(expression=\${env.$it})") | |
| node = resp.getResponse().get("result") | |
| map1.put("env.$it",node.toString().replaceAll("^\"|\"\$", "")) | |
| checkUndefined(currentEndpoint,it, node.toString()) | |
| } | |
| cli.disconnect() | |
| return map1 | |
| } | |
| public | |
| static void main(String[] args) throws IOException, NoSuchAlgorithmException, KeyManagementException, URISyntaxException { | |
| //Inherit from Deployer context | |
| final String currentUser = args[0] | |
| final String currentPw = args[1] | |
| def listEndpoint | |
| final String currentEndpoint1 = args[2] | |
| final String currentEndpoint2 = args[3] | |
| Map<String, String> map1 = process(currentEndpoint1,currentUser,currentPw) | |
| Map<String, String> map2= process(currentEndpoint2,currentUser,currentPw) | |
| def result = compare(map1, map2) | |
| println "$currentEndpoint1 <---> $currentEndpoint2" | |
| //println "-------------- UNCHANGED ------------- " | |
| //println prettyPrint(toJson(result.unchanged)) | |
| println "-------------- ADDED ------------- " | |
| println prettyPrint(toJson(result.added)) | |
| println "-------------- REMOVED ------------- " | |
| println prettyPrint(toJson(result.removed)) | |
| println "-------------- DIFF ------------- " | |
| println prettyPrint(toJson(result.diff)) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment