Hey all wise WLA welcome to this exclusive WLST blog again!
My dear buddies, this week I was invited for a discussion on generic and dynamic domain creation in WebLogic for a development environment. The need of a script that is generic in the sense not specific to any operating environments such as Solaris, Linux, Windows or Mac. And, It should prompt for all the desired inputs to build a basic WebLogic domain in a development environment.
Why Dynamic Domain Script?
- The richness of this script is that, you can use this for your environment directly.
- This is reusable script.
- It is for time saving compare to the regular config.sh execution
- ease of use script
- You can execute on Windows same script can run on Solaris without any changes
Prerequisites and preparation
To execute this script you must define the following:
1. JAVA_HOME define this from WebLogic installation paths
2. WL_HOME define this as WebLogic installation
3. CLASSPATH must have weblogic.jar for running weblogic.WLST
4. PATH must contain JAVA_HOME/bin to run java commands
After setting these you can verify above with echo each environment variable. In Nix platform you can try as:
echo $PATH echo $CLASSPATH echo $WL_HOME echo $JAVA_HOMEIn Windows you can verify it by replace $ with % symbol.
########################################################### # This script will dynamically create the domain as per your inputs # Run on : Oracle WebLogic 8.1, 9.2 10.3 (11g) # Author : Pavan Devarakonda ########################################################### import os WLHOME=os.environ['WL_HOME'] #========================================== # Create a domain from the weblogic domain template. #========================================== readTemplate(WLHOME+'/common/templates/domains/wls.jar') cd('Servers/AdminServer') AdminName=raw_input('Please Enter Admin ServerName: ') set('Name',AdminName) #========================================== # Configure the Administration Server #========================================== AdminListenAdr=raw_input('Please Enter Admin Listen Address: ') AdminListenPort=int(input('Please enter Admin listen Port: ')) set('ListenAddress',AdminListenAdr) set('ListenPort', AdminListenPort) #==================================================== # Define the password for user weblogic. You must define the password before you # can write the domain. #==================================================== cd('/') cd('Security/base_domain/User/weblogic') usr=raw_input('Please Enter AdminUser Name: ') set('Name',usr) AdminPassword=raw_input('Please enter Admin password:') cmo.setPassword(AdminPassword) # - OverwriteDomain: Overwrites domain, when saving, if one exists. setOption('OverwriteDomain', 'true') #============================================== # Write the domain, close template and finally exit from the WLST #============================================== domainPath=raw_input('Enter the domain path: ') domainName=raw_input('Enter domain name: ') print 'Given domain path, name : ', domainPath, domainName writeDomain(domainPath+"/"+domainName) closeTemplate() exit()
Sample Execution
Assume that you saved the above script with the name as "createDomain.py". Of course you can choose your own name for the script!
At your command prompt you can invoke this script as follows:
[WLA@server~/.AdminScripts]$ java weblogic.WLST createDomain.py Initializing WebLogic Scripting Tool (WLST) ... Welcome to WebLogic Server Administration Scripting Shell Type help() for help on available commands Please Enter Admin ServerName: testAdmin Please Enter Admin Listen Address: 127.0.0.1 Please enter Admin listen Port: 8007 Please Enter AdminUser Name: system Please enter Admin password:weblogic103 Enter the domain path: /home/wluser/domains/ Enter domain name: testdomain Given domain path, name : /home/wluser/domains/testdomain Exiting WebLogic Scripting Tool. [WLA@server~/.AdminScripts]$ cd ../domains [WLA@server~/domains]$ ls nmdomain103 testdomain
If you want the same thing without interactive mode, you just want to change the values you don't want to change the Python script for customizing your WebLogic domain then you can use properties file as shown below:
# File: myWLSTdom.properties domainTemplate=c:/wls12c/wlserver/common/templates/domains/wls.jar #Following property is the default property and should not be changed. weblogicdomainpasspath=Security/base_domain/User/weblogic adminUser=weblogic adminPassword=weblogic123$ adminServerName=admin_myWLSTdom adminServerListenaddr=localhost admlistenport=7100 OverwriteDomain=true domainName=myWLSTdom domainHome=/wldomains/myWLSTdom
Creating WLST base domain |
Now let use the properties file and have simple adminserver configurations can be customized with set function.
loadProperties('myWLSTdom.properties') readTemplate(domainTemplate) def printInStyle(txt): print'-'*10 +txt cd('Servers/AdminServer') printInStyle('Give your custom AdminServer name') set('Name',adminServerName) printInStyle('Set the ListenAddress and ListenPort') set('ListenAddress',adminServerListenaddr) set('ListenPort', int(admlistenport)) # Security printInStyle('Creating Password') cd('/') cd(weblogicdomainpasspath) cmo.setPassword(adminPassword) printInStyle('Setting StartUp Options') setOption('OverwriteDomain', OverwriteDomain) # Create Domain to File System printInStyle('Writing Domain To File System') # Change the path to your domain accordingly writeDomain(domainHome) closeTemplate() # Exiting print('Exiting now...') exit()Little cosmotizing with function 'printInStyle', here we can give any symbol then we can have multiple times the number you postfix to the '*'. In the above we had 10 times '-' symbol is printed then the text message.
C:\pbin>java weblogic.WLST -skipWLSModuleScanning create_basedomain.py Initializing WebLogic Scripting Tool (WLST) ... Welcome to WebLogic Server Administration Scripting Shell Type help() for help on available commands ----------Give your custom AdminServer name ----------Set the ListenAddress and ListenPort ----------Creating Password ----------Setting StartUp Options ----------Writing Domain To File System Exiting now... Exiting WebLogic Scripting Tool.
Create Production Domain with WLST
A base WebLogic domain in production mode with generic option using properties file. If you compare with the above script this is having properties and more generic. We have experimented this script with Windows and Linux platforms.
readTemplate(TMPLATE) cd('/') cmo.setName(DOMAIN_NAME) cd('Servers/AdminServer') cmo.setListenAddress(ADMIN_LISTENADDRESS) cmo.setListenPort(int(ADMIN_PORT)) cd( '/' ) cd( 'Security/'+DOMAIN_NAME+'/User/' +ADMIN_USER) cmo.setPassword(ADMIN_PWD) cd('/') setOption("ServerStartMode", "prod") setOption("OverwriteDomain", "true") writeDomain( DOMAIN_DIR+’/'+DOMAIN_NAME ) closeTemplate()
Let me try with the WebLogic 11g version, if you have latest 12c then the domain template path changes as C:/Oracle/Middleware/wlserver/common/templates/wls/wls.jar
If you are using vagrant box use /home/vagrant/fmw/oraclehome/wlserver/common/teplates/wls/wls.jar
The sample properties file looks like this:
TMPLATE = 'C:/Oracle/Middleware/wlserver_10.3/common/templates/domains/wls.jar' ADMIN_PORT = 8001 ADMIN_PWD = weblogic123 ADMIN_USER = weblogic DOMAIN_DIR = C:/wlsdomains DOMAIN_NAME = NC_DOMAIN ADMIN_LISTENADDRESS = 192.168.1.18
java weblogic.WLST -loadProperties ncdomain.properties createproddomain.py
Confirmation of the Domain creation as following screen shot:
WebLogic production domain created with WLST |
Suggestions and improvements
1. You can improve this script for Clustered environment.
2. You can add more functions for each resource configurations such as JDBC DataSource, JMS, and application deployment
3. Verifying the given domain path is also recommended
4. The python script must have exception handling I mean there should try: except: blocks to make more robust.
Buddy you can extend your domain template using pack and unpack commands.
hi,
ReplyDeleteI have WLST question. We are upgrading from 10.3.0.0. to 10.3.5.0. Is there a need to update WLST scripts? I mean is there any changes in WLST since 10.3.0.0?
Thanks,
Priya, most of the scripts works, only you need to change connect() parameters. Cluster using scripts need to double check all the servers must be in RUNNING state.
ReplyDeletewhat all the scripts using?
I am a newbie to weblogic. I took a sample Weblogic Script and i am unable to run that script. Can you please explain me in detail with an example.
ReplyDeleteThanks...
Hi which parameter need to bee added in the above scripts to configure weblogic domain with SOA components?
ReplyDeleteRajesh,
ReplyDeleteThanks for writing, if you are configuring a SOA Domain, we can use as it is script to create the domain and it will be standalone server domain, that is like development domain, where you can select the parameters for deployment of SCA composites that require for your SOA project needs. Alternatively you can use the cluster of managed servers with desired common configurations after this base domain configurations with the link : http://wlstbyexamples.blogspot.in/2013/01/cluster-manuplation-with-wlst.html. write back if you need more details.
Any idea set up security boot strap by WLST to let production server start bypass username and password requirement?
ReplyDeleteHi Pavan,
ReplyDeleteI created the domain with sample domain script, but i could bring up the admin server I am receiving an error : The server name AdminServer specefied with -Dweblogic.Name does not exist. The configuration include
the following servers {mgsmAdm}.
its not working
ReplyDeleteInitializing WebLogic Scripting Tool (WLST) ...
Welcome to WebLogic Server Administration Scripting Shell
Type help() for help on available commands
Problem invoking WLST - Traceback (innermost last):
(no code object) at line 0
File "/u00/app/oracle/product/fmw/wlserver_10.3.6/common/bin/creatProdDom.py", line 15
writeDomain( DOMAIN_DIR+’/'+DOMAIN_NAME )
^
SyntaxError: Lexical error at line 15, column 25. Encountered: "\u2019" (8217), after : ""
Initializing WebLogic Scripting Tool (WLST) ...
ReplyDeleteWelcome to WebLogic Server Administration Scripting Shell
Type help() for help on available commands
Error: readTemplate() failed. Do dumpStack() to see details.
Problem invoking WLST - Traceback (innermost last):
File "/u00/app/oracle/product/fmw/wlserver_10.3.6/common/bin/creatProdDom.py", line 2, in ?
File "/tmp/WLSTOfflineIni7979487040503813589.py", line 17, in readTemplate
The template to read must be a jar file containing a valid domain configuration
at com.oracle.cie.domain.script.jython.CommandExceptionHandler.handleException(CommandExceptionHandler.java:51)
at com.oracle.cie.domain.script.jython.WLScriptContext.handleException(WLScriptContext.java:1538)
at com.oracle.cie.domain.script.jython.WLScriptContext.readTemplate(WLScriptContext.java:340)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
com.oracle.cie.domain.script.jython.WLSTException: com.oracle.cie.domain.script.jython.WLSTException: com.oracle.cie.domain.script.ScriptException: unable to parse "template-info.xml" from template jar "$WLS_HOME/common/templates/domains/wls.jar
The template to read must be a jar file containing a valid domain configuration
@Faheem, You need to check the WL_HOME defined in the .bash_profile or .profile, if not export that with your existing WebLogic installation path. After executing profile then you can proceed for this script execution.
ReplyDeleteI am searching to find guide on creating dynamic domain in wls and thank you for your post.
ReplyDeleteRegards,
WebLogic Training.
Can we use template (.jar) created using pack command or writeTemplete() to create Dynamic Domain? Or only (.jar) created from config builder only will work here?
ReplyDelete@Ajit, It would work for all template jar files.
ReplyDeleteHi,
ReplyDeleteGreat information you have shared and is useful which i dont know.Thanks for sharing this valuable information.weblogic administration online training
Great blog! It is in detail and well structred which made me eassy to understand and also helped me to get new information. weblogic tutorial for beginners
ReplyDeleteI read your blog frequently and I just thought I’d say keep up the amazing work! www.dynamicmarketing.sg/seo-consultant-singapore
ReplyDelete