Last active
March 14, 2017 14:51
-
-
Save sammso/213fd3a3713de666212b8a5d963907a2 to your computer and use it in GitHub Desktop.
Tool to help analyze Liferay portal cache settings
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
/*** | |
* ehCache configuration parser | |
* | |
* This parses the configurations to be imported following table | |
CREATE TABLE CacheSettings ( | |
cacheType VARCHAR(12) NOT NULL, | |
bean VARCHAR(255) NOT NULL, | |
eternal VARCHAR(5) NOT NULL, | |
cacheSize INT NOT NULL, | |
timeToLive INT NULL, | |
timeToIdleSeconds INT NULL, | |
PRIMARY KEY ( cacheType,bean ) | |
); | |
*/ | |
if ( args.length == 0) { | |
println "Provide liferay-multi-vm-clustered.xml or liferay-single-vm.xml file as parameter" | |
return; | |
} | |
def file = new File(args[0]); | |
if (!file.exists()) { | |
println "File " + file.getName() + " does not exist"; | |
return; | |
} | |
if (!file.isFile()) { | |
println "File " + file.getName() + " is not file"; | |
return; | |
} | |
def ehcacheXML = new XmlParser().parse(file) | |
def cacheType = "liferay-m"; | |
if (file.getName().contains("single")) { | |
cacheType = "liferay-s"; | |
} | |
//println ehcacheXML; | |
ehcacheXML.each({ | |
ehcache -> | |
if ( ehcache.name() == "cache" ) { | |
println "INSERT INTO CacheSettings VALUES (\"" + cacheType + "\",\"" + ehcache.@'name' + "\",\"" + ehcache.@'eternal' + "\"," + ehcache.@'maxElementsInMemory' + "," + ehcache.@'timeToLive' + "," + ehcache.@'timeToIdleSeconds' + ");"; | |
} | |
else if ( ehcache.name() == "defaultCache" ) { | |
println "INSERT INTO CacheSettings VALUES (\"" + cacheType + "\",\"_DEFAULTCACHE_\",\"" + ehcache.@'eternal' + "\"," + ehcache.@'maxElementsInMemory' + "," + ehcache.@'timeToLive' + "," + ehcache.@'timeToIdleSeconds' + ");"; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment