Skip to content

Instantly share code, notes, and snippets.

@perrefe
Created January 20, 2014 21:46
Show Gist options
  • Save perrefe/8529846 to your computer and use it in GitHub Desktop.
Save perrefe/8529846 to your computer and use it in GitHub Desktop.
Script para crear datasources en weblogic utilizando la consola WLST
connect('weblogic', 'weblogic1', 't3://10.151.92.113:7001')
edit()
startEdit()
server = getMBean('Servers/server1')
ds1 = {'name': 'ds1', 'jndi': ['jdbc/ds1'], 'url': 'jdbc:oracle:thin:@127.0.0.1:1521:XE', 'user': 'dbuser', 'password': 'dbpass'}
ds2 = {'name': 'ds2', 'jndi': ['jdbc/ds1'], 'url': 'jdbc:oracle:thin:@127.0.0.1:1521:XE', 'user': 'dbuser', 'password': 'dbpass'}
ds3 = {'name': 'ds3', 'jndi': ['jdbc/ds1'], 'url': 'jdbc:oracle:thin:@127.0.0.1:1521:XE', 'user': 'dbuser', 'password': 'dbpass'}
datasources = [ds1, ds2, ds3]
for ds in datasources:
print "Creating " + str(ds['jndi']) + " DataSource"
try:
newDataSource = cmo.createJDBCSystemResource(ds['name'])
newDataSource.addTarget(server)
jdbcResource = newDataSource.getJDBCResource()
jdbcResource.setName(ds['name'])
names = ds['jndi']
dataSourceParams = jdbcResource.getJDBCDataSourceParams()
dataSourceParams.setJNDINames(names)
dataSourceParams.setGlobalTransactionsProtocol('TwoPhaseCommit')
driverParams = jdbcResource.getJDBCDriverParams()
driverParams.setUrl(ds['url'])
driverParams.setDriverName('oracle.jdbc.xa.client.OracleXADataSource')
driverParams.setPassword(ds['password'])
driverProperties = driverParams.getProperties()
driverProperties.createProperty('user')
userProperty = driverProperties.lookupProperty('user')
userProperty.setValue(ds['user'])
connectionPoolParams = jdbcResource.getJDBCConnectionPoolParams()
connectionPoolParams.setTestTableName('SQL SELECT 1 FROM DUAL')
connectionPoolParams.setConnectionCreationRetryFrequencySeconds(10)
save()
except:
print "Can't create datasource " + str(ds['jndi'])
undo('true', 'y')
print 'Activating changes...'
activate(block='true')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment