#-------#
# JMSQueueScript.py
# Requires argument - either install, update or clean
#Requires properties folder to be in same directory as script
#Creates Queues, JMS servers, subdeployments, system modules and sets attributes
#-------#
import sys
import re
global jmsProp
global envProp
#Determine runMode- Install, Update or Clean
try:
runMode = sys.argv[1]
def connectToAdminServer():
global startedNewServer
loadProperties(envProp)
hideDisplay()
hideDumpStack("true")
# try connecting to a running server if it is already running ...
if connected=="false":
try:
URL="t3://"+adminServerListenAddress+":"+adminServerListenPort
print URL
connect(userName, passWord, URL)
except WLSTException:
print 'No server is running at '+URL
hideDumpStack("false")
if connected=="false":
print 'No connection established'
def startTransaction():
edit()
startEdit()
def endTransaction():
#startEdit()
save()
activate(block="true")
#----
# CREATE METHODS -
#----
def create_Queue(path, beanName):
cd(path)
try:
#print "creating Queue: "+beanName
theBean = cmo.lookupQueue(beanName)
if theBean == None:
cmo.createQueue(beanName)
except java.lang.UnsupportedOperationException, usoe:
pass
except weblogic.descriptor.BeanAlreadyExistsException,bae:
pass
except java.lang.reflect.UndeclaredThrowableException,udt:
pass
def create_JMSServer(path, beanName):
cd(path)
try:
#print "creating mbean of type JMSServer ... "
theBean = cmo.lookupJMSServer(beanName)
if theBean == None:
cmo.createJMSServer(beanName)
except java.lang.UnsupportedOperationException, usoe:
pass
except weblogic.descriptor.BeanAlreadyExistsException,bae:
pass
except java.lang.reflect.UndeclaredThrowableException,udt:
pass
def create_JMSSystemResource(path, beanName):
cd(path)
try:
#print "creating mbean of type JMSSystemResource ... "
theBean = cmo.lookupJMSSystemResource(beanName)
if theBean == None:
cmo.createJMSSystemResource(beanName)
except java.lang.UnsupportedOperationException, usoe:
pass
except weblogic.descriptor.BeanAlreadyExistsException,bae:
pass
except java.lang.reflect.UndeclaredThrowableException,udt:
pass
def create_SubDeployment(path, beanName):
cd(path)
try:
#print "creating mbean of type SubDeployment ... "
theBean = cmo.lookupSubDeployment(beanName)
if theBean == None:
cmo.createSubDeployment(beanName)
except java.lang.UnsupportedOperationException, usoe:
pass
except weblogic.descriptor.BeanAlreadyExistsException,bae:
pass
except java.lang.reflect.UndeclaredThrowableException,udt:
pass
#
#----
# SET ATTRIBUTE METHODS -
#----
#
def setAttributesForQueue(path, subdeployment, jndiname, queuename):
cd(path)
print "setting attributes for Queue: "+queuename
set("SubDeploymentName", subdeployment)
set("JNDIName", jndiname)
set("Name", queuename)
def setAttributes_DeliveryParamsOverrides(paramList, modulePath):
for param in paramList:
path = modulePath+"/Queues/"+param+"/DeliveryParamsOverrides/"+param
cd(path)
print "setting DeliveryParamsOverrides to Non-Persistent:" +param
set("DeliveryMode", "Non-Persistent")
def setAttributesFor_c2JMSServer(path, server, persistenceStore):
cd(path)
print "setting attributes for mbean type JMSServer"
refBean0 = getMBean(server)
theValue = jarray.array([refBean0], Class.forName("weblogic.management.configuration.TargetMBean"))
cmo.setTargets(theValue)
#Set the persistence store if one is passed as a parameter
if (persistenceStore != None):
print "mbean is not equal to none"
print persistenceStore
bean = getMBean(persistenceStore)
print bean
cmo.setPersistentStore(bean)
def setAttributesFor_SubDeployment(path, server):
cd(path)
#print "setting attributes for mbean type SubDeployment"
refBean0 = getMBean(server)
theValue = jarray.array([refBean0], Class.forName("weblogic.management.configuration.TargetMBean"))
cmo.setTargets(theValue)
def setAttributesFor_JMSSystemResource(path, server):
cd(path)
#print "setting attributes for mbean type JMSSystemResource"
refBean0 = getMBean(server)
theValue = jarray.array([refBean0], Class.forName("weblogic.management.configuration.TargetMBean"))
cmo.setTargets(theValue)
def setAttributes_MessageLoggingParams(sysModule, jmsResource, loggingFormat, enabled):
path = jmsPath+sysModule+jmsResourcePath+sysModule+"/Queues/"+jmsResource+"/MessageLoggingParams/"+jmsResource
cd(path)
#print "setting attributes for mbean type MessageLoggingParams"
set("MessageLoggingFormat", loggingFormat)
set("MessageLoggingEnabled", enabled)
#----
# create_and_Set ATTRIBUTE METHODS
#----
def create_and_setAttributesFor_SubDeployment(jmsServerName, subDep, sysRes):
createPath = jmsPath + sysRes
create_SubDeployment(createPath, subDep)
setPath = createPath + "/SubDeployments/" + subDep
setAttributesFor_SubDeployment(setPath, jmsServerPath+jmsServerName)
def create_and_setAttributesFor_SystemResources(sysResource, server):
createPath = sPath
create_JMSSystemResource(createPath, sysResource)
setPath = jmsPath + sysResource
setAttributesFor_JMSSystemResource(setPath, server)
def create_and_setAttributesFor_JMSServer(serverName, bean):
create_JMSServer(sPath, serverName)
setPath = jmsServerPath+serverName
setAttributesFor_c2JMSServer(setPath, serversPath+beServerName, bean)
def create_and_setQueues(jndiList, modulePath, c2iDepName):
#create and then set
for jndiName in jndiList:
#print jndiName
create_Queue(modulePath, jndiName)
queuePath = modulePath +"/Queues/" + jndiName
setAttributesForQueue(queuePath, c2iDepName, jndiName, jndiName)
#This could be usefull for one off queues
# for q in customQList:
# exec """qJndiName = """+q+"""jndi"""
# exec """qSysRes = """+q+"""sysRes"""
# exec """qSubDep = """+q+"""subDep"""
# createPath="/JMSSystemResources/"+qSysRes+"/JMSResource/"+qSysRes
# print "createQpath "
# print createPath
# create_Queue(createPath, qJndiName)
# setAttributesForQueue(createPath+"/Queues/"+qJndiName, qSubDep, qJndiName, qJndiName)
def create_and_setAttributesFor_JMSComponents(jmsList):
for jms in jmsList:
exec """jmsName = """+jms+"""Name"""
exec """subDep = """+jms+"""SubDep"""
exec """sysRes = """+jms+"""SysRes"""
exec """sysResTarget = """+jms+"""SysResTarget"""
exec """store = """+jms+"""PersStore"""
exec """jndiList = """+jms+"""Queues"""
exec """nonPersistentList = """+jms+"""NonPers"""
if (len(store)==0):
store=None
create_and_setAttributesFor_JMSServer(jmsName, store)
create_and_setAttributesFor_SystemResources(sysRes, serversPath+sysResTarget)
create_and_setAttributesFor_SubDeployment(jmsName, subDep, sysRes)
modulePath = jmsPath+sysRes+jmsResourcePath+sysRes
if(len(jndiList)>0):
jndiList = standardStringSplit(jndiList,", ")
create_and_setQueues(jndiList, modulePath, subDep)
if(len(nonPersistentList)>0):
nonPersistentList = standardStringSplit(nonPersistentList,", ")
setAttributes_DeliveryParamsOverrides(nonPersistentList, modulePath)
#--------------------------
def install():
#Create JMS Servers
loadProperties(jmsProp)
jmsServerList = standardStringSplit(jmsServers, ", ")
print "Creating and Setting JMS Servers"
create_and_setAttributesFor_JMSComponents(jmsServerList)
#---Below 4 variables are hardcoded for time being
#This should be changed eventually
sysModule = "c2JMSModule"
loggingFormat="%header%,%properties%"
enabled="false"
jmsResource="c2.AsyncDispatcherRequestQ"
setAttributes_MessageLoggingParams(sysModule, jmsResource, loggingFormat, enabled)
def update():
install()
def clean():
loadProperties(jmsProp)
jmsServerList = standardStringSplit(jmsServers, ", ")
remove_JMSServers(jmsServerList)
def run_mode(mode):
if (mode=="install"):
install()
elif (mode=="update"):
#update()
print "Not fully implemented"
elif (mode=="clean"):
#clean()
print "Not fully implemented"
else:
print mode + " is not a valid argument: Current Args are 'install' 'clean' 'update'"
pass
#---------------
def standardStringSplit(strToSplit, splitString):
splitter = re.compile(splitString)
splitList = splitter.split(strToSplit)
return splitList
def remove_JMSServers(jmsServerList):
path = jmsServerPath
for jmsServer in jmsServerList:
exec """jmsName = """+jmsServer+"""Name"""
print jmsName
clean_bean(path, jmsName, 'JMSServer')
def clean_bean(path, beanName, beanType):
cd(path)
#try:
print "Attempting to remove "+beanType+": "+ beanName
exec """theBean = cmo.lookup"""+beanType+"""('"""+beanName+"""')"""
if theBean != None:
print "Deleting "+beanName+"..."
delete(beanName, beanType)
#-------#
try:
if (runMode == []):
print('Run mode must be set')
pass
else:
parentpath = sys.argv[3]
envProp = parentpath+'/weblogic_setup/properties/env.properties'
jmsProp = parentpath+'/weblogic_setup/properties/JMS.properties'
connectToAdminServer()
startTransaction()
run_mode(runMode)
endTransaction()
finally:
print 'JMSQueueScript done'
except IndexError:
print "Default action:Nothing"
print "Argument should be either 'install', 'clean' or 'update'"
Tidbits of useful information of William Dutton, Principal System Administrator and Architect
Thursday, December 10, 2009
WSLT weblogic JMS creation script
here is a script i use at work to create JMS servers modules and queues.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment