子脚本中的WLST命令

时间:2014-09-26 09:37:41

标签: python jython wlst

目前我正在研究可以执行外部jython脚本的jython脚本。执行的(外部)jython脚本必须在运行我的脚本的同一weblogic会话中运行,以便能够取消会话(如果出错)或激活它。我的脚本中正在创建weblogic连接,被调用的脚本必须使用创建的(使用'startEdit()')会话。

我找到了一种混合解决方案,但也许可以做得更好。

工作解决方案中执行的脚本:

import wlst_operations as wl
print 'Start'
wl.cd('/')
print wl.cmo
wl.cd('/Servers/AdminServer')
print wl.cmo
wl.cd('/JDBCSystemResources/pasDataSource/JDBCResource/pasDataSource/JDBCConnectionPoolPara    ms/pasDataSource')
print wl.cmo
wl.cmo.setInitialCapacity(6)

wlst_operations jython取自http://www.javamonamour.org/2013/08/wlst-nameerror-cd.html。 正如您所看到的,必须在每个WLST命令前面放置一个像引用('wl。')这样的对象... 输出很好:

[MBeanServerInvocationHandler]com.bea:Name=gintdev1,Type=Domain
[MBeanServerInvocationHandler]com.bea:Name=AdminServer,Type=Server
[MBeanServerInvocationHandler]com.bea:Name=pasDataSource,Type=weblogic.j2ee.descriptor.wl.JDBCConnectionPoolParamsBean,Parent=[gintdev1]/JDBCSystemResources[pasDataSource],Path=JDBCResource[pasDataSource]/JDBCConnectionPoolParams

当我不使用对象引用时:

from wlstModule import *
print 'user defined'
cd('/')
print cmo
cd('/Servers/AdminServer')
print cmo
cd('/JDBCSystemResources/pasDataSource/JDBCResource/pasDataSource/JDBCConnectionPoolParams/pasDataSource')
print cmo
cmo.setInitialCapacity(6)

然后输出是:

[MBeanServerInvocationHandler]com.bea:Name=gintdev1,Type=Domain
[MBeanServerInvocationHandler]com.bea:Name=gintdev1,Type=Domain
[MBeanServerInvocationHandler]com.bea:Name=gintdev1,Type=Domain
Problem invoking WLST - Traceback (innermost last):
  File "/tmp/lv30083/./orchestrator.py", line 83, in ?
  File "/tmp/lv30083/./orchestrator.py", line 66, in main
  File "/tmp/lv30083/./utils/orch_wl.py", line 55, in execute
  File "user_defined_script_incorrect.py", line 11, in ?
AttributeError: setInitialCapacity

即。 cd命令被执行(没有得到错误),但它只是没有跳转到数据源...

我的脚本是

import orch_logging
import sys
from wlstModule import *
class WeblogicManager(object):
    def connect_to_server(self, p_ssl, p_domainName, p_userConfigFile, p_userKeyFile):
        logger = orch_logging.Logger()
        logger.info('Trying to connect to the node manager. domainName='+p_domainName+',userConfigFile='+p_userConfigFile+',ssl='+p_ssl+',p_userKeyFile='+p_userKeyFile)
        try:
            connect(domainName=p_domainName,userConfigFile=p_userConfigFile,userKeyFile=p_userKeyFile)
            return True
        except:
            logger.error("Error while trying to connect to node manager!")
            return False
    def startEdit(self):
        edit()
        startEdit()
    def activate(self):
        activate()
    def undo(self):
        cancelEdit('y')  
    def disconnect(self):
        disconnect()
    def execute(self, path):
        execfile(path)

有没有办法在不使用'wl'的情况下使用WLST命令。在他们面前参考?

谢谢, 诉

1 个答案:

答案 0 :(得分:1)

我不得不修改我的脚本。所有操作现在都在一个上下文中(在我的脚本的上下文中)

import sys
from wlstModule import *
from weblogic.management.scripting.utils import WLSTUtil
import sys

# needed to execute normal (without object reference) WLST commands in child scripts
origPrompt = sys.ps1
theInterpreter = WLSTUtil.ensureInterpreter();
WLSTUtil.ensureWLCtx(theInterpreter)
execfile(WLSTUtil.getWLSTScriptPath())
execfile(WLSTUtil.getOfflineWLSTScriptPath())
exec(WLSTUtil.getOfflineWLSTScriptForModule())
execfile(WLSTUtil.getWLSTCommonModulePath())
theInterpreter = None
sys.ps1 = origPrompt
modules = WLSTUtil.getWLSTModules()
for mods in modules:
    execfile(mods.getAbsolutePath())
wlstPrompt = "false"

class WeblogicManager(object):
    ...
    def execute(self, path):
        execfile(path)