Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #####################################################################
- # WLST Script to configure Weblogic 12c Domain for Oracle Retail Java Applications 16.0
- #
- # USAGE
- # . $WLS_HOME/server/bin/setWLSEnv.sh
- # cd /tmp
- # java -Xms2G -Xmx2G weblogic.WLST /tmp/01_create_domain.py -p domain.properties
- #
- # domain.properties
- # -----------------
- # DOMAIN=<DOMAIN_NAMW>
- # ADMIN_PASSWORD=<WEBLOGIC_ADMIN_PASSWORD>
- # MANAGED_SERVER=<MANAGED_SERVERNAME>
- # ADMIN_PORT=<ADMINSERVER_PORT>
- # MANAGED_SERVER_PORT=<MANAGED_SERVER_PORT>
- # COHERENCE_PORT=<COHERENCE_PORT>
- # NM_PORT=<NODE_MANAGER_PORT>
- # REPOS_DBURL=jdbc:oracle:thin:@//<HOSTNAME_FQDN>:<LISTENER_PORT>/ORACLE_SID
- # REPOS_DBUSER_PREFIX=<REPOS_SCHEMA_NAME>
- # REPOS_DBPASSWORD=<REPOS_SCHEMA_PASSWORD>
- #
- ##########################################################################################
- ## Parameters
- ##########################################################################################
- import time
- import getopt
- import sys
- import re
- # Get location of the properties file.
- properties = ''
- try:
- opts, args = getopt.getopt(sys.argv[1:],"p:h::",["properies="])
- except getopt.GetoptError:
- print '01_create_domain.py -p '
- sys.exit(2)
- for opt, arg in opts:
- if opt == '-h':
- print '01_create_domain.py -p '
- sys.exit()
- elif opt in ("-p", "--properties"):
- properties = arg
- print 'properties=', properties
- # Load the properties from the properties file.
- from java.io import FileInputStream
- propInputStream = FileInputStream(properties)
- configProps = Properties()
- configProps.load(propInputStream)
- # Set all variables from values in properties file.
- DOMAIN=configProps.get("DOMAIN")
- ADMIN_PASSWORD=configProps.get("ADMIN_PASSWORD")
- MANAGED_SERVER=configProps.get("MANAGED_SERVER")
- ADMIN_PORT=int(configProps.get("ADMIN_PORT"))
- MANAGED_SERVER_PORT=int(configProps.get("MANAGED_SERVER_PORT"))
- COHERENCE_PORT=int(configProps.get("COHERENCE_PORT"))
- NM_PORT=int(configProps.get("NM_PORT"))
- REPOS_DBURL=configProps.get("REPOS_DBURL")
- REPOS_DBUSER_PREFIX=configProps.get("REPOS_DBUSER_PREFIX")
- REPOS_DBPASSWORD=configProps.get("REPOS_DBPASSWORD")
- #Static variables
- MACHINE_NAME = os.environ["HOSTNAME"]
- DOMAIN_PATH = '/u01/app/oracle/config/domains/'
- APP_PATH = '/u01/app/oracle/config/applications/'
- MW_HOME = '/u01/app/oracle/middleware/'
- START_MODE = 'prod'
- DOMAIN_MODE = 'Compact'
- CROSSDOMAIN_ENABLED = false
- NM_TYPE = 'ssl'
- ADMIN_SERVER = 'AdminServer'
- ADMIN_USERNAME = 'weblogic'
- # Display the variable values.
- print 'MACHINE_NAME=',MACHINE_NAME
- print 'MW_HOME=',MW_HOME
- print 'APP_PATH=',APP_PATH
- print 'START_MODE=',START_MODE
- print 'DOMAIN=', DOMAIN
- print 'DOMAIN_PATH=',DOMAIN_PATH
- print 'DOMAIN_MODE=',DOMAIN_MODE
- print 'CROSSDOMAIN_ENABLED=',CROSSDOMAIN_ENABLED
- print 'ADMIN_USERNAME=',ADMIN_USERNAME
- print 'ADMIN_PASSWORD=', ADMIN_PASSWORD
- print 'ADMIN_SERVER=',ADMIN_SERVER
- print 'ADMIN_PORT=', ADMIN_PORT
- print 'COHERENCE_PORT=', COHERENCE_PORT
- print 'MANAGED_SERVER=', MANAGED_SERVER
- print 'MANAGED_SERVER_PORT=', MANAGED_SERVER_PORT
- print 'NM_TYPE=',NM_TYPE
- print 'NM_PORT=', NM_PORT
- print 'REPOS_DBURL=', REPOS_DBURL
- print 'REPOS_DBUSER_PREFIX=', REPOS_DBUSER_PREFIX
- print 'REPOS_DBPASSWORD=', REPOS_DBPASSWORD
- ##########################################################################################
- def alterDatasource(datasource_name, schema_sufix, driver_name):
- cd('/JDBCSystemResource/' + datasource_name + '/JdbcResource/' + datasource_name + '/JDBCDriverParams/NO_NAME_0')
- set('URL',REPOS_DBURL)
- set('PasswordEncrypted',REPOS_DBPASSWORD)
- if driver_name:
- set('DriverName', driver_name)
- cd('Properties/NO_NAME_0/Property/user')
- set('Value',REPOS_DBUSER_PREFIX+'_'+schema_sufix)
- def defineServer(default_name, new_name, machine_name, address, port):
- cd('/Servers')
- servers = ls()
- if (servers.find(default_name) != -1):
- print 'Server ' + default_name + ' already exists'
- cd('/Servers/' + default_name)
- if machine_name != '' :
- set('Machine', machine_name)
- set('ListenAddress', address)
- set('ListenPort',port)
- set('Name',new_name)
- else:
- print 'Server ' + default_name + ' does not exist. ' + new_name + ' will be created exists'
- cd('/')
- create(new_name, 'Server')
- cd('/Servers/' + new_name)
- if machine_name != '' :
- set('Machine', machine_name)
- set('ListenAddress', address)
- set('ListenPort',port)
- def createBootPropertiesFile(domain_dir, username, password) :
- if not os.path.exists(domain_dir + "/servers/" + "AdminServer" + "/security"):
- os.makedirs(domain_dir + "/servers/" + "AdminServer" + "/security")
- filename=(domain_dir + "/servers/" + "AdminServer" + "/security/boot.properties")
- f=open(filename, 'w')
- line='username=' + username + '\n'
- f.write(line)
- line='password=' + password + '\n'
- f.write(line)
- f.close()
- else:
- print 'domain_dir + "/servers/" + "AdminServer" + "/security" exists'
- print 'Creating Domain'
- readTemplate(MW_HOME + 'wlserver/common/templates/wls/wls.jar',DOMAIN_MODE)
- setOption('ServerStartMode', START_MODE)
- setOption('AppDir', APP_PATH + DOMAIN )
- cd('/')
- cd('Security/base_domain/User/weblogic')
- set('Name',ADMIN_USERNAME)
- cmo.setPassword(ADMIN_PASSWORD)
- if CROSSDOMAIN_ENABLED == true:
- create('base_domain','SecurityConfiguration')
- cd('/SecurityConfiguration/base_domain')
- set('CrossDomainSecurityEnabled',true)
- try:
- cd('/')
- create(MACHINE_NAME, 'Machine')
- except BeanAlreadyExistsException:
- print 'Machine ' + MACHINE_NAME + ' already exists'
- cd('Machine/' + MACHINE_NAME)
- create(MACHINE_NAME, 'NodeManager')
- cd('NodeManager/' + MACHINE_NAME)
- set('ListenAddress',MACHINE_NAME)
- set('ListenPort',NM_PORT)
- set('NMType',NM_TYPE)
- defineServer(ADMIN_SERVER, ADMIN_SERVER, MACHINE_NAME, MACHINE_NAME, ADMIN_PORT)
- writeDomain(DOMAIN_PATH + DOMAIN)
- closeTemplate()
- print 'Adding Templates'
- readDomain(DOMAIN_PATH + DOMAIN)
- addTemplate(MW_HOME + 'oracle_common/common/templates/wls/oracle.jrf_template.jar')
- addTemplate(MW_HOME + 'em/common/templates/wls/oracle.em_wls_template.jar')
- addTemplate(MW_HOME + 'oracle_common/common/templates/wls/oracle.wsmpm_template.jar')
- print 'Creating Resources'
- defineServer(MANAGED_SERVER, MANAGED_SERVER, MACHINE_NAME, MACHINE_NAME, MANAGED_SERVER_PORT)
- print 'Change datasource LocalScvTblDataSource'
- cd('/JDBCSystemResource/LocalSvcTblDataSource/JdbcResource/LocalSvcTblDataSource/JDBCDriverParams/NO_NAME_0')
- set('URL',REPOS_DBURL)
- set('PasswordEncrypted',REPOS_DBPASSWORD)
- cd('Properties/NO_NAME_0/Property/user')
- set('Value',REPOS_DBUSER_PREFIX+'_STB')
- print 'Change Coherence Cluster UnicastListenPort'
- cd ('/CoherenceClusterSystemResource/defaultCoherenceCluster/CoherenceResource/defaultCoherenceCluster/CoherenceClusterParams/NO_NAME_0')
- set('UnicastListenPort',COHERENCE_PORT)
- print 'Call getDatabaseDefaults which reads the service table'
- getDatabaseDefaults()
- alterDatasource('opss-data-source', 'OPSS', 'oracle.jdbc.OracleDriver')
- alterDatasource('opss-audit-DBDS', 'IAU_APPEND', 'oracle.jdbc.OracleDriver')
- alterDatasource('opss-audit-viewDS', 'IAU_VIEWER', 'oracle.jdbc.OracleDriver')
- alterDatasource('LocalSvcTblDataSource', 'STB', 'oracle.jdbc.OracleDriver')
- print 'Add server groups JRF-MAN-SVR to Managed Server'
- serverGroup = ["JRF-MAN-SVR"]
- setServerGroups(MANAGED_SERVER, serverGroup)
- updateDomain()
- closeDomain()
- dumpStack()
- print 'Creating boot.properties file'
- createBootPropertiesFile(DOMAIN_PATH+'/'+DOMAIN,ADMIN_USERNAME,ADMIN_PASSWORD)
- print('Exiting...')
- exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement