Wednesday, December 5, 2012

OSB Scripted modification of customization file

While migrating OSB artifacts from one environment to another, we use customization file to apply changes specific to the environment. But to changing the customization file for each environment still demands a manual work.

This manual change is error prone and might create unexpected results.

Here is an alternative for that. Instead of changing the customization file manually, the following ANT script will do the job by reading the target environment specific values from a property file.

Step 1:  Create a base folder called automation and create a sub folder called source under it

Step 2 :  In the customization file identify the properties that might change from environment to envrironment and tokenize them in braces { }

For eg. the below excerpts from the customization file , in which a proxy service picks a file from FTP server and a business service will post that file content to a JMS queue

Proxy Service
=============

   <cus:envValueAssignments>
      <xt:envValueType>Service URI</xt:envValueType>
      <xt:location xsi:nil="true"/>
      <xt:owner>
        <xt:type>ProxyService</xt:type>
        <xt:path>InitiateOrderProcessing/ProxyServices/OrderProcessingInitiateFTP_PS</xt:path>
      </xt:owner>
      <xt:value xsi:type="xs:string" xmlns:xs="http://www.w3.org/2001/XMLSchema">ftp://{FTPHOST}:{FTPPORT}/import</xt:value>
    </cus:envValueAssignments>

Business Service
================


 <tran:tableElement xmlns:tran="http://www.bea.com/wli/sb/transports">
          <tran:URI>jms://{JMSHOST}:{JMSPORT}/weblogic.jms.XAConnectionFactory/Jms.nOrderProcessing</tran:URI>
          <tran:weight>1</tran:weight>
        </tran:tableElement>



Step 3 : Save the customization file as .seed file and keep that in the source folder

Step 4: Create target specific properties file and save it in the automation folder

==========build.dev.properties===================

JMSHOST=localhost
JMSPORT=8001
FTPHOST=testftp
FTPPORT=24
ARCHIVE_DIR=/archive/test
ERROR_DIR=/error/test
DOWNLOAD_DIR=/download/test
=============end of build.dev.properties==============

==============build.qa.properties===================

JMSHOST=myhost
JMSPORT=8011
FTPHOST=mytftp
FTPPORT=21
ARCHIVE_DIR=/archive/testmy
ERROR_DIR=/error/testmy
DOWNLOAD_DIR=/download/testmy
=============end of build.qa.properties================

Step 5 : Create and store the following build.xml file in the base directory(automation)
================build.xml============================

<project name="SOA_OSB_Deployment" basedir="." default="init" xmlns:ac="antlib:net.sf.antcontrib">
    <input message="Enter the environment to deploy:" addproperty="env"/>
    <property file="${basedir}/build.${env}.properties"/>
<property name="sa.source.dir" value="${basedir}/source"/>
<property name="sa.target.dir" value="${basedir}/target"/>
 <taskdef resource="net/sf/antcontrib/antlib.xml">
  <classpath>
    <pathelement location="/automation/ant-contrib-1.0b3.jar"/>
  </classpath>
</taskdef>
<target name="init">
    <delete dir="${sa.target.dir}" verbose="${OSBVerbose}" failonerror="false" includeemptydirs="true"/>
    <mkdir dir="${sa.target.dir}"/>
<antcall target="updateCustomizationFile" inheritAll="Yes"/>
 </target>
<target name="replaceTokens">
    <!-- replace ${} tokens into <param1>.new file -->
    <echo message="Replace Tokens in ${param1}"/>
<echo message="properties file in ${param2}"/>
    <copy file="${param1}" tofile="${param1}.new" overwrite="true">
      <filterchain>
        <replaceregex pattern="\$\{" replace="{"/>
        <filterreader classname="org.apache.tools.ant.filters.ReplaceTokens">
          <param type="propertiesfile" value="${param2}"/>
          <param type="tokenchar" name="begintoken" value="{"/>
          <param type="tokenchar" name="endtoken" value="}"/>
        </filterreader>
      </filterchain>
    </copy>
  </target>
    <target name="updateCustomizationFile" description="Updates the property values for the target environment">
    <tstamp prefix="Start updateCustomizationFile"/>
    <echo message="Parse service accounts"/>
 <for param="seed.file">
<path>
<fileset dir="${sa.source.dir}" includes="**/*.seed"/>
      </path>
      <sequential>
        <echo message="Parse service accounts file: @{seed.file}"/>
         <antcall target="replaceTokens" inheritAll="No">
          <param name="param1" value="@{seed.file}"/>
          <param name="param2" value="build.${env}.properties"/>
        </antcall>
        <copy file="@{seed.file}.new" tofile="customization.xml"/>
<copy file="customization.xml" todir="${sa.target.dir}"/>
<delete file="@{seed.file}.new" quiet="true"/>
           
     </sequential>
    </for>
    <tstamp prefix="finished updateCustomizationFile"/>
  </target>
  </project>
================ end of build.xml=========================




Step 6 : open command prompt and go to the base folder automation . Execute the run command
automation> run

It will prompt for you to give the target environment name.

Step7 :Based on the environment name given it will read the property from the respective properties file and update the customization file.

Result : The modified customization file will be stored in the target folder. Now just apply this customization file from sbconsole or using script as mentioned in the previous listing




No comments:

Post a Comment