Friday, June 28, 2013

Configuring Oracle SOA TLOGS JDBC Persistence Store using WLST Offline

In this post, we will look at configuring Oracle SOA to use TLog JDBC persistent stores using WLST (offline).

First, some info on TLogs. Weblogic Server (WLS) holds records of the state of in-flight transactions that are marked to be committed, in a 'TLOG' (Transaction Log) persistent store. The persistent store can either be files on a file-system or a table in database. When an instance is restarted, the TLog files are used to perform the second step of a two-phase commit on a transaction that was in progress.

So, why is this persistent-store configuration important? Configuring a WLS TLOG store to persist transaction logs to a database provides the following benefits (covered in the WLS documentation):
  • Leverages replication and High Availability characteristics of the underlying database.
  • Simplifies disaster recovery by allowing the easy synchronization of the state of the database and TLOGs.
  • Improved Transaction Recovery service migration as the transaction logs to do not need to be migrated (copied) to a new location.
Now onto the sample WLST OFFLINE python script to see how the persistent store configuration can be accomplished. At a high level, the SOA TLOG configuration script enables JDBC Persistent Store for each Weblogic SOA managed server that belongs to the SOA Cluster. The script was verified in a 11g SOA PS6 env and will give you a general idea on what commands need to be executed.

# This script must be executed in WLST OFFLINE mode. Restart the ADMIN SERVER
# post script execution for the changes to take effect.
#-------------------------------------------------------------------------------
# Purpose: Python Script to configure SOA TLogs to use JDBC Persistent Store
#
# Usage : config-soa-tlogs-jdbcstore.py <soa_domain_homepath>
#-----------------------------------------------------------------------------
import sys
#=======================================================================
# Function to get SOA servers list from SOA cluster
#=======================================================================
def getClusterServers(soaCluster):
print ' Fetch SOA servers in cluster '+soaCluster
soaServerList = []
servers = ls('/Server',returnMap='true')
for srvr in servers :
cd('/Server/'+srvr)
clst = "%s" % get('Cluster')
if (clst.find("Name="+soaCluster+", Type=Cluster")>-1):
print "SOA SERVER: "+ srvr
soaServerList.append(srvr)
return soaServerList
#=======================================================================
# Function to configure SOA TLOG jdbc persistent store
#=======================================================================
def configureSOATlogJDBCStore (soaServerList):
print 'START Configuring SOA TLog JDBC Persistent Store'
try:
## You can get the schema information for <dSName> say 'SOALocalTxDataSource'
## by navigating the mbean tree '/JDBCSystemResources/'+<dSName>+'/JdbcResource/'+<dSName>+'/JDBCDriverParams/
## user Properties
## schemaPrefix = getDSSchemaPrefix ('SOALocalTxDataSource')
schemaPrefix = "FMW_SOAINFRA"
for soaServer in soaServerList:
setSOATlogJDBCStoreAttributes (soaServer, schemaPrefix)
except:
raise
#=======================================================================
# Function to configure SOA TLOG jdbc persistent store properties
# In this example, 'SOALocalTxDataSource' is used. Identify the DataSource
# appropriate for your server transactions
#=======================================================================
def setSOATlogJDBCStoreAttributes (serverName, schemaPrefix):
print 'UPDATE TLog JDBC Persistent Store properties for server '+serverName
try:
cd ('/')
cd ('/Servers/'+serverName)
## Create TransactionLog JDBC Store
create(serverName,'TransactionLogJDBCStore')
cd ('TransactionLogJDBCStore/'+serverName)
set('DataSource','SOALocalTxDataSource')
## for schema PrefixName 'FMW_SOAINFRA' the resulting TLogs table will be created
## in the FMW_SOAINFRA schema, and will be named FMW_SOAINFRA.TLOG_soa_server1_WLStore .
print 'Using TLogs WLStore prefixName '+schemaPrefix+'.TLOG_'+serverName+'_'
set('PrefixName',schemaPrefix+'.TLOG_'+serverName+'_')
set('Enabled','true')
except Exception, detail:
raise Exception ('Exception setting SOA Tlog JDBC Store Attributes')
#
# Main Starts Here
#
soaServerList = ""
# connect to WLS Admin Server
try:
readDomain(wlsDomainHome)
print '***** Read Domain: %s' % wlsDomainHome
except :
print 'XXXXX Could not Read Domain: %s' % wlsDomainHome
exit()
print '######## START SOA TLOG JDBC STORE CONFIGURATION ########'
try:
## Find SOA Cluster or pass the configured SOA cluster name
soaClusterName = "SOACluster"
## Fetch list of SOA Servers configured in SOA Cluster
soaServerList = getClusterServers (soaClusterName)
## Configure Tlog JDBC persistent store for each SOA server
configureSOATlogJDBCStore (soaServerList)
cd ('/')
updateDomain()
closeDomain()
except Exception, ex:
print 'FINAL exception:', ex
dumpStack ()
raise
print '######## SOA TLOG JDBC STORE CONFIGURATION COMPLETE ########'
exit()