Wednesday, 5 November 2014

WebSphere Application Server - Scripting 101

So a colleague asked me how to create (a) users and groups and (b) JDBC data sources in WAS using a Jython script.

Here's my answer: -

Create a Group

AdminTask.createGroup('[-cn Testers]')

Create A User

AdminTask.createUser ('[-uid TestUser1 -password P455w0rd -confirmPassword P455w0rd -cn  Test -sn User1]')

Add User to Group

AdminTask.addMemberToGroup('[-memberUniqueName uid=TestUser1,o=defaultWIMFileBasedRealm -groupUniqueName cn=Testers,o=defaultWIMFileBasedRealm]')

Create Another User

AdminTask.createUser ('[-uid TestUser2 -password P455w0rd -confirmPassword P455w0rd -cn  Test -sn User2]')

Add User to Group

AdminTask.addMemberToGroup('[-memberUniqueName uid=TestUser2,o=defaultWIMFileBasedRealm -groupUniqueName cn=Testers,o=defaultWIMFileBasedRealm]')

and: -

Create JDBC Provider

provider = AdminTask.createJDBCProvider('[-scope Cell=tameb -databaseType DB2 -providerType "DB2 Universal JDBC Driver Provider" -implementationType "Connection pool data source" -name "DB2 Universal JDBC Driver Provider" -description "DB2" -classpath [${DB2UNIVERSAL_JDBC_DRIVER_PATH}/db2jcc.jar ${UNIVERSAL_JDBC_DRIVER_PATH}/db2jcc_license_cu.jar ${DB2UNIVERSAL_JDBC_DRIVER_PATH}/db2jcc_license_cisuz.jar ] -nativePath [${DB2UNIVERSAL_JDBC_DRIVER_NATIVEPATH} ] ]')
AdminConfig.save() 
AdminNodeManagement.syncActiveNodes() 


Create J2C Authentication Alias

AdminTask.setAdminActiveSecuritySettings('[-customProperties["com.ibm.websphere.security.JAASAuthData.removeNodeNameGlobal=true"]]') 
AdminTask.createAuthDataEntry('[-alias db2inst1 -user db2inst1 -password passw0rd -description ]')
AdminConfig.save() 
AdminNodeManagement.syncActiveNodes()


Create JDBC Data Source

databaseName='SAMPLE'
serverName='tameb.uk.ibm.com'
portNumber=60008

ds = AdminTask.createDatasource(provider, '[-name sample -jndiName jdbc/sample -dataStoreHelperClassName com.ibm.websphere.rsadapter.DB2UniversalDataStoreHelper -containerManagedPersistence false -componentManagedAuthenticationAlias db2inst1 -xaRecoveryAuthAlias db2inst1 -configureResourceProperties [[databaseName java.lang.String '+str(databaseName)+'] [driverType java.lang.Integer 4] [serverName java.lang.String '+str(serverName)+'] [portNumber java.lang.Integer '+str(portNumber)+']]')

AdminConfig.create('MappingModule', ds, '[[authDataAlias db2inst1] [mappingConfigAlias ""]]')

AdminConfig.save() 
AdminNodeManagement.syncActiveNodes() 


Sweet :-)

No comments:

Note to self - use kubectl to query images in a pod or deployment

In both cases, we use JSON ... For a deployment, we can do this: - kubectl get deployment foobar --namespace snafu --output jsonpath="{...