Automating application updates on Weblogic 10

One of the things a developer always does is finding new ways to not do something by automating the process. Being responsible for 4 different application, I often have to install a new version in the integration environment, which is a Unix based Weblogic 10.3 instance. This usually takes just 5 minutes, but if you look at this chart, I can actually save 5-21 hours of my time by not doing this !
XKCD: Is It Worth the Time ?

//edit 2013-12-29: Another chart to prove my point:

Geeks and repetitive tasks

 

So, that’s why I wrote a small script that would:

  1. Undeploy an existing version of our application
  2. Download a given version of the application from the DSL
  3. Install this version on Weblogic
  4. Start it

The script can be fully parametrized (see inline comments) and you’ll need a configuration file for your application (a sample is available at the bottom of this post)

The script:

#!/bin/bash
# P_W999 - 2013 - This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
# http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_US
# This script comes as-is, with no guarantees or warranties and it is used at own risk.
# https://pw999.wordpress.com
# v0.1 - 2013-12-13
# * Initial release
#
# If you haven't done yet, make your userconfig and userkey file with the following command:
# java weblogic.Admin -username devuser -password xxxxxxxxxxx -userconfigfile USER_CONFIG -userkeyfile USER_KEY STOREUSERCONFIG
# -username and -password are values the values that will be encrypted and are NOT checked or used to connect to Weblogic itself.
#
# Script Usage:
# ./jodal.sh arg0 arg1
# arg0: the configuration file for your application (path must be relative to $configPath)
# arg1: the version to install
#
# Script example:
# ./jodal.sh myApp 1.2.5-SNAPSHOT
#
# Exit values are:
# 0: OK
# 1: Error
# 2: Arrived at EOF which shouldn't happen

# Path to the setWLSEnv.sh file
setWLSEnvDir=/dev/weblogic/server/bin
# The administration URL. Usually your server's /console address
adminUrl=t3://dev01.mycompany.com:7000
# Where the user config file is stored
userConfigFile=/dev/scripting/USER_CONFIG
# Where the user key file is stored
userKeyFile=/dev/scripting/USER_KEY
# Where to find the configuration files
configPath=/dev/scripting
# Where the application EAR must be downloaded (I rely on wget instead of the non-structured upload command of Weblogic)
uploadFolder=/dev/devdomain/servers/admin/upload

if [ "$1" = "" ] ; then
	echo "** First param was empty, must be ini file"
	exit 1
fi
if [ "$2" = "" ] ; then
	echo "** Second param was empty, must be version"
	exit 1
fi

# Prepare
cd $setWLSEnvDir
./setWLSEnv.sh
# Copy to better named variable
newVersion=$2

# Load config file
if [ -f $configPath/$1 ] ; then
	. $configPath/$1
else
	echo File not found $configPath/$1
	exit 1
fi
# Verify that config file was loaded
if [ "$configFile" != "$1" ] ; then
	echo Expected $1 as config but got $configFile instead
	exit 1
fi
echo "**********************************************************"
echo Group = $groupId
echo App = $appName
echo Version = $newVersion
echo Config = $configFile
echo
echo
echo

# See if must undeploy an earlier version (might be risky, choose your names wisely)
# This command is pretty slow ...
appToUndeploy=$(java weblogic.Deployer -adminurl $adminUrl -userconfigfile $userConfigFile -userkeyfile $userKeyFile -listapps | grep $appName)

if [ $appToUndeploy != "" ] ; then
    echo "** Application found on server, undeploying " $appToUndeploy
	java weblogic.Deployer -adminurl $adminUrl -userconfigfile $userConfigFile -userkeyfile $userKeyFile -undeploy -name $appToUndeploy
	if [ $? -eq 1 ] ; then
		echo "** Auto un-deployment failed"
		exit 1
	fi
fi

# Go to upload folder
cd $uploadFolder
# Make a folder with the groupId of the application
if [ ! -d $groupId ] ; then
	mkdir $groupId
fi

cd $groupId

# Remove older version already in directory
if [ -f $appName-$newVersion.ear ] ; then
	echo "** Removing " $appName-$newVersion.ear
	rm $appName-$newVersion.ear
fi

# Download that EAR
wget $downloadUrl/$newVersion/$appName-$newVersion.ear
echo "** Deploying application to server on " $target
if [ -f $appName-$newVersion.ear ] ; then
	# Deploy
	java weblogic.Deployer -adminurl $adminUrl -userconfigfile $userConfigFile -userkeyfile $userKeyFile -deploy -name $groupId.$appName-$newVersion -source $uploadFolder/$groupId/$appName-$newVersion.ear -targets $target

	if [ $? -eq 1 ] ; then
		echo "** Auto deployment failed"
		exit 1
	fi
	# Start
	java weblogic.Deployer -adminurl $adminUrl -userconfigfile $userConfigFile -userkeyfile $userKeyFile -start -name $groupId.$appName-$newVersion
	exit 0
else
	echo "** Freshly downloaded file not found"
	exit 1
fi
exit 2

And a simple configuration file named ‘myapp.ini’, to be placed next to the script:

#The DSL base URL. It'll be suffixed with $newVersion/$appName-$newVersion.ear
downloadUrl=http://mycompany.intra/dsl/local/com/mycompany/myapp/
#Deployment target for this application
target=dev1Cluster
#The groupId of your application (will be used in deployment name)
groupId=com.mycompany.myapp
#The name of your application
appName=MyApplication
#The name of this configuration file. This is to make sure the correct config file is loaded
configFile=myapp.ini

Given that you already installed your application as MyApplication-1.5.0, you can easily upgrade it to 1.5.2 by calling:

./jodal.sh myapp.ini 1.5.2

Once finished (~50 seconds later), the application will be installed as com.mycompany.myapp.MyApplication-1.5.2

Advertisements

One thought on “Automating application updates on Weblogic 10

  1. Can you please help on the below points …. Please email me your bash script for the below steps

    1. Take a back up of existing war file to archieve folder.
    2. Place a new war file copying from external server.
    3. Stop the application and untarget server for that specific appliaction.
    4. Delete the application and force shutdown the Managed servers.
    5 Deploy the new war file and target the servers
    6 Start the managed servers accordingly….

    Thanks in Advance….

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s