At a public sector organization in the Netherlands an OSB proxy service was (via JMS) reading messages from a WebLogic queue. These messages where then send to a back-end system. Every evening during a certain time period the back-end system was down. So therefor and also in case of planned maintenance there was a requirement whereby it was necessary to be able to stop and start sending messages to the back-end system from the queue. Hence, a script was needed to disable/enable the OSB proxy service (deployed on OSB 11.1.1.7).
This article will explain how the OSB proxy service can be disabled/enabled via WebLogic Server MBeans with JMX.
A managed bean (MBean) is a Java object that represents a Java Management Extensions (JMX) manageable resource in a distributed environment, such as an application, a service, a component, or a device.
First an “high over” overview of the MBeans is given. For further information see “Fusion Middleware Developing Custom Management Utilities With JMX for Oracle WebLogic Server”, via url: https://docs.oracle.com/cd/E28280_01/web.1111/e13728/toc.htm
Next the structure and use of the System MBean Browser in the Oracle Enterprise Manager Fusion Middleware Control is discussed.
Finally the code to disable/enable the OSB proxy service is shown.
To disable/enable an OSB proxy service, also WebLogic Scripting Tool (WLST) can be used, but in this case (also because of my java developer skills) JMX was used. For more information have a look for example at AMIS TECHNOLOGY BLOG: “Oracle Service Bus: enable / disable proxy service with WLST”, via url: https://technology.amis.nl/2011/01/10/oracle-service-bus-enable-disable-proxy-service-with-wlst/
The Java Management Extensions (JMX) technology is a standard part of the Java Platform, Standard Edition (Java SE platform). The JMX technology was added to the platform in the Java 2 Platform, Standard Edition (J2SE) 5.0 release.
The JMX technology provides a simple, standard way of managing resources such as applications, devices, and services. Because the JMX technology is dynamic, you can use it to monitor and manage resources as they are created, installed and implemented. You can also use the JMX technology to monitor and manage the Java Virtual Machine (Java VM).
For another example of using MBeans with JMX, I kindly point you to another article (written by me) on the AMIS TECHNOLOGY BLOG: “Doing performance measurements of an OSB Proxy Service by programmatically extracting performance metrics via the ServiceDomainMBean and presenting them as an image via a PowerPoint VBA module”, via url: https://technology.amis.nl/2016/01/30/performance-measurements-of-an-osb-proxy-service-by-using-the-servicedomainmbean/
Basic Organization of a WebLogic Server Domain
As you probably already know a WebLogic Server administration domain is a collection of one or more servers and the applications and resources that are configured to run on the servers. Each domain must include a special server instance that is designated as the Administration Server. The simplest domain contains a single server instance that acts as both Administration Server and host for applications and resources. This domain configuration is commonly used in development environments. Domains for production environments usually contain multiple server instances (Managed Servers) running independently or in groups called clusters. In such environments, the Administration Server does not host production applications.
Separate MBean Types for Monitoring and Configuring
All WebLogic Server MBeans can be organized into one of the following general types based on whether the MBean monitors or configures servers and resources:
- Runtime MBeans contain information about the run-time state of a server and its resources. They generally contain only data about the current state of a server or resource, and they do not persist this data. When you shut down a server instance, all run-time statistics and metrics from the run-time MBeans are destroyed.
- Configuration MBeans contain information about the configuration of servers and resources. They represent the information that is stored in the domain’s XML configuration documents.
- Configuration MBeans for system modules contain information about the configuration of services such as JDBC data sources and JMS topics that have been targeted at the system level. Instead of targeting these services at the system level, you can include services as modules within an application. These application-level resources share the life cycle and scope of the parent application. However, WebLogic Server does not provide MBeans for application modules.
MBean Servers
At the core of any JMX agent is the MBean server, which acts as a container for MBeans.
The JVM for an Administration Server maintains three MBean servers provided by Oracle and optionally maintains the platform MBean server, which is provided by the JDK itself. The JVM for a Managed Server maintains only one Oracle MBean server and the optional platform MBean server.
MBean Server | Creates, registers, and provides access to… |
Domain Runtime MBean Server | MBeans for domain-wide services. This MBean server also acts as a single point of access for MBeans that reside on Managed Servers.
Only the Administration Server hosts an instance of this MBean server. |
Runtime MBean Server | MBeans that expose monitoring, run-time control, and the active configuration of a specific WebLogic Server instance.
In release 11.1.1.7, the WebLogic Server Runtime MBean Server is configured by default to be the platform MBean server. Each server in the domain hosts an instance of this MBean server. |
Edit MBean Server | Pending configuration MBeans and operations that control the configuration of a WebLogic Server domain. It exposes a ConfigurationManagerMBean for locking, saving, and activating changes.
Only the Administration Server hosts an instance of this MBean server. |
The JVM’s platform MBean server | MBeans provided by the JDK that contain monitoring information for the JVM itself. You can register custom MBeans in this MBean server.
In release 11.1.1.7, WebLogic Server uses the JVM’s platform MBean server to contain the WebLogic run-time MBeans by default. |
Service MBeans
Within each MBean server, WebLogic Server registers a service MBean under a simple object name. The attributes and operations in this MBean serve as your entry point into the WebLogic Server MBean hierarchies and enable JMX clients to navigate to all WebLogic Server MBeans in an MBean server after supplying only a single object name.
MBean Server | Service MBean | JMX object name |
The Domain Runtime MBean Server | DomainRuntimeServiceMBean
Provides access to MBeans for domain-wide services such as application deployment, JMS servers, and JDBC data sources. It also is a single point for accessing the hierarchies of all run-time MBeans and all active configuration MBeans for all servers in the domain. |
com.bea:Name=DomainRuntimeService,Type=weblogic.management.mbeanservers.domainruntime.DomainRuntimeServiceMBean |
Runtime MBean Servers | RuntimeServiceMBean
Provides access to run-time MBeans and active configuration MBeans for the current server. |
com.bea:Name=RuntimeService,Type=weblogic.management.mbeanservers.runtime.RuntimeServiceMBean |
The Edit MBean Server | EditServiceMBean
Provides the entry point for managing the configuration of the current WebLogic Server domain. |
com.bea:Name=EditService,Type=weblogic.management.mbeanservers.edit.EditServiceMBean |
Choosing an MBean Server
If your client monitors run-time MBeans for multiple servers, or if your client runs in a separate JVM, Oracle recommends that you connect to the Domain Runtime MBean Server on the Administration Server instead of connecting separately to each Runtime MBean Server on each server instance in the domain.
The trade off for directing all JMX requests through the Domain Runtime MBean Server is a slight degradation in performance due to network latency and increased memory usage. However, for most network topologies and performance requirements, the simplified code maintenance and enhanced security that the Domain Runtime MBean Server enables is preferable.
System MBean Browser
Oracle Enterprise Manager Fusion Middleware Control provides the System MBean Browser for managing MBeans that perform specific monitoring and configuration tasks.
Via the Oracle Enterprise Manager Fusion Middleware Control for a certain domain, the System MBean Browser can be opened.
Here the previously mentioned types of MBean’s can be seen: Runtime MBeans and Configuration MBeans:
When navigating to “Configuration MBeans | com.bea”, the previously mentioned EditServiceMBean can be found:
When navigating to “Runtime MBeans | com.bea | Domain: <a domain>”, the previously mentioned DomainRuntimeServiceMBean can be found:
Also the later on in this article mentioned MBeans can be found:
For example for the ProxyServiceConfigurationMbean, the available operations can be found:
When navigating to “Runtime MBeans | com.bea”, within each Server the previously mentioned RuntimeServiceMBean can be found.
Code to disable/enable the OSB proxy service
The requirement to be able to stop and start sending messages to the back-end system from the queue was implemented by disabling/enabling the state of the OSB Proxy service JMSConsumerStuFZKNMessageService_PS.
Short before the back-end system goes down, dequeuing of the queue should be disabled.
Right after the back-end system goes up again, dequeuing of the queue should be enabled.
The state of the OSB Proxy service can be seen in the Oracle Service Bus Administration 11g Console (for example via the Project Explorer) in the tab “Operational Settings” of the proxy service.
For ease of use, two ms-dos batch files where created, each using MBeans, to change the state of a service (proxy service or business service). As stated before, the WebLogic Server contains a set of MBeans that can be used to configure, monitor and manage WebLogic Server resources.
- Disable_JMSConsumerStuFZKNMessageService_PS.bat
On the server where the back-end system resides, the ms-dos batch file “Disable_JMSConsumerStuFZKNMessageService_PS.bat” is called.
The content of the batch file is:
java.exe -classpath “OSBServiceState.jar;com.bea.common.configfwk_1.7.0.0.jar;sb-kernel-api.jar;sb-kernel-impl.jar;wlfullclient.jar” nl.xyz.osbservice.osbservicestate.OSBServiceState “xyz” “7001” “weblogic” “xyz” “ProxyService” “JMSConsumerStuFZKNMessageService-1.0/proxy/JMSConsumerStuFZKNMessageService_PS” “Disable”
- Enable_JMSConsumerStuFZKNMessageService_PS.bat
On the server where the back-end system resides, the ms-dos batch file “Enable_JMSConsumerStuFZKNMessageService_PS.bat” is called.
The content of the batch file is:
java.exe -classpath “OSBServiceState.jar;com.bea.common.configfwk_1.7.0.0.jar;sb-kernel-api.jar;sb-kernel-impl.jar;wlfullclient.jar” nl.xyz.osbservice.osbservicestate.OSBServiceState “xyz” “7001” “weblogic” “xyz” “ProxyService” “JMSConsumerStuFZKNMessageService-1.0/proxy/JMSConsumerStuFZKNMessageService_PS” “Enable”
In both ms-dos batch files via java.exe a class named OSBServiceState is being called. The main method of this class expects the following parameters:
Parameter name | Description |
HOSTNAME | Host name of the AdminServer |
PORT | Port of the AdminServer |
USERNAME | Username |
PASSWORD | Passsword |
SERVICETYPE | Type of resource. Possible values are:
|
SERVICEURI | Identifier of the resource. The name begins with the project name, followed by folder names and ending with the resource name. |
ACTION | The action to be carried out. Possible values are:
|
Every change is carried out in it´s own session (via the SessionManagementMBean), which is automatically activated with description: OSBServiceState_script_<systemdatetime>
This can be seen via the Change Center | View Changes of the Oracle Service Bus Administration 11g Console:
The response from “Disable_JMSConsumerStuFZKNMessageService_PS.bat” is:
In the Oracle Service Bus Administration 11g Console this change can be found as a Task:
The result of changing the state of the OSB Proxy service can be checked in the Oracle Service Bus Administration 11g Console.
The same applies when using “Enable_JMSConsumerStuFZKNMessageService_PS.bat”.
In the sample code below the use of the following MBeans can be seen:
- DomainRuntimeServiceMBean (weblogic.management.mbeanservers.domainruntime.DomainRuntimeServiceMBean.class part of <Middleware Home Directory>/wlserver_10.3/server/lib/wlfullclient.jar)
Provides a common access point for navigating to all runtime and configuration MBeans in the domain as well as to MBeans that provide domain-wide services (such as controlling and monitoring the life cycles of servers and message-driven EJBs and coordinating the migration of migratable services). [https://docs.oracle.com/middleware/1213/wls/WLAPI/weblogic/management/mbeanservers/domainruntime/DomainRuntimeServiceMBean.html]
This library is not by default provided in a WebLogic install and must be build. The simple way of how to do this is described in
“Fusion Middleware Programming Stand-alone Clients for Oracle WebLogic Server, Using the WebLogic JarBuilder Tool”, which can be reached via url: https://docs.oracle.com/cd/E28280_01/web.1111/e13717/jarbuilder.htm#SACLT240.
- SessionManagementMBean (com.bea.wli.sb.management.configuration.SessionManagementMBean.class part of <Middleware Home Directory>/Oracle_OSB1/lib/sb-kernel-api.jar)
Provides API to create, activate or discard sessions. [http://docs.oracle.com/cd/E13171_01/alsb/docs26/javadoc/com/bea/wli/sb/management/configuration/SessionManagementMBean.html]
- ProxyServiceConfigurationMBean (com.bea.wli.sb.management.configuration.ProxyServiceConfigurationMBean.class part of <Middleware Home Directory>/Oracle_OSB1/lib/sb-kernel-api.jar)
Provides API to enable/disable services and enable/disable monitoring for a proxy service. [https://docs.oracle.com/cd/E13171_01/alsb/docs26/javadoc/com/bea/wli/sb/management/configuration/ProxyServiceConfigurationMBean.html]
- BusinessServiceConfigurationMBean (com.bea.wli.sb.management.configuration.BusinessServiceConfigurationMBean.class part of <Middleware Home Directory>/Oracle_OSB1/lib/sb-kernel-api.jar)
Provides API for managing business services. [https://docs.oracle.com/cd/E13171_01/alsb/docs25/javadoc/com/bea/wli/sb/management/configuration/BusinessServiceConfigurationMBean.html]
Once the connection to the DomainRuntimeServiceMBean is made, other MBeans can be found via the findService method.
Service findService(String name, String type, String location)
This method returns the Service on the specified Server or in the primary MBeanServer if the location is not specified.
In the code example below certain java fields are used. For reading purposes the field values are shown in the following table:
Field | Field value |
DomainRuntimeServiceMBean.MBEANSERVER_JNDI_NAME | weblogic.management.mbeanservers.domainruntime |
DomainRuntimeServiceMBean.OBJECT_NAME | com.bea:Name=DomainRuntimeService,Type=weblogic.management.mbeanservers.domainruntime.DomainRuntimeServiceMBean |
SessionManagementMBean.NAME | SessionManagement |
SessionManagementMBean.TYPE | com.bea.wli.sb.management.configuration.SessionManagementMBean |
ProxyServiceConfigurationMBean.NAME | ProxyServiceConfiguration |
ProxyServiceConfigurationMBean.TYPE | com.bea.wli.sb.management.configuration.ProxyServiceConfigurationMBean |
BusinessServiceConfigurationMBean.NAME | BusinessServiceConfiguration |
BusinessServiceConfigurationMBean.TYPE | com.bea.wli.sb.management.configuration.BusinessServiceConfigurationMBean |
Because of the use of com.bea.wli.config.Ref.class , the following library <Middleware Home Directory>/Oracle_OSB1/modules/com.bea.common.configfwk_1.7.0.0.jar was needed.
Because of the use of weblogic.management.jmx.MBeanServerInvocationHandler.class , the following library <Middleware Home Directory>/wlserver_10.3/server/lib/wlfullclient.jar was needed.
When running the code the following error was thrown:
java.lang.RuntimeException: java.lang.ClassNotFoundException: com.bea.wli.sb.management.configuration.DelegatedSessionManagementMBean at weblogic.management.jmx.MBeanServerInvocationHandler.newProxyInstance(MBeanServerInvocationHandler.java:621) at weblogic.management.jmx.MBeanServerInvocationHandler.invoke(MBeanServerInvocationHandler.java:418) at $Proxy0.findService(Unknown Source) at nl.xyz.osbservice.osbservicestate.OSBServiceState.<init>(OSBServiceState.java:66) at nl.xyz.osbservice.osbservicestate.OSBServiceState.main(OSBServiceState.java:217) Caused by: java.lang.ClassNotFoundException: com.bea.wli.sb.management.configuration.DelegatedSessionManagementMBean at java.net.URLClassLoader$1.run(URLClassLoader.java:202) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:190) at java.lang.ClassLoader.loadClass(ClassLoader.java:306) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:247) at weblogic.management.jmx.MBeanServerInvocationHandler.newProxyInstance(MBeanServerInvocationHandler.java:619) ... 4 more Process exited.
So because of the use of com.bea.wli.sb.management.configuration.DelegatedSessionManagementMBean.class the following library <Middleware Home Directory>/Oracle_OSB1/lib/sb-kernel-impl.jar was also needed.
The java code:
package nl.xyz.osbservice.osbservicestate; import com.bea.wli.config.Ref; import com.bea.wli.sb.management.configuration.BusinessServiceConfigurationMBean; import com.bea.wli.sb.management.configuration.ProxyServiceConfigurationMBean; import com.bea.wli.sb.management.configuration.SessionManagementMBean; import java.io.IOException; import java.net.MalformedURLException; import java.util.HashMap; import java.util.Hashtable; import java.util.Properties; import javax.management.MBeanServerConnection; import javax.management.MalformedObjectNameException; import javax.management.ObjectName; import javax.management.remote.JMXConnector; import javax.management.remote.JMXConnectorFactory; import javax.management.remote.JMXServiceURL; import javax.naming.Context; import weblogic.management.jmx.MBeanServerInvocationHandler; import weblogic.management.mbeanservers.domainruntime.DomainRuntimeServiceMBean; public class OSBServiceState { private static MBeanServerConnection connection; private static JMXConnector connector; public OSBServiceState(HashMap props) { super(); SessionManagementMBean sessionManagementMBean = null; String sessionName = "OSBServiceState_script_" + System.currentTimeMillis(); String servicetype; String serviceURI; String action; String description = ""; try { Properties properties = new Properties(); properties.putAll(props); initConnection(properties.getProperty("HOSTNAME"), properties.getProperty("PORT"), properties.getProperty("USERNAME"), properties.getProperty("PASSWORD")); servicetype = properties.getProperty("SERVICETYPE"); serviceURI = properties.getProperty("SERVICEURI"); action = properties.getProperty("ACTION"); DomainRuntimeServiceMBean domainRuntimeServiceMBean = (DomainRuntimeServiceMBean)findDomainRuntimeServiceMBean(connection); // Create a session via SessionManagementMBean. sessionManagementMBean = (SessionManagementMBean)domainRuntimeServiceMBean.findService(SessionManagementMBean.NAME, SessionManagementMBean.TYPE, null); sessionManagementMBean.createSession(sessionName); if (servicetype.equalsIgnoreCase("ProxyService")) { // A Ref uniquely represents a resource, project or folder that is managed by the Configuration Framework. // A Ref object has two components: A typeId that indicates whether it is a project, folder, or a resource, and an array of names of non-zero length. // For a resource the array of names start with the project name, followed by folder names, and end with the resource name. // For a project, the Ref object simply contains one name component, that is, the project name. // A Ref object for a folder contains the project name followed by the names of the folders which it is nested under. Ref ref = constructRef("ProxyService", serviceURI); ProxyServiceConfigurationMBean proxyServiceConfigurationMBean = (ProxyServiceConfigurationMBean)domainRuntimeServiceMBean.findService(ProxyServiceConfigurationMBean.NAME + "." + sessionName, ProxyServiceConfigurationMBean.TYPE, null); if (action.equalsIgnoreCase("Enable")) { proxyServiceConfigurationMBean.enableService(ref); description = "Enabled the service: " + serviceURI; System.out.print("Enabling service " + serviceURI); } else if (action.equalsIgnoreCase("Disable")) { proxyServiceConfigurationMBean.disableService(ref); description = "Disabled the service: " + serviceURI; System.out.print("Disabling service " + serviceURI); } else { System.out.println("Unsupported value for ACTION"); } } else if (servicetype.equals("BusinessService")) { Ref ref = constructRef("BusinessService", serviceURI); BusinessServiceConfigurationMBean businessServiceConfigurationMBean = (BusinessServiceConfigurationMBean)domainRuntimeServiceMBean.findService(BusinessServiceConfigurationMBean.NAME + "." + sessionName, BusinessServiceConfigurationMBean.TYPE, null); if (action.equalsIgnoreCase("Enable")) { businessServiceConfigurationMBean.enableService(ref); description = "Enabled the service: " + serviceURI; System.out.print("Enabling service " + serviceURI); } else if (action.equalsIgnoreCase("Disable")) { businessServiceConfigurationMBean.disableService(ref); description = "Disabled the service: " + serviceURI; System.out.print("Disabling service " + serviceURI); } else { System.out.println("Unsupported value for ACTION"); } } sessionManagementMBean.activateSession(sessionName, description); System.out.println(" has been succesfully completed"); } catch (Exception ex) { if (sessionManagementMBean != null) { try { sessionManagementMBean.discardSession(sessionName); System.out.println(" resulted in an error."); } catch (Exception e) { System.out.println("Unable to discard session: " + sessionName); } } ex.printStackTrace(); } finally { if (connector != null) try { connector.close(); } catch (Exception e) { e.printStackTrace(); } } } /* * Initialize connection to the Domain Runtime MBean Server. */ public static void initConnection(String hostname, String portString, String username, String password) throws IOException, MalformedURLException { String protocol = "t3"; Integer portInteger = Integer.valueOf(portString); int port = portInteger.intValue(); String jndiroot = "/jndi/"; String mbeanserver = DomainRuntimeServiceMBean.MBEANSERVER_JNDI_NAME; JMXServiceURL serviceURL = new JMXServiceURL(protocol, hostname, port, jndiroot + mbeanserver); Hashtable hashtable = new Hashtable(); hashtable.put(Context.SECURITY_PRINCIPAL, username); hashtable.put(Context.SECURITY_CREDENTIALS, password); hashtable.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES, "weblogic.management.remote"); hashtable.put("jmx.remote.x.request.waiting.timeout", new Long(10000)); connector = JMXConnectorFactory.connect(serviceURL, hashtable); connection = connector.getMBeanServerConnection(); } private static Ref constructRef(String refType, String serviceURI) { Ref ref = null; String[] uriData = serviceURI.split("/"); ref = new Ref(refType, uriData); return ref; } /** * Finds the specified MBean object * * @param connection - A connection to the MBeanServer. * @return Object - The MBean or null if the MBean was not found. */ public Object findDomainRuntimeServiceMBean(MBeanServerConnection connection) { try { ObjectName objectName = new ObjectName(DomainRuntimeServiceMBean.OBJECT_NAME); return (DomainRuntimeServiceMBean)MBeanServerInvocationHandler.newProxyInstance(connection, objectName); } catch (MalformedObjectNameException e) { e.printStackTrace(); return null; } } public static void main(String[] args) { try { if (args.length <= 0) { System.out.println("Provide values for the following parameters: HOSTNAME, PORT, USERNAME, PASSWORD, SERVICETYPE, SERVICEURI, ACTION.); } else { HashMap<String, String> map = new HashMap<String, String>(); map.put("HOSTNAME", args[0]); map.put("PORT", args[1]); map.put("USERNAME", args[2]); map.put("PASSWORD", args[3]); map.put("SERVICETYPE", args[4]); map.put("SERVICEURI", args[5]); map.put("ACTION", args[6]); OSBServiceState osbServiceState = new OSBServiceState(map); } } catch (Exception e) { e.printStackTrace(); } } }
HI Marc,
Will it be same for 12c as well??
Regards
Pavan
Hello Pavan,
The Java code will work for 12c as well. You have to use the 12c jar files however.
These are the jar’s I used:
<Middleware Home Directory>/osb/lib/modules/oracle.servicebus.configfwk.jar
<Middleware Home Directory>/osb/lib/modules/oracle.servicebus.kernel-api.jar
<Middleware Home Directory>/osb/lib/modules/oracle.servicebus.kernel-wls.jar
<Middleware Home Directory>/wlserver/modules/clients/com.oracle.webservices.wls.jaxrpc-client.jar
<Middleware Home Directory>/wlserver/modules/com.bea.core.management.jmx.jar
<Middleware Home Directory>/wlserver/modules/com.oracle.weblogic.security.jar
<Middleware Home Directory>/wlserver/server/lib/wlthint3client.jar
<Middleware Home Directory>/wlserver/server/lib/wls-api.jar
Please also have a look at:
https://technology.amis.nl/2018/06/05/oracle-service-bus-12-2-1-1-0-service-exploring-via-weblogic-server-mbeans-with-jmx/
Hi Marc,
very useful info. I have not been able to find any MBean that exposes the attributes/operations on “Logging” and “Reports” attributes for an OSB pipeline. It will be appreciated if you can share your knowledge on this.
regards
PK