Friday, August 8, 2014

Oracle Service Bus Deployment - Offline export of Config jar

With PS6, Oracle Service Bus provides the utility jar (com.bea.alsb.tools.configjar.ant.ConfigJarTask) to export the OSB configuration jar without requiring OEPE.

A sample ant task as provided by the Oracle documentation is given below:

<project name="ConfigExport" default="usage" basedir=".">

    <property environment="env" /> 
    <property name="mw.home" location="${env.MW_HOME}" /> 
    <property name="wl.home" location="${env.WL_HOME}" /> 
    <property name="osb.home" location="${env.OSB_HOME}" /> 

    <taskdef name="configjar" 
             classname="com.bea.alsb.tools.configjar.ant.ConfigJarTask" /> 

    <target name="init">
       <property name="task.debug" value="false" /> 
       <property name="task.failonerror" value="true" /> 
       <property name="task.errorproperty" value="" /> 
    </target>

    <target name="run" depends="init">
       <fail unless="settingsFile"/>
       <configjar debug="${task.debug}" 
                  failonerror="${task.failonerror}" 
                  errorProperty="${task.errorproperty}" 
                  settingsFile="${settingsFile}" />
    </target>
</project>

The task expects a mandatory settingsFile parameter, which dictates the rules (files inclusion/exclusion) with regards to OSB project that needs to be exported.

A sample settingsFile as provided by the Oracle documentation is given below:
<configjarSettings xmlns="http://www.bea.com/alsb/tools/configjar/config">
    <source>
        <project dir="/scratch/workspaces/myworkspace/projectX"/>
        <project dir="/scratch/workspaces/myworkspace/projectY"/>
        <extensionMapping>
            <mapping type="Xquery" extensions="xquery,xq,xqy"/>
            <mapping type="XML" extensions="toplink"/>
        </extensionMapping>
    </source>
    <configjar jar="/scratch/workspaces/myworkspace/sbconfig.jar">
        <resourceLevel/>
    </configjar>
</configjarSettings>

The source element defines the source artefacts that needs to be picked up during the load phase and the configjar element defines the details about the configuration jar and what projects/resources it should include.

In this post we will take a look at how this task can be mavenized and the settingsFile can be externalized, so that we don't need to explicitly create different settingsFile for each deployment unit.

The first step is to create the custom settingsFile and load the same into the maven repository.

osb-project-settings.xml

<?xml version="1.0" encoding="UTF-8" ?>
<p:configjarSettings xmlns:p="http://www.bea.com/alsb/tools/configjar/config">
    <p:source>
        <p:project dir="@@osb.project.dir.path@@"/>
        <p:fileset>
            <p:exclude name="*/.settings/**" />
            <p:exclude name="*/import.*" />
            <p:exclude name="*/pom.xml" />
            <p:exclude name="*/target/**" />
            <p:exclude name="*/security/**" />
            <p:exclude name="*/import.*" />
            <p:exclude name="*/alsbdebug.xml" />
            <p:exclude name="*/configfwkdebug.xml" />
            <p:exclude name="*/*settings.xml" />
            <p:exclude name="*/@@osb.project.export.jar@@" />
        </p:fileset>
    </p:source>
    <p:configjar jar="@@osb.project.export.jar@@">
        <p:projectLevel includeSystem="@@osb.include.system@@">
            <p:project>@@osb.project.name@@</p:project>
        </p:projectLevel>
    </p:configjar>
</p:configjarSettings>

pom.xml


<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
    http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion> 
    <parent>
        <groupId>techsamples.fmw</groupId>
        <artifactId>parent</artifactId>
        <version>1.0</version>
    </parent>
    <groupId>techsamples.fmw</groupId>
    <artifactId>osb-build-config</artifactId>
    <packaging>jar</packaging>
    <version>1.0</version>
    <name>osb-build-config</name>
    <!-- copy osb-project-settings.xml  & osbImport.py files -->
    <build>
        <resources>
            <resource>
                <directory>${project.basedir}</directory>
                <includes>
                    <include>osb-project-settings.xml</include>
                    <include>osbImport.py</include>
                </includes>
            </resource>
        </resources>
    </build>
</project>

Now lets load the osb-project-settings-file into the maven repository

The osb-project-settings.xml file will be unpacked from the repository as part of the deployment process and all the tokens are substituted during runtime with the osb project specific details. This way we don't need to have different settings file for each project.

Below are the plugin details for

  • Unpacking the settings file
  • Replacing the tokens in the settings file
  • Export/Deploy the osb configuration jar 



<plugin>
    <artifactId>maven-dependency-plugin</artifactId>
    <dependencies>
        <dependency>
            <groupId>techsamples.fmw</groupId>
            <artifactId>osb-build-config</artifactId>
            <version>1.0</version>
        </dependency>
    </dependencies>
    <executions>
        <execution>
            <id>unpack-osb-build-config-files</id>
            <phase>process-resources</phase>
            <goals>
                <goal>unpack</goal>
            </goals>
            <configuration>
                <artifactItems>
                    <artifactItem>
                        <groupId>techsamples.fmw</groupId>
                        <artifactId>osb-build-config</artifactId>
                        <version>1.0</version>
                        <overWrite>true</overWrite>
                        <outputDirectory>${project.build.directory}</outputDirectory>
                        <includes>
                            *
                        </includes>
                    </artifactItem>
                </artifactItems>
                <overWriteReleases>true</overWriteReleases>
                <overWriteSnapshots>true</overWriteSnapshots>
            </configuration>
        </execution>
    </executions>
</plugin>
<plugin>
    <groupId>com.google.code.maven-replacer-plugin</groupId>
    <artifactId>replacer</artifactId>
    <version>1.5.3</version>
    <executions>
        <execution>
            <id>replace-tokens</id>
            <phase>process-resources</phase>
            <goals>
                <goal>replace</goal>
            </goals>
        </execution>
    </executions>
    <configuration>  
        <includes>  
            <include>${project.build.directory}/osb-project-settings.xml</include>    
        </includes>  
        <replacements>
            <replacement>
                <token>@@osb.project.export.jar@@</token>
                <value>${project.artifactId}-${project.version}.jar</value>
            </replacement>
            <replacement>
                <token>@@osb.project.dir.path@@</token>
                <value>${basedir}/${project.artifactId}</value>
            </replacement>
            <replacement>
                <token>@@osb.project.name@@</token>
                <value>${project.artifactId}</value>
            </replacement>
            <replacement>
                <token>@@osb.include.system@@</token>
                <value>${osb.include.system}</value>
            </replacement>
        </replacements>
    </configuration>
</plugin>
<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.2.1</version>
    <executions>
        <execution>
            <id>export-sbconfigjar</id> 
            <phase>package</phase>
            <goals>
                <goal>exec</goal>
            </goals>
            <configuration>
                <executable>java</executable>
                <commandlineArgs>-Dosb.home=${osb.product.home} -Dweblogic.home=${wls.product.home} -classpath ${osb.classpath} com.bea.alsb.tools.configjar.ConfigJar -settingsfile ${project.build.directory}/osb-project-settings.xml</commandlineArgs>
                <removeAll>true</removeAll>
            </configuration>
        </execution>
        <execution>
            <id>deploy</id>
            <phase>deploy</phase>
            <configuration>
                <executable>java</executable>
                <commandlineArgs>
                    -Dosb.home=${osb.product.home} -Dweblogic.home=${wls.product.home} -classpath ${osb.classpath}
                    -Dwls.deploy.userid=${wls.deploy.userid}
                    -Dwls.deploy.password=${wls.deploy.password}
                    -Dadmin.target.serverURL=t3://${admin.target.address}
                    -Dosb.project.name=${project.artifactId}
                    -Dosb.project.export.jar=${project.build.directory}/${project.artifactId}-${project.version}.${project.packaging}
                    -Dosb.project.customizationFile=${project.basedir}/${project.artifactId}/${project.artifactId}-customizationFile.xml
                    weblogic.WLST ${project.build.directory}/osbImport.py</commandlineArgs>
                
            </configuration>
            <goals>
                <goal>exec</goal>
            </goals>
        </execution>
    </executions>
</plugin>

No comments:

Post a Comment