« Changing WebLogic Annotations on the Fly (more detail) | Main | WebLogic Scheduling - A polling approach to implement a DB event generator for ALSB »

Automate WLS Console Tasks with WLST

This was originally posted on my dev2dev blog October 25th, 2007.

I do a fair amount of shoulder-surfing at some of my customer sites.  One of the fun parts of my job is to see how different organizations (and teams within an organization) go about their jobs and what types of processes they follow.  I've noticed frequently that it is common for developers that are doing code promotions, particularly from personal workstations to shared development environments, to use the WLS console to update their applications by using the point and click approach that takes several minutes and has multiple user interactions.  Once I see this happen twice in a span of 10 minutes because of a minor bug, I quickly realize that there is an optimization opportunity to use a script for this mundane deployment task that is usually done over and over again.

Script it

I'm not going to provide an all-encompassing WLST (WebLogic Scripting Tool) tutorial.  There are lots of other places to get more in-depth information for that including the documentation, numerous entries from Satya Ghattu's blog and code samples.  However, I will show an quick example of how to redeploy an application with the python based scripting language that ships with WLS.  WLST can do a whole lot more than this (automate domain creation, configuration, etc), but this should open the door on the possibilities, and you can be Alice in Wonderland yourself and see how deep the rabbit hold goes.  Let's start with the individual building blocks, then put them all together.

Create Building Blocks

  1. Environment Setup - Just open a command prompt and run the <DOMAIN_HOME>/bin/setDomainEnv.cmd (sh) script.  This sets up all the environment variables for you.

  2. Start WLST - Just type java weblogic.WLST

  3. Connect to the Admin Server - Just use the connect command.  To figure how to do this, just type help().  Then you see that there is help on the common options by typing help('common').  The connect operation is one of the common operations, so for help on that specific operation type help('connect').  Of course there is a full command reference published online as well.  In the most basic OOTB situation, I was able to use this syntax:  connect( 'weblogic', 'weblogic', 't3://localhost:7001')

  4. Let's assume the application hasn't been deployed yet.  So the first step is to deploy the application - deploy('PortalEAR', 'D:/TEMP/wlst/PortalEAR.ear', targets='AdminServer')

  5. Start the application - startApplication('PortalEAR')

  6. Now let's assume you're going to deploy a new version of the application.  You could use the side-by-side deployment feature, but we'll save that for another time and just get the basics down first.  First, stop the existing application - stopApplication('PortalEAR')

  7. Now undeploy it - undeploy('PortalEAR')

  8. Repeat steps 4 and 5, this time pointing to the updated .ear file.

Assemble the building blocks

Once that all works, chain it all together, so you can do it all from one simple script:

updatePortalEAR.cmd

call D:\bea921\user_projects\domains\basic_portal_domain\bin\setDomainEnv.cmd
cd d:\temp\wlst
java weblogic.WLST d:\temp\wlst\updatePortalEAR.py
pause

updatePortalEAR.py

execfile('connect.py')
execfile('stop_and_undeploy.py')
execfile('deploy_and_start.py')
execfile('disconnect.py')

connect.py

print 'connecting to admin server....'
connect( 'weblogic', 'weblogic', 't3://localhost:7001', adminServerName='AdminServer' )

stop_and_undeploy.py

print 'stopping and undeploying ....'
stopApplication('PortalEAR')
undeploy('PortalEAR')

deploy_and_start.py

print 'deploying....'
deploy('PortalEAR', 'D:/TEMP/wlst/PortalEAR.ear', targets='AdminServer')
startApplication('PortalEAR')

disconnect.py

print 'disconnecting from admin server....'
disconnect()
exit()

Hopefully this gives you a flavor of how WLST can automate tasks.  Not only can this save time, but it also can help ensure that consistent processes are applied across environments which can help prevent human error (such as forgetting to check a checkbox in a wizard).  Happy scripting!

Here's the full output from executing my updatePortalEAR.cmd

D:\TEMP\wlst>call D:\bea921\user_projects\domains\basic_portal_domain\bin\setDomainEnv.cmd

Initializing WebLogic Scripting Tool (WLST) ...

Welcome to WebLogic Server Administration Scripting Shell

Type help() for help on available commands

connecting to admin server....
Connecting to t3://localhost:7001 with userid weblogic ...
Successfully connected to Admin Server 'AdminServer' that belongs to domain 'basic_portal_domain'.

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.

stopping and undeploying ....
Stopping application PortalEAR.
<Oct 25, 2007 4:29:33 PM CDT> <Info> <J2EE Deployment SPI> <BEA-260121> <Initiating stop operation for application, PortalEAR [archive: null], to AdminServer .>
.Completed the stop of Application with status completed
Current Status of your Deployment:
Deployment command type: stop
Deployment State : completed
Deployment Message : no message
Undeploying application PortalEAR ...
<Oct 25, 2007 4:29:38 PM CDT> <Info> <J2EE Deployment SPI> <BEA-260121> <Initiating undeploy operation for application, PortalEAR [archive: null], to AdminServer .>
....Completed the undeployment of Application with status completed
Current Status of your Deployment:
Deployment command type: undeploy
Deployment State : completed
Deployment Message : no message
deploying ....
Deploying application from D:\TEMP\wlst\PortalEAR.ear to targets AdminServer (upload=false) ...
<Oct 25, 2007 4:29:51 PM CDT> <Info> <J2EE Deployment SPI> <BEA-260121> <Initiating deploy operation for application, PortalEAR [archive: D:\TEMP\wlst\PortalEAR.ear], to AdminServer .>
...................Completed the deployment of Application with status completed
Current Status of your Deployment:
Deployment command type: deploy
Deployment State : completed
Deployment Message : no message
Starting application PortalEAR.
<Oct 25, 2007 4:30:50 PM CDT> <Info> <J2EE Deployment SPI> <BEA-260121> <Initiating start operation for application, PortalEAR [archive: null], to AdminServer .>
.Completed the start of Application with status completed
Current Status of your Deployment:
Deployment command type: start
Deployment State : completed
Deployment Message : no message
disconnecting from admin server....
Disconnected from weblogic server: AdminServer


Exiting WebLogic Scripting Tool.

<Oct 25, 2007 4:30:53 PM CDT> <Warning> <JNDI> <BEA-050001> <WLContext.close() was called in a different thread than the one in which it was created.>Press any key to continue . . .


Comments (3)

raju:

deploy('PortalEAR', 'D:/TEMP/wlst/PortalEAR.ear', targets='AdminServer')

according to my envirolment i want deploy PortalEar.ear to specific managed servers not only admin server and also i want to deploy remote manage servers using wlst,so plz can u help me out.........

raju,

you can specify the names of multiple servers or clusters in the targets parameter. i recommend that check out the following links:
http://www.oracle.com/technology/obe/fusion_middleware/wls103/SystemMgmt/Command_Line/Command_Line.html
http://edocs.bea.com/wls/docs100/config_scripting/index.html
http://edocs.bea.com/wls/docs100/config_scripting/reference.html#wp1060229

Also, post in the WLS forums if you get stuck.

James

sarangapani:

Done the deployment by using wlst as above successfully
but when use the application ,Getting the following errors and
these errors are not coming after i restart the server.

com.gecs.apollo.common.exception.ApolloUnexpectedException: An unexpected remote exception occured

--> java.rmi.NoSuchObjectException: Bean is already undeployed.
at weblogic.ejb.container.manager.BaseEJBManager.preInvoke(BaseEJBManager.java)

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

About

james_bayer.jpg

I am a Senior Sales Consultant covering enterprise customers in and around the Chicago area focusing on middleware and internet technologies. My career began as a Java consultant and architect where I experienced the technology shift toward SOA. I enjoy helping customers solve business problems by applying Oracle technology solutions.

About This Entry

This page contains a single entry from the blog posted on October 25, 2007 7:42 PM.

The previous post in this blog was Changing WebLogic Annotations on the Fly (more detail).

The next post in this blog is WebLogic Scheduling - A polling approach to implement a DB event generator for ALSB.

Many more can be found on the main index page or by looking through the archives.

Top Tags

Powered by
Movable Type and Oracle