Search This Blog

Showing posts with label Deployment. Show all posts
Showing posts with label Deployment. Show all posts

Saturday, June 18, 2016

Multitenancy in WebLogic 12c Part -7 Deploy and Undeploy Application to a Domain Partition

After almost four months took me to write this, due to busy in work this blog post on WebLogic 12.2.1 MT feature exploration took some time. To workout multiple deployment scenarios on MT environment we need real-time implementation environments. As of now I've limiting my scope to web application deployment on to a partition. You could do much more wider automation using WLST based on this script.

Pre-requisites set-up for Multitenancy:

You can also visit the following post so that you can have connectivity what we are discussing here.

  1. Configure Security Realm for MT
  2. Create Users & Groups for Partition domain
  3. Configure Virtual Target
  4. Creating Partition Domain
  5. Configure IDD for Partition
  6. Partition Control (start/stop using WLST)
  7. Deploy and Undeploy Application on Partition [This post]

Download sample application

You can download sample web application for WebLogic environment :
Here I am using benefits.war which available in Oracle examples.
Download Shopping Cart Sample Link

Deploying an application to a WebLogic server fine it was upto 11g and regular WebLogic environment. In WebLogic 12.2.1 MT introduced with the great feature that is maintaining small domain partitions where you can feel the required resources all that need to run the application you will get in the partition. This MT deployment might more frequent when your application moved to WebLogic 12.2.1.

The deploy() and undeploy() command variation with the number of arguments you pass that are related to partition or resource group template. Here I've used first option targeting to a RUNNING State partition. As Oracle recommends to use ResourceGroupTemplate as target in the MT environment.

undeploy with WLST on Partition Domain
WebLogic web application deployment with WLST to a partition


The best benefit you can provide it to the partition deployment do one time deployment same partition you can package using export you will get final outcome as zip file. That you can reuse in other test environments as well.using import.

def deploy2partition(a,ap, p,rg,o):
        progress=deploy(appName=a, path=ap, partition=p, resourceGroup=rg, deploymentOrder=o, securityModel='DDOnly')
        while not (progress.isCompleted() or progress.isFailed()) :
                os.time.sleep(2)
        print progress.getState()

def undeploy4mPartition(a, p):
        progress=undeploy(appName=a,  partition=p)
        while not (progress.isCompleted() or progress.isFailed()) :
                java.lang.Thread.sleep(2000)
        print progress.getState()

def main():
        # The following are the properties which can be changed according to your needs.
        APP_PATH='/u01/app/software/benefits.war'
        APPNAME='BENEFITS'
        USER='weblogic'
        PASSWD='welcome1'
        ADMURL='t3://192.168.33.100:6100'

        connect(USER, PASSWD, ADMURL)
        partitionName="Corporate_partition"
        rgName="Corporate_rg"
        DOrder=10

        if len(sys.argv) >1:
                choice  = sys.argv[1]
        else:
                usage()

        if choice == 'deploy':
                deploy2partition(APPNAME, APP_PATH, partitionName, rgName, DOrder)
        elif choice == 'undeploy':
                undeploy4mPartition(APPNAME, partitionName)

        disconnect()
        print "Deployment process on partition completed successful !!!"

def usage():
        print """Usage:
        wlst """+sys.argv[0] +""" deploy | undeploy"""
        exit()

main()

The deploy option:
 wlst partitionDeploy1.py deploy
WLST deploy on Partition Domain
Administration Console deployment update:
The undeploy option:
 wlst partitionDeploy1.py undeploy
WLST Undeploy on Partion

Monday, July 25, 2011

Wanna get the status of the applications in domain


In most of WebLogic domain environments we might have seen multiple applications deployed on WebLogic servers. It is difficult to check their status when server uses high CPU utilization. We can get the complete details by giving one input i.e., target-name.

We use navigate MBean tree more frequently while using interactive mode of WLST and in scripting. Here we can call any attribute from any MBean tree by using colon ':' at the MBean tree root. Here we go with a sample of  for you who struggling to understand navigate each and every time.

Please check the below code snippet and you can change as per your requirement.

#############################################################
"""
 This script will get you status of the applications which are deployed 
 in your WebLogic Domain.         
 script get you the colorful output                         
 NOTE : You need to give target name as an input to the script                
 Author: Krishna Sumanth Naishadam                         
"""
##############################################################
import sys

connect('username','password','t3://wl_admin_host:wl_admin_port')
targetName=sys.argv[1]
domainConfig()
apps=cmo.getAppDeployments()
for i in apps:
    navPath1=getMBean('domainConfig:/AppDeployments/'+i.getApplicationName())
    appID=navPath1.getApplicationIdentifier()
    navPath=getMBean('domainRuntime:/AppRuntimeStateRuntime/AppRuntimeStateRuntime')
    sts=navPath.getCurrentState(appID,targetName)
    if(sts == "STATE_ACTIVE"):
        print "\033[1;32m Status of " + i.getApplicationName() + ": " + sts + "\033[1;m"
    else:
        print "\033[1;31m Status of " + i.getApplicationName() + ": " + sts + "\033[1;m"
disconnect()
exit()
 

domain_app_status.sh
********************

WL_HOME="
# set up common environment
. "${WL_HOME}/server/bin/setWLSEnv.sh"

CLASSPATH="${CLASSPATH}:${WL_HOME}/common/eval/pointbase/lib/pbembedded51.jar:${WL_HOME}/common/eval/pointbase/lib/pbtools51.jar:${WL_HOME}/common/eval/pointbase/lib/pbclient51.jar"
read -p "Enter Target Name : " value1

"${JAVA_HOME}/bin/java" -Xmx124m -Dprod.props.file=${WL_HOME}/.product.properties weblogic.WLST domain_app_status.py $value1 $*

The lifecycle of deployment process happen in the following way:



The following Colors I had chosen for reflecting what state for a application on a server.
======
Status of APPNAME1: STATE_ACTIVE (Green Color)
Status of APPNAME2: STATE_FAILED (Red Color)
Status of APPNAME3: STATE_NEW (Red Color)


Please see below screenshot for exact output

References:

Monday, March 22, 2010

Side by Side Deployment with WLST



One of my online buddy requested me Python script help for developing Side by Side(SBS) deployment using WLST.

Automate Python Script for Side By Side deployment.

The project is in developing stage, the client need deploying the same applications with different versions must be available for development and testing teams, an automated handy WLST script is requested to develop by buddy WLA.
Add caption

To do this interesting  task, the plan for execution is prepared as following while doing the deployment criteria:
1. If the application is New and the version is new i.e no other version is in the ACTIVE state with the given appName, the script will deploy the application
2. If one of the version of given application is in ACTIVE state visible in the console, then the developer is try to deploy the next version, the script should do DeActivate the old version and deploy the new version.
3. Now already have two versions deployed on the domain one is : ACTIVE state and other is in RETIERED State then undeploy the REITRED versioned application with a timeout interval or deploy the new version so that it will make current ACTIVE application to RETIERED and new deployment to ACTIVE.

Sample Video demonstration from Oracle Weblogic

For implementing the above logic in chronological way. The real challenge lies in the ISSUE with iterations. it was controlled by 'break' statement usually that we do in any C program. And I have used here a flag variable 'appFlags' to indicate the status of the Application status, like that we are able to maintained two version max in the console of the same app.

-->

import sys
#======================================================= 
# Function for fresh plain deployment
#======================================================= 
def newDeploy(appName,ver):
    print 'Deploying .........'
    deploy(appName,'/path/applications/'+appName+'/'+ver , targets='AdminServer')
    startApplication(appName)

#======================================================= 
# Function for finding the  Application Status
#=======================================================  
def appstatus(appName, serverName):
    cd('domainRuntime:/AppRuntimeStateRuntime/AppRuntimeStateRuntime')
    #get current real state for app in specific server
    currentState = cmo.getCurrentState(appName, serverName)
    return currentState
#======================================================  
# Undeploy the given application 
# Target we can change according to domain and application deployed on
#====================================================== 
def unDeploy(appName):
    print 'stopping and undeploying ....'
    stopApplication(appName, targets='AdminServer')
    undeploy(appName, targets='AdminServer')


#======================================================== 
# Main program here...
# Target you can change as per your need
#========================================================  
appName=sys.argv[1]
ver=sys.argv[2]
connect(user, passwd, adminurl)
cd('AppDeployments')
appflag=0
y=ls(returnMap='true')
for i in y :
 if i.startswith(appName )  ==1:
  #Checking for the application existence)
  print i
  print appstatus(i,'AdminServer')
 if appstatus(i,'AdminServer')=='STATE_RETIRED' :
  appflag=1
  break
 elif appstatus(i,'AdminServer')=='STATE_ACTIVE':
  appflag=2
 else:
  print ' other Applications are Running '
  pass


if appflag == 1 :
    print 'application having RETIERED STATE ..'
    unDeploy(i)
    print appstatus(i,'AdminServer')
    newDeploy(appName,ver)
    print appstatus(i,'AdminServer')
elif appflag== 2:
    print 'Application exists in ACTIVE state...'
    newDeploy(appName,ver)
    print appstatus(i,'AdminServer')
else:
    print 'new application'

How to execute the Side by Side deployment script?
Dear novice WLA, you can execute this script by re-defining your connection parameters at line 36. Remember one more thing is the application targeted to AdminServer this may vary for your environment as managed servers or clusters.
prompt$ java weblogic.WLST SBSDeploy.py

If you like the ideas implemented in this script, useful to your environment please share this article.

Reference URLs:

Popular Posts