WebLogic Scripting Tool (WLST) Overview
There are many newbies into the WebLogic stream ( Development/ Administration). Most of them are novice to WLST. I thought let me found a way to give you best links available on the net.
After being in the development team one of my buddy asked me "your blogs are very nice, I want to learn WLST. But where to start? " My answer for all my blog readers who want to encourage newbies in WLST can pass this post. Currently WLST is supporting Application Servers are listed as follows:
The WLST programming structure follows strict syntax indentation and it is the same structure as in Python programming. As per my experiances with WLST it can be divided into four parts
Import section for Reuse
importing WLST libraries includes Python standard libraries and thousands of new Jython libraries also included. You can have Java packages as module imports which gives you flexible programming.
While writing a WLST script, the file can be store with the extension .py are called python modules. We can reuse the external language such as Java methods into our WLST script you can use import statement for this. Here is the syntaxes that you can use.
You can write a WLST script that uses command line aruguments using sys module sys.args.
Let’s experiment with class in WLST. In a class we can define attributes and we can assign values to them. And we define functions related to that class that you will make.
After this we are able to create instances of the class test. Let us create t as a instance of test class.
There is a difference between class attribute and instance attributes. Let us know about it, The variables u, and p of the instance can be modified by assignment:
In u attribute value was changed into ‘vasuakka’ instead of ‘weblogic’.
Now, let’s experiment with function definition for conversion of Kilobytes to megabytes. The logic of this function is that we can get the megabyte value when you pass the argument as kilobyte this will be divided by 1024.
Comparition operators
This opertators we can use in regular if statements or while statements
Logical Operators
In WLST the variable can be empty or zero values are treated as "", 0, None, 0.0, [], and {}. So you need to be careful when you define a variable and moved the values of variables.
* Until the given number
* From one particular value to another
* From one value to another with increment by value
Experimenting with range function to understand all its capabilities The range command always start from the 0 if you pass single argument that is considered as number of values you want as output.
The source code for the WLST script is written in Python code. The WLST program file must have the extension as .py which is the source code consisting a set of Jython instructions for WebLogic domain. This source code is going to use a JVM machine when it is instructed to RUN the script; its invocation internally generates Java byte code to interpret with the JVM to produce the desired output.
You might wonder by seeing this Chines WLST link, but it is worthy to see in google chrome. Because the web-page is from china and entire page is in chineese language. If you have Google Chrome it will give you translate on top of the page you can choose your choice of language and have knowledge on WLST :)
Here I am sharing the wonderful presentation about WLST overview. Check this following SlideShare Presentation: it's pretty informative, it was delivered by James Bayer who is the technical expert from Oracle. Especially I more impressed myself to see the 47 slide saying about THIS blog as one of the web reference.
After being in the development team one of my buddy asked me "your blogs are very nice, I want to learn WLST. But where to start? " My answer for all my blog readers who want to encourage newbies in WLST can pass this post. Currently WLST is supporting Application Servers are listed as follows:
- WebLogic 8.1
- BEA WebLogic 9.0
- BEA WebLogic 9.1
- BEA WebLogic 9.2
- BEA WebLogic 10.0
- Oracle WebLogic 10g R3
- Oracle WebLogic 11gR1
- Oracle WebLogic 11gR1 PatchSet 1 (10.3.1)
- Oracle WebLogic 11gR1 PatchSet 2 (10.3.2)
- Oracle WebLogic 11gR1 PatchSet 3 (10.3.3)
- Oracle WebLogic 12c
WLST Features indentation - Clear Sytax
The WLST programming structure follows strict syntax indentation and it is the same structure as in Python programming. As per my experiances with WLST it can be divided into four parts
- Importing section
- Global variables
- Definations - class/function
- Main program uses above sections
Import section for Reuse
importing WLST libraries includes Python standard libraries and thousands of new Jython libraries also included. You can have Java packages as module imports which gives you flexible programming.
While writing a WLST script, the file can be store with the extension .py are called python modules. We can reuse the external language such as Java methods into our WLST script you can use import statement for this. Here is the syntaxes that you can use.
import module from module import submodule from . import submodule
You can write a WLST script that uses command line aruguments using sys module sys.args.
WLST Datatypes - Global variables
In WLST you can define the global variables on the top of the program that can be used across all the functions defined in the script. On the other hand you can define the variables in the function definitions that can be treated as local to the function, Jython programming language supported datatypes all can be used it supports- Base Datatypes: integer, float, long, char, str, bool
- Collection Types: list, dictionary, tuple, sequances, maps etc
- Object types: Python objects and Java package objects
Dynamic typing
In WLST supports Python Dynamic typing, we can use same variable for storing different type of data as shown below.
1
2
3
4
5
6
7
8
9
10 |
wls: / offline> # VAR CAN CHANGE INTO MANY TYPES wls: / offline> var = 10 wls: / offline> print var 10 wls: / offline> var = 'Busy in WLST' wls: / offline> print var Busy in WLST wls: / offline> var = [ 1 , 2 , 3 ] wls: / offline> print var [ 1 , 2 , 3 ] |
Class in WLST
Object oriented scripting can be defined and can be reusable with creation of objects.
1
2
3
4
5
6
7 |
class CLASSNAME:
def __init__(): #like C++ constructor
self .name
do something initially
def function1():
do some task |
1
2
3 |
wls: / offline> class test: ... u,p = 'weblogic' , 'vybhav@28' ... |
1
2
3 |
wls: / offline> t = test() wls: / offline> print t.u,t.p weblogic vybhav@ 28 |
1
2
3 |
wls: / offline> t.u = 'vasuakka' wls: / offline> t.u 'vasuakka' |
Function definitions in WLST
How to define a Function in WLST? It is simple it starts with keyword ‘def’, you need to give a name of the function followed by number of argument and a colon. After this you need to give a tab space indentation that indicates the function block. You can add text to tell about what this function will do. Then you can add number of WLST statements or control flow statements. At the bottom of the function you can return a value or you leave that line, it is optional.Now, let’s experiment with function definition for conversion of Kilobytes to megabytes. The logic of this function is that we can get the megabyte value when you pass the argument as kilobyte this will be divided by 1024.
1
2
3
4
5
6 |
wls: / offline> def kb2MB(kb): ... mb = kb / 1024 ... return mb ... wls: / offline> print kb2MB( 2048 ) 2 |
WLST Operators
You WLST commands statements not only JMX accessing functions we need to use some of the Python programming control flows in it. To use the control flow you must know about what kind of operations you can do in WLST. So let us see some of them are:Comparition operators
This opertators we can use in regular if statements or while statements
1 |
= = , >, <, < = , = > |
In WLST the variable can be empty or zero values are treated as "", 0, None, 0.0, [], and {}. So you need to be careful when you define a variable and moved the values of variables.
Iterations in WLST Scripts
We can see the major types of WLST iterations control flows available such as 'for loop' and 'while loop'.The range function
When you are using for-loop best trick to use with range built in Python function. It will take three different optional arguments and gives you different variety of values in the range of list as output.* Until the given number
* From one particular value to another
* From one value to another with increment by value
Experimenting with range function to understand all its capabilities The range command always start from the 0 if you pass single argument that is considered as number of values you want as output.
1
2
3
4
5
6
7
8
9 |
wls: / offline> R = range ( 11 ) wls: / offline> R [ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ] wls: / offline> R = range ( 2 , 10 , 2 ) wls: / offline> R [ 2 , 4 , 6 , 8 ] wls: / offline> R = range ( 2 , 10 , 3 ) wls: / offline> R [ 2 , 5 , 8 ] |
While loop control
This loop control works as same as in C programming style loop. The execution of while loop should not have any control on the variable that is used for iterate the loop. You need to initialize, check the termination condition and in the while loop block it should be iterated by increase or decrease as per program needs.![]() |
WLST While loop - WLST for loop |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 |
wls: / offline> while i< 10 : ... print 'jms' + str (i) + '_server' ... i = i + 1 ...
jms0_server jms1_server jms2_server jms3_server jms4_server jms5_server jms6_server jms7_server jms8_server jms9_server |
The 'for loop' in WLST
Every scripting favourite iterator is for loop. Let us dive into some of the examples with it. The example of the 'for loop' in WLST is given below
1
2
3
4
5
6
7
8
9
10
11
12
13
14 |
wls: / offline> slist = range ( 1 , 11 ) wls: / offline> for i in slist: ... print 'managed' + str (i) + '_server' ... managed1_server managed2_server managed3_server managed4_server managed5_server managed6_server managed7_server managed8_server managed9_server managed10_server |
How WLST script Execution works?
Here I am going to explain with the following picture, how the Python script will be interpreted and internally compiled to java code and then Byte code so that it can be executable on JVM.![]() |
WLST Execution process |
You might wonder by seeing this Chines WLST link, but it is worthy to see in google chrome. Because the web-page is from china and entire page is in chineese language. If you have Google Chrome it will give you translate on top of the page you can choose your choice of language and have knowledge on WLST :)
Here I am sharing the wonderful presentation about WLST overview. Check this following SlideShare Presentation: it's pretty informative, it was delivered by James Bayer who is the technical expert from Oracle. Especially I more impressed myself to see the 47 slide saying about THIS blog as one of the web reference.
Thankyou for visiting this post, feel free to post your comments after
'Weblogic' 카테고리의 다른 글
JVM Monitoring with WLST (0) | 2014.08.20 |
---|---|
WLST Thread Count (0) | 2014.08.20 |
Server State using WLST (0) | 2014.08.19 |
JDBC Monitoring (0) | 2014.08.19 |
weblogic coherence (0) | 2014.08.19 |