Using the Console to Create Repeatable Configuration Scripts

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:

  1. Log into the WLS Console and turn on script recording.

  2. Use the WLS console to make some changes (e.g add a new SSL-enabled server to a existing cluster).

  3. Turn off script recording.

  4. Hand edit the captured script to clean it up and parameterize it (for example, have it prompt for the server name).

This can be a lot easier than starting from scratch since the console will show you which WLST commands you should be using.

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:

  1. Click 'Servers' on the console home page.

  2. Click 'New' to create a new server.

  3. Set 'Server Name' to 'MyServer'.

  4. Set 'Server Listen Address' to 'MyListenAddress'.

  5. Set 'Listen Port' to '7777'.

  6. Select the 'Yes, make this server a member of an existing cluster.' radio button.

  7. Select 'MyCluster' from the list of clusters.

  8. Click 'Finish'.

  9. Click 'MyServer' in the servers table.

  10. Click the 'SSL Listen Port Enabled' check box.

  11. Set 'SSL Listen Port' to '8888'.

  12. Click 'Save'.
Step 3 - Turn Off Recording
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':
startEdit()

cd('/')
cmo.createServer('MyServer')

cd('/Servers/MyServer')
cmo.setListenAddress('MyListenAddress')
cmo.setListenPort(7777)
cmo.setCluster(getMBean('/Clusters/MyCluster'))

activate()

startEdit()
cmo.setListenPortEnabled(true)
cmo.setJavaCompiler('javac')
cmo.setClientCertProxyEnabled(false)
cmo.setMachine(None)

cd('/Servers/MyServer/SSL/MyServer')
cmo.setEnabled(true)
cmo.setListenPort(8888)

activate()

startEdit()

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.
Step 4 - Edit the Captured Script
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.
Here is the edited script (e.g. C:\temp\MyCreateServerScript.py):
connect()
edit()

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:'))

startEdit()

cd('/')
cmo.createServer(myServerName)

cd('/Servers/' + myServerName)
cmo.setListenAddress(myListenAddress)
cmo.setListenPort(myListenPort)
cmo.setCluster(getMBean('/Clusters/MyCluster'))

cmo.setListenPortEnabled(true)
cmo.setJavaCompiler('javac')
cmo.setClientCertProxyEnabled(false)
cmo.setMachine(None)

cd('/Servers/' + myServerName + '/SSL/' + myServerName)
cmo.setEnabled(true)
cmo.setListenPort(mySSLListenPort)

activate()
disconnect()

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.

Using the Script
Here's how to run the script:

  1. 'cd' to your domain's directory on the admin server's machine

  2. run the .\bin\setDomainEnv.cmd script

  3. java weblogic.WLST C:\temp\MyCreateServerScript.py
    • Enter server name:server99

    • Enter listen address:listenaddress99

    • Enter listen port:7099

    • Enter SSL listen port:8099

At this point, you can log into your domain's WLS Console, go to the 'Servers' table and view the new server that the script created.

Summary
In summary, if you want to create a parameterized WLST script that edits a domain's configuration:

  1. Log in into your domain's WLS Console and turn on recording.

  2. Use the console to make the kind of configuration changes that you want your script to have.

  3. Turn off recording.

  4. Make a copy of the captured script, clean it up and parameterize it.

For more information on the WebLogic Server Console's WLST script recording feature, see
Comments:

Thanks for your helpful Post, I hope you have a good day!

Posted by shaiya gold on July 29, 2010 at 02:40 PM PDT #

Thank you for a great post

Posted by Nashville Lock on September 14, 2010 at 04:05 PM PDT #

This is a fine blog and I wished to post a small item to let you know, great work!

Posted by Hellen Guilbault on October 04, 2010 at 07:02 AM PDT #

This is getting a bit more subjective, but I much prefer the Zune Marketplace. The interface is colorful, has more flair, and some cool features like 'Mixview' that let you quickly see related albums, songs, or other users related to what you're listening to. Clicking on one of those will center on that item, and another set of "neighbors" will come into view, allowing you to navigate around exploring by similar artists, songs, or users. Speaking of users, the Zune "Social" is also great fun, letting you find others with shared tastes and becoming friends with them. You then can listen to a playlist created based on an amalgamation of what all your friends are listening to, which is also enjoyable. Those concerned with privacy will be relieved to know you can prevent the public from seeing your personal listening habits if you so choose.

Posted by Diflucan on March 01, 2011 at 10:47 PM PST #

This is the best blog I've ever seen in my life! I really appreciate you taking the time out of your day to share this with everyone.

Posted by How To Get Backlinks on March 02, 2011 at 08:32 PM PST #

I saw a lot of website but I conceive this one has got something extra in it in it

Posted by san diego listings on March 13, 2011 at 06:22 AM PDT #

You gave tremendous positive points there. I did a search on the topic and found most peoples will agree with your blog.

Posted by buy generic Cipro on March 21, 2011 at 04:49 AM PDT #

big thanks great post

Posted by köpek maması fiyatları on April 06, 2011 at 10:59 AM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed
About

The official blog for Oracle WebLogic Server fans and followers!

Stay Connected

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
5
6
7
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today