Friday, February 20, 2015

Weblogic -- a quick look at WLST and typical use case for addressing edit lock problems in EBS 12.2

WLST in Weblogic is a java based cli, that can be used to monitor and administer Weblogic servers and domains. We can also say that WLST is command line utility , which eases some of the administration works.


An example of the benefits of the WLS can be ability to access the Node Manager and starting,stopping or suspending both local or remote managed servers from the command line.. No need to have an admin server up & running, no need for a browser and so on.

Usages : Online and Offline
There are 2 usage for using WLST. Online and offline.When using WLST online , we can connect to Admin or Managed Servers . So we can access the Mbeans(Java objects which provides managed interfaces) .
In offline use, offcourse we have limited functionality.. Still, we can create a new domain or create/change some configuration files like config.xml..

Modes: 
There are 3 modes for using WLST.
Direct/Interactive/Command Line Mode, Script mode, Embedded Mode..
Interactive mode is a standard cli mode, like sqlplus, we execute commands and WLST returns back the response interactively..
We can also supply scripts to WLST. Scripts containing WLST commands in a text file with .py extension. This is called Script mode.
We can also use embedded mode for using WLST .. That is ;we can embed WLST interpreter in our Java code and use it to run WLST commands and scripts.

Okay.. After a general introduction, lets proceed with an example of the usage ;

Lets start by checking the status of a managed server;

First we set our domain env.. -> . $EBS_DOMAIN_HOME/bin/setDomainEnv.sh

java weblogic.WLST
wls:/offline> connect('weblogic','welcome1','t3://ermanhost:7001')
wls:/EBS_domain_ORATEST/serverConfig> cd ('Servers')
wls:/EBS_domain_ORATEST/serverConfig/Servers> ls()
dr--   AdminServer
dr--   forms-c4ws_server1
dr--   forms_server1
dr--   oacore_server1
dr--   oafm_server1

Note that ; we can use ls and cd commands :) ls() or even cd ('..') works well :)

Okay, we have 5 servers in this domain.. This is an EBS 12.2 instance bytheway..

Lets check the status of oacore_server1

wls:/EBS_domain_ORATEST/serverConfig>  print state('oacore_server1')
Current state of 'oacore_server1' : RUNNING

Okay. lets use some help(all) and see what more we can do with it.

 help('all') 
    help('activate')         Activate the changes.
    help('addListener')      Add a JMX listener to the specified MBean.
    help('addTemplate')      Extend the current domain.
    help('adminHome')        Administration MBeanHome.
    help('assign')           Assign resources to one or more destinations.
    help('assignAll')        (Deprecated) Assign all applications or services.
    help('cancelEdit')       Cancel an edit session.
    help('cd')               Navigate the hierarchy of beans.
    help('closeDomain')      Close the current domain.
    help('closeTemplate')    Close the current domain template.
    help('closestore')       Closes a store.
    help('cmo')              Current Management Object.
    help('compactstore')     Compacts and defragments the space occupied by a file store.
    help('config')           (Deprecated) Navigate to the last MBean in configuration hierarchy.
    help('configToScript')   Convert a domain configuration to WLST script.
    help('connect')          Connect WLST to a WebLogic Server instance.
    help('connected')        Variable indicating whether WLST is connected.
    help('create')           Create a configuration bean.
    help('createDomain')     Create a new domain.
    help('currentTree')      Return the current location in the hierarchy.
    help('custom')           Navigate to the root of custom MBeans.
    help('delete')           Delete a configuration bean.
    help('deploy')           Deploy an application.
    help('disconnect')       Disconnect WLST.
    help('distributeApplication')Copy the deployment bundle to targets.
    help('domainConfig')     Navigate to last domain configuration MBean or root.
    help('domainCustom')     Navigate to the root of domain custom MBeans.
    help('domainName')       Name of the domain to which WLST is connected.
    help('domainRuntime')    Navigate to last domain runtime MBean or root.
    help('domainRuntimeService')DomainRuntimeServiceMBean MBean.
    help('dumpStack')        Display stack trace from the last exception.
    help('dumpVariables')    Display all the variables used by WLST.
    help('dumpstore')        Dumps store contents in human-readable format to an XML file.
    help('edit')             Navigate to last edit configuration MBean or root.
    help('editService')      EditServiceMBean MBean.
    help('encrypt')          Encrypt the specified string.
    help('exit')             Exit WLST from the user session.
    help('exitonerror')      Variable indicating whether WLST exits on error.
    help('exportDiagnosticData')Execute a query (offline).
    help('exportDiagnosticDataFromServer')Execute a query (online).
    help('find')             Find MBeans and attributes.
    help('get')              Return the value of the specified attribute.
    help('getActivationTask')Return the latest ActivationTaskMBean.
    help('getAvailableCapturedImages')Returns the list of Diagnostic Images available for downloading.
    help('getConfigManager') Return the ConfigurationManagerMBean.
    help('getMBI')           Return the MBeanInfo.
    help('getMBean')         Return the MBean by browsing to path.
    help('getPath')          Return the MBean path.
    help('getWLDM')          Return the WebLogic DeploymentManager object.
    help('getopenstores')    Returns a list of opened stores (for script access).
    help('getstoreconns')    Returns a list of connections in the specified store (for script access).
    help('home')             Local MBeanHome.
    help('invoke')           Invoke a management operation on the current bean.
    help('isAdminServer')    Variable indicating whether WLST is connected to an Admin Server.
    help('isRestartRequired')Determine whether a server restart is required.
    help('jndi')             Navigate to the JNDI tree.
    help('listApplications') Lists all applications that are currently deployed to the domain.
    help('listChildTypes')   List all the child MBeans for the cmo.
    help('liststore')        Lists store names, open stores, or connections in a store.
    help('loadApplication')  Load an application and deployment plan.
    help('loadDB')           Load SQL files into a database.
    help('loadProperties')   Load property values from a file.
    help('lookup')           Look up the specified MBean.
    help('ls')               List all the child beans and/or attributes.
    help('man')              Display help from MBeanInfo.
    help('mbs')              MBeanServerConnection object.
    help('migrate')          Migrate JTA, JMS or Server services.
    help('nm')               Determine whether WLST is connected to Node Manager.
    help('nmConnect')        Connect WLST to Node Manager.
    help('nmDisconnect')     Disconnect WLST from a Node Manager session.
    help('nmEnroll')         Enroll the machine with Node Manager.
    help('nmGenBootStartupProps')Generate boot and startup properties
    help('nmKill')           Kill the specified server instance.
    help('nmLog')            Return the Node Manager log.
    help('nmServerLog')      Return the server output log.
    help('nmServerStatus')   Return the status of the server.
    help('nmStart')          Start a server using Node Manager.
    help('nmVersion')        Return the Node Manager server version.
    help('openfilestore')    Opens a file store.
    help('openjdbcstore')    Opens a JDBC store.
    help('prompt')           Toggle prompt information.
    help('pwd')              Display the current working directory.
    help('readDomain')       Open an existing domain for updating.
    help('readTemplate')     Open an existing domain template.
    help('recording')        Variable indicating whether WLST is recording.
    help('redeploy')         Reload classes and redeploys an application.
    help('redirect')         Redirect WLST output to the specified filename.
    help('removeListener')   Remove a listener that was previously defined.
    help('resume')           Resume a server instance.
    help('runtime')          (Deprecated) Navigates to the last MBean in runtime hierarchy
    help('runtimeService')   RuntimeServiceMBean MBean.
    help('save')             Save the edits that have been made.
    help('saveDiagnosticImageCaptureEntryFile')Downloads an entry from a captured Diagnostic Image.
    help('saveDiagnosticImageCaptureFile')Downloads a captured Diagnostic Image.
    help('serverConfig')     Navigate to the last configuration MBean or root.
    help('serverName')       Name of the server to which WLST is connected.
    help('serverRuntime')    Navigate to the last runtime MBean or root.
    help('set')              Set the specified attribute value.
    help('setDistDestType')  Sets the distributed destination type.
    help('setOption')        Set options related to a domain creation or update.
    help('showChanges')      Show the current changes that were made.
    help('showListeners')    Show all listeners that are currently defined.
    help('shutdown')         Gracefully shut down a server or a cluster.
    help('start')            Start a Managed Server or a cluster.
    help('startApplication') Start an application.
    help('startEdit')        Start a configuration edit session.
    help('startNodeManager') Start Node Manager.
    help('startRecording')   Record all user interactions with WLST.
    help('startServer')      Start the Administration Server.
    help('state')            Return a map of servers/clusters and their state.
    help('stopApplication')  Stop an application, making it unavailable to users.
    help('stopEdit')         Stop current edit session and release lock.
    help('stopNodeManager')  Stop Node Manager.
    help('stopRecording')    Stop recording WLST commands.
    help('stopRedirect')     Stop redirection of WLST output.
    help('storeUserConfig')  Create a user configuration and key file.
    help('suspend')          Suspend a running server.
    help('threadDump')       Display a thread dump for the specified server.
    help('typeService')      TypeServiceMBean MBean.
    help('unassign')         Unassign applications or resources.
    help('unassignAll')      (Deprecated) Unassign all applications or services.
    help('undeploy')         Undeploy an application.
    help('undo')             Revert all unsaved or unactivated edits.
    help('updateApplication')Update an application configuration using a new deployment plan.
    help('updateDomain')     Update and save the current domain.
    help('username')         Name of user currently connected to WLST.
    help('validate')         Validate the changes that have been made.
    help('validateConfig')   Validate a Domain configuration.
    help('version')          Current version of WLS.
    help('viewMBean')        Display information about an MBean.
    help('writeDomain')      Write the domain configuration information.
    help('writeIniFile')     Convert WLST definitions to Python file.
    help('writeTemplate')    Write the domain template.

