Friday 24 January 2014

Shell script to create Multiple Queues at a time in a Domain.

blogger
                                Shell script to create Multiple Queues at a time in a Domain.

Hello to viewer,

Here is script that will help in creation of multiple queues at a time and will surely save an extra effort and time.

Benefit: It will avoid one by one creation of distributed queues from admin console and allow creation of multiple queue in one go just by executing a shell script.

You need to follow the below steps:

Note: Change the of wlhome, username, password and url according to your Environment.

Step1) Create a directory :

cd /shared/fmw/build/myscript/newscripts/createQueue

Step 2) Create the createQueues.sh file under the current directory location with below content:

#!/bin/sh

# set up WL_HOME, the root directory of your WebLogic installation
WL_HOME="wlhome"

umask 027

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

CLASSPATH="${CLASSPATH}${CLASSPATHSEP}${FMWLAUNCH_CLASSPATH}${CLASSPATHSEP}${DERBY_CLASSPATH}${CLASSPATHSEP}${DERBY_TOOLS}${CLASSPATHSEP}${POINTBASE_CLASSPATH}${CLASSPATHSEP}${POINTBASE_TOOLS}"

if [ "${WLST_HOME}" != "" ] ; then
        WLST_PROPERTIES="-Dweblogic.wlstHome='${WLST_HOME}' ${WLST_PROPERTIES}"
        export WLST_PROPERTIES
fi

echo
echo CLASSPATH=${CLASSPATH}

JVM_ARGS="-Dprod.props.file='${WL_HOME}'/.product.properties ${WLST_PROPERTIES} ${JVM_D64} ${MEM_ARGS} ${CONFIG_JVM_ARGS}"
eval '"${JAVA_HOME}/bin/java"' ${JVM_ARGS} weblogic.WLST createQueues.py


Step 3) Create the  createQueues.py file under the current directory location with below content:


import ConfigParser
def connectToServer():
    try:
        USERNAME = 'username'
        PASSWORD = 'password'
        URL='t3://adminhost:adminport'
        #Connect to the Administration Server
        print 'starting the script ....'
        connect(USERNAME,PASSWORD,URL)
    except:
        print 'Unable to find admin server...'
        exit()

def startEditSession():
    print "Starting the Edit Session"
    edit()
    startEdit()

def activateTheChanges():
    print "Saving and Activating the changes..."
    try:
        save()
        activate(block="true")
        print "script returns SUCCESS"
    except Exception, e:
        print e
        print "Error while trying to save and/or activate!!!"
        dumpStack()
        raise

def disconnectFromServer():
    print "Disconnecting from the Admin Server"
    disconnect()
    print "Exiting from the Admin Server"
    exit()
    print "Mission Accomplished"

def createQueue(queueName,queueJNDIName,systemModuleName,subDeploymentName,targetServerCluster,targetName):
    print 'Creating Queue ', queueName
    cd('/JMSSystemResources/'+systemModuleName+'/JMSResource/'+systemModuleName)
    cmo.createUniformDistributedQueue(queueName)
    cd('/JMSSystemResources/'+systemModuleName+'/JMSResource/'+systemModuleName+'/UniformDistributedQueues/'+queueName)
    cmo.setJNDIName(queueJNDIName)
    cd('/SystemResources/'+systemModuleName+'/SubDeployments/'+subDeploymentName)
    #set('Targets',jarray.array([ObjectName('com.bea:Name=Test2JMSCluster,Type=Cluster')], ObjectName))
    if targetServerCluster in ('C','c') :
        clstrNam=targetName
        set('Targets',jarray.array([ObjectName('com.bea:Name='+clstrNam+',Type=Cluster')], ObjectName))
    else:
        servr=targetName
        set('Targets',jarray.array([ObjectName('com.bea:Name='+servr+',Type=JMSServer')], ObjectName))
    cd('/JMSSystemResources/'+systemModuleName+'/JMSResource/'+systemModuleName+'/UniformDistributedQueues/'+queueName)
    cmo.setSubDeploymentName(subDeploymentName)
    cmo.unSet('Template')
    cmo.setForwardDelay(5)
    print 'Saving the changes'
    try:
        save()
    except weblogic.management.mbeanservers.edit.ValidationException, err:
        print 'Could not save ', err
        dumpStack()
        raise

