Monday, December 3, 2012

Updating Service Account Values in OSB using script

OSB customization file does not support the update of Service Account values.

If we move from one environment to another there is a possibility of the username and password change.

For e.g during QA testing the FTP server may be a sample server and while moving the code to PROD we might to target to a another FTP server which has totally different set of credentials.

Its a hard job to do this change via sb-console after the deployment. Instead of that before the deployment we can change these values for the target environment

Step1 : In the Service Account configuration , instead of hard coding the username and password , provide some tokens as below
================ FTPUser.ServiceAccount ===================

<?xml version="1.0" encoding="UTF-8"?>
<ser:service-account xsi:type="ser:StaticServiceAccount" xmlns:ser="http://www.bea.com/wli/sb/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:con="http://www.bea.com/wli/sb/resources/config">
    <ser:description/>
    <ser:static-account>
        <con:username>{ServiceAccount.FTPUsername.value}</con:username>
        <con:password>{ServiceAccount.FTPPassword.value}</con:password>
    </ser:static-account>
</ser:service-account>


================ end of FTPUser.ServiceAccount====================

Step 2 : Create a build.{env}.properties file as follows

Note {env} could be the any target environment(dev/qa/prod)

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


ServiceAccount.FTPUsername.value=developer
ServiceAccount.FTPPassword.value=exotic


==========end of  build.dev.properties===========


Step 3 : Create the build.xml as follows

================build.xml========================


<project name="SOA_OSB_Deployment" basedir="." default="updateCredentials" xmlns:ac="antlib:net.sf.antcontrib">
 
 <taskdef resource="net/sf/antcontrib/antlib.xml">
  <classpath>
    <pathelement location="/automation/ant-contrib-1.0b3.jar"/>
  </classpath>
</taskdef>


<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="updateCredentials" description="Replace ServiceAccounts with correct passwords">
    <tstamp prefix="Start updateCredentials"/>


     <input message="Please 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"/>
    <delete dir="${sa.target.dir}" verbose="${OSBVerbose}" failonerror="false" includeemptydirs="true"/>
    <mkdir dir="${sa.target.dir}"/>
    <unzip src="${sa.source.dir}/sbconfig.jar" dest="${sa.target.dir}"/>

    <echo message="Parse service accounts"/>
 <for param="sa.file">
<path>
<fileset dir="${sa.target.dir}" includes="**/*.ServiceAccount"/>
      </path>
      <sequential>
        <echo message="Parse service accounts file: @{sa.file}"/>
         <antcall target="replaceTokens" inheritAll="No">
          <param name="param1" value="@{sa.file}"/>
          <param name="param2" value="build.${env}.properties"/>
        </antcall>
        <copy file="@{sa.file}.new" tofile="@{sa.file}"/>
        <delete file="@{sa.file}.new" quiet="true"/>
   
        <zip destfile="target/sbconfig.jar" basedir="${sa.target.dir}" update="false"/>
     </sequential>
    </for>
    <tstamp prefix="finished updateCredentials"/>
  </target>
  </project>

================end of build.xml===================

Step 4 : Create a base folder called automation in the file system
            Create sub folders source and target under automation folder

Step 5:  Copy the build.dev.properties and build.xml files under automation directory

Note: ensure that you have ant-contrib-1.0b3.jar in the path mentioned in the build.xml
 <pathelement location="/automation/ant-contrib-1.0b3.jar"/>

Step 6 : copy the to be updated sbconfig.jar to the source folder

Step 7 : open command prompt and go to the automation folder and run ant
 automation > run
on prompt give the target environment  dev/qa/prod.

The updated sbconfig.jar will now appear in the target folder.

To verify the results unzip the sbconfig.jar and verify the Service Account values.

Now this new sbconfig.jar can be deployed to the target environment

1 comment:

  1. Hi I wanted to know how to connect to sbconsole using wlst command and I wanted to update a XQuery for it.Please let me know.

    ReplyDelete