WLST : get runtime data iterating on instances

In the WebLogic console you may find that is difficult to do a fast check on a runtime property for all the configured managed instances of a domain.

Here you’ll find how to do it by using WLST interactively.

Note: this sample was tested with “WebLogic Server 10.3.5.0”.

After loading the environment (. ./setDomainEnv.sh) and running the WLST console (see Oracle WLS 10.3.5 Documentation – Using WLST) you’ll connect to the administrative instance by using the command

connect(username,password,'t3s://myhost:8001')

You’ll collect the managed servers into “serverNames” variable by going to the Domain Config MBean tree:

wls:/MYDOMAIN/serverConfig> domainConfig()
wls:/MYDOMAIN/domainConfig> serverNames = cmo.getServers()

After that you have to go to the Domain Runtime MBean tree, cycle through the servers and get the desired runtime property (in this sample the “Activation Time”):

wls:/MYDOMAIN/domainConfig> domainRuntime()
wls:/MYDOMAIN/domainRuntime/ServerRuntimes> for name in serverNames:
...     print name
...     cd("/ServerRuntimes/"+name.getName())
...     print java.util.Date(cmo.getActivationTime())
...

Tip: (python syntax) the white space before commands inside the “for” cycle are TAB characters. They are needed to tell the Jython interpreter that the commands must be executed inside the “for” cycle. To end the cycle in the last void line press enter without typing the tab…

Tip: Since WebLogic is implemented with Java, all the values are java-type values. To convert the date value into readable format you must use java.util.Date(<date-value>)

To retrieve other attributes of the ServerRuntime you can refer to the MBean documentation WLS 10.3.5 ServerRuntime Attributes and call “cmo.get<attribute>”.

Improvement: do not exit loop if some instance is not responding.

If one instance is down or not responding the loop will exit. To avoid this you can use the try-except python syntax.

for name in serverNames:
    print name
    try :
        cd("/ServerRuntimes/"+name.getName())
        print java.util.Date(cmo.getActivationTime())
    except WLSTException :
        print "ERROR Detected"

Please note that WLSTException is the exception object type returned when the instance is not up. If you want to catch more exception object types you can use the parenthesis syntax: except (WLSTException, NullPointerException) :

List Oracle Service Bus EndPoints in WLST

If you administer or need to support an Oracle Service Bus installation, you may need to do a fast check on all the systems that are “connected” to the service bus.

In this post I show a simple WLST script that allows to extract all the EndPoints.

A very little theoretical introduction

In Oracle Service Bus (Formerly also known as “BEA AquaLogic Service Bus”) every remotely connected service is configured as “Business Service”. The Business Service configuration usually contains the information on where is the service in the “EndPoint URI” configuration field.

A good tutorial giving infos on Business Services, endpoints, and other basic concept of Oracle Service Bus is here: How to Provision a Service in Oracle Service Bus.

The script

The script was tested on “AquaLogic Service Bus 2.6” and on “Oracle Service Bus 11g (11.1.1.4)”. See below for other tips on the script.

from com.bea.wli.sb.management.configuration import SessionManagementMBean
from com.bea.wli.sb.management.configuration import ALSBConfigurationMBean
from com.bea.wli.sb.management.configuration import BusinessServiceConfigurationMBean
 
from com.bea.wli.sb.util import EnvValueTypes
from com.bea.wli.config import Ref
from com.bea.wli.sb.util import Refs
from xml.dom.minidom import parseString
 
connect(userConfigFile='<userConfigFile_location>', userKeyFile='<userKeyFile_location>', url='t3://<myserver_ip>:<myserver_port>')
domName=cmo.getName()
domainRuntime()
sessionMBean = findService(SessionManagementMBean.NAME,SessionManagementMBean.TYPE)
sessionName="WLSTSession"+ str(System.currentTimeMillis())
sessionMBean.createSession(sessionName)
alsbSession = findService(ALSBConfigurationMBean.NAME + "." + sessionName, ALSBConfigurationMBean.TYPE)
alsbCore = findService(ALSBConfigurationMBean.NAME, ALSBConfigurationMBean.TYPE)
allRefs=alsbCore.getRefs(Ref.DOMAIN)
for ref in allRefs.iterator():
    typeId = ref.getTypeId()
    if typeId == "BusinessService" :
        name=ref.getFullName()
        uris=alsbSession.getEnvValue(ref, EnvValueTypes.SERVICE_URI_TABLE, None)
        print name
        print uris
        print

The connection is performed by using user security files that must be created with the storeUserConfig WLST command. Change <userConfigFile_location>, <userKeyFile_location>, <myserver_ip>, <myserver_port> with the current values.