cle_clock
Home > wikikonf >  was/actions/by kikonf > jmq







Jmq

print

Action : was.jmq   (Category : was, Name : jmq, By : kikonf)
Complete Name : was.jmq.by.kikonf
Version : 5.0        License : Modified BSD License

Purpose of the was category :
Easy to customize. This category use in background the wsadmin command in jython mode (through AdminConfig, AdminControl and AdminTask), to drive WebSphere Application Server ® configuration.
You can use it to manage the whole WebSphere ® architecture.

Purpose of this jmq plugin : Creates one or more Queue Connection Factory(ies), Queue(s) and Activation Spec(s)

The following shows the main Source Code File for the Action : was.jmq

Toggle lines
##  Copyright (c) 2008, Patrick Germain Placidoux
##  All rights reserved.
##
##  This file is part of Kikonf Public Software.
##
##  Kikonf Public Software is released under the modified BSD License,
##  which should accompany it or any part of it in the file "COPYING".
##  If you do not have this file you can access the license 
##  through the WWW at http://www.kikonf.org/license/bsd/license.txt.
## 
##  Home: http://www.kikonf.org
##  Contact: kikonf@gmx.com



from actions.was.tools import *



class Jmq(wasAction):
    PROVIDER='WebSphere MQ JMS Provider'

    def init(self):
        self.__jpvd=None
        
    def extract(self, scope_attrs=None, prefix=None, **keywords):
        self_funct='extract'
        scope_id, scope_attrs, scope=self.getScope(scope_attrs=scope_attrs, indent=self.getIndent())
        version=self.getCAttr('software_was_version')
        self.verbose(scope_attrs, prefix=prefix)
        indent=self.getIndent() + 3*' '

        jmq_node=self.newTop() #-- because in extract mode, each call returns a new blank top node.
    
        jmq_node.setAttrs(prefix=prefix)
    
        mkNodeScope(jmq_node, scope_attrs, isUnique=True) #-- creates a scope node.


        all_acs = {} #-- Preparing activation Spec dict
        if version[:3]>='7.0':
            all_ok_acs = [] 

            verbose('WMQActivationSpecs listing.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
            acs=split( AdminConfig.listWMQActivationSpecs(scope_id) )        
            for activation_specs in acs:
                activation_specs=getShowAsDict(activation_specs)
                
                if prefix!=None and not activation_specs['name'].startswith(prefix):continue
                verbose('WMQActivationSpec:' + activation_specs['name'] + ' listed.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile())
                
                all_acs[AdminConfig.showAttribute(ac, 'destinationJndiName')]=activation_specs

        verbose('MQQueueConnectionFactory listing.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
        
        qcfs = getStartByNameAsDict(split( AdminConfig.getid(self.getScopeCP() + '/JMSProvider:' + Jmq.PROVIDER + '/MQQueueConnectionFactory:/') )) # Tag: qcfs
        qcfs_node=jmq_node.newNode('qcfs')
        
        for qcfname in qcfs.keys():
            if prefix!=None and not qcfname.startswith(prefix):continue
            
            qcfactories=getShowAsDict(AdminConfig.show(qcfs[qcfname]))
            
            verbose('MQQueueConnectionFactory:' + qcfname + ' retreived.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile())            
            _name=qcfname
            if prefix!=None:_name=qcfname.split(prefix + '_')[1]

            attrs={
                'name':_name,
                'jndi_name':qcfactories['jndiName'],
                'channel':qcfactories['channel'],
                'queue_manager': qcfactories['queueManager'],
                'host':qcfactories['host'],
                'port':qcfactories['port'],
                'xa':qcfactories['XAEnabled'],
                'transport_type':qcfactories['transportType'],
                'pollint':qcfactories['pollingInterval'],
            }
            
            if qcfactories.has_key('description') and qcfactories['description']!=None:attrs['desc']=qcfactories['description'][1:-1]
            else:attrs['desc']=None
            if attrs['desc']==DESIGN_NOTICE:attrs['desc']=None
            
            if qcfactories.has_key('CCSID'):attrs['ccsid']=qcfactories['CCSID']
            
            qcf_node=qcfs_node.newNode('qcf', **attrs)
            
            connection_pool_node=qcf_node.newNode('connection_pool')             # Tag: qcfs/qcf/connectionPool
            indent=self.getIndent() + 3*' '
            getConnectionPoolAttrs(qcfactories['connectionPool'], connection_pool_node, level=self.getVerbose(), indent=indent, logFile=self.getLogFile())

        verbose('JMSProvider listing.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
        qs=getStartByNameAsDict(split( AdminConfig.getid(self.getScopeCP() + '/JMSProvider:' + Jmq.PROVIDER + '/MQQueue:/') )) # Tag: Queues
        queues_node=jmq_node.newNode('queues') 
    
        for qname in qs.keys():
            if prefix!=None and not qname.startswith(prefix):continue
            queues=getShowAsDict(AdminConfig.show(qs[qname]))
            verbose('MQQueue:' + qname + ' retreived.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile())
            _name=qname
            if prefix!=None:_name=qname.split(prefix + '_')[1]
            
            attrs={
                'name':_name,
                'queue':queues['baseQueueName'],
                'jndi_name':queues['jndiName'],
                'target':queues['targetClient'],
                'expiry':queues['specifiedExpiry'],       
            }            
            

            if queues.has_key('description') and queues['description']!=None:attrs['desc']=queues['description'][1:-1]
            else:attrs['desc']=None
            if attrs['desc']==DESIGN_NOTICE:attrs['desc']=None
            
            if queues.has_key('serverConnectionChannelName'):attrs['channel']=queues['serverConnectionChannelName']
            if queues.has_key('queueManagerHost'):attrs['host']=queues['queueManagerHost']
            if queues.has_key('queueManagerPort'):attrs['port']=queues['queueManagerPort']
            if queues.has_key('CCSID'):attrs['ccsid']=queues['CCSID']
            if queues.has_key('baseQueueManagerName'):attrs['queue_manager']=queues['baseQueueManagerName']
            
##            print 'attrs:::', attrs
            queue_node=queues_node.newNode('queue', **attrs) 
            indent=self.getIndent() + 3*' '

            
            jndi_name=attrs['jndi_name'] # Associated Activation Specs
            if jndi_name in all_acs.keys():
                activation_specs=getShowAsDict(all_acs[jndi_name])
                all_ok_acs.append(activation_specs['name'])
                self.extCheckActMatchingQ(activation_specs, qs)
                _name=activation_specs['name']
                if prefix!=None:_name=activation_specs['name'].split(prefix + '_')[1]
            
                attrs={                                                         # Tag: Queues/Queue/Activation Spec
                    'name':_name,
                    'jndi_name':activation_specs['jndiName'],
                }
                
                if activation_specs.has_key('description') and activation_specs['description']!=None:attrs['desc']=activation_specs['description'][1:-1]
                else:attrs['desc']=None
                if attrs['desc']==DESIGN_NOTICE:attrs['desc']=None
                if activation_specs.has_key('qmgrSvrconnChannel'):attrs['channel']=activation_specs['qmgrSvrconnChannel']
                if activation_specs.has_key('qmgrName'):attrs['queue_manager']=activation_specs['qmgrName']
                if activation_specs.has_key('qmgrHostname'):attrs['host']=activation_specs['qmgrHostname']
                if activation_specs.has_key('qmgrPortNumber'):attrs['port']=activation_specs['qmgrPortNumber']
                if activation_specs.has_key('CCSID'):attrs['ccsid']=activation_specs['CCSID']
                if activation_specs.has_key('maxPoolSize'):attrs['max_pool']=activation_specs['maxPoolSize']
                
                queue_node.newNode('activation_spec', **attrs)         

        if version[:3]>='7.0':self.extListActNotMatchingQ(all_acs, all_ok_acs)

    def remove(self, no_name, no_name_no_prefix):
        jmq_node=self.getTop()        
        jmq_attrs = jmq_node.getAttrs()
        scope_id, scope_attrs, scope=self.getScope(parent_node=jmq_node, indent=self.getIndent())
        self.verbose(scope_attrs, prefix=jmq_attrs.prefix)
        indent=self.getIndent() + 3*' '
        
        # Removing all Qcfs/Queues/Acs starting by prefix
        if jmq_attrs.prefix!=None:
            #-- no_name/no_name_no_prefix
            prefix=jmq_attrs.prefix
            if no_name_no_prefix:prefix=None        

            self.rmvQcf(prefix=prefix, indent=indent)
            self.rmvQueue(prefix=prefix, indent=indent)
        else:

            # Removing  Qcfs
            pvd=self.getProvider(indent=indent)
            
            if jmq_node.hasNode('qcfs'):
                qcf_nodes=jmq_node.getNode('qcfs')[0].getNodes()
                
                for qcf_node in qcf_nodes:
                    qcf_attrs = qcf_node.getAttrs()
                    #-- no_name/no_name_no_prefix
                    name=qcf_attrs.name
                    if no_name or no_name_no_prefix:name=None
                
                    self.rmvQcf(name=name, indent=indent)
            
            # Removing  Queues and Acs
            if jmq_node.hasNode('queues'):
                queue_nodes=jmq_node.getNode('queues')[0].getNodes()
                
                for queue_node in queue_nodes:
                    queue_attrs = queue_node.getAttrs()
                    #-- no_name/no_name_no_prefix
                    name=queue_attrs.name
                    if no_name or no_name_no_prefix:name=None
                    
                    self.rmvQueue(name=name, indent=indent)

    def inject(self):
        self_funct='inject'
        jmq_node = self.getTop()        
        jmq_attrs = jmq_node.getAttrs()
        scope_id, scope_attrs, scope=self.getScope(parent_node=jmq_node, indent=self.getIndent())
        self.verbose(scope_attrs, prefix=jmq_attrs.prefix)
        indent=self.getIndent() + 3*' '

        #-- Removing all qcfs starting by prefix
        if jmq_attrs.prefix!=None:self.rmvQcf(prefix=jmq_attrs.prefix, indent=self.getIndent())

        #-- Retreiving the WebSphere MQ JMS Provider
        pvd=self.getProvider(indent=indent)
        
        if jmq_node.hasNode('qcfs'):
            verbose('MQQueueConnectionFactory listing.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
            mqtpmpl=split( AdminConfig.listTemplates("MQQueueConnectionFactory") )[0]
            
            for qcf_node in jmq_node.getNode('qcfs')[0].getNodes():                
                qcf_attrs = qcf_node.getAttrs()
                if jmq_attrs.prefix!=None:name=jmq_attrs.prefix + '_' + qcf_attrs.name
                else:
                    name=qcf_attrs.name
                    #-- Removing all Qcf with name
                    self.rmvQcf(name=name, indent=indent)
                
                cmdvalues=[]
                cmdvalues.append(['name', name])
                
                if qcf_attrs.desc!=None:cmdvalues.append(['description', qcf_attrs.desc])
                else:cmdvalues.append(['description', DESIGN_NOTICE])
                
                cmdvalues.append(['jndiName', qcf_attrs.jndi_name])
                cmdvalues.append(['XAEnabled', qcf_attrs.xa])
                cmdvalues.append(['transportType', qcf_attrs.transport_type])
                cmdvalues.append(['pollingInterval', qcf_attrs.pollint])
                cmdvalues.append(['queueManager', qcf_attrs.queue_manager])
                cmdvalues.append(['host', qcf_attrs.host])
                cmdvalues.append(['port', qcf_attrs.port])
                cmdvalues.append(['channel', qcf_attrs.channel])
                cmdvalues.append(['CCSID', qcf_attrs.ccsid])
                
                if qcf_node.hasNode('connection_pool'):
                    conpool_node=qcf_node.getNode('connection_pool')[0]
                    cmdvalues.append(['connectionPool', getConnectionPoolCfgs(conpool_node, level=self.getVerbose(), indent=indent, logFile=self.getLogFile())])

                if len(cmdvalues)!=0:
                    verbose('MQQueueConnectionFactory listing.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
                    AdminConfig.createUsingTemplate('MQQueueConnectionFactory', pvd, cmdvalues, mqtpmpl)
                    verbose('MQQueueConnectionFactory:' + name + ' created.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile())
        
        self.injQueue(jmq_node.getNode('queues')[0].getNodes(), prefix=jmq_attrs.prefix, indent=indent)

    def rmvQcf(self, name=None, prefix=None, indent=None):
        verbose('JMSProvider listing.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
        qcfs=getStartByNameAsDict(split( AdminConfig.getid(self.getScopeCP() + '/JMSProvider:' + Jmq.PROVIDER + '/MQQueueConnectionFactory:/') ))

        for qcfname in qcfs.keys():
            if prefix!=None and qcfname.startswith(prefix) \
            or prefix==None and name!=None and qcfname==name \
            or prefix==None and name==None:
                verbose('MQQueueConnectionFactory:' + qcfname + ' removing.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
                AdminConfig.remove(qcfs[qcfname])
                verbose('MQQueueConnectionFactory:' + qcfname + ' removed.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile())

    def injQueue(self, nodes, prefix=None, indent=None):
        self_funct='injQueue'        
        # Removing all queues starting by prefix
        if prefix!=None:self.rmvQueue(prefix=prefix, indent=indent)
            
        verbose('MQQueue listing template.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
        qtmpl=split( AdminConfig.listTemplates('MQQueue') )[0]

        for queue_node in nodes:
            cmdvalues=[]
            queue_attrs = queue_node.getAttrs()
            if prefix!=None:name=prefix + '_' + queue_attrs.name
            else:
                name=queue_attrs.name
                # Removing all queues with name
                self.rmvQueue(name=name, indent=indent)

            cmdvalues.append(['name', name])
            
            if queue_attrs.desc!=None:cmdvalues.append(['description', queue_attrs.desc])
            else:cmdvalues.append(['description', DESIGN_NOTICE])
            
            cmdvalues.append(['jndiName', queue_attrs.jndi_name])
            cmdvalues.append(['baseQueueName', queue_attrs.queue])
            cmdvalues.append(['specifiedExpiry', queue_attrs.expiry])
            cmdvalues.append(['targetClient', queue_attrs.target])
            cmdvalues.append(['serverConnectionChannelName', queue_attrs.channel])
            if queue_attrs.queue_manager!=None:cmdvalues.append(['baseQueueManagerName', queue_attrs.queue_manager])
            if queue_attrs.host!=None:cmdvalues.append(['queueManagerHost', queue_attrs.host])
            if queue_attrs.port!=None:cmdvalues.append(['queueManagerPort', queue_attrs.port])
            if queue_attrs.ccsid!=None:cmdvalues.append(['CCSID', queue_attrs.ccsid])


            verbose('MQQueue:' + name + ' creating using template.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
            AdminConfig.createUsingTemplate('MQQueue', self.getProvider(indent=indent), cmdvalues, qtmpl)
            verbose('MQQueue:' + name + ' created.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile())
            
            if queue_node.hasNode('activation_spec'):
                version=self.getCAttr('software_was_version')
                if version[:3]<'7.0':raise xception.kikonfActionSystemException(self, self_funct, 'Because using AdminTask.createWMQActivationSpec Activation spec is not allowed for this WAS version:' + version + '. Version must be >=7.0.' )
                self.injActivationSpec(queue_node.getNode('activation_spec')[0], queue_attrs, prefix, indent=indent)

    def rmvQueue(self, name=None, prefix=None, indent=None):
        scope_id, scope_attrs, scope=self.getScope()
        verbose('MQQueue listing.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
        queues=getStartByNameAsDict(split( AdminConfig.list("MQQueue", scope_id) ))
            
        for qname in queues.keys():
            if prefix!=None and qname.startswith(prefix) \
            or prefix==None and name!=None and qname==name \
            or prefix==None and name==None:                
                self.rmvActivationSpec(jndiName=AdminConfig.showAttribute(queues[qname], 'jndiName'))
                verbose('MQQueue:' + qname + ' removing.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
                AdminConfig.remove(queues[qname])        
                verbose('MQQueue:' + qname + ' removed.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile())    

    def injActivationSpec(self, node, queue_attrs, prefix=None, indent=None):
        scope_id, scope_attrs, scope=self.getScope()
        cmdvalues=[]
        activation_spec_attrs = node.getAttrs()
        if prefix!=None:name=prefix + '_' + activation_spec_attrs.name
        else:name=activation_spec_attrs.name
        
        cmdvalues.append(['name', activation_spec_attrs.name])
        
        if activation_spec_attrs.desc!=None:cmdvalues.append(['description', activation_spec_attrs.desc]) 
        else:cmdvalues.append('description', DESIGN_NOTICE) 
        
        cmdvalues.append(['jndiName', activation_spec_attrs.jndi_name])
        cmdvalues.append(['destinationJndiName', queue_attrs.jndi_name])
        cmdvalues.append(['destinationType', queue_attrs.target])
        # cmdvalues.append(['wmqTransportType', transport_type])
        cmdvalues.append(['maxPoolSize', activation_spec_attrs.max_pool])
        cmdvalues.append(['qmgrSvrconnChannel', activation_spec_attrs.channel])
        cmdvalues.append(['qmgrName', activation_spec_attrs.queue_manager])
        cmdvalues.append(['qmgrHostname', activation_spec_attrs.host])
        cmdvalues.append(['qmgrPortNumber', activation_spec_attrs.port])
        cmdvalues.append(['CCSID', queue_attrs.ccsid])

        verbose('WMQActivationSpec creating.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
        AdminTask.createWMQActivationSpec(scope_id, cmdvalues)
        verbose('WMQActivationSpec:' + activation_spec_attrs.name + ' created.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile())
        
    def rmvActivationSpec(self, jndiName=None, prefix=None, indent=None):
        version=self.getCAttr('software_was_version')
        if version[:3]<'7.0':return
        
        scope_id, scope_attrs, scope=self.getScope()
        verbose('WMQActivationSpecs creating.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
        l=split( AdminConfig.listWMQActivationSpecs(scope_id) )
        
        for ac in l:
            acname=AdminConfig.showAttribute(ac, 'name')
            if prefix==None and jndiName!=None and jndiName==AdminConfig.showAttribute(ac, 'jndiName') \
            or prefix!=None and jndiName==None and acname.startswith(prefix) \
            or prefix==None and jndiName==None:
                
                verbose('WMQActivationSpec removing:' + acname + '.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
                AdminConfig.remove(ac)
                verbose('WMQActivationSpec:' + acname + ' removed.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile())
        
    def getProvider(self, indent=None):
        self_funct='getProvider'
        scope_id, scope_attrs, scope=self.getScope()
        if self.__jpvd!=None:return self.__jpvd
        
        verbose('JMSProvider retreiving.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
        
        self.__jpvd=AdminConfig.getid(self.getScopeCP() + '/JMSProvider:' + Jmq.PROVIDER + '/')
        if self.__jpvd in ('', None):raise xception.kikonfActionSystemException(self, self_funct, ' Unable to find the Provider:"' + Jmq.PROVIDER + '" for scope:' + str(scope_attrs) + '.' )
        
        return self.__jpvd
    
    def extCheckActMatchingQ(self, acs, qcfs, all_qs):
        if acs['ccsid']!=qs['ccsid']:
            mess_ac = 'Activation Spec name:' + acs['name'] + ' jndiName:' + acs['jndiName'] + '.'
            mess_q = 'Associated Queue name:' + qs['name'] + ' jndiName:' + qs['jndiName'] + '.'
            mess='Warning! Activation Spec "ccsid" do not match Queue "ccsid" !' 
            print mess
            print mess_ac
            print mess_q

    def extListActNotMatchingQ(self, all_acs, all_ok_acs):
        
        for activation_specs in all_acs:
            if activation_specs['name'] in all_ok_acs:continue
            mess_ac = 'Activation Spec name:' + activation_specs['name'] + ' jndiName:' + activation_specs['jndiName'] + '. Declaration skipped !'
        
            print 'Activation Spec "destinationJndiName" do not match any existing Queue "jndiName" !'
            print mess_ac
            
    def verbose(self, scope_attrs, name=None, prefix=None, logFile=None):
        scope=str(scope_attrs).replace("'", '')[1:-1]
        
        if prefix==None:verbose('MQQueueConnectionFactories,MQQueues,WMQActivationSpecs at scope:' + scope + '.', level=self.getVerbose(), ifLevel=2, indent=self.getIndent())
        else:verbose('MQQueueConnectionFactory,MQQueue,WMQActivationSpecs under prefix:' + prefix + ', at scope:' + scope + '.', level=self.getVerbose(), ifLevel=2, indent=self.getIndent())
							
(Source: <KIKONF_INSTALLATION_DIR>/plugins/actions/was/jmq/by/kikonf/jmq.py)


  • Line 1 to 3 say something , say something , say something
  • Line 10 to 17 say something , say something , say something , say something , say something
  • Line 20 to 25 say something



Trademarks :
  • "IBM WebSphere MQ" and "WebSphere MQ" are registred trademarks of International Business Machines Corporation.
  • "IBM", "WebSphere", "WebSphere Aplication Server", "WAS" are registred trademarks of International Business Machines Corporation.
  • "Java" and "JVM" are a registred trademarks of Oracle and/or its affiliates.
  • Other names may be trademarks of their respective owners.

Copyright © 2011 - Patrick Placidoux, Hélène Malamoud