Friday, 23 November 2012

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 one or more composites applications to different SOA environments. So now you can use it to automate your deployment or use it in your build tool.
In my ant script I will deploy shared artifacts to the MDS, compile, build and package the composite applications 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 continuous 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 jdeveloper\bin folder. Here is a summary of the scripts and what they 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 what is the environment dev or acc.

# demo = true , then no soa scripts will be called.
demo.mode=false
# global
wn.bea.home=C:/oracle/MiddlewareJdev11gR1PS3
java.passed.home=${wn.bea.home}/jdk1.6.0_23
# PS4
#wn.bea.home=D:/Oracle/MiddlewareJDevPS4
#java.passed.home=${wn.bea.home}/jdk160_24
oracle.home=${wn.bea.home}/jdeveloper
wl_home=${wn.bea.home}/wlserver_10.3
# temp
tmp.output.dir=c:/temp
junit.output.dir=../../
# my settings
applications.home=../../applications
applications=HelloWorld
# my settings
mds.repository=C:/oracle/MiddlewareJdev11gR1PS3/jdeveloper/integration/seed/apps/
mds.applications=Woningnet-Test
#demo applications
#applications.home=workspaces
#applications=wrkspc1,wrkspc2
#demo mds locations
#mds.repository=mds/seed/apps/
#mds.applications=company,common
mds.enabled=true
mds.undeploy=true
deployment.plan.environment=dev
# dev deployment server weblogic
dev.serverURL=http://laptopedwin:7001
dev.overwrite=true
dev.user=weblogic
dev.password=weblogic1
dev.forceDefault=true
dev.server=laptopedwin
dev.port=7001
# acceptance deployment server weblogic
acc.serverURL=http://laptopedwin:7001
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
  1. projects=Helloworld  
  2. Helloworld.revision=1.0  
  3. Helloworld.enabled=true  
  4. Helloworld.partition=default  

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">
    <property environment="env"/>
    <property file="${env.CURRENT_FOLDER}/build.properties"/>
    <!-- Antcontrib path -->
    <path id="antcontrib.path">
      <pathelement path="lib/ant-contrib-1.0b3.jar" />
    </path>
    <taskdef classpathref="antcontrib.path"
             resource="net/sf/antcontrib/antlib.xml"/>
    <target name="deployAll">
       <!-- Build time -->
       <tstamp>
          <format property="build.date" pattern="yyyy-MM-dd HH:mm:ss" />
       </tstamp>
       <!-- Build number -->
       <condition property="build.number" value="${env.BUILD_NUMBER}">
          <isset property="env.BUILD_NUMBER" />
       </condition>
       <buildnumber file="build.num" />
<echo message="date = ${build.date}"
level="info"/>
<echo message="build = ${build.number}"
level="info"/>
       <echo file="logs/instance-${build.number}.log" append="true"
             message="deployAll${line.separator}"
             level="info"/>
       <echo file="logs/instance-${build.number}.log" append="true"
             message="basedir ${basedir}${line.separator}"
             level="debug"/>
       <echo file="logs/instance-${build.number}.log" append="true"
             message="current folder ${env.CURRENT_FOLDER}${line.separator}"
             level="debug"/>
<echo file="logs/instance-${build.number}.log" append="true"
message="date = ${build.date}${line.separator}"
level="info"/>
<echo file="logs/instance-${build.number}.log" append="true"
message="build = ${build.number}${line.separator}"
level="info"/>
<echo file="logs/instance-${build.number}.log" append="true"
message="environment = ${deployment.plan.environment}${line.separator}"
level="info"/>
       <mkdir dir="builds/${build.number}"/>
     <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="deployMDS">
        <echo message="undeploy and deploy MDS"
              level="info"/>
        <echo file="logs/instance-${build.number}.log" append="true"
              message="->deployMDS undeploy and deploy MDS${line.separator}"
              level="info"/>
        <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 message="deploy MDS application ${mds.application}"
              level="info"/>
        <echo file="logs/instance-${build.number}.log" append="true"
              message="${line.separator}-->deployMDSApplication deploy MDS application ${mds.application}${line.separator}"
              level="info"/>
        <echo message="remove and create local MDS temp"
              level="debug"/>
        <property name="mds.deploy.dir" value="${tmp.output.dir}/${mds.application}"/>
        <delete dir="${mds.deploy.dir}"/>
        <mkdir dir="${mds.deploy.dir}"/>
        <echo message="create zip from file MDS store"
              level="debug"/>
