Wednesday, July 15, 2009

WLST Scripting: Know More on it: Eg.

### Script to create WebLogic Domain(s) from csv file
02.### Reusable Definitions
03.def buildDomain():
04. ### Read Basic Template
05. readTemplate(WL_HOME+"/common/templates/domains/wls.jar")
06. cd('Servers/AdminServer')
07. set('ListenAddress', adminServerAddress)
08. set('ListenPort', int(adminServerPort))
09. ### Create Admin User
10. cd('/')
11. cd('Security/base_domain/User')
12. delete('weblogic','User')
13. create(adminUser,'User')
14. cd(adminUser)
15. set('Password',adminPassword)
16. set('IsDefaultAdmin',1)
17. ### Write Domain
18. setOption('OverwriteDomain', 'true')
19. writeDomain(domainLocation+'/'+domainName)
20. closeTemplate()
21.def printConfirmation():
22. ### Print Confirmation
23. print ""
24. print "Created Domain With Following Values"
25. print "Domain Name = %s " % domainName
26. print "Domain Location = %s " % domainLocation
27. print "Admin User = %s " % adminUser
28. print "Admin Password = %s " % adminPassword
29. print "Admin Server Address = %s " % adminServerAddress
30. print "Admin Server port = %s " % adminServerPort
31.### Executable Script
32.### CreateDomain.py
33.import sys
34.### Define constants
35.WL_HOME = "/products/beaSB/wlserver_10.0"
36.### Read the command-line arguments
37.argslength = len(sys.argv)
38.if argslength < 2 :
39. print '==>Insufficient arguments'
40. print '==>Syntax: java weblogic.WLST CreateDomain.py csv.file'
41. exit()
42.else:
43. ### Read the csv file
44. fileName = sys.argv[1]
45. print('Reading File \"' + fileName + '\"' )
46. f = open(fileName)
47. try:
48. for line in f.readlines():
49. ### Strip the comment lines
50. if line.strip().startswith('#'):
51. continue
52. else:
53. ### Split the comma seperated values
54. items = line.split(',')
55. items = [item.strip() for item in items]
56. if len(items) != 6:
57. print "==>Bad line: %s" % line
58. print "==>Syntax: domainName, domainLocation, adminUser, adminPassword, adminServerAddress, adminServerPort"
59. else:
60. (domainName, domainLocation, adminUser, adminPassword, adminServerAddress, adminServerPort) = items
61.
62. ### Call the definition buildDomain
63. buildDomain()
64. ### Call the definition printConfirmation
65. printConfirmation()
66. except Exception, e:
67. print "==>Error Occured"
68. print e
69.exit()

No comments: