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’.
# File name: MDS-Create.py
# This python program would create a MultiDataSource - 'MDS1'
# and adds two datasources -'DS1' and 'DS2'
# and targets its to a Server - 'AdminServer'
# Please change the code as per your environment and needs
connect('weblogic','weblogic','t3://localhost:7001')
edit()
startEdit()
cd('/')
# creates a MultiDataSource named ‘MDS1’
cmo.createJDBCSystemResource('MDS1')
cd('/JDBCSystemResources/MDS1/JDBCResource/MDS1')
cmo.setName('MDS1')
cd('/JDBCSystemResources/MDS1/JDBCResource/MDS1/JDBCDataSourceParams/MDS1')
# sets the JNDI name of the multi datasource to 'MDS1'
set('JNDINames',jarray.array([String('MDS1')], String))
# sets the algorithm type to failover
# Refer this link for valid values
# http://edocs.bea.com/wls/docs100/wlsmbeanref/mbeans/JDBCDataSourceParamsBean.html#AlgorithmType
cmo.setAlgorithmType('Failover')
# IMPORTANT -> Adds two datasources 'DS1' and 'DS2' to the multi datasource
cmo.setDataSourceList('DS1,DS2')
cd('/JDBCSystemResources/MDS1')
# targets the MDS Server - 'AdminServer'
set('Targets',jarray.array([ObjectName('com.bea:Name=AdminServer,Type=Server')], ObjectName))
activate()
print('Exiting...')
exit()
# Code written by:
# Unnikrishnan Pillai
Cheers:)
Unni