Guest User

Untitled

a guest
Dec 27th, 2017
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.18 KB | None | 0 0
  1. import os
  2. import sys
  3. from os.path import exists
  4. from sys import argv
  5.  
  6.  
  7. def parsefile():
  8. propfile = "domain.properties"
  9. if exists(propfile):
  10. fo = open(propfile, 'r+')
  11. lines = fo.readlines()
  12. for line in lines:
  13. #print line.rstrip()
  14. if "=" in line:
  15. line = line.rstrip()
  16. key = line.split('=')[0]
  17. value = line.split('=')[1]
  18. _dict[key]=value
  19.  
  20.  
  21. def printdomain():
  22. print '------------------------------'
  23. print "Properties Information"
  24. print '------------------------------'
  25. for key, val in _dict.iteritems():
  26. print key,"=>",val
  27.  
  28. def export_properties():
  29. global _dict
  30. global mwhome
  31. global wlshome
  32. global domainroot
  33. global approot
  34. global domainName
  35. global domain_username
  36. global domain_password
  37. global adminPort
  38. global adminAddress
  39. global adminPortSSL
  40. global adminMachine
  41. global machines
  42. global servers
  43. global clusters
  44. mwhome = _dict.get('mwhome')
  45. wlshome = _dict.get('wlshome')
  46. domainroot = _dict.get('domainroot')
  47. approot = _dict.get('approot')
  48. domainName = _dict.get('domain_name')
  49. domain_username = _dict.get('domain_username')
  50. domain_password = _dict.get('domain_password')
  51.  
  52. adminPort = _dict.get("admin.port")
  53. adminAddress = _dict.get("admin.address")
  54. adminPortSSL = _dict.get("admin.port.ssl")
  55. #adminMachine = _dict.get("admin.machine")
  56.  
  57. machines = _dict.get("machines").split(',')
  58. servers = _dict.get("managedservers").split(',')
  59. clusters = _dict.get("clusters").split(',')
  60.  
  61. def read_template():
  62. # Load the template. Versions < 12.2
  63. try:
  64. readTemplate(wlshome + '/common/templates/wls/wls.jar')
  65. except:
  66. print "Error Reading the Template",wlshome
  67. print "Dumpstack: \n -------------- \n",dumpStack()
  68. sys.exit(2)
  69.  
  70. def create_machine():
  71. try:
  72. cd('/')
  73. for machine in machines:
  74. print "Creating a New Machine with the following Configuration"
  75.  
  76. mn = create(machine,'Machine')
  77. machine_name=_dict.get(machine+'.Name')
  78. if (machine_name != ""):
  79. print "\tMachine Name",machine_name
  80. mn.setName(machine_name)
  81. else:
  82. print "No machine Name mentioned for",machine
  83. except:
  84. print "Creating Machine failed",machine
  85. print "Dumpstack: \n -------------- \n",dumpStack()
  86. sys.exit(2)
  87.  
  88. def create_admin():
  89. try:
  90. print "\nCreating AdminServer with the following Configuraiton"
  91. cd('/Security/base_domain/User/' + domain_username)
  92. cmo.setPassword(domain_password)
  93. cd('/Server/AdminServer')
  94. cmo.setName('AdminServer')
  95. cmo.setListenPort(int(adminPort))
  96. cmo.setListenAddress(adminAddress)
  97. print "\tAdminServer ListenPort:",adminPort
  98. print "\tAdminServer Listenaddress:",adminAddress
  99. print "\tAdminServer SSLListenPort:",adminPortSSL
  100.  
  101. create('AdminServer','SSL')
  102. cd('SSL/AdminServer')
  103. set('Enabled', 'True')
  104. set('ListenPort', int(adminPortSSL))
  105.  
  106. except:
  107. print "Error while creating AdminServer"
  108. print "Dumpstack: \n -------------- \n",dumpStack()
  109.  
  110. def create_managedserver():
  111. try:
  112. cd ('/')
  113. for server in servers:
  114. MSN = _dict.get(server+'.Name')
  115. MSP = _dict.get(server+'.port')
  116. MSA = _dict.get(server+'.address')
  117. MSM = _dict.get(server+'.machine')
  118. print "\nCreating A New Managed Server with following Configuration"
  119. print "\tServerName:",MSN
  120. print "\tServer ListenPort:",MSP
  121. print "\tServer ListenAddress:",MSA
  122. sobj = create(MSN,'Server')
  123. sobj.setName(MSN)
  124. sobj.setListenPort(int(MSP))
  125. sobj.setListenAddress(MSA)
  126.  
  127. #sobj.setMachine(MSM)
  128. except:
  129. print "Error While Creating ManagedServer",server
  130. print "Dumpstack: \n -------------- \n",dumpStack()
  131.  
  132.  
  133. def create_clusters():
  134. try:
  135. cd ('/')
  136. for cluster in clusters:
  137. CN = _dict.get(cluster+'.Name')
  138. cobj = create(CN,'Cluster')
  139. print "\nCreating a New Cluster with the following Configuration"
  140. print "\tClusterName",CN
  141. except:
  142. print "Error while Creating Cluster",cluster
  143. print "Dumpstack: \n -------------- \n",dumpStack()
  144. sys.exit(2)
  145.  
  146. def commit_writedomain():
  147. try:
  148. # If the domain already exists, overwrite the domain
  149. setOption('OverwriteDomain', 'true')
  150.  
  151. setOption('ServerStartMode','prod')
  152. setOption('AppDir', approot + '/' + domainName)
  153.  
  154. writeDomain(domainroot + '/' + domainName)
  155. closeTemplate()
  156.  
  157. except:
  158. print "ERROR: commit_writedomain Failed"
  159. print "Dumpstack: \n -------------- \n",dumpStack()
  160.  
  161. def print_withformat(title):
  162. print "\n-----------------------------------------------------\n",title,"\n-----------------------------------------------------"
  163.  
  164. def print_somelines():
  165. print "-----------------------------------------------------"
  166.  
  167. def print_domainsummary():
  168. print "DomainName:",domainName
  169. print "DomainUserName:",domain_username
  170. print "DomainPassword: ****************"
  171. print "DomainDirectory:",domainroot
  172. print "ApplicationRoot:",approot
  173.  
  174. def start_AdminServer():
  175. try:
  176. global managementurl
  177. managementurl = "t3://"+adminAddress+":"+adminPort
  178. global AdminServerDir
  179. AdminServerDir = domainroot+"/"+domainName+"/servers/AdminServer"
  180. global AdminServerLogDir
  181. AdminServerLog = AdminServerDir+"/logs/AdminServer.log"
  182. global DomainDir
  183. DomainDir = domainroot+"/"+domainName
  184.  
  185. print_somelines()
  186. print "\nStarting Server with following Params"
  187. print_somelines()
  188. print "DomainDir",DomainDir
  189. print "managementurl",managementurl
  190. print_somelines()
  191.  
  192. print "\nRedirecting Startup Logs to",AdminServerLog
  193. startServer('AdminServer',domainName,managementurl,domain_username,domain_password,DomainDir,'true',60000,serverLog=AdminServerLog)
  194.  
  195. print "AdminServer has been successfully Started"
  196. except:
  197. print "ERROR: Unable to Start AdminServer"
  198. print "Dumpstack: \n -------------- \n",dumpStack()
  199.  
  200. def connect_online():
  201. try:
  202. global managementurl
  203. managementurl = "t3://"+adminAddress+":"+adminPort
  204. print "\nConnecting to AdminServer with managementurl",managementurl
  205. connect(domain_username,domain_password,managementurl)
  206. print "\nSuccessfully Connected to AdminServer!!."
  207.  
  208. except:
  209. print "ERROR: Unable to Connect to AdminServer"
  210. sys.exit(2)
  211.  
  212. def acquire_edit_session():
  213. edit()
  214. startEdit()
  215.  
  216. def save_activate_session():
  217. save()
  218. activate()
  219.  
  220. def Enable_wlst_log_redirection():
  221. #wlst output redirect to a logfile
  222. redirect('./wlst_execution.log','false')
  223.  
  224. def Stop_wlst_log_redirection():
  225. stopRedirect()
  226. def map_machines():
  227. #try:
  228. acquire_edit_session()
  229. for machine in machines:
  230. print "Starting to map resources to the machine ",machine
  231. instances = _dict.get(machine+".instances")
  232. #print "INST",instances
  233. if len(instances) > 1:
  234. instances = instances.split(',')
  235. for instance in instances:
  236. if instance == "admin":
  237. instname = "AdminServer"
  238. else:
  239. instname = _dict.get(instance+".Name")
  240. #print "What is the instname",instname
  241. cd ('/Servers/'+instname)
  242. #print "WHARE AM I",pwd()
  243. machine_name=_dict.get(machine+'.Name')
  244. mbean_name='/Machines/'+machine_name
  245. #print "What is Machine MBEAN",mbean_name
  246. cmo.setMachine(getMBean(mbean_name))
  247. else:
  248. instname = _dict.get(instances+".Name")
  249. #print "What is the instname",instname
  250. cd ('/Servers/'+instname)
  251. #print "WHARE AM I",pwd()
  252. machine_name=_dict.get(machine+'.Name')
  253. mbean_name='/Machines/'+machine_name
  254. cmo.setMachine(getMBean(mbean_name))
  255. save_activate_session()
  256.  
  257. def map_clusters():
  258. #try:
  259. acquire_edit_session()
  260. for cluster in clusters:
  261. print "\nStarting to map resources to the cluster ",cluster
  262. members = _dict.get(cluster+".members")
  263. #print "members",members
  264. if len(members) > 1:
  265. members = members.split(',')
  266. for member in members:
  267. if member == "admin":
  268. membername = "AdminServer"
  269. else:
  270. membername = _dict.get(member+".Name")
  271. #print "What is the memberName",membername
  272. cd ('/Servers/'+membername)
  273. #print "WHARE AM I",pwd()
  274. cluster_name=_dict.get(cluster+'.Name')
  275. mbean_name='/Clusters/'+cluster_name
  276. #print "What is Cluster MBEAN",mbean_name
  277. cmo.setCluster(getMBean(mbean_name))
  278. else:
  279. membername = _dict.get(member+".Name")
  280. #print "What is the memberName",membername
  281. cd ('/Servers/'+membername)
  282. #print "WHARE AM I",pwd()
  283. cluster_name=_dict.get(cluster+'.Name')
  284. mbean_name='../../Clusters/'+cluster_name
  285. cmo.setCluster(getMBean(mbean_name))
  286. save_activate_session()
  287. #except:
  288. #print "Machine Creation Failed"
  289.  
  290. if __name__ != "__main__":
  291. _dict={};
  292. Enable_wlst_log_redirection()
  293. print "Start of the script Execution >>"
  294. print "Parsing the properties file..."
  295. parsefile()
  296. print "Exporting the Properties to variables.."
  297. export_properties()
  298. print "Creating Domain from Domain Template..."
  299. read_template()
  300. print_withformat("Creating Machines")
  301. create_machine()
  302. print_somelines()
  303. print_withformat("Creating AdminServer")
  304. create_admin()
  305. print_somelines()
  306. print_withformat("Creating ManagedServers")
  307. create_managedserver()
  308. print_somelines()
  309. print_withformat("Creating Clusters")
  310. create_clusters()
  311. print_somelines()
  312. print "\nCommit and Saving the Domain"
  313. commit_writedomain()
  314. print_withformat("Domain Summary")
  315. print_domainsummary()
  316. print_somelines()
  317. print("Starting the AdminServer")
  318. start_AdminServer()
  319. connect_online()
  320. map_machines()
  321. map_clusters()
  322. print "End of Script Execution << \nGood Bye!"
  323. Stop_wlst_log_redirection()
  324. sys.exit(0)
  325.  
  326. if __name__ == "__main__":
  327. print "This script has to be executed with weblogic WLST"
Add Comment
Please, Sign In to add comment