Search This Blog

Showing posts with label WebLogic. Show all posts
Showing posts with label WebLogic. Show all posts

Sunday, February 12, 2023

Server State using WLST

Hello! Dear Automation focused engineer we have this post about how to work simple server status list for a WebLogic domain. This logic can be build and executed for huge number of WebLogic or FMW Servers in Produciton helps to view all at a time hostnames, their corresponding states.   

Why we needWebLogic Server State? What all those states?

While trouble shooting Middleware/FMW administrator need to check the status of all the WebLogic server instances. This is the basic need when the all the servers are in bounced for production code move. This same script can be applicable for the pre-production or staging environment too. WLST provides the built-in methods, which gives the status of the Server instance or servers in a Cluster. Here we will deal with individual instance wise data.

WebLogic Server Life cycle state diagram

There are several ways to list out the servers. The simple way here you go with interactive way...
In the following example 
  1. We are collecting all the list of servers present in the WebLogic domain
  2. state function applied on each server as item  passed to it
  3. repeat this step 2 until all server list ends
 
wls:/demodomain/serverConfig> x=ls('Servers',returnMap='true')
dr--   demoadm
dr--   demoms1
dr--   demoms2

wls:/demodomain/serverConfig> x
[demoadm, demoms1, demoms2]
wls:/demodomain/serverConfig> for i in x:
... state(i,'Server')
...
Current state of "demoadm" : RUNNING
Current state of "demoms1" : SHUTDOWN
Current state of "demoms2" : SHUTDOWN

Cluster listing
wls:/demodomain/serverConfig> c=ls('Clusters',returnMap='true')
dr--   clstr01

wls:/demodomain/serverConfig> c
[clstr01]
wls:/demodomain/serverConfig> state(c[0],'Cluster')

There are 2 server(s) in cluster: clstr01

States of the servers are
demoms1---SHUTDOWN
demoms2---SHUTDOWN

ServerLIfecycleRuntime Mbean tree


Using above shown MBean hierarchy we can fetch the all WebLogic domain server instance's states. If your production WebLogic domain consists of two digit (eg. 60 instances) or three digit number (eg. 120 instances) of managed server then, it is difficult to see all server’s state at once. Weblogic Administration console is unable to show all the servers in the domain on a single page. Navigating in between also a time eating process so think! think better way!! WLST has the solution.

To get the status of all servers in the domain can be obtained with the following steps
  1. Connect to the WebLogic Admin Server
  2. Fetch the Managed server list from the domainRuntime MBean
  3. Iterate the loop and get the state of each Managed Server with ServerLifeCycle Runtime MBean
  4. Repeat if required the step 3 as per the user input to Continue...
  5. Finally if all desired output is visible then disconnect from the AdminServer and exit.

################################################## 
# This script is used to check the status of all WL instances including the admin
###########################################################

def conn():
    UCF='/path/.AdminScripts/userConfigFile.sec'
    UKF='/path/.AdminScripts/userKeyFile.sec'
    admurl = "t3://hostname:wlport"

    try:
        connect(userConfigFile=UCF, userKeyFile=UKF, url=admurl)
    except ConnectionException,e:
        print '\033[1;31m Unable to find admin server...\033[0m'
        exit()

def ServrState():
    print 'Fetching state of every WebLogic instance'
#Fetch the state of the every WebLogic instance
    for name in serverNames:
        cd("/ServerLifeCycleRuntimes/" + name.getName())
        serverState = cmo.getState()
        if serverState == "RUNNING":
            print 'Server ' + name.getName() + ' is :\033[1;32m' + serverState + '\033[0m'
        elif serverState == "STARTING":
            print 'Server ' + name.getName() + ' is :\033[1;33m' + serverState + '\033[0m'
        elif serverState == "UNKNOWN":
            print 'Server ' + name.getName() + ' is :\033[1;34m' + serverState + '\033[0m'
        else:
            print 'Server ' + name.getName() + ' is :\033[1;31m' + serverState + '\033[0m'
        quit()

def quit():
    print '\033[1;35mRe-Run the script HIT any key..\033[0m'
    Ans = raw_input("Are you sure Quit from WLST... (y/n)")
    if (Ans == 'y'):
        disconnect()
        stopRedirect()
        exit()
    else:
        ServrState()

if __name__== "main":
    redirect('./logs/Server.log', 'false')       
    conn()
    serverNames = cmo.getServers()
    domainRuntime()
    ServrState()

Smart Script

Recently I have online discussion with Dianyuan Wang, state of the Managed servers can be obtained with state() command. This function can be used in two ways: 
  • To get individual managed server status you need to pass arguments as managed server name, type as 'Server'. 
  • Other one is to get individual Cluster wise status. 
This can be achieved by passing two arguments cluster name and type as 'Cluster'. The following script will be illustrate the second option, which I found that shorten code that gives same script outcome as above script. It could be leverage your scripting thoughts it is like a plain vanilla form as shown below:

Note: Hope you follow the WLST Tricks & tips
try:
    connect(url = "t3://adminhostname:adminport")
except:
    print "Connection failed"
state('appclstr','Cluster')
state('web1clstr','Cluster')

...
state('webNclstr','Cluster')
-->

Extra Stroke of this new script is that prints how many servers available in each given cluster.

Server state with redirecting, re in WLST

Wang mailed me his situation clarity of explanation why he chosen state command. And how he resolved with Python script tricks here. Its a great learning for me so sharing with you when I saw same question in StackExchange today(28 April 2014) after 3 years!! "The reason I do not use (for now) domainConfig is because some how few Weblogic domains are not in a good state, and when I run the domainConfig command, it complains that it is not enabled. Hence the alternative way I've selected here is using state command. But it don't return the state. It always return None. But it prints out the state of the server. Here you go, Better way is capture that printing output to a file using WLST command redirect-stopRedirect and then, use the Python regular expression to extract the state of each server. The following is the Python snippet how I use the redirect:
 
# Fill your own connection details 
  serverlist=cmo.getServers()   
  for s in serverlist:   
    server_nm = s.getName()
    urldict[server_nm]='t3s://'+s.getListenAddress()+':'+str(s.getAdministrationPort())   
    #domainRuntime()
    #cd('ServerLifeCycleRuntimes/'+server_nm)
    fileName='/tmp/myserver_state.txt'
    redirect(fileName)
    state(server_nm,'Server')
    stopRedirect()
    f = open(fileName)
    try:
      for line in f.readlines():
        if re.search('Current state',line):
          status[server_nm]=line
    except:
      continue
 
  Ks = status.keys()
  for s in Ks:   
    if re.search('RUNNING',status[s]):
		try:
		connect(username,password,urldict[s])
		except:
		continue
		cd("/Servers/" + s)  


...
best regards! Dianyuan Wang

Here I request you please write back your experiencing with this posting looking ahead for your issues/ suggestions as comments.

Wednesday, August 31, 2022

JMS Module with ConnectionFactory and Queue configuration using WLST

After almost three and half years again revisited to the JMS module script. This time the project needs are quite different. Where the Oracle WebLogic domains classified environments  but they are standalone server domains. That is only AdminServer will be there in the domain and that would be target for the JMS module, JMS Destinations.



Lets begin the experimenting now, the prerequisites for this are:

  1. A WebLogic Domain configured with single AdminServer
  2. AdminServer should be up and RUNNING
  3. To execute the WLST script required PATH, alias should be defined in the profile as shown below:
  4. export MW_HOME=/u01/app/oracle/fmw
    export WL_HOME=$MW_HOME/wls/wlserver
    export USER_MEM_ARGS="-Djava.security.egd=file:/dev/./urandom"
    alias wlst="$MW_HOME/oracle_common/common/bin/wlst.sh -skipWLSModuleScanning"
    

    You can use this freshly created alias wlst at any directory to invoke WLST shell.  The option -skipWLSModuleScanning is easy, faster learnt while working on docker containers and simple way to use.

  5. Execute the configure JMS Servers
  6. The WLST Script for JMS configurations and all frequently changing values are moved into the properties file.


#========================================
# WLST Script purpose: Configuring JMS Module
# Author: Pavan Devarakonda
# Update date: 3rd Aug 2017
#========================================
from java.util import Properties
from java.io import FileInputStream
from java.io import File
from java.io import FileOutputStream
from java import io
from java.lang import Exception
from java.lang import Throwable
import os.path
import sys

envproperty=""
if (len(sys.argv) > 1):
        envproperty=sys.argv[1]
else:
        print "Environment Property file not specified"
        sys.exit(2)

propInputStream=FileInputStream(envproperty)
configProps=Properties()
configProps.load(propInputStream)

##########################################
# Create JMS Moudle will take the 
# arguments as name, subdeployment name
# target can be on admin or managed server or cluster
##########################################
def createJMSModule(jms_module_name, adm_name, subdeployment_name):
        cd('/JMSServers')
        jmssrvlist=ls(returnMap='true')
        print jmssrvlist
        cd('/')
        module = create(jms_module_name, "JMSSystemResource")
        #cluster = getMBean("Clusters/"+cluster_target_name)
        #module.addTarget(cluster)
        #adm_name=get('AdminServerName')
        adm=getMBean("Servers/"+adm_name)
        module.addTarget(adm)
        cd('/SystemResources/'+jms_module_name)

        module.createSubDeployment(subdeployment_name)
        cd('/SystemResources/'+jms_module_name+'/SubDeployments/'+subdeployment_name)
        list=[]
        for j in jmssrvlist:
                s='com.bea:Name='+j+',Type=JMSServer'
                list.append(ObjectName(str(s)))
        set('Targets',jarray.array(list, ObjectName))


def getJMSModulePath(jms_module_name):
        jms_module_path = "/JMSSystemResources/"+jms_module_name+"/JMSResource/"+jms_module_name
        return jms_module_path

def createJMSTEMP(jms_module_name,jms_temp_name):
        jms_module_path= getJMSModulePath(jms_module_name)
        cd(jms_module_path)
        cmo.createTemplate(jms_temp_name)
        cd(jms_module_path+'/Templates/'+jms_temp_name)
        cmo.setMaximumMessageSize(20)

##########################################
# JMS Queu configuration function 
# arguments are : JMS module name, Queue jndiname
# Queue name, jndi name hu
##########################################
def createJMSQ(jms_module_name,jndi,jms_queue_name):
        jms_module_path = getJMSModulePath(jms_module_name)
        cd(jms_module_path)
        cmo.createQueue(jms_queue_name)
        cd(jms_module_path+'/Queues/'+jms_queue_name)
        cmo.setJNDIName(jndi)
        cmo.setSubDeploymentName(subdeployment_name)

adminUser=configProps.get("adminUser")
adminPassword=configProps.get("adminPassword")
adminURL=configProps.get("adminURL")

connect(adminUser,adminPassword,adminURL)
#adm_name=get('AdminServerName')
adm_name=ls('Servers',returnMap='true')[0]
print adm_name
edit()
startEdit()

##########################################
#   JMS CONFIGURATION## 
##########################################
total_conf=configProps.get("total_conf")
tot_djmsm=configProps.get("total_default_jms_module")
#subdeployment_name=configProps.get("subdeployment_name")

a=1
while(a <= int(tot_djmsm)):
        i=int(a)
        jms_mod_name=configProps.get("jms_mod_name"+ str(i))
        #cluster=configProps.get("jms_mod_target"+ str(i))
        subdeployment_name=configProps.get("subdeployment_name"+ str(i))
        createJMSModule(jms_mod_name,adm_name,subdeployment_name)
        total_q=configProps.get("total_queue"+str(i))
        j=1
        while(j <= int(total_q)):
                queue_name=configProps.get("queue_name"+ str(i)+str(j))
                queue_jndi=configProps.get("queue_jndi"+ str(i)+str(j))
                createJMSQ(jms_mod_name,queue_jndi,queue_name)
                j = j + 1
        i=i+1
        a = a+1
save()
activate(block="true")
disconnect() 


Now see this is a sample of properties file that could help you to build the JMS Module, be read by the WLST script at the run time:
###################################################
# JMS SUBDEPLOY CONFIGURATION
###################################################
total_subdply=2
total_default_jms_module=2
total_conf=0
subdeployment_name1=DemoJMSFAServer1
subdeployment_name2=DemoJMSFAServer2

###################################################
# JMS MODULE CONFIGURATION
###################################################
jms_mod_name1=Demo-SystemModule1
jms_mod_name2=Demo-SystemModule2

###################################################
# JMS CONNECTION FACTORY CONFIGURATION
###################################################
conf_jndi1=demoCF
conf_name1=jms/demoCF

###################################################
#   JMS QUEUE CONFIGURATION
###################################################

total_queue1=2
queue_name11=Q1
queue_jndi11=Q1

queue_name12= BQ1
queue_jndi12= BQ1


total_queue2=2
queue_name21=Q2
queue_jndi21=Q2

queue_name22= BQ2
queue_jndi22= BQ2

#========== ADMIN DETAILS =========================
adminUser=weblogic
adminPassword=welcome1
adminURL=t3://192.168.33.100:8100
output
$ wlst jms_module.py jms_module.properties

let's see what happen when you apply this logic on your project? Did you notice any errors? Please write back 🔙 with your error screen shot. 

How do you know everything went well? Open the WebLogic Administration console to check the JMS Module Configuration has successfully created a new JMS resource or not.

You may be intrested to learn more WLST scripting for JMS you can also visit the Uniform Distributed Queue configuration post. Thanks for being with us in this post, Please write to us your errors and exceptions when you run this script.

Saturday, August 14, 2021

How to include modules and Java Options in WLST Shell?

In recent developments in the Python impacting WLST Shell as well. We might want to use Python module into our WLST scripts as well. Sometimes you need a Python module that is available for Python Community same we may use in your WLST, and sometimes you might need some JAVA_OPTIONS must be included before the WLST shell is launched.

Here I will walk you through some scenarios where you need to customize.
  1. When there is customization in WebLogic domains such as Oracle Utilities products uses the SSL enable communication for their AdminServer - Managed servers
  2. WLST shell using a connection to AdminServer with t3s protocol
  3. WebLogic domain for Oracle Data Integrator uses WLST when a managed server used to stop with 'stopManagedWebLogic.sh' or even AdminServer using 'stopWebLogic.sh' script calls WLST scripts to stop and when there is SSL enabled for the security purpose then WLST shell interaction requires SSL configuration details

How to include the Python module in WLST?

This could be a common requirement when automation scripts needs multiple Python modules into their WLST Shell.

Better you can add to your profile script. I've added the following lines to the .bashrc profile script.
alias wlst="$WL_HOME/../oracle_common/common/bin/wlst.sh"
export CONFIG_JVM_ARGS="-Djava.security.egd=file:/dev/./urandom \
-Dweblogic.security.SSL.enableJSSE=true \
-Dweblogic.security.SSL.ignoreHostnameVerification=true \
-Dweblogic.security.TrustKeyStore=DemoTrust \
-Dweblogic.security.CustomTrustKeyStoreType=JKS"

Note here if you are using Demo certificates then you can use the above. But if you have custom certificates then you need to provide Custom Certificates location. 

How you can tune or optimize your WLST Shell launching time?


In your .bashrc or bash_profile you can include the following environment variable which will boost-up or speed up your JVM launching time.
export CONFIG_JVM_ARGS=-Djava.security.egd=file:/dev/./urandom

Configuring FMW domains we expected more with CONFIG_JVM_ARG

export CONFIG_JVM_ARGS=-Dcom.oracle.cie.config.showProfile=true
This will enable the option in the configuration type screen to create a new compact SOA/OSB domain or any FMW 12+ domain. Without -Dcom.oracle.cie.config.showProfile=true FMW Domain creation will not show the Embedded Database option for Database configuration type in the Wizard.

Thursday, January 31, 2013

JMS Module Uniform Distributed Queue using WLST


This post is continous series of JMS configurations experimenting with Python. Here the JMS module configuration changes for the JMS will be stored to config.xml repository and its sub-deployment module descriptor in a separate file. JMS system module can be defined with name, target to servers or cluster, its related sub-deployments such as Queue or publisher/Subscriber topics.

The WebLogic JMS related Mbeans are constructed as follows :
  • JMSBean
  • JMSSystemReourceMBean
  • QueueBean
  • JMSConnectionFactoryBean
  • DistributedQueueBean
  • UniformDistributedQueueBean
  • SubdeploymentMBean

While configuring you need to understand that JMS system module, that consists of ConnectionFactory that give access to the JMS services, and there could be a different scenario on demand. The machines are high-powered, low powered are in the same cluster then JMS destinations must be distributed destinations with ‘Allocate members Uniformly’ option set to false and manually select more physical destination from the high powered machines.The configuring JMS module is going to have various sub-deployment components in it. First we need to configure the JMS Module name, target to the advanced deployment as sub-deployment. 


Now you need brainstrom, and provide your customized domain with JMS module details in the properties file, let me give you sample :
############################################################################### 
# JMS MODULE CONFIGURATION
############################################################################### 
total_default_jms_module=1
jms_mod_name1=jmsSystemModule
jms_mod_target1=my_cluster

Subdeployment in JMS Module

Most of the Admins not really aware of the use of subdeployment. We need to configure a subdeployment per JMS Module. While configuring the subdeployment we have to provide the target as JMS servers which are configured in the first section. Why we need a subdeployment is interesting topic  • To avoid network traffic between JMS components communication • It will group Connection factories, queues, topics

 • Easy to migrate
WebLogic - JMS Module configuration using WLST

###############################################################################
# JMS SUBDEPLOY CONFIGURATION
###############################################################################
total_subdply=1
subdeployment_name=aJmssub

JMS Connection Factory

We have configured the ConnectionFactory properties as follows
###############################################################################
# JMS CONNECTION FACTORY CONFIGURATION
##########
conf_jndi1=myConnectionFactory
conf_name1=MyConnectionFactory
Configuring Uniform distributed queue using WLST We have configured the Queue with Distributed option because we have multiple JMS providers. The Uniform Distributed Queue is the one of the best practice when you have Clustered WebLogic Domain. While configuring this you need a name for the Uniform Distributed Queue and a JNDI name for it.
###############################################################################
#   UNIFORM DISTRIBUTED QUEUE CONFIGURATION
###############################################################################
total_udq=3
udq_name1=jmsIncomingChannel
udq_jndi1=jms/incoming/response
The JMS Module configuration with Subdeployment target to JMS Servers configured earlier. ConnectionFactory, Uniform Distributed Queue target to subdeployment.
from java.util import Properties
from java.io import FileInputStream
from java.io import File
from java.io import FileOutputStream
from java import io
from java.lang import Exception
from java.lang import Throwable
import os.path
import sys

envproperty=""
if (len(sys.argv) > 1):
        envproperty=sys.argv[1]
else:
        print "Environment Property file not specified"
        sys.exit(2)
propInputStream=FileInputStream(envproperty)
configProps=Properties()
configProps.load(propInputStream)

def createJMSModule(jms_module_name,cluster_target_name):
        cd('/JMSServers')
        jmssrvlist=ls(returnMap='true')
       # jmssrvlist=['AjmsServer1','AjmsServer2']
        cd('/')
        module = create(jms_module_name, "JMSSystemResource")
        cluster = getMBean("Clusters/"+cluster_target_name)
        module.addTarget(cluster)
        cd('/SystemResources/'+jms_module_name)

        module.createSubDeployment(subdeployment_name)
        cd('/SystemResources/'+jms_module_name+'/SubDeployments/'+subdeployment_name)
        list=[]
        for j in jmssrvlist:
                s='com.bea:Name='+j+',Type=JMSServer'
                list.append(ObjectName(str(s)))
        set('Targets',jarray.array(list, ObjectName))


def getJMSModulePath(jms_module_name):
        jms_module_path = "/JMSSystemResources/"+jms_module_name+"/JMSResource/"+jms_module_name
        return jms_module_path

def createJMSTEMP(jms_module_name,jms_temp_name):
        jms_module_path= getJMSModulePath(jms_module_name)
        cd(jms_module_path)
        cmo.createTemplate(jms_temp_name)
        cd(jms_module_path+'/Templates/'+jms_temp_name)
        cmo.setMaximumMessageSize(20)

def createJMSUDQ(jms_module_name,jndi,jms_udq_name):
        jms_module_path = getJMSModulePath(jms_module_name)
        cd(jms_module_path)
        cmo.createUniformDistributedQueue(jms_udq_name)
        cd(jms_module_path+'/UniformDistributedQueues/'+jms_udq_name)
        cmo.setJNDIName(jndi)
    #    cmo.setDefaultTargetingEnabled(bool("true"))
        cmo.setSubDeploymentName(subdeployment_name)

def createJMSConnectionFactory(jms_module_name,cfjndi,jms_cf_name):
        jms_module_path = getJMSModulePath(jms_module_name)
        cd(jms_module_path)
        cf = create(jms_cf_name,'ConnectionFactory')
        jms_cf_path = jms_module_path+'/ConnectionFactories/'+jms_cf_name
        cd(jms_cf_path)
        cf.setJNDIName(cfjndi)
        cd (jms_cf_path+'/SecurityParams/'+jms_cf_name)
        #cf.setAttachJMXUserId(bool("false"))
        cd(jms_cf_path+'/ClientParams/'+jms_cf_name)
        cmo.setClientIdPolicy('Restricted')
        cmo.setSubscriptionSharingPolicy('Exclusive')
        cmo.setMessagesMaximum(10)
        cd(jms_cf_path+'/TransactionParams/'+jms_cf_name)
        #cmo.setXAConnectionFactory(bool("true"))
        cd(jms_cf_path)
        cmo.setDefaultTargetingEnabled(bool("true"))

adminUser=configProps.get("adminUser")
adminPassword=configProps.get("adminPassword")
adminURL=configProps.get("adminURL")

connect(adminUser,adminPassword,adminURL)

edit()
startEdit()

 # ====# JMS CONFIGURATION## ##########################################
total_temp=configProps.get("total_temp")
total_udq=configProps.get("total_udq")
total_conf=configProps.get("total_conf")
tot_djmsm=configProps.get("total_default_jms_module")
subdeployment_name=configProps.get("subdeployment_name")

a=1
while(a <= int(tot_djmsm)):
        var1=int(a)
        jms_mod_name=configProps.get("jms_mod_name"+ str(var1))
        cluster=configProps.get("jms_mod_target"+ str(var1))
        createJMSModule(jms_mod_name,cluster)
        i=1

        while(i <= int(total_temp)):
                t_name=configProps.get("temp_name"+ str(i))
                createJMSTEMP(jms_mod_name,t_name)
                i = i + 1

        j=1
        while(j <= int(total_udq)):
                udq_name=configProps.get("udq_name"+ str(j))
                udq_jndi=configProps.get("udq_jndi"+ str(j))
                createJMSUDQ(jms_mod_name,udq_jndi,udq_name)
                j = j + 1
        k = 1
        while(k <= int(total_conf)):
                conf_name=configProps.get("conf_name"+ str(k))
                conf_jndi=configProps.get("conf_jndi"+ str(k))
                createJMSConnectionFactory(jms_mod_name,conf_jndi,conf_name)
                k = k + 1
        a = a+1

save()
activate(block="true")
disconnect()
############################################################

The sample properties listed for helping out how to create here for your projects.
###############################################################################
# JMS SUBDEPLOY CONFIGURATION
###############################################################################
total_subdply=1
total_default_jms_module=1
total_conf=1
subdeployment_name=demoSub

###############################################################################
# JMS CONNECTION FACTORY CONFIGURATION
######################################################
conf_jndi1=demoCF
conf_name1=jms/demoCF

###############################################################################
#   UNIFORM DISTRIBUTED QUEUE CONFIGURATION
###############################################################################
 

total_temp=0
total_udq=2
udq_name1=jmsIncomingChannel
udq_jndi1=jms/incoming/response
temp_name1=jmsIncomingChannel1

udq_name2=jmsOutgoingChannel
udq_jndi2=jms/outgoing/response
temp_name2=jmsOutgoingChannel1

adminUser=weblogic
adminPassword=welcome1
adminURL=t3://192.168.1.106:8100
###############################################################################
# JMS MODULE CONFIGURATION
###############################################################################
total_default_jms_module=1
jms_mod_name1=demo_jmsmod
jms_mod_target1=democlstr

To execute this JMS Module with subdeployments you need to pass the properties file as argument
java weblogic.WLST jms_module.py jms_module.properties
pavanbsd@ubuntu:~/pybin$ wlst jmsmodnq.py jmsmodnq.properties

Initializing WebLogic Scripting Tool (WLST) ...

Welcome to WebLogic Server Administration Scripting Shell

Type help() for help on available commands

Connecting to t3://192.168.1.106:8100 with userid weblogic ...
Successfully connected to Admin Server "demoadmin" 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.

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.
drw-   jms_ms1
drw-   jms_ms2

MBean type JMSSystemResource with name demo_jmsmod has been created successfully.
MBean type ConnectionFactory with name jms/demoCF has been created successfully.
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: demoadmin

Keep writing back 🔙 your error screen shot comments and suggestions on this post. Keep smiling cheers!! 

Sunday, June 10, 2012

JDBC Monitoring

JDBC Monitoring with LWLST script
One fine morning we (WLA support Team) got an assignment, The summary of the assignment was to find "How the WebLogic server instance performing for a DataSource?". WebLogic 9.x onwards a DataSource is associated with a ConnectionPool (a pool of connections to the DB). If we monitor ConnectionPool, inturn it is nothing but monitoring a DataSource.

Of-course the task is not that easy, I have gone through various WebLogic forums to find a appropriate solution for this task.

Oracle WebLogic provides two ways to Monitor a Datasource
1. Monitoring Datasource server wise
2. Testing the Connection Pool

Here I am publishing the same script which Madan Noru/Satya prepared in the old bea fourms or ObjectMix forums. Only one thing is difference is that displaying pattern, I had created a separate header, so that output looks good to see in a table form. To make this possible I have used C-Style print command from Python Language. This format you can change as per your screen display size.

The script will retrieve the JDBC Connection Pool MBean using adminHome, which is deprecated object in WLST. The output of the script will gives you the values of the following attributes:
  • DataSource Name
  • Maximum Capacity of the Connection Pool at Run-time
  • Active Connections Current Count
  • Active Connections High Count
  • Wait Seconds High Count
  • Waiting For Connection Current Count
  • State of the Connection Pool

#=======================================================
# This script will monitor the JDBC CONNECTION POOL
# more details on this script contact: Pavan Devarkonda
#=======================================================
connect("username","passwd","t3://AdminIP:AdminPort")
try:
 poolrtlist=adminHome.getMBeansByType('JDBCConnectionPoolRuntime')
 print ' '
 print ' '
 print 'JDBC CONNECTION POOLS'
 print ' '
 print 'Name Max Active Active WaitSecs Waiting State'
 print ' capacity Current HighCnt HighCnt Count'

 for poolRT in poolrtlist:
  pname = poolRT.getName()
  pmaxcapacity = poolRT.getAttribute("MaxCapacity")
  paccc = poolRT.getAttribute("ActiveConnectionsCurrentCount")
  pachc = poolRT.getAttribute("ActiveConnectionsHighCount")
  pwshc = poolRT.getAttribute("WaitSecondsHighCount")
  pwfccc = poolRT.getAttribute("WaitingForConnectionCurrentCount")
  pstate = poolRT.getAttribute("State")
  print '%10s %7d %7d %7d %7d %7d %10s' % (pname,pmaxcapacity,paccc,pachc, pwshc,pwfccc,pstate)
  print ' '
except:
  print 'Error:'
  dumpStack()
  pass
disconnect()

In Year 2012 revisting the same script

We have trouble in the produciton environment with JDBC Connection pool overloaded. All the ActiveConnectionCount reaching the MaxCapacity of the Connection pool. As a temprory workaround we need to reset the Connection pool for that movement. Permanent cure is tuning the Connection pool. For both solutions we need active monitoring the JDBC Connection pool.
To monitor this we have revisited the same script. Now adding more saus to the script we need to find that ActiveConnectionCount reaching 85% as threshold limit. Once it reaches 85 or greater then monitoring tool like HP OV/some other tool will reads log file generated by the script and then sends warns message to supporting Middleware Admin when threshold crossed. If you have sendmail service on your machine you can send message fromt he script itself.
To do this we had manupulated the above script according to the requirements
  1. We have specified DataSource that are causing this trouble
  2. Used separate properties file for user credentials.
  3. The output of script is redirected to a file
  4. Managed Server name opposite to the monitor values it is tricky but resolved The new script is

#=======================================================
# This script will monitor the JDBC CONNECTION POOL
# Date :  18 Apr 2012
#=======================================================
import sys
import time
try:
        loadProperties('./DBcheck.properties')
        fp=open('ActiveConn.log','a+')
        Date = time.ctime(time.time())
        admurl='t3://'+admAdrs+':'+admPort
        connect(userConfigFile=UCF, userKeyFile=UKEY, url=admurl)
        poolrtlist=adminHome.getMBeansByType('JDBCConnectionPoolRuntime')
        print ' '
        print 'JDBC CONNECTION POOLS'
        print>>fp, '================================================ '

 for poolRT in poolrtlist:
                pname = poolRT.getName()
                pmaxcapacity = poolRT.getAttribute("MaxCapacity")
                paccc = poolRT.getAttribute("ActiveConnectionsCurrentCount")
        
  if pname == 'myDataSource1' or pname == 'myDS2'' or pname == 'myDS3':
                        server= str(poolRT).split(',')[2].split('=')[1]
                        p=(paccc /(pmaxcapacity * 1.0)) * 100 
                        if p >= 85:
                                print >>fp, 'WARNING: The Active connections are Greater than Threshold 85%'
                        print>>fp, '%24s %15s %18s %7d %7d' % (Date,server,pname,pmaxcapacity,paccc)

except Exception, e:
        sys.stderr.write('ERROR: %s\n' % str(e))
        print 'Error:', e
        dumpStack()
        pass
fp.close()
disconnect()


-->

Post script actions

  1. Prepare a Shellscript that will let you know howmuch time it will counsume to run py script.
    clear
    date
    $JAVA_HOME/bin/java weblogic.WLST /path/urscript/jdbcmon.py
    date
    
  2. Schedule a scheduler to run this script autosys or crontab that invokes above shell script.
  3. Configure a monitoring tool frequently lookup the logs and send alert messages such as HP OVO or smpt mailing also fine.
What do you think about this new version of script? Write back your comments and suggestions to deliver better. Refernce Object Mix discussion:
http://objectmix.com/weblogic/549153-weblogic-monitoring-script-wlst-2.html -->

Sunday, March 20, 2011

WLST Tricks & Tips

