Search This Blog

Wednesday, December 22, 2010

My way of deployment with WLST

This Script has ultimate goal to automate to one-step process for deploying the code onto WebLogic Development environments. Usually the development environments are going to have multiple time deployments than other environments. Some of the WebLogic environments creates the persistances objects stores into the servers logs path. To avoid previous object references we need to clean up the cache directory that holds this persistance objects. We have developed a python module for clearCache that will do this task automatically.

There could be dependency on application archive files order. Some of the deployments does not requires the shared libraries deployments. Changes in the web application requires Only web app re-deployment. Changes in the enterprise application needs only EAR file deployments. Considering all these dependencies the script is developed in modular structure.

 The following shell script is developed for the environment which I have used to. The domain path you can specify in the DHOME.

#AppDeployment.sh [Optional]
echo '***** WELCOME TO DEPLOYMENT SCRIPT *****'
user=`echo $LOGNAME`
echo 'APPLICATION DEPLOYMENT IS STARTING IN INSTANCE:' $user
DHOME=/Home/domains/wd$LOGNAME/config
WLHOST=`hostname`
cd $DHOME
WLPORT=`cat config.xml |grep listen-port|tr -s [:blank:] |tr " " "\n" |grep listen-port |cut -c14-17`
URL='t3://'$WLHOST':'$WLPORT
DENV=$HOME/domains/wd$LOGNAME/bin/setDomainEnv.sh
. $DENV $*
echo $CLASSPATH
#calling the paniDeployment.py file
java weblogic.WLST -loadProperties /Home/$user/.Admin/deploy.properties /Home/$user/.Admin/paniDeployment.py $user $URL$CLASSPATH 

Now let me give you what I did in my experiment with deployment script, assume that 'a_ejb.jar','a_adapter.jar','b_adapter.jar','c.war' are the deployable archive file components. You may have different components may be target to different WebLogic server instances or clusters it is your choice of targetting.

Well this might be very lengthy you might feel too much!! but bear with me! this is my first time trial which I made ...

On our WebLogic, there are many logics works hahaaaaaaaaaaaaaaaa!! here I am using Python core library modules such as 'os', 'time' etc.

#======================================================================
# FileName: AppDeployment.py
# Author  : Sarangapani Matoori
#======================================================================
import os
import time
import sys
from java.util import Date
from java.text import SimpleDateFormat
t = Date()
today=SimpleDateFormat("dd_MMM_HH:mm").format(Date())
user=sys.argv[1]
URL=sys.argv[2]
src="/home/"+user+"/CODE/"
bksrc="/home/"+user+"/CODE_"
dpath="/home/domains/wd"+user
ECODE='\033[0m \n'
G='\033[1;40;32m'
R='\033[1;40;31m'
deploylist=['a_ejb.jar','a_adapter.jar','b_adapter.jar','c.war']
def backup():
    try:
         #Creating the Backup with Date And Time 
         command = "cp -R "+src+" "+bksrc+today
         os.system(command)
    except:
          print R+'   Code Backup FAILED!! '+ECODE
          print dumpStack()

def getCode():
        try:
                # GETTING THE Fresg Code from build location 
                os.system('scp user@hostname:/home/user/Code_Ioc/*.*ar '+src)
                print G+'    THE CODE COPIED SUCCESSFULLY  '+ECODE
        except:
                print R+'   THE CODE COPYING FAILED?!?!?'+ECODE
                print dumpStack()
                exit()
def conn():
        try:
                # CONNECTING TO THE SERVER .... 
                connect(userConfigFile=UCF, userKeyFile=UKF, url=URL)
        except:
                print R+'  CONNECTION FAILED....',+ECODE
                print dumpStack()
                exit()
def editing():
        edit()
        startEdit()

def activating():
    save()
    activate()

def stoppingApp():
    deploylist.reverse()
    for s in deploylist:
        try:
            editing()
            progress=stopApplication(s,timeout=360000)
            progress.printStatus()
            activating()
       except:
            print R+'  FAILED TO STOP THE APPLICATION  '+ECODE
            print dumpStack()
  
    print G+'  APPLICATION STOPPED  '+ECODE