<zip destfile="${mds.deploy.dir}/${mds.application}_mds.jar" compress="false">
     <fileset dir="${mds.repository}" includes="${mds.application}/**"/>
     </zip>
        <echo message="create zip with MDS jar"
              level="debug"/>
<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 message="deploy on ${deploy.serverURL} with user ${deploy.user}"
              level="info"/>
        <echo message="deploy sarFile ${mds.deploy.dir}/${mds.application}_mds.zip"
              level="info"/>
        <echo file="logs/instance-${build.number}.log" append="true"
              message="---->deploy on ${deploy.serverURL} with user ${deploy.user}${line.separator}"
              level="info"/>
        <echo file="logs/instance-${build.number}.log" append="true"
              message="---->deploy sarFile ${mds.deploy.dir}/${mds.application}_mds.zip${line.separator}"
              level="info"/>
        <copy todir="builds/${build.number}"
              file="${mds.deploy.dir}/${mds.application}_mds.zip"/>
     <if>
          <equals arg1="${demo.mode}" arg2="false"/>
          <then>
            <ant antfile="${oracle.home}/bin/ant-sca-deploy.xml" inheritAll="false" target="deploy">
             <property name="wl_home" value="${wl_home}"/>
             <property name="oracle.home" value="${oracle.home}"/>
             <property name="serverURL" value="${deploy.serverURL}"/>
             <property name="user" value="${deploy.user}"/>
             <property name="password" value="${deploy.password}"/>
             <property name="overwrite" value="${deploy.overwrite}"/>
             <property name="forceDefault" value="${deploy.forceDefault}"/>
             <property name="sarLocation" value="${mds.deploy.dir}/${mds.application}_mds.zip"/>
            </ant>
          </then>
        </if>
    </target>
    <target name="undeployMDSApplication">
        <echo message="undeploy MDS application ${mds.application}"
              level="info"/>
        <echo file="logs/instance-${build.number}.log" append="true"
              message="${line.separator}-->undeployMDSApplication undeploy MDS application ${mds.application}${line.separator}"
              level="info"/>
        <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 message="undeploy MDS app folder apps/${mds.application}"
              level="info"/>
        <echo file="logs/instance-${build.number}.log" append="true"
              message="---->undeploy MDS app folder apps/${mds.application}${line.separator}"
              level="info"/>
     <if>
          <equals arg1="${demo.mode}" arg2="false"/>
          <then>
            <ant antfile="${oracle.home}/bin/ant-sca-deploy.xml" inheritAll="false" target="removeSharedData">
          <property name="wl_home" value="${wl_home}"/>
              <property name="oracle.home" value="${oracle.home}"/>
              <property name="serverURL" value="${deploy.serverURL}"/>
              <property name="user" value="${deploy.user}"/>
              <property name="password" value="${deploy.password}"/>
              <property name="folderName" value="${mds.application}"/>
            </ant>
          </then>
        </if>
    </target>
    <target name="deployApplication">
        <echo message="deploy application ${application}"
              level="info"/>
        <echo file="logs/instance-${build.number}.log" append="true"
              message="${line.separator}-->deployApplication deploy application ${application}${line.separator}"
              level="info"/>
        <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 message="deploy project ${project} for environment ${deployment.plan.environment}"
              level="info"/>
        <echo file="logs/instance-${build.number}.log" append="true"
              message="${line.separator}---->deployProject deploy project ${project} for environment ${deployment.plan.environment}${line.separator}"
              level="info"/>
        <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"/>
        <propertycopy name="proj.partition" from="${project}.partition"/>
        <echo message="partition ${proj.partition} compositeName ${proj.compositeName} compositeDir ${proj.compositeDir}"
              level="info"/>
        <echo file="logs/instance-${build.number}.log" append="true"
              message="------>partition ${proj.partition}${line.separator}"
              level="info"/>
        <echo file="logs/instance-${build.number}.log" append="true"
              message="------>compositeName ${proj.compositeName}${line.separator}"
              level="info"/>
        <echo file="logs/instance-${build.number}.log" append="true"
              message="------>revision ${proj.revision}${line.separator}"
              level="info"/>
        <echo file="logs/instance-${build.number}.log" append="true"
              message="------>compositeDir ${proj.compositeDir}${line.separator}"
              level="info"/>
        <echo message="build sar package"
              level="info"/>
        <echo file="logs/instance-${build.number}.log" append="true"
              message="------>build sar package${line.separator}"
              level="info"/>
     <if>
          <equals arg1="${demo.mode}" arg2="false"/>
          <then>
            <ant antfile="${oracle.home}/bin/ant-sca-package.xml" inheritAll="false" target="package">
             <property name="compositeDir" value="${proj.compositeDir}/${project}"/>
             <property name="compositeName" value="${proj.compositeName}"/>
             <property name="revision" value="${proj.revision}"/>
             <property name="oracle.home" value="${oracle.home}"/>
             <property name="java.passed.home" value="${java.passed.home}"/>
             <property name="wl_home" value="${wl_home}"/>
             <property name="sca.application.home" value="${proj.compositeDir}"/>
             <property name="scac.application.home" value="${proj.compositeDir}"/>
             <property name="scac.input" value="${proj.compositeDir}/${proj.compositeName}/composite.xml"/>
             <property name="scac.output" value="${tmp.output.dir}/${proj.compositeName}.xml"/>
             <property name="scac.error" value="${tmp.output.dir}/${proj.compositeName}.err"/>
             <property name="scac.displayLevel" value="3"/>
            </ant>
            <copy todir="builds/${build.number}"
                  file="${proj.compositeDir}/${proj.compositeName}/deploy/sca_${proj.compositeName}_rev${proj.revision}.jar"/>
          </then>
        </if>
        
        <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 message="deploy on ${deploy.serverURL} with user ${deploy.user}"
              level="info"/>
        <echo file="logs/instance-${build.number}.log" append="true"
              message="------>deploy on ${deploy.serverURL} with user ${deploy.user}${line.separator}"
              level="info"/>
        <echo message="deploy sarFile ${deploy.sarLocation}"
              level="info"/>
        <echo file="logs/instance-${build.number}.log" append="true"
              message="------>deploy sarFile ${deploy.sarLocation}${line.separator}"
              level="info"/>
        <echo file="logs/instance-${build.number}.log" append="true"
              message="------>deployment plan used ${deploy.configplan}${line.separator}"
              level="info"/>
     <if>
          <equals arg1="${demo.mode}" arg2="false"/>
          <then>
<ant antfile="${oracle.home}/bin/ant-sca-deploy.xml" inheritAll="false" target="deploy">
<property name="wl_home" value="${wl_home}"/>
<property name="oracle.home" value="${oracle.home}"/>
<property name="serverURL" value="${deploy.serverURL}"/>
<property name="user" value="${deploy.user}"/>
<property name="password" value="${deploy.password}"/>
<property name="overwrite" value="${deploy.overwrite}"/>
<property name="forceDefault" value="${deploy.forceDefault}"/>
<property name="sarLocation" value="${deploy.sarLocation}"/>
<property name="configplan" value="${deploy.configplan}"/>
<property name="partition" value="${proj.partition}"/>
</ant>
          </then>
        </if>
        
        <if>
          <equals arg1="${proj.enabled}" arg2="false"/>
          <then>
<echo message="stop ${proj.compositeName}"
     level="info"/>
         <echo file="logs/instance-${build.number}.log" append="true"
             message="------>stop ${proj.compositeName}${line.separator}"
               level="info"/>
<if>
<equals arg1="${demo.mode}" arg2="false"/>
<then>
<ant antfile="${oracle.home}/bin/ant-sca-mgmt.xml" inheritAll="false" target="stopComposite">
<property name="host" value="${deploy.server}"/>
<property name="port" value="${deploy.port}"/>
<property name="user" value="${deploy.user}"/>
<property name="password" value="${deploy.password}"/>
<property name="compositeName" value="${proj.compositeName}"/>
<property name="revision" value="${proj.revision}"/>
<property name="partition" value="${proj.partition}"/>
</ant>
</then>
</if>
          </then>
        </if>
        <if>
          <equals arg1="${proj.enabled}" arg2="true"/>
          <then>
<echo message="stop activate ${proj.compositeName}"
     level="info"/>
         <echo file="logs/instance-${build.number}.log" append="true"
             message="------>activate ${proj.compositeName}${line.separator}"
               level="info"/>
<if>
<equals arg1="${demo.mode}" arg2="false"/>
<then>
<ant antfile="${oracle.home}/bin/ant-sca-mgmt.xml" inheritAll="false"
target="activateComposite">
<property name="host" value="${deploy.server}"/>
<property name="port" value="${deploy.port}"/>
<property name="user" value="${deploy.user}"/>
<property name="password" value="${deploy.password}"/>
<property name="compositeName" value="${proj.compositeName}"/>
<property name="revision" value="${proj.revision}"/>
<property name="partition" value="${proj.partition}"/>
</ant>
</then>
</if>
<echo message="unit test ${proj.compositeName}"
     level="info"/>
         <echo file="logs/instance-${build.number}.log" append="true"
             message="------>unit test ${proj.compositeName}${line.separator}"
               level="info"/>
<if>
<equals arg1="${demo.mode}" arg2="false"/>
<then>
<ant antfile="${oracle.home}/bin/ant-sca-test.xml" inheritAll="false"
target="test">
<property name="scatest.input" value="${project}"/>
<property name="scatest.partition" value="${proj.partition}"/>
<property name="scatest.format" value="junit"/>
<property name="scatest.result" value="${env.CURRENT_FOLDER}/${junit.output.dir}"/>
<property name="jndi.properties.input" value="${deployment.plan.environment}.jndi.properties"/>
</ant>
</then>
</if>
          </then>
        </if>
        <echo message="finish"
  level="info"/>
      <echo file="logs/instance-${build.number}.log" append="true"
          message="------>finish${line.separator}"
           level="info"/>
    </target>
</project>
view raw build.xml This Gist brought to you by GitHub.

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 library and put this in the classpath of ANT or put it in the ANT lib folder.
  1. set ORACLE_HOME=C:\oracle\MiddlewareJdev11gR1PS3  
  2. set ANT_HOME=%ORACLE_HOME%\jdeveloper\ant  
  3. set PATH=%ANT_HOME%\bin;%PATH%  
  4. set JAVA_HOME=%ORACLE_HOME%\jdk1.6.0_23  
  5.   
  6. set CURRENT_FOLDER=%CD%  
  7.   
  8. ant -f build.xml deployAll  


See my github project for the source code https://github.com/biemond/soa_tools
Latest changes.

  • PS3 / PS4 support
  • Activation of the composite
  • partition support
  • Build number generator
  • Build logging
  • SAR and MDS z ipsfiles are bundled under build number.
  • Demo mode, in which you can test the ANT configuration without deploying
The new file structure with a logs and build folder.
 The logging of a run.

2 comments:

  1. I really appreciate information shared above. It’s of great help. If someone want to learn Online (Virtual) instructor lead live training in Oracle 11g Fusion Java Programming, kindly contact us http://www.maxmunus.com/contact
    MaxMunus Offer World Class Virtual Instructor led training on Oracle 11g Fusion Java Programming. We have industry expert trainer. We provide Training Material and Software Support. MaxMunus has successfully conducted 100000+ trainings in India, USA, UK, Australlia, Switzerland, Qatar, Saudi Arabia, Bangladesh, Bahrain and UAE etc.
    For Demo Contact us.
    Nitesh Kumar
    MaxMunus
    E-mail: nitesh@maxmunus.com
    Skype id: nitesh_maxmunus
    Ph:(+91) 8553912023
    http://www.maxmunus.com/



    ReplyDelete
  2. I really appreciate information shared above. It’s of great help. If someone want to learn Online (Virtual) instructor lead live training in Oracle 11g Fusion Java Programming, kindly contact us http://www.maxmunus.com/contact
    MaxMunus Offer World Class Virtual Instructor led training on Oracle 11g Fusion Java Programming. We have industry expert trainer. We provide Training Material and Software Support. MaxMunus has successfully conducted 100000+ trainings in India, USA, UK, Australlia, Switzerland, Qatar, Saudi Arabia, Bangladesh, Bahrain and UAE etc.
    For Demo Contact us.
    Nitesh Kumar
    MaxMunus
    E-mail: nitesh@maxmunus.com
    Skype id: nitesh_maxmunus
    Ph:(+91) 8553912023
    http://www.maxmunus.com/



    ReplyDelete