pythonwebspherejythonwsadmin

A resource already exists


I have an XML list of queues. I configure them without problems with python script and wsadmin console. Now I want to add new queues to the existing list and create them. While creating, console recognizes that queues with JNDI names already exist, and then it stops script. how can I IGNORE resources that already exist and keep creating newly added queues

My python script

import sys
sys.modules['AdminConfig'] = AdminConfig
sys.modules['AdminControl'] = AdminControl
sys.modules['AdminApp'] = AdminApp
sys.modules['AdminTask'] = AdminTask
sys.modules['Help'] = Help
import myfunctions as fl

import xml.etree.ElementTree as ET
tree = ET.parse('queue_xml/queue.xml')
root = tree.getroot()

scopes = root.findall('.//scope')


def createqueue(server_id,ime,jndi,mqname):
    print(server_id)
    print("creating "+ime,jndi,mqname)
    print("-------------------------------------------")
    AdminTask.createWMQQueue(server_id,
                                 ['-name', ime,
                                 '-jndiName', jndi,
                                 '-queueName', mqname
                                  ]
                                  )                 

for scope in scopes:
        typee= scope.find('type').text
        scopename= scope.find('scopename').text
        qe = scope.findall('.//queue')
        for q in qe:
            ime = q.find('name').text
            jndi = q.find('jndi').text
            mqname = q.find('mqname').text
            x = fl.get_scope(typee, scopename)
            createqueue(x,ime,jndi,mqname)

AdminConfig.save()

XML script

<data>
<scope>
    <type>cluster</type>
    <scopename>TRX</scopename>
    <queue>
        <name>AuthenticFlagUpdate100</name>
        <jndi>jms/as/AuthenticFlagUpdate100</jndi>
        <mqname>GCWOD1.QU.CCMS.AUTH.FLAG.UPDATE100</mqname>
    </queue>
</scope>

<scope>
    <type>Servernode</type>
    <scopename>Node:somenode/Server:someserver</scopename>
    <queue>
        <name>AuthenticFlagUpdate230</name>
        <jndi>jms/as/AuthenticFlagUpdate230</jndi>
        <mqname>GCWOD1.QU.CCMS.AUTH.FLAG.UPDATE200</mqname>
    </queue>
</scope>

<scope>
    <type>Node</type>
    <scopename>somenode</scopename>
    <queue>
        <name>AuthenticFlagUpdate310 </name>
        <jndi>jms/as/AuthenticFlagUpdate310</jndi>
        <mqname>GCWOD1.QU.CCMS.AUTH.FLAG.UPDATE300</mqname>
    </queue>
</scope>
</data>

Solution

  • You could do this by first checking if the queue is already present in the server by listing all queues using "AdminTask.listWMQQueues", and skip the queue creation if it already exists.

    See the updated "createqueue" function with this change:

    def createqueue(server_id,ime,jndi,mqname):
        print(server_id)
        print("creating "+ime,jndi,mqname)
        print("-------------------------------------------")
        if AdminTask.listWMQQueues(server_id).find(ime) != -1:
            print ("Queue %s already exists, skip queue creation" % (ime) )
        else:
            AdminTask.createWMQQueue(server_id,
                                     ['-name', ime,
                                     '-jndiName', jndi,
                                     '-queueName', mqname
                                      ]
                                      )
        #end if
    #end def