|
|
|
Jvm
Action : wls.jvm (Category : wls, Name : jvm, By : kikonf)
Complete Name : wls.jvm.by.kikonf Version : 4.0 License : Modified BSD License Purpose of the wls category : Easy to customize. This category use in background the wlst command in jython mode, to drive WebLogic Server ® configuration. You can use it to manage the whole WebLogic ® architecture. Purpose of this jvm plugin : Tunes a JVM The following shows the main Source Code File for the Action : wls.jvm 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 from actions.wls.tools import * from weblogic.management import NoAccessRuntimeException class Jvm(wlsAction): DFT_TEMP_ARGS=( '-DumpDir', '-Dtemp.dir', '-Djava.io.temp', '-Djava.io.tmpdir', '-Djava.util.prefs.userRoot', '-Djava.util.prefs.systemRoot' ) def extract(self, indent=None, scope_attrs=None, **keywords): self_funct='extract' self.verbose(scope_attrs) scope_id, scope_attrs, scope=self.getScope(scope_attrs=scope_attrs, indent=self.getIndent()) indent=self.getIndent() + 3*' ' jvm_node=self.newTop() #-- because in extract mode, each call returns a new blank top node. mkNodeScope(jvm_node, scope_attrs, isUnique=True) #-- creates a scope node. verbose('Jvm listing.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile()) attrs={} # Top Tag attrs cmo=cmo=cd('/Servers/' + scope_attrs['server'] + '/ServerStart/' + scope_attrs['server']) # - gets user attrs['user']=cmo.getUsername() # - gets Password try: password=cmo.getPassword() except NoAccessRuntimeException: password='???' verbose('Passwords retreiving is not allowed because "clearTextCredentialAccessEnabled" attribute is not set in SecurityConfigurationMBean. Password retreiving is skipped !', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile()) attrs['password']=password # - gets root_dir attrs['root_dir']=cmo.getRootDirectory() # - gets java_home attrs['java_home']=cmo.getJavaHome() # - gets dft context cmo=cd('/Servers/' + scope_attrs['server'] + '/WebServer/' + scope_attrs['server']) attrs['dft_context']=cmo.getDefaultWebAppContextRoot() # - gets startup_mode cmo=cd('/Servers/' + scope_attrs['server']) attrs['startup_mode']=cmo.getStartupMode() # - gets enable_ssl cmo=cd('/Servers/' + scope_attrs['server'] + '/SSL/' + scope_attrs['server']) # if cmo.isEnabled():attrs['enable_ssl']='true' if cmo.isTwoWaySSLEnabled():attrs['enable_ssl']='true' # - gets ssl_client_cert if cmo.isClientCertificateEnforced():attrs['ssl_client_cert']='true' # - gets enable_keep_alive cmo=cd('/Servers/' + scope_attrs['server'] + '/WebServer/' + scope_attrs['server']) if cmo.isKeepAliveEnabled():attrs['enable_keep_alive']='true' # - gets enable_plugin cmo=cd('/Servers/' + scope_attrs['server']) if cmo.isWeblogicPluginEnabled():attrs['enable_plugin']='true' # - gets admin_port cmo=cd('/Servers/' + scope_attrs['server']) attrs['admin_port']=cmo.getAdministrationPort() jvm_node.setAttrs(**attrs) #-- Sets Attributes for top node. attrs={} # Tag: redirects cmo=cd('/Servers/' + scope_attrs['server'] + '/WebServer/' + scope_attrs['server']) attrs['frontend_host']=cmo.getFrontendHost() attrs['frontend_htttp_port']=cmo.getFrontendHTTPPort() attrs['frontend_htttps_port']=cmo.getFrontendHTTPSPort() attrs['client_ip_header']=cmo.getClientIpHeader() attrs.values().sort() if (attrs['frontend_host'], attrs['client_ip_header'], attrs['frontend_htttp_port'], attrs['frontend_htttps_port'])!=(None, None, 0, 0): classpath_node=jvm_node.newNode('redirects', **attrs) cmo=cd('/Servers/' + scope_attrs['server'] + '/ServerStart/' + scope_attrs['server']) # Tag: classpath cps=cmo.getClassPath() if cps!=None: cps=cps.split() if len(cps)!=0: cps_node=jvm_node.newNode('classpath') for cp in cps:cps_node.addText(cp) cmo=cd('/Servers/' + scope_attrs['server']) # Tag: prepend_classpath cps=cmo.getJavaCompilerPreClassPath() if cps!=None: cps=cps.split() if len(cps)!=0: cps_node=jvm_node.newNode('prepend_classpath') for cp in cps:cps_node.addText(cp) cmo=cd('/Servers/' + scope_attrs['server']) # Tag: append_classpath cps=cmo.getJavaCompilerPostClassPath() if cps!=None: cps=cps.split() if len(cps)!=0: cps_node=jvm_node.newNode('append_classpath') for cp in cps:cps_node.addText(cp) other_jvmargs=[] for method in ('extXm', 'extShClasses', 'extHprof', 'extVerbose', 'extGc', 'extLibs'): other_jvmargs=getattr(self, method)(other_jvmargs, jvm_node, indent=indent) if len(other_jvmargs)!=0: # Tag: generic_jvm_args generic_jvm_args_node=jvm_node.newNode('generic_jvm_args') for jvmarg in other_jvmargs: generic_jvm_args_node.addText(jvmarg) def inject(self): self_funct='inject' jvm_node = self.getTop() #-- Grabs top node jvm_attrs = jvm_node.getAttrs() scope_id, scope_attrs, scope=self.getScope(parent_node=jvm_node, indent=self.getIndent()) #-- Retreives scope self.verbose(scope_attrs) indent=self.getIndent() + 3*' ' # - sets jvm name # Top Tag attrs verbose('Server:' + scope_attrs['server'] + ' retreiving', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile()) cmo=cd('/Servers/' + scope_attrs['server']) verbose('Server:' + scope_attrs['server'] + ' retreived.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile()) cmo.setVirtualMachineName(scope_attrs['server']) cmo=cd('/Servers/' + scope_attrs['server'] + '/ServerStart/' + scope_attrs['server']) # - sets user/password if jvm_attrs.user!=None:cmo.setUsername(jvm_attrs.user) verbose('user', jvm_attrs.user, level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile()) if jvm_attrs.password!=None:cmo.setPasswordEncrypted(encrypt(jvm_attrs.password)) # - sets root_dir if jvm_attrs.root_dir!=None: cmo.setRootDirectory(jvm_attrs.root_dir) verbose('root_dir', jvm_attrs.root_dir, level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile()) else:cmo.unSet('RootDirectory') # - sets java_home if jvm_attrs.java_home!=None: cmo.setJavaHome(jvm_attrs.java_home) verbose('java_home', jvm_attrs.java_home, level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile()) else:cmo.unSet('JavaHome') # - sets dft_context cmo=cd('/Servers/' + scope_attrs['server'] + '/WebServer/' + scope_attrs['server']) if jvm_attrs.dft_context!=None: cmo.setDefaultWebAppContextRoot(jvm_attrs.dft_context) verbose('dft_context', jvm_attrs.dft_context, level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile()) else:cmo.unSet('DefaultWebAppContextRoot') # - sets startup_mode cmo=cd('/Servers/' + scope_attrs['server']) cmo.setStartupMode(jvm_attrs.startup_mode) verbose('startup_mode', jvm_attrs.startup_mode, level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile()) # - sets enable_ssl cmo=cd('/Servers/' + scope_attrs['server'] + '/SSL/' + scope_attrs['server']) if jvm_attrs.enable_ssl=='true': cmo.setTwoWaySSLEnabled(True) verbose('enable_ssl', jvm_attrs.enable_ssl, level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile()) else:cmo.setTwoWaySSLEnabled(False) if jvm_attrs.ssl_client_cert=='true': cmo.setClientCertificateEnforced(True) verbose('ssl_client_cert', jvm_attrs.ssl_client_cert, level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile()) else:cmo.unSet('ClientCertificateEnforced') # - sets enable_keep_alive cmo=cd('/Servers/' + scope_attrs['server'] + '/WebServer/' + scope_attrs['server']) if jvm_attrs.enable_keep_alive=='true': cmo.setKeepAliveEnabled(True) verbose('enable_keep_alive', jvm_attrs.enable_keep_alive, level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile()) else:cmo.unSet('KeepAliveEnabled') # - sets enable_plugin cmo=cd('/Servers/' + scope_attrs['server']) if jvm_attrs.enable_plugin=='true': cmo.setWeblogicPluginEnabled(True) verbose('enable_plugin', jvm_attrs.enable_plugin, level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile()) else:cmo.unSet('WeblogicPluginEnabled') # - sets admin_port cmo=cd('/Servers/' + scope_attrs['server']) if jvm_attrs.admin_port!=None: cmo.setAdministrationPort(jvm_attrs.admin_port) verbose('admin_port', jvm_attrs.admin_port, level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile()) else:cmo.unSet('AdministrationPort') cmo=cd('/Servers/' + scope_attrs['server'] + '/WebServer/' + scope_attrs['server']) if jvm_node.hasNode('redirects'): # Tag: redirects redirects_attrs=jvm_node.getNode('redirects')[0].getAttrs() verbose('redirects:', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile()) if redirects_attrs.frontend_host!=None: cmo.setFrontendHost(redirects_attrs.frontend_host) verbose('frontend_host', redirects_attrs.frontend_host, level=self.getVerbose(), ifLevel=4, indent=indent + 3*' ', logFile=self.getLogFile()) else:cmo.unSet('FrontendHost') if redirects_attrs.frontend_htttp_port!=None: cmo.setFrontendHTTPPort(redirects_attrs.frontend_htttp_port) verbose('frontend_htttp_port', redirects_attrs.frontend_htttp_port, level=self.getVerbose(), ifLevel=4, indent=indent + 3*' ', logFile=self.getLogFile()) else:cmo.unSet('FrontendHTTPPort') if redirects_attrs.frontend_htttps_port!=None: cmo.setFrontendHTTPSPort(redirects_attrs.frontend_htttps_port) verbose('frontend_htttps_port', redirects_attrs.frontend_htttps_port, level=self.getVerbose(), ifLevel=4, indent=indent + 3*' ', logFile=self.getLogFile()) else:cmo.unSet('FrontendHTTPSPort') if redirects_attrs.client_ip_header!=None: cmo.setClientIpHeader(redirects_attrs.client_ip_header) verbose('client_ip_header', redirects_attrs.client_ip_header, level=self.getVerbose(), ifLevel=4, indent=indent + 3*' ', logFile=self.getLogFile()) else:cmo.unSet('ClientIpHeader') else: cmo.unSet('FrontendHost') cmo.unSet('FrontendHTTPPort') cmo.unSet('FrontendHTTPSPort') cmo.unSet('ClientIpHeader') cmo=cd('/Servers/' + scope_attrs['server'] + '/ServerStart/' + scope_attrs['server']) if jvm_node.hasNode('classpath'): # Tag: classpath cps=jvm_node.getNode('classpath')[0].getText() if len(cps)==0:classpath='' elif len(cps)==1:classpath=cps[0] else:classpath='\n'.join(cps) cmo.setClassPath(classpath) else:cmo.unSet('ClassPath') cmo=cd('/Servers/' + scope_attrs['server']) if jvm_node.hasNode('prepend_classpath'): # Tag: prepend_classpath cps=jvm_node.getNode('prepend_classpath')[0].getText() if len(cps)==0:prepend_classpath='' elif len(cps)==1:prepend_classpath=cps[0] else:prepend_classpath='\n'.join(cps) cmo.setJavaCompilerPreClassPath(prepend_classpath) else:cmo.unSet('JavaCompilerPreClassPath') cmo=cd('/Servers/' + scope_attrs['server']) if jvm_node.hasNode('append_classpath'): # Tag: append_classpath cps=jvm_node.getNode('append_classpath')[0].getText() if len(cps)==0:append_classpath='' elif len(cps)==1:append_classpath=cps[0] else:append_classpath='\n'.join(cps) cmo.setJavaCompilerPostClassPath(append_classpath) else:cmo.unSet('JavaCompilerPostClassPath') cmo=cd('/Servers/' + scope_attrs['server'] + '/ServerStart/' + scope_attrs['server']) s=self.injJvmArgs(jvm_node, indent=indent) if len(s)>=0:cmo.setArguments(s) #-- Treats Jvm Args else:cmo.unSet('Arguments') verbose('Server:' + scope_attrs['server'] + ' modified.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile()) # ------------------------------- Sub methods -------------------------------# def injJvmArgs(self, jvm_node, indent=None): cmdvalues=[] jvm_attrs=jvm_node.getAttrs() # xms/xmx if jvm_attrs.xms!=None:xms=cmdvalues.append('-xms' + str(jvm_attrs.xms) + 'm') if jvm_attrs.xmx!=None:xmx=cmdvalues.append('-xmx' + str(jvm_attrs.xmx) + 'm') if jvm_attrs.temp_dir!=None: for e in Jvm.DFT_TEMP_ARGS:cmdvalues.append(e + '=' + jvm_attrs.temp_dir) # shared_classes if jvm_attrs.shared_classes!='off':cmdvalues.append('-Xshare:' + jvm_attrs.shared_classes) # run_hprof if jvm_attrs.run_hprof=='true':cmdvalues.append('-Xprof') if jvm_node.hasNode('verbose'): # Tag: verbose verbose_attrs=jvm_node.getNode('verbose')[0].getAttrs() if verbose_attrs.clas=='true':cmdvalues.append('-verbose:class') if verbose_attrs.gc=='true':cmdvalues.append('-verbose:jni') if verbose_attrs.jni=='true':cmdvalues.append('-verbose:gc') if jvm_node.hasNode('gc'): # Tag: gc gc_attrs=jvm_node.getNode('gc')[0].getAttrs() if gc_attrs.disable=='true':cmdvalues.append('-Xnoclassgc') if gc_attrs.enable_inc=='true':cmdvalues.append('-Xincgc') if gc_attrs.log_file!=None:cmdvalues.append('-Xloggc:' + gc_attrs.log_file) if jvm_node.hasNode('extlibs'): # Tag: extlibs extlibs=jvm_node.getNode('extlibs')[0].getText() for extlib in extlibs:cmdvalues.append('-extDir ' + extlib) if jvm_node.hasNode('generic_jvm_args'): # Tag: generic_jvm_args generic_jvm_args=jvm_node.getNode('generic_jvm_args')[0].getText() if len(generic_jvm_args)>=1:cmdvalues.extend(generic_jvm_args) return ' '.join(cmdvalues) def extXm(self, other_jvmargs, jvm_node, indent=None): # xms/xmx xms=xmx=None wrks=other_jvmargs other_jvmargs=[] mems={} i=0 while i<len(wrks): entry=wrks[i].strip() if entry.startswith('-xms') or entry.startswith('-xmx'): i=self.__extGcGetMem(wrks, i, mems) else: other_jvmargs.append(entry) i+=1 wrks=None if len(mems)!=0:jvm_node.setAttrs(**mems) return other_jvmargs def __extGcGetMem(self, wrks, i, mems): entry=wrks[i] if entry.startswith('-xms'):key='xms' elif entry.startswith('-xmx'):key='xmx' elif entry.startswith('-xmos'):key='xmos' elif entry.startswith('-xmox'):key='xmox' if entry=='-' + key: i+=1 value=int(wrks[i].strip()) else: value=str(entry.split('-' + key)[1]) if value!=None: if value[-1]=='m':value=value[:-1] try: value=int(value) except:raise xception.kikonfActionSystemException(self, self_funct, 'Unable to retreive a correct int value from Jvm Argument:' + key) mems[key]=value return i def extShClasses(self, other_jvmargs, jvm_node, indent=None): # shared_classes xms=xmx=None shs={'-Xshare:auto': 'auto', '-Xshare:on': 'on', '-Xshare:off': 'off'} wrk=' '.join(other_jvmargs) sh='off' for key in shs.keys(): if wrk.find(key)>=0: wrk.replace(key, '') sh=shs[key] if sh!='off':jvm_node.setAttr('shared_classes', sh) other_jvmargs=wrk.split() return other_jvmargs def extHprof(self, other_jvmargs, jvm_node, indent=None): # run_hprof xms=xmx=None wrk=' '.join(other_jvmargs) found=False if wrk.find('-Xprof')>=0: wrk.replace('-Xprof', '') found=True if found:jvm_node.setAttr('run_hprof', 'true') other_jvmargs=wrk.split() return other_jvmargs def extVerbose(self, other_jvmargs, jvm_node, indent=None): # Tag: verbose xms=xmx=None vbs={'-verbose:class': 'clas', '-verbose:jni': 'jni', '-verbose:gc': 'gc'} wrk=' '.join(other_jvmargs) first_time=True for key in vbs.keys(): if wrk.find(key)>=0: wrk.replace(key, '') if first_time: first_time=False verbose_node=jvm_node.newNode('verbose') verbose_node.setAttr(vbs[key], 'true') other_jvmargs=wrk.split() return other_jvmargs def extGc(self, other_jvmargs, jvm_node, indent=None): # Tag: gc wrk=' '.join(other_jvmargs) attrs={} found=False if wrk.find('-Xnoclassgc')>=0: wrk.replace('-Xnoclassgc', '') found=True attrs['disable']='true' if wrk.find('-Xincgc')>=0: wrk.replace('-Xincgc', '') found=True attrs['enable_inc']='true' if wrk.find('-Xloggc:')>=0: wrk.replace('-Xloggc:', '') found=True spl=wrk.split() attrs['log_file']=spl[0] wrk=' '.join(spl[1:]) if found:gc_node=jvm_node.newNode('gc', **attrs) other_jvmargs=wrk.split() return other_jvmargs def extLibs(self, other_jvmargs, jvm_node, indent=None): # Tag: extlibs wrks=other_jvmargs other_jvmargs=[] extlibs=[] dosh=False i=0 while i<len(wrks): entry=wrks[i].strip() if entry.startswith('-extDir'): dosh=True if entry=='-extDir': i+=1 extlibs.append(wrks[i].strip()) else:extlibs.append(entry.split('-extDir')[1]) else:other_jvmargs.append(entry) i+=1 wrks=None if dosh: extlibs_node=jvm_node.newNode('extlibs') for extlib in extlibs:extlibs_node.addText(extlib) return other_jvmargs def verbose(self, scope_attrs): scope=str(scope_attrs).replace("'", '')[1:-1] verbose('JavaVirtualMachine at scope:' + scope + '.', level=self.getVerbose(), ifLevel=2, indent=self.getIndent())
Trademarks :
|