Here I prepared few of the "Tips" and some commonly useful "Tricks" for developing the huge WLST scripts. These are all the learnings which I have came across in my daily working experiments with Programming Python commands for WLST scripts. These WLST commands can be applicable from WebLogic 9.x to WebLogic 10.3.6 and latest trending WebLogic 12c as well.
  1. Tip 1: Know about Where are you in WLST?


  2. On some situations you might need a clarity about which WebLogic version you are using. WebLogic 11g (10.3) has different subsequent versions 10.3.1,10.3.2,10.3.3 and 10.3.4, for all these the directory structure is ~/Oracle/Middleware/wlserver_10.3 which does not tells you about sub versions. Here WLST  is having a solution for this problem,

    You can find the current WebLogic version to which WLST is connected.

    wls:/offline> print version
    WebLogic Server 10.3.3.0  Fri Apr 9 00:05:28 PDT 2010 1321401
    

    How do you know that the WLST Shell running on which JVM version? The simple solution is you this following Python command that will gives you:

    wls:/offline> sys.platform
    'java1.6.0_21'

  3. Tip 2. How to know Jython version is used by WLST?


  4. To get the Jython version you can use sys.version_info method that will returns. or you can use sys.version exact version.

    wls:/offline> import sys
    wls:/offline> sys.version_info
    (2, 2, 1, 'final', 0)
    
    

    Tip 3. Introspection in WLST


    You might understand that using WLST provided help() sometimes you cannot reach your desired level of script code. Some thing that won't be documented but you might need it to develop the prototype in your WLST script. Often I found this could be a need, most helpful way to reach depth of WLST classes, modules, functions. Best way is we need to use Python introspection methods. It is a wonderful way to resolve your coding clues to use best performing script as outcome.

    In some of the situations, I felt using Jython (Java method) is lengthy than using Python. When Python giving you desired outcome in two lines of code why do you choose Java imports and classes and code become 6-10 lines.

    You might be confused sometimes, brain storm about something why a MBean not working or giving the value of an attribute etc. In your mind there could be a question "what is this actually??" Best solution for this is using Python introspection built-in methods.

    dir([WLST/Python Object])
    
    
    If your WLST MBean or module or a function has documented then you use the following to get that:
    _doc__
    

    In Jython there could be classes or interfaces
    __class__
    

    Tip 4. Naming Rules for WLST


    WLST script can have names are case sensitive and cannot start with a number.  They can contain letters, numbers, and underscore symbols. Let us see few examples here:
     state  State  _state  _2_state_  state_2  StatE

    Most of us face an issue what name makes sense for a variable, module or classwhile writing the WLST scripts. Just like Java Language you can follow specific naming rules, we can also find keyword list available in WLST with the following commands

    wls:/offline> import keyword
    wls:/offline> keyword.kwlist
    ['and', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'exec', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'not', 'or', 'pass', 'print', 'raise', 'return', 'try', 'while', 'yield']
    

    Modules, packages: use lowercase
    Classes: use Capitalized first letters in the Words also follow for exceptions that you create
    Methods, attributes: use lowercase_words
    Local variables: use alphanumeric i, j, sum, x0, etc.
    Globals: use alphanumeric long_descriptive_names

    wls:/offline> sys.modules
    {'weblogic.store.admintool.CommandDefs.CommandType': , ...'sys': sys module, 'weblogic.management.scripting.utils': }
    
    
    
    

    Introspection reveals useful information about your program's objects

    Tip 4 Write a readable script


    While writing a script think about the human readers, Question yourself can you still read your own code ???
    next month?
    next year?
    • Be consistent (but not too consistent!)
    • Use white-space judiciously
    • Write appropriate comments
    • Write helpful doc strings -- not stories or novels
    • Confirm to the existing style even if it’s not your favorite style!
    • local consistency overrides global
    • Update the comments!!and the doc strings!!!

    """Brief one-line description.
    
    Longer description, documenting
    argument values, defaults,
    return values, and exceptions.
    """
    

    When to use classes in WLST? (...and when not!)
    If your script objective is going to have multiple object creation then go for Object-Orientation.

      • You could choose class members or attribute  at the first time
      • name clashes between attribute

    Tip 5 Convene print statement with str()


Most of us from Java/JEE development background common attitude is that using the + operator overloading for strings. Sometimes your WLST script might need to have a print statement, that could include values from a variable or some mathematical expression that might be int type or some other object type. Then such cases, better to use that variable type must be converted to string type by using Python built-in function str() as shown :

print 'Heap Size' + str(totalHeap)

Tip 6: Create single properties file

Every Middleware admin whoever uses this WLST in their environment builds, they must create/use a single properties file where you can have:

  1. Domain properties - username, password, admin url, cluster list
  2. Database configuration properties
  3. JMS configuration properties
  4. WorkManager properties
  5. Monitoring Threshold properties

Tip 7: Using time in WLST


In my daily news updates from social medias I found in reddit.com in the Python community doing excellent there is lots of news about the changes happening with Python programming. One of the blog found very nice examples with date and time functions in Python this can be applicable for our WLST too.

Setting UTC time zone in Python

WLST Tricks


We have come across many situations where it is simple trick works faster to work with WLST scripting. some of them collected here and future also we will update this WLST tricks

Trick 1. Multiple Assignment

In WLST you can assign multiple variables with corresponding multiple values at the same statement or command line.

wls:/offline> cl, ms = ['appclstr','webclstr'], ['app01','app02','web01','web02']
wls:/offline> cl
['appclstr', 'webclstr']
wls:/offline> ms
['app01', 'app02', 'web01', 'web02']


Trick 2. Connect admin without Credentials

When you use storeUserConfig() command for your WebLogic domain environment, the trick here is when you don't specifying any arguments such as user security file, key file paths. WebLogic system automatically generates the following two files:
1. username-WebLogicConfig.properties
2. username-WebLogicKey.properties

For example, Let us assume your user name is 'padmin' then storeUserConfig() command will generates two files as:
* padmin-WebLogicConfig.properties
* padmin-WebLogicKey.properties

Once you got this auto-generated files in you home ($HOME in Unix) directory, WLST Shell automatically detects its existance from this location. You don't need to give the userConfig, Key file paths while connecting. Simply you can connect by giving the adminurl as url value.

wls:/offline> connect(url='t3://myapp.host.com:8756')
Connecting to t3://myapp.host.com:8756 with userid weblogic ...
Successfully connected to Admin Server 'wadmn' that belongs to domain 'mydomain'.

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.

Trick 3: Command Trials

The interactive mode is great for getting instant feedback on the behavior of each WLST command. Having the whole startup, connection, session-init is time-consuming and the interactive mode of WLST avoids this.

First time if you are making a script better idea is have duplicate windows of the host. In one window you can edit and save according to your required changes, on the other hand you can execute the file with execfile('urScript.py').

Trick 4: Using loadProperties

