|
|
|
|
|
Env
Action : tom.env (Category : tom, Name : env, By : kikonf)
Complete Name : tom.env.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 env plugin : This Action configures a Tomcat Environmen entry. The following shows the main Source Code File for the Action : tom.env 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
TYPES=('java.lang.Boolean','java.lang.Byte','java.lang.Character','java.lang.Double','java.lang.Float','java.lang.Integer','java.lang.Long','java.lang.Short','java.lang.String')
#-------------------#
# Utility functions #
#-------------------#
def rmvLink(name, level=None, indent=None, logFile=None):
verbose('Environment Entry 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('Environment Entry ResourceLink:' + name + ' Removed:' + str(n) + ' configuration Entry.', level=level, ifLevel=3, indent=indent, logFile=logFile)
def rmvEnv(name, level=None, indent=None, logFile=None):
verbose('Environment Entry:' + name + ' Removing.', level=level, ifLevel=4, indent=indent, logFile=logFile)
var name = name
%delete Environment where name = ${name}
if ro!=None:n=len(ro)
else:n=0
if n>0:verbose('Environment Entry:' + 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 """
env_attrs=top_node.getAttrs()
verbose('Environment Entry ResourceLink:' + env_attrs.name + ' Creating.', level=level, ifLevel=4, indent=indent, logFile=logFile)
# link node
link_attrs=top_node.getNode('link')[0].getAttrs()
attrs={'global': env_attrs.name, 'name': link_attrs.name, 'type':env_attrs.etype}
# creates
target_node.newNode('ResourceLink', **attrs)
verbose('Environment Entry ResourceLink:' + env_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 Environment Entry """
env_attrs=top_node.getAttrs()
verbose('Environment Entry:' + env_attrs.name + ' Creating.', level=level, ifLevel=4, indent=indent, logFile=logFile)
attrs={}
# envrsc node
envrsc_node=top_node.getNode('envrsc')[0]
envrsc_attrs=envrsc_node.getAttrs()
attrs.update({
'name' : env_attrs.name,
'type' : env_attrs.etype,
'value' : envrsc_attrs.value,
'override' : envrsc_attrs.override
})
# creates
target_node.newNode('Environment', **attrs)
verbose('Environment Entry:' + env_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 !')
envrsc_attrs=self_action.getTop().getAttrs()
## Creates the ResourceLink
print
print '## Creates the Environment Entry ResourceLink'
if self_action.getTop().hasNode('link'):
rmvLink(envrsc_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 Environment Entry
if self_action.getTop().hasNode('envrsc'):
print
print '## Creates the Environment Entry'
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
rmvEnv(envrsc_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
rmvEnv(envrsc_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 !
Trademarks :
|