cle_clock
Home > wikikonf >  tom/actions/by kikonf > trans







Trans

print

Action : tom.trans   (Category : tom, Name : trans, By : kikonf)
Complete Name : tom.trans.by.kikonf
Version : 5.5        License : Modified BSD License

Purpose of the tom category :
Easy to customize. This category use in background the Kikonf Repoz tools to create and configure Apache Tomcat о root installs and Catalina bases at any level (server.xml, hosts or defaults).
You can use it to manage the whole Tomcat о Architecture.

Purpose of this trans plugin : This Action configures a Tomcat Transaction.

The following shows the main Source Code File for the Action : tom.trans

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




#-------------------#
# Utility functions #
#-------------------#



def rmvLink(level=None, indent=None, logFile=None):
    verbose('UserTransaction ResourceLink Removing.', level=level, ifLevel=4, indent=indent, logFile=logFile)
    %delete ResourceLink where type=javax.transaction.UserTransaction
    
    if ro!=None:n=len(ro)
    else:n=0    
    if n>0:verbose('UserTransaction ResourceLink Removed:' + str(n) + ' configuration Entry.', level=level, ifLevel=3, indent=indent, logFile=logFile)

def rmvTrans(factory , level=None, indent=None, logFile=None):
    verbose('UserTransaction on factory:' + factory + ' Removing.', level=level, ifLevel=4, indent=indent, logFile=logFile)
    var factory = factory
    %delete Transaction where  factory = ${factory}
    
    if ro!=None:n=len(ro)
    else:n=0    
    if n>0:verbose('UserTransaction on factory:' + factory + ' Removed:' + str(n) + ' configuration Entry.', level=level, ifLevel=3, indent=indent, logFile=logFile)

def injLink(top_node, target_node, level=0, indent=None, logFile=None):
    """ Creates a ResourceLink """
    trans_attrs=top_node.getAttrs()
    
    # link node
    link_attrs=top_node.getNode('link')[0].getAttrs()
    
    verbose('UserTransaction ResourceLink:' + link_attrs.name + ' Creating.', level=level, ifLevel=4, indent=indent, logFile=logFile)
    
    attrs={'global': 'UserTransaction', 'name': link_attrs.name, 'type':'javax.transaction.UserTransaction'}
    
    # creates
    target_node.newNode('ResourceLink', **attrs)
    verbose('UserTransaction ResourceLink:' + link_attrs.name + ' Created.', level=level, ifLevel=3, indent=indent, logFile=logFile)

def injRsc(top_node, target_node, level=0, indent=None, logFile=None):
    """ Creates a Transaction """
    trans_attrs=top_node.getAttrs()
    verbose('UserTransaction Creating.', level=level, ifLevel=4, indent=indent, logFile=logFile)
    attrs={}
    
    # transrsc node
    transrsc_node=top_node.getNode('transrsc')[0]
    transrsc_attrs=transrsc_node.getAttrs()
    
    attrs['factory']=trans_attrs.factory
    attrs['type']='javax.transaction.UserTransaction'
    
    # properties node
    if transrsc_node.hasNode('properties'):
        properties_node=transrsc_node.getNode('properties')[0]
        if properties_node.hasNode('property'):
            property_nodes=properties_node.getNode('property')
            for property_node in property_nodes:
                property_attrs=property_node.getAttrs()
                attrs[property_attrs.name]=property_attrs.value
        
    # creates
    target_node.newNode('Transaction', **attrs)
    verbose('UserTransaction Created.', level=level, ifLevel=3, indent=indent, logFile=logFile)



#------#
# Main #
#------#


# Stores the Action File's Processor Alias
var source_action_alias=ro['alias']

# Stores the Action File's First Node <=> self_action.getTop()
:ls
source_action_node=ro[0]


try:

    ## Retreives the Scope
    print
    print '## Retreives the Scope'
    scope_name, scope_attrs, scope=self_action.getScope(parent_node=self_action.getTop(), indent=self_action.getIndent())
    self_action.verbose(scope_name=scope_name, scope_attrs=scope_attrs)    
    indent=self_action.getIndent() + 3*' '

    ## Stores the target Scope Processor Alias and mount it
    print '## Stores the target Scope Processor Alias and mount it'
    var target_scope_alias=scope.pc_ro['alias']
    :mount $target_scope_alias
    :ls
    target_node=ro[0]
    
    # Integrity check
    if self_action.getTop().hasNode('link') and not scope.type.startswith('context'):
        raise xception.kikonfActionSystemException(self_action, 'inject', 'Bad Scope:' + scope.type + ', When using Tag "link" A Scope "context" is required for this Action !')
    if scope.type!='resources.global' and not scope.type.startswith('context'):
        raise xception.kikonfActionSystemException(self_action, 'inject', 'Bad Scope:' + scope.type + ',Either a Scope "context" or "resource.global" is required for this Action !')
    if not scope_attrs['resources.global']=='true' and self_action.getTop().hasNode('link'):
        raise xception.kikonfActionSystemException(self_action, 'inject', 'Bad Scope:' + scope.type + ', When an entry link is used, "resources.global" equal true is required for the Scope !')
    trans_attrs=self_action.getTop().getAttrs()
        
    ## Creates the ResourceLink
    print
    print '## Creates the Transaction'

    if self_action.getTop().hasNode('link'):
        rmvLink(level=self_action.getVerbose(), indent=indent, logFile=self_action.getLogFile())
        injLink(self_action.getTop(), target_node, level=self_action.getVerbose(), indent=indent, logFile=self_action.getLogFile())
    
    ## Creates the Transaction
    if self_action.getTop().hasNode('transrsc'):
        print
        print '## Creates the Transaction'
        
        if scope_attrs['resources.global']=='true' and scope.type.startswith('context')  and scope.type!= 'context.global': # Changes the target scope to the global resource scope
            print '# Changes the target scope to the global resource scope'
            var target_root_scope_alias=scope.root_pc_ro['alias']
            :mount $target_root_scope_alias
            :ls
            target_node=ro[0]
            
            # Creates GlobalNamingResources if not exists
            if target_node.hasNode('GlobalNamingResources'):target_node=target_node.getNode('GlobalNamingResources')[0]
            else:target_node=target_node.newNode('GlobalNamingResources')
            :cd GlobalNamingResources
            
            rmvTrans(trans_attrs.factory, level=self_action.getVerbose(), indent=indent, logFile=self_action.getLogFile())
            injRsc(self_action.getTop(), target_node, level=self_action.getVerbose(), indent=indent, logFile=self_action.getLogFile())
            
        else: # target_scope is the rigth target for resource
            :cd /
            :ls
            target_node=ro[0]
            
            # Creates GlobalNamingResources if not exists
            if scope_attrs['resources.global']=='true':
                if target_node.hasNode('GlobalNamingResources'):target_node=target_node.getNode('GlobalNamingResources')[0]
                else:target_node=target_node.newNode('GlobalNamingResources')
                :cd GlobalNamingResources
            
            rmvTrans(trans_attrs.factory, level=self_action.getVerbose(), indent=indent, logFile=self_action.getLogFile())
            injRsc(self_action.getTop(), target_node, level=self_action.getVerbose(), indent=indent, logFile=self_action.getLogFile())

except Exception, e:
    
    _e=xception.kikonfActionSystemException(self_action, 'inject', 'An exception occures ! SubException is:' + str(e) + ' !')
    _e.setSubException(e)
    REPOZ.recordSessionException(self_action.getName(), _e)
    if self_action.getVerbose()>=10:raise
    # Dont forget to skipt a strict empty line at the end to let the Interpretor to interprete the End of the bloc !

							
(Source: <KIKONF_INSTALLATION_DIR>/plugins/actions/tom/trans/by/kikonf/trans.inject.repoz)


  • 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 :
  • "Apache", "Apache Tomcat" and "Tomcat" are trademarks of the Apache Software Foundation.
  • "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