WLST find(): Find is not supported for this tree - weblogic

I have some problem with WLST find
when I am trying to find some Mbean or Attr
even if they are located in the current pwd() I got the same error:
wls:/base_domain/domainRuntime/ServerRuntimes/AdminServer> find('State')
Find is not supported for this tree
And I can not find anything against MBean tree.
How to solve this find problem? please help.

The find() command is not accessible from within domainRuntime() but you can use it with serverRuntime and serverConfig. Instead if you want to see server states, simply do a connect() and then make calls to get each individual server MBean and then get the State.
def checkHealth(serverName):
while 1:
slBean = getServerBean(serverName)
status = slBean.getState()
print 'Status of Managed Server is '+ status
def getServerBean(svrName):
domainRuntime()
slrBean = cmo.lookupServerLifecycleRuntime(svrName)
return slcBean
http://docs.oracle.com/cd/E23943_01/web.1111/e13813/reference.htm#i1064028

Related

WebSphere wsadmin testConnection error message

I'm trying to write a script to test all DataSources of a WebSphere Cell/Node/Cluster. While this is possible from the Admin Console a script is better for certain audiences.
So I found the following article from IBM https://www.ibm.com/support/knowledgecenter/en/SSAW57_8.5.5/com.ibm.websphere.nd.multiplatform.doc/ae/txml_testconnection.html which looks promising as it describles exactly what I need.
After having a basic script like:
ds_ids = AdminConfig.list("DataSource").splitlines()
for ds_id in ds_ids:
AdminControl.testConnection(ds_id)
I experienced some undocumented behavior. Contrary to the article above the testConnection function does not always return a String, but may also throw a exception.
So I simply use a try-catch block:
try:
AdminControl.testConnection(ds_id)
except: # it actually is a com.ibm.ws.scripting.ScriptingException
exc_type, exc_value, exc_traceback = sys.exc_info()
now when I print the exc_value this is what one gets:
com.ibm.ws.scripting.ScriptingException: com.ibm.websphere.management.exception.AdminException: javax.management.MBeanException: Exception thrown in RequiredModelMBean while trying to invoke operation testConnection
Now this error message is always the same no matter what's wrong. I tested authentication errors, missing WebSphere Variables and missing driver classes.
While the Admin Console prints reasonable messages, the script keeps printing the same meaningless message.
The very weird thing is, as long as I don't catch the exception and the script just exits by error, a descriptive error message is shown.
Accessing the Java-Exceptions cause exc_value.getCause() gives None.
I've also had a look at the DataSource MBeans, but as they only exist if the servers are started, I quickly gave up on them.
I hope someone knows how to access the error messages I see when not catching the Exception.
thanks in advance
After all the research and testing AdminControl seems to be nothing more than a convinience facade to some of the commonly used MBeans.
So I tried issuing the Test Connection Service (like in the java example here https://www.ibm.com/support/knowledgecenter/en/SSEQTP_8.5.5/com.ibm.websphere.base.doc/ae/cdat_testcon.html
) directly:
ds_id = AdminConfig.list("DataSource").splitlines()[0]
# other queries may be 'process=server1' or 'process=dmgr'
ds_cfg_helpers = __wat.AdminControl.queryNames("WebSphere:process=nodeagent,type=DataSourceCfgHelper,*").splitlines()
try:
# invoke MBean method directly
warning_cnt = __wat.AdminControl.invoke(ds_cfg_helpers[0], "testConnection", ds_id)
if warning_cnt == "0":
print = "success"
else:
print "%s warning(s)" % warning_cnt
except ScriptingException as exc:
# get to the root of all evil ignoring exception wrappers
exc_cause = exc
while exc_cause.getCause():
exc_cause = exc_cause.getCause()
print exc_cause
This works the way I hoped for. The downside is that the code gets much more complicated if one needs to test DataSources that are defined on all kinds of scopes (Cell/Node/Cluster/Server/Application).
I don't need this so I left it out, but I still hope the example is useful to others too.

WLSTException: Error cding to the MBean while creating JMS Queue

I am trying to create JMSQueue with following code but getting error on
cd ('/JMSSystemResources/BAMJMSSystemResource/JMSResource/BAMJMSSystemResource/Queues/SampleQueue')
When I connected to server runtimeand check I can see JMS Module is not available, but from Admin Console I can clearly see it's (JMS Module BAMJMSSystemResource) available, also it's not giving errors for
Note : I am creating JMS module before calling createJMSQueue function )
def createJMSQueue(jmsQueueName, jmsModuleName, jndiName, subdeployment):
print ' Creating Queue '+jmsQueueName
cd('/')
cd("/JMSSystemResources/"+jmsModuleName+"/JMSResource/"+jmsModuleName)
cmo.createQueue(jmsQueueName)
print('DEBUG >> '+jmsModulePath+'/Queues/'+jmsQueueName)
cd("/JMSSystemResources/"+jmsModuleName+"/JMSResource/"+jmsModuleName+'/Queues/'+jmsQueueName)
set('JNDIName',jndiName)
set('SubDeploymentName',subdeployment)
cd('/JMSSystemResources/'+jmsModuleName+'/SubDeployments/'+subdeployment)
cmo.addTarget(getMBean('/JMSServers/BAMMonitoringServer'))
Error is ,
Starting an edit session ...
Started edit session, please be sure to save and activate your
changes once you are done.
*** Creating JMS Queues ....
Creating Queue SampleQueue
DEBUG >> JMSSystemResources/BAMJMSSystemResource/JMSResource/BAMJMSSystemResource/Queues/SampleQueue
No stack trace available.
Problem invoking WLST - Traceback (innermost last):
File "/home/oracle/JMSConfigurations.py", line 188, in ?
File "/home/oracle/JMSConfigurations.py", line 77, in createJMSQueue
File "<iostream>", line 182, in cd
File "<iostream>", line 1847, in raiseWLSTException
WLSTException: Error cding to the MBean
Would really like to understand what's wrong ?
Shanaka, there could be problem in 'cd' command given after the DEBUG statement. You can give the cd line as below:
cd(jmsModulePath+'/Queues/'+jmsQueueName)
You can also get some more clarity on JMS module creation using WLST by Examples
This section of script looks fine except mix of double and single quote in " cd("/JMSSystemResources/"+jmsModuleName+"/JMSResource/"+jmsModuleName+'/Queues/'+jmsQueueName)"
and assigning target "cmo.addTarget()" , you dont need to target queue if sub-deployment is already targeted to JMS server.
You can check if your edit session of creating JMS module,Sub deployment, target JMS module to server and sub deployment to JMS server is activated successfully.
Then this Queue creation should work fine.
regards,
Kshitij
That can mean that the JMS you are trying to create already exists in WebLogic. Confirm that the JMS names are not existing ones.
I share with you my correct code:
def create_jms_object(name, module, subdeployment, type):
cd('/JMSSystemResources/'+module+'/JMSResource/'+module)
myob=create(name, type)
myob.setJNDIName("jms/"+name)
myob.setSubDeploymentName(subdeployment)
and I call the function here:
queue_name = queue['name']
sub_depl_name = queue['sub_deployment']
if(not_exists_jms_ud_qeue(jms_module_name, queue_name)):
print 'Creating queue '+queue_name
create_jms_object(queue_name, jms_module_name, sub_depl_name, 'UniformDistributedQueue')
print 'Created queue '+queue_name
else:
print 'UniformDistributedQueue ' + queue_name + ' already exists'
cmo = cd('/JMSSystemResources/'+jms_module_name+'/JMSResource/'+jms_module_name+'/UniformDistributedQueues/'+queue_name+'/DeliveryFailureParams/'+queue_name)
redelivery_limit = queue.get('redelivery_limit',-1)
set('RedeliveryLimit', redelivery_limit)
errorDestinationName = queue.get('error_destination', None)
if (errorDestinationName is not None):
errorDestination = getMBean('/JMSSystemResources/'+jms_module_name+'/JMSResource/'+jms_module_name+'/UniformDistributedQueues/'+errorDestinationName)
set('ErrorDestination', errorDestination)
print 'Dead letter queue set to: '+errorDestinationName
else:
cmo.unSet('ErrorDestination')
print 'Dead letter queue unset'
cd('/JMSSystemResources/'+jms_module_name+'/JMSResource/'+jms_module_name+'/UniformDistributedQueues/'+queue_name+'/DeliveryParamsOverrides/'+queue_name)
redelivery_delay = queue.get('redelivery_delay',-1)
set('RedeliveryDelay', redelivery_delay)
time_to_deliver = queue.get('time_to_deliver',-1)
set('TimeToDeliver', time_to_deliver)
where the queue object is the following:
{
"name" : "events_reg_queue",
"sub_deployment" : "Registry-SD",
"redelivery_limit" : 1
}
and the following utility function:
def not_exists_jms_ud_qeue(jmsModuleName, jmsResourceName):
try:
myMBean = getMBean('/JMSSystemResources/'+jmsModuleName+'/JMSResource/'+jmsModuleName+'/UniformDistributedQueues/'+jmsResourceName)
if (myMBean is None):
return true
return false
except:
return true
Did you try traversing the path manually ?
You can traverse the /edit location using the wlst command line.
Use cd("") and ls() to traverse and list those properties you created.

Changing java heapsizes for a websphere server using websphere and wsadminlib.py

Im trying to call a command from wsadminlib.py to change the initialHeapSize and the maximumHeapSize in a script. But unfortunately my jython (and general scripting knowledge) is still total newbie.
Im using the call
#Change Java Heap Size
setJvmProperty(nodeName,serverName,maximumHeapsize -2048 ,initialHeapSize -2048)
Which should relate to the command in the wsadminlib.py library
def setJvmProperty(nodename,servername,propertyname,value):
"""Set a particular JVM property for the named server
Some useful examples:
'maximumHeapSize': 512 ,
'initialHeapSize':512,
'verboseModeGarbageCollection':"true",
'genericJvmArguments':"-Xgcpolicy:gencon -Xdump:heap:events=user -Xgc:noAdaptiveTenure,tenureAge=8,stdGlobalCompactToSatisfyAllocate -Xconcurrentlevel1 -Xtgc:parallel",
"""
jvm = getServerJvm(nodename,servername)
AdminConfig.modify(jvm, [[propertyname, value]])
But I'm met with this issue when i run the script
WASX7017E: Exception received while running file "/etc/was-scripts/administrateservertest.py"; exception information: com.ibm.bsf.BSFException: exception from Jython:
Traceback (innermost last):
File "", line 14, in ?
NameError: maximumHeapsize
Any suggestions would be appreciated as I'm tearing my hair out trying to work this out
this was answered by a friend on face book
I think you might need to make two calls, one for each property you
want to set. e.g.
setJvmProperty(nodeName,serverName,'maximumHeapsize',2048)
For others looking for a more specific answer, try this:
AdminConfig.modify(jvmId,[['genericJvmArguments',arguments],["maximumHeapSize", str(1536)]])

Weblogic Exception after deploy: java.rmi.UnexpectedException

Just encountered a similar issue as described in the below article:
Question: Article with similar error description
java.rmi.UnmarshalException: cannot unmarshaling return; nested exception is:
java.rmi.UnexpectedException: Failed to parse descriptor file; nested exception is:
java.rmi.server.ExportException: Failed to export class
I found that the issue described is totally unrelated to any Java update and is rather an issue with the Weblogic bean-cache. It seems to use old compiled versions of classes when updating a deployment. I was hunting a similar issue in a related question (Question: Interface-Implementation-mismatch).
How can I fix this properly to allow proper automatic deployment (with WLST)?
After some feedback from the Oracle community it now works like this:
1) Shutdown the remote Managed Server
2) Delete directory "domains/#MyDomain#/servers/#MyManagedServer#/cache/EJBCompilerCache"
3) Redeploy EAR/application
In WLST (which one would need to automate this) this is quite tricky:
import shutil
servers=cmo.getServers()
domainPath = get('RootDirectory')
for thisServer in servers:
pathToManagedServer = domainPath + "\\servers\\" + thisServer.getName()
print ">Found managed server:" + pathToManagedServer
pathToCacheDir = pathToManagedServer + "\\" + "cache\\EJBCompilerCache"
if(os.path.exists(pathToCacheDir) and os.path.isdir(pathToCacheDir) ):
print ">Found a cache directory that will be deleted:" + pathToCacheDir
# shutil.rmtree(pathToCacheDir)
Note: Be careful when testing this, the path that is returned by "pathToCacheDir" depends on the MBean-context that is currently set. See samples for WLST command "cd()". You should first test the path output with "print domainPath" and later add the "rmtree" python command! (I uncommented the delete command in my sample, so that nobody accidentially deletes an entire domain!)

WLST capture the output of state('ms1') to a variable

I need to capture the output of the below to a variable.
I know we can get to serverRuntime or domainRuntime() trees and get the state. But need to get the below working.
wls:/owb/serverConfig> state('Server1')
Current state of 'Server1' : RUNNING
I tried two ways:
wls:/owb/serverConfig> print state('Server1')
Current state of 'Server1' : RUNNING
None
wls:/owb/serverConfig> x=state('Server1')
Current state of 'Server1' : RUNNING
wls:/owb/serverConfig> print x
None
You have to use the getState() method of server runtime mbean.
You can obtain the server runtime mbean by navigating into wlst runtime tree or by using a lookup method.
Sample:
domainRuntime()
slrBean = cmo.lookupServerLifeCycleRuntime('Server1')
status = slrBean.getState()
print 'Status of Managed Server is '+status
See also Getting Runtime Information in WLST official documentation.
This same question was raised by Dianyuan Wang with me 2011.
Here is the steps to resolve your issue.
1. Capture the output of state command using redirect, stopRedirect command
2. Use the Python regular expression in search function to extract the desired server output.
Code snippet is here
fileName='/tmp/myserver_state.txt'
redirect(fileName)
state(server_nm,'Server')
stopRedirect()
f = open(fileName)
try:
for line in f.readlines():
if re.search('Current state',line):
status[server_nm]=line
except:
continue
Now you can apply desired logic after this block.
Cheers!!
HTH
Here is what I am using and is working like charm
cd("/ServerRuntimes/ms1")
state=cmo.getState()
print state