Welcome!

Java Authors: Lori MacVittie, Sandi Mappic, JP Morgenthal, Ivan Antsipau, Esmeralda Swartz

Related Topics: Java, Cloud Expo, Apache

Java: Article

Dynamic Clustering for J2EE Cloud Environments

Cloud computing is one of the emerging paradigms in today's computing world

Cloud computing is one of the emerging paradigms in today's computing world. One of the main advantages of migrating to the cloud is its elastic nature. Elasticity allows dynamic provisioning and de-provisioning of resources according to the application's workload requirement.

In a traditional on-premise J2EE infrastructure, information about the application server and web server resources are available during deployment. Clustering of such an infrastructure to achieve scalability is much simpler since the information about resources is known beforehand. But in a cloud environment, because of its elastic nature, resources get provisioned and de-provisioned dynamically based on the workload. So a j2ee cloud environment has challenges like reconfiguring automatically for the addition/removal of application server instances to/from the cluster. One solution from the open source space is to use Apache Httpd web server with mod_cluster load balancing module and JBoss application server.

The article will discuss the features of mod_cluster which enable it to operate in a cloud environment and also the steps to set up a highly scalable J2EE cloud environment in your lab.

Introduction to mod_cluster
mod_cluster is an extension of the Apache httpd mod_proxy load balancing module and can balance http requests across multiple instances of JBoss Application Server, JBoss Web standalone, or Tomcat. The unique feature of mod_cluster is that once the initial configuration is done, there is no need of any manual configuration changes for adding or removing JBoss AS or Tomcat instances.

mod_cluster uses two communication channels for its working. It uses ajp, http or https to forward requests from httpd to one of the application server nodes. The backward channel is used by the application server nodes to send server side information to the httpd side and is the key differentiator for mod_cluster with respect to other load balancing modules. This channel sends real time information about load balancing factors for each node and application life cycle events.

Some of the key features of mod_cluster that enable it to be used in cloud environments are

Dynamic configuration
Common httpd based load balancers like mod_jk and mod_proxy require the configuration of workers (application servers) at the httpd side. So if you want to add a new worker, you will have to change the configuration in httpd side and restart the proxy. This is an overhead in case of large or dynamically varying clusters like in cloud environments.

But with mod_cluster the proxy information is maintained in the application server side through a static list or through the advertise mechanism (using mod_advertise) . As the workers start, the listeners receive multicast pings which contain the host and port information about the proxies. Now the workers can send events to the detected proxies and the proxies auto configure themselves to balance request between the nodes.

Dynamic determination of load balancing factor
In common httpd based load balancers, the ratio in which load is distributed among the workers is determined by a static factor we provide at the httpd load balancer configuration. But in the case of mod_cluster the load balancing factor is determined at the application server side based on the real time values monitored at runtime. Load computation is pluggable and you can write your own LoadMetric based on the metric you want in addition to the default load metrics.

Fine grained web application life cycle
In the case of mod_cluster, the applications deployed in the application server side are registered with the httpd side through the Mod-Cluster Management protocol. So the http side has information about which all applications are deployed in which instances and transfers the requests only to the nodes which have the requested application. Since the proxies have information on the applications deployed on each of the workers, we can keep highly sensitive applications on our private cloud and move lesser critical applications to some public provider. This enables us to scale up without compromising security as the data sensitive applications will be in our local premises only . For example in a shopping cart scenario browsing the catalog can go into the public cloud and sensitive requirements like payments can stay in company's private cloud.

The following section describes how we can set up a highly scalable j2ee environment using vmware(or any other private cloud solution like Eucalyptus or Open Nebula) in your lab setup.

Environment Set-Up
We have VMware vCenter server setup in one of the machines and connected to an ESXi host. The discussion is based on the assumption that the reader knows how to create a virtual machine and install guest operating system in a vmware environment. Our virtual machine has CENTOS 5.4 installed in it.

To set up dynamic cluster in cloud, we need minimum of two instances:

  1. Apache httpd + mod_cluster
  2. JBoss 5.1 application server with mod_cluster

