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

Monday, November 15, 2010

WebLogic domain migration made easy by WLST

Huge migrations will be done in short time with wise WLST tricks. Now every one thinking about visualization of Cloud computing, that impacts on Oracle FMW components and also on WebLogic components. When there is hundreds of servers in build and deploy for a business there must be best practices that includes WLST automation with templatizing is must. This strategy will save lot of time, which consumes for configuring each system resource, user-defined resource on the WebLogic domain. The customized WebLogic domain templates can be used for the following situations:

This new feature is introduced from WebLogic 9.x onwards, we have wonderful options in WLST.
1. Default template to customized domain template
2. Existing Domain to customized domain template then domain
3. Domain Template from WebLogic 9.x to WebLogic 10.x domain and also supports this from WebLogic 10.x to WebLogic 11g migration process.
4. WebLogic Domain migrations from one machine to another

WebLogic Domain migration with WLST


Let me explain my current experiment on creating new WebLogic 11g Domain from existing WebLogic 9.2 domain which we did successfully in UAT, staging and finally in live too. The basic steps I followed in offline are as :
1. creating template: readDomain() from the existing WebLogic 9.2 and create a domain template with writeTemplate().
2. configuring new domain: go to the destination machine and readTemplate(), writeDomain()
3. updating for new domain: readDomain() and then modify the ListenAddress, ListenPort, security settings, and Log details for the domain
4. after making all required changes use updateDomain()

468x60
Big Advantage of Domain Templates using WLST

This will reduce the pain of creating
1. DataSource
3. Multi DataSource
4. JMS module
5. Persistence store
6. Start scripts
7. Domain environment automatically updated

Configure new domain templates


A domain configured from an existing development server to new machine. all the domain files are hoped to new machine, but certain parameters dependent on the local configurations. Such as listen address for the admin server, here is the need of WLST in offline mode to rectify the current environment. readDomain() is the WLST command that gives the access to current configuration and reproduce that domain template with writeTemplate().

Source machine:
readDomain('/home/domains/olddomain')
writeTemplate('/home/templatepath/olddomain.jar')
closeDomain()

Configuring new Domain on migrating machine

Now you can copy this template olddomain.jar file to destination machine and copy to the destination location. Execute following offline command sequence as follows:
createDomain('/olddoamin/path/template.jar’,’domainPath’,’user’, ‘passwd’)

Extending a Domain with WLST

To an existing domain you can change the few parameters regularly this you can give in a separate properties file. Create a simple script when you run the WLST script it will impacted in the new domain for extending with new properties this could be a best practice. For further updates you need to update one of the parameter that will make all the environment scripts updated for this new domain with new environment, So don't forget to update one of these following values:

readTemplate('/home/templatepath/olddomain.jar')
writeDomain('/home/domains/newdomain')
closeTemplate()
readDomain('/home/domains/newdomain')
ls()
cd('Server')
ls()
cd('AdminServer')
set('ListenAddress','hostname.com')
set('ListenPort',10300) # Changing Admin Server ListenPort
set('Name','newAdmin') # Changing Admin server name

cd('/Server/newAdmin/Log/newAdmin')
set('FileName','/home/instances/newAdmin/logs/newAdmin.log')
updateDomain()
closeDomain()

Change to Production Mode
One of the situation that where you start working on developing complete platform designing for a Weblogic based environment such as SOA or WebCenter or some other. You might get situation where you need to change development mode to production mode. If your pre-production environtment is made exaactly simula of production then the only one thing you need to change that is Production Mode. This Production mode will give more security than development mode for WebLogic domain. Using WLST you can do this very easy to modify this
connect(adminUser,adminPassword,adminURL)
edit()
startEdit()

cd('/')

####################################################################################
# DOMAIN LEVEL CONFIGURATIONS
###################################################################################
print ' ******* SETTING DOMAIN LEVEL CONFIGURATIONS *********** '

domMode = getMBean('/')
domMode.setProductionModeEnabled(true)

domLog = getMBean("/Log/"+domainName)
domLog.setFileName(''+domainHome+'/logs/bea/'+domainName+'.log')

secCon = getMBean("/SecurityConfiguration/"+domainName)
secCon.setEnforceValidBasicAuthCredentials(false)

print ' ******* DOMAIN LEVEL CONFIGURATIONS SET SUCCESSFULLY *********** '
save()
activate(block="true")

disconnect()
The properties file be look like this:
adminUser=weblogic
adminPassword=weblogic123$
adminServerName=admin_cldom
adminServerListenaddr=localhost
admlistenport=7100

OverwriteDomain=true
domainName=cldom
domainHome=/wldomains/cldom
After running above script, you need to stop all the servers in the domain with the current domain configuration start the AdminServer first then start remaining managed servers. This will show the impact of change mode. One of my online buddy asked me is there any chance to migrate from non-WebLogic Application server(such as JBoss/WAS/OCJ4 etc) to WebLogic. Right now it is not available from Oracle, If Oracle give similar way of templates  for migrating from OCJ4 Application Server migration, Websphere migration, JBoss migration and TCat server migration templates then it is more easy life for migrating from any J2EE server to any other. This is a very marketing strategy because it can make more revenue for Oracle and it is easy for customers and WLA to migrate JEE applications to Oracle WebLogic Server. What do you say dear blog reader?? Keep writing your suggestions, comments.

Sunday, September 5, 2010

NodeManager Experiments using WLST

Create Machine configure NodeManager using WLST

This blog post is renovated with latest WebLogic 12.2.1 version execution output here. We have more generic reusable functions, three different functions each one has independent task. Where the pre condition for this is you must have a domain configured and admin server is running.

  1. create a machine and setup the Nodemanager 
  2. delete machine from the domain
  3. show all machines in the domain


 

#==========================================================================
# FileName      : createMachine.py
# Updated       : 11/22/2015
# Description:
# This simple script will create multiple machines
# and also set the NodeManager properties
# use demo.properties file loadProperties command line argument expected
#
# You can add this function block to full domain
#==========================================================================

def createMachine(machineName, machineIP,nmPort=5556):
        """
        This function takes three arguments machineName, machineIP, nmPort
        The default nmPort is 5556 and nmType as Plain
        """
        cd('/')
        cmo.createUnixMachine(machineName)

        cd('/Machines/'+machineName+'/NodeManager/'+machineName)
        cmo.setNMType('Plain')
        cmo.setListenAddress(machineIP)
        cmo.setListenPort(nmPort)
        cmo.setDebugEnabled(false)

def deleteMachine(machineName):
        """
        This function takes machineName as argument
        It will delete the Machine MBean from the Domain
        """
        cd('/')
        editService.getConfigurationManager().removeReferencesToBean(getMBean('/Machines/'+machineName))
        cmo.destroyMachine(getMBean('/Machines/'+machineName))

def printMachineList():
        """
        This function will display the machines configured on a domain
        No arguments required
        """
        cd('/')
        redirect('/dev/null', toStdOut='false')
        machineslist=ls('Machines',returnMap='true')
        for m in machineslist: print m
        stopRedirect()

def main():
        """
        Here we can expect ConnectionException, WLSTException
        and also BeanAlreadyExist for createMachine function
        """
        connect(ADMINUSER,ADMINPASSWD, ADMINURL)

        print "Before machines creation..."
        printMachineList()

        edit()
        startEdit()

        for i in range(1,5):
                try:
                        createMachine('machine'+str(i), '192.168.33.'+str(100+i),5566)
                except:
                        print 'Machine creation failed...'+'machine'+str(i)
        activate()

        print "After creation..."
        printMachineList()

        HitKey=raw_input('Press any key to continue...')

        startEdit()
        for i in range(1,5):
                try:
                        deleteMachine('machine'+str(i))
                except:
                        print 'Unable to remove machine...'
        activate()

        print "After removing machines..."
        printMachineList()
main()

Excecution of the Machine configuration is as follows....


java weblogic.WLST  -loadProperties demo.properties createMachine.py

create, delete and show machines in WebLogic 12.2.1 domain

Double confirmation with Admin console

Machine in WebLogic Domain configured with WLST


Start n Stop the Server using NodeManager by WLST

Manage the Server Life Cycle continues...
[2] Configure a NodeManager to start WebLogic Server instances (using console and command-line)

Start n Stop Server using NodeManager by WLST:

In the sun Solaris environment we need to change few nodemanager.properties to run the NodeManager. There are two kinds of Node Managers available
Java based Node manager
Script based Node manager

while connecting to nodemanager we have received an error as below:

Error encounter when the java native
bash-3.00$ tail -100f nodemanager.log


weblogic.nodemanager.common.ConfigException: Native version is enabled but node manager native library could not be loaded
at weblogic.nodemanager.server.NMServerConfig.initProcessControl(NMServerConfig.java:239)
at weblogic.nodemanager.server.NMServerConfig.(NMServerConfig.java:179)
at weblogic.nodemanager.server.NMServer.init(NMServer.java:177)
at weblogic.nodemanager.server.NMServer.(NMServer.java:142)
at weblogic.nodemanager.server.NMServer.main(NMServer.java:327)
at weblogic.NodeManager.main(NodeManager.java:31)
Caused by: java.lang.UnsatisfiedLinkError: no nodemanager in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1682)
at java.lang.Runtime.loadLibrary0(Runtime.java:822)
at java.lang.System.loadLibrary(System.java:993)
at weblogic.nodemanager.util.UnixProcessControl.(UnixProcessControl.java:16)
at weblogic.nodemanager.util.Platform.getProcessControl(Platform.java:108)
at weblogic.nodemanager.server.NMServerConfig.initProcessControl(NMServerConfig.java:237)
... 5 more

java weblogic.WLST startAdmin.py wcludomNM

connect('weblogic', 'weblogic', 't3://wlhost:7913')
nmEnroll('/home/wluser/domains/WLclsnm')
CLASSPATH to set for NodeManager:
export NM_HOME = $WL_HOME/common/nodemanager

CLASSPATH=/export/home/wladmin/wl813/bea/jdk142_04/jre/lib/rt.jar:/export/home/wladmin/wl813/bea/jdk142_04/lib/rt.jar:/export/home/wladmin/wl813/bea/patches/CR204958_810sp3_v1.jar:/export/home/wladmin/wl813/bea/weblogic81/server/lib/weblogic.jar

startNodeManager(verbose='true',NodeManagerHome='/home/wluser/bea/weblogic92/common/nodemanager')

To Check the log of nodemanager.log
tail -100f /home/wluser/bea/weblogic92/common/nodemanager/nodemanager.log

/home/wluser/bea/weblogic92/common/nodemanager/nodemanager.domains>

nmConnect('weblogic', 'weblogic', 'wlshostname','5556', 'WLclsnm', '/home/wluser/domains/WLclsnm')

prps = makePropertiesObject('weblogic.ListenPort=9013')
wls:/WLclsnm/serverConfig>
wls:/WLclsnm/serverConfig> nmStart('app01',props=prps)
Starting server app02 ...
Error Starting server app02: weblogic.nodemanager.NMException:
Exception while starting server 'app02': java.io.IOException: Server failed to start up. See server output log for more details.

prps = makePropertiesObject('weblogic.ListenPort=9013')

start('wlctr', 'Cluster')

nmStart('app02',props=prps)
Starting server AdminServer...
Server AdminServer started successfully

nmConnect('weblogic', 'weblogic', 'remotehostnameofmanagedserver' '5556','WLclsnm', '/home/wluser/domains/','plain')

Still workin progress to start the remotemanaged server by using wlst
(I am getting some errors when I tried ...will update this site Once it will done successfully if anybody is done plz post it as comment.)
Posted by Pani at 9:44 AM 1 comments:


Archana said...
Hi,
We are also facing the same issue. Not able to start managed servers using makepropertiesobject.

Did u get any solution.
Yes, Archana, We found the Solution as using PLAIN type for NodeManager is good to go.

Wednesday, August 25, 2010

Get Options for command line in WLST script

Problem Statement

Required a Python script for check if the WebLogic admin server is 'Running' or Not recursively
To execute this you have 2 options
1. Executing forever
2. timeout, interval as aruguments

If it isn't keep checking forever or as long as is passed on the command- line with the -t parameter. The wait between checks can be modified with the -i parameter on the command line.

There could be your environemnt also need such options for a Python script. This script will be a example for such requirements.

Script Logic
Hey Smart WLAs what do you think the solution for the above problem statement?? Got any idea? I know you guys are very intelligents!! hope you got idea about getting options at command-line. Yes, it is possible for our WLST Script too, getopt is a python capability which allows us to accept the command line arguments with options -t, -i. Of-course my buddy struggle to find this clues on the Google almost took 2 days.
  1. To read the command line values as dictionary and split as key, value pair and compare the key with desired options then performing the script according to user choice.
  2. If the user failed to enter the options at commandline exception handling with usage funcation.
  3. WLST connect to admin server regular function.
  4. Using sleep method for stopping the WLST execution for some time interval. Repeating this process till given timeout or run this above steps for forever.


#!/usr/bin/python
# Author : Raghunath
# Save Script as : checkAdmin.py 

import time
import getopt
import sys

# ========= connecting to Admin server ==================
def connectAdmin():
   r=1
   try:
        # Update the following line as per your environment
        connect(url='t3://AdminHost:AdminPort')
        print "*** Connected sucessesfully ***"
        r=0
        sys.exit(r)
    except:
        return r
 
def usage():
    print "Usage:"
    print "checkAdmin.py [-t timeout] [-i interval]"
    print "exit with 0 if find Admin Server"
    print "exit with 1 if do not find Admin Server"
    print "if no timeout is given, look for Admin Server until it is found"


# ===== Default settings ===================
Timeout = 0 
Interval = 25000
forever = 1

#====== Main program ===============================
try:
    opts, args = getopt.getopt( sys.argv[1:], "t:i", ["Timeout","Interval"] )
except getopt.GetoptError, err:
    print str(err)
    usage()
    sys.exit(2)

#===== Handling get options  ===============
for opt, arg in opts:
    if opt == "-t":
        Timeout = arg
        forever = 0
    elif opt == "-i":
        Interval = arg

while (forever == 1) or  (Timeout > 0):
     if connectsave() == 1:
         print 'Now, Sleeping  15 sec *************'
         java.lang.Thread.sleep( Interval )
         print 'Waking up after 15 sec ...'
     
      
print 'done'



To run the above script you can make a small shell script as follows:
# checkAdmin.sh

. $WL_HOME/server/bin/setWLSEnv.sh
java weblogic.WLST checkAdmin.py "$@"

Run this shell script as :
$ checkAdmin.sh -t 100 -i 20

or you call directly python script as follows
$ java weblogic.WLST checkAdmin.py -t 100 -i 20

Note that indentation is must for every Python script, please double check before you run the script.
Write back for any issues ariases when you execute the script in your environment.
Referneces:

# email functionality base on http://docs.python.org/library/email-examples.html

Tuesday, August 24, 2010

Configuring Multi DataSource

Introducing Problem Statement for this post is WLST which enables us to configure any kind of resource on a WebLogic domain. Here I am with new attempt to configuring Multi Datasource. In most of new domain configurations you need to work separately for configuring Datasource. We are already seen how to configure a Dynamic Datasource with customized property file, Adding to the same topic now we are going to work on Multi Datasource configuration.

The steps involved in multi datasource confiuration are as follows:
1. Configure individual datasource
2. Configure a new multidatasource
3. Add the datasources created in steip 1

Keeping more flavor (Object-Orientation) to your script we will create a Class in WLST this time. Are you ready??? I know you guys very intelligents and know all WLST tricks how they works and all!! Lets dive into the process of configuration.
-->


#==========================================
# File name: ConfigMDS.py
# Please change the code (line 38) as per your environment and needs
# Author : Inteligent WLA :)
#=============================================

class MDS:          
 def __init__(self, nam):
  self.nam  = nam 

 def configMDS(self):
  n=self.nam
  try:
   cd('/')
   cmo.createJDBCSystemResource(n)
   cd('/JDBCSystemResources/'+n+'/JDBCResource/'+n)
   cmo.setName(n)
   cd('JDBCDataSourceParams/'+n)
   set('JNDINames',jarray.array([String(n)], String))
 
   cmo.setAlgorithmType('Failover')
   dslist=raw_input('Please enter comma separating Datasources for MDS:')
   cmo.setDataSourceList(dslist)
   cd('/JDBCSystemResources/'+n)
   targetType=raw_input('Target to (C)luster or (S)erver: ')
   if targetType in ('C','c') :
           clstrNam=raw_input('Cluster Name: ')
               set('Targets',jarray.array([ObjectName('com.bea:Name='+clstrNam+',Type=Cluster')], ObjectName))
          else:
               servr=raw_input('Server Name: ')
               set('Targets',jarray.array([ObjectName('com.bea:Name='+servr+',Type=Server')], ObjectName))
   print 'Succesfully configured MultiDataSource...'
   activation()
  except BeanAlreadyExistsException:
   print 'Error: '+n+' BeanAlreadyExists...'
       cancelEdit('y')
   exit()

#===== main program===============
if __name__== "main":
 connect('wlusr','paswd','t3://AdminUrl:AdminPort')
 edit()
 startEdit()
 
 mdsName = raw_input("Please enter MultiDataSource name: ")
  # create object, call configMDS
 MDS(mdsName).configMDS()
 print('Exiting...')
 exit() 

Here you can templatise more by creating the a properties file where you need to store Multidatasoruce name, JNDIName, WebLogic Admin user, Password, AdminURL, the datasource names you wish to add to the multidatasource.

Use the same steps as followed in the Generic Data Source Creation.

# http://unni-at-work.blogspot.com/2009/03/multi-data-source-using-wlst.html
# http://edocs.bea.com/wls/docs100/wlsmbeanref/mbeans/JDBCDataSourceParamsBean.html#AlgorithmType

Monday, May 31, 2010

JDBC datasource monitoring

"JDBC Monitoring" script, which I was published 2 days back works good for simple single data source and also multi datasources on a domain. But, there is an inadquate information about targeted servers that script doesn't have the flexibility for displaying those managed server mapping with a DataSource.

One of blog follower(Mr. Venkatesh Durai) asked me for the same, A script works for managed server wise display for the Datasource performance monitoring with WLST. It was already discussed by Srikanth Sonti and Vijay Bheemaneni in Oracle WLST ORKUT forums.


Orkut link
Here we go with the latest script, HTH scriptors...

#========================================================
# ScriptFile: DSMonitor.py 
# Author : Pavan Devarakonda
# Purpose : Multi Datasource monitoring with Server wise
#========================================================
urldict={}
def conn():
try:
    print 'Connecting to Admin server....'
    connect(username, password, adminurl)