def readConfigurationFile():
    try:
        parser = ConfigParser.ConfigParser()
        parser.read('/shared/fmw/build/myscript/newscripts/createQueue/propFile/jmsQueues.ini')
    except ConfigParser.ParsingError, err:
        print 'Could not parse:', err
    for section_name in parser.sections():
        print 'Section:', section_name
        print '  Options:', parser.options(section_name)
        createQueue(parser.get(section_name, 'queueName'),
                    parser.get(section_name, 'queueJNDIName'),
                    parser.get(section_name, 'systemModuleName'),
                    parser.get(section_name, 'subDeploymentName'),
                    parser.get(section_name, 'targetServerCluster'),
                    parser.get(section_name, 'targetName'))

    print 'Queue created successfully'
#Read Configuration File ends here

###############     Main Script   #####################################
#Conditionally import wlstModule only when script is executed with jython
if __name__ == '__main__':
    from wlstModule import *#@UnusedWildImport
print('This will enable you to create distributed JMS Queues')
connectToServer()
startEditSession()
readConfigurationFile()
#createQueue()
activateTheChanges()
disconnectFromServer()

####################################


Step 3) Create a folder propFile > cd propFile > Create a file jmsQueues.ini under this folder with below content. It contains the details of queues that you want to create in one go. Below example is for two queues ,for more number of queues you can add the snippet accordingly.

[TestQ]
queueName = TestQ1
queueJNDIName = jms/Q/TestQ
systemModuleName = SOAJMSModule
subDeploymentName = SOAJMSServer1984410823
targetServerCluster = x
targetName = SOAJMSServer_auto_1
[TestQueue]
queueName = TestQueue2
queueJNDIName = jms/Q/TestQueue
systemModuleName = SOAJMSModule
subDeploymentName = SOAJMSServer1984410823
targetServerCluster = x
targetName = SOAJMSServer_auto_1


After this you just need to execute the shell script and then verfiy it from admin console.
sh createQueues.sh

Thanks a lot for your patience!!!

Regards
-Ashish

Sunday 19 January 2014

Script for Running instances Email Notification for Composite deployed in any domain

blogger
          Script for Running instances Email Notification for Composite deployed in any domain

Hello to viewer,

This script is for getting the Email Notification in case there is any Running instance of any composite.
This script will monitor the instances of last one hour and if there is any running instance found for any composite deployed in our domain , it simple sends an alert in the form of Email Notification.

Benefit: It is helpful in monitoring the critical transaction especially in production environment so that any transaction failure can be recovered by getting the prior notification.

You need to follow the below steps:

Step 1) Create the below directory structure.

cd /shared/fmw/myscript/monitor

Step 2) Create a file InstanceMonitor.sh under current directory with below content.

#!/bin/sh
export ORACLE_HOME=oracle_home


COMPMON_HOME='/shared/fmw/myscript/monitor'
cd $COMPMON_HOME

MAILTO=xxxxxx@xxxxxx.com
MAILCC=xxxxxx@xxxxxx.com
DBUSER=database_user
PASSWORD=password
HOST=hostname
PORT=port
SERVICE_NAME=service_name
INFO=OFF
ENV=ENV_NAME
MAILFROM=xxxxxx@xxxxx.com
START=ON
OUTPUT=/shared/fmw/myscript/monitor/output.html

if [ -f $COMPMON_HOME/sqloutput.txt ]; then
  rm -f $COMPMON_HOME/sqloutput.txt
fi

if [ -f $COMPMON_HOME/.tmp ]; then
  rm -f $COMPDBMON_HOME/.tmp
fi

########### For MY Domain ########

#if [ ! -f /shared/fmw/myscript/monitor/donotmail ]; then

        echo " " >$OUTPUT
        (
        echo "<br>"
        echo "<H2>LIST OF RUNNING INSTANCES for Composite in Mydomain</H2>"
        #echo "<br>"
        echo "<table border = 1 cellSpacing= 1 cellPadding=1 >"
        echo "<th>"
        echo "<tr bgcolor='#CFCFFF' ><FONT face=Tahoma color='blue'> "
        echo "<td colspan='1' align='center' font-color='blue'><b>INSTANCE ID</b></td>"
        echo "<td colspan='1' align='center' font-color='blue'><b>COMPOSITE NAME</b></td>"
        echo "<td colspan='1' align='center' font-color='blue'><b>SOURCE NAME</b></td>"
        echo "<td colspan='1' align='center' font-color='blue'><b>CONVERSATION ID</b></td>"
        echo "<td colspan='1' align='center' font-color='blue'><b>CREATED TIME</b></td>"
        echo "</font>"
        echo "</tr>"
        echo "</th>"
        echo "<tr>"
        )>>$OUTPUT

        RETURN=`sqlplus -S 'database_user/password@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=hostname)(PORT=port)))(CONNECT_DATA=(SERV
ER=DEDICATED)(SERVICE_NAME=servicename)))' < query.sql`

        len=`expr length "$RETURN"`
        if [ `echo $len` -gt 0 ]; then
        sed '/^$/d' < $COMPMON_HOME/sqloutput.txt >$COMPMON_HOME/.tmp
        i=1
        while read record; do
                if [ $i -ge 6 ]; then
                                echo "</tr>" >>$OUTPUT
                                echo "<tr>" >>$OUTPUT
                                i=1
                else
                                (echo "<td>"
                                echo $record
                                echo "</td>" )>>$OUTPUT
                                i=`expr $i + 1`

                fi
        done < /shared/fmw/myscript/monitor/.tmp
        echo "</tr>" >>$OUTPUT
        echo "</table>" >>$OUTPUT
        echo "<hr>" >>$OUTPUT


(
                        echo "From: $MAILFROM"; \
                        echo "To: $MAILTO"; \
                        echo "Cc: $MAILCC"; \
                        echo "Content-Type: text/html";\
                        echo "Subject:Running Instances Monitoring"; \
                        echo ""; \
                        cat $OUTPUT; \
                ) | /usr/lib/sendmail -t
        fi



Note: you need to provide the value of  below variable according to your environment:

oracle_home

TNS_ENTRY: 

DBUSER=database_user
PASSWORD=password
HOST=hostname
PORT=port
SERVICE_NAME=service_name


Step 3) Create the file query.sql file that contains the sql script for getting the Running instance details of composites deployed in any domain.

SET ECHO ON
WHENEVER SQLERROR EXIT -1 ROLLBACK
SET TRIMOUT ON
SET HEAD OFF
SET feedback OFF
SET serveroutput OFF

spool sqloutput.txt
select mycom.id, substr(mycom.composite_DN, 0, instr(mycom.composite_DN, '!')-1) Composite_name, mycom.source_name, mycom.conversation_id
, to_char(mycom.created_time, 'MM/DD/YY-HH:MI:SS')
from composite_instance mycom
where
mycom.state = '0'
and mycom.id not in (select cmpst_id from cube_instance mycube)
and mycom.created_time > sysdate - 1/24
and substr(mycom.composite_DN, 0, instr(mycom.composite_DN, '!')-1) IN('composite_name separated by comma for which you want to monitor running instances');
spool off

quit


After this you just need to execute the shell script or you can set this job in cron for every 30 min.

Thanks a lot for your pateince!!!!

Regards
-Ashish

Thursday 16 January 2014

Shell script to Automate the process of Retiring and Activation of Multiple composites in different domain at one time.

blogger

Shell script to Automate the process of Retiring and Activation of Multiple composites in different domain at one time.
Hello to viewer,

Here is the Shell script to Automate the process of Retiring and Activation of Multiple composites in different domain at one time.

Benefit: Some time we are required to stop the Inflow of the data whenever we need to do any release in order to avoid any data failure or data loss.At that time we can use this script to Retire multiple composite in different domain that are getting data from external resource.
This can be one of the scenario ,however there can be several other reason.

You just need to follow the below steps :

Step 1) Create the directory structure as below:

cd /shared/fmw/build/Myscript/retservice

Step 2) Create Myservicelist.txt file under current directory "retservice"

This file contains the details of composites that we need to retire in below format. File can contains entry from different domain as shown below in given format.

Format:

composite_name,version,partition_name,domain_name

Example:
               Mycomposite,1.0.0,Mypartition,MyDomain.
               Mycomposite1,1.0.0,Mypartition1,MyDomain1

Step 3) Create "MyEnv.txt" in current directory file that contains details of your Environment

# My_MyDomain deployment server weblogic
 My_MyDomain_serverURL=http://host : managed_server_port
 My_MyDomain_user=user
 My_MyDomain_password=password
 My_MyDomain_host=host
 My_MyDomain_port=managed_server_port
 My_MyDomain_adminhost=admin_host
 My_MyDomain_adminport=admin_port


# My_MyDomain1 deployment server weblogicMy_MyDomain1_serverURL=http://host : managed_server_port
 My_MyDomain1_user=user
 My_MyDomain1_password=password
 My_MyDomain1_host=host
 My_MyDomain1_port=managed_server_port
 My_MyDomain1_adminhost=admin_host
 My_MyDomain1_adminport=admin_port


Step 3) Create "retireservice.py" in the current directory that executes the wlst command.


import sys
sca_retireComposite(sys.argv[1],sys.argv[2],sys.argv[3],sys.argv[4],sys.argv[5],sys.argv[6],partition=sys.argv[7])



Step 4) Create "retireComposite.sh" in the current directory that calls the python script.


#!/bin/sh
# set up WL_HOME, the root directory of your WebLogic installation
WL_HOME="wl_home"

umask 027

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

CLASSPATH="${CLASSPATH}${CLASSPATHSEP}${FMWLAUNCH_CLASSPATH}${CLASSPATHSEP}${DERBY_CLASSPATH}${CLASSPATHSEP}${DERBY_TOOLS}${CLASSPATHSEP}${POINTBASE_CLASSPAT
H}${CLASSPATHSEP}${POINTBASE_TOOLS}"

if [ "${WLST_HOME}" != "" ] ; then
        WLST_PROPERTIES="-Dweblogic.wlstHome='${WLST_HOME}' ${WLST_PROPERTIES}"
        export WLST_PROPERTIES
fi

#echo
#echo CLASSPATH=${CLASSPATH}

JVM_ARGS="-Dprod.props.file='${WL_HOME}'/.product.properties ${WLST_PROPERTIES} ${JVM_D64} ${MEM_ARGS} ${CONFIG_JVM_ARGS}"
    while read LINE; do
      domain=$(echo "$LINE" | awk -F, '{ print $4 }');
      servicename=$(echo "$LINE" | awk -F, '{ print $1 }');
      version=$(echo "$LINE" | awk -F, '{ print $2 }');
      partition=$(echo "$LINE" | awk -F, '{ print $3 }');
          while read LINE1; do
          temp=$(echo "$LINE1" | grep $2'_'$domain'_adminhost'| awk -F= '{ print $2 }');
          if [ "$temp" != "" ]; then
          targethost=$temp;
          fi
          temp=$(echo "$LINE1" | grep $2'_'$domain'_port'| awk -F= '{ print $2 }');
          if [ "$temp" != "" ]; then
          targetport=$temp;
          fi
          temp=$(echo "$LINE1" | grep $2'_'$domain'_user'| awk -F= '{ print $2 }');
          if [ "$temp" != "" ]; then
          user=$temp;
          fi
          temp=$(echo "$LINE1" | grep $2'_'$domain'_password'| awk -F= '{ print $2 }');
          if [ "$temp" != "" ]; then
          password=$temp;
          fi
          done < $2'Env'.txt
    ORACLE_HOME/common/bin/wlst.sh retireservice.py ${targethost} ${targetport} ${user} ${password} $servicename $version $partition > output.txt
    done < $1'servicelist'.txt

                                
Note: Change the value of wl_home, ORACLE_HOME according to your environment.

How to execute this:

It will require two parameter.

sh retireComposite.sh My My ( $1'servicelist'.txt and $2'Env'.txt , Hope you understand the difference between Two twins My ;))

After this just refersh the FARM and verify the composite.

For Activation : You jus need to change the wlst command in retireservice.py rather you should prefer to give some meaning full name . Replace retireservice with activateservice, retireComposite with activateComposite and retservice with actservice.

import sys
sca_activateComposite(sys.argv[1],sys.argv[2],sys.argv[3],sys.argv[4],sys.argv[5],sys.argv[6],partition=sys.argv[7])

Thanks a lot for your patience!!!

Regards
-Ashish

Tuesday 14 January 2014

Shell script to Send email notification for Composites that are in Retired state in any domain.

blogger
Hello to viewer,

This shell script is for Monitoring purpose for all the composites that are default and in retired state.

Script will send the Email Notification in case it finds the default version of the composites deployed in any domain in Retired state.

Benefit : Helpful for techies supporting soa application in weblogic 11g environment. they will get the prior notification in case composites is in retired state so that any transaction failure can be avoided that are critical in production environment.

Here is the flow:

Shell calls the python ---> python executes the wlst command.

Wlst command: It will list all the composites that are deployed in any domain.

sca_listDeployedComposites('host','manageserver_port','user','password')

Change the value of host,manageserver_port,user and password accrding to your environment.

Follow the below steps:

Step 1) : Create the directory structure as below:

cd /shared/fmw/build/script/yourscript

Step 2) : Under your current directory "yourscript " create serviceList.py file with content below:

import ConfigParser
def connectToServer():
        USERNAME = 'user'
        PASSWORD = 'password'
        URL='t3://host : adminport'
        #Connect to the Administration Server
        print 'starting the script ....'
        connect(USERNAME,PASSWORD,URL)

def disconnectFromServer():
    print "Disconnecting from the Admin Server"
    disconnect()
    print "Exiting from the Admin Server"
    exit()
    print "Mission Accomplished"

def readConfigurationFile():
    try:
        print 'Entry point...'
        sca_listDeployedComposites('host','manageserver_port','user','password')


    except :
        print 'Unable to find admin server...'
        exit()

    print 'Command executed successfully'

###############     Main Script   #####################################
#Conditionally import wlstModule only when script is executed with jython
if __name__ == '__main__':
    from wlstModule import *#@UnusedWildImport
print('This will enable you to create distributed JMS Queues')
connectToServer()
readConfigurationFile()
#activateTheChanges()
disconnectFromServer()
####################################


 Step 3)  : Under your current directory "yourscript " create serviceList.sh with the content below :


#!/bin/sh
sender="sender@xxxxx.com"
receiver="receiver@xxxxx.com"
subj="CompositeStatus"
OUTPUT=/shared/fmw/build/script/yourscript/CompositeStatus.html
MAILTO=receiver@xxxxx.com
MAILCC=InCC@xxxxx.com
MAILFROM=sender@xxxxx.com
# set up WL_HOME, the root directory of your WebLogic installation
WL_HOME="wl_home"

umask 027

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

CLASSPATH="${CLASSPATH}${CLASSPATHSEP}${FMWLAUNCH_CLASSPATH}${CLASSPATHSEP}${DERBY_CLASSPATH}${CLASSPATHSEP}${DERBY_TOOLS}${CLASSPATHSEP}${POINTBASE_CLASSPAT
H}${CLASSPATHSEP}${POINTBASE_TOOLS}"

