Script to create multiple workmanager in weblogic domain.
Hello Viewer,
I was asked to migrate the current weblogic resources to new weblogic domain as a part of upgrade project, among those weblogic resources there were around seventy workmanager with corresponding MaxThreadsConstraints.
I could manage to find the script on google for this task but only for single workmanager. So i tried to slightly tickle this script for managing this task of creating multiple workmanager with there corresponding MaxThreadsConstraints and MinThreadsConstraints in one go.
Below are steps to be followed.
1) Create a file with name createWorkManager.py with below content:
--------------------------------------------------------------------------------------------------------------
import sys
import os
import jarray
import dircache
from java.io import File
from java.io import FileInputStream
from java.lang import String
propInputStream = FileInputStream("details.properties")
configProps = Properties()
configProps.load(propInputStream)
domainName=configProps.get("domain.name")
adminURL=configProps.get("admin.url")
adminUserName=configProps.get("admin.userName")
adminPassword=configProps.get("admin.password")
totalWM_to_Create=configProps.get("total.WM")
#connection()
connect(adminUserName, adminPassword, adminURL)
edit()
startEdit()
print '======= Creating a WorkManager name as ======='
i=1
while (i <= int(totalWM_to_Create)) :
try :
cd('/')
workManagerName=configProps.get("workManagerName."+ str(i))
maxThreadConstraintName=configProps.get("maxThreadConstraintName."+ str(i))
minThreadConstraintName=configProps.get("minThreadConstraintName."+ str(i))
ServerName=configProps.get("ServerName."+ str(i))
MaxThread=configProps.get("MaxThread."+ str(i))
MinThread=configProps.get("MinThread."+ str(i))
cd('edit:/SelfTuning/' + domainName + '/WorkManagers/')
create(workManagerName,'WorkManagers')
cd('edit:/SelfTuning/' + domainName + '/WorkManagers/' + workManagerName)
cmo.addTarget(getMBean("/Clusters/"+ 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("/Clusters/"+ 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("/Clusters/"+ 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)
print '==> WorkManager Creation Finished ... Please Double Check from AdminConsole...'
except:
print '***** CANNOT CREATE Workmanager!!! Check If the Workmanager With the Name : ' , workManagerName ,' Alreday exists or NOT...'
print ''
i = i + 1
print '========================================='
print '========================================='
save()
activate()
activate()
---------------------------------------------------------------------------------------------------------
2) create a file with name createWorkManager.sh with below content:
----------------------------------------------------------------------------------------------------------
#!/bin/sh
export LOGFILE="/Mylocation/createWM.log"
if [ -f $LOGFILE ]; then
rm -f $LOGFILE
fi
rm -rf /Mylocation/createWM.log
WL_HOME="your weblogic_home"
export WL_HOME
cd /Mylocation/
sh ${WL_HOME}/common/bin/wlst.sh /Mylocation/createWorkManager.py >> /Mylocation/createWM.log
exit
-----------------------------------------------------------------------------------------------------------
Note: change wl_home and mylocation as per your environment and requirement.
3) create a properties file with name "details.properties" which will have the details like below :
-----------------------------------------------------------------------------------------------------------
domain.name=DOMAIN_NAME
admin.url=t3://Adminhost:Adminport
admin.userName=username
admin.password=xxxxxxxxx
total.WM=2
ServerName.1=SOA_CLUSTER
MinThread.1=7
MaxThread.1=15
workManagerName.1=MyTestWorkManager1
maxThreadConstraintName.1=MyTestMaxThreadConstraint1
minThreadConstraintName.1=MyTestMinThreadConstraint1
ServerName.2=SOA_CLUSTER
MinThread.2=7
MaxThread.2=15
workManagerName.2=MyTestWorkManager2
maxThreadConstraintName.2=MyTestMaxThreadConstraint2
minThreadConstraintName.2=MyTestMinThreadConstraint2
---------------------------------------------------------------------------------------------------------------
Note:
a) total.WM = total number of workmanager you want to create.
b) Don't forget to add numeric suffix for every new entry.
4) Flow:
createWorkManager.sh ----> createWorkManager.py---------> details.properties
5) How to run :
a) Go to /Mylocation
cd /Mylocation/
b) execute the shell script:
sh createWorkManager.sh
Thanks a lot for your patience!!!
Regards
-Ashish
Regards
-Ashish
No comments:
Post a Comment