You are on page 1of 55

Weblogic Server 9/10 Administration L2

WebLogic Scripting Tool
Prachi Joshi

Objectives
 At the end of this session, participant should be able to



Describe the use of WLST
Write WLST scripts
Use interactive and embedded WLST
Write Ant scripts to leverage WLST

2

Contents
 Introduction to WLST
 WLST Online or Offline
 Interactive, Script , and Embedded Mode
 WLST Commands
 WLST sample scripts
 WLST using ant
 Embedded wlst sample

3

Introduction to WLST
 The WebLogic Scripting Tool (WLST) is a command-line
scripting environment that you can use to create, manage,
and monitor WebLogic Server domains
 It is based on the Java scripting interpreter, Jython
 In addition to supporting standard Jython features such as
local variables, conditional variables, and flow control
statements, WLST provides a set of scripting functions
(commands) that are specific to WebLogic Server
 User can extend the WebLogic scripting language to suit
his needs by following the Jython language syntax

4

WLST Online or Offline
 WLST can be used as
 Command-line equivalent to the WebLogic Server Administration
Console (WLST online)
 Or
 Command-line equivalent to the Configuration Wizard (WLST
offline)

5

Using WLST Online  WLST can be used to      Connect to a running Administration Server Manage the configuration of an active domain View performance data about resources in the domain Manage security data (such as adding or removing users) Connect to Managed Servers (cannot modify configuration data from Managed Servers)  WLST online is a Java Management Extensions (JMX) client  It interacts with a server’s in-memory collection of Managed Beans (MBeans). which are Java objects that provide a management interface for an underlying resource 6 .

inactive domain View performance data about resources in a domain Modify security data (such as adding or removing users)  WLST offline provides read and write access to the configuration data that is persisted in the domain’s config directory or in a domain template JAR created using Template Builder 7 . WLST can be used to      Create domain templates Create a new domain based on existing templates Extend an existing.Using WLST Offline  Without connecting to a running WebLogic Server instance.

WebLogic Server does not store most of its default values in the domain’s configuration files  This optimization prevents management objects from being displayed by WLST offline  If default value of attributes whose management object is not displayed by WLST offline needs to be changed. first use the create command to create the management object 8 .Restrictions For Modifying Configuration Data With WLST Offline  Oracle recommends not to use WLST offline to manage the configuration of an active domain  Offline edits are ignored by running servers and can be overwritten by JMX clients such as WLST online or the WebLogic Server Administration Console  As a performance optimization.

9 .

prototyping command syntax. and verifying configuration options before building a script  Using WLST interactively is particularly useful for getting immediate feedback after making a critical configuration change  The WLST scripting shell maintains a persistent connection with an instance of WebLogic Server  WLST can write all of the commands that you enter during a WLST session to a file  You can edit this file and run it as a WLST script 10 .Interactive. is useful for learning the tool. and Embedded Mode  Following techniques can be used to invoke WLST commands:  Interactive Mode:  Enter a command and view the response at a command-line prompt. Script .

Interactive Mode 11 .

you can:  Automate WebLogic Server configuration and application deployment  Apply the same configuration settings. much like a shell script  Scripts contain WLST commands in a text file with a . conditional statements. flow control constructs.py file extension  You use script files with the Jython commands for running scripts  Using WLST scripts.Interactive. across multiple nodes of a topology  Take advantage of scripting language features. and Embedded Mode Continued…  Script Mode:  Scripts invoke a sequence of WLST commands without requiring input. Script . such as loops. and variable evaluations that are limited in interactive mode  Schedule scripts to run at various times 12 . iteratively.

Script .Interactive. and Embedded Mode Continued…  Automate repetitive tasks and complex procedures  Configure an application in a hands-free data center  Embedded Mode  Instantiate the WLST interpreter in your Java code and use it to run WLST commands and scripts  All WLST commands and variables that you use in interactive and script mode can be run in embedded mode 13 .

Script And Embedded Mode  Script Mode  Embedded Mode 14 .

jar') 15 .Syntax for WLST Commands  Command names and arguments are case sensitive  Enclose arguments in single or double quotes  For example. 'newServer' or "newServer"  If you specify a backslash character (\) in a string. either precede the backslash with another backslash or precede the entire string with a lower-case r character  The \ or r prevents Jython from interpreting the backslash as a special character  For example when specifying a file pathname that contains a backslash:  readTemplate('c:\\userdomains\\mytemplates\\mytemplate.jar')  Or  readTemplate(r'c:\userdomains\mytemplates\mytemplate.

 If you need to cd to a management object whose name includes a forward slash (/).Syntax for WLST Commands Continued…  When using WLST offline. the following characters are not valid in names of management objects:  period (. surround the object name in parentheses  For example:  cd('JMSQueue/(jms/REGISTRATION_MDB_QUEUE)') 16 .)  forward slash (/)  backward slash (\).