Now we can look into creating each of these images/templates with necessary startup scripts in details. These steps can be done in any of the CentOS 5 installed machine or virtual machines.

Creating Apache httpd image
Step 1. Create a base virtual machine with centos 5.x as the guest operating system.
Refer creating a virtual machine and installing guest os for VMWare virtual machine creation.

Step 2. Install Apache httpd and mod_cluster in the virtual machine
Download the apache httpd integrated with latest mod_cluster distribution here. To install httpd with mod_cluster, move the distribution to the vm and extract mod_cluster-1.1.xxx-linux2-x86-ssl.tar.gz file using the following command

tar xvf mod-cluster-1.1.0.xxx-linux2-x86-ssl.tar.gz

This by default installs httpd with required mod_cluster modules in /opt/jboss directory.

Step 3. Configuring mod_cluster at httpd side
The httpd configuration file will be httpd.conf which is located in /opt/JBoss/httpd/httpd/conf. From mod_cluster1.1.0CR2 mod_cluster comes with some quick start values.

LoadModule proxy_module modules/mod_proxy.so

LoadModule proxy_ajp_module modules/mod_proxy_ajp.so

LoadModule slotmem_module modules/mod_slotmem.so

LoadModule manager_module modules/mod_manager.so

LoadModule proxy_cluster_module modules/mod_proxy_cluster.so

LoadModule advertise_module modules/mod_advertise.so

The above configuration specifies the extra modules required for httpd with mod_cluster. If you are adding mod_cluster to the existing httpd installation, you have to download the modules and add the above configuration to httpd.conf file.

# MOD_CLUSTER_ADDS

# Adjust to you hostname and subnet.

<IfModule manager_module>

Listen *:6666

ManagerBalancerName mycluster

<VirtualHost *:6666>

<Directory />

Order deny,allow

Deny from none

Allow from all

</Directory>

KeepAliveTimeout 300

MaxKeepAliveRequests 0

#ServerAdvertise on http://@IP@:6666

AdvertiseFrequency 5

#AdvertiseSecurityKey secret

#AdvertiseGroup @ADVIP@:23364

<Location /mod_cluster_manager>

SetHandler mod_cluster-manager

Order deny,allow

Deny from none

Allow from all

</Location>

</VirtualHost>

</IfModule>

Customize the above configuration for your own needs as this is not suitable for production environment.

Step 4. Starting httpd at boot up
We need the httpd to be up and running when the machines boots up. To achieve this we have to expose httpd as a service through init scripts.

The below script can be used to start and stop httpd at boot up.

#!/bin/sh

# chkconfig: - 64 36

# description: Apache Start|Restart|Stop Web Server

APACHE_HOME=/opt/jboss/httpd

case "$1" in

start)

echo "Starting Apache ..."

# Change the location to your specific location

$APACHE_HOME/sbin/apachectl start

;;

stop)

echo "Stopping Apache ..."

# Change the location to your specific location

$APACHE_HOME/sbin/apachectl stop

;;

graceful)

echo "Restarting Apache gracefully..."

# Change the location to your specific location

$APACHE_HOME/sbin/apachectl graceful

;;

restart)

echo "Restarting Apache ..."

# Change the location to your specific location

$APACHE_HOME/sbin/apachectl restart

;;

*)

echo "Usage: '$0' {start|stop|restart|graceful}" >&2

exit 64

;;

esac

exit 0

Copy the above script to /etc/init.d/httpd file or write your own startup script for apache httpd.

Give the file execute permission

chmod +x /etc/init.d/httpd

Add httpd as service at required run levels

chkconf -add httpd

chkconfig -level 345 httpd on

Now to test the set up try

service httpd start

Starting httpd:                                         [ OK ]

Try http://[ip]:[mod_clusterport]/mod_cluster_manager in the browser.

You should be able to see the following window

Step 5. Convert virtual machine to template
To avoid repeating the same steps for creating httpd virtual machine, you can create the clone of the vm. For vmware powerOff the virtual machine and clone it to template

Now we will look into how to create the jboss image.

Creating JBoss image
Step 1. Create the Centos vm

Refer image creation for httpd

