k_satish22
asked on
Jython Script to modify listener ports
Hi,
I am trying to create a jython script to modify listener ports by taking the properties from a properties file. But some how it is not working and I am not sure whether my approach is correct or not. Can someone please help me? Please find the attachment for the script and properties fille.
Thanks
UpdateLP.py
UpdateLP.txt
I am trying to create a jython script to modify listener ports by taking the properties from a properties file. But some how it is not working and I am not sure whether my approach is correct or not. Can someone please help me? Please find the attachment for the script and properties fille.
Thanks
UpdateLP.py
UpdateLP.txt
what do you it;s not working? it fails or you dont see the result after successful execution ?
ASKER
It is failing with errors. I thinking there is some problem with the logic. The script I am using was created to create listener ports. I am trying to modify it to use for modify listener port properties.
It would help us if you provided the output of a sample execution.
For what are you looking?
- Comments / suggestions about what is failing during the execution of the script?
- Comments / suggestions about programming style?
For what are you looking?
- Comments / suggestions about what is failing during the execution of the script?
- Comments / suggestions about programming style?
ASKER
Hello HonorGod,
I need a script to modify the listner port properties in JACL and jython. Both the script should take input from a properties file.
here is the output of the script ...
C:\IBM\WebSphere\AppServer \profiles\ AppSrv01\b in>wsadmin -lang jython -f C:\ACS\
Jython_Scripts\createLP.py C:\ACS\Jython_Scripts\crea teLP.txt
WASX7209I: Connected to process "server1" on node ATL0LW00R996VTNNode01 using SO
AP connector; The type of process is: UnManagedProcess
WASX7303I: The following options are passed to the scripting environment and are
available as arguments that are stored in the argv variable: "[C:\ACS\Jython_Sc
ripts\createLP.txt]"
createLP: INFO --- In main function
createLP: INFO --- Loading the properties to Hash Map => START......
createLP: INFO --- Loading the properties to Hash Map => DONE.
createLP: INFO --- Adding property value to servers START......
createLP: ERROR --- Unable to find server server1.Check the logs for more inform
ation.
WASX7017E: Exception received while running file "C:\ACS\Jython_Scripts\cre ateLP
.py"; exception information: com.ibm.ws.scripting.Scrip tingExcept ion: WASX7077E:
Incomplete config id: need closing parenthesis in ""
Thank you
I need a script to modify the listner port properties in JACL and jython. Both the script should take input from a properties file.
here is the output of the script ...
C:\IBM\WebSphere\AppServer
Jython_Scripts\createLP.py
WASX7209I: Connected to process "server1" on node ATL0LW00R996VTNNode01 using SO
AP connector; The type of process is: UnManagedProcess
WASX7303I: The following options are passed to the scripting environment and are
available as arguments that are stored in the argv variable: "[C:\ACS\Jython_Sc
ripts\createLP.txt]"
createLP: INFO --- In main function
createLP: INFO --- Loading the properties to Hash Map => START......
createLP: INFO --- Loading the properties to Hash Map => DONE.
createLP: INFO --- Adding property value to servers START......
createLP: ERROR --- Unable to find server server1.Check the logs for more inform
ation.
WASX7017E: Exception received while running file "C:\ACS\Jython_Scripts\cre
.py"; exception information: com.ibm.ws.scripting.Scrip
Incomplete config id: need closing parenthesis in ""
Thank you
Given the input file attached above, I would expect your script to failing within createPropValues() when it makes this call
updateLP(cellName,nodeName ,serverNam e,cfName,r olesList[0 ],rolesLis t[1],roles List[2],ro lesList[3] ,rolesList [4])
because updateLP() would try to:
server = AdminConfig.getid('/Cell:' +cellName+ '/Node:'+n odeName+'/ Server:'+s erverName)
when cellName, nodeName, and serverName are empty strings, which would mean that the call would be like:
server = AdminConfig.getid('/Cell:/ Node:/Serv er:')
which should result in an error like this:
WASX7015E: Exception running command: "AdminConfig.getid('/Cell: /Node:/Ser ver:')"; exception information:
com.ibm.ws.scripting.Scrip tingExcept ion: Invalid object name: /Cell:/Node:/Server:
On the other hand, if your "property file" actually contains valid values for
CellName=
NodeName=
ServerName=
Then, the result of the call to AdminConfig.getid() should be a valid configuration ID.
However, we don't know for certain because the script doesn't display the result of the call.
So, where might it be failing? Well, since we don't see the message that "should" be generated next (i.e., "nupdateLP: INFO --- Checking to see if Listener port..."), the call that is most likely failing is:
mls = AdminConfig.list('MessageL istenerSer vice', server)
updateLP(cellName,nodeName
because updateLP() would try to:
server = AdminConfig.getid('/Cell:'
when cellName, nodeName, and serverName are empty strings, which would mean that the call would be like:
server = AdminConfig.getid('/Cell:/
which should result in an error like this:
WASX7015E: Exception running command: "AdminConfig.getid('/Cell:
com.ibm.ws.scripting.Scrip
On the other hand, if your "property file" actually contains valid values for
CellName=
NodeName=
ServerName=
Then, the result of the call to AdminConfig.getid() should be a valid configuration ID.
However, we don't know for certain because the script doesn't display the result of the call.
So, where might it be failing? Well, since we don't see the message that "should" be generated next (i.e., "nupdateLP: INFO --- Checking to see if Listener port..."), the call that is most likely failing is:
mls = AdminConfig.list('MessageL
ASKER
You are correct I have removed the cell name, node name and server name in the attached properties file. The property file which I am using is having those details.
For so reason when I am using single quote characters wsadmin is throwing the below error so I changed the single quote characters to double quote characters and it worked. I have updated the script with double quote characters.
wsadmin>AdminConfig.getid( 'Cell:ATL0 LW00R996VT NNode01Cel l/Node:ATL 0LW00R996V TNNode01/S erver:serv er1')
WASX7015E: Exception running command: "AdminConfig.getid('Cell:A TL0LW00R99 6VTNNode01 Cell/Node: ATL0LW00R9 96VTNNode0 1/Server:s erver1')"
; exception information:
com.ibm.ws.scripting.Scrip tingExcept ion: Invalid object name: Cell:ATL0LW00R996VTNNode01 Cell/Node: ATL0LW00R9 96VTNNode0 1/Server:s erve
r1
Now I am getting below error when I am executing the script. Please find the attachment for you updated script and properties file.
C:\IBM\WebSphere\AppServer \profiles\ AppSrv01\b in>wsadmin -lang jython -f C:\ACS\Jython_Scripts\Upda te_LP.py C:\ACS\Jython_Scripts\Upd
ate_LP.txt
WASX7209I: Connected to process "server1" on node ATL0LW00R996VTNNode01 using SOAP connector; The type of process is: UnManagedProce
ss
WASX7303I: The following options are passed to the scripting environment and are available as arguments that are stored in the argv v
ariable: "[C:\ACS\Jython_Scripts\Up date_LP.tx t]"
updateLP: INFO --- In main function
updateLP: INFO --- Loading the properties to Hash Map => START......
updateLP: INFO --- Loading the properties to Hash Map => DONE.
updateLP: INFO --- Adding property value to servers START......
WASX7017E: Exception received while running file "C:\ACS\Jython_Scripts\Upd ate_LP.py" ; exception information: com.ibm.bsf.BSFExceptio
n: exception from Jython:
Traceback (innermost last):
File "<string>", line 130, in ?
File "<string>", line 123, in main
File "<string>", line 59, in createPropValues
File "<string>", line 64, in updateLP
TypeError: __add__ nor __radd__ defined for these operands
Update-LP.py
Update-LP.txt
For so reason when I am using single quote characters wsadmin is throwing the below error so I changed the single quote characters to double quote characters and it worked. I have updated the script with double quote characters.
wsadmin>AdminConfig.getid(
WASX7015E: Exception running command: "AdminConfig.getid('Cell:A
; exception information:
com.ibm.ws.scripting.Scrip
r1
Now I am getting below error when I am executing the script. Please find the attachment for you updated script and properties file.
C:\IBM\WebSphere\AppServer
ate_LP.txt
WASX7209I: Connected to process "server1" on node ATL0LW00R996VTNNode01 using SOAP connector; The type of process is: UnManagedProce
ss
WASX7303I: The following options are passed to the scripting environment and are available as arguments that are stored in the argv v
ariable: "[C:\ACS\Jython_Scripts\Up
updateLP: INFO --- In main function
updateLP: INFO --- Loading the properties to Hash Map => START......
updateLP: INFO --- Loading the properties to Hash Map => DONE.
updateLP: INFO --- Adding property value to servers START......
WASX7017E: Exception received while running file "C:\ACS\Jython_Scripts\Upd
n: exception from Jython:
Traceback (innermost last):
File "<string>", line 130, in ?
File "<string>", line 123, in main
File "<string>", line 59, in createPropValues
File "<string>", line 64, in updateLP
TypeError: __add__ nor __radd__ defined for these operands
Update-LP.py
Update-LP.txt
> You are correct I have removed the cell name, node name and server name in the attached properties file. The property file which I am using is having those details.
This is very reasonable.
> For so reason when I am using single quote characters wsadmin is throwing the below error so I changed the single quote characters to double quote characters and it worked. I have updated the script with double quote characters.
Jython (and Python) allow either single, or double quotes as string delimiters. The limitations are:
- The same quote character (either single or double) must be used to end the string that was used to start the string. So, if you start the string with a single quote, then you must end with a single quote.
- If the string needs to include, or contain, the starting/ending quote character, then the place(s) within the string where this character should be positioned, must be "escaped" by having the quote character immediately preceded by a backslash character:
>>> 'Don\'t'
"Don't"
> WASX7015E: Exception running command: ...
> ... Invalid object name:
The "name" that you specified is invalid because it should start and end with a slash...
AdminConfig.getid( '/Cell:ATL0LW00R996VTNNode 01Cell/Nod e:ATL0LW00 R996VTNNod e01/Server :server1/' )
> Traceback (innermost last):
File "<string>", line 130, in ?
File "<string>", line 123, in main
File "<string>", line 59, in createPropValues
File "<string>", line 64, in updateLP
TypeError: __add__ nor __radd__ defined for these operands
The way to read this is:
- Line 130 is where the first (outermost) function call occurred.
When we look at this line, we find that it contains:
130: main()
Which is no surprise.
- The next function call happened in line 123, which happens to be within the function named main()
as the stack trace tells us. This line has:
123: createPropValues()
- The next function call happened in line 59, which is in createPropValues, and which looks like:
59: updateLP(...)
- The last line (i.e., 64) tells us the one in which the error (exception) actually occurred. This line has:
64: server = AdminConfig.getid("/Cell:" +cellName+ "/Node:"+n odeName+"/ Server:"+s erverName)
What's wrong with this statement? Well, it all depends upon the values of the variables.
If cellName, nodeName, and serverName are strings, then the plus sign represents a string concatenation operation. However, if, for example, the value of cellName is None, we get the following:
This is very reasonable.
> For so reason when I am using single quote characters wsadmin is throwing the below error so I changed the single quote characters to double quote characters and it worked. I have updated the script with double quote characters.
Jython (and Python) allow either single, or double quotes as string delimiters. The limitations are:
- The same quote character (either single or double) must be used to end the string that was used to start the string. So, if you start the string with a single quote, then you must end with a single quote.
- If the string needs to include, or contain, the starting/ending quote character, then the place(s) within the string where this character should be positioned, must be "escaped" by having the quote character immediately preceded by a backslash character:
>>> 'Don\'t'
"Don't"
> WASX7015E: Exception running command: ...
> ... Invalid object name:
The "name" that you specified is invalid because it should start and end with a slash...
AdminConfig.getid( '/Cell:ATL0LW00R996VTNNode
> Traceback (innermost last):
File "<string>", line 130, in ?
File "<string>", line 123, in main
File "<string>", line 59, in createPropValues
File "<string>", line 64, in updateLP
TypeError: __add__ nor __radd__ defined for these operands
The way to read this is:
- Line 130 is where the first (outermost) function call occurred.
When we look at this line, we find that it contains:
130: main()
Which is no surprise.
- The next function call happened in line 123, which happens to be within the function named main()
as the stack trace tells us. This line has:
123: createPropValues()
- The next function call happened in line 59, which is in createPropValues, and which looks like:
59: updateLP(...)
- The last line (i.e., 64) tells us the one in which the error (exception) actually occurred. This line has:
64: server = AdminConfig.getid("/Cell:"
What's wrong with this statement? Well, it all depends upon the values of the variables.
If cellName, nodeName, and serverName are strings, then the plus sign represents a string concatenation operation. However, if, for example, the value of cellName is None, we get the following:
wsadmin>"/Cell:" + None
WASX7015E: Exception running command: ""/Cell:" + None"; exception information:
com.ibm.bsf.BSFException: exception from Jython:
Traceback (innermost last):
File "<input>", line 1, in ?
TypeError: __add__ nor __radd__ defined for these operands
So, you really need to verify your data before you use it.
Does that make sense?
Does that make sense?
ASKER
Thank you somuch for your help. Yes it make perfect sence.
Now I have resolve few issues with script but now it failing with a message saying Listener port not there on the server. Please find the details below. Can you please fix the logic which I have used in the script?
Requirments of othe script is
1. check whether the ListnerPort is there or not, if it not there exit from the script saying ListnerPort is not there.
2 If ListnerPort is there update the ListnerPort properties by taking them from the properties file.
C:\IBM\WebSphere\AppServer \profiles\ AppSrv01\b in>wsadmin -lang jython -f C:\ACS\Jython_Scripts\Upda te_LP.py C:\ACS\Jython_Scripts\Upd
ate_LP.txt
WASX7209I: Connected to process "server1" on node ATL0LW00R996VTNNode01 using SOAP connector; The type of process is: UnManagedProce
ss
WASX7303I: The following options are passed to the scripting environment and are available as arguments that are stored in the argv v
ariable: "[C:\ACS\Jython_Scripts\Up date_LP.tx t]"
updateLP: INFO --- In main function
updateLP: INFO --- Loading the properties to Hash Map => START......
updateLP: INFO --- Loading the properties to Hash Map => DONE.
updateLP: INFO --- Adding property value to servers START......
updateLP: INFO --- Checking to see if Listener port sample is configured on server server1
updateLP: INFO --- Listener port sample Not there on server server1. Skipping Listener port modification.
Now I have resolve few issues with script but now it failing with a message saying Listener port not there on the server. Please find the details below. Can you please fix the logic which I have used in the script?
Requirments of othe script is
1. check whether the ListnerPort is there or not, if it not there exit from the script saying ListnerPort is not there.
2 If ListnerPort is there update the ListnerPort properties by taking them from the properties file.
C:\IBM\WebSphere\AppServer
ate_LP.txt
WASX7209I: Connected to process "server1" on node ATL0LW00R996VTNNode01 using SOAP connector; The type of process is: UnManagedProce
ss
WASX7303I: The following options are passed to the scripting environment and are available as arguments that are stored in the argv v
ariable: "[C:\ACS\Jython_Scripts\Up
updateLP: INFO --- In main function
updateLP: INFO --- Loading the properties to Hash Map => START......
updateLP: INFO --- Loading the properties to Hash Map => DONE.
updateLP: INFO --- Adding property value to servers START......
updateLP: INFO --- Checking to see if Listener port sample is configured on server server1
updateLP: INFO --- Listener port sample Not there on server server1. Skipping Listener port modification.
Your description of what you need (now) is much better. [Thank you!]
Please attach the current version of your script.
Thanks!
Please attach the current version of your script.
Thanks!
ASKER
ASKER
Hi HonorGod
I know you are busy. Just want to know the status. Thank you very much for your help.
I know you are busy. Just want to know the status. Thank you very much for your help.
I know that it's not complete, but take a look at this...
'''Command: %(cmdName)s\n
Purpose: Use a properties file to modify Listener Ports\n
Usage: wsadmin -f %(cmdName)s.py <inputFile>\n
Example: ./wsadmin.sh -f %(cmdName)s.py %(cmdName)s.txt'''
import AdminConfig;
import os;
import sys;
#---------------------------------------------------------------------
# Name: process()
# Role: Attempt to read, and process the specified input file.
#---------------------------------------------------------------------
def process( filename ) :
# print 'process( "%s" )' % filename;
try :
info, server = {}, None;
f = open( filename );
data = f.read().splitlines();
for line in data :
if line and not line.startswith( '#' ) :
if line.find( ':' ) < 0 :
name, value = line.split( '=', 1 );
info[ name ] = value;
elif line.startswith( 'Property:Value' ) :
if not server :
name = '/Cell:%(CellName)s/Node:%(NodeName)s/Server:%(ServerName)s/' % info;
server = AdminConfig.getid( name );
if not server :
print 'Specified server not found: %s\n' % name;
break;
head, tail = line.split( '=', 1 );
jndi, rest = tail.split( ':', 1 );
print 'jndi:', jndi;
print 'rest:', rest;
f.close();
except :
t, v = sys.exc_info()[ :2 ];
t, v = str( t ), str( v );
print 'Exception\n Type: %s\nValue: %s' % ( t, v );
#---------------------------------------------------------------------
# Name: textFile()
# Role: Determine if the specified file exists, and is a "regular"
# file (e.g., is not a directory)
#---------------------------------------------------------------------
def textFile( filename ) :
return os.path.exists( filename ) and os.path.isfile( filename );
#---------------------------------------------------------------------
# Name: main()
# Role: Routine used to perform script role.
#---------------------------------------------------------------------
def main() :
argc = len( sys.argv );
if argc != 1 :
print 'Error: unexpected number of command line arguments: %d\n' % argc;
Usage();
filename = sys.argv[ 0 ];
# print 'filename: %s' % filename;
if not textFile( filename ) :
print 'Error: file not found, or invalid: %s\n' % filename;
Usage();
process( filename );
#---------------------------------------------------------------------
# Name: Usage()
# Role: Display script usage (docstring) information
#---------------------------------------------------------------------
def Usage( cmdName = None ) :
import re;
if not cmdName :
cmdLine = os.environ.get( 'IBM_JAVA_COMMAND_LINE' );
scriptPath = re.sub( '.*-f ([^ ]*).*', r'\1', cmdLine );
scriptName = os.path.basename( scriptPath );
if scriptName.endswith( '.py' ) :
cmdName = scriptName[ :-3 ];
else :
cmdName = scriptName;
print __doc__ % locals();
sys.exit();
#---------------------------------------------------------------------
# Name: anonymous / unnamed
# Role: script execution appears to begin here
# Note: Verify that the script was executed, not imported.
#---------------------------------------------------------------------
if __name__ == '__main__' :
main();
else :
print 'Error: Script must be executed, not imported.\n'
Usage( __name__ );
I don't have any ListenerPorts defined, so I was wondering if you would try the following for me in an wsadmin command invocation:
I'm trying to find out if we can get the list of defined ListenerPorts scoped by an Application Server
Thanks
I'm trying to find out if we can get the list of defined ListenerPorts scoped by an Application Server
Thanks
wsadmin -conntype none -lang jython -c "print AdminConfig.list( 'ListenerPort', AdminConfig.getid( '/Cell:ATL0LW00R996VTNNode01Cell/Node:ATL0LW00R996VTNNode01/Server:server1/' ) )"
Equivalent interactive commands:
---------------------------------------------------------------
s = AdminConfig.getid( '/Cell:ATL0LW00R996VTNNode01Cell/Node:ATL0LW00R996VTNNode01/Server:server1/' )
print AdminConfig.list( 'ListenerPort', s )
---------------------------------------------------------------
ASKER
wsadmin>s = AdminConfig.getid( '/Cell:ATL0LW00R996VTNNode 01Cell/Nod e:ATL0LW00 R996VTNNod e01/Server :server1/' )
wsadmin>print AdminConfig.list( 'ListenerPort', s )
sample(cells/ATL0LW00R996V TNNode01Ce ll/nodes/A TL0LW00R99 6VTNNode01 /servers/s erver1|ser ver.xml#Li stenerPort _129782655 1343)
wsadmin>print AdminConfig.list( 'ListenerPort', s )
sample(cells/ATL0LW00R996V
Excellent. That helps immensely!
Alright. This version makes use of that information.
Here's the next question for you:
Given the specified "ListenerPort Name", do you want to modify all of the attributes using the input line?
For example, from your input file, the "ListenerPort Name" should be "sample"
Do you want to change the connectionFactoryJNDIName to what follows, then
the maxSessions, maxRetries, and maxMessages using the (integer) values that follow?
What happens if a value is missing?
Are the values required, or optional?
Thanks for helping me understand.
Alright. This version makes use of that information.
Here's the next question for you:
Given the specified "ListenerPort Name", do you want to modify all of the attributes using the input line?
For example, from your input file, the "ListenerPort Name" should be "sample"
Do you want to change the connectionFactoryJNDIName to what follows, then
the maxSessions, maxRetries, and maxMessages using the (integer) values that follow?
What happens if a value is missing?
Are the values required, or optional?
Thanks for helping me understand.
'''Command: %(cmdName)s\n
Purpose: Use a properties file to modify Listener Ports\n
Usage: wsadmin -f %(cmdName)s.py <inputFile>\n
Example: ./wsadmin.sh -f %(cmdName)s.py %(cmdName)s.txt'''
import AdminConfig;
import os;
import sys;
#---------------------------------------------------------------------
# Name: process()
# Role: Attempt to read, and process the specified input file.
#---------------------------------------------------------------------
def process( filename ) :
# print 'process( "%s" )' % filename;
try :
info, server = {}, None;
f = open( filename );
data = f.read().splitlines();
for line in data :
if line and not line.startswith( '#' ) :
if line.find( ':' ) < 0 :
name, value = line.split( '=', 1 );
info[ name ] = value;
elif line.startswith( 'Property:Value' ) :
if not server :
name = '/Cell:%(CellName)s/Node:%(NodeName)s/Server:%(ServerName)s/' % info;
server = AdminConfig.getid( name );
if not server :
print 'Specified server not found: %s\n' % name;
break;
prefix, suffix = line.split( '=', 1 );
LPname, rest = suffix.split( ':', 1 );
print 'LPname:', LPname;
print 'rest:', rest;
for LP in AdminConfig.list( 'ListenerPort', server ).splitlines() :
if LPname == AdminConfig.showAttribute( LP, 'name' ) :
print AdminConfig.show( LP );
f.close();
except :
t, v = sys.exc_info()[ :2 ];
t, v = str( t ), str( v );
print 'Exception\n Type: %s\nValue: %s' % ( t, v );
#---------------------------------------------------------------------
# Name: textFile()
# Role: Determine if the specified file exists, and is a "regular"
# file (e.g., is not a directory)
#---------------------------------------------------------------------
def textFile( filename ) :
return os.path.exists( filename ) and os.path.isfile( filename );
#---------------------------------------------------------------------
# Name: main()
# Role: Routine used to perform script role.
#---------------------------------------------------------------------
def main() :
argc = len( sys.argv );
if argc != 1 :
print 'Error: unexpected number of command line arguments: %d\n' % argc;
Usage();
filename = sys.argv[ 0 ];
# print 'filename: %s' % filename;
if not textFile( filename ) :
print 'Error: file not found, or invalid: %s\n' % filename;
Usage();
process( filename );
#---------------------------------------------------------------------
# Name: Usage()
# Role: Display script usage (docstring) information
#---------------------------------------------------------------------
def Usage( cmdName = None ) :
import re;
if not cmdName :
cmdLine = os.environ.get( 'IBM_JAVA_COMMAND_LINE' );
scriptPath = re.sub( '.*-f ([^ ]*).*', r'\1', cmdLine );
scriptName = os.path.basename( scriptPath );
if scriptName.endswith( '.py' ) :
cmdName = scriptName[ :-3 ];
else :
cmdName = scriptName;
print __doc__ % locals();
sys.exit();
#---------------------------------------------------------------------
# Name: anonymous / unnamed
# Role: script execution appears to begin here
# Note: Verify that the script was executed, not imported.
#---------------------------------------------------------------------
if __name__ == '__main__' :
main();
else :
print 'Error: Script must be executed, not imported.\n'
Usage( __name__ );
ASKER
It would be good if they are optional. Depending on the requirements we will update the properties file with the required values. If we did not specify a value in the properties files that value should not be changed.
Thank you so much for your help. You Rock...
Thank you so much for your help. You Rock...
This "might" work...
'''Command: %(cmdName)s\n
Purpose: Use a properties file to modify Listener Ports\n
Usage: wsadmin -f %(cmdName)s.py <inputFile>\n
Example: ./wsadmin.sh -f %(cmdName)s.py %(cmdName)s.txt'''
import AdminConfig;
import os;
import sys;
#---------------------------------------------------------------------
# Name: process()
# Role: Attempt to read, and process the specified input file.
#---------------------------------------------------------------------
def process( filename ) :
# print 'process( "%s" )' % filename;
try :
info, server = {}, None;
f = open( filename );
data = f.read().splitlines();
for line in data :
if line and not line.startswith( '#' ) :
if line.find( ':' ) < 0 :
name, value = line.split( '=', 1 );
info[ name ] = value;
elif line.startswith( 'Property:Value' ) :
if not server :
name = '/Cell:%(CellName)s/Node:%(NodeName)s/Server:%(ServerName)s/' % info;
server = AdminConfig.getid( name );
if not server :
print 'Specified server not found: %s\n' % name;
break;
#-----------------------------------------------------------
# prefix == 'Property:Value'
# suffix == ListenerPort Name:JNDI Name,Connection Factory Name,maxsessions,maxretries,maxmessages
#-----------------------------------------------------------
prefix, suffix = line.split( '=', 1 );
LPname, rest = suffix.split( ':', 1 );
print 'LPname:', LPname;
print 'rest:', rest;
#-----------------------------------------------------------
# [ 0 ] == destinationJNDIName
# [ 1 ] == connectionFactoryJNDIName
# [ 2 ] == maxSessions
# [ 3 ] == maxRetries
# [ 4 ] == maxMessages
#-----------------------------------------------------------
values = rest.split( ',' );
values.extend( [ '' ] * 5 ); # Guarantee sufficient values exist...
for LP in AdminConfig.list( 'ListenerPort', server ).splitlines() :
if LPname == AdminConfig.showAttribute( LP, 'name' ) :
print 'Before:\n' + ( '-' * 50 );
print AdminConfig.show( LP );
print '-' * 50;
#-------------------------------------------------------
# Use list comprehension to
#-------------------------------------------------------
changes = [ item for item in [ 'destinationJNDIName' , values[ 0 ] ],
[ 'connectionFactoryJNDIName', values[ 1 ] ],
[ 'maxSessions' , values[ 2 ] ],
[ 'maxRetries' , values[ 3 ] ],
[ 'maxMessages' , values[ 4 ] ] if item[ 1 ] ] );
print 'Changes: ' + str( changes );
AdminConfig.modify( LP, changes );
print ' After:\n' + ( '-' * 50 );
print AdminConfig.show( LP );
print '-' * 50;
f.close();
except :
t, v = sys.exc_info()[ :2 ];
t, v = str( t ), str( v );
print 'Exception\n Type: %s\nValue: %s' % ( t, v );
#---------------------------------------------------------------------
# Name: textFile()
# Role: Determine if the specified file exists, and is a "regular"
# file (e.g., is not a directory)
#---------------------------------------------------------------------
def textFile( filename ) :
return os.path.exists( filename ) and os.path.isfile( filename );
#---------------------------------------------------------------------
# Name: main()
# Role: Routine used to perform script role.
#---------------------------------------------------------------------
def main() :
argc = len( sys.argv );
if argc != 1 :
print 'Error: unexpected number of command line arguments: %d\n' % argc;
Usage();
filename = sys.argv[ 0 ];
# print 'filename: %s' % filename;
if not textFile( filename ) :
print 'Error: file not found, or invalid: %s\n' % filename;
Usage();
process( filename );
#---------------------------------------------------------------------
# Name: Usage()
# Role: Display script usage (docstring) information
#---------------------------------------------------------------------
def Usage( cmdName = None ) :
import re;
if not cmdName :
cmdLine = os.environ.get( 'IBM_JAVA_COMMAND_LINE' );
scriptPath = re.sub( '.*-f ([^ ]*).*', r'\1', cmdLine );
scriptName = os.path.basename( scriptPath );
if scriptName.endswith( '.py' ) :
cmdName = scriptName[ :-3 ];
else :
cmdName = scriptName;
print __doc__ % locals();
sys.exit();
#---------------------------------------------------------------------
# Name: anonymous / unnamed
# Role: script execution appears to begin here
# Note: Verify that the script was executed, not imported.
#---------------------------------------------------------------------
if __name__ == '__main__' :
main();
else :
print 'Error: Script must be executed, not imported.\n'
Usage( __name__ );
ASKER
I am getting below error when I am executing the script
C:\IBM\WebSphere\AppServer \profiles\ AppSrv01\b in>wsadmin -lang jython -f C:\ACS\Jython_Scripts\Fina l_Working_ Scripts\up dateLP.py C:\A
CS\Jython_Scripts\Final_Wo rking_Scri pts\Update LP.txt
WASX7209I: Connected to process "server1" on node ATL0LW00R996VTNNode01 using SOAP connector; The type of process is: UnManagedProce
ss
WASX7303I: The following options are passed to the scripting environment and are available as arguments that are stored in the argv v
ariable: "[C:\ACS\Jython_Scripts\Fi nal_Workin g_Scripts\ UpdateLP.t xt]"
WASX7017E: Exception received while running file "C:\ACS\Jython_Scripts\Fin al_Working _Scripts\u pdateLP.py "; exception information: co
m.ibm.bsf.BSFException: exception from Jython:
Traceback (innermost last):
File "<string>", line 6, in ?
ImportError: no module named AdminConfig
C:\IBM\WebSphere\AppServer
CS\Jython_Scripts\Final_Wo
WASX7209I: Connected to process "server1" on node ATL0LW00R996VTNNode01 using SOAP connector; The type of process is: UnManagedProce
ss
WASX7303I: The following options are passed to the scripting environment and are available as arguments that are stored in the argv v
ariable: "[C:\ACS\Jython_Scripts\Fi
WASX7017E: Exception received while running file "C:\ACS\Jython_Scripts\Fin
m.ibm.bsf.BSFException: exception from Jython:
Traceback (innermost last):
File "<string>", line 6, in ?
ImportError: no module named AdminConfig
hm. Sorry, I guess that my environment automatically made the wsadmin scripting object available in a way that let me do that statement (i.e., line 6).
What happens if you delete, or comment out that line?
e.g.,
Change:
import AdminConfig;
To:
# import AdminConfig;
What happens if you delete, or comment out that line?
e.g.,
Change:
import AdminConfig;
To:
# import AdminConfig;
ASKER
I getting below error.
C:\IBM\WebSphere\AppServer \profiles\ AppSrv01\b in>wsadmin -lang jython -f C:\ACS\Jython_Scripts\Fina l_Working_ Scripts\up dateLP_1.p y C:
\ACS\Jython_Scripts\Final_ Working_Sc ripts\Upda teLP.txt
WASX7209I: Connected to process "server1" on node ATL0LW00R996VTNNode01 using SOAP connector; The type of process is: UnManagedProce
ss
WASX7303I: The following options are passed to the scripting environment and are available as arguments that are stored in the argv v
ariable: "[C:\ACS\Jython_Scripts\Fi nal_Workin g_Scripts\ UpdateLP.t xt]"
Error: Script must be executed, not imported.
Command: main
Purpose: Use a properties file to modify Listener Ports
Usage: wsadmin -f main.py <inputFile>
Example: ./wsadmin.sh -f main.py main.txt
C:\IBM\WebSphere\AppServer \profiles\ AppSrv01\b in>
C:\IBM\WebSphere\AppServer
\ACS\Jython_Scripts\Final_
WASX7209I: Connected to process "server1" on node ATL0LW00R996VTNNode01 using SOAP connector; The type of process is: UnManagedProce
ss
WASX7303I: The following options are passed to the scripting environment and are available as arguments that are stored in the argv v
ariable: "[C:\ACS\Jython_Scripts\Fi
Error: Script must be executed, not imported.
Command: main
Purpose: Use a properties file to modify Listener Ports
Usage: wsadmin -f main.py <inputFile>
Example: ./wsadmin.sh -f main.py main.txt
C:\IBM\WebSphere\AppServer
ooh. What version of WebSphere are you using?!?
Change line 130 from this:
if __name__ == '__main__' :
To this:
if ( __name__ == '__main__' ) or ( __name__ == 'main' ) :
(sigh)... bit my wsadmin... thank you very much...
Change line 130 from this:
if __name__ == '__main__' :
To this:
if ( __name__ == '__main__' ) or ( __name__ == 'main' ) :
(sigh)... bit my wsadmin... thank you very much...
Did you try that suggestion?
Did it fix your issue?
Did it fix your issue?
hehe... That typo should have been..
bit BY wsadmin...
bit BY wsadmin...
ASKER
I am executing the script on WAS 6.1. Still gettings error...
C:\IBM\WebSphere\AppServer \profiles\ AppSrv01\b in>wsadmin -lang jython -f C:\ACS\Jython_Scripts\Fina l_Working_ Scripts\up dateLP_1.p y C:
\ACS\Jython_Scripts\Final_ Working_Sc ripts\Upda teLP.txt
WASX7209I: Connected to process "server1" on node ATL0LW00R996VTNNode01 using SOAP connector; The type of process is: UnManagedProce
ss
WASX7303I: The following options are passed to the scripting environment and are available as arguments that are stored in the argv v
ariable: "[C:\ACS\Jython_Scripts\Fi nal_Workin g_Scripts\ UpdateLP.t xt]"
WASX7017E: Exception received while running file "C:\ACS\Jython_Scripts\Fin al_Working _Scripts\u pdateLP_1. py"; exception information:
com.ibm.bsf.BSFException: exception from Jython:
Traceback (innermost last):
(no code object) at line 0
File "<string>", line 103
main();
^
SyntaxError: invalid syntax
C:\IBM\WebSphere\AppServer
\ACS\Jython_Scripts\Final_
WASX7209I: Connected to process "server1" on node ATL0LW00R996VTNNode01 using SOAP connector; The type of process is: UnManagedProce
ss
WASX7303I: The following options are passed to the scripting environment and are available as arguments that are stored in the argv v
ariable: "[C:\ACS\Jython_Scripts\Fi
WASX7017E: Exception received while running file "C:\ACS\Jython_Scripts\Fin
com.ibm.bsf.BSFException: exception from Jython:
Traceback (innermost last):
(no code object) at line 0
File "<string>", line 103
main();
^
SyntaxError: invalid syntax
The indentation must be wrong. Let me attach it as a file.
Update-LP.py.txt
Update-LP.py.txt
ASKER
Thank you so much for you hard work.
When I executed the above attached script it failed with below error in line 62. I think there extra ")" I removed it and script worked absolutely fine.
I think AdminConfig.Save() is missing Please let me know where to added save and sync node in the script.
C:\IBM\WebSphere\AppServer \profiles\ AppSrv01\b in>wsadmin -lang jython -f C:\ACS\Jython_Scripts\Fina l_Working_ Scripts\fi n\Update_L P.py
C:\ACS\Jython_Scripts\Fina l_Working_ Scripts\Up dateLP.txt
WASX7209I: Connected to process "server1" on node ATL0LW00R996VTNNode01 using SOAP connector; The type of process is: UnManagedProce
ss
WASX7303I: The following options are passed to the scripting environment and are available as arguments that are stored in the argv v
ariable: "[C:\ACS\Jython_Scripts\Fi nal_Workin g_Scripts\ UpdateLP.t xt]"
LPname: sample
rest: Dest,QCF,5,1,1
Before:
-------------------------- ---------- ---------- ----
[connectionFactoryJNDIName QCF]
[destinationJNDIName Dest]
[maxMessages 1]
[maxRetries 1]
[maxSessions 1]
[name sample]
[stateManagement (cells/ATL0LW00R996VTNNode 01Cell/nod es/ATL0LW0 0R996VTNNo de01/serve rs/server1 |server.xm l#StateMan ageable_12 9782655134
3)]
-------------------------- ---------- ---------- ----
Changes: [['destinationJNDIName', 'Dest'], ['connectionFactoryJNDINam e', 'QCF'], ['maxSessions', '5'], ['maxRetries', '1'], ['maxMess
ages', '1']]
After:
-------------------------- ---------- ---------- ----
[connectionFactoryJNDIName QCF]
[destinationJNDIName Dest]
[maxMessages 1]
[maxRetries 1]
[maxSessions 5]
[name sample]
[stateManagement (cells/ATL0LW00R996VTNNode 01Cell/nod es/ATL0LW0 0R996VTNNo de01/serve rs/server1 |server.xm l#StateMan ageable_12 9782655134
3)]
-------------------------- ---------- ---------- ----
WASX7309W: No "save" was performed before the script "C:\ACS\Jython_Scripts\Fin al_Working _Scripts\f in\Update_ LP.py" exited; configura
tion changes will not be saved.
When I executed the above attached script it failed with below error in line 62. I think there extra ")" I removed it and script worked absolutely fine.
I think AdminConfig.Save() is missing Please let me know where to added save and sync node in the script.
C:\IBM\WebSphere\AppServer
C:\ACS\Jython_Scripts\Fina
WASX7209I: Connected to process "server1" on node ATL0LW00R996VTNNode01 using SOAP connector; The type of process is: UnManagedProce
ss
WASX7303I: The following options are passed to the scripting environment and are available as arguments that are stored in the argv v
ariable: "[C:\ACS\Jython_Scripts\Fi
LPname: sample
rest: Dest,QCF,5,1,1
Before:
--------------------------
[connectionFactoryJNDIName
[destinationJNDIName Dest]
[maxMessages 1]
[maxRetries 1]
[maxSessions 1]
[name sample]
[stateManagement (cells/ATL0LW00R996VTNNode
3)]
--------------------------
Changes: [['destinationJNDIName', 'Dest'], ['connectionFactoryJNDINam
ages', '1']]
After:
--------------------------
[connectionFactoryJNDIName
[destinationJNDIName Dest]
[maxMessages 1]
[maxRetries 1]
[maxSessions 5]
[name sample]
[stateManagement (cells/ATL0LW00R996VTNNode
3)]
--------------------------
WASX7309W: No "save" was performed before the script "C:\ACS\Jython_Scripts\Fin
tion changes will not be saved.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Once again Thank you very much for the script. You are the Best.
Why did you choose your answer as the solution?
Was that a mistake? I think so... ;-)
Was that a mistake? I think so... ;-)
ASKER
I am sorry it is a mistake.
Thanks for the grade & points.
Good luck & have a great day.
Good luck & have a great day.