Tag: Jboss AS7

JBoss AS 7 Clustering on OpenShift


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 :

ssh 123a456c09d12345b123a12345cc1234@clusterwebapp-mydomain.rhcloud.com

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 :

ssh 123a456c09d12345b123a12345cc1234@clusterwebapp-mydomain.rhcloud.com

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 🙂

Integrate your Eclipse Juno IDE with Openshift


In this article we will discuss how can we integrate our Eclipse IDE to OpenShift and create new applications. In previous articles we discussed about how we can connect to OpenShift and create application through command line and management console ? But of-course it would be really great if we can create, build, test, modify and publish our applications directly from the IDE itself.

I am going to use Eclipse Juno, which is the latest eclipse IDE and will create a sample JBossAS-7 application

Download Eclipse from here.

Download Eclipse Juno depending on your Operating System. I chose Windows-64 bit version. If you are already running an older version of Eclipse, you can always upgrade it or try to follow the same steps with little tweaks 🙂

Step-1: Start Eclipse and navigate to Help tab. Here select Eclipse Marketplace and search for JBoss Tools, click on install.

Select the OpenShift tools as shown in image :

Once done, click next and accept the License Agreements and then restart Eclipse. It will come up with a welcome page like below :

Step-2 : Lets create an application now. On the welcome page itself click on OpenShift Application. It will ask you to sign-in with your OpenShift account. Saving the password is completely your choice.

Now give a name to your application and select what type of application you want to create from the available options shown in below image. Also select the embedded cartridges, if you want to use any.

I am not using any embedded cartridge for now, now click next.

Here we get an option, whether we want to create a new project or would like to use an existing project. Also it is good to check the option for creating a server, which will help us to easily test and publish our application. Click next.

Now we need to setup clone destination, basically the application created on OpenShift Server will be cloned to this directory. Make sure that directory exists, before this setup 🙂

Step-3 : Now it is time to configure SSH keys, if you don’t.. you would end up with below.

Click on SSH2 Preferences to configure your keys. Navigate to Key Management and click on Generate RSA Key.

Let’s save the private key and click Ok.

Step-4 : Now you must add this public key to your OpenShift account. For this

login to your OpenShift account. Navigate to My Account page and add your Public Key there.

Let’s carry forward the Step-3 and click on finish. This will prompt you to enter a passphrase for your private key.

Click Ok and you will get a local copy of the application on your machine. You may see an error mark against your application in Package Explorer view, this can be solved by updating you maven configuration. Check below :

Step-5 : Now lets make some changes in to the application. I made a change in “index.html”. once you save this, you might get a popup stating that there has been a change in one of your file, would you like to publish it ? you can click on yes and the change would be pushed to OpenShift server.

Right click on your project and run the application on server.

This will first build your application :

and then it will publish it as well, see the changes that we made :

You can also navigate to the Servers tab, right click on your OpenShift Server and click on Publish.

If you want to tail the log files, check environment variables or try port-forwarding it is all there. See below :

So once the environment has been set, you can make multiple changes and can publish them at your will. 🙂

Middlewaremagic Team 🙂

How to load jars residing over NFS in JBossAS7 classpath ?


In this article we will discuss how can we load jars residing over NFS in JBoss AS-7 classpath. In some development environment, when there are multiple jars and properties files are being used by multiple servers, it is good to put all of them in a central repository, so that if the files (jar/properties files/xmls) are modified, all the servers will pickup the latest version and there will be less overhead related to copying the latest versions to individual servers

NFS allows a user on a client computer to access files over a network in a manner similar to how local storage is accessed. I installed NFS using below link :


As JBoss AS-7 has introduced a module structure to load your custom jars. One can quickly create a custom module and put the required jars in them, with appropriate entries in module.xml . But in this case we would be needing an additional module directory, which would be residing over NFS server and we would map this to our local (client) server.

Step-1: Modify standalone.sh and add a separate module directory. To do this navigate to $JBOSS_HOME/bin and edit the file.

Search for keyword “module” and it should look like below :

if [ "x$JBOSS_MODULEPATH" = "x" ]; then

Edit the above section of your “standalone.sh” script and then add the “:” separated path of your module directories as following


#if [ "x$JBOSS_MODULEPATH" = "x" ]; then

Here /mnt/nfs/ is the directory, where our new module directory would be residing.

Step-2 : On the shared mount create below directory structure :

├── aaa
   └── bbb
       └── ccc
           └── main
               ├── module.xml
               ├── utility_JAR.jar



module.xml :


<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="aaa.bbb.ccc">
       <resource-root path="utility_JAR.jar"/>


Step-3 : Now lets create a simple application which would be using utility_JAR.jar (ClassLoaderTestWAR.war). The war file will have below structure :”

├── index.jsp
   ├── jboss-deployment-structure.xml
   ├── web.xml

Where :

index.jsp :

     <head><title>ClassLoader Demo</title></head>
     <body bgcolor="maroon" text="white">
                    <h1>Class Loader Demo..</h1>

       aaa.bbb.TestUtility utility=new aaa.bbb.TestUtility();
       String whichClassLoader=utility.sayWhichClassLoader();
       System.out.println("nnt -----> "+whichClassLoader);


jboss-deployment-structure.xml :


<?xml version="1.0" encoding="UTF-8"?>
       <module name="aaa.bbb.ccc" />


web.xml :




Step-4 : Now deploy the application and start the JBoss AS-7 server.

Step-5 : Access the application using : http://localhost:8080/ClassLoaderTestWAR

You will see something like below :

If the above output comes that means the jar was loaded from our new module directory, which resides over NFS.

Middlewaremagic Team 🙂

Copyright © 2010-2012 Middleware Magic. All rights reserved. |