def pUndeploy():
     deploylist.reverse()
     for s in deploylist:
        try:
                editing()
                progress=undeploy(s, timeout=360000)
                progress.printStatus()
                activating()
        except:
                print R+'  FAILED TO UNDEPLOY THE APPLICATION  '+ECODE
                print dumpStack()
     print G+'  APPLICATION UNDEPLOYED   '+ECODE

# This module is optional 
def clearCache():
        try:
                print G+'  CLEARING THE CACHE  '+ECODE
                command = "rm -rf "+dpath+"/servers/"+user+"/tmp/*.*"
                os.system(command)
                print G+'  CLEARED THE CACHE   '+ECODE
        except:
                print R+'  FAILED TO CLEAR CACHE '+ECODE

def pDeploy():
     for s in deploylist:
        try:
            editing()
            progress=deploy(s,src+s,target=user,timeout=360000)
            progress.printStatus()
            activating()
        except:
            print R+'FAILED TO DEPLOY THE APPLICATION'+ECODE
            print dumpStack()
     print G+'  APPLICATION DEPLOYED  '+ECODE

def startingApp():
     for s in deploylist:
        try:
                editing()
                startApplication(s,timeout=360000)
                activating()
        except:
            print R+'FAILED TO START THE APPLICATION '+ECODE
     print G+'APPLICATION STARTED SUCCESSFULLY '+ECODE

if __name__== "main":
        backup()
        getCode()
        conn()
        stoppingApp()
        pUndeploy()
        clearCache()
        pDeploy()
        startingApp()
        print G+' ....DEPLOYMENET DONE...'+ECODE
###### End of pani Deployment.py file ###########
We have gone thru the Satya blog, Satya (the original author of WLST) already wrote os.system usage in the following link:
http://ghattus.com/2007/01/01/wlst-startserver-re-visited/

Following comments archived from "WLSTBYPANI" post:



prasanth vasireddy said...
what are the argument to pass through this script..what are the deploy.properties file?. References:

Saturday, December 18, 2010

Bounce Servers with NodeManager using WLST

NodeManager using WLST
Any Middleware admin can make their life easy with WLST, to play with Server Life Cycle we can use NodeManager WLST commands. WLST provides us

  • start the NodeManager
  • connect to the NodeManager, then we can use them to start or stop the WebLogic servers on the machine.

Start Node Manager

Usually, as part of configuring Node Manager, you create a Windows service or a daemon that automatically starts Node Manager when the host computer starts.

If Node Manager is not already running, you can logon to the host computer and use WLST to start it as shown:
c:\>java weblogic.WLST 
wls:/offline> startNodeManager()
We can connect from the WLST SHELL to a NodeManager by entering the nmConnect command. 
wls:/offline>nmConnect('username','password','nmHost','nmPort','domainName','domainDir','nmType')
For example, 
nmConnect('weblogic', 'secret', 'localhost', '5556', 'mydomain','c:/bea/user_projects/domains/mydomain','ssl')
 
Connecting to Node Manager ... 
Successfully connected.
 

BEA-090403 :Authentication for user denied

If you are not configured the NodeManager running WebLogic domain then, You never know what is the nodemanager user, password for that domain. By default the WebLogic admin Console must works. One of my experiance that there could be multiple users access the WebLogic admin role in such situations we need to check the initial domain configuration made up with the user credential that will help you to start the Node Manager. If it doesn't works for you then update the Node Manager username and password in the WebLogic Console and then connect.
nmDisconnect() command will do, disconnect WLST from a Node Manager session.
nm() command - You may execute many WLST commands in between nmStart and nmDisconnect then, you wonder that is it connected to NodeManager or not. To check this at WLST Shell prompt we have nm command

wls:/offline> nm()
Not connected to Node Manager

nmStart - Starts a server in the current domain using Node Manager, Conditionas applyed !! Java Node Managed will work here the Node Manager running on the different machine cannot execute this command.
Let use the nmStart command to start the Admin server as it is known as a best practice. 
wls:/nm/mydomain>nmStart('AdminServer')
starting server AdminServer ... 
Server AdminServer started successfully

