Search This Blog

Saturday, 27 October 2012

WLST (weblogic scripting tool)

Wlst is a kind of scripting tool which is a combination of jython language.  If you want to edit manged server name or some port number or you want to add  cluser or you want to configure jdbc or you  want to configure jms . How exactly we can do? By using only admin console.  By editing config.xml.  Apart from that ......  We can create and we can work with our domain using WLST.
We can work with any of these components using wlst . This wlst is like your admin console but instead of woking with console we will work with commands. Some times for security reasons console might be disabled in some environments.
What is wlst? 
Different modes of wlst?
What are the features of wlst?
 Diff b/w offline and online modes?
 Advantages of wlst ?  
MBean Architecture? 
How to create a domain using wlst?
Wlst is used only for weblogic server. Python is a oops language. Jython is Embedded scripting language. Wlst is a combination of both python and jython. Basically the syntax is python and it is embedded with jython.
      The WebLogic Scripting Tool (WLST) is a command-line scripting environment that you can use to create, manage, and monitor WebLogic Server domains. It is based on the Java scripting interpreter, Jython. 
 In addition to supporting standard Jython features such as local variables, conditional variables, and flow control statements, WLST provides a set of scripting functions (commands) that are specific to WebLogic Server. 
You can use WLST as the command-line equivalent to the WebLogic Server Administration Console (WLST online) or as the command-line equivalent to the Configuration Wizard (WLST offline).
Three types of modes : 1) Interactive mode. 2) Scripting 3) Embedded.    
Interactive mode: In which you enter a command and view the response at a command-line prompt, is useful for learning the tool, prototyping command syntax, and verifying configuration options before building a script. Using WLST interactively is particularly useful for getting immediate feedback after making a critical configuration change. The WLST scripting shell maintains a persistent connection with an instance of WebLogic Server..
Script Mode: Scripts invoke a sequence of WLST commands without requiring your input, much like a shell script. Scripts contain WLST commands in a text file with a .py file extension, for example, filename.py. You use script files with the Jython commands for running script.
Embedded mode, you instantiate the WLST interpreter in your Java code and use it to run WLST commands and scripts. All WLST commands and variables that you use in interactive and script mode can be run in embedded mode.  We don’t use this mode generally.
To invoke the wlst go to /bea/weblogic91/common/bin /wlst.cmd  and execute wlst.cmd      
Executing WLST Script file:

1. java weblogic.WLST filePath.py

2. java weblogic.WLST Initializing WebLogic Scripting Tool (WLST) ... ...  
wls:/(offline)> execfile(‘/home/example.py') starting the script ...           

 
WLST- Online/Offline
You can use WLST as the command-line equivalent to the WebLogic Server Administration Console (WLST online) or as the command-line equivalent to the Configuration Wizard (WLST offline).
Online: You can use WLST to connect to a running Administration Server and manage the configuration of an active domain, view performance data about resources in the domain, or manage security data (such as adding or removing users). You can also use WLST to connect to Managed Servers, but you cannot modify configuration data from Managed Servers.
Offline: Without connecting to a running WebLogic Server instance, you can use WLST to create domain templates, create a new domain based on existing templates, or extend an existing, inactive domain. You cannot use WLST offline to view performance data about resources in a domain or modify security data (such as adding or removing users).                                              
Display help information for WLST commands by entering the help command:
help(‘online’)
help(‘offline’)
wls:/offline> help()
WLST is a command line scripting tool to configure and administer WebLogic Server.
Try: help('all') List all WLST commands available.
help('browse') List commands for browsing the hierarchy.
help('common') List the most commonly used commands.
help('control') List commands for controlling the domain/server.
help('deployment') List commands for deploying applications.
help('diagnostics') List commands for performing diagnostics.
help('editing') List commands for editing the configuration.
help('information') List commands for displaying information.
help('lifecycle') List commands for managing life cycle.
help('nodemanager') List commands for using Node Manager.
help('offline') List all offline commands available.
help('online') List all online commands available.
help('storeadmin') List all store admin commands.
help('trees') List commands use to navigate MBean hierarchy.
help('variables') List all global variables available.
Features -Advantages

Easily move resources from one Domain to another
Make reliable changes to config.xml without a running server
Use WLST in conjunction with any java utility tools (e.g. ant, jython scripts)
Extend WLST to add any Custom commands
WLST helps in retrieving MBeans names in a similar fashion to navigating
hierarchy of files in a file system.
Configuration MBean Hierarchy

Configuration MBean Hierarchy
Domain MBean (root)
|---MBeantype (LogMBean)
|---MBeaninstance (medrec)
|---MBeanattributes & operations (e.g. FileName)
|---MBeantype (SecurityConfigurationMBean)
|---MBeantype (ServerMBean)
|---MBeaninstance (ManagedServer1)
|---MBeanattributes & operations (e.g.AutoRestart)
When WLST first connects to an instance of WebLogic Server, cmo is initialized to the root of all configuration management objects: DomainMBean.MBean type, the value of cmo reflects the parent MBean.
MBean name, gives the name of the mbean object.

Edit Configuration MBeans
DomainMBean root contains editable copy of all configuration MBeans in the domain. The “change management process” controls distributing configuration changes in a domain representing a DB transactionedit()- used to create, delete, get, set, invoke
startEdit() - initiates modifications that are treated as a part of a batch change that is not committed to the repository until you enter the save command.
validate() - ensures that changes are valid before saving
save() - saves your changes to a pending version
activate() - initiates the distribution of the changes and releases the loc
stopEdit() - stops the current editing session and releases edit lock.
isRestartRequired(‘true’) - determines if a change made to an MBean attribute requires re-start 




Deployment using WLST.

deploy.py

print '***********************************************************************'
connect('weblogic','weblogic','t3://localhost:7001')
print '***********************************************************************'
edit()
print '***********************************************************************'
startEdit()
print '***********************************************************************'
print '***********************************************************************'
deploy('benefits','/home/application/benefits.war',targets="ms1,ms2")
print '***********************************************************************'
save()
print '***********************************************************************'
activate()
print '***********************************************************************'
disconnect()

Undeploying Application using wlst

./wlst.sh undeploy.py

connect('weblogic','weblogic','t3://localhost:8001')
print "undeploying application........."
undeploy('benefits')
print "........................."
disconnect()
exit()

Deployed Application status using wlst

print "deployed application status"
connect('weblogic','weblogic','t3://localhost:8001')
print "**************Deployed application status****************"
ls('AppDeployments')
print "*********************************************************"
disconnect()
exit()

Creating Domain using WLST

print "Reading existing domain....."
readDomain('/home/bea/user_projects/domains/prod_domain')
print "Writing the existing domain into template file...."
writeTemplate('/home/bea/user_projects/domains/prod_new_domain.jar')
print "closing the Domain ..........."
closeDomain()
print "Creating new domain with newly created template file.............."
createDomain('/home/bea/user_projects/domains/prod_new_domain.jar','/home/bea/user_projects/domains/prod_new_domain','weblogic','weblogic')

Checking the server health using WLST

connect('weblogic','weblogic','t3://localhost:7001')
domainRuntime()
cd('ServerRuntimes')
servers=domainRuntimeService.getServerRuntimes()
for server in servers:
        serverName=server.getName();
        print '**************************************************\n'
        print '##############   ',serverName,    '###############'
        print '**************************************************\n'
        print '##### Server State           #####', server.getState()
        print '##### Server ListenAddress   #####', server.getListenAddress()
        print '##### Server ListenPort      #####', server.getListenPort()
        print '##### Server Health State    #####', server.getHealthState()


exit()


Starting admin server using Nodemanger/ From remote location

Open nodemanager.properties file which is located at /home/bea/weblogic91/common/nodemanager  and change the below entry
SecureListener=false

Loging to console : Navigate to Machines->Machine-1->Node Manager-> Type : Plain




Step 1) cd /home/bea/weblogic92/common/bin
           ./wlst.sh
Step 2) Start Node manager :
           i) /home/bea/weblogic92/server/bin/startNodeManager.sh
            or
           ii)  startNodeManager(verbose='true', NodeManagerHome='/home/bea/weblogic92/common/nodemanager',ListenPort='5556', ListenAddress='localhost')
Step 3) Connect to Nodemanager
        wls:/offline> nmConnect('weblogic', 'weblogic', 'localhost', '5556', 'dev_domain','/home/bea/user_projects/domains/dev_domain','plain')
Connecting to Node Manager ...
Successfully Connected to Node Manager.

Step 4) start AdminServer
     wls:/nm/dev_domain>  prps = makePropertiesObject('weblogic.ListenPort=7001')
wls:/nm/dev_domain>  nmStart('AdminServer',props=prps)
Starting server AdminServer ...
Successfully started server AdminServer ...

Checking the server status using nodemanager


wls:/nm/dev_domain> nmServerStatus('AdminServer')

RUNNING


To Kill server using Nodemanager

wls:/nm/dev_domain> nmKill('AdminServer')
Killing server AdminServer ...
Successfully killed server AdminServer ...


To check nodemanager version

wls:/nm/dev_domain> nmVersion()
The Node Manager version that you are currently connected to is 9.2.3.0.

To stop nodemanger

stopNodeManager()

Disconnect from nodemanger


nmDisconnect()


Creating users and assigning to groups (usercreation.py)


connect('weblogic','weblogic','t3://localhost:7001')
serverConfig()
cd('/SecurityConfiguration/base_domain/Realms/myrealm/AuthenticationProviders/DefaultAuthenticator')
cmo.createUser('pavan','pavan123',"")
cmo.addMemberToGroup('Administrators','pavan')
disconnect()
exit()

Changing password for existing user (passwordchange.py)

DomainName = "base_domain"

ADMINUrl = "t3://localhost:7001"

ADMINUser = "pavan"

oldPassword = "pavan123"

newPassword = "pavan456"

print  '*****************'
connect(ADMINUser,oldPassword,ADMINUrl)

cd('/SecurityConfiguration/'+DomainName+'/Realms/myrealm/AuthenticationProviders/DefaultAuthenticator')

cmo.resetUserPassword(ADMINUser,newPassword)

print  '*****************'

disconnect()

print '*** connecting with new password***......................................'


connect(ADMINUser,newPassword,ADMINUrl)


How to delete a message from JMS queue

connect('weblogic', 'weblogic', 't3://localhost:7003')
serverRuntime()
cd('/JMSRuntime/MS1.jms/JMSServers/dizzyworldJMSServer/Destinations/DizzyworldJMSModule!dizzyworldqueue')
cmo.deleteMessages('')



  

1 comment:

sunil choudhary said...

Excellent post. You have shared some wonderful tips. I completely agree with you that it is important for any blogger to help their visitors. Once your visitors find value in your content, they will come back for more How to Run Python Program In Script Mode