Data Source Creation
I want to create Data Source using Python Script.
My Server Details are,
Cluster Environment: 1 Admin Server and 2 Managed Server (wls_osb1 and wls_osb2)
Domain Name: soa_domain
Save below weblogic.properties file as weblogic.properties
#################################################################################
# admin server url
admin.url=t3://localhost:7001
#################################################################################
#Domain Name:
domainName=soa_domain
osbServer1=wls_osb1
osbServer2=wls_osb2
#Manage Server Name:
targetServer.1=wls_osb1
targetServer.2=wls_osb2
#Cluster Name:
osb_ClusterName=osb_cluster
migrateServerType=MigratableTarget
clusterServerType=Cluster
normalServerType=Server
#################################################################################
# Data Source Properties
#################################################################################
#Below Data Sources will be create
#Data Source Name For OFM: 1. jdbcOFMCrossRefDS
# 2. jdbcOFMAQDS_OFM
# 3. jdbcOFMDBDS_OFM
# 4. jdbcEventEngineDSOFM
# 5. jdbcExceptionOFMDS
#Data Source Name For OFMOI: 1. jdbcOFMAQDS_OFMOI
# 2. jdbcOFMDBDS_OFMOI
# 3. jdbcEventEngineDSOFMOI
# 4. jdbcExceptionOFMOIDS
#################################################################################
XA_DriverClassName=oracle.jdbc.xa.client.OracleXADataSource
nonXA_DriverClassName=oracle.jdbc.OracleDriver
total.DSName=9
#XA Data-source for all the cross reference
DSName.1=jdbcOFMCrossRefDS
DSjndiName.1=jdbcOFMCrossRefDS
dbURL.1=jdbc:oracle:thin:@localhost:1521:orcl1
DBUser.1=OFM_OFM
DBPassword.1=ofm_12744
maxCapacity.1=100
minCapacity.1=10
inactiveConnectionTimeoutSecs.1=3660
initialCap.1=10
connect_TIMEOUT_Value.1=30000
ONS_Node.1=ofm:10100,ofm:10108
ShrinkFrequencySeconds.1=300
ConnectionReserveTimeoutSeconds.1=60
ConnectionCreationRetryFrequencySeconds.1=10
StatementCacheSize.1=15
SecondsToTrustAnIdlePoolConnection.1=0
TestFrequencySeconds.1=600
XARetryDurationSec.1=300
XARetryIntervalSec.1=60
read_TIMEOUT_Value.1=300000
#XA Data-source for Error handling using OFM_OFM
DSName.2=jdbcExceptionOFMDS
DSjndiName.2=jdbcExceptionOFMDS
dbURL.2=jdbc:oracle:thin:@localhost:1521:orcl1
DBUser.2=OFM_OFM
DBPassword.2=ofm_12744
maxCapacity.2=100
minCapacity.2=10
inactiveConnectionTimeoutSecs.2=3660
initialCap.2=10
connect_TIMEOUT_Value.2=30000
ONS_Node.2=ofm:10100,ofm:10108
ShrinkFrequencySeconds.2=300
ConnectionReserveTimeoutSeconds.2=60
ConnectionCreationRetryFrequencySeconds.2=10
StatementCacheSize.2=15
SecondsToTrustAnIdlePoolConnection.2=0
TestFrequencySeconds.2=600
XARetryDurationSec.2=300
XARetryIntervalSec.2=60
read_TIMEOUT_Value.2=300000
#XA Data-source for AQ using OFM_OFMOI
DSName.3=jdbcOFMAQDS_OFMOI
DSjndiName.3=jdbcOFMAQDS_OFMOI
dbURL.3=jdbc:oracle:thin:@localhost:1521:orcl1
DBUser.3=OFM_OFMOI
DBPassword.3=ofm_12744
maxCapacity.3=100
minCapacity.3=10
inactiveConnectionTimeoutSecs.3=60
initialCap.3=10
connect_TIMEOUT_Value.3=30000
ONS_Node.3=ofm:10100,ofm:10108
ShrinkFrequencySeconds.3=300
ConnectionReserveTimeoutSeconds.3=60
ConnectionCreationRetryFrequencySeconds.3=10
StatementCacheSize.3=15
SecondsToTrustAnIdlePoolConnection.3=0
TestFrequencySeconds.3=600
XARetryDurationSec.3=300
XARetryIntervalSec.3=60
read_TIMEOUT_Value.3=300000
#XA Data-source for AQ using OFM_OFM
DSName.4=jdbcOFMAQDS_OFM
DSjndiName.4=jdbcOFMAQDS_OFM
dbURL.4=jdbc:oracle:thin:@localhost:1521:orcl1
DBUser.4=OFM_OFM
DBPassword.4=ofm_12744
maxCapacity.4=100
minCapacity.4=10
inactiveConnectionTimeoutSecs.4=60
initialCap.4=10
connect_TIMEOUT_Value.4=30000
ONS_Node.4=ofm:10100,ofm:10108
ShrinkFrequencySeconds.4=300
ConnectionReserveTimeoutSeconds.4=60
ConnectionCreationRetryFrequencySeconds.4=10
StatementCacheSize.4=15
SecondsToTrustAnIdlePoolConnection.4=0
TestFrequencySeconds.4=600
XARetryDurationSec.4=300
XARetryIntervalSec.4=60
read_TIMEOUT_Value.4=300000
#XA Data-source for DB using OFM_OFMOI
DSName.5=jdbcOFMDBDS_OFMOI
DSjndiName.5=jdbcOFMDBDS_OFMOI
dbURL.5=jdbc:oracle:thin:@localhost:1521:orcl1
DBUser.5=OFM_OFMOI
DBPassword.5=ofm_12744
maxCapacity.5=100
minCapacity.5=10
inactiveConnectionTimeoutSecs.5=60
initialCap.5=10
connect_TIMEOUT_Value.5=30000
ONS_Node.5=ofm:10100,ofm:10108
ShrinkFrequencySeconds.5=300
ConnectionReserveTimeoutSeconds.5=60
ConnectionCreationRetryFrequencySeconds.5=10
StatementCacheSize.5=15
SecondsToTrustAnIdlePoolConnection.5=0
TestFrequencySeconds.5=600
XARetryDurationSec.5=300
XARetryIntervalSec.5=60
read_TIMEOUT_Value.5=300000
#XA Data-source for DB using OFM_OFM
DSName.6=jdbcOFMDBDS_OFM
DSjndiName.6=jdbcOFMDBDS_OFM
dbURL.6=jdbc:oracle:thin:@localhost:1521:orcl1
DBUser.6=OFM_OFM
DBPassword.6=ofm_12744
maxCapacity.6=100
minCapacity.6=10
inactiveConnectionTimeoutSecs.6=60
initialCap.6=10
connect_TIMEOUT_Value.6=30000
ONS_Node.6=ofm:10100,ofm:10108
ShrinkFrequencySeconds.6=300
ConnectionReserveTimeoutSeconds.6=60
ConnectionCreationRetryFrequencySeconds.6=10
StatementCacheSize.6=15
SecondsToTrustAnIdlePoolConnection.6=0
TestFrequencySeconds.6=600
XARetryDurationSec.6=300
XARetryIntervalSec.6=60
read_TIMEOUT_Value.6=300000
#XA Data-source for EventEngine using OFM_tracker_OFMOI
DSName.7=jdbcEventEngineDSOFMOI
DSjndiName.7=jdbcEventEngineDSOFMOI
dbURL.7=jdbc:oracle:thin:@localhost:1521:orcl1
DBUser.7=OFM_tracker_OFMOI
DBPassword.7=ofmtrack_12744
maxCapacity.7=100
minCapacity.7=10
inactiveConnectionTimeoutSecs.7=60
initialCap.7=10
connect_TIMEOUT_Value.7=30000
ONS_Node.7=ofm:10100,ofm:10108
ShrinkFrequencySeconds.7=300
ConnectionReserveTimeoutSeconds.7=60
ConnectionCreationRetryFrequencySeconds.7=10
StatementCacheSize.7=15
SecondsToTrustAnIdlePoolConnection.7=0
TestFrequencySeconds.7=600
XARetryDurationSec.7=300
XARetryIntervalSec.7=60
read_TIMEOUT_Value.7=300000
#XA Data-source for EventEngine using OFM_tracker_OFM
DSName.8=jdbcEventEngineDSOFM
DSjndiName.8=jdbcEventEngineDSOFM
dbURL.8=jdbc:oracle:thin:@localhost:1521:orcl1
DBUser.8=OFM_tracker_OFM
DBPassword.8=ofmtrack_12744
maxCapacity.8=100
minCapacity.8=10
inactiveConnectionTimeoutSecs.8=60
initialCap.8=10
connect_TIMEOUT_Value.8=30000
ONS_Node.8=ofm:10100,ofm:10108
ShrinkFrequencySeconds.8=300
ConnectionReserveTimeoutSeconds.8=60
ConnectionCreationRetryFrequencySeconds.8=10
StatementCacheSize.8=15
SecondsToTrustAnIdlePoolConnection.8=0
TestFrequencySeconds.8=600
XARetryDurationSec.8=300
XARetryIntervalSec.8=60
read_TIMEOUT_Value.8=300000
#XA Data-source for Error handling using OFM_OFMOI
DSName.9=jdbcExceptionOFMOIDS
DSjndiName.9=jdbcExceptionOFMOIDS
dbURL.9=jdbc:oracle:thin:@localhost:1521:orcl1
DBUser.9=OFM_OFMOI
DBPassword.9=ofm_12744
maxCapacity.9=100
minCapacity.9=10
inactiveConnectionTimeoutSecs.9=60
initialCap.9=10
connect_TIMEOUT_Value.9=30000
ONS_Node.9=ofm:10100,ofm:10108
ShrinkFrequencySeconds.9=300
ConnectionReserveTimeoutSeconds.9=60
ConnectionCreationRetryFrequencySeconds.9=10
StatementCacheSize.9=15
SecondsToTrustAnIdlePoolConnection.9=0
TestFrequencySeconds.9=600
XARetryDurationSec.9=300
XARetryIntervalSec.9=60
read_TIMEOUT_Value.9=300000
#################################################################################
Now, below python script you have to save as create_XA_DataSource.py
#################################################################################
#!/usr/bin/python
from java.io import FileInputStream
import time
propInputStream= FileInputStream('weblogic.properties')
configProps = Properties()
configProps.load(propInputStream)
adminURL= configProps.get('admin.url')
# Enter username and password
adminUserName= ''
adminPassword= ''
Target_Cluster=configProps.get('osb_ClusterName')
Server_type_Cluster=configProps.get('clusterServerType')
total_data_source_to_create=configProps.get('total.DSName')
db_XA_Driver=configProps.get('XA_DriverClassName')
connect(adminUserName, adminPassword, adminURL)
edit()
startEdit()
try:
#################################################################################
#For Datasource
#################################################################################
i=1
while (i <= int(total_data_source_to_create)):
try:
cd('/')
########################Declaration#######################
dsName = configProps.get('DSName.'+ str(i))
dsJNDIName = configProps.get('DSjndiName.'+ str(i))
dbUrl = configProps.get('dbURL.'+ str(i))
dbUser = configProps.get('DBUser.'+ str(i))
dbPassword = configProps.get('DBPassword.'+ str(i))
MxCap = configProps.get('maxCapacity.'+ str(i))
MinCap = configProps.get('minCapacity.'+ str(i))
inactiveConnectionTimeoutSeconds = configProps.get('inactiveConnectionTimeoutSecs.'+ str(i))
initialCapacity = configProps.get('initialCap.'+ str(i))
CONNECT_TIMEOUT_Value = configProps.get('connect_TIMEOUT_Value.'+ str(i))
READ_TIMEOUT_Value = configProps.get('read_TIMEOUT_Value.'+ str(i))
ONS_Nodes=configProps.get('ONS_Node.'+ str(i))
shrinkFrequencySecs=configProps.get('ShrinkFrequencySeconds.'+ str(i))
ConnReserveTimeout=configProps.get('ConnectionReserveTimeoutSeconds.'+ str(i))
ConnCreationRetryFrequency=configProps.get('ConnectionCreationRetryFrequencySeconds.'+ str(i))
StmtCacheSize=configProps.get('StatementCacheSize.'+ str(i))
SecToTrustAnIdlePoolConn=configProps.get('SecondsToTrustAnIdlePoolConnection.'+ str(i))
TestFrequencySec=configProps.get('TestFrequencySeconds.'+ str(i))
XaRetryDurationSec=configProps.get('XARetryDurationSec.'+ str(i))
XaRetryIntervalSec=configProps.get('XARetryIntervalSec.'+ str(i))
########################Declaration#######################
cmo.createJDBCSystemResource(dsName)
cd('/JDBCSystemResources/'+ dsName +'/JDBCResource/'+ dsName)
cmo.setName(dsName)
cd('/JDBCSystemResources/'+ dsName +'/JDBCResource/'+ dsName +'/JDBCDataSourceParams/'+ dsName)
set('JNDINames',jarray.array([String(dsJNDIName)], String))
cd('/JDBCSystemResources/'+ dsName +'/JDBCResource/'+ dsName +'/JDBCDriverParams/'+ dsName)
cmo.setUrl(dbUrl)
cmo.setDriverName(db_XA_Driver)
cmo.setPassword(dbPassword)
cd('/JDBCSystemResources/'+ dsName +'/JDBCResource/'+ dsName +'/JDBCConnectionPoolParams/'+ dsName)
cmo.setTestTableName('SQL SELECT 1 FROM DUAL\r\n\r\n')
set('MaxCapacity',MxCap)
set('MinCapacity',MinCap)
set('InactiveConnectionTimeoutSeconds',inactiveConnectionTimeoutSeconds)
cmo.setTestConnectionsOnReserve(true)
set('InitialCapacity',initialCapacity)
set('ShrinkFrequencySeconds',shrinkFrequencySecs)
set('ConnectionReserveTimeoutSeconds',ConnReserveTimeout)
set('ConnectionCreationRetryFrequencySeconds',ConnCreationRetryFrequency)
set('StatementCacheSize',StmtCacheSize)
set('SecondsToTrustAnIdlePoolConnection',SecToTrustAnIdlePoolConn)
set('TestFrequencySeconds',TestFrequencySec)
cd('/JDBCSystemResources/'+ dsName +'/JDBCResource/'+ dsName +'/JDBCDriverParams/'+ dsName +'/Properties/'+ dsName)
cmo.createProperty('user')
cmo.createProperty('oracle.net.CONNECT_TIMEOUT')
cmo.createProperty('oracle.jdbc.ReadTimeout')
cd('/JDBCSystemResources/'+ dsName +'/JDBCResource/'+ dsName +'/JDBCDriverParams/'+ dsName +'/Properties/'+ dsName +'/Properties/user')
cmo.setValue(dbUser)
cd('/JDBCSystemResources/'+ dsName +'/JDBCResource/'+ dsName +'/JDBCDriverParams/'+ dsName +'/Properties/'+ dsName +'/Properties/oracle.net.CONNECT_TIMEOUT')
set('Value',CONNECT_TIMEOUT_Value)
cd('/JDBCSystemResources/'+ dsName +'/JDBCResource/'+ dsName +'/JDBCDriverParams/'+ dsName +'/Properties/'+ dsName +'/Properties/oracle.jdbc.ReadTimeout')
set('Value',READ_TIMEOUT_Value)
cd('/JDBCSystemResources/'+ dsName +'/JDBCResource/'+ dsName +'/JDBCDataSourceParams/'+ dsName)
cmo.setGlobalTransactionsProtocol('TwoPhaseCommit')
cd('/SystemResources/'+ dsName)
set('Targets',jarray.array([ObjectName('com.bea:Name='+Target_Cluster+',Type='+Server_type_Cluster)], ObjectName))
###########################ONS_Node############################################
cd('/JDBCSystemResources/'+ dsName +'/JDBCResource/'+ dsName +'/JDBCOracleParams/'+ dsName)
cmo.setFanEnabled(true)
set('OnsNodeList',ONS_Nodes)
############################Transaction############################################
cd('/JDBCSystemResources/'+ dsName +'/JDBCResource/'+ dsName +'/JDBCXAParams/'+ dsName)
cmo.setXaSetTransactionTimeout(true)
set('XaRetryDurationSeconds',XaRetryDurationSec)
set('XaRetryIntervalSeconds',XaRetryIntervalSec)
cmo.setXaEndOnlyOnce(true)
cmo.setRecoverOnlyOnce(true)
###############################Transaction###################################
print 'Datasource: "',dsName,'" has been created Successfully'
except:
i = i + 1
#################################################################################
except: # catch *all* exceptions
print('--> something went wrong, bailing out', sys.exc_info()[0])
stopEdit('y')
raise SystemExit
save()
activate()
#################################################################################
Procedure to run above python script,
Step1: Copy your weblogic.properties and create_XA_DataSource.py
in /u01/Middleware/wlserver_10.3/common/bin location. Where wlst.sh or wlst.cmd present
Step2: Run ./wlst.sh (if you install middleware in UNIX) or wlst.cmd (if you install middleware in
windows)
Step 3: When Username and Password asked that time you have to pass weblogic console username and password.
No comments:
Post a Comment