except:
    print 'Admin Server NOT in RUNNING state....'


def initialize():
    conn()
    try:
        serverlist=['app01','app02','app03'...]
        for s in serverlist:
            cd("/Servers/"+s)
            urldict[s]='t3://'+get('ListenAddress')+':'+str(get('ListenPort'))
            JDBCStat()
     except:
          print 'issue in accessing JDBC Pool'

def printline():
    print '------------------------------------------------------------'

def printHeadr():
    print 'JDBC CONNECTION POOLS STATISTICS'
    print ' '
    print 'Name      Max      Active  Active   WaitSecs Waiting  State'
    print '          capacity Current HighCnt  HighCnt  Count'
    printline()

def getJDBCDetails():
    pname=get("Name")
    pmcapacity=get("CurrCapacityHighCount")
    paccc = get("ActiveConnectionsCurrentCount")
    pachc = get("ActiveConnectionsHighCount")
    pwshc = get("WaitSecondsHighCount")
    pwfccc = get("WaitingForConnectionCurrentCount")
    pstate = get("State")
    print '%10s %7d %7d %7d %7d %7d %10s' % (pname,pmcapacity,paccc,pachc, pwshc,pwfccc,pstate)
    print ' '

def JDBCStat():
    Ks = urldict.keys()
    Ks.sort()
    printHeadr() 
    for s in Ks:
    try:
        connect(user, passwd,urldict[s])
        serverRuntime()
        cd('JDBCServiceRuntime/'+s+'/JDBCDataSourceRuntimeMBeans/')
        print ' '+s
        printline()
        DSlist=ls(returnMap='true')
        for ds in DSlist:
            cd(ds)
            getJDBCDetails()
            cd('..')
    except:
 #pass
        print 'Exception'
        quit()

def quit():
    print ' Hit any key to Re-RUN this script ...' 
    Ans = raw_input("Are you sure Quit from WLST... (y/n)")
    if (Ans == 'y'):
        disconnect()
        stopRedirect()
    else:
        JDBCStat() 

if __name__== "main":
    redirect('./logs/JDBCCntwlst.log', 'false')
    initialize()
    print 'done'




How to run this Script??
Recently one of my blog follower wrote to me " What is the right way for running this monitoring scripts?". Here I am editing my blogs for more readable and flexible for novice WLA.

You need to update with your environment details at line 5, 11, 14. Create this script in a separate folder where you should maintain logs folder, this is expected by line 67.

To run the above script you need to use regular WLST invoking command as follows:
prompt> java weblogic.WLST DSMonitor.py

This is universal way of running WLST I mean on UNIX flavours, on Windows, on Mac OS too.

Friday, May 28, 2010

Mail from WLST when abnormal state for Server

In most of production environments there could be possibility of a WebLogic server instances go on overload and crash or it could reach to a non RUNNING state due to many reasons. But if we know the state of that WebLogic server instance then we can act immediately for further harm to be predicated and confidently control that could happen  in that WebLogic domain.


Python network library smtplib in WLST

WLST supports multiple the network libraries such as

  1. ftplib 
  2. poplib 
  3. imaplib 
  4. smtplib 
  5. telnetlib 
these are  network capabilities in their process, scripting we need to import the libraries and you can use the built-in functions. Before using this smtp libraries you need to check the SMTP service enabled on the machine.

Here I am trying to send the alert mail message when one of the WebLogic Managed Server goes to SHUTDOWN state or UNKNOWN state or some other state which is not RUNNING.

-->

Assuming that your machine have SMTP mail service must enabled. Check before creating this script on the box. Here in the following script you can replace the 'To' address value given as  pavanwla@MAILSERVER.com with mailing address of your supporting WebLogic Administrators (WLA) list by comma separation.
#======================================================
# Script File : StatusMail.py
# Author      : Pavan Devarakonda
# Updated on  : 29th April 2010
#======================================================
import smtplib
import time

From = "wla@WLSERVER.com"
To   =["pavanwla@MAILSERVER.com"]
Date = time.ctime(time.time())
URL='t3://'+get('ListenAddress')+':'+str(get('ListenPort'))

def getServerNames():
   domainConfig()
   return cmo.getServers()

def mailing(name, stat):
    serverRuntime()
    serverConfig()
    if stat == 'SHUTDOWN':
        Subject = ' major: '
    else:
        Subject= 'Critical:'
    Subject= Subject + 'The Weblogic server instance ' +name + ' is ' + stat

    Text='The Server ' +name +'   in the '+ stat+'  Listening at URL ' + URL
    Msg = ('From: %s\r\nTo: %s\r\nDate: \%s\r\nSubject: %s\r\n\r\n%s\r\n' %(From, To, Date, Subject, Text))
    s = smtplib.SMTP('YOURSMTP.DOMAIN.COM')
    rCode = s.sendmail(From, To, Msg.as_string())
    s.quit()

    if rCode:
        print 'Fail to send message...'

def serverStatus(server):
    cd('/ServerLifeCycleRuntimes/' +server)
    return cmo.getState()

def checkStatus():
    try:
        connect('username','******','t3://adminIP:AdminPort')
        serverNames= getServerNames()
        domainRuntime()
        for name in serverNames:
            print name        
            serverState = serverStatus(name)
            if serverState == "SHUTDOWN": 
                mailing(name, serverState)
            elif serverStat == 'UNKNOWN':
                mailing(name, serverState)
    except:
        mailing('AdminServer','Connection Fail')

if __name__== "main":
    redirect('./logs/status.log', 'false')
    checkStatus()
    print 'done'
To make you more comfortable here you need to update few lines 7, 8 10, 27, and 40. Hope you have idea what need to replace in these lines! for your environment.

Cronjob schedule

If you need this script need to run for every 30 mins you can schedule the following line into a shell script. map the shell script to crontab by giving the -e option. If got any trouble please write back to me :)

To test run this script in UNIX/Windows/MacOS/anyother...
prompt> java weblogic.WLST StatusMail.py

Keep posting your valuable comments and suggestions on this post.

References:

  1. http://docs.python.org/library/smtplib.html
  2. http://uthcode.sarovar.org/pyconindia2010/presentation.html

Wednesday, May 19, 2010

WebLogic Scripting Tool (WLST) Overview

