简体   繁体   中英

WLST commands in child script

Currently I am working on jython script that can execute an external jython script. The executed (external) jython script must run in the same weblogic session where my script runs in order to be able to cancel the session (in case of error) or activate it. The weblogic connection is being created in my script and the called script has to use the created (with 'startEdit()') session.

I found a hybrid solution but perhaps it can be done better.

The executed script in the working solution:

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)

The wlst_operations jython was taken from http://www.javamonamour.org/2013/08/wlst-nameerror-cd.html . As you can see an object like reference ('wl.') must be put in front of each WLST command… The output is fine:

[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

When I don't use the object reference:

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)

Then the output is:

[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

ie the cd commands are executed (not getting error) but it just doesn't jump to the datasource…

My script is

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)

Is there any way to use the WLST commands without using the 'wl.' reference in front of them?

Thanks, V.

I had to modify my script. All the operations are now in one context (in the context of my script)

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM