Sunday, November 13, 2011

Jython script to create queue connection factory at node scope

import sys,java
from java.util import Properties
from java.io import FileInputStream
from org.python.modules import time
lineSep = java.lang.System.getProperty('line.separator')

def QF(node,timeOut,maxConn,minConn,reapTime,unusdTimeout,agedTimeout,StimeOut,SmaxConn,SminConn,SreapTime,SunusdTimeout,SagedTimeout,name,jndiname,xa,fail,auth_name,msg,pool,qmanager,rescan,tptype,connpool,purge,Spurge,mapping):

# Declare global variables

global AdminConfig
global AdminControl

# Gets the name of cell

cell = AdminControl.getCell()

cellid = AdminConfig.getid('/Cell:'+ cell +'/')

print " ----------------------------------------------------------------------------------------- "


#------QueueConnectionFactory--------#

MS=AdminConfig.getid('/Cell:'+ cell +'/Node:'+ node +'/JMSProvider:WebSphere MQ JMS Provider/')

QF=AdminConfig.getid('/Cell:'+ cell +'/Node:'+ node +'/JMSProvider:WebSphere MQ JMS Provider/MQQueueConnectionFactory:'+ name +'/')

if len(QF) == 0 :
print "QueueConnectionFactory does not exists .... "
else :
print "QueueConnectionFactory exists, so removing old QueueConnectionFactory ... "
AdminConfig.remove(QF)
print "QueueConnectionFactory removed .. "


print "Creating QueueConnectionFactory .. "

name1 = ["name" , name]

jndi = ["jndiName" , jndiname ]

XA = ["XAEnabled", xa ]

fail = ["failIfQuiesce", fail ]

auth = ["authMechanismPreference", auth_name]

msgreten = ["msgRetention", msg]

pool_int = ["pollingInterval", pool ]

qm = ["queueManager", qmanager ]

rscan = ["rescanInterval", rescan ]

tp = ["transportType", tptype]

map_configalias_attr = ["mappingConfigAlias", mapping]

map_attrs=[map_configalias_attr]

mapping_attr=["mapping", map_attrs]

conn = ["useConnectionPooling", connpool]

timeout = ["connectionTimeout" , timeOut]

maxconn = ["maxConnections" , maxConn]

minconn = ["minConnections" , minConn]

reaptime = ["reapTime" , reapTime]

unusedtimeout = ["unusedTimeout" , unusdTimeout]

agedtimeout = ["agedTimeout" , agedTimeout]

purgepolicy = ["purgePolicy" , purge]

connPoolAttrs = [timeout , maxconn , minconn , reaptime , unusedtimeout , agedtimeout , purgepolicy]

conn_pool = ["connectionPool", connPoolAttrs ]

Stimeout = ["connectionTimeout" , StimeOut]

Smaxconn = ["maxConnections" , SmaxConn]

Sminconn = ["minConnections" , SminConn]

Sreaptime = ["reapTime" , SreapTime]

Sunusedtimeout = ["unusedTimeout" , SunusdTimeout]

Sagedtimeout = ["agedTimeout" , SagedTimeout]

Spurgepolicy = ["purgePolicy" , Spurge]

sessPoolAttrs = [Stimeout , Smaxconn , Sminconn , Sreaptime , Sunusedtimeout , Sagedtimeout , Spurgepolicy]

sess_pool = ["sessionPool", sessPoolAttrs ]

qf_attr = [name1 , jndi , XA , fail , auth , mapping_attr ,msgreten ,pool_int , qm, rscan , tp , conn , conn_pool, sess_pool]

newqf = AdminConfig.create('MQQueueConnectionFactory' , MS , qf_attr)

print "QueueConnectionFactory created .. "

AdminConfig.save()

print " Saving Configuraion "

print " ----------------------------------------------------------------------------------------- "




#--------------------------------------------------------------#


## Full Syncronization ##

print " Syncronizing configuration with Master Repository "

nodelist = AdminTask.listManagedNodes().split(lineSep)

for nodename in nodelist :

print " syncronizing nodes .......... "

####################Identifying the ConfigRepository MBean and assign it to variable######################

repo = AdminControl.completeObjectName('type=ConfigRepository,process=nodeagent,node='+ nodename +',*')

AdminControl.invoke(repo, 'refreshRepositoryEpoch')

sync = AdminControl.completeObjectName('cell='+ cell +',node='+ nodename +',type=NodeSync,*')

print AdminControl.invoke(sync , 'sync')

print " ----------------------------------------------------------------------------------------- "

print " ----------------------------------------------------------------------------------------- "

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

#main program starts here

arglen=len(sys.argv)

num_exp_args=3

if (arglen != num_exp_args):

print "Three arguments are required.one of them is property file"

print " ----------------------------------------------------------------------------------------- "

sys.exit(-1)

propFile=sys.argv[0]

properties=Properties();

try:

properties.load(FileInputStream(propFile))

print " ----------------------------------------------------------------------------------------- "

print "Succesfully read property file "+propFile

print " ----------------------------------------------------------------------------------------- "

except:

print "Cannot read property file "+propFile
sys.exit(-1)

print " ----------------------------------------------------------------------------------------- "

node = sys.argv[1]
timeOut = int(properties.getProperty("Connection_timeout"))
maxConn = int(properties.getProperty("Maximum_connections"))
minConn = int(properties.getProperty("Minimum_connections"))
reapTime = int(properties.getProperty("Reap_time"))
unusdTimeout = int(properties.getProperty("Unused_timeout"))
agedTimeout = int(properties.getProperty("Aged_timeout"))
StimeOut = int(properties.getProperty("SConnection_timeout"))
SmaxConn = int(properties.getProperty("SMaximum_connections"))
SminConn = int(properties.getProperty("SMinimum_connections"))
SreapTime = int(properties.getProperty("SReap_time"))
SunusdTimeout = int(properties.getProperty("SUnused_timeout"))
SagedTimeout = int(properties.getProperty("SAged_timeout"))
name = str(properties.getProperty("Name"))
jndiname = str(properties.getProperty("Jndi_Name"))
xa = str(properties.getProperty("XAEnabled"))
fail = str(properties.getProperty("Enable-return-methods-during-shutdown"))
auth_name = str(properties.getProperty("authMechanismPreference"))
msg = str(properties.getProperty("Msg-Retention"))
pool = str(properties.getProperty("Polling-Interval"))
qmanager = sys.argv[2]
rescan = str(properties.getProperty("Rescan-Interval"))
tptype = str(properties.getProperty("TransportType"))
connpool = str(properties.getProperty("useConnectionPooling"))
purge = str(properties.getProperty("Purge_policy"))
Spurge = str(properties.getProperty("SPurge_policy"))
mapping = str(properties.getProperty("Mapping-configuration-alias"))

QF(node,timeOut,maxConn,minConn,reapTime,unusdTimeout,agedTimeout,StimeOut,SmaxConn,SminConn,SreapTime,SunusdTimeout,SagedTimeout,name,jndiname,xa,fail,auth_name,msg,pool,qmanager,rescan,tptype,connpool,purge,Spurge,mapping)

No comments:

Post a Comment