Tuesday, August 21, 2012

Managed Deployments in Jboss AS 7

This post is targeted at Jboss AS 7 users/developers who are struggling with automated managed deployments ever since the hue architectural change in AS7 that implements a parallel deployer as opposed to serial or sequential/ordered deployer in prior versions like Jboss 5.1 and Jboss 4.0.x.

No doubt that the parallel deployer and the architecture around this has been more aligned towards achieving blazing startup times through clear modularity. This works great for developers building new java EE applications agaionst AS7. What about folks that are trying to migrate their legacy applications to AS7?

In this document I am going to focus more on a particular use case that is widely used in servers before AS7.

Let's say we have an application core-app.ear that is the core framework, API, Engine whatever you want to call it. Some may refer this to as shared or common code. And there are a suite of application's bundled as .ear that leverage core-app.ear or depend on the common code or framework beans, spring beans and so forth.  In the AS7 world this model is a problem largely because of the parallel loading sequence. The consumer applications need to start-up after the core-app.ear has started and fully initialized.

The Jboss AS7 documentation doesn't throw too much light on this except for setting up dependencies in your class-path or defining your modular dependencies in jboss-deployment-structure.xml. There are some ways on how one could extend the Jboss AS7 subsystem and provide custom implementations but nothing obvious (I still have to explore this more) . 

Here is a that I could pull this off without too many changes and might be the way to go for some of you unless AS7 has a way to switch to serial deployers:

For my applications I leverage the springframework so you would see a lot of references to Spring beans and classes that are used. I also use little JMX to get me some AS7 properties etc.

Modes

This document assumes we are running under the Standalone mode (Domain mode is largely the same except that it uses a server-group to associate deployments).

The Deployment Scanner

Its important to understand the deployment scanner and how to configure this before we deep dive into the implementation. If you haven't looked at this before, I would highly recommend that you read up: https://docs.jboss.org/author/display/AS7/Deployment+Scanner+configuration before you read up any further.

In the Jboss 4.0.5 we used to have a deploy directory that is scanned by Jboss automatically and deployed on startup. Anything else that needed to be scanned could be configured under jboss-service.xml. Withing a folder configured for scanning the older versions of Jboss used an aphabetical sorter to determine the loading sequence. I would say it was pretty much flexible and managed to a large extent.

I tried to achieve the same here with AS7.


As you see, I have two deployment scanners that I refer to as auto_deployer and managed_deployer respectively. The auto_deployer as the name suggests we have this setup to deploy applications on container start up. The managed_deployer deals with the applications that are dependent on the applications that the auto_deployer picks up and deploys but does not attempt to auto-deploy at container startup.


File Markers

https://docs.jboss.org/author/display/AS72/Application+deployment


Application Startup and Managed Deployer's using File Markers

In the jboss 4.0.x world I used to leverage a JbossNotificationListener that used to be ntified on container startup. I yet have to find the replacement in AS7.  But there are a few ways we could do this.  We could use a MBeanServerDelegate and register for registration events. For the scope of this post I am leveraging Spring's ContextLoaderListener.

Here is how it would look under your Deployment Descriptor:



FooSpringContextLoaderListener.java



This way we also leverage the parallel deployer for the "ears" deployment_scanner.   As soon as we run through teh folder and create marker files for ears we need to deploy, AS7 kicks off a parallel deployer and thus helps us achieve the best of both worlds.

We may implement business logic to selectively deploy applications on your business needs and services.

We may also use CLI to achieve the same but this example tries to implement the same programmatically and achieve seamless deployment with less management overhead outside of Jboss AS7.


References that maybe useful to you:


1. 5 ways to deploy applications on AS7: http://www.youtube.com/watch?v=OuFaYYQVJP0
2. More on MBeans: http://middlewaremagic.com/jboss/?tag=mbeans
3. CLI Client API : http://jamezp.blogspot.com/2011/07/jboss-application-server-deployment.html