High availability and fail-over are very important feature for any kind of infrastructure. As the name suggests the services should be available at any given point of time and requests should fail over if any component goes down abruptly. You can have several parallel instance of an application and can scale up and down depending on the business requirement, without worrying much about the cost. Load is distributed across different servers, and even if one or more of the servers fails, the application is still accessible via the other application instances. HA is crucial for scalable enterprise applications, as you can improve performance by adding more gears (which will be replica of your current one).
The latest Openshift Online has came up with “JEE Full Profile on JBoss” cartridge which allows you to get benefits of JBoss Clustering. It simply uses HAProxy as a load balancer upfront and creates multiple replicas of you application. The scaling can be based on your choice automatic or manual.
In this article we will see a demo of JBoss Clustering over Openshift. We will deploy a sample application on a two node JBoss Cluster and will try to replicate the user sessions in case of a jvm failure.
Step-1: Create a new application. Please note that we are using “-s” here to enable scaling:
$ rhc app create -a clusterwebapp -t jbossas-7 -s
Above will create a directory “clusterwebapp” at the location from where you ran the command from your terminal.
Download the application from : https://github.com/nikhilmone/ClusteredWebApp and put it inside the deployments directory. Once done simple git add, commit and push your application.
Step-2 : For this example we would be using manual scaling, so that we can quickly check if session replication works.
$ cd clusterwebapp/.openshift/markers/
Step-3 : Create a blank file as “disable_auto_scaling” :
$ touch disable_auto_scaling
Step-4 : Now add the changes to git repository, commit the changes and push them to Openshift server :
.. $ cd ../../ $ git add .openshift/markers/disable_auto_scaling $ git commit -m "disabling auto-scaling" $ git push ..
Step-3 : Once the auto-scaling is disabled, lets enable manual scaling :
Create an SSH connection to your application :
for eg :
Step-4 : Run below command to enable manual scaling :
$ add-gear -a APPNAME -u UUID -n NAMESPACE
for eg :
.. add-gear -a clusterwebapp -u 123a456c09d12345b123a12345cc1234 -n mydomain ..
Now manual scaling is enabled. Let’s check if High Availability works. Try to access the application using the url :
Navigate to the management console now and select how many gears you want to scale your application, select two for now, so we will have a 2 node JBoss Clustering.
Let’s try to hit the application which is currently deployed on a 2 node JBoss Cluster.
http://clusterwebapp-mydomain.rhcloud.com/ClusterWebApp, this gives the welcome page.
You can see the session ID here. Now since we have established a session with the application, let’s bring down the JBoss node abruptly to check if this session fails over.
SSH to your application using :
Grep for the java process and kill the process id, now our JBoss server is down. If clustering is working, the url should still work.
Hit http://clusterwebapp-mydomain.rhcloud.com/ClusterWebApp again, if this gives the same session ID that means our session has been failed over to the other JBoss node. To make sure this, do check the server logs 🙂
Note that you can only run TCP clustering on OpenShift as of now. The best part is a developer need not to bother about clustering configuration OpenShift takes care of that. Quite a PaaS huh !! 🙂
Middlewaremagic Team 🙂