WLST as a Jython Module

Few questions that I answered about WLST as a module via various email queries recently.

What is a Jython Module?
In simple words, a jython Module is more or less like a Java class/object that you can import into other Modules. Lets say, you wrote a script/module ‘A.py’ and you defined a function ‘myFunction’. Now you can import this A.py into a different script, say B.py’ and call the function ‘myFunction’. Here’s how you do it.

A.py
——-
def myFunction():
··print “Hello There!”

def printFirstName(myName):
··print “Hello “+myName

B.py
——
import A
A.myFunction()
A.printFirstName(“satya”)

WLST provides a convienient way for you to import it as a module into your scripts and use all the WLST commands that are supported. The advantage of doing this is you can write Jython Modules without any WebLogic dependency and import WLST module into these modules. For example, now you can have another module C.py where you will import wlstModule.py and A.py.

C.py
——
import A
import wlstModule.py as myWLST
# connect to the server
myWLST.connect(‘weblogic’,'weblogic’,'t3://sghattu:7001′)
# call a function from module A
A.printFirstName(“satya”)
#start and edit session and create a server
myWLST.edit()
myWLST.startEdit()
newSvr = myWLST.cmo.createServer(‘ms1′)
newSvr.setListenPort(8001)
myWLST.activate()
myWLST.disconnect()


What is the difference between WLST as a Module and invoking WLST?
If you invoke WLST via ‘java weblogic.WLST‘, WLST instantiates a Jython Interpreter, creates a WLST Namespace and installs all the WLST functions in it. You can import other modules, but you will not have access to WLST functions from these external modules because when you import other modules they will be imported into the Jython’s Default NameSpace not the WLST NameSpace. To use your modules in WLST namespace you will have to execute the module in wlst NameSpace using execfile(externalModule.py).

Where can I find WLST Module and are there any recommendations
WLST Module is under {WL_HOME}/common/wlst/modules/wlstModule.py. You can also generate one using the writeIniFile command.
If you are using WLST as a module, you should use java org.python.util.jython to invoke your scripts. Do not use java weblogic.WLST and import WLST as a module. This will import WLST Module into WLST NameSpace and if you mix the module calls with straight WLST calls, you will see some weird interactions. This is not recommended. Please use straight Jython if you are using WLST as a Module.

_uacct = “UA-2684269-2″;
urchinTracker();

17 Responses to “WLST as a Jython Module”

  1. Vishnu says:

    Hello Satya,

    What tool, IDE can be used to code WLST/Jython scripts?

    Thanks for very useful info on your blog.

    cheers,
    Vishnu.

  2. Satya Ghattu's Blog says:

    Vishnu,
    I have answered your question with a blog entry, http://satya-ghattu.blogspot.com/2008/10/ide-for-wlst.html#links

  3. Mukul4U says:

    Hi Satya,

    I am unable to create roles and policies using WLST. I was able to create user and groups but no information is there on how to create global roles and policies.
    Can you please provide some info?

    Mukul

  4. msacks says:

    Satya,
    Do you have any recommendations for parsing script options for custom WLST scripts?

    It seems as if only getopt works with the WLST namespace, optparse does not seem to be supported by default.

  5. Madan says:

    Hi Satya,

    Can you recommend some way of starting Managed Servers directly without the help of Admin/Node manager using JMX?

    Thanks!
    Madan Noru

  6. Madan says:

    Hi Satya,

    Do you know a way to start managed server without the help of Nodemanager (Admin may be okay) using JMX?

    Thanks!
    Madan Noru

  7. Satya Ghattu's Blog says:

    Unfortunately there is no way you can programmatically start a managed server w/o NodeManager on a remote machine. You need some process on remote machine that can process your request and execute the start command. The only other alternative is execute the startManagedWebLogic script for each managed server

  8. Madan says:

    Thanks very much for your reply.

  9. Mohammad says:

    Hi Satya,

    I use Eclipse 3.4 that is not compatible with JyDT. so I use PyDev on Eclipse as Jython IDE.

    But I can not import WLST. I have added wlstModule.py, weblogic.jar and jython-modules.jar to my project.

    However I can use WLST in my IDE and have “ypeError: cannot lazy load PyObject subclass” error message.

    What can be the problem?

  10. Pankaj says:

    Hello Satya,
    Since you are the author of WLST, I am hoping you can shed some light on this:)

    I am attempting to use WLSTInterpreter class in a webapp that also uses JMX to connect to Websphere and Weblogic. The JMX piece works fine and I can querry mbeans on both the servers. However, on the WLS side, when I attempt to invoke the WLSTInterpreter constructor I get the not-very-useful message:

    Traceback (innermost last):
    File "&ltiostream&gt", line 31, in ?
    TypeError: cannot lazy load PyObject subclass

    Now I am attempting to run this webapp in Tomcat 6.0.18. I know that Tomcat truncates the java.class.path to only include the bootstrap classes. So I looked at the code of WLSTInterpreter and it's collaborators and it seems that it IS relying on the classpath. So I interjected a System.setProperty("java.class.path", "…") before I call the WLSTInterpreter class, but that doesn't seem to help. I still get that cryptic error.
    Can you tell me what class (within the WLST classes) throws that error?
    I cannot even use dumpStack() because I cannot even get an instance of the Jython Interpreter!

    Any help will be much appreciated!

  11. Sam says:

    I am writing a script to configure weblogic remotely. Am importing the wlst module to do that. can u tell me the jars which need o be in my classpath since i am getting errors
    thanks

  12. sghattu says:

    You will need weblogic.jar in the classpath.

  13. Sam says:

    And when i import the wlst module where do i put the wlstModule.py module? shud it go in the Jython home under lib or shud it just be in the classpath?
    I get this error if u have seen this before on the line where i import the wlstModule

    at weblogic.management.scripting.utils.WLSTUtil.getOfflineWLSTScriptPath(WLSTUtil.java:75)
    at weblogic.management.scripting.utils.WLSTUtil.setupOffline(WLSTUtil.java:214)
    at weblogic.management.scripting.utils.WLSTInterpreter.(WLSTInterpreter.java:133)
    at weblogic.management.scripting.utils.WLSTInterpreter.(WLSTInterpreter.java:75)
    at weblogic.management.scripting.utils.WLSTUtil.ensureInterpreter(WLSTUtil.java:135)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)

    java.lang.RuntimeException: java.lang.RuntimeException: Invocation Target exception while getting the WLSTOffLineScript path

    Any help would be appreciated

  14. Gaurav says:

    Hi Satya,

    I am using WLST with Weblogic 9.2 for automating an application deployment process. When I try to deploy EAR file using deploy command, it throws error saying application has invalid version identifier. I checked in MANIFEST-MF file and found that version included invalid characters such as curly braces. I removed them and it worked fine. My question is that why WLST throws error when application is deployed through WLST while no error is thrown when deployed manually through administative console? Is there any work aroud for this? Please help. If everytime I modify MANIFEST-MF file before running my scripts, it defeats the purpose of automation :-(
    Please note that no error is thrown when I deploy applications on Weblogic 8.1.6. Scripts written for Weblogic 8.1.6 work perfectly without any errors.

    Regards,
    Gaurav

  15. sghattu says:

    Thats weird. Did you approach Oracle Support about this? It seems like a bug especially if the console lets you deploy the same app w/o any issue. WLST directly uses the JMX MBeans to do the deployment and although console uses the Mbeans, sometimes it can do more validations and be more forgiving.
    Do let me know what you find.

    -satya ghattu

  16. Ryan says:

    When I enter an edit session with edit() & startEdit() and use the destroy commands for data sources or JMS modules in WLST for Weblogic 10 (Oracle WLS 11g) WLST prints out that it has deleted the desired module or other resource. Thus, i call activate() to commit my changes. If I then look in the Web console the deleted resource is still there, and if I try to create it again it fails with error message indicating the MBean already exists. Why is this?

  17. aziz says:

    Hi,
    I am using these java arguments also
    -Djava.security.egd=file:/dev/./urandom -Dweblogic.security.SSL.ignoreHostnameVerification=true -Dweblogic.security.TrustKeyStore=DemoTrust

    How can I pass those when I use wlst as jython module..

    otherwise it gives the below error:

    thanks