Tuesday 18 November 2014

Create WebLogic 12C Datasource using WLST Scripting Tool


          Creating and configuring various resources in WebLogic Server using WLST tool, where we used properties file data as an input to the resource configuration. Here is an example in which we can see How to Configure WebLogic DataSource using WLST tool
In bellow sample, use a properties file to avoid hard coding. This script will be same for various DataSource configuration and need to change the Properties files entry to make a new DataSource.
Step1). Create a Directory (Based on space availability) in your file system:
”C:WLST_DS_Creation” and place a properties file like below in this directory with name “Datasource.properties”
Datasource.properties:
Location of Properties:- C:\Users\krushnavenus\Desktop\Datasource\datasource.properties
 




Datasource.py:
 Step2). Create Datasource in different directory by following WLST script
Create “Datasource.py”:
Location of Datasource.py:- C:\Users\krushnavenus\Desktop\Datasource\datasource.py

# ###############     Connecting to Start     #################################
def connectAdmin() :
 try:
  connect(CONUSR,CONPWD, CONURL)
  print('Successfully connected')
 except:
  print 'Unable to find admin server...'
  exit()
################### Configuring Connection Pool #############################
def connPool(DSnam) :
 DRVPARM='/JDBCSystemResources/'+DSnam+'/JDBCResource/'+DSnam+'/JDBCDriverParams/'+DSnam
 cd(DRVPARM)
 set('Url',DBURL)
 set('DriverName',DBDRV)
 set('Password',DBPASS)
 cd(DRVPARM+'/Properties/'+DSnam)
 cmo.createProperty('user')
 cd(DRVPARM+'/Properties/'+DSnam+'/Properties/user')
 set('Value',DBUSR)

############         Creating Data source    ###############################
def createDS() :
 print('Naming the datasource')
 DSnam = DSName
 cmo.createJDBCSystemResource(DSnam)
 RESOURCE='/JDBCSystemResources/'+DSnam+'/JDBCResource/'+DSnam
 cd(RESOURCE)
 set('Name',DSnam)

 #Setting JNDI name
 cd(RESOURCE+'/JDBCDataSourceParams/'+DSnam)
 print RESOURCE+'/JDBCDataSourceParams/'+DSnam
 set('JNDINames',jarray.array([String(JNDIName)], String))

 connPool(DSnam)

 #Set Connection Pool specific parameters
 cd(RESOURCE+'/JDBCConnectionPoolParams/'+DSnam)
 cmo.setTestConnectionsOnReserve(true)
 cmo.setTestTableName('SQL SELECT 1 FROM DUAL')
 cmo.setConnectionReserveTimeoutSeconds(25)
 cmo.setMaxCapacity(15)
 cmo.setConnectionReserveTimeoutSeconds(10)
 cmo.setTestFrequencySeconds(120)

 cd(RESOURCE+'/JDBCDataSourceParams/'+DSnam)
 cmo.setGlobalTransactionsProtocol('TwoPhaseCommit')
 cd('/JDBCSystemResources/'+DSnam)

 # targets the DS to Servers(Cluster or Server)
 #targetType=raw_input('Target to (C)luster or (S)erver: ')
 #if targetType in ('C','c') :
 if targetType == 'true':
  #clstrNam=raw_input('Cluster Name: ')
  set('Targets',jarray.array([ObjectName('com.bea:Name='+clstrNam+',Type=Cluster')], ObjectName))
 else:
  #servr=raw_input('Server Name: ')
  set('Targets',jarray.array([ObjectName('com.bea:Name='+servr+',Type=Server')], ObjectName))

###############     Main Script   #####################################
if __name__== "main":
 print('This will enable you to create or update a Datasource')
 connectAdmin()
 edit()
 startEdit()
 # Create a new JDBC resource)
 cd('/')
 createDS()
 save()
 activate()
 dumpStack()
 disconnect()
####################################



execution command:-
syntax:
$MW_HOME/$WL_HOME/common/bin/wlst.sh –loadProperties datasource.properties datasource.py location
Execution command:-
D:\u02\app\Oracle\Middleware\Oracle_Home\wlserver\common\bin>wlst.cmd -loadProperties C:\Users\krushnavenus\Desktop\Datasource\datasource.propertiesC:\Users\krushnavenus\Desktop\Datasource\datasource.py


OUT PUT OF DATASOURCES:-
A JDBC data source is an object bound to the JNDI tree that provides database connectivity through a pool of JDBC connections. Applications can look up a data source on the JNDI tree and then borrow a database connection from a data source.
This Screen shot summarizes the JDBC data source objects that have been created in this domain.




No comments:

Post a Comment