One of my blog follower Raghu asked me how to use properties in the WLST script. Though I had used different types of properties from properties file, but his requirement is something different he want to reuse the WLST script only by changing the properties file.

cat mys.properties
SERVERS=myser1,myser2,myser3
ADMINSERVER=demoAdmin


Here is the WLST script snippet that uses above defined properties using loadProperties() built-in function call
loadProperties('path/mys.properties')
print SERVERS
serverlsit=SERVERS.split(',')
print serverlist[1]

for i in serverlist:
    print i

Remember that properties are just like Java language properties or C/C++ define constants, which holds name, and corresponding the string values. So when you store portno in properties file better convert using int().
Hope this is useful for your reusable scripts.

Trick 5: How to debug WLST script?

The best way to identify the WLST script bugs using dumpStack(). This works only when you are running interactive mode. If you found a script (such as my blog) or from somewhere after you update all properties you wish to test and it doesn't works! then you wish to debug it.

1. Using simple print variable values
2. Using Python exception values
3. Double check indentations
4. Casting values (converting values str to int or str to bool)

Some of the cases you need to understand that casting fails the values are not allowed to change because WLST variables are created in Runtime. The datatypes are strong type like Java and C++ languages and dynamic type while running it will be assigned to a datatype.

You can enable debug flag at the time of invocation of WLST shell.

java -Dpython.verbose=debug weblogic.WLST

Also you have one more option using debug("true") or set('DebugEnabled', 'true') in the starting of WLST script that will force debug output

If you are using OEPE (Eclipse for developing WLST) then you have much scope to debug every variable content. Right click on the WLST script select 'Debug As', choose 'WLST run' from the list Menu. Please check the screenshot that give you more clear idea on this Oracle link.

Trick Cancel the Edit in WLST

Today while working on WLST in interactive mode to fix the JMS configuration issue, sometime you start editing the configuration you might need to undo the changes you did on the edit tree. This is possible using cancelEdit() give the answer y to confirm when it prompts you. Else you can use cancelEdit('y') as a trick.

Trick 6: Suppress Junk Output in WLST

There is junk when you capture the list from ls(returnMap='true') command execution.
If you are running WLST in *nix based environment you can use /dev/null path for suppressing the junk outputs as shown below redirect command.

redirect('/dev/null','false')
ls()
redirect('/dev/null','true')


Trick 7: Resolve indentation/dedent issue with vi setting


WLST Code copied from NotePad++ to vi editor tabspace issue
when you write few lines in the notepad++ it takes 4 spaces as tabspace, but in the vi editor it is 8 it mismatches and cannot fit into the block. So when run the script it throws 'dedent' issue. To resolve this in vi editor you can set the tabspace=4

: set tabspace=4

Keep writing your valuable comments and great suggestions to improve this blog tutorial ...

References:
  1. 1. Dive into Python
  2. Python Library link
  3. http://forums.oracle.com/forums/thread.jspa?messageID=9416182&tstart=0

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

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

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, April 22, 2009

JVM Monitoring with WLST

Hey dear WLAs, here I am with a new assignment for JVM monitoring. The fresh production environment setup with Clustered Domain with multiple physical locations with multiple UNIX machines.

The WebLogic capacity planning going on and various low memory or OutOfMemory issues araising when new migration happen from WebLogic 8.1 to 9.2 MP3. To identity how the Garbage Collection working? How much free memory is available for each instance? This can be known with JVM statistics, which inturn tuning the JVM parameters or reset is easy for decide.

I had found a JVM monitoring script that is best suites to my WebLogic environment.

This script is able to get all server instances JVM statistics with a single run. The beauty of WLST is that it runs on single JVM and provides us the required output with the help of domain, server Runtime MBeans, which are supported by WebLogic 9.x and later releases by default supporting JMX 1.2, which has many good features to control and monitor the Runtime Environment of a WebLogic Server instance.


Here have the script which I have modified as per my task there is little C-style customization done with Python language syntax. I mean in Jython which actally used in the WLST.


This could be further refined but ... short of time I am pubishing this
Enjoy!!! Jython/WLST SCRIPTING

#You can create key files
ucf='keypath/xuserconfig.key'
ukf='keypath/xkeyfile.key'
admurl = "t3://hostingdns.com:port"

# This module is for retrieve the JVM statistics
def monitorJVMHeapSize():
     connect(userConfigFile=ucf, userKeyFile=ukf, url=admurl)
     # alternate connect('user', 'passwd', 'adminurl')
     serverNames = getRunningServerNames()
     domainRuntime()

     print '                TotalJVM  FreeJVM  Used JVM' 
     print '=============================================='
     for name in serverNames:
   try:
    cd("/ServerRuntimes/"+name.getName()+"/JVMRuntime/"+name.getName())
    freejvm = int(get('HeapFreeCurrent'))/(1024*1024)
    totaljvm = int(get('HeapSizeCurrent'))/(1024*1024)
    usedjvm = (totaljvm - freejvm)
    print '%14s  %4d MB   %4d MB   %4d MB ' %  (name.getName(),totaljvm, freejvm, usedjvm)
   except WLSTException,e:
     pass

# This module for managed Servers list
def getRunningServerNames():
     domainConfig()
     return cmo.getServers()
 
if __name__== "main":
     monitorJVMHeapSize()
     disconnect()

Here in this program you can add more functionality with getting the HeapFreePercent. It is just a variable assigned with get('HeapFreePercent') . Later, You can print that variable value.

Popular Posts