Weblogic Scripting Tool (WLST) Overview

Overview

WebLogic Scripting Tool (WLST) is a command-line scripting interface that enables you to manage and monitor Oracle WebLogic Server domains. WLST provides a way to automate administration tasks, such as configuring and deploying applications, managing servers and clusters, and monitoring domain resources. It supports both online and offline modes, allowing you to interact with the WebLogic Server domain in real-time or in batch mode. WLST scripts can be written in either Jython or Python scripting languages and can be executed either locally or remotely. WLST provides a powerful tool for managing and configuring complex WebLogic Server environments.

There are numerous newcomers in the WebLogic field, both in development and administration. Many of them are inexperienced with WLST. I decided to research and compile a list of the most helpful links available online for your reference.

One of my colleagues on the development team asked me how to get started with learning WLST after reading my blogs. I want to share my response with all my blog readers who wish to support newcomers to WLST. Currently, WLST supports the following application servers:

  • WebLogic 8.1
  • BEA WebLogic 9.0
  • BEA WebLogic 9.1
  • BEA WebLogic 9.2
  • BEA WebLogic 10.0

Since its inception in the BEA System Inc. era, WLST has been supported in WebLogic versions 8.1 onwards, including the latest service packs up to version 10.0. Following Oracle’s acquisition of BEA, WLST is supported in the following versions:

  • 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
  • Oracle WebLogic 14c

Weblogic Features Indentation – Clear Syntax

The programming structure of WLST strictly adheres to syntax indentation, which is similar to that used in Python programming. In my experience with WLST, it can be divided into four main sections:

  1. Import Section
  2. Global Variables
  3. Class and Function Definitions
  4. Main Program that utilises the above sections

Import section for Reuse

When importing WLST libraries, you have access to not only the Python standard libraries but also thousands of new Jython libraries. Additionally, you can import Java packages as modules, which provides greater flexibility in programming.

When creating a WLST script, files that are saved with the extension .py are referred to as Python modules. We can incorporate external languages, such as Java methods, into our WLST script using the import statement. Here are the syntaxes that can be used for this purpose:

import module
from module import submodule
from . import submodule

The sys module in WLST enables the use of command-line arguments in scripts. By using sys.args, you can write a WLST script that utilizes command-line arguments.

WLST Datatypes – Global Variables

In WLST, global variables can be defined at the beginning of the program and can be accessed across all the functions defined in the script. Alternatively, variables can be defined within the function definitions, making them local to that function. WLST supports Jython programming language data types, allowing for a wide range of data types to be utilized in scripts

  • Base Datatypes: integer, float, long, char, str, bool
  • Collection Types: list, dictionary, tuple, sequances, maps etc
  • Object types: Python objects and Java package objects

WLST supports Python Dynamic typing, which allows for the same variable to be used to store different types of data, as demonstrated below:

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 in WLST involves the creation of objects that can be defined and reused.

class CLASSNAME:
 def __init__():   #like C++ constructor
  self.name
  do something initially
 def function1():
  do some task 

Let’s explore the use of classes in WLST. Within a class, attributes can be defined and values can be assigned to them. Additionally, functions related to that class can be defined to make use of these attributes.

wls:/offline> class test:
...     u,p='weblogic','chaudhary@007'
...

Once the class has been defined, instances of that class can be created. For example, we can create an instance of the “test” class by defining “t” as an instance.

wls:/offline> t=test()
wls:/offline> print t.u,t.p
weblogic chaudhary@007

In WLST, there is a distinction between class attributes and instance attributes. Instance attributes, such as “u” and “p” in this example, can be modified by assignment:

wls:/offline> t.u='mohit'
wls:/offline> t.u
'mohit'

The value of the “u” attribute was modified from “weblogic” to “mohit”.

Function Definitions in WLST

Defining a function in WLST is a simple process. The function begins with the keyword “def”, followed by the function’s name and the number of arguments, followed by a colon. A tab space is then used to indicate the function block. A brief description of what the function will do can be included, followed by a number of WLST statements or control flow statements. At the bottom of the function, a value can be returned or the line can be left blank (this is optional).

Let’s try defining a function for converting kilobytes to megabytes in WLST. The function logic is that when an argument in kilobytes is passed, it will be divided by 1024 to obtain the megabyte value.

wls:/offline> def kb2MB(kb):
...     mb=kb/1024
...     return mb
...
wls:/offline> print kb2MB(2048)

WLST Operators

In WLST, you can use not only JMX accessing functions but also Python programming control flows. To use control flows, you must understand the operations that can be performed in WLST. Let’s take a look at some of them.

  • Comparison Operators:

These operators can be used in regular if statements or while statements.

==, >, <, <=, =>
  • Logical Operators:

Empty or zero values in WLST are represented by “”, 0, None, 0.0, [], and {}. Therefore, it is important to be cautious while defining a variable and assigning its value in WLST.

How WLST script Execution works?

In the following image, I will illustrate how the Python script is interpreted, compiled into Java code, and ultimately converted into bytecode that can be executed on the JVM.

The WLST script’s source code is composed of Jython instructions and is written in Python code. The file for the WLST program must have a .py extension, which is the source code containing a set of Jython instructions for a WebLogic domain. When instructed to run the script, it uses a JVM machine, and its invocation generates Java byte code internally, which is interpreted with the JVM to produce the desired output.

Cheers!!!

About the author

Mohit Chaudhary

Hey there, I am IT enthusiast who is passionate about Middleware, DevOps, Cloud and much more.

View all posts

Leave a Reply

Your email address will not be published. Required fields are marked *