Thursday, July 29, 2004

Configure session failover in an OC4J cluster (9i)

Summary
The test JSP shown below should be deployed as part of an EAR file (eg. mywar.ear) to a container (eg. wartest). The steps walk through how to test and ensure that sessions are failed over from one node to another in this active-active setup.

Prerequisites

  • 3 separate ORACLE_HOME's installed, one for the web server, and two for separate application servers.
  • The application servers should already be associated with an Infrastructure repository.

Details
1. Create the following test.jsp file, generate an EAR file that includes this JSP (eg. mywar.ear), and deploy it to a container (eg. wartest).
       
        <%@page session="true" %>
        <%
          if (request.getParameter("action") != null) {
            if (request.getParameter("action").equals("set")) {
              session.putValue("test",(String)session.getId());
            } else if (request.getParameter("action").equals("unset")) {
              session.putValue("test",null);
            }
          }
          if (session.getValue("test") == null) {
            out.println("Session variable 'test' is NULL.<br>");
          } else {
            out.println("Session variable 'test' has the session id ");
            out.println("value of: " + session.getValue("test") + ".<br>");
          }
        %>
        <br>
        <a href="test.jsp?action=set">Set session variable</a><br>
        <a href="test.jsp?action=unset">Remove session variable</a><br>
        <a href="test.jsp">Refresh page</a><br>
       
2. Before generating the EAR file, modify your web.xml (located in the WEB-INF directory) and add the following line immediately under.
           
            <distributable/>
           
3. Create a cluster using Enterprise Manager, and associate the application servers to this cluster.
           
a. Navigate to Oracle Enterprise Manager 10g Application Server Control (eg. http://app1.oracle.com:1810/)
            b. Click on Create Cluster
            c. Enter a cluster name, and click on Create (eg. AppServerCluster)
            d. Click on OK
e. Check the radio box on each application server, and click on Join Cluster (eg. do this for app1.oracle.com and app2.oracle.com)
           
4. Configure state replication (this step needs to be done only once on any application server within the cluster).
           
a. Navigate to Oracle Enterprise Manager 10g Application Server Control (eg. http://app1.oracle.com:1810/)
            b. Click on your application server (eg. app1.oracle.com)
            c. Click on wartest (in this document, we are using the wartest container)
            d. Click on Administration
            e. Click on Replication Properties
            f. Check Replicate session state
            g. Click on Apply
            h. Click on OK
           
5. Startup the wartest container on each application server (there are multiple ways to do this).
           
            dcmctl start -co wartest
           
6. Modify the mod_oc4j.conf file on your web server (located at $ORACLE_HOME/Apache/Apache/conf/) and add the following two lines:
           
            Oc4jMount /mywar cluster://AppServerCluster:wartest
        Oc4jMount /mywar/* cluster://AppServerCluster:wartest
           
7. Restart the web server:
           
            dcmctl stop -ct ohs
        dcmctl start -ct ohs
           
8. Test the session failover.
           
Navigate to test.jsp on your browser, click on Set session variable, and identify which application server you are hitting. Shutdown that application server container manually, and click on Refresh page, and the session variable should now be carried over to the other application server instance.
           
For comparison purposes, modify the web server's mod_oc4j.conf and use the following configuration instead:
            Oc4jMount /mywar instance://app1.oracle.com:wartest,app2.oracle.com:wartest
        Oc4jMount /mywar/* instance://app1.oracle.com:wartest,app2.oracle.com:wartest
           
            Upon repeating the same test, you will notice that the session is not carried over.
           
Applicable Versions

Oracle Application Server 10g (9.0.4)

No comments: