Created
August 13, 2010 17:49
-
-
Save markito/523260 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
@author: markito | |
@version: 1.0 | |
@summary: Script to create necessary JMS queues | |
@todo: SORTED ????? Example: alist = sorted(environments.iteritems(), key=lambda (k,v): (v,k)) | |
@todo: SCP solution to create the files only work for Linux/Unix environments. | |
''' | |
import sys, os, getopt | |
from java.lang import System | |
JMS_STORE_PATH = "/domains/ps_db_Fmw/stores" | |
components = [ | |
"AtendimentoProvABCSImpl", | |
"GerenciadorSegmentacaoEBS", | |
"GerenciarTarefasSegmentacaoEBS"] | |
environments = {"dev": | |
{"cluster1" : | |
["ps_db1_271a", "ps_db1_271b"], | |
}, | |
"hml": | |
{"cluster1" : | |
["ps_hb1_247a", "ps_hb1_248a"] | |
}, | |
"prd": | |
{"cluster1" : | |
["ps_hb1_247a", "ps_hb1_248a"] | |
} | |
} | |
def showEnvironments (): | |
''' | |
Show all environments and servers setup | |
''' | |
for environment, clusters in environments.iteritems(): | |
print environment | |
for cluster, nodes in clusters.iteritems(): | |
print cluster | |
for node in nodes: | |
print node | |
def createJMSFoldersFile(): | |
''' | |
Generate a shell script to create all JMS Store folders | |
''' | |
print "### Generating script for JMS Stores" | |
folderFile = open("/tmp/FolderFile.sh", "w") | |
mkdirCommands = [] | |
mkdirCommands.append("#!/bin/sh \n") | |
mkdirCommands.append("echo '### Creating JMS Store folders' \n\n") | |
for cluster, nodes in environments[env].iteritems(): | |
for node in nodes: | |
for component in components: | |
actual = "%(component)s-%(node)s" % {'component': component, 'node' : node} | |
mkdirCommands.append("mkdir %(path)s/%(actual)s \n" % {'path' : JMS_STORE_PATH, 'actual': actual}) | |
folderFile.writelines(mkdirCommands) | |
print "Done" | |
def createJMSQueues(component, targets): | |
''' | |
Create JMS queues (Request,Response and Error) for specific component and targets | |
''' | |
filas = ['Request', 'Response', 'Error'] | |
print "#### Create JMS Queues: " + component | |
for fila in filas: | |
cd('/JMSSystemResources/JMSModule-%(component)s/JMSResource/JMSModule-%(component)s' % {'component' : component} ) | |
cmo.createUniformDistributedQueue('%(component)s-%(fila)s' % {'component':component, 'fila':fila}) | |
# settings | |
cd('/JMSSystemResources/JMSModule-%(component)s/JMSResource/JMSModule-%(component)s/UniformDistributedQueues/%(component)s-%(fila)s' % {'component':component, 'fila':fila}) | |
cmo.setJNDIName('%(component)s-%(fila)s' % {'component':component, 'fila':fila}) | |
cmo.setLoadBalancingPolicy('Round-Robin') | |
cmo.setSubDeploymentName('%s' % (component)) | |
# targeting | |
cd('/SystemResources/JMSModule-%(component)s/SubDeployments/%(component)s' % {'component':component}) | |
for t in targets: | |
cmo.addTarget(t) | |
def createJMSModuleAndSubDeployment(cluster, nodes, components): | |
''' | |
Create JMS Module and Subdeployment for all nodes and components | |
''' | |
for component in components: | |
print "#### JMS Module creation JMSModule-%s" % (component) | |
cd('/') | |
cmo.createJMSSystemResource("JMSModule-%s" % (component)) | |
# setting and targeting | |
cd("/SystemResources/JMSModule-%s" % (component)) | |
set("Targets",jarray.array([ObjectName('com.bea:Name=%s,Type=Cluster' % (cluster))], ObjectName)) | |
print "#### Subdeployment creation" | |
cmo.createSubDeployment(component) | |
cd("/SystemResources/JMSModule-%(component)s/SubDeployments/%(component)s" % {'component':component}) | |
# targeting | |
targets = [] | |
for node in nodes: | |
t = getMBean("/JMSServers/JMSServer-%(component)s-%(node)s" % {'component' : component, 'node' : node}) | |
# save to use on queue creation without querying MBeans again | |
targets.append(t) | |
cmo.addTarget(t) | |
createJMSQueues(component, targets) | |
def createJMSFileStore(node, actual): | |
''' | |
Create JMS File Store and apply targeting | |
''' | |
print "#### Create file store: FileStore-%s" % (actual) | |
cd('/') | |
cmo.createFileStore("FileStore-%s" % (actual)) | |
# file store directory | |
cd("/FileStores/FileStore-%s" % (actual)) | |
cmo.setDirectory("stores/%s" % (actual)) | |
# targeting | |
set('Targets', jarray.array([ObjectName('com.bea:Name=%s,Type=Server' % (node))], ObjectName)) | |
def createJMSServer(node, actual): | |
''' | |
Create JMS Server and apply targeting | |
''' | |
print "#### Create JMSServer: JMSServer-%s" % (actual) | |
cd('/') | |
cmo.createJMSServer("JMSServer-%s" % (actual)) | |
cd("/Deployments/JMSServer-%s" % (actual)) | |
cmo.setPersistentStore(getMBean("/FileStores/FileStore-%s" % (actual))) | |
set('Targets', jarray.array([ObjectName('com.bea:Name=%s,Type=Server' % (node))], ObjectName)) | |
def onlineExecution(): | |
try: | |
connect(username, password, url) | |
edit() | |
startEdit() | |
try: | |
for cluster, nodes in environments[env].iteritems(): | |
print "#### Using cluster: " + cluster | |
for node in nodes: | |
print "### Node: " + node | |
for componente in components: | |
actual = "%(componente)s-%(node)s" % {'componente': componente, 'node' : node} | |
createJMSFileStore(node, actual) | |
createJMSServer(node, actual) | |
print '' | |
createJMSModuleAndSubDeployment(cluster,nodes, components) | |
showChanges() | |
s = raw_input("## Confirm ? (This will save and activate your current session) ") | |
if s == "y": | |
save() | |
else: | |
cancelEdit() | |
activate(block="true") | |
except Exception, err: | |
print >> sys.stderr, "-- Exception occurred --" | |
print >> sys.stderr, err | |
dumpStack() | |
print >> sys.stderr, "-- Ended with exception --" | |
finally: # old python version need this, sux! | |
disconnect() | |
exit() | |
################################### MAIN ########################################################### | |
def main(argv=None): | |
''' | |
Main method | |
''' | |
global env | |
global username | |
global password | |
global url | |
if argv is None: | |
argv = sys.argv | |
opts, args = getopt.getopt(argv[1:], "c:q:e:h", ["createScript", "createQueue", "environment", "help"]) | |
for opt,arg in opts: | |
if opt in ("-c","--createScript"): | |
env = arg | |
createJMSFoldersFile() | |
elif opt in ("-q", "--createQueue"): | |
env = arg | |
username = args[0] | |
password = args[1] | |
url = args[2] | |
onlineExecution() | |
elif opt in ("-h", "--help"): | |
print "Looking for help ? try -> www.google.com" | |
print "Usage: ./createJMSResources.py [option]" | |
print "OPTIONS:" | |
print "-q or --createQueue [environment] [username] [password] [url\:port]" | |
print "-c or --createScript [environment]" | |
else: | |
assert False, "Unhandled option" | |
#################################### END OF FUNCTIONS ############################################## | |
if __name__ == "__main__": | |
sys.exit(main()) | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment