Wednesday, 13 March 2013

Ant scripts for Oracle SOA Suite 11g code deployment (Windows)

This blog post provides Ant scripts that simplify the deployment, undeployment, and management of code to Oracle SOA Suite 11g. These scripts are designed for Windows (will release the Linux instructions soon). For those familiar with it, I do not use the configuration plan (long story).

Who these scripts are designed for:
  • Developers who want an automated approach to deploy/undeploy/manage code
  • App Admins who want to manage code from a Windows-based operating system

What you can do with the scripts:
  • Deploy multiple composites using a single Ant command
  • Undeploy multiple composites using a single Ant command
  • Start multiple composites using a single Ant command
  • Stop multiple composites using a single Ant command
  • List deployed composites
  • Tokenize and detokenize code
  • Import artifacts (XSDs, DVMs, WSDLs, fault policies) to the MDS
  • Export the entire MDS (for backup or browsing purposes)

To see how these scripts work, check out:


One-time Setup and Configuration

1. Download ant_soa11g_windows.zip from here

2. Unzip ant_soa11g_windows.zip to your local c:\ drive (it should exist as c:\ant)

3. Edit setEnvironmentVars.bat and modify the following:
CODE_FOLDER  <-- top-level directory where your code exists (e.g., c:\ant\code)
ORACLE_HOME  <-- directory of JDev 11g (e.g., c:\jdev11g)
JAVA_HOME    <-- ensure that the JDK path is correct
4. Edit soa-environment.properties and modify only the following variables:
wn.bea.home=C:/jdev11g              <-- directory of JDev 11g (similar to ORACLE_HOME above)
tmp.output.dir=c:/ant/temp          <-- temp directory for MDS generation, default is c:\ant\temp
local.mds.repository=c:/ant/apps    <-- location of local MDS copy (for MDS imports)
local.mds.export=c:/ant/apps.backup <-- location of local MDS backup folder (for MDS exports)
5. Double-click on winInstall.bat so that it copies the necessary JARs to the appropriate directories

6. For every SOA Suite 11g environment, create the following 3 files.
For example, if you have a DEV, TEST, and PROD environments, then create the following 9 files:
soa-build-dev.properties
soa-build-test.properties
soa-build-prod.properties
soa-cfgplan-dev.xml
soa-cfgplan-test.xml
soa-cfgplan-prod.xml
soa-token-dev.properties
soa-token-test.properties
soa-token-prod.properties
The ant_soa11g_windows.zip file includes samples for a DEV environment, so just make copies of those files for your other environments.
7. Edit all soa-build-*.properties and soa-token-*.properties files and modify the following:
USERNAME    <-- weblogic username (e.g., 'weblogic')
PASSWORD    <-- weblogic password
SOAHOST     <-- hostname or IP address of SOA Suite 11g server
SOAPORT     <-- port for the soa_server1 managed server (e.g., 8001)
DBUSERNAME  <-- MDS database username (e.g., 'dev_mds')
DBPASSWORD  <-- MDS database password
DBHOST      <-- database host
DBPORT      <-- database port
DBSID       <-- database name

Deploy, Undeploy, Start, Stop, and Detokenize Composites

1. Define the CustomProcessList.txt (see Define the Custom Process List below)

2. Open a command prompt window and type the following
cd c:\ant
call setEnvironmentVars.bat
call ant -f build.soa.xml <target> -Dtargetenv=<env>
Where <target> is deployComposites, undeployComposites, startComposites, stopComposites, or detokenizeComposites. This will loop through and perform the action against all the composites listed in the CustomProcessList.txt file.
Where <env> is your dev, test, or whatever environments you configured earlier.

List Composites

1. Open a command prompt window and type the following
cd c:\ant
call setEnvironmentVars.bat
call ant -f build.soa.xml listComposites -Dtargetenv=<env>
Where <env> is your dev, test, or whatever environments you configured earlier.

Export MDS

1. Open a command prompt window and type the following
cd c:\ant
call setEnvironmentVars.bat
call ant -f build.soa.xml exportMDS -Dtargetenv=<env>
Where <env> is your dev, test, or whatever environments you configured earlier.
2. The export file will be saved to c:\ant\apps.backup in the format of MDSbackup.<env>.YYYY-MM-DD-HHMI.jar (e.g., MDSbackup.dev.2011-01-20_1140.jar)


Import Artifacts to MDS

1. Define the CustomMDSList.txt (see Define the Custom MDS List below)

2. Add all the schemas, WSDLs, DVMs, fault policies, to the c:\ant\apps\<application> directory.
For example:
c:\ant\apps\App1MetaData\dvm\Currency.dvm
c:\ant\apps\App1MetaData\dvm\Country.dvm
c:\ant\apps\App1MetaData\config\fault-bindings.xml
c:\ant\apps\App1MetaData\config\fault-policies.xml
c:\ant\apps\App1MetaData\schemas\shared\Types.xsd
c:\ant\apps\App1MetaData\schemas\hr\Account.xsd
3. Open a command prompt window and type the following
cd c:\ant
call setEnvironmentVars.bat
call ant -f build.soa.xml importMDS -Dtargetenv=<env>
Where <env> is your dev, test, or whatever environments you configured earlier.

Define the Custom Process List

Before using any of these Ant scripts that are related to code, you must create a CustomProcessList.txt file.

1. Create the c:\ant\CustomProcessList.txt file, using the following format:
<composite_name>,<partition>,<revision>,<default_composite>,<relative_directory_of_code>

For example, the file may look like this:
HelloWorld1,default,1.0,true,hrprojects\employees\HelloWorld1
HelloWorld2,default,1.0,true,hrprojects\employees\HelloWorld2
HelloWorld3,hello99,2.0,false,hrprojects\test\synchronize\HelloWorld3
This says that there are 3 composites to loop through; HelloWorld1, HelloWorld2, and HelloWorld3. If deployed, the first 2 will be deployed to the 'default' partition and a revision of '1.0' while the last one will be deployed to the 'hello99' partition with a revision of '2.0'. The last composite will not be set as the default composite, designated by the value of 'false'.
  
The directory path shown is relative to the %CODE_FOLDER% environment variable set earlier. For example, if %CODE_FOLDER% is set to c:\ant\code, then the three projects above should exist in the following local directories:
c:\ant\code\hrprojects\employees\HelloWorld1
c:\ant\code\hrprojects\employees\HelloWorld2
c:\ant\code\hrprojects\test\synchronize\HelloWorld3

Define the Custom MDS List

Before using any of the Ant targets that are related to the MDS, you must create a CustomMDSList.txt file.

1. Create the c:\ant\CustomMDSList.txt file, using the following format:
<app_name>,false

For example, the file may look like this:
App1MetaData,false
App2MetaData,false
If you run the MDS import script, it will import the following local directory to its relative MDS directory as follows:
c:\ant\apps\App1MetaData  -->  oramds:/apps/App1MetaData
c:\ant\apps\App2MetaData  -->  oramds:/apps/App2MetaData
For example, you may have a combination of XSDs, DVMs, and fault policies as shown: 
c:\ant\apps\App1MetaData\dvm\Currency.dvm
c:\ant\apps\App1MetaData\dvm\Country.dvm
c:\ant\apps\App1MetaData\config\fault-bindings.xml
c:\ant\apps\App1MetaData\config\fault-policies.xml
c:\ant\apps\App1MetaData\schemas\shared\Types.xsd
c:\ant\apps\App1MetaData\schemas\hr\Account.xsd
When you run the MDS import script, because the CustomMDSList.txt file is referencing the local c:\ant\apps\App1MetaData directory, all files under that local directory will be imported to the MDS.

Adding Additional Tokens

The detokenizeComposites target loops through all code in your CustomProcessList.txt file, and detokenizes your code. For example, if your code has the following string @SOAServer@, the command below will replace it with whatever value is specified in the soa-token-*.properties file. This allows you to not hardcode values in your code.

If you want to add additional token variables, say @SomeEndpoint@, you must do the following:

1. Add the new token to the soa-token-*.properties file. For example:
SomeEndpoint = http://dev.ipnweb.com:7777
2. Edit build.soa.xml and add the token in two separate targets (detokenizeComposites and tokenizeComposites):
<replacefilter token="@SomeEndpoint@" value="${SomeEndpoint}"/> 
<replacefilter token="${SomeEndpoint}" value="@SomeEndpoint@"/>

No comments:

Post a Comment

xslt padding with characters call template for left pad and right pad

  Could a call-template be written that took two parameters ?   a string, and a   number) return the string with empty spaces appended t...