ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button

Using XML and Jar Utility API to Build a Rule-Based Java EE Auto-Deployer
Pages: 1, 2, 3, 4

2. EAR Packaging: Extend Packaging to Include XML

After the Application Assembler generates the XML deployment rule, the next step is to package the EAR to include this rule document.



An extended JAVA EE application EAR including the XML rule will have the following structure. An "EXT-INF" directory is defined inside EAR to keep the extended deployment files as depicted in Figure 6.

  • Deployment XML rule: rule.xml

  • SQL files: used by SQL deployment modules specified at the rule document

  • LDIF files: used by LDAP deployment modules to upload/expose system configurations

  • Other resource files that are specified and used in the rule

Figure 6
Figure 6. Extended Java EE EAR file structure

In this sample, an ant script is used to package the EAR. Once the EAR is packaged, the application assembler will deliver this extended EAR to the Deployer.

<project name="ExtPackaging" default="package" basedir="..">
    <property name="ear.dir" value="${basedir}/ear"/>
    <property name="ext.dir" value="${basedir}/ext"/>
    <property name="ldap.dir" value="${basedir}/ldap"/>
    <property name="sql.dir" value="${basedir}/sql"/>
    <property name="etc.dir" value="${basedir}/etc"/>
    <property name="dist" value="${basedir}/dist"/>
    <property name="application.ear" value="SOManager.ear"/>
    <mkdir dir="${ear.dir}/EXT-INF"/>
    <mkdir dir="${ear.dir}/EXT-INF/sql"/>
    <mkdir dir="${ear.dir}/EXT-INF/ldap"/>
    <mkdir dir="${ear.dir}/EXT-INF/etc"/>
    
    <target name="package"
        description="creates custom java ee archive">
        <copy todir="${ear.dir}/EXT-INF" file="${ext.dir}/rule.xml"/>
        <copy todir="${ear.dir}/EXT-INF/sql">
            <fileset dir="${sql.dir}">
                <include name="*.sql"/>
            </fileset>
        </copy>
        <copy todir="{ear.dir}/EXT-INF/ldap">
            <fileset dir="${ldap.dir}">
                <include name="*.ldif"/>
            </fileset>
        </copy>
        <copy todir="{ear.dir}/EXT-INF/etc">
            <fileset dir="${etc.dir}"/>
        </copy>
        <ear destfile="${dist}/${application.ear}" 
            appxml="${ear.dir}/META-INF/application.xml" 
            manifest="${ear.dir}/META-INF/MANIFEST.MF">
            <metainf dir="${ear.dir}/META-INF"/> 
            <fileset dir="${ear.dir}"/>
        </ear>
    </target>
</project>

3. Deployer: Extending Packaging to Include XML Rule

This is the last and most exciting part of the deployment: push one button to kick off the auto-deployment. First, let's see how the sample application works (as depicted in Figure 7):

  • Browse and upload the EAR

  • Push the Deploy button

  • Done!

Figure 7
Figure 7. Sample application of auto-deployment

What happened on the backend?

  • First, The Deployer Java object wires the real deployment provider class, which is implemented for the specific application server. For example, WebLogic, WebSphere, and JBoss.

  • Then, the Deployer Java object parses the EAR file to retrieve the rule.xml and de-serializes XML to the Rule POJOs.

  • Finally, the Deployer Java object calls the provider's deploy() method by passing the EAR and the Rule object. The provider object deploys DataSources, JMS, and executes SQL statements, and/or uploads system configuration details to LDAP, etc.

Design of the Deployer application
  • Application Server Independent: an Inversion of Control (IoC) design pattern is used in the design of the Deployer to keep it independent of the application server. Different DeployProvider classes are implemented for major Java EE application servers, such as WebLogic, WebSphere, and JBOSS. The Deployer Java object wires the real provider class at runtime based on the deployment requirement. Since the providers are pluggable, the system can easily support different application servers, and its core part is vender independent.

  • Rule-based deployment: a standard, vendor-independent XML rule is designed to instruct the deployer for the deployment. The XStream utility library is used to bind the XML document to Rule POJOs. The rule is also easy to extend to support new requirements.

  • Extended deployments: various deployment module POJOs are designed to extend the deployable modules and tasks. Not only DataSource and JMS can be deployed automatically, SQL execution, LDAP configuration setup can also be supported. Moreover, a new deployment module POJO can be easily designed to applied to the deploy provider class.

  • EAR Analyzer: uses Java's Jar utility API to parse and analyze the EAR file, and extracts the interested files (i.e., rule.xml, SQL files, LDIF files, etc.) from the EXT-INF/ of the EAR.

The class design is depicted in Figure 8.

Figure 8
Figure 8. Class diagram of the Deployer Application

The deployment flow is shown in Figure 9.

Figure 9
Figure 9. Sequence diagram of the deployment flow

Pages: 1, 2, 3, 4

Next Pagearrow