weblogic.descriptor.BeanAlreadyExistsException: Bean already exists
A simple approach is to use the "cd" command to navigate into that configuration MBean. If the "cd" command throws an exception then you can safely assume that the resource/configuration doesn't exists and you can continue creating.
...
### Check for the server
try:
cd('/Servers/' + mgdServerName)
print '===> Server \"' +mgdServerName+'\" already exists'
print '===> No action was performed'
exit()
except:
pass
...
The other approach is to catch the "BeanAlreadyExistsException" while creating the resource and safely exiting the script.
...
### Create the Managed Server
edit()
startEdit()
try:
create(mgdServerName, resourceType)
print '===> Created Managed Server - ' + mgdServerName
pass
except BeanAlreadyExistsException:
print '===> Server \"' +mgdServerName+'\" already exists'
print '===> No action was performed'
cancelEdit('y')
exit()
...
But with this approach you are starting an edit session and creating the server to find out it's existence. So you have to cancel the edit session once you find out that the resource that you are creating already exists if not you might get a warning message similar to the following:
You have an edit session open and you will lose all outstanding changes and your edit session will be stopped if you exit. Are you sure you would like to exit? (y/n)
So cancelling the edit session with a responce 'y' will make WLST not to prompt for user response. I shall discuss how to streamline the outputs from WLST and redirect them to an output file or log file in a later post.
WLST-BP-3 Check for the resource or configuration existence before creating them
Bala, this is really useful stuff! Thanks for taking the time to post it!!
ReplyDelete(This is Del Simmons from your class in Dallas at the end of last year)
This is very usefull info.I am looking for creation of domain script which can read from .csv file and create a domain.
ReplyDeleteThis is raja from chicago class
october 08.
THanks for helping.
Raja
Hi Raja,
ReplyDeleteSee this post for creating domains from csv file - http://weblogicserver.blogspot.com/2009/03/reading-csv-file-in-wlst-script.html
Hi Bala,
ReplyDeleteI am getting the same error that you have mentioned here, but I am not sure what to do with the code snippet that you have provided. Am using basic UNIX commands to configure my domain.
Hi Swagat,
ReplyDeleteIf you get that error then you are creating something that already exists. Try to change the name of the resource and rerun your script.
Hi Bala,
ReplyDeleteThanks for posting very good articles.
Vijay Bheemineni.
Rather nice site you've got here. Thanks for it. I like such topics and anything that is connected to them. I would like to read more soon.
ReplyDeleteBest wishes
Jeph Normic
Hi Bala,
ReplyDeleteHere is a 3rd method to check for resource existence. This is the one I prefer
because it has no side-effect (neither change cmo, nor need edit session), but
it only works for online WLST.
### Check for the server
...
myMBean = getMBean('/Servers/' + mgdServerName) # WLST Online only
if myMBean is None:
# resource does not exist, create it
myMBean = create(mgdServerName, 'Server')
...
else:
# resource already exists, nothing to do
# use myMBean, no matter it was existing or has just been created
...
Thanks for your blog!
Regards,
Gregoire Vatry