← All posts

Multi Data Source using WLST

Pool your data sources for failover, scripted in minutes

Unni Pillai
Unni Pillai

A multi data source can be thought of as a pool of data sources. Multi data sources are best used for failover or load balancing between nodes of a highly available database system, such as redundant databases or Oracle Real Application Clusters (RAC).

Note that multi data sources do not provide any synchronization between databases. It is assumed that database synchronization is handled properly outside of WebLogic Server so that data integrity is maintained.

All data sources used by a multi data source to satisfy connection requests must be deployed on the same servers and clusters as the multi data source. A multi data source always uses a data source deployed on the same server to satisfy connection requests. Multi data sources do not route connection requests to other servers in a cluster or in a domain.

This script creates a Multi Datasource (MDS1) with two DataSources (DS1 and DS2) and deploys it to a server ‘AdminServer’.

Written by Unni on Mon 2 Mar 13:48 download

  1. # File name: MDS-Create.py

  2. # This python program would create a MultiDataSource - ‘MDS1’

  3. # and adds two datasources -‘DS1’ and ‘DS2’

  4. # and targets its to a Server - ‘AdminServer’

  5. # Please change the code as per your environment and needs

  6. connect(‘weblogic’,‘weblogic’,‘t3://localhost:7001’)

  7. edit()

  8. startEdit()

  9. cd(’/’)

  10. # creates a MultiDataSource named ‘MDS1’

  11. cmo.createJDBCSystemResource(‘MDS1’)

  12. cd(‘/JDBCSystemResources/MDS1/JDBCResource/MDS1’)

  13. cmo.setName(‘MDS1’)

  14. cd(‘/JDBCSystemResources/MDS1/JDBCResource/MDS1/JDBCDataSourceParams/MDS1’)

  15. # sets the JNDI name of the multi datasource to ‘MDS1’

  16. set(‘JNDINames’,jarray.array([String(‘MDS1’)], String))

  17. # sets the algorithm type to failover

  18. # Refer this link for valid values

  19. # http://edocs.bea.com/wls/docs100/wlsmbeanref/mbeans/JDBCDataSourceParamsBean.html#AlgorithmType

  20. cmo.setAlgorithmType(‘Failover’)

  21. # IMPORTANT -> Adds two datasources ‘DS1’ and ‘DS2’ to the multi datasource

  22. cmo.setDataSourceList(‘DS1,DS2’)

  23. cd(‘/JDBCSystemResources/MDS1’)

  24. # targets the MDS Server - ‘AdminServer’

  25. set(‘Targets’,jarray.array([ObjectName(‘com.bea:Name=AdminServer,Type=Server’)], ObjectName))

  26. activate()

  27. print(‘Exiting…’)

  28. exit()

  29. # Code written by:

  30. # Unnikrishnan Pillai

Hope this helps :)

Unni

unni@unnikrishnanpillai.tk