|
|
|
Mailrsc
Action : tom.mailrsc (Category : tom, Name : mailrsc, By : kikonf)
Complete Name : tom.mailrsc.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 mailrsc plugin : This Action configures a Tomcat Java Mail Resource. The following shows the main Source Code File for the Action : tom.mailrsc 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('Java Mail 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('Java Mail ResourceLink:' + name + ' Removed:' + str(n) + ' configuration Entry.', level=level, ifLevel=3, indent=indent, logFile=logFile) def rmvMailRsc(name, level=None, indent=None, logFile=None): verbose('Java Mail 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('Java Mail 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 """ mailrsc_attrs=top_node.getAttrs() verbose('Java Mail ResourceLink:' + mailrsc_attrs.name + ' Creating.', level=level, ifLevel=4, indent=indent, logFile=logFile) # link node link_attrs=top_node.getNode('link')[0].getAttrs() attrs={'global': mailrsc_attrs.name, 'name': link_attrs.name, 'type':'javax.mail.Session'} # creates target_node.newNode('ResourceLink', **attrs) verbose('Java Mail ResourceLink:' + mailrsc_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 Java Mail Resource """ mailrsc_attrs=top_node.getAttrs() verbose('Java Mail Resource:' + mailrsc_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' : mailrsc_attrs.name, 'auth' : auth, 'mail.smtp.host' : resource_attrs.host, }) attrs['type']='javax.mail.Session' # creates target_node.newNode('Resource', **attrs) verbose('Java Mail Resource:' + mailrsc_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 !') mailrsc_attrs=self_action.getTop().getAttrs() ## Creates the ResourceLink print print '## Creates the Java Mail resourceLink' if self_action.getTop().hasNode('link'): rmvLink(mailrsc_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 Java Mail Resource if self_action.getTop().hasNode('resource'): print print '## Creates the Java Mail 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 rmvMailRsc(mailrsc_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 rmvMailRsc(mailrsc_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 :
|