cle_clock
Home > wikikonf >  was/actions/by kikonf > chgports







Chgports

print

Action : was.chgports   (Category : was, Name : chgports, By : kikonf)
Complete Name : was.chgports.by.kikonf
Version : 5.0        License : Modified BSD License

Purpose of the was category :
Easy to customize. This category use in background the wsadmin command in jython mode (through AdminConfig, AdminControl and AdminTask), to drive WebSphere Application Server ® configuration.
You can use it to manage the whole WebSphere ® architecture.

Purpose of this chgports plugin : Change all the JVM (TM) ports

The following shows the main Source Code File for the Action : was.chgports

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.was.tools import *



class Chgports(wasAction):
            
    def extract(self, 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*' '

        chgports_node=self.newTop() #-- because in extract mode, each call returns a new blank top node.
        chgports_node.setAttrs()
        mkNodeScope(chgports_node, scope_attrs, isUnique=True) #-- creates a scope node.

        verbose('Node retreiving.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())    
        nd = AdminConfig.getid('/Cell:' + self.getCell() + '/Node:' + scope_attrs['node'] + '/')
        verbose('Node:' + scope_attrs['node'] + ' listed.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile())
        
        ses=getStartByNameAsDict(split(AdminConfig.list("ServerEntry", nd)))
        verbose('ServerEntries listed.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile())

        was_ports_attrs={}
        for se in ses.keys():
            if se!=scope_attrs['server']:continue
            se=ses[se]
            seps=split(AdminConfig.showAttribute(se, "specialEndpoints"))
            verbose('specialEndpoints for server:' + scope_attrs['server'] + ' retreived.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile())
            
            for sep in seps:
                en=AdminConfig.showAttribute(sep, "endPointName")
                port=AdminConfig.showAttribute(AdminConfig.showAttribute(sep, "endPoint"), 'port')
                was_ports_attrs[en]=port
                verbose('Port ' + en + ':' + port + ' retreived.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile())
            
        if self.getCAttr('software_was_version').startswith('6'):wastag='was6Ports'
        else:wastag='was7Ports'
        
        chgports_node.newNode(wastag, **was_ports_attrs)

    def inject(self):
        self_funct='inject'
        chgports_node = self.getTop()                                           #-- Grabs top node
        chgports_attrs = chgports_node.getAttrs()
        scope_id, scope_attrs, scope=self.getScope(parent_node=chgports_node, indent=self.getIndent()) #-- Retreives scope
        self.verbose(scope_attrs) 
        indent=self.getIndent() + 3*' '

        #-- check both options are not used.
        was_ports_attrs=None
        starting_port=None
        if chgports_attrs.starting_port!=None:
            if chgports_node.hasNode('was6Ports') or chgports_node.hasNode('was7Ports'):raise xception.kikonfActionSystemException(self, self_funct, 'If Attribute "starting_port" is guiven, tags: was6Ports or was7Ports or cannot be !')
            starting_port=chgports_attrs.starting_port
        else:
            wasvers=getWasVersion()
            if wasvers.startswith('6'):
                if not chgports_node.hasNode('was6Ports'):raise xception.kikonfActionSystemException(self, self_funct, 'The tag: was6Ports is required. WebSphere 6.x is detected. Because you do not use the Attribute: "starting_port", the specific tag: was6Ports is required !')
                was_ports_attrs=chgports_node.getNode('was6Ports')[0].getdAttrs()  
                wasmes='was6Ports'  
            if wasvers.startswith('7'):
                if not chgports_node.hasNode('was7Ports'):raise xception.kikonfActionSystemException(self, self_funct, 'The tag: was7Ports is required. WebSphere 6.x is detected. Because you do not use the Attribute: "starting_port", the specific tag: was7Ports is required !')
                was_ports_attrs=chgports_node.getNode('was7Ports')[0].getdAttrs()  
                wasmes='was7Ports'  
    
        verbose('Node retreiving.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
        nd = AdminConfig.getid('/Cell:' + self.getCell() + '/Node:' + scope_attrs['node'] + '/')
        
        ses=getStartByNameAsDict(split(AdminConfig.list("ServerEntry", nd)))
        
        for se in ses.keys():
            if se!=scope_attrs['server']:continue
            se=ses[se]
            seps=split(AdminConfig.showAttribute(se, "specialEndpoints"))
            verbose('specialEndpoints for server:' + scope_attrs['server'] + ' retreived.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile())
            
            if chgports_attrs.starting_port!=None:
                port = chgports_attrs.starting_port
                for sep in seps:
                    en=AdminConfig.showAttribute(sep, "endPointName")
                    ep=AdminConfig.showAttribute(sep, "endPoint")
                    AdminConfig.modify(ep, 'port', str(port))
                    verbose('Port ' + en + ':' + str(port) + ' set.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile())
                    port+=1
            else:
                for sep in seps:
                    en=AdminConfig.showAttribute(sep, "endPointName")
                    if not en in was_ports_attrs.keys():raise xception.kikonfActionSystemException(self, self_funct, 'Unknown port Named:' + en + ' found into the JVM configuration. Advice: Be sure to use the rigth specific tag (either was6Ports or was7Ports) for the right WebSphere version !\n You are actually using the ' + wasmes + ' tag.')
                    port=was_ports_attrs[en]
                    ep=AdminConfig.showAttribute(sep, "endPoint")
                    AdminConfig.modify(ep, 'port', str(port))
                    verbose('Port ' + en + ':' + str(port) + ' set.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile())
            break
        
    def verbose(self, scope_attrs):
        scope=str(scope_attrs).replace("'", '')[1:-1]
        
        verbose('JVM Ports at scope:' + scope + '.', level=self.getVerbose(), ifLevel=2, indent=self.getIndent())
							
(Source: <KIKONF_INSTALLATION_DIR>/plugins/actions/was/chgports/by/kikonf/chgports.py)


  • Line 1 to 3 say something , say something , say something
  • Line 10 to 17 say something , say something , say something , say something , say something
  • Line 20 to 25 say something



Trademarks :
  • "IBM", "WebSphere", "WebSphere Aplication Server", "WAS" are registred trademarks of International Business Machines Corporation.
  • "Java" and "JVM" are a registred trademarks of Oracle and/or its affiliates.
  • Other names may be trademarks of their respective owners.

Copyright © 2011 - Patrick Placidoux, Hélène Malamoud