Automating creation of JMS Queues and JmsAdapter plan updates and redeployment

Following on from my recent post on automation of creation of JDBC resources, I am happy to report I now have a script which can be used for JMS Queues!

Again, this is not as wonderful as I would like it to be, but here it is, in case it may help someone.  It is also in Subversion on java.net (may be newer).

# Copyright 2012 Oracle Corporation.
# All Rights Reserved.
#
# Provided on an 'as is' basis, without warranties or conditions of any kind,
# either express or implied, including, without limitation, any warranties or
# conditions of title, non-infringement, merchantability, or fitness for a
# particular purpose. You are solely responsible for determining the
# appropriateness of using and assume any risks. You may not redistribute.
#
# Please refer to https://redstack.wordpress.com/continous-integration for details.
#
# This WLST script can be used as part of a continuous integration build process
# before deploying a SCA composite, to create any necessary JMS Queues
# on the WebLogic Server.
#
# In addition to creating the queue, this script will also update the
# resource adapter and redeploy it.
#
# Parts of this script were adapted from Richard van den Berg's post at
# https://forums.oracle.com/forums/message.jspa?messageID=10131949#10131949

import time

#
# These are the parameters that you need to edit before running this script
#

# admin server url
url                  = 't3://localhost:7001'
# username to connect to the admin server
username             = 'weblogic'
# password to connect to the admin server
password             = 'welcome1'
# the name for the EIS - as defined in the JMS Adapter wizard in JDEV
eisName              = 'eis/wls/redstackQueue'
# the admin or managed server to target where the JmsAdapter is deployed
serverName           = 'soa_server1'
nmServerName         = 'soa_server1'
# the name for the queue
qName               = 'redstackQueue'
# the JNDI name for the queue
jndiName             = 'jms/redstackQueue'
# the JMS Module for the queue
jmsModule            = 'SOAJMSModule'
# the Subdeployment for the queue
jmsSubDeployment     = 'SOASubDeployment'
# the host where node manager is running
nmHost               = 'localhost'
# the port to connect to node manager (5556 is default for plain mode)
nmPort               = '5556'
# the user to connect to node manager
nmUser               = 'weblogic'
# the password to connection to node manager
nmPassword           = 'welcome1'
# the name of the weblogic domain
domain               = 'base_domain'

# don't change these ones
uniqueString         = ''
appName              = 'JmsAdapter'
moduleOverrideName   = appName+'.rar'
moduleDescriptorName = 'META-INF/weblogic-ra.xml'

#
# method definitions
#

def makeDeploymentPlanVariable(wlstPlan, name, value, xpath, origin='planbased'):
  """Create a varaible in the Plan.
  This method is used to create the variables that are needed in the Plan in order
  to add an entry for the outbound connection pool for the new data source.
  """

  try:
    variableAssignment = wlstPlan.createVariableAssignment(name, moduleOverrideName, moduleDescriptorName)
    variableAssignment.setXpath(xpath)
    variableAssignment.setOrigin(origin)
    wlstPlan.createVariable(name, value)

  except:
    print('--> was not able to create deployment plan variables successfully')

def main():

  print ' Copyright 2012 Oracle Corporation. '
  print ' All Rights Reserved. '
  print ''
  print ' Provided on an ''as is'' basis, without warranties or conditions of any kind, '
  print ' either express or implied, including, without limitation, any warranties or '
  print ' conditions of title, non-infringement, merchantability, or fitness for a '
  print ' particular purpose. You are solely responsible for determining the '
  print ' appropriateness of using and assume any risks. You may not redistribute.'
  print ''
  print ' Please refer to https://redstack.wordpress.com/continous-integration for details.'
  print ''
  print ' This WLST script can be used as part of a continuous integration build process'
  print ' before deploying a SCA composite, to create any necessary JMS queues'
  print ' on the WebLogic Server.'
  print ''
  print ' In addition to creating the queue, this script will also update the '
  print ' resource adapter and redeploy it.'
  print ''
  print ' !!! WARNING !!! WARNING !!! WARNING !!! WARNING !!! WARNING !!! WARNING !!!'
  print ''
  print ' This script will make changes to your WebLogic domain.  Make sure you know '
  print ' what you are doing.  There is no support for this script.  If something bad '
  print ' happens, you are on your own!  You have been warned.'

  #
  # generate a unique string to use in the names
  #

  uniqueString = str(int(time.time()))

  #
  # Create a JDBC Data Source.
  #

  try:
    print('--> about to connect to weblogic')
    connect(username, password, url)
    print('--> about to create a queue ' + qName)
    edit()
    startEdit()
    cd('/JMSSystemResources/' + jmsModule + '/JMSResource/' + jmsModule)
    cmo.createQueue(qName)
    cd('/JMSSystemResources/' + jmsModule + '/JMSResource/' + jmsModule + '/Queues/' + qName)
    set('JNDIName', jndiName)
    set('SubDeploymentName', jmsSubDeployment)
    save()
    print('--> activating changes')
    activate()
    print('--> done')

#
# update the deployment plan
#
    print('--> about to update the deployment plan for the DbAdapter')
    startEdit()
    planPath = get('/AppDeployments/JmsAdapter/PlanPath')
    appPath = get('/AppDeployments/JmsAdapter/SourcePath')
    print('--> Using plan ' + planPath)
    plan = loadApplication(appPath, planPath)
    print('--> adding variables to plan')

    makeDeploymentPlanVariable(plan, 'ConnectionInstance_eis/wls/' + qName + '_JNDIName_' + uniqueString, eisName, '/weblogic-connector/outbound-resource-adapter/connection-definition-group/[connection-factory-interface="oracle.tip.adapter.jms.IJmsConnectionFactory"]/connection-instance/[jndi-name="' + eisName + '"]/jndi-name')
    makeDeploymentPlanVariable(plan, 'ConfigProperty_ConnectionFactoryLocation' + uniqueString, eisName, '/weblogic-connector/outbound-resource-adapter/connection-definition-group/[connection-factory-interface="oracle.tip.adapter.jms.IJmsConnectionFactory"]/connection-instance/[jndi-name="' + eisName + '"]/connection-properties/properties/property/[name="ConnectionFactoryLocation"]/value')
    print('--> saving plan')
    plan.save();
    save();
    print('--> activating changes')
    activate(block='true');
    cd('/AppDeployments/JmsAdapter/Targets');
    print('--> redeploying the JmsAdapter')
    print(appName, planPath)
    redeploy(appName, planPath, targets=cmo.getTargets());
    print('--> done')

  except:
    print('--> something went wrong, bailing out')
    stopEdit('y')
    raise SystemExit

  #
  # disconnect from the admin server
  #

  print('--> disconnecting from admin server now')
  disconnect()

  #
  # Restart the managed server using the node manager.
  #

  try:
    print('--> about to restart server ' + nmServerName)
    nmConnect(nmUser, nmPassword, nmHost, nmPort, domain)
    print('--> stopping server...')
    nmKill(nmServerName)
    print('--> starting server')
    nmStart(nmServerName)
    print('--> done')
    nmDisconnect()

  except:
    print('--> was not able to restart server successfully')

#
#  this is the main entry point
#

main()

Enjoy!

About Mark Nelson

Mark Nelson is an Architect (an "IC6") in the Fusion Middleware Central Development Team at Oracle. Mark's job is to make Fusion Middleware easy to use in the cloud and at home, for developers and operations folks, with special focus on continuous delivery, configuration management and provisioning - making it simple to manage the configuration of complex environments and applications built with Oracle Database, Fusion Middleware and Fusion Applications, on-premise and in the cloud. Before joining this team, Mark was a senior member of the A-Team since 2010, and worked in Sales Consulting at Oracle since 2006 and various roles at IBM since 1994.
This entry was posted in Uncategorized and tagged , , , , , . Bookmark the permalink.

One Response to Automating creation of JMS Queues and JmsAdapter plan updates and redeployment

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s