This example is an implementation of the Spring PetClinic application based on GigaSpaces as the backbone instead of a relational database. It is a reference implementation rather than a fully optimized production application.
It is consisted of a web application that stores the pet clinic information into the space (by implementing the Clinic DAO interface which accesses a relational database in the original petclinic), a space (partitioned-sync2backup, 2 primaries and two backup) and a mirror service to which the space is connected and saves data asynchronously. The mirror service connected to a MySql database and stores information into it using hibernate.
The following presentation provides an overview of the migration process from JEE to GigaSpaces XAP and discusses the differences between the two platforms, using the PetClinic application as a basis for comparison.
Modifications to the Original PetClinic
A few modifications were made to adjust the application to GigaSpaces:
- The Clinic interface has two implementation on top of GigaSpaces:
- Naive implementation, made using direct space calls
- Optimized implementation, using GigaSpaces executors, that minimizes the network calls instead of calling the space more than once
for each operation
- Some changes have been made to the domain model since GigaSpaces does not support object relationships out of the box. In addition, The space does not have an integer-based id generator (only String based), so one was implemented to preserve the applications semantics.
You should have the following installed on your machine for the demo to run work properly:
The application contains the following modules, each has its own Eclipse project and IntelliJ iml file (You need to have the following path variables in either IDE for you're project to compile correctly within it: GS_HOME - points to GigaSpacesXAP home, SPRING25_HOME - points to the Spring framework 2.5.4 (or higher) distribution, MYSQL_DRIVER_JAR - points to the MySql driver jar. Note that in Eclipse you will have to define the user libraries):
- space-pu: contains the space to which the data is saved and an initialization service for the space based id generator.
- mirror: contains the mirror service to which the space. The space replicates changes to the domain model asynchronously to be saved in the database. The database is MySql 5.1, and should be initialized with the provided SQL script (see below).
- common: contains classes shared by the PUs and web application, namely the domain model classes Clinic DAO interface.
- webapp: contains the web application, including all web related resources.
Build and Deployment
If you wish not to build the project yourself, you should download the binary distribution of each module's processing unit here.
Otherwise, you will have to download and install Spring framework 2.5.5 (with dependencies). If you have a higher version of Spring it's also fine, just make sure to update the Spring jar if you're using GigaSpaces 6.6.0 build 2601 (which is bundled with Spring 2.5.4). The jar is located under lib/spring in the GigaSpaces distribution.
|Use the appropriate Spring distribution|
It's important to download The Spring distribution with dependencies, as the build relies on the 3rd party jars included with this distribution. This project has been tested with Spring 2.5.5, which can be downloaded here. Since Spring is fully backwards-compatible, you may also use version 2.5.6, which can be downloaded here
The example uses ant as its build tool and uses a standard build.xml file. To run the build script, use the provided build.sh/bat file.
Running the build script with no parameters within the current directory will launch the all task, which will build all the packages. The build depends on GigaSpacesXAP6.6, Spring 2.5.4 (or higher) and MySql JDBC driver libraries. To run the build script simply cd to the example's directory and call build.sh/bat.
Make sure to edit the setenv.sh/bat file in the root of the project to provide the locations of GigaSpaces6.6 XAP, Spring framework 2.5.4 and MySql Driver locations.
Also, make sure to validate the JDBC credentials under common/src/jdbc.properties.
The output of the build is the mirror and space PUs and the web application war file.
(As mentioned above, these are also available as a separate download here if you don't want to build the project yourself).
|Initialize the database|
Before you start the application, you will need to initialize the MySql database with the provided SQL script (located under the common directory in the example).
This is typically done by calling:
mysql < [Example Root]/common/createDB.sql
In order to deploy the application onto the Service Grid, a GSM and two or three GSCs will need to be started (note, we need two GSCs because of the SLA defined within the space-pu module). Also note that you can use the new GigaSpaces Agent available in version 7.0.
Once you start the agent, it will start all the required components locally. This is done by calling <GigaSpaces root>/bin/gs-agent.sh(bat).
To deploy the application, you can run the deploy task in the build script by typing build.sh(bat) deploy. This will deploy the mirror, the space-pu and the web application.
Alternatively, you can deploy the application manually: First deploy the mirror, then deploy the space-pu and last deploy the generated war file using the UI for example.
Some ways to play with the demo can be:
- Start another GSC and relocate (drag and drop in the GS-UI) the web application / one of the spaces to the the new GSC.
- Kill one of the GSC that runs the web application processing unit. The web application will be started on one of the remaining GSCs.
Note that you can also run the processing units from within your IDE using the IntegratedProcessingUnitContainer.