Look we have stopEdit :) I
 help('stopEdit')         Stop current edit session and release lock.

So, lets put a domain lock on the admin console and leave it there..


Why do I give stopEdit() as an example? Because I want to address the problem in automated EBS 12.2 startups :)

Such as this one :

START SCRIPT:
### ERMAN ARSLAN EBS 12.2 APPS START automated
### 12/30/2013
## supply appspassword and weblogicpassword in sequence as command line arguments
### reviewed and tested 1/15/2015
if [ `whoami` == "root" ]
then
echo you can not run this script with root!
exiting
else
. /u01/apps/EBSapps.env run
{ echo apps; echo $1; echo $2; } | sh $ADMIN_SCRIPTS_HOME/adstrtal.sh -nopromptmsg
fi

The problem is if we have domain lock in the Weblogic(which comes with the EBS 12.2) then our managed server start scripts hang... 
What we normally do to fix the problem is actually -> connecting to admin server and releasing the lock..

But now, we will release that lock using WLST :)

What we need to do is using edit() to reach the edit tree, and then using stopEdit to end the edit session..

wls:/EBS_domain_ORATEST/serverConfig> edit()
Sure you would like to stop your edit session? (y/n)
y
Edit session has been stopped successfully.

That 's all. Our edit lock is released.
When we check it using Admin console, we will see that there is no locks anymore..


As you see in the picture above, it is clean :)

Morover;if we can use this wlst command in our EBS start scripts , we can fix the problem even in there..

Okay lets use WLST in scriptized mode and release the lock by using the following script ..

We create a script named erman.py with the following contents;
connect('weblogic','welcome1','t3://ermanhost:7001')
edit()
stopEdit(defaultAnswer='y')
exit()

Then use this script for releasing the lock;

java weblogic.WLST erman.py
Initializing WebLogic Scripting Tool (WLST) ...
Welcome to WebLogic Server Administration Scripting Shell
Type help() for help on available commands
Connecting to t3://ermanhost:7001 with userid weblogic ...
Successfully connected to Admin Server 'AdminServer' that belongs to domain 'EBS_domain_ORATEST'.
Warning: An insecure protocol was used to connect to the 
server. To ensure on-the-wire security, the SSL port or 
Admin port should be used instead.
Location changed to edit tree. This is a writable tree with 
DomainMBean as the root. To make changes you will need to start 
an edit session via startEdit(). 
For more help, use help(edit)
You already have an edit session in progress and hence WLST will 
continue with your edit session.
Edit session has been stopped successfully.
Exiting WebLogic Scripting Tool.

Script works well.
Then we put this script into our automatic start script and we are fixing the "hang" problem..

EBS 12.2 START SCRIPT:
### ERMAN ARSLAN EBS 12.2 APPS START automated
### 12/30/2013
## supply appspassword and weblogicpassword in sequence as command line arguments
### reviewed and tested 1/15/2015
### 02/20/2015 modified to relase the domain lock before starting the application services
if [ `whoami` == "root" ]
then
echo you can not run this script with root!
exiting
else
. /u01/apps/EBSapps.env run
. $EBS_DOMAIN_HOME/bin/setDomainEnv.sh
java weblogic.WLST erman.py
. /u01/apps/EBSapps.env run
{ echo apps; echo $1; echo $2; } | sh $ADMIN_SCRIPTS_HOME/adstrtal.sh -nopromptmsg
fi


Note that: If we dont have domain lock present at the time that we run this script; we may get the following exception:
WLSTException: Error occured while performing stopEdit : Cannot call stopEdit without an edit session in progress

But this is not a problem, it does not break our script . That 'is ; even if there are exception in WLST, the shell continues to execute the remaining lines of our shell script and able start our EBS services without any problems..
Here is the test ;

Contents of erman.sh: 

java weblogic.WLST erman.py
echo "I could execute commands here :)"

Lets run erman.sh and see if we could execute the commands after getting the exception caused by the absence of the edit lock.

sh erman.sh 

Initializing WebLogic Scripting Tool (WLST) ...

Welcome to WebLogic Server Administration Scripting Shell

Type help() for help on available commands

Problem invoking WLST - java.io.FileNotFoundException: /u01/install/APPS/fs1/FMW_Home/user_projects/domains/EBS_domain_ORATEST/erman.py (No such file or directory)
********I could execute commands here :)   --> So no problems :)

Okay.. In this post, I have tried to give some general information about WLST. I have given some examples for using the commands in this tool and also tried to consolidate our learnings by making a use case in EBS 12.2..
Hope you 'll find it useful.

2 comments :

  1. Thank you for posting such nice information on WLS.I learn using of some help(all) commands it helps me in my weblogic training in Hyderabad thank you.

    ReplyDelete

If you will ask a question, please don't comment here..

For your questions, please create an issue into my forum.

Forum Link: http://ermanarslan.blogspot.com.tr/p/forum.html

Register and create an issue in the related category.
I will support you from there.