We will see creating and
configuring various resources in WebLogic Server using the WLST where we
used properties file data as an input to the resource configuration.
Here is an example in which we will see How to Configure WebLogic
DataSource using WLST?
In this sample we will use a properties file to avoid hard coding. This script will be same for various DataSource configuration just we need to change the Properties files entry to make a new DataSource.
Step :1) Create a file and copy the following python script.
#=======================================================================
#| Author : XXXXXXXX |
#| Date : 28/June/2013 |
#| Description : This will create the Data Sources, EIS Connection |
#| Factories and corresponding Configurations. |
#=======================================================================
from java.io import FileInputStream
from java.util import Properties
import sys
import os
# Load the properties file.
def loadProperties(fileName):
properties = Properties()
input = FileInputStream(fileName)
properties.load(input)
#input.close()
#result= {}
for entry in properties.entrySet():
print entry.key + ' = ' + entry.value
#result[entry.key] = entry.value
return properties
def deleteIgnoringExceptions(mbean):
try: delete(mbean)
except:
dumpStack()
pass
def startTransaction():
edit()
startEdit()
def endTransaction():
save()
activate(block="true")
properties = loadProperties(sys.argv[1])
domainName = properties.get('domainname')
adminURL= properties.get('adminurl')
adminUserName= properties.get('adminusername')
adminPassword= properties.get('adminpassword')
dsName= properties.get('datasourcename')
dsFileName= properties.get('datasourcefilename')
dsDatabaseName=properties.get('datasourcedatabasename')
datasourceTarget=properties.get('datasourcetarget')
dsJNDIName=properties.get('datasourcejndiname')
dsDriverName=properties.get('datasourcedriverclass')
dsURL=properties.get('datasourceurl')
dsUserName=properties.get('datasourceusername')
dsPassword=properties.get('datasourcepassword')
dsTestQuery=properties.get('datasourcetestquery')
oracleHome=properties.get('oracleHome')
connect(adminUserName, adminPassword, adminURL)
startTransaction()
cd('/JDBCSystemResources/')
deleteIgnoringExceptions(dsName)
endTransaction()
startTransaction()
print '*******************************************************'
print '* Starting to create the Data Source *'
print '*******************************************************'
cd('/')
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(dsURL)
cmo.setDriverName( dsDriverName )
cmo.setPassword(dsPassword)
cd('/JDBCSystemResources/' + dsName + '/JDBCResource/' + dsName + '/JDBCConnectionPoolParams/' + dsName )
cmo.setTestTableName(dsTestQuery)
cd('/JDBCSystemResources/' + dsName + '/JDBCResource/' + dsName + '/JDBCDriverParams/' + dsName + '/Properties/' + dsName )
cmo.createProperty('user')
cd('/JDBCSystemResources/' + dsName + '/JDBCResource/' + dsName + '/JDBCDriverParams/' + dsName + '/Properties/' + dsName + '/Properties/user')
cmo.setValue(dsUserName)
#cd('/JDBCSystemResources/' + dsName + '/JDBCResource/' + dsName + '/JDBCDriverParams/' + dsName + '/Properties/' + dsName )
#cmo.createProperty('databaseName')
#cd('/JDBCSystemResources/' + dsName + '/JDBCResource/' + dsName + '/JDBCDriverParams/' + dsName + '/Properties/' + dsName + '/Properties/databaseName')
#cmo.setValue(dsDatabaseName)
#cd('/JDBCSystemResources/' + dsName + '/JDBCResource/' + dsName + '/JDBCDataSourceParams/' + dsName )
#cmo.setGlobalTransactionsProtocol('OnePhaseCommit')
cd('/SystemResources/' + dsName )
set('Targets',jarray.array([ObjectName('com.bea:Name=' + datasourceTarget + ',Type=Server')], ObjectName))
endTransaction()
print 'Data source ' + dsName + ' configured'
print '*******************************************************'
print '* Data Source creation completed *'
print '*******************************************************'
#Connect
#appPath='/app/oracle/middleware/soa11g/soa/connectors/DbAdapter.rar'
#planPath='/app/oracle/middleware/soa11g/soa/connectors/DbAdapterPlanGenerated.xml'
appPath=oracleHome+'/soa/connectors/DbAdapter.rar'
planPath=oracleHome+'/soa/connectors/DbAdapterPlanGenerated.xml'
CFName=properties.get('connfactname')
dsName=dsJNDIName
appName='DbAdapter'
moduleOverrideName=appName+'.rar'
moduleDescriptorName='META-INF/weblogic-ra.xml'
print 'Starting the JCA changes'
def makeDeploymentPlanVariable(wlstPlan, name, value, xpath, origin='planbased'):
print 'inside makeDeploymentPlanVariable'
while wlstPlan.getVariableAssignment(name, moduleOverrideName, moduleDescriptorName):
print 'inside wlstPlan.getVariableAssignment'
wlstPlan.destroyVariableAssignment(name, moduleOverrideName, moduleDescriptorName)
while wlstPlan.getVariable(name):
print 'inside wlstPlan.getVariable'
wlstPlan.destroyVariable(name)
variableAssignment = wlstPlan.createVariableAssignment( name, moduleOverrideName, moduleDescriptorName )
variableAssignment.setXpath( xpath )
variableAssignment.setOrigin( origin )
wlstPlan.createVariable( name, value )
def main():
connect(adminUserName, adminPassword, adminURL)
try:
startTransaction()
#planPath = get('/AppDeployments/DbAdapter/PlanPath')
print '__ Using plan ' + planPath
myPlan=loadApplication(appPath, planPath)
print '___ BEGIN change plan'
# makeDeploymentPlanVariable(myPlan, 'ConnectionInsta CFName +'_JNDIName_abc123XXX','+ CFName', '/weblogic-connector/outbound-resource-adapter/connection-definition-group/[connection-factory-interface="javax.resource.cci.ConnectionFactory"]/connection-instance/[jndi-name="'+ CFName + '"]/jndi-name')
makeDeploymentPlanVariable(myPlan, 'ConnectionInstance_' + CFName +'_JNDIName_abc123XXX',CFName, '/weblogic-connector/outbound-resource-adapter/connection-definition-group/[connection-factory-interface="javax.resource.cci.ConnectionFactory"]/connection-instance/[jndi-name="'+ CFName + '"]/jndi-name')
makeDeploymentPlanVariable(myPlan, 'ConfigProperty_xADataSourceName_'+ dsName +'_abc123XXX',dsName, '/weblogic-connector/outbound-resource-adapter/connection-definition-group/[connection-factory-interface="javax.resource.cci.ConnectionFactory"]/connection-instance/[jndi-name="'+ CFName + '"]/connection-properties/properties/property/[name="xADataSourceName"]/value')
print '___ DONE change plan'
myPlan.save();
endTransaction()
cd('/AppDeployments/DbAdapter/Targets');
redeploy(appName, planPath,targets=cmo.getTargets());
print 'EIS Connection factory ' + CFName + 'using' + dsName + ' configured';
except:
#stopEdit('y')
print 'Datasource creation failed '
#traceback.format_tb(traceback_)
main()
Step :2) Save the file with .py extension (Ex:- CreateDataSource.py ).
Step :3) Create the properties file for providing required data source values as shown below and save it with .properties extension.
#===========================================================================
#| Author : XXXXXXXXX |
#| Date : 28/June/2013 |
#| Description : Propertie file for creating datasource and EIS DB Adapter |
#===========================================================================
# Domain settings
# Domain Can be find out on Weblogic Console -> DomainStructure
domainname=<SOA Domain Name>
# Give the Url for the Admin Server
adminurl=t3://<SOA Host Name>:7001
# Give Username of weblogic Admin server
adminusername=weblogic
# Give Password of weblogic Admin server
adminpassword=admin123
#datasource settings
datasourcename=ERPXXCXL
datasourcedatabasename=xxcxl
datasourcetarget=soa_server1
datasourcefilename= ERPXXCXL + '.xml'
datasourcejndiname= jdbc/ERPXXCXL
datasourcedriverclass=oracle.jdbc.xa.client.OracleXADataSource
# Give Connection string of EBS Database
datasourceurl=jdbc:oracle:thin:@<Host Name>:1521:<UserName>
# Give xxcxl as User name of EBS Database
datasourceusername=xxcxl
# Give corresponding password of xxcxl user
datasourcepassword=xxcxl
datasourcetestquery=SQL SELECT * FROM DUAL
#EIS Connection Factory settings
# Give the path of Oracle Home directory of SOA server
oracleHome=/u01/Middleware/Oracle_SOA1
connfactname=eis/DB/ERPXXCXL
Step :4) Open filezilla/winscp and copy the both files in server(EX :- /home/oracle).
Step :5) Open putty and Navigate to the web logic home(Ex:- $ORACLE_HOME/wlserver_10.3/server/bin ).
Step :6) Finally run the following command, it will create and configure data sources along with DB Adapter deployments.
In this sample we will use a properties file to avoid hard coding. This script will be same for various DataSource configuration just we need to change the Properties files entry to make a new DataSource.
Step :1) Create a file and copy the following python script.
#=======================================================================
#| Author : XXXXXXXX |
#| Date : 28/June/2013 |
#| Description : This will create the Data Sources, EIS Connection |
#| Factories and corresponding Configurations. |
#=======================================================================
from java.io import FileInputStream
from java.util import Properties
import sys
import os
# Load the properties file.
def loadProperties(fileName):
properties = Properties()
input = FileInputStream(fileName)
properties.load(input)
#input.close()
#result= {}
for entry in properties.entrySet():
print entry.key + ' = ' + entry.value
#result[entry.key] = entry.value
return properties
def deleteIgnoringExceptions(mbean):
try: delete(mbean)
except:
dumpStack()
pass
def startTransaction():
edit()
startEdit()
def endTransaction():
save()
activate(block="true")
properties = loadProperties(sys.argv[1])
domainName = properties.get('domainname')
adminURL= properties.get('adminurl')
adminUserName= properties.get('adminusername')
adminPassword= properties.get('adminpassword')
dsName= properties.get('datasourcename')
dsFileName= properties.get('datasourcefilename')
dsDatabaseName=properties.get('datasourcedatabasename')
datasourceTarget=properties.get('datasourcetarget')
dsJNDIName=properties.get('datasourcejndiname')
dsDriverName=properties.get('datasourcedriverclass')
dsURL=properties.get('datasourceurl')
dsUserName=properties.get('datasourceusername')
dsPassword=properties.get('datasourcepassword')
dsTestQuery=properties.get('datasourcetestquery')
oracleHome=properties.get('oracleHome')
connect(adminUserName, adminPassword, adminURL)
startTransaction()
cd('/JDBCSystemResources/')
deleteIgnoringExceptions(dsName)
endTransaction()
startTransaction()
print '*******************************************************'
print '* Starting to create the Data Source *'
print '*******************************************************'
cd('/')
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(dsURL)
cmo.setDriverName( dsDriverName )
cmo.setPassword(dsPassword)
cd('/JDBCSystemResources/' + dsName + '/JDBCResource/' + dsName + '/JDBCConnectionPoolParams/' + dsName )
cmo.setTestTableName(dsTestQuery)
cd('/JDBCSystemResources/' + dsName + '/JDBCResource/' + dsName + '/JDBCDriverParams/' + dsName + '/Properties/' + dsName )
cmo.createProperty('user')
cd('/JDBCSystemResources/' + dsName + '/JDBCResource/' + dsName + '/JDBCDriverParams/' + dsName + '/Properties/' + dsName + '/Properties/user')
cmo.setValue(dsUserName)
#cd('/JDBCSystemResources/' + dsName + '/JDBCResource/' + dsName + '/JDBCDriverParams/' + dsName + '/Properties/' + dsName )
#cmo.createProperty('databaseName')
#cd('/JDBCSystemResources/' + dsName + '/JDBCResource/' + dsName + '/JDBCDriverParams/' + dsName + '/Properties/' + dsName + '/Properties/databaseName')
#cmo.setValue(dsDatabaseName)
#cd('/JDBCSystemResources/' + dsName + '/JDBCResource/' + dsName + '/JDBCDataSourceParams/' + dsName )
#cmo.setGlobalTransactionsProtocol('OnePhaseCommit')
cd('/SystemResources/' + dsName )
set('Targets',jarray.array([ObjectName('com.bea:Name=' + datasourceTarget + ',Type=Server')], ObjectName))
endTransaction()
print 'Data source ' + dsName + ' configured'
print '*******************************************************'
print '* Data Source creation completed *'
print '*******************************************************'
#Connect
#appPath='/app/oracle/middleware/soa11g/soa/connectors/DbAdapter.rar'
#planPath='/app/oracle/middleware/soa11g/soa/connectors/DbAdapterPlanGenerated.xml'
appPath=oracleHome+'/soa/connectors/DbAdapter.rar'
planPath=oracleHome+'/soa/connectors/DbAdapterPlanGenerated.xml'
CFName=properties.get('connfactname')
dsName=dsJNDIName
appName='DbAdapter'
moduleOverrideName=appName+'.rar'
moduleDescriptorName='META-INF/weblogic-ra.xml'
print 'Starting the JCA changes'
def makeDeploymentPlanVariable(wlstPlan, name, value, xpath, origin='planbased'):
print 'inside makeDeploymentPlanVariable'
while wlstPlan.getVariableAssignment(name, moduleOverrideName, moduleDescriptorName):
print 'inside wlstPlan.getVariableAssignment'
wlstPlan.destroyVariableAssignment(name, moduleOverrideName, moduleDescriptorName)
while wlstPlan.getVariable(name):
print 'inside wlstPlan.getVariable'
wlstPlan.destroyVariable(name)
variableAssignment = wlstPlan.createVariableAssignment( name, moduleOverrideName, moduleDescriptorName )
variableAssignment.setXpath( xpath )
variableAssignment.setOrigin( origin )
wlstPlan.createVariable( name, value )
def main():
connect(adminUserName, adminPassword, adminURL)
try:
startTransaction()
#planPath = get('/AppDeployments/DbAdapter/PlanPath')
print '__ Using plan ' + planPath
myPlan=loadApplication(appPath, planPath)
print '___ BEGIN change plan'
# makeDeploymentPlanVariable(myPlan, 'ConnectionInsta CFName +'_JNDIName_abc123XXX','+ CFName', '/weblogic-connector/outbound-resource-adapter/connection-definition-group/[connection-factory-interface="javax.resource.cci.ConnectionFactory"]/connection-instance/[jndi-name="'+ CFName + '"]/jndi-name')
makeDeploymentPlanVariable(myPlan, 'ConnectionInstance_' + CFName +'_JNDIName_abc123XXX',CFName, '/weblogic-connector/outbound-resource-adapter/connection-definition-group/[connection-factory-interface="javax.resource.cci.ConnectionFactory"]/connection-instance/[jndi-name="'+ CFName + '"]/jndi-name')
makeDeploymentPlanVariable(myPlan, 'ConfigProperty_xADataSourceName_'+ dsName +'_abc123XXX',dsName, '/weblogic-connector/outbound-resource-adapter/connection-definition-group/[connection-factory-interface="javax.resource.cci.ConnectionFactory"]/connection-instance/[jndi-name="'+ CFName + '"]/connection-properties/properties/property/[name="xADataSourceName"]/value')
print '___ DONE change plan'
myPlan.save();
endTransaction()
cd('/AppDeployments/DbAdapter/Targets');
redeploy(appName, planPath,targets=cmo.getTargets());
print 'EIS Connection factory ' + CFName + 'using' + dsName + ' configured';
except:
#stopEdit('y')
print 'Datasource creation failed '
#traceback.format_tb(traceback_)
main()
Step :2) Save the file with .py extension (Ex:- CreateDataSource.py ).
Step :3) Create the properties file for providing required data source values as shown below and save it with .properties extension.
#===========================================================================
#| Author : XXXXXXXXX |
#| Date : 28/June/2013 |
#| Description : Propertie file for creating datasource and EIS DB Adapter |
#===========================================================================
# Domain settings
# Domain Can be find out on Weblogic Console -> DomainStructure
domainname=<SOA Domain Name>
# Give the Url for the Admin Server
adminurl=t3://<SOA Host Name>:7001
# Give Username of weblogic Admin server
adminusername=weblogic
# Give Password of weblogic Admin server
adminpassword=admin123
#datasource settings
datasourcename=ERPXXCXL
datasourcedatabasename=xxcxl
datasourcetarget=soa_server1
datasourcefilename= ERPXXCXL + '.xml'
datasourcejndiname= jdbc/ERPXXCXL
datasourcedriverclass=oracle.jdbc.xa.client.OracleXADataSource
# Give Connection string of EBS Database
datasourceurl=jdbc:oracle:thin:@<Host Name>:1521:<UserName>
# Give xxcxl as User name of EBS Database
datasourceusername=xxcxl
# Give corresponding password of xxcxl user
datasourcepassword=xxcxl
datasourcetestquery=SQL SELECT * FROM DUAL
#EIS Connection Factory settings
# Give the path of Oracle Home directory of SOA server
oracleHome=/u01/Middleware/Oracle_SOA1
connfactname=eis/DB/ERPXXCXL
Step :4) Open filezilla/winscp and copy the both files in server(EX :- /home/oracle).
Step :5) Open putty and Navigate to the web logic home(Ex:- $ORACLE_HOME/wlserver_10.3/server/bin ).
Step :6) Finally run the following command, it will create and configure data sources along with DB Adapter deployments.
./wlst.sh /home/oracle/CreateDataSource.py /home/oracle/erpxxcxl.properties
No comments:
Post a Comment