I have 2 scripts: Test1.py and Test2.py. Test2.py import Test1 and Test1.py simply invokes WebSphere wsadmin AdminConfig object and it works fine with jython 2.1, but it fails with jython 2.7.
Test1.py:
def print1():
print "I am Test1"
cell = AdminConfig.list('Cell')
print "cell " + cell
Test2.py:
import Test1
def print2():
Test1.print1()
print "I am Test2"
nodes = AdminConfig.list('Node')
print nodes
print2()
In jython 2.1, we have hardcoded in wsadmin code to retrieve each Adminxxxx objects from the __built__in such as:
mgr.exec("jython", "", -1, -1, "from org.python.core import __builtin__");
mgr.exec("jython", "", -1, -1, "__builtin__.Help = Help");
mgr.exec("jython", "", -1, -1, "__builtin__.AdminControl = AdminControl");
mgr.exec("jython", "", -1, -1, "__builtin__.AdminConfig = AdminConfig");
mgr.exec("jython", "", -1, -1, "__builtin__.AdminApp = AdminApp");
mgr.exec("jython", "", -1, -1, "__builtin__.AdminTask = AdminTask");
But it does not work in jython 2.7.
We will get the NameError: global name 'AdminConfig' is not defined:
WASX7017E: Exception received while running file "c:/test2.py"; exception information: com.ibm.bsf.BSFException: excepti
on from Jython:
Traceback (most recent call last):
File "<string>", line 15, in <module>
File "<string>", line 9, in print2
File "c:\xx1617.02\WebSphere\AppServer_2\profiles\Dmgr01\bin\Test1.py", line 21, in print1
cell = AdminConfig.list('Cell')
NameError: global name 'AdminConfig' is not defined
If I add the line in Test1.py to get AdminConfig object from sys._getframe(1).f_locals['AdminConfig'], it works fine.
Test1.py:
AdminConfig = sys._getframe(1).f_locals['AdminConfig']
def print1():
print "I am Test1"
cell = AdminConfig.list('Cell')
print "cell " + cell
I tried to call the same jython command in wsadmin code, but it does not work:
mgr.exec("jython", "import sys", 0, 0, "import sys");
mgr.exec("jython", "", -1, -1, "AdminConfig = sys._getframe(0).f_locals['AdminConfig']");
mgr.exec("jython", "", -1, -1, "AdminApp = sys._getframe(0).f_locals['AdminApp']");
mgr.exec("jython", "", -1, -1, "AdminControl = sys._getframe(0).f_locals['AdminControl']");
mgr.exec("jython", "", -1, -1, "AdminTask = sys._getframe(0).f_locals['AdminTask']");
mgr.exec("jython", "", -1, -1, "Help = sys._getframe(0).f_locals['Help']");
Can anyone look at this bug quickly as we will ship jython 2.7 in WebSphere Application Server V9 and it will impact our customers to use modules (import a module). Why it can't no longer get wsadmin Adminxxxx object from __builtin__? |