Thursday, February 26, 2009

This post is a continuation of my previous post - in a series of posts about WLST scripting best practices. When using WLST script for performing configuration changes always check whether someone else is making changes. WebLogic support configuration changes using many methods but not limited to:

Administration Console

Interactive WLST

WLST SCripts

JMX

Ant Scripts

3rd Party Tools

So it is always better to check whether someone else is making changes while you are ready to start a change session. WebLogic Server will allow only one change session at a time no matter which one of the above methods you use for configuration management. Especially environments with multiple administrators the best practice is to have individual logins for each administrator so that you can have more controlled environment. If you are interested in configuration auditing to find out who is responsible for what, see this post.

Use the Configuration Manager to find out information about existing change sessions. You can find out whether someone else had already started a change session, if so who is making changes, are there any unactivated changed, if so what changes are unactivated etc. from the configuration manager. The following example illustrates a code snippet which checks for existing sessions using configuration manager:

...### Get the Configuration Manager and check for existing sessioncfgManager = getConfigManager()try: cfgManager.getChanges() print '===> Someone else is making changes'except: print '===> No one else is making changes'...

The following example illustrates a code snippet which checks for the number of unactivated changes using configuration manager:

The above code snippet may work only if you are the user who is making the changes. The following example illustrates a code snippet which checks and prints the user who is currently making changes using configuration manager:

...### Get the Configuration Manager and check for existing sessioncfgManager = getConfigManager()try: cfgManager.getChanges() print '===> User ' + configmanager.getCurrentEditor() + ' is making changes'except: print '===> No one else is making changes'...

The following example is a complete script which checks for an existing session and if one doesn't exists then it will create a new managed server by starting a new session. If a session already exists then it will simply display that information and will exit.

### Get the Configuration ManagercfgManager = getConfigManager()try: cfgManager.getChanges() print '===> Currently there is a Session' if cfgManager.isEditor() == true: ### You are making changes!!! print '===> Looks like you started that session' print '===> You can check the console for any pending changes' print '===> Try rerunning this script after you release or commit the pending changes' exit()