Thursday, 22 December 2011

Deploy Soa Suite 11g composite applications with Ant scripts

With Soa Suite 11g you can deploy your composite applications from JDeveloper or with Ant. In this blog I will do this with the soa 11g Ant scripts. These ant scripts can only deploy one project so I made an Ant script around the soa ant scripts which can deploy more composites applications to different Soa enviroments. So now you can use it to automate your deployment or use it in your build tool. In my ant script I will deploy to the MDS, compile, build and package the composite application and deploy this to the soa server, after this I use an ant script to start the unit tests and generate a junit result xml and at last I can optional disable the composite.
This junit xml can be used in your continious build system. You can easily extend this build script so you use it to manage the composite applications.
For more info over ant deployment see the official deployment documentation .
The official ant scripts are located in the jdeverloper\bin folder. Here is a summary what are and can do
  • ant-sca-test.xml, This script can start the test suites of the composite and generates a juinit report and not Attaches, extracts, generates, and validates configuration plans for a SOA composite application, The official documentation description is not correct.
  • ant-sca-compile.xml, Compiles a SOA composite application ,this script is also called in the package scrip, so we don't need to call this directly.
  • ant-sca-package.xml, Packages a SOA composite application into a composite SAR file and also validates and build the composite application.
  • ant-sca-deploy.xml, Deploys a SOA composite application.
  • ant-sca-mgmt.xml, Manages a SOA composite application, including starting, stopping, activating, retiring, assigning a default revision version, and listing deployed SOA composite applications.

Here is the main build.properties where you have to define the jdeveloper and your application home, which composite applications you want to deploy and to which environment dev or acc.



# global
wn.bea.home=C:/oracle/MiddlewareJdev11gR1PS1
oracle.home=${wn.bea.home}/jdeveloper
java.passed.home=${wn.bea.home}/jdk160_14_R27.6.5-32
wl_home=${wn.bea.home}/wlserver_10.3

# temp
tmp.output.dir=c:/temp
junit.output.dir=../../

applications.home=../../applications
applications=HelloWorld

mds.enabled=true
mds.reposistory=C:/oracle/MiddlewareJdev11gR1PS1/jdeveloper/integration/seed/apps/
mds.applications=Woningnet-Test
mds.undeploy=true


deployment.plan.environment=dev

# dev deployment server weblogic
dev.serverURL=http://laptopedwin:8001
dev.overwrite=true
dev.user=weblogic
dev.password=weblogic1
dev.forceDefault=true
dev.server=laptopedwin
dev.port=8001

# acceptance deployment server weblogic
acc.serverURL=http://laptopedwin:8001
acc.overwrite=true
acc.user=weblogic
acc.password=weblogic1
acc.forceDefault=true
acc.server=laptopedwin
acc.port=8001


Every application can have one or more soa projects so the main ant script will load the application properties file which contains all the project with its revision number.
Here is a example of SoaEjbReference.properties file

projects=Helloworld

Helloworld.revision=1.0
Helloworld.enabled=false

Because in my example I have two soa environments so I need to create two configuration plans. With this plan ( which look the wls plan ) can change the url of endpoints so it matches with the environment.
Select the composite application xml and generate a configuration plan.
Add the dev or acc extension to the file name.
Here you see how the plan looks like.



And here is the main ant build script which can do it all and calls the Oracle Ant scripts.

<?xml version="1.0" encoding="iso-8859-1"?>
<project name="soaDeployAll" default="deployAll">
<echo>basedir ${basedir}</echo>

<property environment="env"/>
<echo>current folder ${env.CURRENT_FOLDER}</echo>

<property file="${env.CURRENT_FOLDER}/build.properties"/>

<taskdef resource="net/sf/antcontrib/antcontrib.properties"/>

<import file="${basedir}/ant-sca-deploy.xml"/>
<import file="${basedir}/ant-sca-package.xml"/>
<import file="${basedir}/ant-sca-test.xml"/>
<import file="${basedir}/ant-sca-test.xml"/>
<import file="${basedir}/ant-sca-mgmt.xml"/>


<target name="deployAll">
<if>
<equals arg1="${mds.enabled}" arg2="true"/>
<then>
<antcall target="deployMDS" inheritall="true"/>
</then>
</if>
<foreach list="${applications}" param="application" target="deployApplication" inheritall="true" inheritrefs="false"/>
</target>


<target name="unDeployMDS">
<echo>undeploy MDS</echo>
<foreach list="${mds.applications}" param="mds.application" target="undeployMDSApplication" inheritall="true" inheritrefs="false"/>
</target>

<target name="deployMDS">
<echo>undeploy and deploy MDS</echo>
<if>
<equals arg1="${mds.undeploy}" arg2="true"/>
<then>
<foreach list="${mds.applications}" param="mds.application" target="undeployMDSApplication" inheritall="true" inheritrefs="false"/>
</then>
</if>
<foreach list="${mds.applications}" param="mds.application" target="deployMDSApplication" inheritall="true" inheritrefs="false"/>
</target>

<target name="deployMDSApplication">
<echo>deploy MDS application ${mds.application}</echo>

<echo>remove and create local MDS temp</echo>
<property name="mds.deploy.dir" value="${tmp.output.dir}/${mds.application}"/>

<delete dir="${mds.deploy.dir}"/>
<mkdir dir="${mds.deploy.dir}"/>

<echo>create zip from file MDS store</echo>
<zip destfile="${mds.deploy.dir}/${mds.application}_mds.jar" compress="false">
<fileset dir="${mds.reposistory}" includes="${mds.application}/**"/>
</zip>

<echo>create zip with MDS jar</echo>
<zip destfile="${mds.deploy.dir}/${mds.application}_mds.zip" compress="false">
<fileset dir="${mds.deploy.dir}" includes="*.jar"/>
</zip>

<propertycopy name="deploy.serverURL" from="${deployment.plan.environment}.serverURL"/>
<propertycopy name="deploy.overwrite" from="${deployment.plan.environment}.overwrite"/>
<propertycopy name="deploy.user" from="${deployment.plan.environment}.user"/>
<propertycopy name="deploy.password" from="${deployment.plan.environment}.password"/>
<propertycopy name="deploy.forceDefault" from="${deployment.plan.environment}.forceDefault"/>

<echo>deploy MDS app</echo>

<echo>deploy on ${deploy.serverURL} with user ${deploy.user}</echo>
<echo>deploy sarFile ${mds.deploy.dir}/${mds.application}_mds.zip</echo>

<antcall target="deploy" inheritall="false">
<param name="wl_home" value="${wl_home}"/>
<param name="oracle.home" value="${oracle.home}"/>
<param name="serverURL" value="${deploy.serverURL}"/>
<param name="user" value="${deploy.user}"/>
<param name="password" value="${deploy.password}"/>
<param name="overwrite" value="${deploy.overwrite}"/>
<param name="forceDefault" value="${deploy.forceDefault}"/>
<param name="sarLocation" value="${mds.deploy.dir}/${mds.application}_mds.zip"/>
</antcall>
</target>

<target name="undeployMDSApplication">
<echo>undeploy MDS application ${mds.application}</echo>

<propertycopy name="deploy.serverURL" from="${deployment.plan.environment}.serverURL"/>
<propertycopy name="deploy.overwrite" from="${deployment.plan.environment}.overwrite"/>
<propertycopy name="deploy.user" from="${deployment.plan.environment}.user"/>
<propertycopy name="deploy.password" from="${deployment.plan.environment}.password"/>
<propertycopy name="deploy.forceDefault" from="${deployment.plan.environment}.forceDefault"/>

<echo>undeploy MDS app folder apps/${mds.application} </echo>
<antcall target="removeSharedData" inheritall="false">
<param name="wl_home" value="${wl_home}"/>
<param name="oracle.home" value="${oracle.home}"/>
<param name="serverURL" value="${deploy.serverURL}"/>
<param name="user" value="${deploy.user}"/>
<param name="password" value="${deploy.password}"/>
<param name="folderName" value="${mds.application}"/>
</antcall>
</target>


<target name="deployApplication">
<echo>deploy application ${application}</echo>
<property file="${env.CURRENT_FOLDER}/${applications.home}/${application}/build.properties"/>
<foreach list="${projects}" param="project" target="deployProject" inheritall="true" inheritrefs="false"/>
</target>

<target name="deployProject">
<echo>deploy project ${project} for environment ${deployment.plan.environment}</echo>

<property name="proj.compositeName" value="${project}"/>
<property name="proj.compositeDir" value="${env.CURRENT_FOLDER}/${applications.home}/${application}"/>
<propertycopy name="proj.revision" from="${project}.revision"/>
<propertycopy name="proj.enabled" from="${project}.enabled"/>

<echo>deploy compositeName ${proj.compositeName}</echo>
<echo>deploy compositeDir ${proj.compositeDir}</echo>

