Monday, November 12, 2012

start/stop/activate/retire composites using wlst

Here is a script for doing the state change for a deployed composite. This is a generic python script which will cater the requirement for start/stop/retire/activate any number of composites at a time

Step1 :
Create a property file, specify the server connection details, the list of composites and the action required on them

========= composite.properties ==================

url=t3://localhost:7001
host=localhost
port=8001
username=weblogic
password=weblogic1

COMPOSITES=default/SampleCursorRef/1.0,default/ReloadProcess/1.0
operation=retire

========== end of composite.properties =============

Step 2 :
Create the following python script

=================StateChange.py===============
from java.io import FileInputStream
propInputStream = FileInputStream("D:\\tech\\wlst\\composite.properties")
configProps = Properties()
configProps.load(propInputStream)
url = configProps.get("url")
print 'url=', url
host = configProps.get("host")
print 'host=', host
port = configProps.get("port")
print 'port=', port
username = configProps.get("username")
print 'username=', username
password = configProps.get("password")
print 'password = ', password
operation = configProps.get("operation")
print 'operation = ', operation

print '========================'
print 'host=', host
COMPOSITES = configProps.get("COMPOSITES")
print 'COMPOSITES = ', COMPOSITES
print 'host=', host
compositeList=COMPOSITES.split(',')
print compositeList[1]
count = 0
for i in compositeList:
   compositeProps = compositeList[count].split("/")
   partition = compositeProps[0]
   compoisteName = compositeProps[1]
   version = compositeProps[2]
   print 'partition ..',partition
   print 'newPartition..',newPartition
   print 'compoisteName ..',compoisteName
   print 'version ..',version
   print '========================'
   
   print 'trying to  ',operation ,'the', compoisteName
   try:
if operation=='start':
sca_startComposite(host, port, username, password, compoisteName, version)
elif operation=='stop':
sca_stopComposite(host, port, username, password, compoisteName, version)
elif operation=='activate':
sca_activateComposite(host, port, username, password, compoisteName, version)
elif operation=='retire':
sca_retireComposite(host, port, username, password, compoisteName, version)
else:
   print '=======DO NOTHING ========='
   except NameError, e:
print 'EXCEPTION OCCURED'
print "Please check there is: ", sys.exc_info()[0], sys.exc_info()[1]
   else:
print 'Completed the action on ',compoisteName
   count = count+1
=================end of StateChange.py============

Step3: Open a command promt and start the wslt command from D:\Oracle\Middleware\Oracle_SOA1\common\bin as follows  

D:\Oracle\Middleware\Oracle_SOA1\common\bin>wlst.cmd

This will start the wslt engine . Now execute the python script from the wlst prompt as follows
wls:/offline> execfile('D:\\tech\wlst\\StateChange.py')

To do start/stop/activate change the value for operation in the composite.properties file

Sample result
===================== 
trying to   retire the ReloadProcess
host = localhost
port = 8001
user = weblogic
partition = default
compositeName = ReloadProcess
revision = 1.0
label =  None
compositeDN =default/ReloadProcess!1.0
Connecting to: service:jmx:t3://localhost:8001/jndi/weblo
Composite (default/ReloadProcess!1.0) is successfully ret
Completed the action on  ReloadProcess
=======================================


1 comment: