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
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
Thanks for sharing,get an affordable dedicated server at best prices and services.
ReplyDelete