Calling wsadmin scripts from ant

You can simply add the following to a target.
For the following wsadmin should be in your PATH env.

< exec dir="." executable="wsadmin.bat" logError="true" failonerror="true" output="wsconfig.out" >
< arg line="-lang jython -f ../../createQFactory.py"/ >
< /exec >

All output will be logged to wsconfig.out

wasprofile -create -delete

Sometimes you require to do things silently, without any questions asked and “Just Do It” attitude is required.

I often find my self with this problem.

If you want to delete or create a Websphere profile from your command line try the following. (I have tried on RSA only)

# deleteing a profile
wasprofile -delete -profileName MyProfile

You should get the following message on deletion

INSTCONFSUCCESS: Success: The profile no longer exists.

Creating a websphere profile

wasprofile -create -profileName MyProfile -profilePath \
[PROFILE PATH] -templatePath \
[RSA HOME]runtimes\base_v6\profileTemplates\default \
-nodeName [NODE NAME] -cellName [CELL NAME] -hostName [HOSTNAME].

HowTo create a JDBC provider with wsadmin scripting – Jython

Last week I wrote a post about creating MQQueues with jacl. However today I am moving to Jython. This is the new scripting languauge supported by the wsadmin. The following write-up helps you create a JDBC provider using Jython in 6 easy steps on the wsadmin console.

Pre requirements:
Following should be known to start using this tutorial.

1. How to launch the wsadmin with Jython enabled.

Where will I find the wsadmin?
It is typically placed in the bin directory of your server.
In my case its lying in my RAD installation directory as
../Rational/SDP/6.0/runtimes/base_v6/bin

To invoke the wasadmin, just open your terminal and move to the bin dir where you can simply call it by typing wsadmin -lang jython. By doing so you would be invoking the default profile. if you want to specify the profile then use the switch -profileName YOURPROFILENAME

You can either paste the commands step by step or store the whole code listing in one file like DataSources.py. This means you can run this with wsadmin by specifying the -f switch.

After the wsadmin console is launched we can now move to creating the provider step by step.

STEP 1.
Identify classpath for the provider. This is a path to the jar files that need to be used by the provider. In our case its a jdbc dirver for oracle.

driverPath = 'C:\lib\ojdbc14.jar'

STEP 2.
Identify the node and cell that will hold this provider. Node/Cell is how websphere is organized. As the Provider will be created inside a node we need to know which node we are working with.

cellName=AdminControl.getCell()
nodeName=AdminControl.getNode()
node = AdminConfig.getid('/Cell:%s/Node:%s/' % (cellName,nodeName))

In the code above first we get the NodeName and CellName of the current connected server and then take the reference of it as node.

STEP 3.
Specify a template, In our case we have taken an ‘Oracle JDBC Driver (XA)’ template.
The following command will list the template for the provider specified and store it in a variable ‘providerTemplate’

providerTemplate=AdminConfig.listTemplates('JDBCProvider', 'Oracle JDBC Driver (XA)')

STEP 4.
The name for our provider. It could be any name you want to give your provider.

providerName = ['name', 'Oracle JDBC Driver (XA)']

Implementation class and classpath for driver.
It is important to give the implementation class for our provider. In some cases they can be different in ours we use the default one.

implClassName = ['implementationClassName', 'oracle.jdbc.xa.client.OracleXADataSource']

STEP 5.
The following code will just put all the above variables into a form expected by wsadmin as a temp variable jdbcAttrs.

classpath = ['classpath',driverPath]
jdbcAttrs = [providerName,  implClassName,classpath]

STEP 6.

Now is the time to create the provider. and the following will just do that. It passes the type of the provider, the node ref, the jdbcAttrs created in step 5 and the template to be used to create the provider.

provider  = AdminConfig.createUsingTemplate('JDBCProvider', node, jdbcAttrs, providerTemplate)
AdminConfig.save()

This is pretty much it. You should now be able to see the provider in the AdminConsole.

Complete code listing is as follows

driverPath = 'C:\lib\ojdbc14.jar'
cellName=AdminControl.getCell()
nodeName=AdminControl.getNode()
providerTemplate=AdminConfig.listTemplates('JDBCProvider', 'Oracle JDBC Driver (XA)')
node = AdminConfig.getid('/Cell:%s/Node:%s/' % (cellName,nodeName))
 
providerName = ['name', 'Oracle JDBC Driver (XA)']
implClassName = ['implementationClassName', 'oracle.jdbc.xa.client.OracleXADataSource']
classpath = ['classpath',driverPath]
jdbcAttrs = [providerName,  implClassName,classpath]
provider  = AdminConfig.createUsingTemplate('JDBCProvider', node, jdbcAttrs, providerTemplate)
AdminConfig.save()

