WebSphere 6, like all modern application servers, comes with a JMX framework that enables the developer to create cusotm Java applications that manage the server. Basically the idea is that you can perform all the administration tasks (that are available through the admin console) using a Java application locally or remotly.
The problem is that every applicaton server has a different solution, which makes it hard to create a management application that deals with multiple servers. The Management API (JSR-77) should solve this problem, but I found that it’s capabilities are not enough when you want to change the configuration and not only read it.
On WebSphere 6, there are a few things you should understand before going into writing a JMX client:
- WebSphere 6 is based on the latest JMX 1.2 spec so JDK 1.4 and 5 will work great. Remember that in JDK 5 the JMX classes are bundled with the rt.jar.
- The entire configuration domain is divided into two sections: runtime data and configuration data. On the runtime data section, you will find registered MBeans that can be read. To get those, you just need to query the MBeanServer and get the managed objects.On the configuration data section you will find managed objects that construct the configuration of the server but cannot be found using the MBeanServer query methods (since they are not registered there).
The main API you should use is found in the com.ibm.websphere.management.configservice package. The interesting interface is ConfigService, and two interesting classes ConfigServiceProxy and ConfigServiceHelper. Here is a direct link to the API docs: http://publib.boulder.ibm.com/infocenter/wasinfo/v6r0/index.jsp?topic=/com.ibm.websphere.javadoc.doc/public_html/api/index.html
The basic idea behind working with the WebSphere configuration, is that you can use the ConfigService methods to construct, edit and delete configuration objects, that will later can be saved to the main configuration repository and used in runtime. Some configuration changes require server restart, and some can be used instantly. Unfortunally, the ConfigService API is very low-level, and the high-level API is not available to external applications, so you should know what you are doing when manipulating the configuration. The ConfigService will let you change the configuration XML files for Server / Node / Cell / Cluster, but you should be familiar with the structure and elements used in those configuration files.
The easiest way to do that is to create the configuration you need with the admin console and then check the changes in the files, later trying to do the same with the ConfigService API. The config files help is also available at: http://publib.boulder.ibm.com/infocenter/wasinfo/v6r0/topic/com.ibm.websphere.javadoc.doc/configdoc/index.html
Let’s go over the main methods that should be used when creating configuration objects, I will concentrate on changing the configuration and not reading it, since reading is pure standard JMX work. Hopefully in part 2 I will give some code examples.
ConfigService interface main methods:
- queryConfigObjects - This method is used when you want to look up a config objects in the configuration. Remember that config objects are not registered in the MBeanServer so the standard query methods will not work, and you should use this one. The method let you select the scope and pattern, and return an array of ObjectNames. Note the special keys: _WEBSPHERE_CONFIG_DATA_TYPE and _WEBSPHERE_CONFIG_DATA_ID that are used here to identify config objects.
- createConfigData - This one is used to create new configuration data. Every config object has a parent config object, an attributeName that is used as the child element name in the parent element scope, a type and a list of attributes.You should know the type names, the attributeName and the supported attributes for each config object you add (remember looking at the XML files for the correct values here…)
- addElement - used when the configuration data includes a collection of objects (like properties). Just select the attribute name and value, and where you want to put it in the collection (or just use -1).
- getAttribute - can be used to get an attribute value form a config object.
- getRelationship - get child config objects by the relationship name. This is useful when you know the structure of the configuration file, and want to browse the tree.
- save / discard - control saving or discarding the changes made.
Apart from those, there are other methods available, the complete reference can be found in the API docs.
A session concept is also available (but not mandatory, you can use null for the session arguments), it is explained in the API docs quite good.
On the next part, I will give some code samples to a JMX client that works with WebSphere, and will talk about the requirments for working with WAS 6 from Sun’s JVM.