|
|
|
Crtcluster
Action : tom.crtcluster (Category : tom, Name : crtcluster, By : kikonf)
Complete Name : tom.crtcluster.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 crtcluster plugin : Configure a Tomcat/Apache Cluster The following shows the main Source Code File for the Action : tom.crtcluster 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 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 action_node=ro[0] try: from StringIO import StringIO from os import path sbworkers=StringIO() sbmounts=StringIO() indent=self_action.getIndent() + 3*' ' ## Retreives the Scope action_attrs=action_node.getAttrs() ## Check first print '## Check first' # if action_attrs.listener_host==None:action_attrs.listener_host=action_attrs.virtual_host if not path.isdir(action_attrs.includes_dir):raise xception.kikonfActionSystemException(self_action, 'inject', 'The directory: includes_dir, for the generated files must exist ! Your value: ' + action_attrs.includes_dir + '.') includes_dir = path.normpath(action_attrs.includes_dir) if action_attrs.cronolog!=None and not path.isfile(action_attrs.cronolog):raise xception.kikonfActionSystemException(self_action, 'inject', 'When guiven, the cronolog executable path must exist ! Your value: ' + action_attrs.cronolog + '.') uris_node=action_node.getNode('uris')[0] uris=uris_node.getTexts() if len(uris)==0:raise xception.kikonfActionSystemException(self_action, 'inject', 'Tag uris must be filled !') for i in range(len(uris)): uri=uris[i] if not uri.startswith('/'):uris[i]='/' + uri name_separator=action_node.getNode('nodes')[0].getAttr('name_separator') node_nodes=action_node.getNode('nodes')[0].getNode('node') ## Creates Include file print print '## Creates Include file' verbose('Include file: ' + action_attrs.lbname + '_jk.conf' + ' Creating.', level=self_action.getVerbose(), ifLevel=4, indent=indent, logFile=self_action.getLogFile()) templates_dir = path.normpath(self_action.getCurrentDir() + '/templates') target_jk_conf=path.normpath(path.realpath(includes_dir + '/' + action_attrs.lbname + '_jk.conf')) if action_attrs.usejk=='true':mod_apa=path.normpath(path.realpath(templates_dir + '/mod_jk.tmpl')) else:mod_apa=path.normpath(path.realpath(templates_dir + '/mod_proxy.tmpl')) attrs = { 'lbname': action_attrs.lbname, 'conf_dir': action_attrs.conf_dir, 'static_dir': action_attrs.static_dir, 'log_dir' : action_attrs.log_dir, 'listener_host': action_attrs.listener_host, 'listener_port': action_attrs.listener_port, 'virtual_host': action_attrs.virtual_host } if action_attrs.cronolog==None:attrs['log_base']=action_attrs.log_dir else:attrs['log_base']='|' + action_attrs.cronolog + ' -l ' + action_attrs.log_dir var mod_apa = mod_apa var target_jk_conf = target_jk_conf var attrs = attrs :tpc -D $mod_apa -f $target_jk_conf --temp_vars $attrs -s -n var mod_apa_alias = ro['alias'] :mount $mod_apa_alias verbose('Include file: ' + action_attrs.lbname + '_jk.conf' + ' Created.', level=self_action.getVerbose(), ifLevel=3, indent=indent, logFile=self_action.getLogFile()) ## Feeds worker/mount files print print '## Feeds worker/mount files' # Mod_jk if action_attrs.usejk=='true': fmounts='jk_mounts.properties' sbmounts.write('# Mod_Proxy Workers for cluster' + action_attrs.lbname + LINESEP) sbmounts.write('# ' + DESIGN_NOTICE + 2*LINESEP) for uri in uris:sbmounts.write(uri + '=' + action_attrs.lbname + LINESEP) fworkers='jk_workers.properties' sbworkers.write('# Mod_Proxy Workers for cluster' + action_attrs.lbname + LINESEP) sbworkers.write('# ' + DESIGN_NOTICE + 2*LINESEP) sbworkers.write('# Worker list for mapping requests:' + LINESEP) sbworkers.write('worker.list=' + action_attrs.lbname + ',status' + 2*LINESEP) nodes=[] for node_node in node_nodes: node_attrs=node_node.getAttrs() nodes.append(node_attrs.name) sbworkers.write('# Define node ' + node_attrs.name + ':' + LINESEP) sbworkers.write('worker.' + node_attrs.name + '.host=' + node_attrs.host + LINESEP) sbworkers.write('worker.' + node_attrs.name + '.port=' + str(node_attrs.port) + LINESEP) sbworkers.write('worker.' + node_attrs.name + '.type=ajp13' + LINESEP) sbworkers.write('worker.' + node_attrs.name + '.lbfactor=' + str(node_attrs.load_factor) + LINESEP) sbworkers.write('worker.' + node_attrs.name + '.cachesize=' + str(node_attrs.jk_cache_size) + 2*LINESEP) sbworkers.write('# Load-blancing behaviour:' + LINESEP) sbworkers.write('worker' + node_attrs.name + '.type=lb' + LINESEP) sbworkers.write('worker' + node_attrs.name + '.balance_workers=' + str(nodes)[1:-1].replace("'", '').replace(' ', '') + LINESEP) sbworkers.write('worker' + node_attrs.name + '.sticky_session=1' + 2*LINESEP) sbworkers.write('# Status Worker for management:' + LINESEP) sbworkers.write('worker.status.type=status' + LINESEP) # Mod_proxy else: fmounts='proxy_mounts.conf' sbmounts.write('# Mod_Proxy Workers for cluster' + action_attrs.lbname + LINESEP) sbmounts.write('# ' + DESIGN_NOTICE + 2*LINESEP) for uri in uris: sbmounts.write( 'ProxyPass ' + uri + ' balancer://' + action_attrs.lbname + uri + ' stickysession=JSESSIONID|jsessionid nofailover=' + action_attrs.proxy_nofailover + LINESEP ) fworkers='proxy_workers.conf' sbworkers.write('# Mod_Proxy Workers for cluster' + action_attrs.lbname + LINESEP) sbworkers.write('# ' + DESIGN_NOTICE + 2*LINESEP) for node_node in node_nodes: node_attrs=node_node.getAttrs() sbworkers.write( 'BalancerMember ajp://' + node_attrs.host + ':' + str(node_attrs.port) + ' route=' + node_attrs.name + name_separator + action_attrs.lbname + ' retry=60 loadfactor=' + str(node_attrs.load_factor) + LINESEP ) ## Creates worker/mount files print print '## Creates worker/mount files' verbose('Worker/mount files: ' + fworkers + '/' + fmounts + ' Creating.', level=self_action.getVerbose(), ifLevel=4, indent=indent, logFile=self_action.getLogFile()) if not self_action.getCAttr('test'): #-- Create fworkers fd = open(path.normpath(path.realpath(includes_dir + '/' + fworkers)), 'wb') fd.write(sbworkers.getvalue()) fd.close() #-- Create fmounts fd = open(path.normpath(path.realpath(includes_dir + '/' + fmounts)), 'wb') fd.write(sbmounts.getvalue()) fd.close() verbose('Worker/mount files: ' + fworkers + '/' + fmounts + ' Created.', level=self_action.getVerbose(), ifLevel=3, indent=indent, logFile=self_action.getLogFile()) else: message=xception.kikonfActionInformation(self_action, 'inject', 'Worker/mount files: ' + fworkers + '/' + fmounts + ' Not created, because Action is running in test mode.').warn(verbose=self_action.getVerbose(), doPrint=False) verbose(message, level=self_action.getVerbose(), ifLevel=3, indent=indent, logFile=self_action.getLogFile()) if self_action.getCAttr('test'): exit # scope_name, scope_attrs, scope= 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 :
|