Chapter 8. Administration with scripting 329
Example 8-11 The wsadmin commands for properties based configuration
AdminTask.extractConfigProperties('-configData Node=myNode -propertiesFileName
myNodeProperties.props')
AdminTask.validateConfigProperties('-propertiesFileName myNodeProperties.props
-reportFile report.txt')
AdminTask.applyConfigProperties('-propertiesFileName myPropFile.props -validate
true')
AdminTask.deleteConfigProperties('-propertiesFileName myPropFile.props')
AdminTask.createPropertiesFileTemplates('-propertiesFileName serverTemplate.props
-configType Server')
Because it is not possible to modify every configuration using properties file-based
configuration, do
not use this tool for backup and recovery. Use the BackupConfig and
RestoreConfig commands in the <was_home>/bin directory as the main backup and recovery
tools.
8.6 Managing WebSphere using script libraries
You can use script libraries to perform a higher level of wsadmin functions than when using a
single wsadmin command. Only a single line from a library function is needed to perform
complex functions. Each script is written in Jython and is often referred to as
the Jython
script
. The script libraries are categorized into six types, and the types are subdivided, as
listed in Table 8-2.
Python script files are supplied for each Jython class file. The Python files can be read as text
files. Table 8-2 shows the scripts and the type of resources they manage. Each script has a
set of procedures that perform specific functions.
Table 8-2 The types of script libraries
Properties file-based configuration: You can find more information about properties
file-based configuration in the WebSphere Application Server information center at the
following website:
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=phil&product=was
-base-dist&topic=rxml_7propbasedconfig
TYPE Python (Jython) script file
Application AdminApplication
AdminBLA
PerfTuning ApplyPerfTuning
Resources AdminJ2C
AdminJDBC
AdminJMS
AdminResources
330 WebSphere Application Server V8.5 Administration and Configuration Guide for the Full Profile
8.6.1 Invoking script libraries
The script libraries are located in the install_root /scriptlibraries directory. These
libraries are loaded when wsadmin starts and are readily available from the wsadmin command
prompt or to be used from the customized scripts. You can invoke the scripts in interactive
mode or script mode.
Interactive mode
Interactive mode is suitable for simple tasks and testing. Using this mode allows you to get
the results directly. To invoke a script interactively, start a wsadmin session, and enter the
script name, procedure, and arguments at the wsadmin> prompt (see Example 8-12).
Example 8-12 Using the Jython scripts in interactive mode
C:\WebSphereV8.5\AppServer\bin>wsadmin -lang jython
WASX7209I: Connected to process "dmgr" on node DmgrNode02 using SOAP connector;
The type of process is: DeploymentManager
WASX7031I: For help, enter: "print Help.help()"
wsadmin>AdminServerManagement.checkIfServerExists("sys1Node01", "Amember01")
---------------------------------------------------------------
AdminServerManagement: Check if server exists
Node name: sys1Node01
Server name: Amember01
Usage: AdminServerManagement.checkIfServerExists("sys1Node01", "Amember01")
---------------------------------------------------------------
'true'
wsadmin>
Script file mode (-f)
Using a script file with wsadmin is useful when you want to have daily tasks performed
automatically or if you need to manage multiple servers. To run in script mode, select the
Security AdminAuthorizations
Servers AdminClusterManagement
AdminServerManagement
System AdminNodeGroupManagement
AdminNodeManagement
Utilities AdminLibHelp
AdminUtilities
Script libraries, their procedures, and syntax: You can find more information about
these script libraries in the WebSphere Application Server information center at the
following website:
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=phil&product=was
-base-dist&topic=welc_ref_adm_jython
TYPE Python (Jython) script file
Application AdminApplication
AdminBLA
Chapter 8. Administration with scripting 331
script libraries to use and merge them into your own script file. Save the custom script as a
Python file, and run it from the command line.
Example 8-13 shows a Python file containing two script library commands.
Example 8-13 The script for test.py
# Writting by Jython
# Script file name : test.py
AdminServerManagement.checkIfServerExists("sys1Node01", "Amember21")
AdminServerManagement.createApplicationServer(“sys1Node01”, “Amember21”)
Example 8-14 shows how to invoke the script.
Example 8-14 Using the invoke test.py script
C:\WebSphereV8.5\AppServer\bin>
C:\WebSphereV8.5\AppServer\bin>wsadmin.bat -lang jython -f C:\temp\test.py
Customizing scripts
Customizing scripts is an advanced use of the script mode. You can add customized code
written in Python or Jython to your script file (the one that calls the script libraries).
When customizing a script:
1. Run each Jython script in interactive mode and then verify the syntax and the result.
2. Create the script file that will call the script libraries by combining all Jython scripts. Verify
that the results are as you expect.
3. Add your additional wsadmin commands, written in Python and then verify that the
customized script does the work that you intended.
8.6.2 Displaying help for script libraries
You can use the AdminLibHelp script to display each script within a script library. For example,
the following command displays each script in the AdminApplication script library:
print AdminLibHelp.help("AdminApplication")
You can use the help script to display detailed descriptions, arguments, and usage
information for a specific script. For example, the following command displays detailed script
information for the listApplications script in the AdminApplication script library:
print AdminApplication.help('listApplications')
Example 8-15 shows sample code for displaying help information for the
createApplicationServer procedure in the AdminServerManagement script.
Example 8-15 Help information for a procedure in createApplicationServer
wsadmin>print AdminServerManagement.help('createApplicationServer')
WASL2004I: Procedure: createApplicationServer
Note: Do not modify the script libraries. If you need to customize the scripts, you can copy
parts of the library code to other files and modify the copied code to improve it or to better
suit your needs.

Get WebSphere Application Server V8.5 Administration and Configuration Guide for the Full Profile now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.