Link to home
Start Free TrialLog in
Avatar of amughal7
amughal7

asked on

Jython script to create a queue

I would like to create a new queue using jython script (in SIBus (Buses > Bus name > Destinations))
i.e, Click New, selecsts queue from destinations, identifier (give it a name (myQueue)
then assign the queue to bus member and create.

I can't find an AdminTask function that could do this. Checked AdminTask.help()
Does anyone know if there is one?
That would simplify the create statment in 1 line or so I guess.

However, I believe I would need to do something like the following but not really sure.

SID = AdminConfig.getid( '/Cell:.../Node:.../Server:server1/' )
QID=AdminControl.queryNames('type=SIBQueuePoint,name=ABC,*')
Que=AdminControl.getAttribute(SID,'xyz')
AdminConfig.create('<queue name>', ,  )
AdminConfig.save();

Many Thanks.
Avatar of HonorGod
HonorGod
Flag of United States of America image

What version of WebSphere?

What is in the "Installed Product" section of the versionInfo command script?

C:\IBM\WebSphere\AppServer\bin\versionInfo

or

/opt/IBM/WebSphere/AppServer/bin/versionInfo.sh
If you are using V7 or V8, you might want to take a look at using properties configuration files:

Working with service integration properties files

http://publib.boulder.ibm.com/infocenter/wasinfo/v7r0/index.jsp?topic=%2Fcom.ibm.websphere.base.doc%2Finfo%2Faes%2Fae%2Ftxml_config_prop_sib.html
Avatar of amughal7
amughal7

ASKER

Using version 7.0.0.15 ND
Super.

Steps taken:

- Select / expand "Service integration"
- Select "Buses" link
- Click New button
  Leave "Bus security" enabled
  Click Next
- Step 1.1: Introduction
  Click Next
- Step 1.2: Specify transport level security
  Leave "Require clients use SSL protected transports" enabled
  Click Next
- Step 1.3: Select the security domain for the bus
  Leave "Inherit the cell level security domain" selected ?
  Click Next
- Step 1.4: Confirm the enablement of security
  Review changes to be made
  Click Next
- Step 2: Confirm create of new bus
  Click Finish

Click "View administrative scripting command for last action" to see what Jython statements needed to be used to perform these actions:

Is this right so far?
AdminTask.createSIBus('[-bus magic -busSecurity true -scriptCompatibility 6.1 ]')
AdminTask.getSecurityDomainForResource('[-resourceName SIBus=magic -getEffectiveDomain false]')
AdminTask.modifySIBus('[-bus magic -busSecurity true -permittedChains SSL_ENABLED ]')

Open in new window

I found these scripts at:

http://www.webspheretools.com/sites/webspheretools.nsf/docs/WebSphere%20Jython%20JMS%20Scripts

Unfortunately, as they are displayed on the website, all indentation is lost... ;-(

So, I have added the indentation as I was reading the code, and it looks as seen below.

Note:
  Apparently, he calls a routine named sop() that I couldn't find (I gave up after trying for about 15 - 20 minutes).

I presume that something like the definition for sop() shown below may suffice
###############################################################################
# JMS Resource Management
# From: http://www.webspheretools.com/sites/webspheretools.nsf/docs/WebSphere%20Jython%20JMS%20Scripts
#   By: Steve Robinson
###############################################################################

def enableService(serviceName, scope):
    """ This method encapsulates the base action of enabling a service for use in WAS.

Parameters:
serviceName - Name of the service to be enabled in String format
scope - Identification of object (such as server or node) in String format.
Returns:
No return value
"""
    m = "enableService: "
    #--------------------------------------------------------------------
    # Get a list of service objects. There should only be one.
    # If there's more than one, use the first one found.
    #--------------------------------------------------------------------
    services = _splitlines(AdminConfig.list(serviceName, scope))
    if ( len(services) == 0 ) :
      sop(m, "The %s service could not be found." % serviceName)
      return
    #endIf
    serviceID = services[0]

    #--------------------------------------------------------------------
    # Set the service enablement
    #--------------------------------------------------------------------
    if (AdminConfig.showAttribute(serviceID, "enable") == "true"):
        sop(m, "The %s service is already enabled." % serviceName)
    else:
        AdminConfig.modify(serviceID, [["enable", "true"]] )
    #endElse
#endDef

def deleteAllSIBuses():
    """Deletes all SIB bus objects in the configuration."""
    m = "deleteAllSIBuses: "
    #sop(m,"Entry.")

    try:
        bus_list = _splitlines(AdminTask.listSIBuses())
        #sopY(m,"bus_list=%s" % ( bus_list ))

        for bus in bus_list:
            #sop(m,"bus=%s" % ( bus ))
            bus_name = getNameFromId(bus)
            sop(m,"Deleting bus_name=%s" % ( bus_name ))
            AdminTask.deleteSIBus('[-bus %s ]' % (bus_name))
    except AttributeError:
        return
    #sop(m,"Exit.")
#endDef

def addSIBusMember(clusterName, nodeName, serverName, SIBusName):
    """ This method encapsulates the actions needed to add a server-node or a cluster to a bus.
It will scan the member list to determine if cluster or server-node is already on the specified
bus. If not, it will add the member.

Parameters:
clusterName - Name of the cluster to add onto bus in String format. If value is "none", server-node will be added instead of cluster
nodeName - Name of node containing server to add onto bus in String format.
serverName - Name of server to add onto bus in String format.
SIBusName - Name of bus to add member onto in String format.
Returns:
No return value
"""
    m = "addSIBusMember: "

    if(clusterName == "none"):
        for member in _splitlines(AdminTask.listSIBusMembers(["-bus", SIBusName])):
            memberNode = AdminConfig.showAttribute(member, "node")
            memberServer = AdminConfig.showAttribute(member, "server")
            if((memberNode == nodeName) and (memberServer == serverName)):
                sop(m, "The bus member already exists.")
                return
                #endIf
        #endFor
        AdminTask.addSIBusMember(["-bus", SIBusName, "-node", nodeName, "-server", serverName])
    else:
        for member in _splitlines(AdminTask.listSIBusMembers(["-bus", SIBusName])):
            memberCluster = AdminConfig.showAttribute(member, "cluster")
            if(memberCluster == clusterName):
                sop(m, "The bus member already exists.")
                return
            #endIf
    #endFor

    AdminTask.addSIBusMember(["-bus", SIBusName, "-cluster", clusterName])
    #endElse
#endDef

def createSIBus(clusterName, nodeName, serverName, SIBusName, scope, busSecurity=""):
    """ This method encapsulates the actions needed to create a bus on the current cell.
It will check to see if the bus already exists. If not, it will add the member.

Parameters:
clusterName - Name of the cluster to add onto bus in String format. If value is "none", server-node will be added instead of cluster
nodeName - Name of node containing server to add onto bus in String format.
serverName - Name of server to add onto bus in String format.
SIBusName - Name of bus to create in String format.
scope - Identification of object (such as server or node) in String format.
busSecurity - Set this option to TRUE to enforce the authorization policy for the bus
Returns:
No return value
"""
    m = "createSIBus: "
    #--------------------------------------------------------------------
    # Create a bus in the current cell. As well as creating a bus, the
    # createSIBus command will create a default topic space on the bus.
    #--------------------------------------------------------------------
    bus = AdminConfig.getid('/SIBus:%s' % SIBusName)

    if((len(bus) == 1) or (len(bus) == 0)):
        params = ["-bus", SIBusName, "-description", "Messaging bus for testing"]
        if(not(busSecurity == "")):
            params.append("-busSecurity")
            params.append(busSecurity)
        else:
            # Use deprecated -secure option for compatibility with prior versions of this script.
            params.append("-secure")
            params.append("FALSE")
        #endElse
        AdminTask.createSIBus(params)
    else:
        sop(m, "The %s already exists." % SIBusName)
    #endElse

    #--------------------------------------------------------------------
    # Add SI bus member
    #--------------------------------------------------------------------
    addSIBusMember(clusterName, nodeName, serverName, SIBusName)

    #--------------------------------------------------------------------
    # Enable SIB service
    #--------------------------------------------------------------------
    enableService("SIBService", scope)
#endDef

def createSIBus_ext(SIBusName, desc, busSecurity, interAuth, medAuth, protocol, discard, confReload, msgThreshold ):
    """ This method encapsulates the actions needed to create a bus on the current cell.
It will check to see if the bus already exists. If not, it will create the bus.

Parameters:
SIBusName - Name of bus to create in String format.
desc - Descriptive information about the bus.
busSecurity - Enables or disables bus security.
interAuth - Name of the authentication alias used to authorize communication between messaging engines on the bus.
medAuth - Name of the authentication alias used to authorize mediations to access the bus.
protocol - The protocol used to send and receive messages between messaging engines, and between API clients and messaging engines.
discard - Indicate whether or not any messages left in a queue's data store should be discarded when the queue is deleted.
confReload - Indicate whether configuration files should be dynamically reloaded for this bus.
msgThreshold - The maximum number of messages that any queue on the bus can hold.
Returns:
No return value
"""
    m = "createSIBus_ext: "
    sop (m, "Entering createSIBus_ext function...")
    #--------------------------------------------------------------------
    # Create a bus in the current cell.
    #--------------------------------------------------------------------
    bus = AdminConfig.getid('/SIBus:%s' % SIBusName)
    if((len(bus) == 1) or (len(bus) == 0)):
        params = ["-bus", SIBusName, "-description", desc, "-interEngineAuthAlias", interAuth, "-mediationsAuthAlias", medAuth, "-protocol", protocol, "-discardOnDelete", discard, "-configurationReloadEnabled", confReload, "-highMessageThreshold", msgThreshold ]
        if(not(busSecurity == "")):
            params.append("-busSecurity")
            params.append(busSecurity)
        else:
            # Use deprecated -secure option for compatibility with prior versions of this script.
            params.append("-secure")
            params.append("FALSE")
        #endElse
        AdminTask.createSIBus(params)
    else:
        sop(m, "The %s already exists." % SIBusName)
    #endElse
#endDef


def addSIBusMember_ext (clusterName, nodeName, serverName, SIBusName, messageStoreType, logSize, logDir, minPermStoreSize, minTempStoreSize, maxPermStoreSize, maxTempStoreSize, unlimPermStoreSize, unlimTempStoreSize, permStoreDirName, tempStoreDirName, createDataSrc, createTables, authAlias, schemaName, dataSrcJNDIName ):

    """ This method encapsulates the actions needed to add a server-node or a cluster to a bus.
It will scan the member list to determine if cluster or server-node is already on the specified
bus. If not, it will add the member.

Parameters:
clusterName - Name of the cluster to add onto bus in String format. If value is "none", server-node will be added instead of cluster
nodeName - Name of node containing server to add onto bus in String format.
serverName - Name of server to add onto bus in String format.
SIBusName - Name of bus to add member onto in String format.
messageStoreType - Indicates whether a filestore or datastore should be used. Valid values are 'filestore' and 'datastore'.
logSize - The size, in megabytes, of the log file.
logDir - The name of the log files directory.
minPermStoreSize - The minimum size, in megabytes, of the permanent store file.
minTempStoreSize - The minimum size, in megabytes, of the temporary store file.
maxPermStoreSize - The maximum size, in megabytes, of the permanent store file.
maxTempStoreSize - The maximum size, in megabytes, of the temporary store file.
unlimPermStoreSize -'true' if the permanent file store size has no limit; 'false' otherwise.
unlimTempStoreSize - 'true' if the temporary file store size has no limit; 'false' otherwise.
permStoreDirName - The name of the store files directory for permanent data.
tempStoreDirName - The name of the store files directory for temporary data.
createDataSrc - When adding a server to a bus, set this to true if a default datasource is required. When adding a cluster to a bus, this parameter must not be supplied.
createTables - Select this option if the messaging engine creates the database tables for the data store. Otherwise, the database administrator must create the database tables.
authAlias - The name of the authentication alias used to authenticate the messaging engine to the data source.
schemaName - The name of the database schema used to contain the tables for the data store.
dataSrcJNDIName - The JNDI name of the datasource to be referenced from the datastore created when the member is added to the bus.
Returns:
No return value
"""
    m = "addSIBusMember: "
    sop (m, "Entering addSIBusMember function...")

    params = "-bus", SIBusName

    if(clusterName == "none"):
        for member in _splitlines(AdminTask.listSIBusMembers(["-bus", SIBusName])):
            memberNode = AdminConfig.showAttribute(member, "node")
            memberServer = AdminConfig.showAttribute(member, "server")
            if((memberNode == nodeName) and (memberServer == serverName)):
                sop(m, "The bus member already exists.")
                return
            #endIf
        #endFor
        params += "-node", nodeName, "-server", serverName
    else:
        for member in _splitlines(AdminTask.listSIBusMembers(["-bus", SIBusName])):
            memberCluster = AdminConfig.showAttribute(member, "cluster")
            if(memberCluster == clusterName):
                sop(m, "The bus member already exists.")
                return
            #endIf
        #endFor
        params += "-cluster", clusterName
    #endElse

    if (messageStoreType.lower() == 'filestore'):
        params += "-fileStore",
        params += "-logSize", logSize, "-logDirectory", logDir,
        params += "-minPermanentStoreSize", minPermStoreSize, "-minTemporaryStoreSize", minTempStoreSize,
        params += "-unlimitedPermanentStoreSize", unlimPermStoreSize, "-unlimitedTemporaryStoreSize", unlimTempStoreSize,

        if (unlimPermStoreSize == 'false'):
            params += "-maxPermanentStoreSize", maxPermStoreSize,
        #endIf

        if (unlimTempStoreSize == 'false'):
            params += "-maxTemporaryStoreSize", maxTempStoreSize,
        #endif
        params += "-permanentStoreDirectory", permStoreDirName, "-temporaryStoreDirectory", tempStoreDirName
    else:
        if (messageStoreType.lower() == 'datastore'):
            params += "-dataStore",
            params += "-createDefaultDatasource", createDataSrc,
            params += "-datasourceJndiName", dataSrcJNDIName,
            params += "-createTables", createTables,
            params += "-authAlias", authAlias, "-schemaName", schemaName
        #endIf
    #endIf

    AdminTask.addSIBusMember(params)

#endDef

def createSIBJMSConnectionFactory(clusterName, serverName, jmsCFName, jmsCFJNDI, jmsCFDesc, jmsCFType, SIBusName, provEndPoints, scope, authAlias=""):
    """ This method encapsulates the actions needed to create a JMS Connection Factory for handling connections between communicators and queues.

Parameters:
clusterName - Name of the cluster to associate connection factory with in String format. If value is "none", server will be used instead of cluster
serverName - Name of server to associate connection factory with in String format.
jmsCFName - Name to use for connection factory in String format.
jmsCFJNDI - JNDI Identifier to use for connection factory in String format.
jmsCFDesc - Description of the connection factory in String format.
jmsCFType - Type of the connection factory in String format
SIBusName - Name of bus to associate connection factory with in String format.
provEndPoints - Provider of connection factory in String format
scope - Identification of object (such as server or node) in String format.
authAlias - Authentication alias for connection factory in String format
Returns:
No return value
"""
    m = "createSIBJMSConnectionFactory: "
    #--------------------------------------------------------------------
    # Create SIB JMS connection factory
    #--------------------------------------------------------------------
    if(clusterName == "none"):
        jmsCF = AdminConfig.getid('/Server:%s/J2CResourceAdapter:SIB JMS Resource Adapter/J2CConnectionFactory:%s' % (serverName,jmsCFName))
    else:
        jmsCF = AdminConfig.getid('/ServerCluster:%s/J2CResourceAdapter:SIB JMS Resource Adapter/J2CConnectionFactory:%s' % (clusterName,jmsCFName))
    #endElse
    if (len(jmsCF) != 0):
        sop(m, "The %s JMS connection factory already exists." % jmsCFName)
        return
    #endIf

    #--------------------------------------------------------------------
    # Create the SIB JMS connection factory
    #--------------------------------------------------------------------
    params = ["-name", jmsCFName, "-jndiName", jmsCFJNDI, "-busName", SIBusName, "-description", jmsCFDesc]
    if(not(jmsCFType == "")):
        params.append("-type")
        params.append(jmsCFType)
    #endIf
    if(not(provEndPoints == "")):
        params.append("-providerEndPoints")
        params.append(provEndPoints)
    #endIf
    if(not(authAlias == "")):
        params.append("-containerAuthAlias")
        params.append(authAlias)
    #endIf

    AdminTask.createSIBJMSConnectionFactory(scope, params)
#endDef

def createSIBJMSQueue(jmsQName, jmsQJNDI, jmsQDesc, SIBQName, scope):
    """ This method encapsulates the actions needed to create a JMS Queue for messages.

Parameters:
jmsQName - Name to use for queue in String format.
jmsQJNDI - JNDI Identifier to use for queue in String format.
jmsQDesc - Description of the queue in String format.
SIBQName - Queue Name value used in protocol in String format
scope - Identification of object (such as server or node) in String format.
Returns:
No return value
"""
    m = "createSIBJMSQueue: "
    #--------------------------------------------------------------------
    # Create SIB JMS queue
    #--------------------------------------------------------------------
    for queue in _splitlines(AdminTask.listSIBJMSQueues(scope)):
       name = AdminConfig.showAttribute(queue, "name")
       if (name == jmsQName):
           sop(m, "The %s SIB JMS queue already exists." % jmsQName)
           return
       #endIf
    #endFor

    params = ["-name", jmsQName, "-jndiName", jmsQJNDI, "-description", jmsQDesc, "-queueName", SIBQName]
    AdminTask.createSIBJMSQueue(scope, params)
#endDef

def createSIBQueue(clusterName, nodeName, serverName, SIBQName, SIBusName):
    """ This method encapsulates the actions needed to create a queue for the Service Integration Bus.

Parameters:
clusterName - Name of the cluster to associate queue with in String format. If value is "none", server-node will be used instead of cluster
nodeName - Name of node containing server to associate queue with in String format.
serverName - Name of server to associate queue with in String format.
SIBQName - Name of queue to create in String format
SIBusName - Name of bus to associate queue with in String format.
Returns:
No return value
"""
    m = "createSIBQueue: "
    #--------------------------------------------------------------------
    # Create SIB queue
    #--------------------------------------------------------------------
    for queue in _splitlines(AdminConfig.list("SIBQueue")):
        identifier = AdminConfig.showAttribute(queue, "identifier")
        if (identifier == SIBQName):
            sop(m, "The %s SIB queue already exists." % SIBQName)
            return
        #endIf
    #endFor

    #--------------------------------------------------------------------
    # Create SIB queue
    #--------------------------------------------------------------------
    if(clusterName == "none"):
        params = ["-bus", SIBusName, "-name", SIBQName, "-type", "Queue", "-node", nodeName, "-server", serverName]
    else:
        params = ["-bus", SIBusName, "-name", SIBQName, "-type", "Queue", "-cluster", clusterName]
    #endElse
    AdminTask.createSIBDestination(params)
#endDef

def createSIBJMSTopic(jmsTName, jmsTJNDI, jmsTDesc, SIBTName, SIBTopicSpace, scope):
    """ This method encapsulates the actions needed to create a JMS Topic.

Parameters:
jmsTName - Name of topic in String format
jmsTJNDI - JNDI Identifier of topic in String format
jmsTDesc - Description of topic in String format
SIBTName - Topic name value used in SIB in String format
SIBTopicSpace - Topic space value used in SIB in String format
scope - Identification of object (such as server or node) in String format.
Returns:
No return value
"""
    m = "createSIBJMSTopic: "
    #--------------------------------------------------------------------
    # Create SIB JMS topic
    #--------------------------------------------------------------------
    for topic in _splitlines(AdminTask.listSIBJMSTopics(scope)):
        name = AdminConfig.showAttribute(topic, "name")
        if (name == jmsTName):
            sop(m, "The %s SIB JMS topic already exists." % jmsTName)
            return
        #endIf
    #endFor

    params = ["-name", jmsTName, "-jndiName", jmsTJNDI, "-description", jmsTDesc, "-topicName", SIBTName, "-topicSpace", SIBTopicSpace]
    AdminTask.createSIBJMSTopic(scope, params)
#endDef

def createSIBTopic(clusterName, nodeName, serverName, SIBTName, SIBusName):
    """ This method encapsulates the actions needed to create a topic for the Service Integration Bus.

Parameters:
clusterName - Name of the cluster to associate topic with in String format. If value is "none", server-node will be used instead of cluster
nodeName - Name of node containing server to associate topic with in String format.
serverName - Name of server to associate topic with in String format.
SIBQName - Name of topic to create in String format
SIBusName - Name of bus to associate topic with in String format.
Returns:
No return value
"""
    m = "createSIBTopic: "
    #--------------------------------------------------------------------
    # Create SIB topic
    #--------------------------------------------------------------------
    for topic in _splitlines(AdminConfig.list("SIBTopicSpace")):
        identifier = AdminConfig.showAttribute(topic, "identifier")
        if (identifier == SIBTName):
            sop(m, "The %s SIB topic already exists." % SIBTName)
            return
        #endIf
    #endFor

    #--------------------------------------------------------------------
    # Create SIB topic
    #--------------------------------------------------------------------
    if(clusterName == "none"):
        params = ["-bus", SIBusName, "-name", SIBTName, "-type", "TopicSpace", "-node", nodeName, "-server", serverName]
    else:
        params = ["-bus", SIBusName, "-name", SIBTName, "-type", "TopicSpace", "-cluster", clusterName]
    #endElse
    AdminTask.createSIBDestination(params)
#endDef

def createSIBJMSActivationSpec(activationSpecName, activationSpecJNDI, jmsQJNDI, destinationType, messageSelector, authAlias, SIBusName, scope):
    """ This method encapsulates the actions needed to create a JMS Activation Specification.

Parameters:
activationSpecName - Name of activation spec in String format
actiovationSpecJNDI - JNDI Identifier of activation spec in String format
jmsQJNDI - JNDI Identifier of the JMS queue to associate spec with in String format
destinationType - Type of destination end point in String format
messageSelector - Identifier of the message selector in String format
authAlias - Authentication alias for activation spec in String format
SIBusName - Name of bus to connect activation spec to in String format
scope - Identification of object (such as server or node) in String format.
Returns:
No return value
"""
    m = "createSIBJMSActivationSpec: "

    for spec in _splitlines(AdminTask.listSIBJMSActivationSpecs(scope)):
        name = AdminConfig.showAttribute(spec, "name")
        if (name == activationSpecName):
            sop(m, "The %s SIB JMS activation spec already exists." % activationSpecName)
            return
        #endIf
    #endFor

    #--------------------------------------------------------------------
    # Create SIB JMS activation spec
    #--------------------------------------------------------------------
    params = ["-name", activationSpecName, "-jndiName", activationSpecJNDI, "-busName", SIBusName, "-destinationJndiName", jmsQJNDI, "-destinationType", destinationType]
    if(not(authAlias == "")):
        params.append("-authenticationAlias")
        params.append(authAlias)
    #endIf
    if(not(messageSelector == "")):
        params.append("-messageSelector")
        params.append(messageSelector)
    #endIf
    AdminTask.createSIBJMSActivationSpec(scope, params)
#endDef

def deleteSIBJMSConnectionFactory(jmsCFName, clusterName, serverName):
    """ This method encapsulates the actions needed to delete a SIB JMS Connection Factory.

Parameters:
jmsCFName - Name of connection factory in String format.
clusterName - Name of the cluster to associate queue with in String format. If value is "none", server will be used instead of cluster.
serverName - Name of server to associate queue with in String format.
Returns:
No return value
"""
    m = "deleteSIBJMSConnectionFactory: "
    #--------------------------------------------------------------------
    # Retrieve specific Object ID and remove Connection Factory using ID
    #--------------------------------------------------------------------
    if(clusterName == "none"):
        jmsCF = AdminConfig.getid('/Server:%s/J2CResourceAdapter:SIB JMS Resource Adapter/J2CConnectionFactory:%s' % (serverName,jmsCFName))
    else:
        jmsCF = AdminConfig.getid('/Cluster:%s/J2CResourceAdapter:SIB JMS Resource Adapter/J2CConnectionFactory:%s' % (clusterName,jmsCFName))
    #endElse
    if(not(jmsCF == "")):
        AdminConfig.remove(jmsCF)
        sop(m, "Deleted connection factory %s" % jmsCFName)
    else:
        sop(m, "ConnectionFactory %s not found" % jmsCFName)
    #endElse
#endDef

def deleteSIBJMSActivationSpec(jmsASName, clusterName, serverName):
    """ This method encapsulates the actions needed to delete a SIB JMS Activation Specification.

Parameters:
jmsASName - Name of activation spec in String format.
clusterName - Name of the cluster to associate queue with in String format. If value is "none", server will be used instead of cluster.
serverName - Name of server to associate queue with in String format.
Returns:
No return value
"""
    m = "deleteSIBJMSActivationSpec: "
    #--------------------------------------------------------------------
    # Retrieve specific Resource Adapter Type ID for SIB JMS Resource Adapter
    #--------------------------------------------------------------------
    if(clusterName == "none"):
        ra = AdminConfig.getid('/Server:%s/J2CResourceAdapter:SIB JMS Resource Adapter' % serverName)
    else:
        ra = AdminConfig.getid('/Cluster:%s/J2CResourceAdapter:SIB JMS Resource Adapter' % clusterName)
    #endElse

    #--------------------------------------------------------------------
    # Remove the Activation Spec found in the SIB JMS Resource Adapter
    #--------------------------------------------------------------------
    for spec in _splitlines(AdminTask.listJ2CActivationSpecs(ra, ["-messageListenerType", "javax.jms.MessageListener"])):
        name = AdminConfig.showAttribute(spec, "name")
        if (name == jmsASName):
            AdminConfig.remove(spec)
            sop(m, "Deleted ActivationSpec %s" % jmsASName)
            return
        #endIf
    #endFor

    sop(m, "ActivationSpec %s not found" % jmsASName)
#endDef

def deleteSIBJMSQueue(qName, scope):
    """ This method encapsulates the actions needed to delete a SIB JMS Queue.

Parameters:
qName - Name of JMS queue in String format.
scope - Identification of object (such as server or node) in String format.
Returns:
No return value
"""
    m = "deleteSIBJMSQueue: "
    #--------------------------------------------------------------------
    # Search for queue based on scope and delete
    #--------------------------------------------------------------------
    for queue in _splitlines(AdminTask.listSIBJMSQueues(scope)):
        name = AdminConfig.showAttribute(queue, "name")
        if (name == qName):
            AdminTask.deleteSIBJMSQueue(queue)
            sop(m, "Deleted jms queue %s" % qName)
            return
        #endIf
    #endFor
#endDef

def deleteSIBJMSTopic(tName, scope):
    """ This method encapsulates the actions needed to delete a SIB JMS Topic.

Parameters:
tName - Name of JMS queue in String format.
scope - Identification of object (such as server or node) in String format.
Returns:
No return value
"""
    m = "deleteSIBJMSTopic: "
    #--------------------------------------------------------------------
    # Search for topic based on scope and delete
    #--------------------------------------------------------------------
    for topic in _splitlines(AdminTask.listSIBJMSTopics(scope)):
        name = AdminConfig.showAttribute(topic, "name")
        if (name == tName):
            AdminTask.deleteSIBJMSTopic(topic)
            sop(m, "Deleted jms topic %s" % tName)
            return
        #endIf
    #endFor
#endDef

def deleteSIBQueue(qName, SIBusName):
    """ This method encapsulates the actions needed to delete a SIB Queue.

Parameters:
qName - Name of SIB queue in String format.
SIBusName - Name of the bus the queue is associated with in String format.
Returns:
No return value
"""
    m = "deleteSIBQueue: "
    #--------------------------------------------------------------------
    # Search for queue based on scope and delete
    #--------------------------------------------------------------------
    params = ["-bus", SIBusName, "-name", qName]
    scope = ["-bus", SIBusName, "-type", "Queue"]

    if(not(re.compile(SIBusName, 0).search(AdminTask.listSIBuses())==None)):
        for q in _splitlines(AdminTask.listSIBDestinations(scope)):
            name = AdminConfig.showAttribute(q, "identifier")
            if (name == qName):
                AdminTask.deleteSIBDestination(params)
                sop(m, "Deleted destination %s" % qName)
                return
            #endIf
        #endFor
    #endIf
#endDef

def deleteBus(SIBusName):
    """ This method encapsulates the actions needed to delete a Service Integration Bus.

Parameters:
SIBusName - Name of the bus to delete in String format
Returns:
No return value
"""
    m = "deleteBus: "
    #--------------------------------------------------------------------
    # Search for bus using the provided bus name
    #--------------------------------------------------------------------
    for bus in _splitlines(AdminTask.listSIBuses()):
        name = AdminConfig.showAttribute(bus, "name")
        if (name == SIBusName):
            params = ["-bus", SIBusName]
            AdminTask.deleteSIBus(params)
            sop(m, "deleted SIBus %s" % SIBusName)
            return
        #endIf
    #endFor
#endDef

Open in new window

#---------------------------------------------------------------------
# Name: sop()
# Role: Display the specified message
#---------------------------------------------------------------------
def sop( callerName, message ) :
  print '%s(): %s' % ( callerName, message )

Open in new window

Thanks but I don't need to create the bus nor the members etc. I just need to create a queue and a destination.
Something like
aa=AdminTask.createSIBDestination('[-bus '+busName+' -name '+names[d]+' -type '+QType+' '+installScope+' -description '+str(destinationRetries)+']')

and
ab=AdminTask.createSIBJMSQueue(resourceScopeLevel, '[-name '+queueDefs[q]+' -jndiName '+qJndi[q]+' -description  -queueName '+queueNames[q]+' -deliveryMode Application -busName '+busName+']')

The user would be prompted to enter the queue name, jndi, busName and installScope they want.  
so from websphere console I am trying to achieve/add a queue here
Resources > JMS > Queue
If you look at a queue things to consider are:
Scope, Name, JNDI name, Bus Name, Queue name (which would be the same as name), delivery mode

and a destination in the SIBus > Bus name > Destinations (should be a queue) with the same queue name as above, because I am trying to assign the queue to the bus.

Thanks.
Wow, the "help text" for AdminTask.createSIBDestionation shows just how complicated a call to this method can be.

Reformatted for easier reading:

Using that, and your example statement in https://www.experts-exchange.com/questions/27308733/Jython-script-to-create-a-queue.html?anchorAnswerId=36544706#a36544706

I would probably create a routine something like the one shown below.
However, it is very terse, and doesn't really include any error checking, so I would be likely to add parameter value check (especially for stuff like "type", and the optional reliability parameter values)
WASX8006I: Detailed help for command: createSIBDestination

Description: Create bus destination.

Target object:   None

Arguments:
  *bus             - Name of the bus where this destination is to be configured.
  *name            - Destination name.
  *type            - Destination type
                     (Alias | Foreign | Port | Queue | TopicSpace | WebService).
   cluster         - To assign the destination to a cluster, supply cluster name,
                     but not node and server name or WebSphere MQ server name.
   node            - To assign the destination to a server, supply node name
                     server name, but not cluster name or WebSphere MQ server
                     name.
   server          - To assign the destination to a server, supply node name
                     server name, but not cluster name or WebSphere MQ server
                     name.
   wmqServer       - To assign the destination to a WebSphere MQ server, supply
                     a WebSphere MQ server name, but not node, server name or
                     cluster name.
   aliasBus        - If this is an alias destination, the source bus name of
                     alias mapping.
   targetBus       - If this is an alias destination, the name of the bus that
                     the destination it maps to is configured on.
   targetName      - If this is an alias destination, the name of the
                     destination it maps to.
   foreignBus      - If this is a foreign destination, the name of the foreign
                     bus.
   description     - Description.
   reliability     - The quality of service for message flows through this
                     destination, from BEST_EFFORT_NON-PERSISTENT to
                     ASSURED_PERSISTENT, in order of increasing reliability.
                     Higher levels of reliability have higher impacts on the
                     performance.
   maxReliability  - The maximum reliability quality of service that is accepted
                     for values specified by producers.
   nonPersistentReliability
                   - The quality of service used for inbound messages which
                     WebSphere MQ regards as being non-persistent.  Allowable
                     values are { BEST_EFFORT_NONPERSISTENT |
                     EXPRESS_NONPERSISTENT | RELIABLE_NONPERSISTENT |
                     RELIABLE_PERSISTENT | ASSURED_PERSISTENT }.
   persistentReliability
                   - The quality of service used for inbound messages which
                     WebSphere MQ regards as being persistent.  Allowable values
                     are { BEST_EFFORT_NONPERSISTENT | EXPRESS_NONPERSISTENT |
                     RELIABLE_NONPERSISTENT | RELIABLE_PERSISTENT |
                     ASSURED_PERSISTENT }.
   overrideOfQOSByProducerAllowed
                   - Controls the quality of service for message flows between
                     producers and the destination. Select this option to use
                     the quality of service specified by producers instead of
                     the quality defined for the destination.
   defaultPriority - The default priority for message flows through this
                     destination, in the range 0 (lowest) through 9 (highest).
                     This default priority is used for messages that do not
                     contain a priority value.
   maxFailedDeliveries
                   - The maximum number of times that service tries to deliver a
                     message to the destination before forwarding it to the
                     exception destination.
   exceptionDestination
                   - The name of another destination to which the system sends a
                     message that cannot be delivered to this destination within
                     the specified maximum number of failed deliveries.
   sendAllowed     - Clear this option (setting it to false) to stop producers
                     from being able to send messages to this destination.
   receiveAllowed  - Clear this option (setting it to false) to prevent consumers
                     from being able to receive messages from this destination.
   receiveExclusive
                   - Select this option (setting it to true) to allow only one
                     consumer to attach to a destination.
   maintainStrictMessageOrder
                   - Select this option (setting it to true) to enforce message
                     order for this destination.
   topicAccessCheckRequired - Topic access check required.
   replyDestination
                   - The name of the destination for reply messages.
   replyDestinationBus
                   - The name of the bus on which the reply destination is
                     configured.
   delegateAuthorizationCheckToTarget
                   - Indicates whether the authorization check should be
                     delegated to the alias or target destination.
   wmqQueueName    - The name of the WebSphere MQ queue for messages.  This
                     must be specified with the WebSphere MQ server name, but
                     not node, server name or cluster name.
   useRFH2         - Determines if messages sent to the WebSphere MQ destination
                     have an RFH2 header or not.  This must be specified with the
                     WebSphere MQ server name, but not node, server name or
                     cluster name.
   auditAllowed    - Used to allow or prevent the bus from auditing topic level
                     authorization checks when the bus and application server
                     have auditing enabled.
   blockedRetryTimeout
                   - Override the blocked destination retry interval configured
                     on the messaging engine owning the destination.
   mqRfh2Allowed   - If selected, messages sent to WebSphere MQ will include an
                     RFH2 header. The RFH2 header stores additional information
                     to that which is stored in the WebSphere  MQ message header.

Steps:
   defaultForwardRoutingPath
                   - Default forward routing path.
   queuePoints     - A list of the queue points that will be used by users of
                     the alias destination
   mediationPoints - A list of the mediation points that will be used by users
                     of the alias destination

Open in new window

def createSIBDestination( busName, name, Type, scope, scopeName, desc = None ) :
  return AdminTask.createSIBDestination( [ item for item in [ [ '-bus', busName ], [ '-name', name   ], [ '-type', Type ], [ '-' + scope, scopeName ], [ '-description', desc ] ] if item[ 1 ] ] )

Open in new window

Thanks HonorGod looks more like what I require.
But what about the createQueue? Is your script creating both the destination and the queue.

Also could u help with providing me with the complete script including the variable where the user would substitute their values (jndi name, queue name etc)

I actually want to run it and see if the queue gets created in the 2 places, namely Resources > JMS and SIB > Destination as expected.

Much appreciated.
That is a simple function example for one way to create the SIB destination.

I wanted to make sure that we were in agreement about the direction being taken.

> Also could u help with providing me with the complete script including the variable where the user would substitute their values (jndi name, queue name etc)

Yes.  That's the direction we're trying to go.

ASKER CERTIFIED SOLUTION
Avatar of amughal7
amughal7

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That's great news.
scripted correctly