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







Beanrsc

print

Action : tom.beanrsc   (Category : tom, Name : beanrsc, By : kikonf)
Complete Name : tom.beanrsc.by.kikonf
Version : 4.0        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 beanrsc plugin : This Action configures a Tomcat Bean Factory Resource.

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

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(name, level=None, indent=None, logFile=None):
    verbose('JavaBean Factory ResourceLink:' + name + ' Removing.', level=level, ifLevel=4, indent=indent, logFile=logFile)
    var name = name
    %delete ResourceLink where global = ${name}
    
    if ro!=None:n=len(ro)
    else:n=0    
    if n>0:verbose('JavaBean Factory ResourceLink:' + name + ' Removed:' + str(n) + ' configuration Entry.', level=level, ifLevel=3, indent=indent, logFile=logFile)

def rmvBeanRsc(name, level=None, indent=None, logFile=None):
    verbose('JavaBean Factory Resource:' + name + ' Removing.', level=level, ifLevel=4, indent=indent, logFile=logFile)
    var name = name
    %delete Resource where  name = ${name}
    
    if ro!=None:n=len(ro)
    else:n=0    
    if n>0:verbose('JavaBean Factory Resource:' + name + ' 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 """
    beanrsc_attrs=top_node.getAttrs()
    verbose('JavaBean Factory ResourceLink:' + beanrsc_attrs.name + ' Creating.', level=level, ifLevel=4, indent=indent, logFile=logFile)
    
    # link node
    link_attrs=top_node.getNode('link')[0].getAttrs()
    
    attrs={'global': beanrsc_attrs.name, 'name': link_attrs.name, 'type':beanrsc_attrs.btype}
    
    # creates
    target_node.newNode('ResourceLink', **attrs)
    verbose('JavaBean Factory ResourceLink:' + beanrsc_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 JavaBean Factory Resource """
    beanrsc_attrs=top_node.getAttrs()
    verbose('JavaBean Factory Resource:' + beanrsc_attrs.name + ' Creating.', level=level, ifLevel=4, indent=indent, logFile=logFile)
    attrs={}
    
    # resource node
    resource_node=top_node.getNode('resource')[0]
    resource_attrs=resource_node.getAttrs()
    
    #- guess auth
    if resource_attrs.auth=='true':auth='Container'
    else:auth='Application'
    
    attrs.update({
        'name' : beanrsc_attrs.name,
        'auth' : auth,
        'type' : beanrsc_attrs.btype
    })
    
    attrs['factory']='org.apache.naming.factory.BeanFactory'    
    
    # properties node
    if resource_node.hasNode('properties'):
        properties_node=resource_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('Resource', **attrs)
    verbose('JavaBean Factory Resource:' + beanrsc_attrs.name + ' 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 !')
    beanrsc_attrs=self_action.getTop().getAttrs()
        
    ## Creates the ResourceLink
    print
    print '## Creates the JavaBean Factory ResourceLink'

    if self_action.getTop().hasNode('link'):
        rmvLink(beanrsc_attrs.name, 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 JavaBean Factory Resource
    if self_action.getTop().hasNode('resource'):
        print
        print '## Creates the JavaBean Factory Resource'
        
        
        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
            # interv 01 + :cd /
            :cd /
            :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
            
            rmvBeanRsc(beanrsc_attrs.name, 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
            if scope_attrs['resources.global']=='true':
                :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
            
            rmvBeanRsc(beanrsc_attrs.name, 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/beanrsc/by/kikonf/beanrsc.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