WLST Commands 17 .

and redeploy applications and standalone modules to a WebLogic Server instance  Update an existing deployment plan  Interrogate the WebLogic Deployment Manager object  Start and stop a deployed application 18 .WSLT Command Categories  Browse Commands:  Navigate the hierarchy of configuration or runtime beans and control the prompt display  Control Commands:  Connect to or disconnect from a server  Create and configure a WebLogic domain or domain template  Exit WLST  Deployment Commands:  Deploy. undeploy.

servers. runtime bean.WSLT Command Categories Continued…  Diagnostics Commands:  Export diagnostic data  Editing Commands:  Interrogate and edit configuration beans  Information Commands:  Interrogate domains. shut down. and provide configuration bean. restart. and monitor WebLogic Server instances using Node Manager  Tree Commands:  Navigate among MBean hierarchies 19 . and variables. and WLST-related information  Life Cycle Commands:  Manage the life cycle of a server instance  Node Manager Commands:  Start.

Browse Commands  cd: (Online or Offline)  Navigate the hierarchy of configuration or runtime beans  currentTree: (Online)  Return the current tree location  prompt: (Online or Offline)  Toggle the display of path information at the prompt  pwd: (Online or Offline)  Display the current location in the configuration or runtime bean hierarchy 20 .

Control Commands  connect: (Online or Offline)  Connect WLST to a WebLogic Server instance  disconnect: (Online)  Disconnect WLST from a WebLogic Server instance  createDomain: (Offline)  Create a new domain using the specified template  readTemplate: (Offline)  Open an existing domain template for domain creation  writeDomain: (Offline)  Write the domain configuration information to the specified directory  closeTemplate: (Offline)  Close the current domain template 21 .

Control Commands Continued…  readDomain: (Offline)  Open an existing domain for updating  addTemplate: (Offline)  Extend the current domain using an application or service extension template  updateDomain: (Offline)  Update and save the current domain  closeDomain: (Offline)  Close the current domain  writeTemplate: (Offline)  Writes the configuration information to the specified domain template file  exit: (Online or Offline)  Exit WLST from interactive session and close the scripting shell 22 .

Deployment Commands  deploy: (Online)  Deploy an application to a WebLogic Server instance  distributeApplication: (Online)  Copy the deployment bundle to the specified targets  getWLDM: (Online)  Return the WebLogic DeploymentManager object  listApplications: (Online)  List all applications that are currently deployed in the domain  loadApplication: (Online)  Load an application and deployment plan into memory  redeploy: (Online)  Reload classes and redeploy a previously deployed application 23 .

making it un available to users  undeploy: (Online)  Undeploy an application from the specified servers  updateApplication: (Online)  Update an application configuration using a new deployment plan 24 . making it available to users  stopApplication: (Online)  Stop an application.Deployment Commands Continued…  startApplication: (Online)  Start an application.

Diagnostics Commands  exportDiagnosticData: (Offline)  Execute a query against the specified log file  exportDiagnosticDataFromServer: (Online)  Execute a query on the server side and retrieves the exported WebLogic Diagnostic Framework (WLDF) data 25 .

and discard all unsaved changes  This operation can be called by any user with administrator privileges.Editing Commands  activate: (Online or Offline)  Activate changes saved during the current editing session but not yet deployed  assign: (Offline)  Assign resources to one or more destinations  assignAll: (Offline)  Assign all applications or services to one or more destinations  cancelEdit: (Online)  Cancel an edit session. release the edit lock. even if the user did not start the edit session  create: (Online or Offline)  Create a configuration bean of the specified type for current bean 26 .

Editing Commands Continued…  delete: (Online or Offline)  Delete an instance of a configuration bean of the specified type for the current configuration bean  encrypt: (Online)  Encrypt the specified string  get: (Online or Offline)  Return the value of the specified attribute  getActivationTask: (Online)  Return the latest ActivationTask MBean on which a user can get status  Invoke: (Online)  Invoke a management operation on the current configuration bean  isRestartRequired: (Online)  Determine whether a server restart is required 27 .

Editing Commands Continued…  loadDB: (Offline)  Load SQL files into a database  loadProperties: (Online or Offline)  Load property values from a file  save: (Online)  Save the edits that have been made but have not yet been saved  set: (Online or Offline)  Set the specified attribute value for the current configuration bean  setOption: (Offline)  Set options related to a domain creation or update  showChanges: (Online)  Show the changes made by the current user during the current edit session 28 .

