Wednesday, 21 November 2012

Using wsadmin to script the creation of a JDBC data source - using input parameters

In this article, I explain how I was able to create a wsadmin script, using the Jython language, to automate the creation of a JDBC data source, to allow WebSphere Application Server 8 to connect to DB2 UDB 9.7. I also highlight an exception that I kept on seeing ( for hours and hours and hours ) and how I resolved it ....

The requirement was to create a script that would be called from a Bash shell script, with input parameters, and would then create a data source, and the associated J2C alias and mapping.

In essence, it looked like this: -


provider_id=AdminConfig.getid('/Cell:E1DSCell/JDBCProvider:DB2 XA provider/')

dsid = AdminTask.createDatasource('provider_id, '[-name [Team Server Datasource] -jndiName jdbc/ilogDataSource -dataStoreHelperClassName -componentManagedAuthenticationAlias RES_db2conn -containerManagedPersistence false -xaRecoveryAuthAlias RES_db2conn -configureResourceProperties [[databaseName java.lang.String ' + str(databaseName) + '] [driverType java.lang.Integer ' + str(driverType) + '] [serverName java.lang.String ' + str(serverName) + '] [portNumber java.lang.Integer ' + portNumber + ']]') 

AdminConfig.create('MappingModule', dsid , '[[authDataAlias RES_db2conn [mappingConfigAlias ""]]')

However, when I executed it, I was seeing: -

$ /opt/IBM/WebSphere/AppServer80/profiles/E1DSDMNODE/bin/ -lang jython -user wasadmin -password passw0rd -f ~/ E1DSCELL RESDB 4 50000

WASX7209I: Connected to process "dmgr" on node E1DSDMNODENode using SOAP connector;  The type of process is: DeploymentManager
WASX7303I: The following options are passed to the scripting environment and are available as arguments that are stored in the argv variable: "[E1DSCELL, RESDB, 4,, 50000]"
WASX7017E: Exception received while running file "/home/wasadmin/"; exception information: java.lang.IllegalArgumentException: java.lang.IllegalArgumentException: WASX7122E: Expected "]"  not found. 
[-name [Team Server Datasource] -jndiName jdbc/ilogDataSource -dataStoreHelperClassName -componentManagedAuthenticationAlias RES_db2conn -containerManagedPersistence false -xaRecoveryAuthAlias RES_db2conn -configureResourceProperties [[databaseName java.lang.String RESDB] [driverType java.lang.Integer 4] [serverName java.lang.String] [portNumber java.lang.Integer 50000]]

WASX7341W: No "save" was performed before the interactive scripting session exited; configuration changes will not be saved.

It took me AGES to realise that the exception was actually coming from the AdminConfig.create() command: -

AdminConfig.create('MappingModule', dsid , '[[authDataAlias RES_db2conn [mappingConfigAlias ""]]')

rather than the the AdminTask.createDatasource() command, and that it was simply a syntax error on my part - I should have written: -

AdminConfig.create('MappingModule', dsid , '[[authDataAlias RES_db2conn] [mappingConfigAlias ""]]')

Obviously, I should've broken the script down into separate commands, but I got fixated on the AdminTask command, and spent hours hacking around with that :-)

For the record, I didn't actually NEED to use the str() command, as the input parameters were already strings - I've since changed the script to this: -

dsid = AdminTask.createDatasource(provider_id, '[-name [Team Server Datasource] -jndiName jdbc/ilogDataSource -dataStoreHelperClassName -componentManagedAuthenticationAlias RES_db2conn -containerManagedPersistence false -xaRecoveryAuthAlias RES_db2conn -configureResourceProperties [[databaseName java.lang.String ' + databaseName + '] [driverType java.lang.Integer ' + driverType + '] [serverName java.lang.String ' + serverName + '] [portNumber java.lang.Integer ' + portNumber + ']]') 

The moral of the story ? If you get exceptions from your Jython script, in the words of MC Hammer, BREAK IT DOWN :-)

Ah well, it's life up here on the learning curve, every day is a school day.

1 comment:

Ashrith said...
This comment has been removed by the author.