Running OW2 JOnAS on Windows Azure

Introduction

This article is explaining how to deploy and run OW2 JOnAS and Java EE applications on the Microsoft Windows Azure cloud plateform.

What is Azure ?

Windows Azure is the cloud plateform provided by Microsoft. It's basically an IaaS (Infrastructure as a Service) plateform provider. Microsoft runs multiple Datacenters around the world for cloud hosting services.

windows_azure_logo.jpg

Preparation

Pre-requisites / Installation

Windows

The Azure SDK requires one of the following OS:

  • Windows 7
  • Windows Vista Service Pack 2 or greater
  • Windows Server 2008 SP2 or greater.

Azure SDK

Get the latest Azure SDK from the azure web site.
Important: IIS 7 has to be activated along ASP.NET support before installing the SDK.

Eclipse

Azure Account Creation

If you don't already have an Azure subscription, go to the microsoft azure website.
There is a 3 months free trial with blocked quotas (you are sure not to be charged anytime) that is very handy for experiments. You have to log-in with your Live ID.

Blob Storage

Once the account is open, it is possible to create a new Azure storage server.
This will be very handy for storing big files and avoid too much internet traffic between your workstation and the cloud. We could use it to store the Java VM zip file and the JOnAS archive.

Eclipse Project

This section focus on how to create and configure your Azure eclipse project.

New Azure Project

Click on New ... / Other ... and then select Windows Azure Project.
You'll have to write down a name for your project.

Prepare the Role(s)

The New Project window let the developper configure the roles needed in his/her deployment. Any number of Roles can be defined for a deployment, each of them having a distinct name.

For this simple tutorial, we'll use only 1 Role that will correspond to a unique JOnAS instance.

Endpoint Configuration

The Azure plugin automatically configures a default HTTP input endpoint. It declares a public port opened on '80' that will pass request to the 'internal' port 8080. As JOnAS is using '9000' for its default HTTP port, we have to update this value.

Notice that up to 25 endpoints can be defined there. Theses are the ports of a load-balancer that will be accessible from the external world. And load-balancer passing/balancing requests to an internal port of one Role.

The approot Folder

Each Role has an 'approot' folder. All of its content will be part of the Azure applicative package that will be uploaded and then deployed to the cloud.

We will place in this folder everything that will be required in order to have a working JOnAS instance with its application(s).

Binaries

Java and JOnAS zip files have be placed into the approot/ directory.

Application(s) + Dependencies

Having JOnAS running on Azure is nice, but having your application running on top of JOnAS is better.

In this tutorial, we propose to mimic the JONAS_ROOT structure:

  • deploy/
  • conf/
  • lib/ext/

deploy/ Folder

The content of this directory is intended to be copied into the ${JONAS_ROOT}/deploy/ directory. All the files in this directory will be deployed by JOnAS.

At this location, place your application's file(s) (.war, .ear, .jar, .rar) and all dependencies that are required for your application to work.
For example, a DataSource XML file is usually required in order to connect the application with a database.

/////////////// Example JDBC-DS XML

conf/ Folder

The content of this directory will override any file located in the ${JONAS_ROOT}/conf/ directory. It is useful to provide a kind of patch on the default JOnAS configuration.

lib/ext/ Folder

Usually, this directory is used to automate the transformation of an average jar file into an OSGi bundle. This is useful for adding new libraries into the application server (such as JDBC drivers).

In this example, we place the SQL Server JDBC Driver jar file (3.0 stable or 4.0 CTP3) in that directory.

Startup Script

The startup script is the heart of your deployment. It is executed when the applicative package has been unpacked.

The first task of the script is to unpack the binaries:

@REM Prepare directory (shorter names)
@REM ------------------------------------------------------------
rd "C:\%ROLENAME%"
mklink /D "C:\%ROLENAME%" "%ROLEROOT%\approot"
cd /d "C:\%ROLENAME%"
@REM Unpack Java SDK + OW2 JOnAS
@REM ------------------------------------------------------------
cscript /nologo "util\unzip.vbs" "jdk1.7.0_02.zip" "%CD%"
cscript /nologo "util\unzip.vbs" "ow2-jonas-5.2.2-light.zip" "%CD%"

The second task is to setup the environment variables required to run JOnAS:

@REM Set required environment variables
@REM ------------------------------------------------------------
SET JONAS_ROOT=C:\%ROLENAME%\ow2-jonas-5.2.2
SET JAVA_HOME=C:\%ROLENAME%\jdk1.7.0_02
SET PATH=%PATH%;%JAVA_HOME%\bin;%JONAS_ROOT%\bin

Then, it overrides/patches the unpacked JOnAS and copy the application in the deploy/ directory:

@REM Overwrite some JOnAS files
@REM ------------------------------------------------------------
COPY /Y "conf\*" "%JONAS_ROOT%\conf"
COPY /Y "lib\ext\*" "%JONAS_ROOT%\lib\ext"
@REM Place application's modules in the deploy/ directory
@REM ------------------------------------------------------------
COPY /Y "deploy\*" "%JONAS_ROOT%\deploy"

Finally, it simply starts the application server:

@REM Spawn a JOnAS process and exit the current shell
@REM ------------------------------------------------------------
%JONAS_ROOT%\bin\jonas.bat start

/////////////// Example Startup script

Service Definition

Service Configuration

Local testing

Deployment

Azure Management Portal

Staging

Production

RDP

Windows Azure Api

Conclusion

Potential Evolutions

Thank You