Skip to content

Latest commit

 

History

History
232 lines (168 loc) · 9.04 KB

tomcat-pu.markdown

File metadata and controls

232 lines (168 loc) · 9.04 KB
layout title categories weight parent
post
Embedding Tomcat as a Web Container
SBP
1800
production.html

{% summary %}This article presents embedding Tomcat 7 within the XAP data grid{% endsummary %}

{% tip %} Author:Ali Hodroj, Director of Solution Architecture, GigaSpaces
Recently tested with GigaSpaces version: XAP 9.6
Last Update: Feb 2014
{% endtip %}

Overview

{%section%} {%column width=80% %} GigaSpaces XAP allows for embedding a Tomcat 7 web container within the service grid by deploying it as a processing unit. The integration is achieved by utilizing the Embedded Tomcat API, which only requires a few lines of code to start an instance within a processing unit. This integration lets the end user enjoy all the useful features of Apache Tomcat, while leveraging the high availability and SLA monitoring of the XAP service grid. {%endcolumn%}

{%column width=15% %} tomcat_logo.jpeg {%endcolumn%} {%endsection%}

The key features of the embedded Tomcat are:

  • Auto-Scaling: Dynamic allocation and auto-scaling of Tomcat instances (hosting a web application) as well as automatically updating your load balancer through the Admin API
  • Simplified Management: Consolidated management of your web tier along with your data grid under one common administrative interface (through a web, desktop, and CLI administrative interface)
  • Fault Tolerance and Isolation: SLA enforcement through the Grid Service Manager by providing JVM-level, Machine-level, and Zone-level redundancy and failover upon deployment.
  • Low latency: Leverage colocation of Tomcat instances with space instances to avoid network round trips that access POJO from the data grid.

Deployment

Embedding Tomcat along with one or more associated web application is simply a matter of deploying a skeleton tomcat processing unit that contains both the Tomcat instantiation code as well as a your target web applications self-contained within the processing unit. This provides a clean way to deploy and undeploy the entire server instance along with its associated applications.

The tomcat processing unit hierarchy, once built with maven, will have the following structure:

Tomcat PU {%wbr%} |- com {%wbr%} |- lib {%wbr%} |- META-INF {%wbr%} |- webapps

{: .table .table-bordered}

Folder Purpose
com Contains compiled code for instantiating Tomcat as well as utilizing server parameters
lib Additional libraries required by Tomcat and web application
META-INF Contains the PU.XML file for configuring Tomcat along with an optional SLA.XML file for configuring the processing unit SLA
webapps A collection of web applications which will be loaded by Tomcat

In order to deploy Tomcat along with your web application within XAP, the following steps must be followed:

Step 1: Download the tomcat-pu project from here{%wbr%} Step 2: Configure the Tomcat instance through PU.XML to specify the container and application configuration

{%highlight xml%} {%endhighlight%}

{: .table .table-bordered}

Property Description
appBase Location in the project of web applications
contextPath Root context path for applications
port Starting port number when deploying multiple instances
portRetries How many ports to try before giving up
webapps The collection of web applications contained in the processing unit.

Step 3: Place your web applications in src/main/resources/webapps{%wbr%} Step 4: (optional) Specify the SLA parameters for fault isolation and redundancy through an SLA.XML file in META-INF/spring

{: .table .table-bordered}

Setting SLA Directive
Maximum of one Tomcat instance per JVM <os-sla:sla max-instances-per-vm="1" />
Maximum of one Tomcat instance per physical machine <os-sla:sla max-instances-per-machine="1" />
Maximum of one Tomcat instance per zone (sets of machines or availability zone) <os-sla:sla max-instances-per-zone="1" />

Step 5: Build the project through mvn package{%wbr%} Step 6: Deploy processing unit in XAP, once deployed Tomcat should appear as the following

tomcat1.png

Navigate to (default) port 8888 to test your web application

tomcat2.png

Step 7: Increase or decrease instances of Tomcat running through the “Deployed Processing Units” tab

tomcat3.png

With the default project, upon adding new instances on your local machine, the next one should be listening on port 8889.

Class Loading

The following describes the structure of the class loaders when several web applications are deployed on the Service Grid:

     Bootstrap (Java)
              |
           System (Java)
              |
           Common (Service Grid)
              |
        Tomcat 7 Container (Tomcat)
         /        \
    WebApp1     WebApp2

The following table shows which user controlled locations end up in which class loader, and the important JAR files that exist within each one:

{: .table .table-bordered}

Class Loader User Locations
Common [GSRoot]/lib/platform/ext/*.jar
Tomcat 7 [PU]/lib, [PU]/com/*
Webapp [PU]/webapps/WEB-INF/classes, [PU]/webapps/WEB-INF/lib/*.jar

Tomcat Cluster with a Data Grid Deployment

See below for different options deploying Tomcat cluster with an embedded data grid or Tomcat cluster using a local cache with Remote data grid:

Deploying Two nodes Tomcat Cluster with an Embedded Sync-replicated Data-Grid

The pu.xml should include: {%highlight xml%} <beans .... <os-core:embedded-space id="space" name="space" /> {%endhighlight%}

Tomcat Cluster with two instances embedded sync-replicated data-grid deploy command: {%highlight xml%} gs deploy -cluster schema=sync_replicated total_members=2 tomcat-pu-1.0-SNAPSHOT.jar {%endhighlight%}

Deploying Two nodes Tomcat Cluster with an Embedded ASync-replicated Data-Grid

The pu.xml should include: {%highlight xml%} <beans .... <os-core:embedded-space id="space" name="space" /> {%endhighlight%}

Tomcat Cluster with two instances embedded async-replicated data-grid deploy command: {%highlight xml%} gs deploy -cluster schema=async_replicated total_members=2 tomcat-pu-1.0-SNAPSHOT.jar {%endhighlight%}

Deploying Two nodes Tomcat Cluster with a Local-cache Communicating with a Remote Data-Grid

The pu.xml should include: {%highlight xml%} <beans

<bean id="tomcat7" class="com.gigaspaces.tomcat.Tomcat7">

.... <os-core:space-proxy id="space" name="space" /> <os-core:local-cache id="localCacheSpace" space="space"> os-core:properties 5000000 75 73 71 50 1000 20 false 200 </os-core:properties> </os-core:local-cache>

<os-core:giga-space id="localCache" space="localCacheSpace"/>
{%endhighlight%}

Data Grid (Two partitions with a sync-replicated backup) deploy command: {%highlight xml%} gs deploy-space -cluster schema=partitioned-sync2backup total_members=2,1 space {%endhighlight%}

Tomcat Cluster deploy command: {%highlight xml%} gs deploy -cluster total_members=2 tomcat-pu-1.0-SNAPSHOT.jar {%endhighlight%}

Elastic Load Balancer

Implementing automatic updates of load balancer tables can be done through the combination of the Admin API for monitoring the processing unit instances. A similar pattern is available through the Apache Load Balancer processing unit.