and discard unsaved changes  unassign: (Offline)  Unassign applications or resources from one or more destinations  unassignAll: (Offline)  Unassign applications or resources from one or more destinations  undo: (Online)  Revert all unsaved or unactivated edits  Validate: (Online)  Validate the changes made but have not yet been saved 29 .Editing Commands Continued…  startEdit: (Online)  Start a configuration edit session on behalf of the currently connected user  stopEdit: (Online)  Stop the current edit session. release the edit lock.

Information Commands  addListener: (Online)  Add a JMX listener to the specified Mbean  configToScript: (Online or Offline)  Convert an existing server configuration (config directory) to an executable WLST script  dumpStack: (Online or Offline)  Display stack trace from the last exception that occurred. and reset the trace  dumpVariables: (Online or Offline)  Display all variables used by WLST. including their name and value  find: (Online)  Find MBeans and attributes in the current hierarchy 30 .

Information Commands Continued…  getConfigManager: (Online)  Return the latest ConfigurationManagerBean MBean which manages the change process  getMBean: (Online)  Return the MBean by browsing to the specified path  getMBI: (Online)  Return the MBeanInfo for the specified MBeanType or the cmo variable  getPath: (Online)  Return the MBean path for the specified MBean instance  listChildTypes: (Online)  List all the children MBeans that can be created or deleted for the cmo 31 .

Information Commands Continued…  lookup: (Online)  Look up the specified Mbean  ls: (Online or Offline)  List all child beans and/or attributes for the current configuration or runtime bean  man: (Online)  Display help from MBeanInfo for the current MBean or its specified attribute  redirect: (Online or Offline)  Redirect WLST output to the specified filename  removeListener: (Online)  Remove a listener that was previously defined  showListeners: (Online)  Show all listeners that are currently defined 32 .

Information Commands Continued…  startRecording: (Online or Offline)  Record all user interactions with WLST. useful for capturing commands to replay  state: (Online)  Returns a map of servers or clusters and their state using Node Manager  stopRecording: (Online or Offline)  Stop recording WLST commands  stopRedirect: (Online or Offline)  Stop the redirection of WLST output to a file  storeUserConfig: (Online)  Create a user configuration file and an associated key file  threadDump: (Online or Offline)  Display a thread dump for the specified server 33 .

