Hi,

Jay SenSharma

Jay SenSharma

Here we are going to see a very Simple WLST Script to configure the WorkManager with MaxThreadConstraint and MinThreadConstraint and Assigning them to the WorkManager which we created using the same Script.

Step1). Create a Directry some where in your File System like: “C:WorkManager_WLST”

Step2). Write a Property file with the name “workManagerProperties.properties” inside the “C:WorkManager_WLST”

adminServerName=AdminServer
ServerName=AdminServer
domainName=base_domain
domainDire=C:/bea103/user_projects/domains/base_domain
host=localhost
protocol=t3
AdminPort=7001
username=weblogic
password=weblogic
MinThread=7
MaxThread=15
workManagerName=MyTestWorkManager
maxThreadConstraintName=MyTestMaxThreadConstraint
minThreadConstraintName=MyTestMinThreadConstraint

Step3). Now write the WLST pythin script “createWorkManager.py” inside “”C:WorkManager_WLST”” to create the WorkManager like following

import sys
import os
import jarray
import dircache
from java.io import File
from java.lang import String

myPropertyFile = "workManagerProperties.properties"

#=======================================================================================
# connection() Definition
#=======================================================================================
def connection():
	print '===> Connecting as '+ username + ' To WebLogic URL ' + url + '...'
	try:
		connect(username, password, url)
	except WLSTException:
		print '==> Error Connecting to The URL ' + url
		CancelEdit('y')
		exit()

print '==== Exiting Because Of Connectivity Error ===='
#=======================================================================================
print '======= Reading Property File and Connecting to Server ========'
loadProperties(myPropertyFile)
url=protocol + '://' + host + ':' + AdminPort
connection()

edit()
startEdit()
print '======= Creating a WorkManager name as ======='
cd('edit:/SelfTuning/' + domainName + '/WorkManagers/')
create(workManagerName,'WorkManagers')
cd('edit:/SelfTuning/' + domainName + '/WorkManagers/' + workManagerName)
cmo.addTarget(getMBean("/Servers/"+ ServerName))
save()
print ' WorkManager Created...'

print '======= Creating MaxThreadsConstraint ======='
cd('edit:/SelfTuning/' + domainName + '/MaxThreadsConstraints/')
try:
	create(maxThreadConstraintName,'MaxThreadsConstraints')
except Exception:
	print 'Issue in Creating MaxThreads exiting'
cd('edit:/SelfTuning/' + domainName + '/MaxThreadsConstraints/' + maxThreadConstraintName)
cmo.addTarget(getMBean("/Servers/"+ ServerName))
set('Count',MaxThread)
save()

print '======= Creating MinThreadsConstraint ======='
cd('edit:/SelfTuning/' + domainName + '/MinThreadsConstraints/')
try:
	create(minThreadConstraintName,'MinThreadsConstraints')
except Exception:
	print 'Issue In Creating MinThreads '
cd('edit:/SelfTuning/' + domainName + '/MinThreadsConstraints/' + minThreadConstraintName)
cmo.addTarget(getMBean("/Servers/"+ ServerName))
set('Count',MinThread)
save()

print '======= Assigning the MaxThreadConstraint to the WorkManager ======='
cd('edit:/SelfTuning/' + domainName + '/WorkManagers/' + workManagerName)
bean=getMBean('/SelfTuning/' + domainName + '/MaxThreadsConstraints/' + maxThreadConstraintName)
cmo.setMaxThreadsConstraint(bean)

print '======= Assigning the MinThreadConstraint to the WorkManager ======='
cd('edit:/SelfTuning/' + domainName + '/WorkManagers/' + workManagerName)
bean=getMBean('/SelfTuning/' + domainName + '/MinThreadsConstraints/' + minThreadConstraintName)
cmo.setMinThreadsConstraint(bean)

save()
activate(block="true")
print '==> WorkManager Creation Finished ... Please Double Check from AdminConsole...'
disconnect()

Step4). Open a Command Window and then run the “setWLSEn.cmd” (for windows)… or “setWLSEnv.sh” (for Unix Based OS) Then run the WLST Script :
NOTE: Run the setWLSEnv.sh always with preseeding two DOTs like
“. ./setWLSEnv.sh”
The first DOT represents that set the Environment in the current Shell, AND the second ./ represents execute the script from the current directory.

running the setWLSEnv.cmd to set CLASSPATH/PATH

running the setWLSEnv.cmd to set CLASSPATH/PATH

java weblogic.WLST createWorkManager.py workManagerProperties.properties

Running the WLST Script to Create WorkManager

Running the WLST Script to Create WorkManager

Step5). Double check the AdminConsole that everything looks good?

Admin Console After Creation of WorkManager

Admin Console After Creation of WorkManager

.
.
Thanks
Jay SenSharma

If you enjoyed this post, please considerleaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.