Adding AQ Adapter configuration using WLST

Having to deploy a service that uses the AQ Adapter on multiple servers I set out to create a WLST script that could create the necessary configuration from a property file. It took me a little while to get everything working as I wanted it to. Once you figure it all out, it really isn't that difficult, but there weren't a lot of guies specifically for AQ  Adapter configuration. There are plenty for the DB Adapter and the idea is basically the same.
 

Creating AQ Adapter configuration

I'll post the script here to serve as an example. It might take a little adapting to use it in your own environment.

 

 

from java.io import FileInputStream

#==============================

# Main Method

#==============================


def main(argv):

if (len(argv) <= 3):

usage();

sys.exit(-1);


# Variables

local = argv[1]

wls_username = argv[4]

wls_password = argv[5]

wls_host = argv[6]

wls_port = argv[7]

mw_home = argv[8]

domain_name = argv[2]

userConfigFilePath='c:\\Oracle\\Domains\\'+domain_name+'\\bin\\custom\\user'

userKeyFilePath='c:\\Oracle\\Domains\\'+domain_name+'\\bin\\custom\\key'


#Connect to Admin Server

if local == 'true':

 

 connect(wls_username,wls_password,url='t3://'+wls_host+':'+wls_port)

else:

 domain_home='c:\\Oracle\\Domains\\'+domain_name

 connect(userConfigFile=userConfigFilePath, userKeyFile=userKeyFilePath, url='t3://'+wls_host+':'+wls_port)


properties = getProperties(argv[3]);


print "Creating AQ configuration"

createAQ(properties, mw_home)

print "AQ configuration updated!"


def createAQ(properties, mw_home):

#Global Variables

aqAdapterName = 'AqAdapter'

aqAdapterPath = mw_home + '/Oracle_SOA1/soa/connectors/AqAdapter.rar'


try:

edit()

startEdit()


#Load Application

print "Loading Application"

currentPlanAdapterPath = get('/AppDeployments/AqAdapter/PlanPath')

aqAdapter = loadApplication(aqAdapterPath, currentPlanAdapterPath)

#Configure Properties

print "Creating Variables"

print "Creating ConnectionInstance variable"

aqConnectionInstanceValue = properties.get('aq.connectioninstance.value')

aqConnectionInstanceName = 'ConnectionInstance_' + aqConnectionInstanceValue

aqConnectionInstanceXPath = '/weblogic-connector/outbound-resource-adapter/connection-definition-group/[connection-factory-interface="javax.resource.cci.ConnectionFactory"]/connection-instance/[jndi-name="' + aqConnectionInstanceValue + '"]/jndi-name'

createAppVariable(aqAdapter, aqConnectionInstanceName, aqConnectionInstanceValue, aqConnectionInstanceXPath)


print "Creating DataSource variable"

aqDataSourceName = 'ConfigProperty_DataSourceName_' + aqConnectionInstanceValue

aqDataSourceValue = properties.get('aq.datasource.value')

aqDataSourceXPath = '/weblogic-connector/outbound-resource-adapter/connection-definition-group/[connection-factory-interface="javax.resource.cci.ConnectionFactory"]/connection-instance/[jndi-name="' + aqConnectionInstanceValue + '"]/connection-properties/properties/property/[name="DataSourceName"]/value'

createAppVariable(aqAdapter, aqDataSourceName, aqDataSourceValue, aqDataSourceXPath)


#Save Application

aqAdapter.save()


save()

activate()

redeploy(aqAdapterName, currentPlanAdapterPath, targets=cmo.getTargets());

except Exception, e:

print 'Failed to create AQ configuration'

stopEdit('y')

sys.exit(1)


def createAppVariable(wlstPlan, name, value, xpath, overrideName='AqAdapter.rar', moduleDescriptorName='META-INF/weblogic-ra.xml', origin='planbased'): 

#Ensure variable is overwritten

wlstPlan.destroyVariable(name)

wlstPlan.destroyVariableAssignment(name, overrideName, moduleDescriptorName)

#Create Variable Assignment

variableAssignment = wlstPlan.createVariableAssignment(name, overrideName, moduleDescriptorName)

variableAssignment.setXpath(xpath)

variableAssignment.setOrigin(origin)


#Assign Value to Variable

wlstPlan.createVariable(name, value)


#==============================

# Helper Methods

#==============================


def getProperties(file):

try:

prop = FileInputStream(file)

properties = Properties()

properties.load(prop)

except Exception, e:

print "Something fishy about that file <"+file+">"

sys.exit(0)

return properties



def usage():

print 'Usage: '+sys.argv[0]+' <local> <domain_name> <propertyfile> <weblogic username> <weblogic password> <weblogic host> <weblogic port> <mw_home>'


#==============================

# Start Main

#==============================

main(sys.argv)

This should get you going, and hopefully save someone some hassle of getting this going themselves.