py) file 34 . such as the attribute names and values.Information Commands Continued…  viewMBean: (Online)  Display information about an MBean. and operations  writeIniFile: (Online or Offline)  Convert WLST definitions and method declarations to a Python (.

Life Cycle Commands  migrate: (Online)  Migrate services to a target server within a cluster  resume: (Online)  Resume a server instance that is suspended or in ADMIN state  shutdown: (Online)  Gracefully shut down a running server instance or cluster  start: (Online)  Start a Managed Server instance or a cluster using Node Manager  startServer: (Online or Offline)  Start the Administration Server  suspend: (Online)  Suspend a running server 35 .

properties and startup. boot.Node Manager Commands  nm: (Online)  Determine whether WLST is connected to Node Manager  nmConnect: (Online or Offline)  Connect WLST to Node Manager to establish a session  nmDisconnect: (Online or Offline)  Disconnect WLST from a Node Manager session  nmEnroll: (Online)  Enroll the machine on which WLST is currently running  nmGenBootStartupProps: (Online)  Generates the Node Manager property files.  nmKill: (Online or Offline)  Kill the specified server instance that was started with Node Manager 36 . for the specified server.properties.

Node Manager Commands Continued…  nmLog: (Online or Offline)  Return the Node Manager log  nmServerLog: (Online or Offline)  Return the server output log of the server that was started with Node Manager  nmServerStatus: (Online or Offline)  Return the status of the server that was started with Node Manager  nmStart: (Online or Offline)  Start a server in the current domain using Node Manager  nmVersion: (Online or Offline)  Return the Node Manager server version  startNodeManager: (Online or Offline)  Start Node Manager at default port (5556) 37 .

DomainMBean 38 .0  custom: (Online)  Navigate to the root of custom MBeans that are registered in the server  domainConfig: (Online)  Navigate to the last MBean to which you navigated in the domain configuration hierarchy or to the root of the hierarchy.Tree Commands  config: (Online)  Navigate to the last MBean to which you navigated in the configuration MBean hierarchy or to the root of all configuration beans. DomainMBean  This command is deprecated as of WebLogic Server 9.

DomainRuntimeMBean  edit: (Online)  Navigate to the last MBean to which you navigated in the configuration edit MBean hierarchy or to the root of the hierarchy.0 39 .Tree Commands Continued…  domainRuntime: (Online)  Navigate to the last MBean to which you navigated in the domain runtime hierarchy or to the root of the hierarchy. DomainMBean  Jndi: (Online)  Navigates to the JNDI tree for the server to which WLST is currently connected  runtime: (Online)  Navigate to the last MBean to which you navigated in the Runtime hierarchy or the root of all runtime objects. DomainRuntimeMBean  This command is deprecated as of WebLogic Server 9.

DomainMBean  serverRuntime: (Online)  Navigate to the last MBean to which you navigated in the runtime MBean hierarchy or to the root of the hierarchy.Tree Commands Continued…  serverConfig: (Online)  Navigate to the last MBean to which you navigated in the configuration MBean hierarchy or to the root of the hierarchy. ServerRuntimeMBean 40 .

py       Connects WLST to an Administration Server Starts an edit session And creates 10 Managed Servers It then creates two clusters Assigns servers to each cluster And disconnects WLST from the server  cluster_deletion.py  Removes the clusters and servers created in cluster_creation.WLST Online Sample Scripts  Online sample scripts can be found at c:\beahome\wlserver_10.py 41 .3\samples\server\examples\src\e xamples\wlst\online  cluster_creation.

JMS queues.WLST Online Sample Scripts Continued…  configJMSSystemResource. and JMS templates in a JMS System module  The JMS queues and topics are targeted using sub-deployments       deleteJMSSystemResource.py  Removes the JMS System module created by configJMSSystemResource.py 42 .py Connects WLST to an Administration Server Starts an edit session Creates two JMS Servers And targets them to the Administration Server Then creates JMS topics.

py 43 .py  Connects WLST to an Administration Server  Starts an edit session  And creates a JDBC data source called myJDBCDataSource  jdbc_data_source_deletion.py  Removes the JDBC data source created by jdbc_data_source_creation.WLST Online Sample Scripts Continued…  jdbc_data_source_creation.

Output of cluster_creation.py 44 .

py  Creates a simple WebLogic domain demonstrating how to open a domain template. create and edit configuration objects. representing a typical development environment  This type of configuration is not recommended for production environments  The script uses the Basic WebLogic Server Domain template  distributedQueues.py  Demonstrates two methods for creating distributed queues  The script uses the Basic WebLogic Server Domain template and extends it using the Avitek Medical Records Sample 45 .WLST Offline Sample Scripts  The WLST offline scripts are located at: WL_HOME\common\templates\scripts\wlst  basicWLSDomain. and write the domain configuration information to the specified directory  The sample consists of a single server.

py  Creates a single-cluster domain.WLST Offline Sample Scripts Continued…  clusterMedRecDomain. nor does it deploy any sample applications  The script uses the Basic WebLogic Server Domain template 46 . creating three Managed Servers and assigning them to a cluster  The script uses the Basic WebLogic Server Domain template and extends it using the Avitek Medical Records Sample extension template  sampleMedRecDomain.py  Creates a domain that defines resources similar to those used in the Avitek MedRec sample  This example does not recreate the MedRec example in its entirety.

or you can create a WLST script in a nested element within this task  The wlst task is predefined in the version of Ant that is installed with WebLogic Server  Sample ant build. that invokes a WLST script from an Ant build file  This task is used to invoke the script file.xml file for running WLST script 47 . wlst.Running WLST from Ant  WebLogic Server provides a custom Ant task.

wlst Task  <taskdef name="wlst" classname="weblogic. if no nested <script> is used 48 .ant.management. this task fails  Required: Yes.taskdefs.WLSTTa sk" />  Parameters:  properties="prop sFile"  Name and location of a properties file that contains name-value pairs that you can reference in your WLST script  Required: No  fileName="fileName"  Name and location of the WLST script file that you would like to execute  If the specified WLST script file does not exist.

wlst Task Continued…  executeScriptBef oreFile="value"  Boolean value specifying whether this task invokes the script in the nested <script> element before the script file specified by the fileName attribute  This attribute defaults to true. specifying that the embedded script is invoked first  Required: No  Default: true  debug="value"  Boolean value specifying whether debug statements should be output when this task is executed  Required: No  Default: false 49 .

argv variable  Required: No  failOnError="val ue"  Boolean value specifying whether the Ant build will fail if this task fails  Required: No  Default: true 50 .wlst Task Continued…  arguments="arglist"  List of arguments to pass to the script  These arguments are accessible using the sys.

dir}"/> </classpath> <script> connect('weblogic'. 't3://localhost:7001') </script> </wlst> </target> 51 .classpath./myscript. 'weblogic'.py"> <classpath> <pathelement location="${my.Sample ant script <target name="configServer"> <wlst debug="false" failOnError="false" executeScriptBeforeFile="true" fileName=".

Running cluster_creation.py Using Ant 52 .

Embedded Mode Sample  Sample java code illustrates how to instantiate the WLST interpreter and use it to  connect to a running server  create two servers  and assign them to clusters  EmbeddedWLST.java 53 .

and Embedded Mode WLST Commands WLST sample scripts WLST using ant Embedded wlst sample 54 .Summary  In this session we covered        Introduction to WLST WLST Online or Offline Interactive. Script .