This article is a legacy article. It applies to previous versions of the Liferay product. While the article is no longer maintained, the information may still be applicable.
This article describes how to achieve integration between Terracotta and Liferay.
In order to successfully integrate Terracotta with Liferay, a patch from LPS-31709 will be required.
After obtaining the patch, please follow these instructions:
LIFERAY_HOME=/run/shm/6120/bundles TOMCAT_HOME=$LIFERAY_HOME/tomcat-7.0.27 TERRACOTTA_ADDRESS=127.0.0.1:9510 TERRACOTTA_HOME=$HOME/Downloads/terracotta-3.5.5
1. Find the version of Terracotta that corresponds to the version of EhCache used by Liferay. For example, in 6.1 EE SP1 (6.1.20), Liferay uses EhCache 2.4.6. Therefore, a version of Terracotta is needed that ships with EhCache 2.4.x. Terracotta 3.5.3 ships with EhCache 2.4.6 and Terracotta 3.5.5 ships with EhCache 2.4.8.
2. Remove all the EhCache and SLF4j JARs in Liferay's WEB-INF/lib folder and replace them with the ones that are provided in Terracotta's ehcache/lib folder. If this were written in a shell script, it might look something like this:
rm $TOMCAT_HOME/webapps/ROOT/WEB-INF/lib/ehcache*.jar rm $TOMCAT_HOME/webapps/ROOT/WEB-INF/lib/slf4j*.jar cp $TERRACOTTA_HOME/ehcache/lib/ehcache*.jar $TOMCAT_HOME/webapps/ROOT/WEB-INF/lib cp $TERRACOTTA_HOME/ehcache/lib/slf4j*.jar $TOMCAT_HOME/webapps/ROOT/WEB-INF/lib
3. If session replication is not used (please note that session replication is currently not possible with Lifreay 6.1), copy the terracotta-toolkit JAR toLiferay's WEB-INF/lib folder. If this were written in a shell script, it might look something like this:
cp $TERRACOTTA_HOME/common/terracotta-toolkit*.jar $TOMCAT_HOME/webapps/ROOT/WEB-INF/lib
4. Extract the hibernate-terracotta.xml and liferay-multi-vm-terracotta.xml from portal-impl.jar and place them in a "myehcache" folder in Liferay's WEB-INF/classes. After doing so, replace any instance of "localhost:9510" with the actual IP address and port where Terracotta is running (it runs on port 9510 by default, so only change the IP address if it is on a different server). If this were written in a shell script, it might look something like this:
unzip -qq $TOMCAT_HOME/webapps/ROOT/WEB-INF/lib/portal-impl.jar ehcache/hibernate-terracotta.xml ehcache/liferay-multi-vm-terracotta.xml -d $TOMCAT_HOME/webapps/ROOT/WEB-INF/classes mv $TOMCAT_HOME/webapps/ROOT/WEB-INF/classes/ehcache $TOMCAT_HOME/webapps/ROOT/WEB-INF/classes/myehcache sed -i "s/localhost:9510/$TERRACOTTA_ADDRESS/g" $TOMCAT_HOME/webapps/ROOT/WEB-INF/classes/myehcache/hibernate-terracotta.xml sed -i "s/localhost:9510/$TERRACOTTA_ADDRESS/g" $TOMCAT_HOME/webapps/ROOT/WEB-INF/classes/myehcache/liferay-multi-vm-terracotta.xml
5. Add the new hibernate-terracotta.xml and liferay-multi-vm-terracotta.xml to portal-ext.properties. For example, if using the portal-ext.properties in $LIFERAY_HOME, then the shell script might look something like this:
echo -e "\n" >> $LIFERAY_HOME/portal-ext.properties echo "net.sf.ehcache.configurationResourceName=/myehcache/hibernate-terracotta.xml" >> $LIFERAY_HOME/portal-ext.properties echo "ehcache.multi.vm.config.location=/myehcache/liferay-multi-vm-terracotta.xml" >> $LIFERAY_HOME/portal-ext.properties
6. Remove all the Quartz JARs in Liferay's WEB-INF/lib folder and replace them with the quartz-all and quartz-terracotta JARs that are provided in Terracotta's quartz folder. There are other Quartz JARs included in the Terracotta distribution, but they can be safely ignore. If this were written in a shell script, it might look something like this:
rm $TOMCAT_HOME/webapps/ROOT/WEB-INF/lib/quartz*.jar cp $TERRACOTTA_HOME/quartz/quartz-all*.jar $TOMCAT_HOME/webapps/ROOT/WEB-INF/lib cp $TERRACOTTA_HOME/quartz/quartz-terracotta*.jar $TOMCAT_HOME/webapps/ROOT/WEB-INF/lib
7. Update portal-ext.properties so that the old org.quartz.* properties are all blanked out, the jobStore class is set to org.terracotta.quartz.TerracottaJobStore, and a new property "tcConfigUrl" is added which points to the IP address and port where Terracotta are located. If this were written in a shell script, it might look something like this:
echo -e "\n" >> $LIFERAY_HOME/portal-ext.properties echo "org.quartz.jobStore.class=org.terracotta.quartz.TerracottaJobStore" >> $LIFERAY_HOME/portal-ext.properties echo "org.quartz.jobStore.tcConfigUrl=$TERRACOTTA_ADDRESS" >> $LIFERAY_HOME/portal-ext.properties echo "org.quartz.jobStore.dataSource=" >> $LIFERAY_HOME/portal-ext.properties echo "org.quartz.jobStore.isClustered=" >> $LIFERAY_HOME/portal-ext.properties echo "org.quartz.jobStore.misfireThreshold=" >> $LIFERAY_HOME/portal-ext.properties echo "org.quartz.jobStore.tablePrefix=" >> $LIFERAY_HOME/portal-ext.properties echo "org.quartz.jobStore.useProperties=" >> $LIFERAY_HOME/portal-ext.properties
8. The last step is to consider enabling session replication with Terracotta. Hypothetically, if one were to upgrade Liferay's version of EhCache to the same one used in a version of Terracotta where the TerracottaTomcat70xSessionValve is present and fix all EhCache wrapper classes so they properly implement all the new methods added to the upgraded EhCache interface classes. After doing that, users are able to enable session replication using Terracotta.
In order to accomplish this, add the terracotta-toolkit JAR to lib/ext and ensure that the terracota-session JAR is included in lib/ext as well. Afterwards, update all the context XMLs for each of the web applications (stored in conf/Catalina/localhost for Tomcat) so that they know to use the Terracotta valve. If this were to be written as a shell script, it might look something like this:
cp $TERRACOTTA_HOME/common/terracotta-toolkit*.jar $TOMCAT_HOME/lib/ext cp $TERRACOTTA_HOME/sessions/terracotta-session*.jar $TOMCAT_HOME/lib/ext for file in $TOMCAT_HOME/conf/Catalina/localhost/*; do sed -i "s/<\/Context>/\t<Valve className=\"org.terracotta.session.TerracottaTomcat70xSessionValve\" tcConfigUrl=\"$TERRACOTTA_ADDRESS\"\/>\n<\/Context>/" $file
This resource might also prove useful: How do I cluster Liferay with Terracotta?