2016-01-25

Beware of Liferay on a GlassFish Application Server

If you're using Liferay to build a portal or website, I highly recommend using Liferay with bundled Tomcat.  Learn from other's headaches, it's not worth the trouble of trying to use something other than Tomcat.

Originally, we were trying to use GlassFish 3.x.x because we have a support contract.  We got our environments up and running reasonably quickly.  Our environments were the following:

  • Local Dev (Windows 7) - Tomcat7 (bundled Liferay Developer Studio), MySQL V5 DB
  • Dev (Ubuntu VM) - Liferay 6.1.2 deployed to GlassFish , MySQL V5 DB
  • Test (RHEL) - Liferay 6.1.2 deployed to GlassFish , Oracle 10G
  • QA (RHEL) - Liferay 6.1.2 deployed to GlassFish, Oracle 10G
  • Production (RHEL) - Liferay 6.1.2 deployed GlassFish, Oracle 10G

Once we started doing significant work, developing portlets and customizing Liferay (hooks, themes, ext plugin, etc...) we started running into problems.

I had difficulties migrating data between environments, which was important early in development.  While trying to migrate the database from one environment to another (Control Panel -> Server -> Administration -> Data Migration), I repeatedly got errors and the migration failed.  I determined that migrating from one environment to another never worked when using Liferay deployed to GlassFish.  The migrations always failed with a null pointer exception.  Analysing the error in the logs and a Google search didn't lead to a solution to the problem.

However, I did eventually find a workaround for migrating data between environments, but it wasn't practical due to our network configuration (Firewalls blocking traffic between certain environments).  The workaround was to connect my Local Dev environment, by temporarily modifying my portal-ext.properties file, to the source database for the data migration.  Basically I found that the version of Liferay bundled with Tomcat was the only Liferay installation able to perform the data migration successfully.

We did encounter other problems using GlassFish as well.  We put a lot of effort into clustering Liferay deployed to GlassFish without success.  After scouring the Liferay forums and discussing our options with Liferay support we decided to give up on GlassFish and use Tomcat instead.

After switching to Tomcat, we had clustering working with minimal effort and our data migration issues were solved.  In hindsight we would have saved a lot of time and effort by simply using Tomcat from the start.  It's important to note as well, that we haven't had any stability/reliability issues due to Tomcat, and have almost been live for 2 years. 

2015-05-04

Polishing your Portal with a High-Load Page

When your servers become overloaded with requests, they're unable to your end users with the experience you desire.  It's important in these situations to fail gracefully so that your end users (customers, employees or whomever it may be) don't become frustrated with your site.  We wanted to provide a customized high-load page so that our site:

  • Fails gracefully for users trying to connect, and minimally affects users who are already connected
  • Looks a more polished and professional
  • Is guaranteed to provide a known QoS to our customers

The portal we're customizing is based on Liferay.  In our case, we didn't like the error page that Liferay provides by default when using the session.max.allowed property, so we decided to do some customizations.

To do so we added a redirect to a high load page based on the user session count.  The high load page is an extremely simple page.  We're using static HTML served by Tomcat, and we made it as light weight as possible.  Serving the page with Apache HTTP would be better, however we don't have the option to do so in our system.

There were 4 steps to adding this page:

1. Add custom properties to portal-ext.properties file

2. Create a class that tracks the session count
 - Use a listener to track the number of sessions , increasing count on creation and decreasing count on destroy
 - There are several examples of doing this on the web, i.e.
 - http://tomcat-configure.blogspot.ca/2009/01/tomcat-session-listener-example.html
 - The listener must be added to the web.xml in your Liferay ext plugin

3. Check session count in all desired classes that extend HttpServlet
  - Must be done in the Liferay ext plugin, follow proper ext patterns explained at www.liferay.com
  - If too high (above threshold in portal-ext.properties), redirect to low load page and invalidate session
    - Redirection page should be in portal-ext.properties to allow it to be reconfigured without recompiling the code (and redeploying the ext plugin)

4.  Create a very simple target page that will result in minimal server load
 - In our case I just created a directory in webapps (using tomcat) with an index.html file
 - index.html contained simple message explaining we're experiencing higher than normal load, please re-visit the site later


2015-02-13

Automatically Email Zigbee/Z-wave Sensor Changes from the Almond+ WiFi Router

Disclaimer: I do not work for Securifi

Last year I backed the Almond+ WiFi router on Kickstarter (Securifi).  After a couple of delays which weren't entirely unexpected from this type of project, I received it in the mail.  Since then, it has been working quite well.

Before delivering the Almond+, Securifi sent out an option for backers to order sensors from them.  Since they were ~$30 each, I figured I would get a couple and try them out.  I ordered a flood sensor, AC switch, window/door switch and a motion sensor.

Securifi has a cloud service that allows you to remotely connect to your router, monitor sensors, etc...  They're working on pushing sensor statuses to a mobile app you install on your smartphone, however last I checked they have some bugs they're still fixing.  There are several people waiting patiently for this functionality, including myself.  I also decided to quickly code a poller.

Since you can get sensor statuses from the routers web interface, I decided to write a python polling script that will scrape the sensor values from your router and send an email whenever they change.  I threw the script together pretty quickly, so it's not the greatest code but it works.

I setup the script as a service that automatically runs on startup on a computer running Ubuntu Linux.

A couple of quick notes:
  • Update all the xxxx in the Python source code as appropriate
  • You may have to tweak ALMOND_URL for different versions of firmware
    • I have version Software Version : AP2-R070-L009-W016-ZW016-ZB005
  • I did have issues with the gmail password, and had to follow some steps found at the accounts website (see comment above variable) to setup the application
  • With a couple of changes, I'm sure you can get it working with email services other than gmail, or if you're more ambitious change it entirely to use some other communication (twitter, ifttt would be very powerful, etc...)
  • I added a bit of code to interpret the status of the sensors I have, I haven't tried it with any other sensors but I don't see why they wouldn't work
    • Custom code can easily be added for other sensors to make their status more human readable
Click here for the Python source code.

Post any questions, suggestions, and changes/additions you make in the comments section below.