Using the Console to Create Repeatable Configuration Scripts
By tom.moreau on Aug 31, 2009
WebLogic Server provides several administration tools such as the WLS Console (a graphical user interface) and WLST (a tool that runs Jython-based configuration scripts).
If you need to make small ad hoc changes or one time configuration changes, the WLS Console is a great choice. However, sometimes you need to repeatedly make a set of coordinated changes. For example, you might want to scale up a domain by periodially adding an SSL-enabled server to an existing cluster as the load goes up. In these cases, writing a WLST script can be a better choice. A script guarantees consistency and saves the administrator from having to repeatedly make coordinated changes across a number of console pages.
So, how do you get started writing your WLST script, especially if you're not a WLST script expert? The WLS Console provides a recording feature that writes out the edits you make in the console to a WLST script.
The basic idea is that you:
- Log into the WLS Console and turn on script recording.
- Use the WLS console to make some changes (e.g add a new SSL-enabled server to a existing cluster).
- Turn off script recording.
- Hand edit the captured script to clean it up and parameterize it (for example, have it prompt for the server name).
This blog walks you through how to use the WLS Console's WLST script recording feature to create a script. The script prompts the adminstrator for a server name, listen address, listen port and SSL listen port. Then it creates a new SSL-enabled server with these values and adds it to the existing cluster named 'MyCluster'.
For this blog, I'm assuming that you're using a development mode domain that has the 'Automatically Acquire Lock and Activate Changes' console preference enabled (this is the default for development mode domains). I'm also assuming your domain already has a cluster named 'MyCluster'.
Here are the steps.
Step 1 - Turn On Recording
Log into the WLS Console and click 'Record' (in the the toolbar near the top of the page). This starts WLST script recording. When you start recording, the console prints out the name of the WLST script file it will create. For example:
The recording session has started. Recording to C:\mydomain\Script1251228165047.py.Any configuration changes you make will be recorded in this script. Remember the name of this script since you'll be hand editing it later.
Note: deployment plan changes and security data changes (such as adding, deleting and modifying users, groups, roles and policies) will not be captured in the script.
Step 2 - Use the WLS Console to Make Typical Edits
Use the WLS Console to make some changes to the domain's configuration. For this example, create a new server in 'MyCluster', enable SSL for the server and customize the server's listen address, listen port and SSL listen port:
- Click 'Servers' on the console home page.
- Click 'New' to create a new server.
- Set 'Server Name' to 'MyServer'.
- Set 'Server Listen Address' to 'MyListenAddress'.
- Set 'Listen Port' to '7777'.
- Select the 'Yes, make this server a member of an existing cluster.' radio button.
- Select 'MyCluster' from the list of clusters.
- Click 'Finish'.
- Click 'MyServer' in the servers table.
- Click the 'SSL Listen Port Enabled' check box.
- Set 'SSL Listen Port' to '8888'.
- Click 'Save'.
Click 'Record' again in the toobar near the top of the page. This stops WLST script recording. The console will print out the name of the script again:
The recording session has ended. Script recorded to C:\mydomain\Script1251228165047.py.You now have a script that shows how to add a new SSL-enabled server named 'MyServer' to the cluster 'MyCluster':
If you look at this script, you'll notice that it isn't ready to use yet:
- It doesn't connect to the admin server at the beginning or disconnect at the end
- It doesn't call 'edit' to tell WLST to use the 'edit' MBean server. Note: the administration server has several different MBean servers. The 'edit' MBean server is the one that lets you view and manage the domain's configuration.
- There are extra 'activate' and 'startEdit' calls. This is because 'Automatically Acquire Lock and Activate Changes' is enabled (this preference makes every console page uses a separate configuration editing session).
- The server name, cluster name, listen address, listen port and SSL listen port values are hard coded.
Make a copy of the captured script, then edit the copy to address these issues.
- Call 'connect' at the beginning of the script. To connect, WLST needs to know the admin server url as well as the admin user name and password. You have two choices on how to get this information:
- Prompt for them or get them from the command line, then pass them to the 'connect' command.
- Don't pass any parameters to the 'connect' command. Instead, always run WLST from the domain directory on the admin server's machine. When you do this, WLST can automatically figure out the username, password, and url. This example takes this approach.
- Call 'edit' to tell WLST to use the admin server's 'edit' JMX server.
- Call 'disconnect' at the end of the script.
- Remove the extra 'activate' and 'startEdit' commands.
- Parameterize the script, that is, let the administrator specify the server name, listen address, listen port and SSL listen port. The two main ways to get these parameters are to prompt for them or to get them from the command line. This example prompts for them. Note: Since this example wants to show how to add new servers to an existing cluster, it leaves the cluster name hard coded in the script (ie. 'MyCluster'). This is typical. Most scripts want to parameterize some values and hard code others.
- You also might want to add some error handling to the script. This example does not show how to do this.
You now have a parameterized WLST script that your administrator can use to add new SSL-enabled servers to 'MyCluster' as the load goes up.
myServerName = raw_input('Enter server name:')
myListenAddress = raw_input('Enter listen address:')
myListenPort = int(raw_input('Enter listen port:'))
mySSLListenPort = int(raw_input('Enter SSL listen port:'))
cd('/Servers/' + myServerName)
cd('/Servers/' + myServerName + '/SSL/' + myServerName)
Using the Script
Here's how to run the script:
- 'cd' to your domain's directory on the admin server's machine
- run the .\bin\setDomainEnv.cmd script
- java weblogic.WLST C:\temp\MyCreateServerScript.py
- Enter server name:server99
- Enter listen address:listenaddress99
- Enter listen port:7099
- Enter SSL listen port:8099
In summary, if you want to create a parameterized WLST script that edits a domain's configuration:
- Log in into your domain's WLS Console and turn on recording.
- Use the console to make the kind of configuration changes that you want your script to have.
- Turn off recording.
- Make a copy of the captured script, clean it up and parameterize it.