How to create WebLogic Server datasource & add the datasource to my Cluster: WLST

Creating the Python Script createmydatasource.py:

# set variables
# AdminServer URL:
admurl = ‚t3://myhost:7001‘
# WebLogic Admin User:
username = ‚weblogic‘
# WebLogic Admin User Password:
passwd = ‚welcome1‘
# Datasource Name
datasourcename = ‚mydatasource‘
# JNDI Patch:
jndiname = ‚/jdbc/mydatasource‘
# CLuster Name
clustername = ‚mycluster‘
# Connection Pool Settings:
initialcap = 5
maxcap = 5
mincap = 5


cachetype = ‚LRU‘
cachesize = 30
testreserve = true
testfreq = 240
trustidle = 60
shrink = 300
# JDBC Driver Settings:
drivername = ‚oracle.jdbc.xa.client.OracleXADataSource‘
# Database Connectionstring
jdbcurl = ‚jdbc:oracle:thin:@mydbhost:1521:database‘
# Database User Informations
dbuser = ‚mydbuser‘
dbpassword = ‚welcome1′
testtable=’SQL SELECT 1 FROM DUAL‘

# Connect to Admin Server
connect(username, passwd, admurl)

# Lock and Edit:
edit()
startEdit()

# Which MS Servers are in my cluster?
cd(‚/Clusters‘)
cd(clustername)
target = cmo

cd(‚/‘)

# Create data source
jdbcresource = create(datasourcename, ‚JDBCSystemResource‘)
theresource = jdbcresource.getJDBCResource()
theresource.setName(datasourcename)

# Configure JNDI
# Set JNDI name
jdbcresourceparams = theresource.getJDBCDataSourceParams()
jdbcresourceparams.setJNDINames([jndiname])
jdbcresourceparams.setGlobalTransactionsProtocol(‚TwoPhaseCommit‘)

# Configure the connection pool
pool = theresource.getJDBCConnectionPoolParams()
pool.setInitialCapacity(initialcap)
pool.setMaxCapacity(maxcap)
pool.setMinCapacity(mincap)
pool.setStatementCacheType(cachetype)
pool.setStatementCacheSize(cachesize)
pool.setTestConnectionsOnReserve(testreserve)
pool.setTestFrequencySeconds(testfreq)
pool.setSecondsToTrustAnIdlePoolConnection(trustidle)
pool.setShrinkFrequencySeconds(shrink)
pool.setTestTableName(testtable)

# Configure JDBC Driver:
driver = theresource.getJDBCDriverParams()
driver.setDriverName(drivername)
driver.setUrl(jdbcurl)
driver.setPassword(dbpassword)
driverprops = driver.getProperties()
userprop = driverprops.createProperty(‚user‘)
userprop.setValue(dbuser)

# Set data source target
jdbcresource.addTarget(target)

# Activate changes
save()
activate(block=’true‘)
print ‚>>>Data source created successfully!‘
exit()

Execute steps:

source $DOMAIN_HOME/bin/setDomainEnv.sh
java weblogic.WLST createmydatasource.py

Advertisements

Autor: Neselovskyi, Borys

Oracle Database / Middleware / Engineered System Solution Architect

Kommentar verfassen

Trage deine Daten unten ein oder klicke ein Icon um dich einzuloggen:

WordPress.com-Logo

Du kommentierst mit Deinem WordPress.com-Konto. Abmelden / Ändern )

Twitter-Bild

Du kommentierst mit Deinem Twitter-Konto. Abmelden / Ändern )

Facebook-Foto

Du kommentierst mit Deinem Facebook-Konto. Abmelden / Ändern )

Google+ Foto

Du kommentierst mit Deinem Google+-Konto. Abmelden / Ändern )

Verbinde mit %s