Creating the MQQueues with wsadmin scripting – JACL Part 2

Yesterday I wrote an article about creating and configuring the MQQueueConnectionFactory with the JACL on the wsadmin console. The other half of the article that was left out was to create the queues also.

The world looks pretty much the same today and my /etc/profile doesnt seemed to have been sourced again. Good we dont need a restart.

You would find some of the steps to be similar and that is because we are running on the same configs.

Step 1.
Identify the Provider for your Queue. By default this is the name for it. If you have created a new provider with a different name then specify it here.

set tmp1 "WebSphere MQ JMS Provider"

Step 2.
Now you would need to find the CELL NAME and the NODE NAME of your server
A typical location to my websphere profile’s Node configuration file is as follows
C:\Programs\IBM\Rational\SDP\6.0\runtimes\base_v6\profiles\test_wsp\config\cells\BNode05Cell\nodes\BNode05
The cell name in this location is after \cells\ i.e. BNode05Cell
And the node name is at the end after \nodes\ i.e. BNode05

set newjmsp [$AdminConfig getid /Cell:CELLNAMECell/Node:NODENAME/JMSProvider:$tmp1/]

Step 3.
You would now need to set the attributes that go into the queue.

To see all the attributes you can simply run the following command

$AdminConfig [required|attributes] MQQueue

i.e. required or attributes

The attributes that I will be setting in the following commands are
name, jndiName, baseQueueName, targetClient

set name [list name NAME]
set jndi [list jndiName jms/jndiName]
set baseQN [list baseQueueName BASEQUEUENAME]
set targetclient [list targetClient MQ]

You can see in the above example the target client is set to MQ it can be JMS based on your configuration.

Step 4.
Now set all parameters in one string so that they can be passed to the command as one.

set mqqAttrs [list $name $jndi $baseQN $targetclient]

Step 5.
Now to create the MQQueue use the following command. This will add the Queue to the node and cell mentioned earlier in step 2.

$AdminConfig create MQQueue $newjmsp $mqqAttrs

Once it is created it is not saved and only stays in the current session. So to save it run the following command. And you should be all set.

$AdminConfig save

You can alternatively also save this script in a file on your local system. And run it by passing it to the wasadmin. Follwing is a sample command.

wsadmin -profileName test_wsp -f $SCRIPT_FILENAME_LOCATION$

‘Complete code listing is as follows.

set tmp1 "WebSphere MQ JMS Provider"
 
set newjmsp [$AdminConfig getid /Cell:HOSTNAMENode04Cell/Node:HOSTNAMENode04/JMSProvider:$tmp1/]
 
set name [list name Q.REPLY]
set jndi [list jndiName jms/Q.REPLY]
set baseQN [list baseQueueName Q.SYSTEM]
set targetclient [list targetClient MQ]
set mqqAttrs [list $name $jndi $baseQN $targetclient]
 
$AdminConfig create MQQueue $newjmsp $mqqAttrs
 
$AdminConfig save

Creating the MQQueueConnectionFactory with wsadmin scripting – JACL Part 1.

While working my way in some piece of long java code I came across this huge pile of sand that just shattered me off every bit of patience I was left with. The dilemma all of us face every second day. CONFIGURATIONS!!

While my sarcastic mind was just saying Congratulations to me instead. And just how the – would you expect me to start configuring now.

So what exactly is my problem? I have a list of MQs, Factories, datasource, providers etc.. that I need to configure. And every time I create a new profile on my RAD (Rational Application Developer) I have to manually goto the Admin console and configure them.

With the very useless bit of linux I am acquainted too I cant live with clicks at least while programming.

As I am working with websphere and its a biggy in all those names I thought the guys would be smart and would at least have something in the box for *people like me. Well guess what I was right.

IBM has provided two languages for scripting.

1. JACL
2. Jython

If I am not wrong JACL will be deprecated out in future releases and Jython would be the tool for our scripting bit. [ Link here ]

In this article I will just go briefly with JACL and move to Jython in the next version where we will be able to configure the data sources in the websphere.

So what exactly is JACL. or pronounced as “JACKAL”

Jacl, Java Command Language, is much like/version of the Tcl scripting language for the Java. It runs on the JVM much like we hear about JRuby and the interpreter is written completely in Java.

For more details on the language itself you could go [ here ]

Lets get down to business: How to create a Webspehere MQ Connection Factory with wsamdin using JACL.
You would already have some of the details of the queues but some you will need to extract.

