Technical

WLST 101

WebLogic Scripting Tool (WLST) is the scripting tool for administering WebLogic domains. Based on Jython (a Java implementation of the Python programming language) it allows users to automate repetitive tasks when building and maintaining their WebLogic deployments. Instead of having to install the domain manually, remembering all the configuration items you need to modify on the console and starting and restarting the servers you can automate this through the use of WLST scripts.

The contents of this post will be discussed at the Canberra Oracle Middleware Forum event. Come along to learn about this topic and others every month.

What can I do with it?

There are 4 main use cases for WLST, but as it’s a fully-fledged programming language there are lots of areas where you might find WLST useful.

  • Making changes to an installed domain
  • Creating a domain
  • Deploying applications to domains
  • Starting/stopping servers

How to use it

Via the command line:

java weblogic.WLST OR
 ./wlst.sh

With a jython script:

java weblogic.WLST script.py OR
./wlst.sh script.py

In Java

import weblogic.management.scripting

When using the command line options, make sure to set your environment variables. You can do so with the WL_HOME/server/bin/setWLSEnv.sh file.

Changing configuration

The most common action you will be doing in WLST is making changes to the configuration of your domain. This is done by traversing the ‘tree’ of available MBeans (Management Beans) in the domain and making your changes. Eg: To change the listen port for a domain, you would use the following:

readDomain('path to domain')
cd('Server/AdminServer')
set('ListenPort', 7777)
updateDomain()

Now, before you go off making changes to your domain you need to understand the difference between online and offline in WLST. Online in WLST means that you are connected to a running WebLogic domain, and offline means the domain is not running. This is important as there some things you can do in one mode, but not in the other. Generally you should make configuration changes in online mode and create and modify domains in offline mode (except for the above script which would be done in offline mode so the server can be started with this new information). If you make changes in offline mode on a running domain the changes will be ignored.

Creating a domain

You can use WLST to create a domain and configure it to suit your deployment needs. Templates are used to create the domain and you can either create your own templates or use some of the provided ones in WebLogic. The domain templates available in a base install of WebLogic (10.3.6) are (located in the WL_HOME/common/templates/domains folder):

  • wls.jar: A basic WebLogic Server domain. Use this to start with a clean slate
  • diameterdomain.jar: Sets up an IMS-like system (IP Media System)
  • geo1domain.jar: Used with the geo2domain to set up a graphically-redundant SIP domain
  • geo2domain.jar: See above
  • rdmbsdomain.jar: Sets up a weblogic domain with a different security provider database
  • replicateddomain.jar: Sets up a replicated SIP cluster with engines and two replicas
  • sipserverdomain.jar: Creates a SIP server (Session Initiation Protocol). Used for controlling multimedia communication sessions such as voice and video over IP
  • wls_starter.jar: A base WebLogic server domain with a welcome page application

There are also templates to add applications to a domain plus more templates when you install other OFM components (such as SOA Suite and OSB).

Alternatively you can create your own templates by configuring a domain with config_builder.sh tool (in WL_HOME/common/bin). Or you can use WLST to read a domain and create a template from it using the writeTemplate function.

Managing servers

You can start and stop servers using the startServer and stopServer commands in WLST. However, it is recommended to use the Node Manager to start and stop the servers you need as the Node Manager can use start-up scripts and start servers on multiple machines. I’ll post a more detailed example on how to start and stop using the NodeManager later.

Example: Heap Status

I found the following online (apologies I can’t remember who to credit) that’s a good (and useful) example of what can be done with WLST.

connect(username='weblogic', password='welcome1', url='t3://localhost:7001')
domainRuntime()
 
servers = domainRuntimeService.getServerRuntimes();
print('################################################################')
print('# Java heap information per server')
print('################################################################')
print('%20s %10s %8s %8s %4s' % ('Server','Current','Free','Max','Free'))
for server in servers:
   free    = int(server.getJVMRuntime().getHeapFreeCurrent())/(1024*1024)
   freePct = int(server.getJVMRuntime().getHeapFreePercent())
   current = int(server.getJVMRuntime().getHeapSizeCurrent())/(1024*1024)
   max     = int(server.getJVMRuntime().getHeapSizeMax())/(1024*1024)
   print('%20s %7d MB %5d MB %5d MB %3d%%' % (server.getName(),current,free,max,freePct))
 
disconnect()
exit()

This will return the Java heap usage for each server in your domain. Example output:

################################################################
# Java heap information per server
################################################################
 Server        Current   Free     Max      Free
 AdminServer   502 MB    160 MB   683 MB   49%

Tips

When you use WLST in the command line you will notice that you can’t access your history of commands (by pressing the up arrow). This can be annoying when you spell something wrong or forget a comma and have to rewrite your entire command. Thankfully there is a way to re-enable this feature (atleast on Linux). (The following instructions are for Oracle Linux)

Now you can access wlst by typing ‘wlst’ at the command line and you can use the arrow keys to access your command history. (Thanks to https://blogs.oracle.com/johngraves for this tip)

For more information on WLST check out the official Oracle documentation, in particular the Language Reference

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s