10 Apr 2012
April 10, 2012

NameError: AdminTask

April 10, 2012 Blog, WebSphere, WebSphere Application Server 0 Comment

When accessing a wsadmin object in my imported Jython module, I get the following error:

C:\scripts>"C:/Program Files/IBM/WebSphere/AppServer/profiles/AppSrv01/bin/wsadmin.bat" -lang jython -f "C:/scripts/class_test.py"
WASX7209I: Connected to process "server1" on node myNode01 using SOAP connector;  The type of process is: UnManagedProcess
*** Loading Class JVMModifier...
setJVMProperties.py loaded as a module
dir(): ['__doc__', '__file__', '__name__', 'setJVMPropertiesClass']
METHOD: nodeName
METHOD: serverName
METHOD: verboseModeClass
METHOD: verboseModeGarbageCollection
METHOD: verboseModeJNI
METHOD: initialHeapSize
METHOD: maximumHeapSize
setJVMProperties: Modifying attributes: [ -serverName server1 -nodeName myNode01 -verboseModeClass false -verboseModeGarbageCollection false -verboseModeJNI false -ini
imumHeapSize 1024]
WASX7017E: Exception received while running file "C:/scripts/class_test.py"; exception information: com.ibm.bsf.BSFException: exception from Jython:
Traceback (innermost last):
  File "<string>", line 10, in ?
  File "C:\scripts\.\classJVMProperties.py", line 171, in modify
NameError: AdminTask

The simple reason is that since we are importing a jython module and in this module there is a call to AdminTask, we cannot reference the AdminTask object from the parent module that is importing our module that contains the call to AdminTask. This is because we have lost the name space.

1. Change your code not use imports
2. User profile scripts (add a jython module to preload the wsadmin objects when your scrip, before your script is called.

Example: Code to import WAS Admin Objects using the profile command:

set WAS_HOME=C:/Program Files/IBM/WebSphere/AppServer/profiles/AppSrv01
set SCRIPT_HOME=C:/scripts
"%WAS_HOME%/bin/wsadmin.bat" -lang jython -profile "%SCRIPT_HOME%/wasObjects.py" -f "%SCRIPT_HOME%/class_test.py" 
sys.modules[ 'AdminApp' ] = AdminApp
sys.modules[ 'AdminConfig' ] = AdminConfig
sys.modules[ 'AdminControl' ] = AdminControl
sys.modules[ 'AdminTask' ] = AdminTask
sys.modules[ 'Help' ] = Help

Leave a Reply