Step 1.
Identify the Provider for your Factory. By default this is the name for it. If you have created a new provider with a different name then specify it here.

set tmp1 "WebSphere MQ JMS Provider"

Step 2.
Now you would need to find the CELL NAME and the NODE NAME of your server
A typical location to my websphere profile’s Node configuration file is as follows
C:\Programs\IBM\Rational\SDP\6.0\runtimes\base_v6\profiles\test_wsp\config\cells\BNode05Cell\nodes\BNode05
The cell name in this location is after \cells\ i.e. BNode05Cell
And the node name is at the end after \nodes\ i.e. BNode05

set newjmsp [$AdminConfig getid /Cell:CELLNAMECell/Node:NODENAME/JMSProvider:$tmp1/]

Step 3.
Now you need to specify the Factories properties.

The properties I plan to setup are as follows.
Name, jndiName,QueueManager, sname, port, channel, ttype, xaenabled

To check what are the required parameters for the Factory you can run the following command on the wsadmin console.

$AdminConfig required WASQueueConnectionFactory

Example output:

wsadmin $AdminConfig required WASQueueConnectionFactory
Attribute                       Type
name                            String
jndiName                        String

Where will I find the wsadmin?
It is typically placed in the bin directory of your server.
In my case its lying in my RAD installation directory as
../Rational/SDP/6.0/runtimes/base_v6/bin

To invoke the wasadmin, just open your terminal and move to the bin dir where you can simply call it by typing wsadmin.  By doing so you would be invoking the default profile. if you want to specify the profile then use the switch -profileName YOURPROFILENAME

To see the all parameters required and optional write the following command on the console.

$AdminConfig attributes WASQueueConnectionFactory

Example output:

wsadmin $AdminConfig attributes WASQueueConnectionFactory
"XAEnabled boolean"
"authDataAlias String"
"authMechanismPreference ENUM(BASIC_PASSWORD, KERBEROS)"
"category String"
"connectionPool ConnectionPool"
"description String"
"jndiName String"
"logMissingTransactionContext boolean"
"manageCachedHandles boolean"
"mapping MappingModule"
"name String"
"node String"
"preTestConfig ConnectionTest"
"propertySet J2EEResourcePropertySet"
"provider J2EEResourceProvider@"
"providerType String"
"serverName String"
"sessionPool ConnectionPool"
"xaRecoveryAuthAlias String"

I have added some extra optional parameters for those of us who are using extra options.

set name [list name NAME]
 
set jndi [list jndiName jms/JNDINAME]
 
set qManager [list queueManager QMANAGER]
 
set sname [list host HOSTNAME]
 
set port [list port 1414]
 
set channel [list channel CHANNEL]
 
set ttype [list transportType CLIENT]
 
set xa [list XAEnabled True|false]

Step 4.
Now set all parameters in one string so that they can be passed to the command as one.

set mqcfAttrs [list $name $jndi $qManager $sname $port $channel $ttype $xa]

Step 5.
Now to create the Factory use the following command. This will add the factory to the node and cell mentioned earlier in step 2.

$AdminConfig create MQQueueConnectionFactory $newjmsp $mqcfAttrs

Once it is created it is not saved and only stays in the current session. So to save it run the following command. And you should be all set.

$AdminConfig save

You can alternatively also save this script in a file on your local system. And run it by passing it to the wasadmin. Follwing is a sample command.

wsadmin -profileName test_wsp -f $SCRIPT_FILENAME_LOCATION$

Complete code listing is as follows.

set tmp1 "WebSphere MQ JMS Provider"
 
set newjmsp [$AdminConfig getid /Cell:CELLNAMECell/Node:NODENAME/JMSProvider:$tmp1/]
 
set name [list name NAME]
 
set jndi [list jndiName jms/JNDINAME]
 
set qManager [list queueManager QMANAGER]
 
set sname [list host HOSTNAME]
 
set port [list port 1414]
 
set channel [list channel CHANNEL]
 
set ttype [list transportType CLIENT]
 
set xa [list XAEnabled false]
 
set mqcfAttrs [list $name $jndi $qManager $sname $port $channel $ttype $xa]
 
$AdminConfig create MQQueueConnectionFactory $newjmsp $mqcfAttrs
 
$AdminConfig save

More Resources:

[http://publib.boulder.ibm.com/infocenter/wasinfo/v6r1/index.jsp?topic=/com.ibm.websphere.nd.doc/info/ae/ae/rmig_deprecationlist.html]

[http://publib.boulder.ibm.com/infocenter/imshelp1/v3r0/index.jsp?topic=/com.ibm.sif.doc/jaclabout.html]