nmKill command - will kills the specified WebLogic server instance that was started with the Node Manager only. 
wls:/nm/mydomain>nmKill('AdminServer')
Killing server AdminServer
Server AdminServer killed successfully

Best Practices with Nodemanager


  • Use the nodemanager to start the admin server
  • connect to the admin server
  • start the managed servers with regular WLST lifecycle commands
  • Don't kill the managed server with UNIX kill command when it is started with a Node Manager or with WLST nmStart command

WLST Life cycle commands will enables you to start all managed servers in the domain with single connection to the admin server, regardless of which machines host these Managed Servers.


My online buddy asked me to publish a WLST script for Node maneger that bounces WebLogic server. Its really wonderful thought having this idea with WLST.


Have it your way
This script you can customized as per your environment.
Here you need to do the following which are instructed by buddy because I don't have NodeManager environment test this script. But strongly confident that this will work for you,
* please change the AdminServer's Listen address, Listen port in connection module.

#===========================================
# This module will starts the NodeManager
# Author: Sumanth Krishna
#========================================
def startnm():
 try:
  progress=startNodemanger()
  progress.printStatus()
 except:
  print 'FAILED TO START NODE MANAGER'
  print dumpStack()
# The module NodeManager connects to the AdminServer
def connectnm():
  try:
     progress=nmConnect(user,passwd,WLHOST,NMPORT,domainname,domainpath,plain)
     progress.printStatus()
 except:
     print 'FAILED TO CONNECT NODE MANAGER'
     print dumpStack()

# This module is for starting the AdminServer pass AdminServer name
def startAdminServer(svrName):
   try:
      nmStart(svrName)
  except:
      print "Problem starting the Admin server "+svrName

# This module for starting the managed server
def startManagedServers():
 try:
     mbeans = home.getMBeansByType("ServerLifeCycleRuntime")
     for i in mbeans:
        svrName = i.getName()
        if svrName != serverName:
          if i.getState() != "RUNNING":
            nmStart(svrName)
 except:
     print "Problem starting the managed server "+svrName

#Main functaion i.e., all functions used to call from here
if __name__== "main":
   startnm()
   connectnm()
   startAdminServer()
   startManagedServers()
   print 'DONE'

Review this script and write back comments and suggestions to me your trial outputs and issues... whatever you have with this

Good Reference Links:
1. James Bayer blog

Related Posts

Thursday, December 2, 2010

Switching from WLST edit tree

An online buddy pinged me today and asking 'Urgent!! I am in WLST edit session, I want to come out I don't know how to do that'. I asked did you done the modifications to the configuration?. He said 'yep! I want regular prompt from this edit!>'. I asked to try save(), activate() he said it don't works!!

While working on edit tree you might gone some where and your remote connection got disconnected, re-entering to the edit session you can use startEdit().

Oh.. ohh what else we can do? I had a thought he might want to navigate from edit tree to some other mbean tree. I asked him to try ' serverConfig() '. He is happily said it Works!!

Best alternate is  using currentTree(), This command enables you to store the current location in the hierarchy and easily return to it after browsing.

wls:/testdomain/edit> loc=currentTree()
wls:/testdomain/edit> serverRuntime()
Location changed to serverRuntime tree. This is a read-only tree with
ServerRuntimeMBean as the root.
For more help, use help('serverRuntime')
 
wls:/testdomain/serverRuntime> loc()
wls:/testdomain/edit>

What is learning here?
WLST is having various options for MBeans traversals. Basic differences I understand are:
1. Read-only tree
2. Editable tree

Read only trees
once you connected to the WebLogic domain first you are in the serverConfig tree it is a read-only tree. Similarly you can navigate on the such read-only trees serverRuntime, domainRuntime,

To save the changes which you made on the current configuration save(). After saving you can continue the changes to the configuration. You make the changes permanent by activate() the configuration. When something configured wrong on your interactive WLST session you can use say UNDO for your settings by cancelEdit('y'). It is like clicking on WebLogic administration console at the change control 'Undo All changes' button.

Reference:
http://download.oracle.com/docs/cd/E13222_01/wls/docs92/config_scripting/reference.html#wp1179175
http://weblogicserver.blogspot.com/2009/03/check-for-resourceconfiguration.html

Popular Posts