8i | 9i | 10g | 11g | 12c | 13c | 18c | 19c | 21c | 23c | Misc | PL/SQL | SQL | RAC | WebLogic | Linux
Create a Data Source Using WebLogic Scripting Tool (WLST)
WebLogic Scripting Tool (WLST) provides a command line scripting interface to manage WebLogic Server instances and domains. This article gives an example of creating a data source in an existing domain using WLST. You will need to adjust the values in the properties file and may wish to alter the script to suit your needs.
The easiest way to generate WLST scripts is to use the "Record" functionality in the Administration Console. The WLST in this article was generated in that way, then amended to replace hard-coded values with parameters.
Script
Create a file called "create_data_source.py" with the following contents.
#!/usr/bin/python # Author : Tim Hall # Save Script as : create_data_source.py import time import getopt import sys import re # Get location of the properties file. properties = '' try: opts, args = getopt.getopt(sys.argv[1:],"p:h::",["properies="]) except getopt.GetoptError: print 'set_datasource.py -p <path-to-properties-file>' sys.exit(2) for opt, arg in opts: if opt == '-h': print 'set_datasource.py -p <path-to-properties-file>' sys.exit() elif opt in ("-p", "--properties"): properties = arg print 'properties=', properties # Load the properties from the properties file. from java.io import FileInputStream propInputStream = FileInputStream(properties) configProps = Properties() configProps.load(propInputStream) # Set all variables from values in properties file. adminUsername=configProps.get("admin.username") adminPassword=configProps.get("admin.password") adminURL=configProps.get("admin.url") dsName=configProps.get("ds.name") dsJNDIName=configProps.get("ds.jndi.name") dsURL=configProps.get("ds.url") dsDriver=configProps.get("ds.driver") dsUsername=configProps.get("ds.username") dsPassword=configProps.get("ds.password") dsTargetType=configProps.get("ds.target.type") dsTargetName=configProps.get("ds.target.name") # Display the variable values. print 'adminUsername=', adminUsername print 'adminPassword=', adminPassword print 'adminURL=', adminURL print 'dsName=', dsName print 'dsJNDIName=', dsJNDIName print 'dsURL=', dsURL print 'dsDriver=', dsDriver print 'dsUsername=', dsUsername print 'dsPassword=', dsPassword print 'dsTargetType=', dsTargetType print 'dsTargetName=', dsTargetName # Connect to the AdminServer. connect(adminUsername, adminPassword, adminURL) edit() startEdit() # Create data source. 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(dsDriver) set('Password', dsPassword) cd('/JDBCSystemResources/' + dsName + '/JDBCResource/' + dsName + '/JDBCConnectionPoolParams/' + dsName) cmo.setTestTableName('SQL SELECT 1 FROM DUAL\r\n\r\n') 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 + '/JDBCDataSourceParams/' + dsName) cmo.setGlobalTransactionsProtocol('TwoPhaseCommit') cd('/SystemResources/' + dsName) set('Targets',jarray.array([ObjectName('com.bea:Name=' + dsTargetName + ',Type=' + dsTargetType)], ObjectName)) save() activate() disconnect() exit()
Properties
Create a file called "myDomain-ds.properties" with the following contents.
# AdminServer connection details. admin.username=weblogic admin.password=Password1 admin.url=t3://ol6.localdomain:7001 ds.name=MYDS ds.jndi.name=jdbc/MYDS ds.url=jdbc:oracle:thin:@ol7-121:1521/pdb1 ds.driver=oracle.jdbc.xa.client.OracleXADataSource ds.username=scott ds.password=tiger ds.target.type=Cluster ds.target.name=myCluster_1
Run It
Create the data source using the following commands.
# Set environment. export MW_HOME=/u01/app/oracle/middleware export WLS_HOME=$MW_HOME/wlserver_10.3 export WL_HOME=$WLS_HOME export JAVA_HOME=/u01/app/oracle/jdk1.7.0_79 export PATH=$JAVA_HOME/bin:$PATH export DOMAIN_HOME=/u01/app/oracle/config/domains/myDomain . $DOMAIN_HOME/bin/setDomainEnv.sh # Create the data source. java weblogic.WLST create_data_source.py -p myDomain-ds.properties
For more information see:
Hope this helps. Regards Tim...