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:

6 comments:

  1. Thanks for the info. I've been trying to get this to work on a Windows 2003 Server for a couple of weeks and your post solved my problem.

    When I try this command though the console displays the children of the e:\monitoring folder but hangs after that and does not return control to the calling script. I tried using the 'dir' command and that works ok but I am trying to use powershell to write some events to the Windows 2003 Event Log. Any ideas on why this hangs?

    import os
    .
    .
    .
    cmd = "powershell -command get-childitem e:\monitoring"
    os.system(cmd)

    Thanks

    GregC

    ReplyDelete
  2. Hi

    This is great working script... I am looking for a feature that needs to be included in a deployment automation. For development/testing environments, the frequency of deployments are quite high... I was wondering if there was a way a log the events that happen from start to end of a deployment in DEBUG mode and store it in a log file. I can send this file to the developers for troubleshooting purposes if a deployments fails or does not work as per their expectations.

    I have been looking for a way to do this... but with my limited scripting skills I am finding it hard to find a solution... can u provide some help..

    Thanks

    Anto

    ReplyDelete
  3. Hi Pavan,

    I want to deploy application named "xyzreleaseversion.buildversion.ear" using wlst. But the interpreter exiting with error as there are two . in app name.

    Can you please help me on this.

    ReplyDelete
  4. what are the argument to pass through this script..what are the deploy.properties file?

    ReplyDelete
  5. Excellent data with lots of information. I have bookmarked this page for my future reference. Do share more updates.
    Tally Course in Chennai
    Online Tally Course
    Tally Course in Bangalore
    Tally Training in Coimbatore

    ReplyDelete

Please write your comment here

Popular Posts