Tag: OpenShift

JBoss AS 7 Clustering on OpenShift

Hi,

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 :

$ssh UUID@APPNAME-NAMESPACE.rhcloud.com

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 !! 🙂

Regards,
Middlewaremagic Team 🙂


Integrate your Eclipse Juno IDE with Openshift

Hi,

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. 🙂

Regards,
Middlewaremagic Team 🙂


How to achieve high availability on Openshift ?

Hi,

High availability is a very important feature for any kind of infrastructure. As the name suggests the services should be available at any given point of time. 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).

Lets create a scaled application and see how High Availability works in Openshift. Follow Below steps :

Step-1: Create a new application. Please note that we are using “-s” here to enable scaling:

$ rhc app create -a myhaproxy -t jbossas-7 -s

Above will create a directory “myhaproxy” at the location from where you ran the command from your terminal.

Now there are two types of scaling : Automatic and Manual. The command mentioned in Step-1 creates an application which is auto-scalable, i.e. the application will be scaled based on the incoming load. However you can also scale your application manually. For eg: if you are anticipating a certain amount of load, or you have limited resources (less number of gears available), or if you want to control the cost manually.

Lets see how can we scale our application manually.

Step-2 : Navigate from the directory “myhaproxy” which got created in Step-1 to :

$ cd myhaproxy/.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 :

$ssh UUID@APPNAME-NAMESPACE.rhcloud.com

for eg :

ssh 123a456c09d12345b123a12345cc1234@myhaproxy-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 myhaproxy -u 123a456c09d12345b123a12345cc1234 -n mydomain

..

Now manual scaling is enabled. Let’s check if High Availability works. Try to access the application using the url :

myhaproxy-mydomain.rhcloud.com, this gives the welcome page.

Now again ssh to your application using :

ssh 123a456c09d12345b123a12345cc1234@myhaproxy-mydomain.rhcloud.com

Grep for the java process and kill the process id, now our JBoss server is down. If high availability is working, the url should still work.

myhaproxy-mydomain.rhcloud.com, if this gives the welcome page, we are good :). (Preferably try from a different browser)

You can see high availability statistics from the management console, by logging in to

You can also select minimum or maximum number of gears you want to scale up to.

Regards,
Middlewaremagic Team 🙂


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