Step 2. Install Java
You can get the latest Java from the following location and the second link explains steps for java installation.

http://www.oracle.com/technetwork/java/javase/downloads/index.html

http://www.oracle.com/technetwork/java/javase/index-137561.html

Step 3. Installing JBoss AS with mod_cluster

We are using JBoss 5.1GA which can be obtained here. Let $JBOSS_HOME is the JBoss installation directory. For installing jBoss AS simply extract the downloaded tar file.

For the demo JBOSS_HOME = /home /JBoss-5.1.0.GA

Download the latest java bundles for mod_cluster here. mod_cluster 1.1.0 work with with JBoss AS 5.1 with out of box.Extract the mod_cluster-1.1.0.xxx-bin.tar.gz file and copy the mod_cluster.sar to the deploy folder.

tar xvf mod_cluster-1.1.0.CR3-bin.tar.gz

cp -r /tmp/mod_cluster.sar $JBOSS_HOME/server/all/deploy

Assuming you have extracted to /tmp directory

cp -r /tmp/mod_cluster.sar $JBOSS_HOME/server/all/deploy

Step 4. Configuration

The main configuration file is mod_cluster-JBoss-beans.xml under

$JBOSS_HOME /server/all/deploy/ mod_cluster.sar/ META-INF/

By default mod_cluster is configured to work in clustered mode. In clustered mode, a single JBoss node is responsible for providing the entire cluster view to the front-end httpd processes.  The default configuration uses advertise mechanism using the mod_advertise module.

Step 5. JBoss as a service at startup

Execute the following commands to add new user jboss and give the startup file execute permission.

#create and give permissions to user jboss

adduser jboss

chown -Rf jboss.jboss /$JBOSS_HOME

#copy the default startup script to /etc/init.d

cd /$JBOSS_HOME /bin

cp JBoss_init_redhat.sh /etc/init.d/jboss

chmod +x /etc/init.d/jboss

Modify the /etc/init.d/jboss file to point JBOSS_HOME and JAVAPTH to point to the actual installed directories.

# chkconfig: - 35 90

# description: JBoss Start|Restart|Stop Application Server

# pidfile: /var/run/JBoss.pid

....

JBOSS_HOME=${JBOSS_HOME:-"$JBOSS_HOME"}

#define the user under which JBoss will run, or use 'RUNASIS' to run as the current user

JBOSS_USER=${JBOSS_USER:-"JBoss"}

#make sure java is in your path

JAVAPTH=${JAVAPTH:-"jdk installation folder "}

#configuration to use, usually one of 'minimal', 'default', 'all'

JBOSS_CONF=${JBOSS_CONF:-"all"}

#if JBOSS_HOST specified, use -b to bind JBoss services to that address

OS=`uname`

IP="" # store IP

case $OS in

Linux) IP=`ifconfig eth0| grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'`;;

FreeBSD|OpenBSD) IP=`ifconfig eth0 | grep -E 'inet.[0-9]' | grep -v '127.0.0.1' | awk '{ print $2}'` ;;

SunOS) IP=`ifconfig -a eth0 | grep inet | grep -v '127.0.0.1' | awk '{ print $2} '` ;;

*) IP="Unknown";;

Esac

#Bind to the current ip address

JBOSS_HOST=$IP

JBOSS_BIND_ADDR=${JBOSS_HOST:+"-b $JBOSS_HOST"}

The above modification is to bind jboss to the ip address of the jboss instance.

To add jboss as a service at startup,

#command to start jboss at runlevel 3,4 and 5

chkconfig --add jboss

chkconfig --level 345 jboss on

service jboss start

Check in the browser if JBoss is started

http://[jboss-ip]:8080

Step 6. Convert vm to template

For vmware powerOff the virtual machine and clone it to template.

Testing the environment
Create virtual machines from the above created templates using vijava api or vCenter client. After one instance of both apache httpd and jboss got powered on, check the mod_cluster_manager using the url,

http://[webserverip]:[mod_clusterport]/mod_cluster_manager/

We can see that the JBoss worker is balanced by the mod_cluster. If we create one more JBoss instance, the new one will get added to that balancer. So if you have an application deployed on both of the JBoss instances, the requests will be distributed across the JBoss instances. Similarly when you start up new JBoss instances, the instances will get registered automatically to the proxy and become available for load balancing.If we kill a JBoss instance that will automatically get de-registered from the proxy balancer.

Set up in an environment where multicast is not supported
The above setup showed mod_cluster configuration using advertise mechanism, which uses muticast pings for auto discovery. But major cloud providers like Amazon EC2, Rackspace, GoGrid etc doesn't support multicast in their environment. To overcome this, information about the proxies can be passed through an JBoss argument (JBoss.mod_cluster.proxyList) at start instance up or use the addProxy method exposed by mod_cluster through JMX. The addProxy method takes the IP of httpd proxy and the port on which mod_cluster is listening. You can go to the JBoss AS JMX-Console to do this or use the java code to invoke this method remotely.

To disable the advertise mechanism following configuration changes need to be done :

At httpd side : Set the ServerAdvertise property to off in httpd.conf config file in /opt/JBoss/httpd/httpd/conf

ServerAdvertise off

At JBoss Side : Set advertise property in ModClusterConfig bean to false in mod_cluster-JBoss-beans.xml under $JBOSS_HOME /server/all/deploy/ mod_cluster.sar/ META-INF/

<property name="advertise">false</property>

After setting these properties, create virtual machines from the templates. We can see in the mod_cluster_manger of the apache instance that that jboss node is not added. Now  we have to add the proxy instance to the jboss mod_cluster configuration through JMX. The following code snippet can be used to add a proxy to the balancer.

Hashtable contextProps = new Hashtable();

contextProps.put("java.naming.factory.initial"," org.JBoss.naming.HttpNamingContextFactory");

