|
|
|
Aprconn
Action : tom.aprconn (Category : tom, Name : aprconn, By : kikonf)
Complete Name : tom.aprconn.by.kikonf Version : 1.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 aprconn plugin : Configure an HTTP connector. The following shows the main Source Code File for the Action : tom.aprconn 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 REALMES={ 'udb' : 'org.apache.catalina.realm.UserDatabaseRealm', 'mem' : 'org.apache.catalina.realm.MemoryRealm', 'jaas' : 'className="org.apache.catalina.realm.JAASRealm', 'jdbc' : 'org.apache.catalina.realm.JDBCRealm', 'datarsc' : 'org.apache.catalina.realm.DataSourceRealm', 'ldaps' : 'org.apache.catalina.realm.JNDIRealm' } #-------------------# # Utility functions # #-------------------# def checkUdbescIntegrity(udbrsc, level=0, indent=None, logFile=None): # Checks udbesc integrity print print '# Checks udbesc integrity' #:mount $target_scope_alias # get Steady var datarsc_name=udbrsc # check for a resource print '#-- Does a Resource named:' + udbrsc + ' exists for the context ?' %select name at Resource where name=${udbrsc} and type=org.apache.catalina.UserDatabase if len(ro)==0: # check for a resourceLink print '#-- Does a ResourceLink named:' + udbrsc + ' exists for the context ?' %select name at ResourceLink where name=${udbrsc} and type=org.apache.catalina.UserDatabase if len(ro)==0: verbose('Tomcat configuration inconsistency no Resource or ResourceLink found for referenced UserDatabase Resource:' + datarsc + ' ! Keep going on.', level=level, ifLevel=3, indent=indent, logFile=logFile) return False return True def checkDatarscIntegrity(datarsc, level=0, indent=None, logFile=None): # Checks datarsc integrity print print '# Checks datarsc integrity' #:mount $target_scope_alias # get Steady var datarsc_name=datarsc # check for a resource print '#-- Does a Resource named:' + datarsc_name + ' exists for the context ?' %select name at Resource where name=${datarsc_name} and type=javax.sql.DataSource if len(ro)==0: # check for a resourceLink print '#-- Does a ResourceLink named:' + datarsc_name + ' exists for the context ?' %select name at ResourceLink where name=${datarsc_name} and type=javax.sql.DataSource if len(ro)==0: verbose('Tomcat configuration inconsistency no Resource or ResourceLink found for referenced JDBC DataSource Resource:' + datarsc + ' ! Keep going on.', level=level, ifLevel=3, indent=indent, logFile=logFile) return False return True def injRealme(top_node, realme_node, realme, level=0, indent=None, logFile=None): """ Creates a Realme """ realme_attrs=realme_node.getdAttrs() if realme=='udb':checkUdbescIntegrity(realme_attrs['resourceName'], level=level, indent=indent, logFile=logFile) elif realme=='datarsc':checkDatarscIntegrity(realme_attrs['dataSourceName'], level=level, indent=indent, logFile=logFile) verbose('Realme:' + realme + ' Creating.', level=level, ifLevel=4, indent=indent, logFile=logFile) attrs={} attrs.update(realme_attrs) attrs['digest']=top_node.getAttr('digest') attrs['className']=REALMES[realme] # creates target_node.newNode('Realme', **attrs) verbose('Realme:' + realme + ' 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] realmes=[] # Intergrity check for realme in REALMES: if self_action.getTop().hasNode(realme):realmes.append(realme) if len(realmes)==0:raise xception.kikonfActionSystemException(self_action, 'inject', 'At least on realme (in ' + str(REALMES)[1:-1] + ') is required !') if len(realmes)>1:raise xception.kikonfActionSystemException(self_action, 'inject', 'Over numbered Realmes: only one realme is allowed ! Found: ' + str(realmes)[1:-1] + '.') if not scope_name.startswith('context') and scope_name not in ('engine', 'host'):raise xception.kikonfActionSystemException(self_action, 'inject', 'Bad Scope: ' + scope_name + ', Scope should be one of: "engine", "host" or "context" !') realme=realmes[0] class_name=REALMES[realme] ## Destroys first print print '## Destroys first' verbose('Realme: ' + realme + ' Removing.', level=self_action.getVerbose(), ifLevel=4, indent=indent, logFile=self_action.getLogFile()) var class_name=class_name :rm Realme@className=${class_name} #%delete Realme where className = ${class_name} deleted_nodes=ro if deleted_nodes!=None:n=len(deleted_nodes) else:n=0 if n>0:verbose('Realme: ' + realme + ' Removed:' + str(n) + ' configuration Entry.', level=self_action.getVerbose(), ifLevel=3, indent=indent, logFile=self_action.getLogFile()) ## Creates the Realme print print '## Creates the Realme' realme_node=self_action.getTop().getNode(realme)[0] injRealme(self_action.getTop(), realme_node, realme, 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 :
|