Question & Answer
Question
I need help with creating JDBC provider and Data source at cluster scope using Jython commands
Answer
You can make use of Command Assistance in admin console to create this.
First create a JDBC Provider in the admin console and once you click Finish button, you will see Command Assistance in the right hand side. Click on "View administrative scripting command for last action" and it will display the Jython command to create a JDBC Provider.
The sample command looks like below:
AdminTask.createJDBCProvider('[-scope Cluster=test -databaseType DB2 -providerType "DB2 Universal JDBC Driver Provider" -implementationType "Connection pool data source" -name "DB2 Universal JDBC Driver Provider" -description "One-phase commit DB2 JCC provider that supports JDBC 3.0. Data sources that use this provider support only 1-phase commit processing, unless you use driver type 2 with the application server for z/OS. If you use the application server for z/OS, driver type 2 uses RRS and supports 2-phase commit processing." -classpath [${DB2UNIVERSAL_JDBC_DRIVER_PATH}/db2jcc.jar ${UNIVERSAL_JDBC_DRIVER_PATH}/db2jcc_license_cu.jar ${DB2UNIVERSAL_JDBC_DRIVER_PATH}/db2jcc_license_cisuz.jar ] -nativePath [${DB2UNIVERSAL_JDBC_DRIVER_NATIVEPATH} ] ]')
Then create a data source in the admin console and do the same as above i.e click on "View administrative scripting command for last action"..
The Sample command looks like below:
AdminTask.createDatasource('"DB2 Universal JDBC Driver Provider(cells/TestCell01/clusters/test|resources.xml#JDBCProvider_1572207613350)"', '[-name test -jndiName jdbc/test -dataStoreHelperClassName com.ibm.websphere.rsadapter.DB2UniversalDataStoreHelper -containerManagedPersistence true -componentManagedAuthenticationAlias -configureResourceProperties [[databaseName java.lang.String abcd] [driverType java.lang.Integer 4] [serverName java.lang.String abcd] [portNumber java.lang.Integer 50000]]]')
Now open command prompt and then navigate to:
AdminTask.createDatasource('"DB2 Universal JDBC Driver Provider(cells/TestCell01/clusters/test|resources.xml#JDBCProvider_1572207613350)"', '[-name test -jndiName jdbc/test -dataStoreHelperClassName com.ibm.websphere.rsadapter.DB2UniversalDataStoreHelper -containerManagedPersistence true -componentManagedAuthenticationAlias -configureResourceProperties [[databaseName java.lang.String abcd] [driverType java.lang.Integer 4] [serverName java.lang.String abcd] [portNumber java.lang.Integer 50000]]]')
Now open command prompt and then navigate to:
<WAS installation root>/AppSrv01/bin/
and run command wsadmin.bat -lang jython
Run above command Create JDBC Provider and then run save command: AdminConfig.save() and then run Create Data source command which will create JDBC Provider and Data source.
But this is not generic command since we are copying JDBCProvider ID hard coded in the createDataSource command (check above command in bold). So to make it generic you need to get this id dynamically. For that you need to make a change to above createDataSource command. The sample command looks like below:
AdminTask.createDatasource(AdminConfig.getid('/JDBCProvider:DB2 Universal JDBC Driver Provider/'), '[-name sample -jndiName jdbc/sample -dataStoreHelperClassName com.ibm.websphere.rsadapter.DB2UniversalDataStoreHelper -containerManagedPersistence true -componentManagedAuthenticationAlias -configureResourceProperties [[databaseName java.lang.String test] [driverType java.lang.Integer 4] [serverName java.lang.String 10.100.200.300] [portNumber java.lang.Integer 50000]]]')
AdminTask.createDatasource(AdminConfig.getid('/JDBCProvider:DB2 Universal JDBC Driver Provider/'), '[-name sample -jndiName jdbc/sample -dataStoreHelperClassName com.ibm.websphere.rsadapter.DB2UniversalDataStoreHelper -containerManagedPersistence true -componentManagedAuthenticationAlias -configureResourceProperties [[databaseName java.lang.String test] [driverType java.lang.Integer 4] [serverName java.lang.String 10.100.200.300] [portNumber java.lang.Integer 50000]]]')
After executing above command then run AdminConfig.save() command to save changes (after running this command only you see the newly created data source in the admin console). Also finally run the sync commands to reflect changes to the node/nodes.
Sample command looks like below:
Sync1 = AdminControl.completeObjectName('type=NodeSync,node=TestNode01,*')
AdminControl.invoke(Sync1, 'sync')
[{"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Product":{"code":"SSEQTP","label":"WebSphere Application Server"},"Component":"","Platform":[{"code":"PF002","label":"AIX"},{"code":"PF010","label":"HP-UX"},{"code":"PF043","label":"Red Hat"},{"code":"PF033","label":"Windows"}],"Version":"All Versions","Edition":"","Line of Business":{"code":"LOB45","label":"Automation"}}]
Was this topic helpful?
Document Information
Modified date:
30 October 2019
UID
ibm11099137