if [ "${WLST_HOME}" != "" ] ; then
        WLST_PROPERTIES="-Dweblogic.wlstHome='${WLST_HOME}' ${WLST_PROPERTIES}"
        export WLST_PROPERTIES
fi

#echo
#echo CLASSPATH=${CLASSPATH}

JVM_ARGS="-Dprod.props.file='${WL_HOME}'/.product.properties ${WLST_PROPERTIES} ${JVM_D64} ${MEM_ARGS} ${CONFIG_JVM_ARGS}"
sh ORACLE_HOME/common/bin/wlst.sh serviceList.py > output.out
#eval '"${JAVA_HOME}/bin/java"' ${JVM_ARGS} weblogic.WLST serviceList.py

#grep -E "mode=retired"\|"state=off" output.out | grep "isDefault=true" > retired.out

#grep -v "partition=SOAInfraTest" retired.out > stateoff.out

#awk -F, '{ print $1, $2 }' stateoff.out > CompositeStatus.out

N=0
COUNT=0
echo '<html>' > $OUTPUT
echo "<br /><b style='color:#ff0000'>Below are the tables showing retired / shutdown composite with there partition and domain.</b> <br /><br />" >> $OUTPUT
while read LINE ; do

       if echo "$LINE" | egrep -q "user = " > /dev/null; then
          N=$((N+1))
          if [ "$N" -ge 2 ] ; then
               echo "</table>" >> $OUTPUT
               echo "<br />" >> $OUTPUT
          fi
         echo "<span style='color:black;font-weight:bold;'>" >> $OUTPUT
         echo "$LINE" | awk '{print $3}' >> $OUTPUT
         echo "</span>" >> $OUTPUT
         echo "<br />" >> $OUTPUT
         echo "<table border=1 cellpadding=0 cellspacing=0 style='background-color:#eee'>" >>$OUTPUT
         echo "<tr style='background-color:#ddd'>" >> $OUTPUT
         echo "<th>Composite Name</th><th>Partition Name</th>" >>$OUTPUT
         echo "</tr>" >> $OUTPUT
       fi

       if echo "$LINE" | grep -E "mode=retired"\|"state=off" | grep "isDefault=true" | grep -v "partition=SOAInfraTest" > /dev/null; then
          echo "<tr >" >> $OUTPUT
          echo "<td style='padding:3px 5px;width:300px;'>" >> $OUTPUT
          echo "$LINE" | awk '{print $2}' | sed -e "s/,//g"   >> $OUTPUT
          echo "</td>" >> $OUTPUT
          echo "<td style='padding:3px 5px;width:300px;'>" >> $OUTPUT
          echo "$LINE" | awk '{print $3}' | sed -e "s/,//g" >> $OUTPUT
          echo "</td>" >> $OUTPUT
          echo "</tr>" >> $OUTPUT
       fi
       #echo "$LINE" | grep -E "mode=retired"\|"state=off" | grep "isDefault=true" | awk '{print $2,$3}'
done < output.out
echo "</table>" >> $OUTPUT
echo '</html>' >> $OUTPUT

#cat /shared/fmw/build/script/yourscript/abcd.html | mail -s $subj sender@xxxxx.com

#mail --append="Content-type: text/html" -s "Built notification" sender@xxxxx.com < /shared/fmw/build/script/yourscript/abcd.html

(
                        echo "From: $MAILFROM"; \
                        echo "To: $MAILTO"; \
                        echo "Cc: $MAILCC"; \
                        echo "Content-Type: text/html";\
                        echo "Subject: CompositeStatus"; \
                        echo ""; \
                        cat $OUTPUT; \
                ) | /usr/lib/sendmail -t



Note : Change the value of wl_home, oracle_home, sender, receiver according to your environment.

After this you just need to execute the shell script or you can set this job in cron.

Thanks a lot for your patience !!!! 

Regards
-Ashish