Vivek's Blogs
EJB Availabilty example using Java web start
I thought it would be nice to add a simple GUI to the sample described in my previous blog entry, so that we can make use of java webstart for appclient.
The new sample ear file can be found here.
Source for the ear file is here
After setting up the cluster .Pls use the following steps to run the appclient sample.
Login to Glassfish Application server Admin GUI
select 'Enterprise applications"
click on deploy on the right frame.
click on Browse and give the sample ear file location. pls make sure to select java-webstart,availability and target cluster
After deploy , click on SFSB - application name on the right frame.
General tab will list out the modules , appclient and a ejb jar.
Click on the Launch link , this will list out the available links , choose any one of them and click on launch button.
Thats it! You will see the sample's GUI
Running the sample is similar to my previous blog entry
You can add an attribute and see in which instance the bean is created and the data is saved.
Bring down this instance using Appserver's admin GUI and try to add one more attribute.then click on show
this will show both attributes.
Posted at 02:28PM Dec 03, 2008 by Vivekanandh Sedhumadhavan in Sun | Comments[0]
EJB AVAILABILITY
Thanks to Gopal Jorapur for his valuable input.
EJB Data Availability in
Glassfish
Objective
Overview
Installation
Configuration
Deployment
Running the sample
Optimization
Dynamic cluster support
Troubleshooting
Objective
Share my experience on EJB Availability in GlassFish. We are
going to show a simple Stateful Session Bean application deployed on a
GlassFish cluster and show how the SFSB data survives across failovers.
Overview
High availability applications and services provide their functionality continuously, regardless of hardware and software failures.
GlassFish provides High Availability Service for following components
HTTP Session Availability
JMS Availability
RMI-IIOP Loadbalancing and Failover
Http session availability is explained here, JMS Availability is explained in this doc
In this blog, we are explaining the EJB Data Availability, the sample uses Appclient container for RMI-IIOP Loadbalancing and Failover
Installation
Download GlassFish
V2 UR2 build from here. (At the bottom of the page, download links are available, please pick the build for your platform)
to install glassfish and
configure cluster.
java -Xmx256m -jar
./glassfish-installer-v2.1-b35-sunos.jar
Following instructions are
from "setting up one machine cluster" from here
cd glassfish
chmod -R +x lib/ant/bin
lib/ant/bin/ant -f setup-cluster.xml
cd ${glassfish.home}/bin
asadmin start-domain domain1
cd to
${glassfish.home}/samples/quickstart/clusterjsp
${glassfish.home}/bin/asant setup-one-machine-cluster
${glassfish.home}/bin/asadmin start-cluster cluster1
Our cluster is up and running now with
two applciation server instances named instance-ONE and instance-TWO
Now lets configure the appclient
In this example we will be using
the appclient script from $AS_HOME/bin along with the sun-acc.xml
from $DOMAIN_HOME/config/sun-acc.xml. There is also a package-appclient
script to install appclient separately. This will be useful for installing appclient on seperate machines to drive the load.
Now we need to find out atleast one
IIOP_LISTENER_PORT to configure sun-acc.xml. To know the IIOP_LISTENER_PORT of a
particular instance, type in the following command
${glassfish.home/bin/asadmin
get instance-ONE.system-property.IIOP_LISTENER_PORT
edit
${glassfish.home}/domains/domain1/config/sun-acc.xml as following
Replace the port no with the one we got
from asadmin get command
<target-server name="hostname" address="hostname" port="3700"/>
Add the following line after the
target-server line
<property name="com.sun.appserv.iiop.loadbalancingpolicy"
value="ic-based"/>
Edit the log-service line and
fill in the absolute path for the log file
<log-service file="/export/home/space/appclient/bin/appc.log"
level="INFO"/>
Deployment
Get the src and application ear file
${glassfish.home}/bin/asadmin deploy --host hostname --port 4848 --type
application --target cluster1 --retrieve ./
--availabilityenabled=true ${ear_file_location}/SFSB.ear
Now lets talk about two deployment options we used
The first one is "--availabilityenabled=true" - this
is to specify high availability for our application.
High Availability is achieved by storing session state in a persistence store. There are three
types of persistence stores are supported in GlassFish
1. HA (used HADB as the persistence store)
2. File (used flat file system for persistence store)
3. Replicated (same as in-memory, uses replication as persistence store)
We
are using in-memory persistence in this sample. The cluster is
configured for in-memory by default (No additional configuration
required!)
At the high level, the replication works in a ring topology, basically
each instance replicates its session/ejb data to its buddy
instance. More about this architecure can be found here
The second deployment option of interest is "--retrieve ./" - this
option is to tell the system that we expect a client jar and we
need that jar to be copied in the current directory
More information about GlassFish Application Client Container can be found here
As the application is deployed on the cluster, the bean is available on both the instances of cluster.
The client looks up the bean in one of the instance
(determined by the appclient container in a round-robin fashion) and
it has options to add,delete, print attribute operations on the bean.
In this example we first add an attribute (name, value pair),
then we will stop the instance that served this request. Add another
attribute from the same client, this time the bean will be
reconstructed in the second instance and the previous data is also
recovered. This explains data availability across failovers.
Now lets start the appclient
${glassfish.home}/bin/appclient -xml
${glassfish.home}/domains/domain1/config/sun-acc.xml -client
./SFSBClient.jar
Bean Lookup Successful
Add an Attribute(a)
Remove an Attribute(r)
Print Attributes(p)
Quit(q)
type option
'a' , type in name and value of the attributes.
**********************************************
Enter name :abc
Enter value :123
Attribute abc added on
instance: instance-ONE
**********************************************
After entering the
attribute value, Client will tell us in which instance the bean is
residing.
Open another command window,
stop this instance
${glassfish.home}/bin/asadmin stop-instance instance-ONE
continue adding one more
attribute by typing in 'a'
**********************************************
Enter name :cde
Enter value :456
Attribute abc added on
instance: instance-TWO
**********************************************
now select 'p' to print the existing attributes.
**********************************************
Name : abc, Value: 123
Name : cde, Value: 456
**********************************************
instance-ONE was
replicating to instance-TWO, so the bean data from ONE was replicated to
TWO.
while adding the second
attribute, client first tries to access the
instance-ONE(to maintain stickyness), since the instance was down, there will be a connection failure
exception.
(please see in appc.log, location defined in sun-acc.xml)
Then the client tries to
connect to instance-TWO and succeed
type in 'q' to quit
Optimization
Now we know that the EJB
data is replicated to some other instance. this is some what a costly
operation so we dont want to do it often.
There are two ways to tell
the ejb container that we need the bean state (data) to be saved
at the time.
1.marking the business
method of a bean for checkpointing
2. marking the
business method of the bean to be run inside of a transaction (Data is
by default saved at the end of the transaction)
This sample uses
transaction to initiate the save. This is achieved by
declaring 'addAttribute()' business method of the
bean as transactional (pls see the source)
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public String addAttribute(String name,String
value)
Dynamic Clustering
You can add more
instances to the setup and try the sample again. the available
IIOP_PORTs are dynamically identfied pls see the following line in appc.log this
will list all the available urls
INFO: corbaloc url
==>iiop:1.2@hostname:33702,iiop:1.2@hostname:33702,iiop:1.2@hostname:33700
1. During Configuration step, If the following command fails
${glassfish.home/bin/asadmin
get instance-ONE.system-property.IIOP_LISTENER_PORT
Then please try
${glassfish.home/bin/asadmin get
cluster1-config.system-property.IIOP_LISTENER_PORT
2. If you see CORBA connection exception during second add attribute, most probably log location could be wrong. The exception is expected, since the instance is down
Posted at 03:16PM Jun 09, 2008 by Vivekanandh Sedhumadhavan in Sun | Comments[4]