Script to Pause/Resume the multiple distributed queues at a time
Hello to Viewers,
This script will help in performing the pause and resume operation on multiple distributed queues in one go. You don't need to go to the console and do the same task manually which is of-course time
taking and error prone.
FLOW:
shell script ---> python --> wlst command.
Here shell script will call python script and in python we have mentioned few relevant wlst command that perform the actual task.
Follow the below steps:
1) Create a shell script under below directory: QueueOperation.sh
I have taken the directory structure as below:
/opt/soauser/automation/SOAQueueOperation/
QueueOperation.sh
---------------------------------------------------------------------------------------------------------------
#!/bin/sh
export LOGFILE="/opt/soauser/automation/SOAQueueOperation/Q_Pause_Resume.log"
if [ -f $LOGFILE ]; then
rm -f $LOGFILE
fi
rm -rf /opt/soauser/automation/SOAQueueOperation/Q_Pause_Resume.log
WL_HOME="/xxxxxx/xxxx/xxx/wlserver_10.3"
export WL_HOME
echo "Please enter pause to PAUSE the queues or resume to RESUME the queues:"
read PARAMETER1
cd /opt/soauser/automation/SOAQueueOperation/
sh ${WL_HOME}/common/bin/wlst.sh /opt/soauser/automation/SOAQueueOperation/QueueOperation.py $PARAMETER1 $1 >> /opt/soauser/automation/SOAQueueOperation/Q_Pause_Resume.log
exit
--------------------------------------------------------------------------------------------------------------
2) Create a text file in same directory that contains the queue name:
Suppose you need to pause the queues related to SAP then name it as SAPQueueList.txt(targetQueueList.txt)
here target could be SAP or any end system to which queues are related.
SAPQueueList.txt
----------------------------------------------------------------------------------------------------------
QueueName1
QueueName2
----------------------------------------------------------------------------------------------------------
3) Create a python file under the same directory: QueueOperation.py
Here i am assuming that
I have 2 JMS servers : JMSSERVER1 and JMSSERVER2
My Managed servers name is MS1 and MS2
JMS module: JMSMODULE
QueueOperation.py
----------------------------------------------------------------------------------------------------------
from java.io import FileInputStream
import java.lang
import os
import string
import sys , traceback
operation=sys.argv[1]
target=sys.argv[2]
def connectToServerJMS1():
USERNAME = 'username'
PASSWORD = 'password'
URL='t3://managedserver1host:managedserver1port'
#Connect to the ManagedServer1
print 'starting the script ....'
connect(USERNAME,PASSWORD,URL)
def connectToServerJMS2():
USERNAME = 'username'
PASSWORD = 'password'
URL='t3://managedserver2host:managedserver2port'
#Connect to the ManagedServer2
print 'starting the script ....'
connect(USERNAME,PASSWORD,URL)
def disconnectFromServer():
print "Disconnecting from the ManagedServer"
disconnect()
print "Exiting from the Managed Server"
exit()
print "Mission Accomplished"
def pauseQueueConsumptionJMS1(queueName):
try:
print 'Entry point1...'
serverRuntime()
# queueName = str(queueName.strip())
queueName = queueName.strip()
print 'test0'
cd('/JMSRuntime/MS1.jms/JMSServers/JMSSERVER1/Destinations/JMSMODULE!JMSSERVER1@'+ queueName)
print 'test1'
cmo.pauseConsumption()
print 'Queue: "', queueName ,'" has been CONSUMPTION Paused ON JMS1 Successfully'
except :
print 'Something went wrong...'
exit()
def pauseQueueConsumptionJMS2(queueName):
try:
print 'Entry point2...'
serverRuntime()
queueName = queueName.strip()
print 'test2'
cd('/JMSRuntime/MS2.jms/JMSServers/JMSSERVER2/Destinations/JMSMODULE!JMSSERVER2@'+ queueName)
print 'test3'
cmo.pauseConsumption()
print 'Queue: "', queueName ,'" has been CONSUMPTION Paused ON JMS2 Successfully'
except :
print 'Something went wrong...'
exit()
def resumeQueueConsumptionJMS1(queueName):
try:
print 'Entry point...'
serverRuntime()
queueName = queueName.strip()
cd('JMSRuntime/MS1.jms/JMSServers/JMSSERVER1/Destinations/JMSMODULE!JMSSERVER1@'+ queueName)
cmo.resumeConsumption()
print 'Queue: "', queueName ,'" has been CONSUMPTION resumed Successfully'
except :
print 'Something went wrong...'
exit()
def resumeQueueConsumptionJMS2(queueName):
try:
print 'Entry point...'
serverRuntime()
queueName = queueName.strip()
cd('JMSRuntime/MS2.jms/JMSServers/JMSSERVER2/Destinations/JMSMODULE!JMSSERVER2@'+ queueName)
cmo.resumeConsumption()
print 'Queue: "', queueName ,'" has been CONSUMPTION resumed Successfully'
except :
print 'Something went wrong...'
exit()
############### 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 perform operation on distributed JMS Queues')
#connectToServer()
listName = target+'QueueList.txt'
if operation=='pause':
f = open(listName,'r')
out = f.readlines()
for queueName in out:
queueName.strip()
print 'Trying Consumption Pause on '+queueName
connectToServerJMS1()
pauseQueueConsumptionJMS1(queueName)
disconnect()
connectToServerJMS2()
pauseQueueConsumptionJMS2(queueName)
disconnect()
print 'Consumption Paused on '+queueName
else:
f = open(listName,'r')
out = f.readlines()
for queueName in out:
queueName.strip()
print 'Trying Consumption Resume on '+queueName
connectToServerJMS1()
resumeQueueConsumptionJMS1(queueName)
disconnect()
connectToServerJMS2()
resumeQueueConsumptionJMS2(queueName)
print 'Consumption Resumed on'+queueName
#exit()
disconnectFromServer()
####################################
---------------------------------------------------------------------------------------------------------
HOW TO RUN:
Simply run the shell script and provide the target system name as a parameter for ex:
cd /opt/soauser/automation/SOAQueueOperation/
sh QueueOperation.sh SAP
(here SAP is the target so python file will look for SAPQueueList.txt)
then it will ask for the operation to be performed : Please enter pause to PAUSE the queues or resume to RESUME the queues
type the operation name and press "enter" and then verify the log file(Q_Pause_Resume.log) and queue status from console.
Thanks a lot for your patience !!!!
Regards
-Ashish
Regards
-Ashish