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







Udbrsc

print

Action : tom.udbrsc   (Category : tom, Name : udbrsc, By : kikonf)
Complete Name : tom.udbrsc.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 udbrsc plugin : This Action configures a Tomcat User Database Resource.

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

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('UserDatabase 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('UserDatabase ResourceLink:' + name + ' Removed:' + str(n) + ' configuration Entry.', level=level, ifLevel=3, indent=indent, logFile=logFile)

def rmvUdbRsc(name, level=None, indent=None, logFile=None):
    verbose('UserDatabase 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('UserDatabase 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 """
    datarsc_attrs=top_node.getAttrs()
    verbose('UserDatabase ResourceLink:' + datarsc_attrs.name + ' Creating.', level=level, ifLevel=4, indent=indent, logFile=logFile)
    
    # link node
    link_attrs=top_node.getNode('link')[0].getAttrs()
    
    attrs={'global': datarsc_attrs.name, 'name': link_attrs.name, 'type':'org.apache.catalina.UserDatabase'}
    
    # creates
    target_node.newNode('ResourceLink', **attrs)
    verbose('UserDatabase ResourceLink:' + datarsc_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 UserDatabase Resource """
    datarsc_attrs=top_node.getAttrs()
    verbose('UserDatabase Resource:' + datarsc_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' : datarsc_attrs.name,
        'auth' : auth,
        'factory' : resource_attrs.factory,
        'pathname' : resource_attrs.pathname,
        'readonly' : resource_attrs.readonly,
    })
    if resource_attrs.description!=None:attrs['description']=resource_attrs.description
    
    attrs['type']='org.apache.catalina.UserDatabase'
        
    # creates
    target_node.newNode('Resource', **attrs)
    verbose('UserDatabase Resource:' + datarsc_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(), context_template=None, global_template='resources.global')
    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 !')
    datarsc_attrs=self_action.getTop().getAttrs()
        
    ## Creates the ResourceLink
    print
    print '## Creates the UserDatabase ResourceLink'

    if self_action.getTop().hasNode('link'):
        rmvLink(datarsc_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 UserDatabase Resource
    if self_action.getTop().hasNode('resource'):
        print
        print '## Creates the UserDatabase 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
            :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
            
            rmvUdbRsc(datarsc_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
            
            rmvUdbRsc(datarsc_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/udbrsc/by/kikonf/udbrsc.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