contextProps.put("java.naming.provider.url", http://+JBossinstanceip+":8080/invoker/JNDIFactory");

contextProps.put("java.naming.factory.url.pkgs", "org.JBoss.naming.client");

InitialContext ctx = new InitialContext(contextProps);  // From table

MBeanServerConnection server = (MBeanServerConnection) ctx.lookup("jmx/invoker/RMIAdaptor");

Object op = server.invoke(new ObjectName("JBoss.web:service=ModCluster"), "addProxy", new Object[]{webServerIP,webServermod_clusterPort},new String[]{"java.lang.String","int"} );

Now if you check the mod_cluster_manager we can see that the jboss node now balanced by mod_cluster.

Conclusion
With capabilities like dynamic addition of workers without any configuration changes, knowledge of deployed applications and calculation of the real time load balancing factor based on different metrics , it is certain that mod_cluster is the future of load balancer modules for apache and it will also have a huge impact in the cloud environment.

More Stories By Joel Mathew

Joel Mathew works as a Technology Analyst at SETLabs, R&D division, at Infosys Technologies Ltd. He has close to 3 years of experience in development of Cloud computing, Java and Java EE applications, Web 2.0,etc.

@ThingsExpo Stories
The Internet of Things will greatly expand the opportunities for data collection and new business models driven off of that data. In her session at Internet of @ThingsExpo, Esmeralda Swartz, CMO of MetraTech, will discuss how for this to be effective you not only need to have infrastructure and operational models capable of utilizing this new phenomenon, but increasingly service providers will need to convince a skeptical public to participate. Get ready to show them the money! Speaker Bio: Esmeralda Swartz, CMO of MetraTech, has spent 16 years as a marketing, product management, and busin...
Samsung VP Jacopo Lenzi, who headed the company's recent SmartThings acquisition under the auspices of Samsung's Open Innovaction Center (OIC), answered a few questions we had about the deal. This interview was in conjunction with our interview with SmartThings CEO Alex Hawkinson. IoT Journal: SmartThings was developed in an open, standards-agnostic platform, and will now be part of Samsung's Open Innovation Center. Can you elaborate on your commitment to keep the platform open? Jacopo Lenzi: Samsung recognizes that true, accelerated innovation cannot be driven from one source, but requires a...
SYS-CON Events announced today that Red Hat, the world's leading provider of open source solutions, will exhibit at Internet of @ThingsExpo, which will take place on November 4–6, 2014, at the Santa Clara Convention Center in Santa Clara, CA. Red Hat is the world's leading provider of open source software solutions, using a community-powered approach to reliable and high-performing cloud, Linux, middleware, storage and virtualization technologies. Red Hat also offers award-winning support, training, and consulting services. As the connective hub in a global network of enterprises, partners, a...
P2P RTC will impact the landscape of communications, shifting from traditional telephony style communications models to OTT (Over-The-Top) cloud assisted & PaaS (Platform as a Service) communication services. The P2P shift will impact many areas of our lives, from mobile communication, human interactive web services, RTC and telephony infrastructure, user federation, security and privacy implications, business costs, and scalability. In his session at Internet of @ThingsExpo, Robin Raymond, Chief Architect at Hookflash Inc., will walk through the shifting landscape of traditional telephone a...
SYS-CON Events announced today that Matrix.org has been named “Silver Sponsor” of Internet of @ThingsExpo, which will take place on November 4–6, 2014, at the Santa Clara Convention Center in Santa Clara, CA. Matrix is an ambitious new open standard for open, distributed, real-time communication over IP. It defines a new approach for interoperable Instant Messaging and VoIP based on pragmatic HTTP APIs and WebRTC, and provides open source reference implementations to showcase and bootstrap the new standard. Our focus is on simplicity, security, and supporting the fullest feature set.
BSQUARE is a global leader of embedded software solutions. We enable smart connected systems at the device level and beyond that millions use every day and provide actionable data solutions for the growing Internet of Things (IoT) market. We empower our world-class customers with our products, services and solutions to achieve innovation and success. For more information, visit www.bsquare.com.
How do APIs and IoT relate? The answer is not as simple as merely adding an API on top of a dumb device, but rather about understanding the architectural patterns for implementing an IoT fabric. There are typically two or three trends: Exposing the device to a management framework Exposing that management framework to a business centric logic • Exposing that business layer and data to end users. This last trend is the IoT stack, which involves a new shift in the separation of what stuff happens, where data lives and where the interface lies. For instance, it’s a mix of architectural style...
SYS-CON Events announced today that SOA Software, an API management leader, will exhibit at SYS-CON's 15th International Cloud Expo®, which will take place on November 4–6, 2014, at the Santa Clara Convention Center in Santa Clara, CA. SOA Software is a leading provider of API Management and SOA Governance products that equip business to deliver APIs and SOA together to drive their company to meet its business strategy quickly and effectively. SOA Software’s technology helps businesses to accelerate their digital channels with APIs, drive partner adoption, monetize their assets, and achieve a...
From a software development perspective IoT is about programming "things," about connecting them with each other or integrating them with existing applications. In his session at @ThingsExpo, Yakov Fain, co-founder of Farata Systems and SuranceBay, will show you how small IoT-enabled devices from multiple manufacturers can be integrated into the workflow of an enterprise application. This is a practical demo of building a framework and components in HTML/Java/Mobile technologies to serve as a platform that can integrate new devices as they become available on the market.
SYS-CON Events announced today that Utimaco will exhibit at SYS-CON's 15th International Cloud Expo®, which will take place on November 4–6, 2014, at the Santa Clara Convention Center in Santa Clara, CA. Utimaco is a leading manufacturer of hardware based security solutions that provide the root of trust to keep cryptographic keys safe, secure critical digital infrastructures and protect high value data assets. Only Utimaco delivers a general-purpose hardware security module (HSM) as a customizable platform to easily integrate into existing software solutions, embed business logic and build s...
Connected devices are changing the way we go about our everyday life, from wearables to driverless cars, to smart grids and entire industries revolutionizing business opportunities through smart objects, capable of two-way communication. But what happens when objects are given an IP-address, and we rely on that connection, sometimes with our lives? How do we secure those vast data infrastructures and safe-keep the privacy of sensitive information? This session will outline how each and every connected device can uphold a core root of trust via a unique cryptographic signature – a “bir...
Internet of @ThingsExpo Silicon Valley announced on Thursday its first 12 all-star speakers and sessions for its upcoming event, which will take place November 4-6, 2014, at the Santa Clara Convention Center in California. @ThingsExpo, the first and largest IoT event in the world, debuted at the Javits Center in New York City in June 10-12, 2014 with over 6,000 delegates attending the conference. Among the first 12 announced world class speakers, IBM will present two highly popular IoT sessions, which will take place November 4-6, 2014 at the Santa Clara Convention Center in Santa Clara, Calif...
Almost everyone sees the potential of Internet of Things but how can businesses truly unlock that potential. The key will be in the ability to discover business insight in the midst of an ocean of Big Data generated from billions of embedded devices via Systems of Discover. Businesses will also need to ensure that they can sustain that insight by leveraging the cloud for global reach, scale and elasticity.
WebRTC defines no default signaling protocol, causing fragmentation between WebRTC silos. SIP and XMPP provide possibilities, but come with considerable complexity and are not designed for use in a web environment. In his session at Internet of @ThingsExpo, Matthew Hodgson, technical co-founder of the Matrix.org, will discuss how Matrix is a new non-profit Open Source Project that defines both a new HTTP-based standard for VoIP & IM signaling and provides reference implementations.

SUNNYVALE, Calif., Oct. 20, 2014 /PRNewswire/ -- Spansion Inc. (NYSE: CODE), a global leader in embedded systems, today added 96 new products to the Spansion® FM4 Family of flexible microcontrollers (MCUs). Based on the ARM® Cortex®-M4F core, the new MCUs boast a 200 MHz operating frequency and support a diverse set of on-chip peripherals for enhanced human machine interfaces (HMIs) and machine-to-machine (M2M) communications. The rich set of periphera...

SYS-CON Events announced today that Aria Systems, the recurring revenue expert, has been named "Bronze Sponsor" of SYS-CON's 15th International Cloud Expo®, which will take place on November 4-6, 2014, at the Santa Clara Convention Center in Santa Clara, CA. Aria Systems helps leading businesses connect their customers with the products and services they love. Industry leaders like Pitney Bowes, Experian, AAA NCNU, VMware, HootSuite and many others choose Aria to power their recurring revenue business and deliver exceptional experiences to their customers.
The Internet of Things (IoT) is going to require a new way of thinking and of developing software for speed, security and innovation. This requires IT leaders to balance business as usual while anticipating for the next market and technology trends. Cloud provides the right IT asset portfolio to help today’s IT leaders manage the old and prepare for the new. Today the cloud conversation is evolving from private and public to hybrid. This session will provide use cases and insights to reinforce the value of the network in helping organizations to maximize their company’s cloud experience.
The Internet of Things (IoT) is making everything it touches smarter – smart devices, smart cars and smart cities. And lucky us, we’re just beginning to reap the benefits as we work toward a networked society. However, this technology-driven innovation is impacting more than just individuals. The IoT has an environmental impact as well, which brings us to the theme of this month’s #IoTuesday Twitter chat. The ability to remove inefficiencies through connected objects is driving change throughout every sector, including waste management. BigBelly Solar, located just outside of Boston, is trans...
SYS-CON Events announced today that Matrix.org has been named “Silver Sponsor” of Internet of @ThingsExpo, which will take place on November 4–6, 2014, at the Santa Clara Convention Center in Santa Clara, CA. Matrix is an ambitious new open standard for open, distributed, real-time communication over IP. It defines a new approach for interoperable Instant Messaging and VoIP based on pragmatic HTTP APIs and WebRTC, and provides open source reference implementations to showcase and bootstrap the new standard. Our focus is on simplicity, security, and supporting the fullest feature set.
Predicted by Gartner to add $1.9 trillion to the global economy by 2020, the Internet of Everything (IoE) is based on the idea that devices, systems and services will connect in simple, transparent ways, enabling seamless interactions among devices across brands and sectors. As this vision unfolds, it is clear that no single company can accomplish the level of interoperability required to support the horizontal aspects of the IoE. The AllSeen Alliance, announced in December 2013, was formed with the goal to advance IoE adoption and innovation in the connected home, healthcare, education, aut...