-->
There are many newbies into the WebLogic stream ( Development/ Administration). Most of them are novice to WLST. I thought let me found a way to give you best links available on the net.

After being in the development team one of my buddy asked me "your blogs are very nice, I want to learn WLST. But where to start? " My answer for all my blog readers who want to encourage newbies in WLST can pass this post. Currently WLST is supporting Application Servers are listed as follows:
  • WebLogic 8.1
  • BEA WebLogic 9.0
  • BEA WebLogic 9.1
  • BEA WebLogic 9.2
  • BEA WebLogic 10.0
WLST is first initiated in the BEA System Inc., days so it is supported since WebLogic 8.1 onwards with latest service packs till WebLogic version 10.0. After Oracle acquisition following are the versions:

  • Oracle WebLogic 10g R3
  • Oracle WebLogic 11gR1
  • Oracle WebLogic 11gR1 PatchSet 1 (10.3.1)
  • Oracle WebLogic 11gR1 PatchSet 2 (10.3.2)
  • Oracle WebLogic 11gR1 PatchSet 3 (10.3.3)
  • Oracle WebLogic 12c

WLST Features indentation - Clear Sytax


The WLST programming structure follows strict syntax indentation and it is the same structure as in Python programming. As per my experiances with WLST it can be divided into four parts
  1. Importing section
  2. Global variables
  3. Definations - class/function
  4. Main program uses above sections

Import section for Reuse
importing WLST libraries includes Python standard libraries and thousands of new Jython libraries also included. You can have Java packages as module imports which gives you flexible programming.

While writing a WLST script, the file can be store with the extension .py are called python modules. We can reuse the external language such as Java methods into our WLST script you can use import statement for this. Here is the syntaxes that you can use.

import module
from module import submodule
from . import submodule

You can write a WLST script that uses command line aruguments using sys module sys.args.

WLST Datatypes - Global variables

In WLST you can define the global variables on the top of the program that can be used across all the functions defined in the script. On the other hand you can define the variables in the function definitions that can be treated as local to the function, Jython programming language supported datatypes all can be used it supports
  • Base Datatypes: integer, float, long, char, str, bool
  • Collection Types: list, dictionary, tuple, sequances, maps etc
  • Object types: Python objects and Java package objects
Dynamic typing
In WLST supports Python Dynamic typing, we can use same variable for storing different type of data as shown below.
wls:/offline> # VAR CAN CHANGE INTO MANY TYPES
wls:/offline> var=10
wls:/offline> print var
10
wls:/offline> var='Busy in WLST'
wls:/offline> print var
Busy in WLST
wls:/offline> var=[1,2,3]
wls:/offline> print var
[1, 2, 3]

Class in WLST

Object oriented scripting can be defined and can be reusable with creation of objects.
 
class CLASSNAME:
 def __init__():   #like C++ constructor
  self.name
  do something initially
 def function1():
  do some task 
Let’s experiment with class in WLST. In a class we can define attributes and we can assign values to them. And we define functions related to that class that you will make.
wls:/offline> class test:
...     u,p='weblogic','vybhav@28'
...
After this we are able to create instances of the class test. Let us create t as a instance of test class.
wls:/offline> t=test()
wls:/offline> print t.u,t.p
weblogic vybhav@28
There is a difference between class attribute and instance attributes. Let us know about it, The variables u, and p of the instance can be modified by assignment:
wls:/offline> t.u='vasuakka'
wls:/offline> t.u
'vasuakka'
In u attribute value was changed into ‘vasuakka’ instead of ‘weblogic’.

Function definitions in WLST

How to define a Function in WLST? It is simple it starts with keyword ‘def’, you need to give a name of the function followed by number of argument and a colon. After this you need to give a tab space indentation that indicates the function block. You can add text to tell about what this function will do. Then you can add number of WLST statements or control flow statements. At the bottom of the function you can return a value or you leave that line, it is optional.
Now, let’s experiment with function definition for conversion of Kilobytes to megabytes. The logic of this function is that we can get the megabyte value when you pass the argument as kilobyte this will be divided by 1024.
wls:/offline> def kb2MB(kb):
...     mb=kb/1024
...     return mb
...
wls:/offline> print kb2MB(2048)
2

WLST Operators

You WLST commands statements not only JMX accessing functions we need to use some of the Python programming control flows in it. To use the control flow you must know about what kind of operations you can do in WLST. So let us see some of them are:

Comparison operators
This opertators we can use in regular if statements or while statements
==, >, <, <=, =>

Logical Operators
In WLST the variable can be empty or zero values are treated as "", 0, None, 0.0, [], and {}. So you need to be careful when you define a variable and moved the values of variables.

How WLST script Execution works?

Here I am going to explain with the following picture, how the Python script will be interpreted and internally compiled to java code and then Byte code so that it can be executable on JVM.
WLST Execution process
The source code for the WLST script is written in Python code. The WLST program file must have the extension as .py which is the source code consisting a set of Jython instructions for WebLogic domain. This source code is going to use a JVM machine when it is instructed to RUN the script; its invocation internally generates Java byte code to interpret with the JVM to produce the desired output. You might wonder by seeing this Chines WLST link, but it is worthy to see in google chrome. Because the web-page is from china and entire page is in chaineese language. If you have Google Chrome it will give you translate on top of the page you can choose your choice of language and have knowledge on WLST :) Here I am sharing the wonderful presentation about WLST overview. Check this following SlideShare Presentation: it's pretty informative, it was delivered by James Bayer who is the technical expert from Oracle. Especially I more impressed myself to see the 47 slide saying about THIS blog as one of the web reference.
Thankyou for visiting this post, feel free to post your comments after viewing these video links.

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:

Friday, February 12, 2010

Restarting 24 x 7 Domain with WLST

Here I have little bit struggle to reach a conclusion that, what all servers need to stop? when to stop? the preparing script I did with my analysis that stated that few sites requires 24x7 HA. Few of them don't need the HA, that is site can have sometime outage where it doesn't have request for the application.

Me and Prasanna Yalam discussed about a strategy where every time you run few servers can be stopped from different physical locations. when starting them up then only next round of managed servers can be stopped. This strategy implementation firstly thought with 2 scripts then I made it 2 phases one by one can be done with user input. This module named as 'regularStop()', which supports 24x7 HA domain.

