Advertisement
Guest User

Untitled

a guest
Mar 4th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.27 KB | None | 0 0
  1. #####################################################################
  2. # WLST Script to configure Weblogic 12c Domain for Oracle Retail Java Applications 16.0
  3. #
  4. # USAGE
  5. # . $WLS_HOME/server/bin/setWLSEnv.sh
  6. # cd /tmp
  7. # java -Xms2G -Xmx2G weblogic.WLST /tmp/01_create_domain.py -p domain.properties
  8. #
  9. # domain.properties
  10. # -----------------
  11. # DOMAIN=<DOMAIN_NAMW>
  12. # ADMIN_PASSWORD=<WEBLOGIC_ADMIN_PASSWORD>
  13. # MANAGED_SERVER=<MANAGED_SERVERNAME>
  14. # ADMIN_PORT=<ADMINSERVER_PORT>
  15. # MANAGED_SERVER_PORT=<MANAGED_SERVER_PORT>
  16. # COHERENCE_PORT=<COHERENCE_PORT>
  17. # NM_PORT=<NODE_MANAGER_PORT>
  18. # REPOS_DBURL=jdbc:oracle:thin:@//<HOSTNAME_FQDN>:<LISTENER_PORT>/ORACLE_SID
  19. # REPOS_DBUSER_PREFIX=<REPOS_SCHEMA_NAME>
  20. # REPOS_DBPASSWORD=<REPOS_SCHEMA_PASSWORD>
  21. #
  22. ##########################################################################################
  23. ## Parameters
  24. ##########################################################################################
  25.  
  26. import time
  27. import getopt
  28. import sys
  29. import re
  30.  
  31. # Get location of the properties file.
  32. properties = ''
  33. try:
  34. opts, args = getopt.getopt(sys.argv[1:],"p:h::",["properies="])
  35. except getopt.GetoptError:
  36. print '01_create_domain.py -p '
  37. sys.exit(2)
  38. for opt, arg in opts:
  39. if opt == '-h':
  40. print '01_create_domain.py -p '
  41. sys.exit()
  42. elif opt in ("-p", "--properties"):
  43. properties = arg
  44. print 'properties=', properties
  45.  
  46. # Load the properties from the properties file.
  47. from java.io import FileInputStream
  48.  
  49. propInputStream = FileInputStream(properties)
  50. configProps = Properties()
  51. configProps.load(propInputStream)
  52.  
  53. # Set all variables from values in properties file.
  54. DOMAIN=configProps.get("DOMAIN")
  55. ADMIN_PASSWORD=configProps.get("ADMIN_PASSWORD")
  56. MANAGED_SERVER=configProps.get("MANAGED_SERVER")
  57. ADMIN_PORT=int(configProps.get("ADMIN_PORT"))
  58. MANAGED_SERVER_PORT=int(configProps.get("MANAGED_SERVER_PORT"))
  59. COHERENCE_PORT=int(configProps.get("COHERENCE_PORT"))
  60. NM_PORT=int(configProps.get("NM_PORT"))
  61. REPOS_DBURL=configProps.get("REPOS_DBURL")
  62. REPOS_DBUSER_PREFIX=configProps.get("REPOS_DBUSER_PREFIX")
  63. REPOS_DBPASSWORD=configProps.get("REPOS_DBPASSWORD")
  64.  
  65. #Static variables
  66. MACHINE_NAME = os.environ["HOSTNAME"]
  67. DOMAIN_PATH = '/u01/app/oracle/config/domains/'
  68. APP_PATH = '/u01/app/oracle/config/applications/'
  69. MW_HOME = '/u01/app/oracle/middleware/'
  70. START_MODE = 'prod'
  71. DOMAIN_MODE = 'Compact'
  72. CROSSDOMAIN_ENABLED = false
  73. NM_TYPE = 'ssl'
  74. ADMIN_SERVER = 'AdminServer'
  75. ADMIN_USERNAME = 'weblogic'
  76.  
  77. # Display the variable values.
  78. print 'MACHINE_NAME=',MACHINE_NAME
  79. print 'MW_HOME=',MW_HOME
  80. print 'APP_PATH=',APP_PATH
  81. print 'START_MODE=',START_MODE
  82. print 'DOMAIN=', DOMAIN
  83. print 'DOMAIN_PATH=',DOMAIN_PATH
  84. print 'DOMAIN_MODE=',DOMAIN_MODE
  85. print 'CROSSDOMAIN_ENABLED=',CROSSDOMAIN_ENABLED
  86. print 'ADMIN_USERNAME=',ADMIN_USERNAME
  87. print 'ADMIN_PASSWORD=', ADMIN_PASSWORD
  88. print 'ADMIN_SERVER=',ADMIN_SERVER
  89. print 'ADMIN_PORT=', ADMIN_PORT
  90. print 'COHERENCE_PORT=', COHERENCE_PORT
  91. print 'MANAGED_SERVER=', MANAGED_SERVER
  92. print 'MANAGED_SERVER_PORT=', MANAGED_SERVER_PORT
  93. print 'NM_TYPE=',NM_TYPE
  94. print 'NM_PORT=', NM_PORT
  95. print 'REPOS_DBURL=', REPOS_DBURL
  96. print 'REPOS_DBUSER_PREFIX=', REPOS_DBUSER_PREFIX
  97. print 'REPOS_DBPASSWORD=', REPOS_DBPASSWORD
  98.  
  99. ##########################################################################################
  100. def alterDatasource(datasource_name, schema_sufix, driver_name):
  101. cd('/JDBCSystemResource/' + datasource_name + '/JdbcResource/' + datasource_name + '/JDBCDriverParams/NO_NAME_0')
  102. set('URL',REPOS_DBURL)
  103. set('PasswordEncrypted',REPOS_DBPASSWORD)
  104. if driver_name:
  105. set('DriverName', driver_name)
  106. cd('Properties/NO_NAME_0/Property/user')
  107. set('Value',REPOS_DBUSER_PREFIX+'_'+schema_sufix)
  108.  
  109. def defineServer(default_name, new_name, machine_name, address, port):
  110. cd('/Servers')
  111. servers = ls()
  112. if (servers.find(default_name) != -1):
  113. print 'Server ' + default_name + ' already exists'
  114. cd('/Servers/' + default_name)
  115. if machine_name != '' :
  116. set('Machine', machine_name)
  117. set('ListenAddress', address)
  118. set('ListenPort',port)
  119. set('Name',new_name)
  120. else:
  121. print 'Server ' + default_name + ' does not exist. ' + new_name + ' will be created exists'
  122. cd('/')
  123. create(new_name, 'Server')
  124. cd('/Servers/' + new_name)
  125. if machine_name != '' :
  126. set('Machine', machine_name)
  127. set('ListenAddress', address)
  128. set('ListenPort',port)
  129.  
  130. def createBootPropertiesFile(domain_dir, username, password) :
  131. if not os.path.exists(domain_dir + "/servers/" + "AdminServer" + "/security"):
  132. os.makedirs(domain_dir + "/servers/" + "AdminServer" + "/security")
  133. filename=(domain_dir + "/servers/" + "AdminServer" + "/security/boot.properties")
  134. f=open(filename, 'w')
  135. line='username=' + username + '\n'
  136. f.write(line)
  137. line='password=' + password + '\n'
  138. f.write(line)
  139. f.close()
  140. else:
  141. print 'domain_dir + "/servers/" + "AdminServer" + "/security" exists'
  142.  
  143. print 'Creating Domain'
  144.  
  145. readTemplate(MW_HOME + 'wlserver/common/templates/wls/wls.jar',DOMAIN_MODE)
  146.  
  147. setOption('ServerStartMode', START_MODE)
  148. setOption('AppDir', APP_PATH + DOMAIN )
  149.  
  150. cd('/')
  151. cd('Security/base_domain/User/weblogic')
  152. set('Name',ADMIN_USERNAME)
  153. cmo.setPassword(ADMIN_PASSWORD)
  154.  
  155. if CROSSDOMAIN_ENABLED == true:
  156. create('base_domain','SecurityConfiguration')
  157. cd('/SecurityConfiguration/base_domain')
  158. set('CrossDomainSecurityEnabled',true)
  159.  
  160. try:
  161. cd('/')
  162. create(MACHINE_NAME, 'Machine')
  163. except BeanAlreadyExistsException:
  164. print 'Machine ' + MACHINE_NAME + ' already exists'
  165.  
  166. cd('Machine/' + MACHINE_NAME)
  167. create(MACHINE_NAME, 'NodeManager')
  168. cd('NodeManager/' + MACHINE_NAME)
  169. set('ListenAddress',MACHINE_NAME)
  170. set('ListenPort',NM_PORT)
  171. set('NMType',NM_TYPE)
  172.  
  173. defineServer(ADMIN_SERVER, ADMIN_SERVER, MACHINE_NAME, MACHINE_NAME, ADMIN_PORT)
  174. writeDomain(DOMAIN_PATH + DOMAIN)
  175. closeTemplate()
  176.  
  177. print 'Adding Templates'
  178.  
  179. readDomain(DOMAIN_PATH + DOMAIN)
  180. addTemplate(MW_HOME + 'oracle_common/common/templates/wls/oracle.jrf_template.jar')
  181. addTemplate(MW_HOME + 'em/common/templates/wls/oracle.em_wls_template.jar')
  182. addTemplate(MW_HOME + 'oracle_common/common/templates/wls/oracle.wsmpm_template.jar')
  183.  
  184. print 'Creating Resources'
  185. defineServer(MANAGED_SERVER, MANAGED_SERVER, MACHINE_NAME, MACHINE_NAME, MANAGED_SERVER_PORT)
  186.  
  187. print 'Change datasource LocalScvTblDataSource'
  188. cd('/JDBCSystemResource/LocalSvcTblDataSource/JdbcResource/LocalSvcTblDataSource/JDBCDriverParams/NO_NAME_0')
  189. set('URL',REPOS_DBURL)
  190. set('PasswordEncrypted',REPOS_DBPASSWORD)
  191. cd('Properties/NO_NAME_0/Property/user')
  192. set('Value',REPOS_DBUSER_PREFIX+'_STB')
  193.  
  194. print 'Change Coherence Cluster UnicastListenPort'
  195. cd ('/CoherenceClusterSystemResource/defaultCoherenceCluster/CoherenceResource/defaultCoherenceCluster/CoherenceClusterParams/NO_NAME_0')
  196. set('UnicastListenPort',COHERENCE_PORT)
  197.  
  198. print 'Call getDatabaseDefaults which reads the service table'
  199. getDatabaseDefaults()
  200.  
  201. alterDatasource('opss-data-source', 'OPSS', 'oracle.jdbc.OracleDriver')
  202. alterDatasource('opss-audit-DBDS', 'IAU_APPEND', 'oracle.jdbc.OracleDriver')
  203. alterDatasource('opss-audit-viewDS', 'IAU_VIEWER', 'oracle.jdbc.OracleDriver')
  204. alterDatasource('LocalSvcTblDataSource', 'STB', 'oracle.jdbc.OracleDriver')
  205.  
  206. print 'Add server groups JRF-MAN-SVR to Managed Server'
  207. serverGroup = ["JRF-MAN-SVR"]
  208. setServerGroups(MANAGED_SERVER, serverGroup)
  209.  
  210. updateDomain()
  211. closeDomain()
  212. dumpStack()
  213.  
  214. print 'Creating boot.properties file'
  215. createBootPropertiesFile(DOMAIN_PATH+'/'+DOMAIN,ADMIN_USERNAME,ADMIN_PASSWORD)
  216.  
  217. print('Exiting...')
  218. exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement