Wednesday, 9 March 2016

Deploying SOA 11g Application using ANT

Deploying SOA 11g Application using ANT

This blog will guide you the deploy SOA applications using ANT script.
Here is my subversion directory structure,
image
Under applications you put your application and projects underneath,
image
You might have several projects, in my case I’ve two projects BusinessEventTest and HelloWorldEmail.Every project has got its own deployment plan for different environments like in my case BusinessEventTest_cfgplan_dev.xml and HelloWorldEmail_cfgplan_dev.xml.
Create a build.properties file under applications and fill accordingly as below,
image
Give the partition name where you want to deploy.
Go back and under tools you should have following files,
image
In build.properties give the below information,
*****************************************************************************
# global
fmw.home=C:/shrik/Oracle/fmw
oracle.home=${fmw.home}/jdeveloper
java.passed.home=C:/shrik/Oracle/SOAWork/composites/jrockit
wl_home=${fmw.home}/wlserver_10.3
# temp
tmp.output.dir=c:/temp
junit.output.dir=../../
applications.home=../../applications
applications=HelloWorld
mds.enabled=false
mds.reposistory=${oracle.home}/integration/seed/apps/
mds.applications=Woningnet-Test
mds.undeploy=false
deployment.plan.environment=dev
# dev deployment server weblogic
dev.serverURL=http://shreekanta-pc:7001
dev.overwrite=true
dev.user=weblogic
dev.password=welcome1
dev.forceDefault=true
dev.server=shreekanta-pc
dev.port=7001
In dev.jndi.properties give the below information,
java.naming.factory.initial=weblogic.jndi.WLInitialContextFactory
java.naming.provider.url=t3://shreekanta-pc:7001/soa-infra
java.naming.security.principal=weblogic
java.naming.security.credentials=welcome1
dedicated.connection=true
dedicated.rmicontext=true
****************************************************************************
build.xml file ,you can use as it is else can customize as per your need,
***************************************************************************
<?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"/>

    <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>
        <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>  
    </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>
         <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>
    </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"/>
        <propertycopy name="proj.partition" from="${project}.partition"/>
    
    
        <echo>deploy compositeName ${proj.compositeName}</echo>
        <echo>deploy compositeDir ${proj.compositeDir}</echo>

         <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>
        <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>

         <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="partition" value="${proj.partition}"/>
             <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}"/>
        </ant>
       <echo>disable or enable composite ${proj.compositeName} </echo>
                
        <if>
          <equals arg1="${proj.enabled}" 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>
        <if>
          <equals arg1="${proj.enabled}" arg2="true"/>
          <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>
    
            <echo>unit test sarFile ${proj.compositeName} </echo>
            <ant antfile="${oracle.home}/bin/ant-sca-test.xml" inheritAll="false" target="test">
                 <property name="scatest.input" value="${project}"/>
                 <property name="scatest.format" value="junit"/>
                 <property name="scatest.result" value="${env.CURRENT_FOLDER}/${junit.output.dir}"/>
                 <property name="scatest.partition" value="${proj.partition}"/>
                 <property name="jndi.properties.input" value="${deployment.plan.environment}.jndi.properties"/>
            </ant>
          </then>
        </if>    
    
     
    </target>

</project>
**********************************************************************************
At last deployAll.bat file would have following entries,
image
Open a command prompt and execute deployAll which will deploy all your projects under a particular application in SOA Server.

No comments:

Post a Comment