One more thing we need to consider here is most of the Production deployments are in nostage mode, when new version release of application code requires complete domain down option requirement. This is another module take cares where it will stop all clusters in the domain should be passed. The module named as 'releaseStop()'. This you can use for any WebLogic domain.


After composing whole script ran it then found that there is need of server state or cluster state when it is given shutdown command. So every shutdown command is followed by state command given that gives more confidence on script how it is executing.

Finally by performing releaseStop() or RegularStop() we can go for stopping the Admin Server.


Note: Don't forget proper indentations, while editing my script it might be disturbed here.
#====================================
# Script File: StopWLDomain.py
# This module is for 24x7  Domain****
# First phase stops few managed servers of few sites
# Second phase will be used for stop remaining servers
# Note that Second phase allowed only when you press 'y'
# before that you need to Start all the Phase 1 stopped servers.
#====================================
def conn():
 try:
  connect(user, passwd, adminurl)
 except ConnectionException,e:
  print '\033[1;31m Unable to find admin server...\033[0m'
  exit()

#====================================
# Stop all instances of a Cluster 
#====================================
def stopClstr(clstrName):
 try:
  shutdown(clstrName,"Cluster")
  state(clstrName,"Cluster")
 except Exception, e:
  print 'Error while shutting down cluster ',e
  dumpStack()
  return

#====================================
# All the instances of all Clusters will be down for release
#====================================
def releaseStop():
 clstrList=["webclstr1", "webclstr2'..."ejbclstr"]
 for clstr in clstrList:
  stopClstr(clstr) 

#====================================
# Stop a instances given as parameter 
#====================================
def stopInst(iservr):
 try:
  state(str(iservr))
  shutdown(str(iservr), 'Server',force="true")
  state(str(iservr))
 except Exception, e:
  print iservr, 'is having error in shutting down'
  pass

#====================================
# Regular Rstart is 24x7 supported for :SITE1, SITE2, SITE3
#====================================
def regularStop():
 clstrList=["non247clstr1", "non247clstr2"]
 for clstr in clstrList:
  stopClstr(clstr) 
 servrList=servrList=["app1","app2","app3"... "web1","web2"] #sitewise list of servers need to stop
 for inst in servrList:
  stopInst(inst)
 print 'Now, please start the instances exclude the phase 2 instances ...'
 phase2=raw_input("Want to proceed for Phase 2...(y/n)")
 if phase2 == 'y':
  serverList=["app4","web3"...] # remaining Managed Servers to stop after phase servers UP n Running
  for inst in serverList:
   stopInst(inst)

#====================================
# Exiting the script
#====================================
def quit():
 disconnect()
 exit()

#====================================
# The main script starts here...
#====================================
if __name__ == "main":
 conn()
 print ' 1. Regular Stop (24x7)\n 2. Release Stop\n 0. Quit\n'
 sAns=raw_input('Enter your choice: ')
 if int(sAns) == 1:
 regularStop()
 elif int(sAns) == 2:
 releaseStop()
 elif int(sAns)== 0:
 quit()
 else:
 print 'Warning: Invalid option...'
 exit()
 print 'Finally stopping admin now...'
 shutdown()

#========WLST=BY=EXAMPLES==============

You can run this script with java in your PATH and weblogic.jar in the CLASSPATH.
java weblogic.WLST StopWLDomain.py

Wednesday, February 3, 2010

Configuring a Generic Datasource

Configuring the datasource is one time activity for any project in production environment but where as for development or testing environment there is always need for change the datasource as per the demand. These changes makes interrupt majority of the development process. To improve this process we can have a Generic JDBC Data source configuring script in your utilities space.

Creating the data source using a python script makes 100% reusable. Here my perception is that if we don’t hard code the JDBC parameters it will be easy to use for all environments as well as for any kinds of database platforms and their respective driver param values to replace also.

Initially lets go with single Data source creation with targeting to the user input Server it can be Managed Server or AdminServer (basic domain), later on we can go for improve further to target to a Cluster.

JDBC Datasource in offline vs Online WLST


This scripting we can write in two ways offline and in online. In the offile mode we need to navigate the MBean and create, configure parameter and finally do assign() them to a Server or Cluster of a domain. For the online script we need to set the target using setTarget() command. To do this we must connect to the Admin server and acquire lock on configuration repository by edit() or startEdit() commands.


assign('JDBCSystemResource', ‘myds', 'Target', demoCluster')
# -- or --
assign('JDBCSystemResource', ‘myds', 'Target', demoServer')

Datasource MBean in WebLogic
JDBCSystemResourceMBean tree


Oracle WebLogic supports jDriver for various DBMS. And also WebLogic supports XA drivers for distributed transactions. Supporting Third-Party Drivers also available from DBMS vendors. Note the following are the WebLogic supports Drivers for DBMS:

Cloudscape DB2 PostgreSQL
Oracle  Ms SQL Progress
MySQL  PointBase Sybase

Configuring new data source custom properties
Now let us try to configure a new data source with a custom properties for Connection Pool parameters, weblogic console connecting parameters into a same file or you can specify with different properties files. When the properties file is used it must be loaded before first line of processing statement in the script. We have two options to load the properties one is using command line and other one is using loadProperties() method.

###################****##############****########################
# Generic script applicable on any Operating Environments (Unix, Windows)
# ScriptName    : ConfigDS.py
# Properties    : ConfigDS.properties
# Author        : Srikanth Panda
# Updated by    : Pavan Devarakonda
###############     Connecting to Start     #################################
def connectAdmin() :
 try:
  connect(CONUSR,CONPWD, CONURL)
  print('Successfully connected')
 except:
  print 'Unable to find admin server...'
  exit()
################### Configuring Connection Pool #############################
def connPool(DSnam) :
 DRVPARM='/JDBCSystemResources/'+DSnam+'/JDBCResource/'+DSnam+'/JDBCDriverParams/'+DSnam
 cd(DRVPARM)
 set('Url',DBURL)
 set('DriverName',DBDRV)
 set('Password',DBPASS)
 cd(DRVPARM+'/Properties/'+DSnam)
 cmo.createProperty('user')
 cd(DRVPARM+'/Properties/'+DSnam+'/Properties/user')
 set('Value',DBUSR)

############         Creating Data source    ###############################
def createDS() :
 print('Naming the datasource')
 DSnam = DSName
 cmo.createJDBCSystemResource(DSnam)
 RESOURCE='/JDBCSystemResources/'+DSnam+'/JDBCResource/'+DSnam
 cd(RESOURCE)
 set('Name',DSnam)

 #Setting JNDI name
 cd(RESOURCE+'/JDBCDataSourceParams/'+DSnam)
 print RESOURCE+'/JDBCDataSourceParams/'+DSnam
 set('JNDINames',jarray.array([String(DSnam)], String))

 connPool(DSnam)

 #Set Connection Pool specific parameters
 cd(RESOURCE+'/JDBCConnectionPoolParams/'+DSnam)
 cmo.setTestConnectionsOnReserve(true)
 cmo.setTestTableName('SQL SELECT 1 FROM DUAL')
 cmo.setConnectionReserveTimeoutSeconds(25)
 cmo.setMaxCapacity(15)
 cmo.setConnectionReserveTimeoutSeconds(10)
 cmo.setTestFrequencySeconds(120)

 cd(RESOURCE+'/JDBCDataSourceParams/'+DSnam)
 cmo.setGlobalTransactionsProtocol('TwoPhaseCommit')
 cd('/JDBCSystemResources/'+DSnam)

 # targets the DS to Servers(Cluster or Server)
 targetType=raw_input('Target to (C)luster or (S)erver: ')
 if targetType in ('C','c') :
  clstrNam=raw_input('Cluster Name: ')
  set('Targets',jarray.array([ObjectName('com.bea:Name='+clstrNam+',Type=Cluster')], ObjectName))
 else:
  servr=raw_input('Server Name: ')
  set('Targets',jarray.array([ObjectName('com.bea:Name='+servr+',Type=Server')], ObjectName))

###############     Main Script   #####################################
if __name__== "main":
 print('This will enable you to create or update a Datasource')
 connectAdmin()
 edit()
 startEdit()
 # Create a new JDBC resource)
 cd('/')
 createDS()
 save()
 activate()
 disconnect()
####################################


You can configure as many as datasource but you need to provide the responding properties file. The base script will remain unchanged only the properties files will be varies when you move to different database environment.

Derby datasource using WLST on Weblogic 12.1.2

Here I have experimented the above datasource creation script with Apache Derby Database which is a default database part of Oracle WebLogic 12c. You don't need to run the database externally. When you run the WebLogic instance it automatically runs this Derby database instance.

The sample derby database properties are as follows:
DBURL= jdbc:derby://localhost:1527/demodbs
DBDRV=org.apache.derby.jdbc.ClientXADataSource
#oracle.jdbc.OracleDriver
DBPASS=welcome1
DBUSR=weblogic
DSName=myDs
CONUSR=weblogic
CONPWD=welcome1
CONURL=192.168.56.101:8100

Lets execute the script and see...
~/pybin$ wlst -loadProperties createDS.properties createDS.py

Initializing WebLogic Scripting Tool (WLST) ...

Welcome to WebLogic Server Administration Scripting Shell

Type help() for help on available commands

This will enable you to create or update a Datasource
Connecting to t3://192.168.56.101:56001 with userid weblogic ...
Successfully connected to Admin Server "demoadm" that belongs to domain "demodomain".

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.

Successfully connected
Location changed to edit tree. This is a writable tree with
DomainMBean as the root. To make changes you will need to start
an edit session via startEdit().

For more help, use help('edit')
You already have an edit session in progress and hence WLST will
continue with your edit session.

Starting an edit session ...
Started edit session, please be sure to save and activate your
changes once you are done.
Naming the datasource
/JDBCSystemResources/myDs/JDBCResource/myDs/JDBCDataSourceParams/myDs
Target to (C)luster or (S)erver: C
Cluster Name: clstr01
Saving all your changes ...
Saved all your changes successfully.
Activating all your changes, this may take a while ...
The edit lock associated with this edit session is released
once the activation is completed.
Activation completed
Disconnected from weblogic server: demoadm

Oracle Datasource using WLST

The customized properties file "configDS.properties" goes like this:
#==========================
# FileName : ConfigDS.properties
#==========================
DBURL=jdbc:oracle:thin:@dbhostname:dbport:dbschema
DBDRV=oracle.jdbc.OracleDriver
DBPASS=dbpasswd
DBUSR=dbuser
DSName=myDs
CONUSR=system
CONPWD=*********
CONURL=hostname:adminport

General WLST execution instructions


Now to execute the custom properties datasource script the command will be given as follows:
java weblogic.WLST –loadProperties ConfigDS.properties ConfigDS.py

Sunday, January 31, 2010

Configuring WorkManager using WLST


The WorkManager configuration can be possible only when you navigate on SelfTuning tree. After navigating with cding to SelfTuning MBean hierarcy. You can list out the SelfTuning tree that consists of the following branch trees, which are allowed us to created new MBeans using create command.
  1. ContextRequestClasses
  2. FairShareRequestClasses
  3. ResponseTimeRequestClasses
  4. Capacities
  5. MaxThreadsConstraints
  6. MinThreadsConstraints
  7. WorkManagers
WebLogic WorkManager Threadpool configurations
Here I am with few examples of my experiments with WorkManager and its constraints or Request Classess. To configure a new Global or Server instances wise or Cluster-wide Workmanager using online WLST you need to follow the below steps:

1. connect to the Administration Server.
2. switch to edit tree
3. configure a class or constraint for the WorkManager.
4. set the target as per your need to a server or to a cluster.
5. configure a new workmananger
6. navigate to the newly configured WorkManager MBean and set the constraint or class which created in the step 3.
7. target the workmanager to a server instance or to a cluster as per the need.
8. Save the changes and activate them.
9. While performing the above steps the script can throw WLST Exceptions such as BeanAlreadyExistsException handle them

We can configure a WorkManager and its related constraint or Request classes in two modes 1. online WLST 2. offline WLST The only difference here is targeting the WorkManger instance to a Server or a cluster, Online WLST requires
set('Targets',jarray.array([ObjectName('com.bea:Name=appClstr,Type=Cluster')], ObjectName))
set('Targets',jarray.array([ObjectName('com.bea:Name=app1,Type=Server')], ObjectName))

WLST MaxThreadsConstraints

Now let us see the example for configuring a MaxThreadsConstraints using Online WLSTHere we are going to set the Count value as per the need in the runtime for the MaxThreadConstraint. Better you can also chance to target to Server instance instead of Cluster.
#********************************************************************************
# Configure a WorkManager with  MaxThreadsConstrain
#********************************************************************************
from weblogic.descriptor import BeanAlreadyExistsException


try:
  connect('adminuser','adminpasswd','t3://adminHost:adminPort')
  
  edit()
  startEdit()
  c=input('Enter the Max Thread Count: ')
  mtc='MaxThreadsConstraint'+str(c)
  cd('/SelfTuning/wd1')
  cmo.createMaxThreadsConstraint(mtc)
  cd('/SelfTuning/wd1/MaxThreadsConstraints/'+mtc)
  cmo.setCount(c)
  set('Targets',jarray.array([ObjectName('com.bea:Name=appClstr,Type=Cluster')], ObjectName))
  cd('/SelfTuning/wd1')
  wm = cmo.createWorkManager('pwm1')
  cd('/SelfTuning/wd1/WorkManagers/pwm1')
  set('Targets',jarray.array([ObjectName('com.bea:Name=appClstr,Type=Cluster')], ObjectName))
  cmo.setMaxThreadsConstraint(getMBean('/SelfTuning/wd1/MaxThreadsConstraints/'+mtc))
  save()
  activate()
except (WLSTException, BeanAlreadyExistsException), e:
  print 'Error in script:', e
  cancelEdit('y')
else:
 disconnect()
 

Then the outcome looks like below:
wls:/offline> execfile('ConfigWM1.py')
Connecting to t3://adminHost:port with userid system ...
Successfully connected to Admin Server 'padmin' that belongs to domain 'wd1'.
...


You already have an edit session in progress and hence WLST will
continue with your edit session.

Starting an edit session ...
Started edit session, please be sure to save and activate your
changes once you are done.
Enter the Max Thread Count: 45
Saving all your changes ...
Saved all your changes successfully.
Activating all your changes, this may take a while ...
The edit lock associated with this edit session is released
once the activation is completed.
Activation completed
Disconnected from weblogic server: padmin

Capacity Constraint

Now let us see the example for configuring a capacity constraint using online WLST


#Capacity constraint
#********************************************************************************
from weblogic.descriptor import BeanAlreadyExistsException

try:
  # replace following values 
  connect('adminuser','adminpasswd','t3://adminHost:adminPort')
  edit()
  startEdit()
  cd('/SelfTuning/wd1')
  cmo.createCapacity('pcap2')
  cd('Capacities/pcap2')
  set('Count',10)
  set('Notes','This will set Capacity constraint')
  set('Targets',jarray.array([ObjectName('com.bea:Name=appClstr,Type=Cluster')], ObjectName))
  cd('/SelfTuning/wd1')
  wm = cmo.createWorkManager('pwm2')
  cd('/SelfTuning/wd1/WorkManagers/pwm2')
  set('Targets',jarray.array([ObjectName('com.bea:Name=appClstr,Type=Cluster')], ObjectName))
  cmo.setCapacity(getMBean('/SelfTuning/wd1/Capacities/pcap2'))
  save()
  activate()
except (WLSTException, BeanAlreadyExistsException), e:
  print 'Error in script:', e
  cancelEdit('y')
else:
 disconnect()

The output will be like this:
wls:/offline>  execfile('ConfigWM2.py')
Connecting to t3://adminHost:port with userid system ...
Successfully connected to Admin Server 'padmin' that belongs to domain 'wd1'.
....

Starting an edit session ...
Started edit session, please be sure to save and activate your
changes once you are done.
Saving all your changes ...
Saved all your changes successfully.
Activating all your changes, this may take a while ...
The edit lock associated with this edit session is released
once the activation is completed.
Activation completed
Disconnected from weblogic server: padmin
Double check your changes for WorkManager done success on Admin Console. Please write back your feedback and comments on this post... -->

Wednesday, January 27, 2010

WLST Offline vs WLST Online

Hey Middleware automation expert, Welcome to my Post. Working with WLST we have two different sections of commands available they are defined as: 1. Off-line WLST (default shell)
2. Online WLST mode (after connecting admin)

 

WLST Offline
The WLST offline configuration commands analogous to the Configuration Wizard. You just need to know the navigation on the WebLogic configuration MBean trees, modify the MBean attribute values. Internally this WLST offline commands works on WebLogic domain Configuration Framework, the Configuration Wizard also uses it.
Consistent results when using either tool read and write access to the configuration data that is persisted in the domain’s config directory or in a domain template JAR

These WLST offline commands intended to create a domain or modify a non-running domain. Used during WLS install to create samples domains

WLST Online
The WLST online commands are analogous to the Administration Console changes after connecting to admin server. WLST Online mode is a Java Management Extension (JMX) client it allow you to interact with in-memory runtime Management Beans (MBeans). In the online administrator intended use the runtime management tools: configuration,
management, deployment, monitoring.
When you use connect() command at offline it will transfer your prompt to ServerConfig that indicates online command mode. Where the commands will execute directly on running/ active resources.
The following table shows the major differences between
Offline, Online commands:

WLST Offline vs WLST Online


WLST Offline


WLST Online


1.WLST Offline commands can do:

a) Create/modify domain templates

b) Create domains

c) Extend an existing domains by access and modify the configuration for
an offline domain



2. WLST Offline mode commands can’t do:

a) View runtime performance data

b) Modify security data


1. WLST Online commands can do:

a) Change configuration when servers are in RUNNING state

b) View runtime data for monitoring various runtime MBeans performances

c) Deploy applications targeting to Servers or clusters

d) Start and stop servers or cluster members.



2. WLST Online commands can’t do the following:

a) Create a new domain (must be offline mode) you can only update an
existing domain configuration.


3. Default interactive mode will be in offline mode


3. The offline connect() command changes to online, disconnect() command
used to come back to offline. Mostly script mode is useful.


4. Configuring resources like JDBC, JMS can be assigned with assign()
command to targets.


4. Configuring resources required set command with Targets as argument and
committing the changes with save(), activate() commands.


5. The Offline commands are executed faster

5. Online commands are slower because they have to interact with live objects.

Earlier this table was big aquard to look now it reshaped with proper wraper, that overcome blogger table blanks issue.


Hope this table helped you!! Keep writing your feedback comments!!

Popular Posts