<antcall target="package" inheritall="false">
<param name="compositeDir" value="${proj.compositeDir}/${project}"/>
<param name="compositeName" value="${proj.compositeName}"/>
<param name="revision" value="${proj.revision}"/>
<param name="oracle.home" value="${oracle.home}"/>
<param name="java.passed.home" value="${java.passed.home}"/>
<param name="wl_home" value="${wl_home}"/>
<param name="sca.application.home" value="${proj.compositeDir}"/>
<param name="scac.application.home" value="${proj.compositeDir}"/>
<param name="scac.input" value="${proj.compositeDir}/${proj.compositeName}/composite.xml"/>
<param name="scac.output" value="${tmp.output.dir}/${proj.compositeName}.xml"/>
<param name="scac.error" value="${tmp.output.dir}/${proj.compositeName}.err"/>
<param name="scac.displayLevel" value="3"/>
</antcall>

<property name="deploy.sarLocation" value="${proj.compositeDir}/${proj.compositeName}/deploy/sca_${proj.compositeName}_rev${proj.revision}.jar"/>
<property name="deploy.configplan" value="${proj.compositeDir}/${proj.compositeName}/${proj.compositeName}_cfgplan_${deployment.plan.environment}.xml"/>

<propertycopy name="deploy.serverURL" from="${deployment.plan.environment}.serverURL"/>
<propertycopy name="deploy.overwrite" from="${deployment.plan.environment}.overwrite"/>
<propertycopy name="deploy.user" from="${deployment.plan.environment}.user"/>
<propertycopy name="deploy.password" from="${deployment.plan.environment}.password"/>
<propertycopy name="deploy.forceDefault" from="${deployment.plan.environment}.forceDefault"/>
<propertycopy name="deploy.server" from="${deployment.plan.environment}.server"/>
<propertycopy name="deploy.port" from="${deployment.plan.environment}.port"/>

<echo>deploy on ${deploy.serverURL} with user ${deploy.user}</echo>
<echo>deploy sarFile ${deploy.sarLocation}</echo>

<antcall target="deploy" inheritall="false">
<param name="wl_home" value="${wl_home}"/>
<param name="oracle.home" value="${oracle.home}"/>
<param name="serverURL" value="${deploy.serverURL}"/>
<param name="user" value="${deploy.user}"/>
<param name="password" value="${deploy.password}"/>
<param name="overwrite" value="${deploy.overwrite}"/>
<param name="forceDefault" value="${deploy.forceDefault}"/>
<param name="sarLocation" value="${deploy.sarLocation}"/>
<param name="configplan" value="${deploy.configplan}"/>
</antcall>

<echo>unit test sarFile ${proj.compositeName} </echo>


<antcall target="test" inheritall="false">
<param name="scatest.input" value="${project}"/>
<param name="scatest.format" value="junit"/>
<param name="scatest.result" value="${env.CURRENT_FOLDER}/${junit.output.dir}"/>
<param name="jndi.properties.input" value="${deployment.plan.environment}.jndi.properties"/>
</antcall>

<echo>disable composite ${proj.compositeName} </echo>

<if>
<equals arg1="${proj.enabled}" arg2="false"/>
<then>
<antcall target="stopComposite" inheritall="false">
<param name="host" value="${deploy.server}"/>
<param name="port" value="${deploy.port}"/>
<param name="user" value="${deploy.user}"/>
<param name="password" value="${deploy.password}"/>
<param name="compositeName" value="${proj.compositeName}"/>
<param name="revision" value="${proj.revision}"/>
</antcall>

</then>
</if>



</target>
</project>


For development testing environment I need to have dev.jndi.properties

java.naming.factory.initial=weblogic.jndi.WLInitialContextFactory
java.naming.provider.url=t3://localhost:8001/soa-infra
java.naming.security.principal=weblogic
java.naming.security.credentials=weblogic1
dedicated.connection=true
dedicated.rmicontext=true


And finally the cmd script to run this ant script. To make this work we need the ant-contrib libray and put this in the classpath.

set ORACLE_HOME=C:\oracle\MiddlewareJdev11gR1PS1
set ANT_HOME=%ORACLE_HOME%\jdeveloper\ant
set PATH=%ANT_HOME%\bin;%PATH%
set JAVA_HOME=%ORACLE_HOME%\jdk160_14_R27.6.5-32

set CURRENT_FOLDER=%CD%

ant -f build.xml deployAll -Dbasedir=%ORACLE_HOME%\jdeveloper\bin


Here is the zip with all the files and extract this and put this all in the jdeveloper/bin folder.

No comments:

Post a Comment